Skip to content

Commit e948f59

Browse files
committed
docs: add errors for old and new assertions
1 parent ebe6b30 commit e948f59

File tree

3 files changed

+311
-11
lines changed

3 files changed

+311
-11
lines changed

docs/FluentAssertionsAnalyzer.md

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ collection.Any().Should().BeTrue();
3636
collection.Should().NotBeEmpty();
3737
```
3838

39+
#### Failure messages
40+
41+
```cs
42+
// arrange
43+
44+
// old assertion:
45+
collection.Any().Should().BeTrue(); // fail message: Expected collection.Any() to be true, but found False.
46+
47+
// new assertion:
48+
collection.Should().NotBeEmpty(); // fail message: Expected collection not to be empty.
49+
```
50+
3951
### scenario: CollectionShouldBeEmpty
4052

4153
```cs
@@ -52,6 +64,21 @@ collection.Should().HaveCount(0);
5264
collection.Should().BeEmpty();
5365
```
5466

67+
#### Failure messages
68+
69+
```cs
70+
// arrange
71+
72+
// old assertion:
73+
collection.Any().Should().BeFalse(); // fail message: Expected collection.Any() to be false, but found True.
74+
collection.Count().Should().Be(0); // fail message: Expected collection.Count() to be 0, but found 3 (difference of 3).
75+
collection.Count.Should().Be(0); // fail message: Expected collection.Count to be 0, but found 3 (difference of 3).
76+
collection.Should().HaveCount(0); // fail message: Expected collection to contain 0 item(s), but found 3: {1, 2, 3}.
77+
78+
// new assertion:
79+
collection.Should().BeEmpty(); // fail message: Expected collection to be empty, but found {1, 2, 3}.
80+
```
81+
5582
### scenario: CollectionShouldNotContainCondition
5683

5784
```cs
@@ -66,6 +93,19 @@ collection.Where(i => i == 4).Should().BeEmpty();
6693
collection.Should().NotContain(i => i == 4);
6794
```
6895

96+
#### Failure messages
97+
98+
```cs
99+
// arrange
100+
101+
// old assertion:
102+
collection.Any(i => i == 4).Should().BeFalse(); // fail message: Expected collection.Any(i => i == 4) to be false, but found True.
103+
collection.Where(i => i == 4).Should().BeEmpty(); // fail message: Expected collection.Where(i => i == 4) to be empty, but found {4}.
104+
105+
// new assertion:
106+
collection.Should().NotContain(i => i == 4); // fail message: Expected collection {1, 2, 3, 4, 5} to not have any items matching (i == 4), but found {4}.
107+
```
108+
69109
### scenario: CollectionShouldNotContainItem
70110

71111
```cs
@@ -79,6 +119,18 @@ collection.Contains(4).Should().BeFalse();
79119
collection.Should().NotContain(4);
80120
```
81121

122+
#### Failure messages
123+
124+
```cs
125+
// arrange
126+
127+
// old assertion:
128+
collection.Contains(4).Should().BeFalse(); // fail message: Expected collection.Contains(4) to be false, but found True.
129+
130+
// new assertion:
131+
collection.Should().NotContain(4); // fail message: Expected collection {1, 2, 3, 4, 5} to not contain 4.
132+
```
133+
82134
### scenario: CollectionShouldOnlyContainProperty
83135

84136
```cs
@@ -92,6 +144,18 @@ collection.All(x => x > 0).Should().BeTrue();
92144
collection.Should().OnlyContain(x => x > 0);
93145
```
94146

147+
#### Failure messages
148+
149+
```cs
150+
// arrange
151+
152+
// old assertion:
153+
collection.All(x => x > 0).Should().BeTrue(); // fail message: Expected collection.All(x => x > 0) to be true, but found False.
154+
155+
// new assertion:
156+
collection.Should().OnlyContain(x => x > 0); // fail message: Expected collection to contain only items matching (x > 0), but {-1} do(es) not match.
157+
```
158+
95159
### scenario: CollectionShouldContainItem
96160

97161
```cs
@@ -105,6 +169,18 @@ collection.Contains(2).Should().BeTrue();
105169
collection.Should().Contain(2);
106170
```
107171

172+
#### Failure messages
173+
174+
```cs
175+
// arrange
176+
177+
// old assertion:
178+
collection.Contains(2).Should().BeTrue(); // fail message: Expected collection.Contains(2) to be true, but found False.
179+
180+
// new assertion:
181+
collection.Should().Contain(2); // fail message: Expected collection {1, 3, 4, 5} to contain 2.
182+
```
183+
108184
### scenario: CollectionShouldContainCondition
109185

110186
```cs
@@ -119,6 +195,19 @@ collection.Where(i => i == 2).Should().NotBeEmpty();
119195
collection.Should().Contain(i => i == 2);
120196
```
121197

198+
#### Failure messages
199+
200+
```cs
201+
// arrange
202+
203+
// old assertion:
204+
collection.Any(i => i == 2).Should().BeTrue(); // fail message: Expected collection.Any(i => i == 2) to be true, but found False.
205+
collection.Where(i => i == 2).Should().NotBeEmpty(); // fail message: Expected collection.Where(i => i == 2) not to be empty.
206+
207+
// new assertion:
208+
collection.Should().Contain(i => i == 2); // fail message: Expected collection {3, 4, 5} to have an item matching (i == 2).
209+
```
210+
122211
### scenario: CollectionShouldHaveCount_Count
123212

124213
```cs
@@ -133,6 +222,19 @@ collection.Count.Should().Be(3);
133222
collection.Should().HaveCount(3);
134223
```
135224

225+
#### Failure messages
226+
227+
```cs
228+
// arrange
229+
230+
// old assertion:
231+
collection.Count().Should().Be(3); // fail message: Expected collection.Count() to be 3, but found 5.
232+
collection.Count.Should().Be(3); // fail message: Expected collection.Count to be 3, but found 5.
233+
234+
// new assertion:
235+
collection.Should().HaveCount(3); // fail message: Expected collection to contain 3 item(s), but found 5: {1, 2, 3, 4, 5}.
236+
```
237+
136238
### scenario: CollectionShouldHaveCount_Length
137239

138240
```cs
@@ -146,6 +248,18 @@ collection.Length.Should().Be(3);
146248
collection.Should().HaveCount(3);
147249
```
148250

251+
#### Failure messages
252+
253+
```cs
254+
// arrange
255+
256+
// old assertion:
257+
collection.Length.Should().Be(3); // fail message: Expected collection.Length to be 3, but found 5.
258+
259+
// new assertion:
260+
collection.Should().HaveCount(3); // fail message: Expected collection to contain 3 item(s), but found 5: {1, 2, 3, 4, 5}.
261+
```
262+
149263
### scenario: CollectionShouldNotHaveCount_Count
150264

151265
```cs
@@ -159,6 +273,18 @@ collection.Count().Should().NotBe(4);
159273
collection.Should().NotHaveCount(4);
160274
```
161275

276+
#### Failure messages
277+
278+
```cs
279+
// arrange
280+
281+
// old assertion:
282+
collection.Count().Should().NotBe(4); // fail message: Did not expect collection.Count() to be 4.
283+
284+
// new assertion:
285+
collection.Should().NotHaveCount(4); // fail message: Expected collection to not contain 4 item(s), but found 4.
286+
```
287+
162288
### scenario: CollectionShouldContainSingle
163289

164290
```cs
@@ -174,6 +300,20 @@ collection.Should().HaveCount(1);
174300
collection.Should().ContainSingle();
175301
```
176302

303+
#### Failure messages
304+
305+
```cs
306+
// arrange
307+
308+
// old assertion:
309+
collection.Count().Should().Be(1); // fail message: Expected collection.Count() to be 1, but found 3.
310+
collection.Count.Should().Be(1); // fail message: Expected collection.Count to be 1, but found 3.
311+
collection.Should().HaveCount(1); // fail message: Expected collection to contain 1 item(s), but found 3: {1, 2, 3}.
312+
313+
// new assertion:
314+
collection.Should().ContainSingle(); // fail message: Expected collection to contain a single item, but found {1, 2, 3}.
315+
```
316+
177317
### scenario: CollectionShouldHaveCountGreaterThan_CountShouldBeGreaterThan
178318

179319
```cs
@@ -187,6 +327,18 @@ collection.Count().Should().BeGreaterThan(2);
187327
collection.Should().HaveCountGreaterThan(2);
188328
```
189329

330+
#### Failure messages
331+
332+
```cs
333+
// arrange
334+
335+
// old assertion:
336+
collection.Count().Should().BeGreaterThan(2); // fail message: Expected collection.Count() to be greater than 2, but found 1.
337+
338+
// new assertion:
339+
collection.Should().HaveCountGreaterThan(2); // fail message: Expected collection to contain more than 2 item(s), but found 1: {1}.
340+
```
341+
190342
### scenario: CollectionShouldHaveCountGreaterOrEqualTo_CountShouldBeGreaterOrEqualTo
191343

192344
```cs
@@ -200,6 +352,18 @@ collection.Count().Should().BeGreaterOrEqualTo(3);
200352
collection.Should().HaveCountGreaterOrEqualTo(3);
201353
```
202354

355+
#### Failure messages
356+
357+
```cs
358+
// arrange
359+
360+
// old assertion:
361+
collection.Count().Should().BeGreaterOrEqualTo(3); // fail message: Expected collection.Count() to be greater than or equal to 3, but found 2.
362+
363+
// new assertion:
364+
collection.Should().HaveCountGreaterOrEqualTo(3); // fail message: Expected collection to contain at least 3 item(s), but found 2: {1, 2}.
365+
```
366+
203367
### scenario: CollectionShouldHaveCountLessThan_CountShouldBeLessThan
204368

205369
```cs
@@ -213,6 +377,18 @@ collection.Count().Should().BeLessThan(4);
213377
collection.Should().HaveCountLessThan(4);
214378
```
215379

380+
#### Failure messages
381+
382+
```cs
383+
// arrange
384+
385+
// old assertion:
386+
collection.Count().Should().BeLessThan(4); // fail message: Expected collection.Count() to be less than 4, but found 5.
387+
388+
// new assertion:
389+
collection.Should().HaveCountLessThan(4); // fail message: Expected collection to contain fewer than 4 item(s), but found 5: {1, 2, 3, 4, 5}.
390+
```
391+
216392
### scenario: CollectionShouldHaveCountLessOrEqualTo_CountShouldBeLessOrEqualTo
217393

218394
```cs
@@ -226,6 +402,18 @@ collection.Count().Should().BeLessOrEqualTo(3);
226402
collection.Should().HaveCountLessOrEqualTo(3);
227403
```
228404

405+
#### Failure messages
406+
407+
```cs
408+
// arrange
409+
410+
// old assertion:
411+
collection.Count().Should().BeLessOrEqualTo(3); // fail message: Expected collection.Count() to be less than or equal to 3, but found 4.
412+
413+
// new assertion:
414+
collection.Should().HaveCountLessOrEqualTo(3); // fail message: Expected collection to contain at most 3 item(s), but found 4: {1, 2, 3, 4}.
415+
```
416+
229417
### scenario: CollectionShouldHaveSameCount_ShouldHaveCountOtherCollectionCount
230418

231419
```cs
@@ -240,6 +428,18 @@ collection.Should().HaveCount(otherCollection.Count());
240428
collection.Should().HaveSameCount(otherCollection);
241429
```
242430

431+
#### Failure messages
432+
433+
```cs
434+
// arrange
435+
436+
// old assertion:
437+
collection.Should().HaveCount(otherCollection.Count()); // fail message: Expected collection to contain 4 item(s), but found 3: {1, 2, 3}.
438+
439+
// new assertion:
440+
collection.Should().HaveSameCount(otherCollection); // fail message: Expected collection to have 4 item(s), but found 3.
441+
```
442+
243443
### scenario: CollectionShouldNotHaveSameCount_CountShouldNotBeOtherCollectionCount
244444

245445
```cs
@@ -254,6 +454,18 @@ collection.Count().Should().NotBe(otherCollection.Count());
254454
collection.Should().NotHaveSameCount(otherCollection);
255455
```
256456

457+
#### Failure messages
458+
459+
```cs
460+
// arrange
461+
462+
// old assertion:
463+
collection.Count().Should().NotBe(otherCollection.Count()); // fail message: Did not expect collection.Count() to be 3.
464+
465+
// new assertion:
466+
collection.Should().NotHaveSameCount(otherCollection); // fail message: Expected collection to not have 3 item(s), but found 3.
467+
```
468+
257469
### scenario: CollectionShouldContainSingle_WhereShouldHaveCount1
258470

259471
```cs
@@ -267,6 +479,18 @@ collection.Where(i => i == 1).Should().HaveCount(1);
267479
collection.Should().ContainSingle(i => i == 1);
268480
```
269481

482+
#### Failure messages
483+
484+
```cs
485+
// arrange
486+
487+
// old assertion:
488+
collection.Where(i => i == 1).Should().HaveCount(1); // fail message: Expected collection.Where(i => i == 1) to contain 1 item(s), but found 2: {1, 1}.
489+
490+
// new assertion:
491+
collection.Should().ContainSingle(i => i == 1); // fail message: Expected collection to contain a single item matching (i == 1), but 2 such items were found.
492+
```
493+
270494
### scenario: CollectionShouldNotBeNullOrEmpty
271495

272496
```cs
@@ -281,4 +505,17 @@ collection.Should().NotBeNull().And.NotBeEmpty();
281505
collection.Should().NotBeNullOrEmpty();
282506
```
283507

508+
#### Failure messages
509+
510+
```cs
511+
// arrange
512+
513+
// old assertion:
514+
collection.Should().NotBeEmpty().And.NotBeNull(); // fail message: Expected collection not to be empty.
515+
collection.Should().NotBeNull().And.NotBeEmpty(); // fail message: Expected collection not to be empty.
516+
517+
// new assertion:
518+
collection.Should().NotBeNullOrEmpty(); // fail message: Expected collection not to be empty.
519+
```
520+
284521

0 commit comments

Comments
 (0)