Skip to content

Commit 9d7eefb

Browse files
authored
feat: add nunit collection assert Contains (#347)
* feat: add nunit collection assert Contains
1 parent 7fbc44b commit 9d7eefb

File tree

7 files changed

+819
-54
lines changed

7 files changed

+819
-54
lines changed

docs/Nunit3Analyzer.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ This is a generated file, please edit src\FluentAssertions.Analyzers.FluentAsser
1414
- [AssertNotZero](#scenario-assertnotzero) - `number.Should().NotBe(0);`
1515
- [CollectionAssertAreEqual](#scenario-collectionassertareequal) - `collection.Should().Equal(expected);`
1616
- [CollectionAssertAreNotEqual](#scenario-collectionassertarenotequal) - `collection.Should().NotEqual(expected);`
17+
- [CollectionAssertContains](#scenario-collectionassertcontains) - `collection.Should().Contain(2);`
18+
- [CollectionAssertContains_WithCasting](#scenario-collectionassertcontains_withcasting) - `collection.Should().Contain((int)item);`
19+
- [CollectionAssertDoesNotContain](#scenario-collectionassertdoesnotcontain) - `collection.Should().NotContain(4);`
20+
- [CollectionAssertDoesNotContain_WithCasting](#scenario-collectionassertdoesnotcontain_withcasting) - `collection.Should().NotContain((int)item);`
1721

1822

1923
## Scenarios
@@ -362,4 +366,116 @@ CollectionAssert.AreNotEqual(expected, collection); /* fail message: Expected:
362366
collection.Should().NotEqual(expected); /* fail message: Did not expect collections {1, 2, 3} and {1, 2, 3} to be equal. */
363367
```
364368

369+
### scenario: CollectionAssertContains
370+
371+
```cs
372+
// arrange
373+
var collection = new[] { 1, 2, 3 };
374+
375+
// old assertion:
376+
CollectionAssert.Contains(collection, 2);
377+
378+
// new assertion:
379+
collection.Should().Contain(2);
380+
```
381+
382+
#### Failure messages
383+
384+
```cs
385+
var collection = new[] { 1, 2, 3 };
386+
387+
// old assertion:
388+
CollectionAssert.Contains(collection, 4); /* fail message: Expected: some item equal to 4
389+
But was: < 1, 2, 3 >
390+
*/
391+
392+
// new assertion:
393+
collection.Should().Contain(4); /* fail message: Expected collection {1, 2, 3} to contain 4. */
394+
```
395+
396+
### scenario: CollectionAssertContains_WithCasting
397+
398+
```cs
399+
// arrange
400+
var collection = new[] { 1, 2, 3 };
401+
object item = 2;
402+
403+
// old assertion:
404+
CollectionAssert.Contains(collection, item);
405+
406+
// new assertion:
407+
collection.Should().Contain((int)item);
408+
```
409+
410+
#### Failure messages
411+
412+
```cs
413+
var collection = new[] { 1, 2, 3 };
414+
object item = 4;
415+
416+
// old assertion:
417+
CollectionAssert.Contains(collection, item); /* fail message: Expected: some item equal to 4
418+
But was: < 1, 2, 3 >
419+
*/
420+
421+
// new assertion:
422+
collection.Should().Contain((int)item); /* fail message: Expected collection {1, 2, 3} to contain 4. */
423+
```
424+
425+
### scenario: CollectionAssertDoesNotContain
426+
427+
```cs
428+
// arrange
429+
var collection = new[] { 1, 2, 3 };
430+
431+
// old assertion:
432+
CollectionAssert.DoesNotContain(collection, 4);
433+
434+
// new assertion:
435+
collection.Should().NotContain(4);
436+
```
437+
438+
#### Failure messages
439+
440+
```cs
441+
var collection = new[] { 1, 2, 3 };
442+
443+
// old assertion:
444+
CollectionAssert.DoesNotContain(collection, 2); /* fail message: Expected: not some item equal to 2
445+
But was: < 1, 2, 3 >
446+
*/
447+
448+
// new assertion:
449+
collection.Should().NotContain(2); /* fail message: Expected collection {1, 2, 3} to not contain 2. */
450+
```
451+
452+
### scenario: CollectionAssertDoesNotContain_WithCasting
453+
454+
```cs
455+
// arrange
456+
var collection = new[] { 1, 2, 3 };
457+
object item = 4;
458+
459+
// old assertion:
460+
CollectionAssert.DoesNotContain(collection, item);
461+
462+
// new assertion:
463+
collection.Should().NotContain((int)item);
464+
```
465+
466+
#### Failure messages
467+
468+
```cs
469+
var collection = new[] { 1, 2, 3 };
470+
object item = 2;
471+
472+
// old assertion:
473+
CollectionAssert.DoesNotContain(collection, item); /* fail message: Expected: not some item equal to 2
474+
But was: < 1, 2, 3 >
475+
*/
476+
477+
// new assertion:
478+
collection.Should().NotContain((int)item); /* fail message: Expected collection {1, 2, 3} to not contain 2. */
479+
```
480+
365481

docs/Nunit4Analyzer.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ This is a generated file, please edit src\FluentAssertions.Analyzers.FluentAsser
1414
- [AssertNotZero](#scenario-assertnotzero) - `number.Should().NotBe(0);`
1515
- [CollectionAssertAreEqual](#scenario-collectionassertareequal) - `collection.Should().Equal(expected);`
1616
- [CollectionAssertAreNotEqual](#scenario-collectionassertarenotequal) - `collection.Should().NotEqual(expected);`
17+
- [CollectionAssertContains](#scenario-collectionassertcontains) - `collection.Should().Contain(2);`
18+
- [CollectionAssertContains_WithCasting](#scenario-collectionassertcontains_withcasting) - `collection.Should().Contain((int)item);`
19+
- [CollectionAssertDoesNotContain](#scenario-collectionassertdoesnotcontain) - `collection.Should().NotContain(4);`
20+
- [CollectionAssertDoesNotContain_WithCasting](#scenario-collectionassertdoesnotcontain_withcasting) - `collection.Should().NotContain((int)item);`
1721

1822

1923
## Scenarios
@@ -389,4 +393,120 @@ CollectionAssert.AreNotEqual(expected, collection); /* fail message: Assert.Th
389393
collection.Should().NotEqual(expected); /* fail message: Did not expect collections {1, 2, 3} and {1, 2, 3} to be equal. */
390394
```
391395

396+
### scenario: CollectionAssertContains
397+
398+
```cs
399+
// arrange
400+
var collection = new[] { 1, 2, 3 };
401+
402+
// old assertion:
403+
CollectionAssert.Contains(collection, 2);
404+
405+
// new assertion:
406+
collection.Should().Contain(2);
407+
```
408+
409+
#### Failure messages
410+
411+
```cs
412+
var collection = new[] { 1, 2, 3 };
413+
414+
// old assertion:
415+
CollectionAssert.Contains(collection, 4); /* fail message: Assert.That(collection, Has.Member(actual))
416+
Expected: some item equal to 4
417+
But was: < 1, 2, 3 >
418+
*/
419+
420+
// new assertion:
421+
collection.Should().Contain(4); /* fail message: Expected collection {1, 2, 3} to contain 4. */
422+
```
423+
424+
### scenario: CollectionAssertContains_WithCasting
425+
426+
```cs
427+
// arrange
428+
var collection = new[] { 1, 2, 3 };
429+
object item = 2;
430+
431+
// old assertion:
432+
CollectionAssert.Contains(collection, item);
433+
434+
// new assertion:
435+
collection.Should().Contain((int)item);
436+
```
437+
438+
#### Failure messages
439+
440+
```cs
441+
var collection = new[] { 1, 2, 3 };
442+
object item = 4;
443+
444+
// old assertion:
445+
CollectionAssert.Contains(collection, item); /* fail message: Assert.That(collection, Has.Member(actual))
446+
Expected: some item equal to 4
447+
But was: < 1, 2, 3 >
448+
*/
449+
450+
// new assertion:
451+
collection.Should().Contain((int)item); /* fail message: Expected collection {1, 2, 3} to contain 4. */
452+
```
453+
454+
### scenario: CollectionAssertDoesNotContain
455+
456+
```cs
457+
// arrange
458+
var collection = new[] { 1, 2, 3 };
459+
460+
// old assertion:
461+
CollectionAssert.DoesNotContain(collection, 4);
462+
463+
// new assertion:
464+
collection.Should().NotContain(4);
465+
```
466+
467+
#### Failure messages
468+
469+
```cs
470+
var collection = new[] { 1, 2, 3 };
471+
472+
// old assertion:
473+
CollectionAssert.DoesNotContain(collection, 2); /* fail message: Assert.That(collection, Has.No.Member(actual))
474+
Expected: not some item equal to 2
475+
But was: < 1, 2, 3 >
476+
*/
477+
478+
// new assertion:
479+
collection.Should().NotContain(2); /* fail message: Expected collection {1, 2, 3} to not contain 2. */
480+
```
481+
482+
### scenario: CollectionAssertDoesNotContain_WithCasting
483+
484+
```cs
485+
// arrange
486+
var collection = new[] { 1, 2, 3 };
487+
object item = 4;
488+
489+
// old assertion:
490+
CollectionAssert.DoesNotContain(collection, item);
491+
492+
// new assertion:
493+
collection.Should().NotContain((int)item);
494+
```
495+
496+
#### Failure messages
497+
498+
```cs
499+
var collection = new[] { 1, 2, 3 };
500+
object item = 2;
501+
502+
// old assertion:
503+
CollectionAssert.DoesNotContain(collection, item); /* fail message: Assert.That(collection, Has.No.Member(actual))
504+
Expected: not some item equal to 2
505+
But was: < 1, 2, 3 >
506+
*/
507+
508+
// new assertion:
509+
collection.Should().NotContain((int)item); /* fail message: Expected collection {1, 2, 3} to not contain 2. */
510+
```
511+
392512

0 commit comments

Comments
 (0)