Skip to content

Commit 5cf9e97

Browse files
authored
feat: add nunit IsEmpty asserts migration docs (#334)
1 parent 65f2531 commit 5cf9e97

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed

docs/NunitAnalyzer.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ This is a generated file, please edit src\FluentAssertions.Analyzers.FluentAsser
88
- [BooleanAssertIsFalse](#scenario-booleanassertisfalse) - `flag.Should().BeFalse();`
99
- [AssertNull](#scenario-assertnull) - `obj.Should().BeNull();`
1010
- [AssertNotNull](#scenario-assertnotnull) - `obj.Should().NotBeNull();`
11+
- [AssertIsEmpty](#scenario-assertisempty) - `collection.Should().BeEmpty();`
12+
- [AssertIsNotEmpty](#scenario-assertisnotempty) - `collection.Should().NotBeEmpty();`
1113

1214

1315
## Scenarios
@@ -136,4 +138,58 @@ Assert.IsNotNull(obj); /* fail message: Expected: not null
136138
obj.Should().NotBeNull(); /* fail message: Expected obj not to be <null>. */
137139
```
138140

141+
### scenario: AssertIsEmpty
142+
143+
```cs
144+
// arrange
145+
var collection = new List<int>();
146+
147+
// old assertion:
148+
Assert.IsEmpty(collection);
149+
150+
// new assertion:
151+
collection.Should().BeEmpty();
152+
```
153+
154+
#### Failure messages
155+
156+
```cs
157+
var collection = new List<int> { 1, 2, 3 };
158+
159+
// old assertion:
160+
Assert.IsEmpty(collection); /* fail message: Expected: <empty>
161+
But was: < 1, 2, 3 >
162+
*/
163+
164+
// new assertion:
165+
collection.Should().BeEmpty(); /* fail message: Expected collection to be empty, but found {1, 2, 3}. */
166+
```
167+
168+
### scenario: AssertIsNotEmpty
169+
170+
```cs
171+
// arrange
172+
var collection = new List<int> { 1, 2, 3 };
173+
174+
// old assertion:
175+
Assert.IsNotEmpty(collection);
176+
177+
// new assertion:
178+
collection.Should().NotBeEmpty();
179+
```
180+
181+
#### Failure messages
182+
183+
```cs
184+
var collection = new List<int>();
185+
186+
// old assertion:
187+
Assert.IsNotEmpty(collection); /* fail message: Expected: not <empty>
188+
But was: <empty>
189+
*/
190+
191+
// new assertion:
192+
collection.Should().NotBeEmpty(); /* fail message: Expected collection not to be empty. */
193+
```
194+
139195

src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs/NunitAnalyzerTests.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.VisualStudio.TestTools.UnitTesting;
22
using Assert = NUnit.Framework.Assert;
33
using FluentAssertions;
4+
using System.Collections.Generic;
45

56
namespace FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs;
67

@@ -182,4 +183,70 @@ public void AssertNotNull_Failure_NewAssertion()
182183
// new assertion:
183184
obj.Should().NotBeNull();
184185
}
186+
187+
[TestMethod]
188+
public void AssertIsEmpty()
189+
{
190+
// arrange
191+
var collection = new List<int>();
192+
193+
// old assertion:
194+
Assert.IsEmpty(collection);
195+
196+
// new assertion:
197+
collection.Should().BeEmpty();
198+
}
199+
200+
[TestMethod, ExpectedTestFrameworkException]
201+
public void AssertIsEmpty_Failure_OldAssertion()
202+
{
203+
// arrange
204+
var collection = new List<int> { 1, 2, 3 };
205+
206+
// old assertion:
207+
Assert.IsEmpty(collection);
208+
}
209+
210+
[TestMethod, ExpectedTestFrameworkException]
211+
public void AssertIsEmpty_Failure_NewAssertion()
212+
{
213+
// arrange
214+
var collection = new List<int> { 1, 2, 3 };
215+
216+
// new assertion:
217+
collection.Should().BeEmpty();
218+
}
219+
220+
[TestMethod]
221+
public void AssertIsNotEmpty()
222+
{
223+
// arrange
224+
var collection = new List<int> { 1, 2, 3 };
225+
226+
// old assertion:
227+
Assert.IsNotEmpty(collection);
228+
229+
// new assertion:
230+
collection.Should().NotBeEmpty();
231+
}
232+
233+
[TestMethod, ExpectedTestFrameworkException]
234+
public void AssertIsNotEmpty_Failure_OldAssertion()
235+
{
236+
// arrange
237+
var collection = new List<int>();
238+
239+
// old assertion:
240+
Assert.IsNotEmpty(collection);
241+
}
242+
243+
[TestMethod, ExpectedTestFrameworkException]
244+
public void AssertIsNotEmpty_Failure_NewAssertion()
245+
{
246+
// arrange
247+
var collection = new List<int>();
248+
249+
// new assertion:
250+
collection.Should().NotBeEmpty();
251+
}
185252
}

0 commit comments

Comments
 (0)