Skip to content

Commit fe77373

Browse files
authored
docs: add errors for old and new assertions (p2) (#318)
* docs: add errors for old and new assertions * docs: add errors for old and new assertions * docs: add errors for old and new assertions * docs: add errors for old and new assertions * docs: add errors for old and new assertions * docs: add errors for old and new assertions
1 parent 284cde0 commit fe77373

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

docs/FluentAssertionsAnalyzer.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ collection.Should().NotBeEmpty();
4040

4141
```cs
4242
// arrange
43+
var collection = new List<int> { };
4344

4445
// old assertion:
4546
collection.Any().Should().BeTrue(); // fail message: Expected collection.Any() to be true, but found False.
@@ -68,6 +69,7 @@ collection.Should().BeEmpty();
6869

6970
```cs
7071
// arrange
72+
var collection = new List<int> { 1, 2, 3 };
7173

7274
// old assertion:
7375
collection.Any().Should().BeFalse(); // fail message: Expected collection.Any() to be false, but found True.
@@ -97,6 +99,7 @@ collection.Should().NotContain(i => i == 4);
9799

98100
```cs
99101
// arrange
102+
var collection = new List<int> { 1, 2, 3, 4, 5 };
100103

101104
// old assertion:
102105
collection.Any(i => i == 4).Should().BeFalse(); // fail message: Expected collection.Any(i => i == 4) to be false, but found True.
@@ -123,6 +126,7 @@ collection.Should().NotContain(4);
123126

124127
```cs
125128
// arrange
129+
var collection = new List<int> { 1, 2, 3, 4, 5 };
126130

127131
// old assertion:
128132
collection.Contains(4).Should().BeFalse(); // fail message: Expected collection.Contains(4) to be false, but found True.
@@ -148,6 +152,7 @@ collection.Should().OnlyContain(x => x > 0);
148152

149153
```cs
150154
// arrange
155+
var collection = new List<int> { 1, 2, 3, -1 };
151156

152157
// old assertion:
153158
collection.All(x => x > 0).Should().BeTrue(); // fail message: Expected collection.All(x => x > 0) to be true, but found False.
@@ -173,6 +178,7 @@ collection.Should().Contain(2);
173178

174179
```cs
175180
// arrange
181+
var collection = new List<int> { 1, 3, 4, 5 };
176182

177183
// old assertion:
178184
collection.Contains(2).Should().BeTrue(); // fail message: Expected collection.Contains(2) to be true, but found False.
@@ -199,6 +205,7 @@ collection.Should().Contain(i => i == 2);
199205

200206
```cs
201207
// arrange
208+
var collection = new List<int> { 3, 4, 5 };
202209

203210
// old assertion:
204211
collection.Any(i => i == 2).Should().BeTrue(); // fail message: Expected collection.Any(i => i == 2) to be true, but found False.
@@ -226,6 +233,7 @@ collection.Should().HaveCount(3);
226233

227234
```cs
228235
// arrange
236+
var collection = new List<int> { 1, 2, 3, 4, 5 };
229237

230238
// old assertion:
231239
collection.Count().Should().Be(3); // fail message: Expected collection.Count() to be 3, but found 5.
@@ -252,6 +260,7 @@ collection.Should().HaveCount(3);
252260

253261
```cs
254262
// arrange
263+
var collection = new int[] { 1, 2, 3, 4, 5 };
255264

256265
// old assertion:
257266
collection.Length.Should().Be(3); // fail message: Expected collection.Length to be 3, but found 5.
@@ -277,6 +286,7 @@ collection.Should().NotHaveCount(4);
277286

278287
```cs
279288
// arrange
289+
var collection = new List<int> { 1, 2, 3, 4 };
280290

281291
// old assertion:
282292
collection.Count().Should().NotBe(4); // fail message: Did not expect collection.Count() to be 4.
@@ -304,6 +314,7 @@ collection.Should().ContainSingle();
304314

305315
```cs
306316
// arrange
317+
var collection = new List<int> { 1, 2, 3 };
307318

308319
// old assertion:
309320
collection.Count().Should().Be(1); // fail message: Expected collection.Count() to be 1, but found 3.
@@ -331,6 +342,7 @@ collection.Should().HaveCountGreaterThan(2);
331342

332343
```cs
333344
// arrange
345+
var collection = new List<int> { 1 };
334346

335347
// old assertion:
336348
collection.Count().Should().BeGreaterThan(2); // fail message: Expected collection.Count() to be greater than 2, but found 1.
@@ -356,6 +368,7 @@ collection.Should().HaveCountGreaterOrEqualTo(3);
356368

357369
```cs
358370
// arrange
371+
var collection = new List<int> { 1, 2 };
359372

360373
// old assertion:
361374
collection.Count().Should().BeGreaterOrEqualTo(3); // fail message: Expected collection.Count() to be greater than or equal to 3, but found 2.
@@ -381,6 +394,7 @@ collection.Should().HaveCountLessThan(4);
381394

382395
```cs
383396
// arrange
397+
var collection = new List<int> { 1, 2, 3, 4, 5 };
384398

385399
// old assertion:
386400
collection.Count().Should().BeLessThan(4); // fail message: Expected collection.Count() to be less than 4, but found 5.
@@ -406,6 +420,7 @@ collection.Should().HaveCountLessOrEqualTo(3);
406420

407421
```cs
408422
// arrange
423+
var collection = new List<int> { 1, 2, 3, 4 };
409424

410425
// old assertion:
411426
collection.Count().Should().BeLessOrEqualTo(3); // fail message: Expected collection.Count() to be less than or equal to 3, but found 4.
@@ -432,6 +447,7 @@ collection.Should().HaveSameCount(otherCollection);
432447

433448
```cs
434449
// arrange
450+
var collection = new List<int> { 1, 2, 3 };
435451

436452
// old assertion:
437453
collection.Should().HaveCount(otherCollection.Count()); // fail message: Expected collection to contain 4 item(s), but found 3: {1, 2, 3}.
@@ -458,6 +474,7 @@ collection.Should().NotHaveSameCount(otherCollection);
458474

459475
```cs
460476
// arrange
477+
var collection = new List<int> { 1, 2, 3 };
461478

462479
// old assertion:
463480
collection.Count().Should().NotBe(otherCollection.Count()); // fail message: Did not expect collection.Count() to be 3.
@@ -483,6 +500,7 @@ collection.Should().ContainSingle(i => i == 1);
483500

484501
```cs
485502
// arrange
503+
var collection = new List<int> { 1, 2, 3, 1 };
486504

487505
// old assertion:
488506
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}.
@@ -509,6 +527,7 @@ collection.Should().NotBeNullOrEmpty();
509527

510528
```cs
511529
// arrange
530+
var collection = new List<int>();
512531

513532
// old assertion:
514533
collection.Should().NotBeEmpty().And.NotBeNull(); // fail message: Expected collection not to be empty.

src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocsGenerator/DocsGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public async Task Execute()
8080
.Select((x, i) => x.ToString().TrimStart() + " \t// fail message: " + exceptionMessageLines[i]);
8181
var newAssertion = statements.Single(x => x.Span.CompareTo(newAssertionComment.Span) > 0).ToString().TrimStart() + " \t// fail message: " + exceptionMessageLines[^1];
8282

83-
var arrange = bodyLines[0..1].Select(l => l.Length > paddingToRemove ? l.Substring(paddingToRemove) : l).Aggregate((a, b) => $"{a}{Environment.NewLine}{b}");
83+
var arrange = bodyLines[0..2].Select(l => l.Length > paddingToRemove ? l.Substring(paddingToRemove) : l).Aggregate((a, b) => $"{a}{Environment.NewLine}{b}");
8484

8585
var methodBody = $"```cs{Environment.NewLine}{arrange}{Environment.NewLine}```";
8686

0 commit comments

Comments
 (0)