Skip to content

Commit bf7a559

Browse files
authored
feat: add nunit collection assert AreEqual (#346)
1 parent d652dfa commit bf7a559

File tree

6 files changed

+382
-0
lines changed

6 files changed

+382
-0
lines changed

docs/Nunit3Analyzer.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ This is a generated file, please edit src\FluentAssertions.Analyzers.FluentAsser
1212
- [AssertIsNotEmpty](#scenario-assertisnotempty) - `collection.Should().NotBeEmpty();`
1313
- [AssertZero](#scenario-assertzero) - `number.Should().Be(0);`
1414
- [AssertNotZero](#scenario-assertnotzero) - `number.Should().NotBe(0);`
15+
- [CollectionAssertAreEqual](#scenario-collectionassertareequal) - `collection.Should().Equal(expected);`
16+
- [CollectionAssertAreNotEqual](#scenario-collectionassertarenotequal) - `collection.Should().NotEqual(expected);`
1517

1618

1719
## Scenarios
@@ -300,4 +302,64 @@ Assert.That(number, Is.Not.Zero); /* fail message: Expected: not equal to 0
300302
number.Should().NotBe(0); /* fail message: Did not expect number to be 0. */
301303
```
302304

305+
### scenario: CollectionAssertAreEqual
306+
307+
```cs
308+
// arrange
309+
var collection = new[] { 1, 2, 3 };
310+
var expected = new[] { 1, 2, 3 };
311+
312+
// old assertion:
313+
CollectionAssert.AreEqual(expected, collection);
314+
315+
// new assertion:
316+
collection.Should().Equal(expected);
317+
```
318+
319+
#### Failure messages
320+
321+
```cs
322+
var collection = new[] { 1, 2, 3 };
323+
var expected = new[] { 1, 2, 4 };
324+
325+
// old assertion:
326+
CollectionAssert.AreEqual(expected, collection); /* fail message: Expected and actual are both <System.Int32[3]>
327+
Values differ at index [2]
328+
Expected: 4
329+
But was: 3
330+
*/
331+
332+
// new assertion:
333+
collection.Should().Equal(expected); /* fail message: Expected collection to be equal to {1, 2, 4}, but {1, 2, 3} differs at index 2. */
334+
```
335+
336+
### scenario: CollectionAssertAreNotEqual
337+
338+
```cs
339+
// arrange
340+
var collection = new[] { 1, 2, 3 };
341+
var expected = new[] { 1, 2, 4 };
342+
343+
// old assertion:
344+
CollectionAssert.AreNotEqual(expected, collection);
345+
346+
// new assertion:
347+
collection.Should().NotEqual(expected);
348+
```
349+
350+
#### Failure messages
351+
352+
```cs
353+
var collection = new[] { 1, 2, 3 };
354+
var expected = new[] { 1, 2, 3 };
355+
356+
// old assertion:
357+
CollectionAssert.AreNotEqual(expected, collection); /* fail message: Expected: not equal to < 1, 2, 3 >
358+
But was: < 1, 2, 3 >
359+
*/
360+
361+
// new assertion:
362+
collection.Should().NotEqual(expected); /* fail message: Did not expect collections {1, 2, 3} and {1, 2, 3} to be equal. */
363+
```
364+
303365

docs/Nunit4Analyzer.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ This is a generated file, please edit src\FluentAssertions.Analyzers.FluentAsser
1212
- [AssertIsNotEmpty](#scenario-assertisnotempty) - `collection.Should().NotBeEmpty();`
1313
- [AssertZero](#scenario-assertzero) - `number.Should().Be(0);`
1414
- [AssertNotZero](#scenario-assertnotzero) - `number.Should().NotBe(0);`
15+
- [CollectionAssertAreEqual](#scenario-collectionassertareequal) - `collection.Should().Equal(expected);`
16+
- [CollectionAssertAreNotEqual](#scenario-collectionassertarenotequal) - `collection.Should().NotEqual(expected);`
1517

1618

1719
## Scenarios
@@ -325,4 +327,66 @@ Assert.That(number, Is.Not.Zero); /* fail message: Assert.That(number, Is.Not.
325327
number.Should().NotBe(0); /* fail message: Did not expect number to be 0. */
326328
```
327329

330+
### scenario: CollectionAssertAreEqual
331+
332+
```cs
333+
// arrange
334+
var collection = new[] { 1, 2, 3 };
335+
var expected = new [] { 1, 2, 3 };
336+
337+
// old assertion:
338+
CollectionAssert.AreEqual(expected, collection);
339+
340+
// new assertion:
341+
collection.Should().Equal(expected);
342+
```
343+
344+
#### Failure messages
345+
346+
```cs
347+
var collection = new[] { 1, 2, 3 };
348+
var expected = new[] { 1, 2, 4 };
349+
350+
// old assertion:
351+
CollectionAssert.AreEqual(expected, collection); /* fail message: Assert.That(actual, Is.EqualTo(expected).AsCollection)
352+
Expected and actual are both <System.Int32[3]>
353+
Values differ at index [2]
354+
Expected: 4
355+
But was: 3
356+
*/
357+
358+
// new assertion:
359+
collection.Should().Equal(expected); /* fail message: Expected collection to be equal to {1, 2, 4}, but {1, 2, 3} differs at index 2. */
360+
```
361+
362+
### scenario: CollectionAssertAreNotEqual
363+
364+
```cs
365+
// arrange
366+
var collection = new[] { 1, 2, 3 };
367+
var expected = new[] { 1, 2, 4 };
368+
369+
// old assertion:
370+
CollectionAssert.AreNotEqual(expected, collection);
371+
372+
// new assertion:
373+
collection.Should().NotEqual(expected);
374+
```
375+
376+
#### Failure messages
377+
378+
```cs
379+
var collection = new[] { 1, 2, 3 };
380+
var expected = new[] { 1, 2, 3 };
381+
382+
// old assertion:
383+
CollectionAssert.AreNotEqual(expected, collection); /* fail message: Assert.That(actual, Is.Not.EqualTo(expected).AsCollection)
384+
Expected: not equal to < 1, 2, 3 >
385+
But was: < 1, 2, 3 >
386+
*/
387+
388+
// new assertion:
389+
collection.Should().NotEqual(expected); /* fail message: Did not expect collections {1, 2, 3} and {1, 2, 3} to be equal. */
390+
```
391+
328392

src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,4 +457,76 @@ public void AssertNotZero_Failure_NewAssertion()
457457
// new assertion:
458458
number.Should().NotBe(0);
459459
}
460+
461+
[Test]
462+
public void CollectionAssertAreEqual()
463+
{
464+
// arrange
465+
var collection = new[] { 1, 2, 3 };
466+
var expected = new [] { 1, 2, 3 };
467+
468+
// old assertion:
469+
CollectionAssert.AreEqual(expected, collection);
470+
471+
// new assertion:
472+
collection.Should().Equal(expected);
473+
}
474+
475+
[Test, ExpectedAssertionException]
476+
public void CollectionAssertAreEqual_Failure_OldAssertion()
477+
{
478+
// arrange
479+
var collection = new[] { 1, 2, 3 };
480+
var expected = new[] { 1, 2, 4 };
481+
482+
// old assertion:
483+
CollectionAssert.AreEqual(expected, collection);
484+
}
485+
486+
[Test, ExpectedAssertionException]
487+
public void CollectionAssertAreEqual_Failure_NewAssertion()
488+
{
489+
// arrange
490+
var collection = new[] { 1, 2, 3 };
491+
var expected = new[] { 1, 2, 4 };
492+
493+
// new assertion:
494+
collection.Should().Equal(expected);
495+
}
496+
497+
[Test]
498+
public void CollectionAssertAreNotEqual()
499+
{
500+
// arrange
501+
var collection = new[] { 1, 2, 3 };
502+
var expected = new[] { 1, 2, 4 };
503+
504+
// old assertion:
505+
CollectionAssert.AreNotEqual(expected, collection);
506+
507+
// new assertion:
508+
collection.Should().NotEqual(expected);
509+
}
510+
511+
[Test, ExpectedAssertionException]
512+
public void CollectionAssertAreNotEqual_Failure_OldAssertion()
513+
{
514+
// arrange
515+
var collection = new[] { 1, 2, 3 };
516+
var expected = new[] { 1, 2, 3 };
517+
518+
// old assertion:
519+
CollectionAssert.AreNotEqual(expected, collection);
520+
}
521+
522+
[Test, ExpectedAssertionException]
523+
public void CollectionAssertAreNotEqual_Failure_NewAssertion()
524+
{
525+
// arrange
526+
var collection = new[] { 1, 2, 3 };
527+
var expected = new[] { 1, 2, 3 };
528+
529+
// new assertion:
530+
collection.Should().NotEqual(expected);
531+
}
460532
}

src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs/Nunit3AnalyzerTests.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,4 +460,76 @@ public void AssertNotZero_Failure_NewAssertion()
460460
// new assertion:
461461
number.Should().NotBe(0);
462462
}
463+
464+
[TestMethod]
465+
public void CollectionAssertAreEqual()
466+
{
467+
// arrange
468+
var collection = new[] { 1, 2, 3 };
469+
var expected = new[] { 1, 2, 3 };
470+
471+
// old assertion:
472+
CollectionAssert.AreEqual(expected, collection);
473+
474+
// new assertion:
475+
collection.Should().Equal(expected);
476+
}
477+
478+
[TestMethod, ExpectedTestFrameworkException]
479+
public void CollectionAssertAreEqual_Failure_OldAssertion()
480+
{
481+
// arrange
482+
var collection = new[] { 1, 2, 3 };
483+
var expected = new[] { 1, 2, 4 };
484+
485+
// old assertion:
486+
CollectionAssert.AreEqual(expected, collection);
487+
}
488+
489+
[TestMethod, ExpectedTestFrameworkException]
490+
public void CollectionAssertAreEqual_Failure_NewAssertion()
491+
{
492+
// arrange
493+
var collection = new[] { 1, 2, 3 };
494+
var expected = new[] { 1, 2, 4 };
495+
496+
// new assertion:
497+
collection.Should().Equal(expected);
498+
}
499+
500+
[TestMethod]
501+
public void CollectionAssertAreNotEqual()
502+
{
503+
// arrange
504+
var collection = new[] { 1, 2, 3 };
505+
var expected = new[] { 1, 2, 4 };
506+
507+
// old assertion:
508+
CollectionAssert.AreNotEqual(expected, collection);
509+
510+
// new assertion:
511+
collection.Should().NotEqual(expected);
512+
}
513+
514+
[TestMethod, ExpectedTestFrameworkException]
515+
public void CollectionAssertAreNotEqual_Failure_OldAssertion()
516+
{
517+
// arrange
518+
var collection = new[] { 1, 2, 3 };
519+
var expected = new[] { 1, 2, 3 };
520+
521+
// old assertion:
522+
CollectionAssert.AreNotEqual(expected, collection);
523+
}
524+
525+
[TestMethod, ExpectedTestFrameworkException]
526+
public void CollectionAssertAreNotEqual_Failure_NewAssertion()
527+
{
528+
// arrange
529+
var collection = new[] { 1, 2, 3 };
530+
var expected = new[] { 1, 2, 3 };
531+
532+
// new assertion:
533+
collection.Should().NotEqual(expected);
534+
}
463535
}

0 commit comments

Comments
 (0)