Skip to content

Commit a06160a

Browse files
committed
docs: fluent assertions string assertions
1 parent fc4eef1 commit a06160a

File tree

2 files changed

+166
-0
lines changed

2 files changed

+166
-0
lines changed

docs/FluentAssertionsAnalyzer.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ This is a generated file, please edit src\FluentAssertions.Analyzers.FluentAsser
88
- [StringShouldEndWith](#scenario-stringshouldendwith) - `actual.Should().EndWith(expected);`
99
- [StringShouldNotBeNullOrEmpty](#scenario-stringshouldnotbenullorempty) - `actual.Should().NotBeNullOrEmpty();`
1010
- [StringShouldBeNullOrEmpty](#scenario-stringshouldbenullorempty) - `actual.Should().BeNullOrEmpty();`
11+
- [StringShouldBeNullOrWhiteSpace](#scenario-stringshouldbenullorwhitespace) - `actual.Should().BeNullOrWhiteSpace();`
12+
- [StringShouldNotBeNullOrWhiteSpace](#scenario-stringshouldnotbenullorwhitespace) - `actual.Should().NotBeNullOrWhiteSpace();`
13+
- [StringShouldHaveLength](#scenario-stringshouldhavelength) - `actual.Should().HaveLength(expected);`
1114
- [CollectionShouldNotBeEmpty](#scenario-collectionshouldnotbeempty) - `collection.Should().NotBeEmpty();`
1215
- [CollectionShouldBeEmpty](#scenario-collectionshouldbeempty) - `collection.Should().BeEmpty();`
1316
- [CollectionShouldNotContainCondition](#scenario-collectionshouldnotcontaincondition) - `collection.Should().NotContain(i => i == 4);`
@@ -160,6 +163,86 @@ string.IsNullOrEmpty(actual).Should().BeTrue(); // fail message: Expected strin
160163
actual.Should().BeNullOrEmpty(); // fail message: Expected actual to be <null> or empty, but found "actual".
161164
```
162165

166+
### scenario: StringShouldBeNullOrWhiteSpace
167+
168+
```cs
169+
// arrange
170+
var actual = string.Empty;
171+
172+
// old assertion:
173+
string.IsNullOrWhiteSpace(actual).Should().BeTrue();
174+
175+
// new assertion:
176+
actual.Should().BeNullOrWhiteSpace();
177+
```
178+
179+
#### Failure messages
180+
181+
```cs
182+
// arrange
183+
var actual = "actual";
184+
185+
// old assertion:
186+
string.IsNullOrWhiteSpace(actual).Should().BeTrue(); // fail message: Expected string.IsNullOrWhiteSpace(actual) to be True, but found False.
187+
188+
// new assertion:
189+
actual.Should().BeNullOrWhiteSpace(); // fail message: Expected actual to be <null> or whitespace, but found "actual".
190+
```
191+
192+
### scenario: StringShouldNotBeNullOrWhiteSpace
193+
194+
```cs
195+
// arrange
196+
var actual = "actual";
197+
198+
// old assertion:
199+
string.IsNullOrWhiteSpace(actual).Should().BeFalse();
200+
201+
// new assertion:
202+
actual.Should().NotBeNullOrWhiteSpace();
203+
```
204+
205+
#### Failure messages
206+
207+
```cs
208+
// arrange
209+
var actual = string.Empty;
210+
211+
// old assertion:
212+
string.IsNullOrWhiteSpace(actual).Should().BeFalse(); // fail message: Expected string.IsNullOrWhiteSpace(actual) to be False, but found True.
213+
214+
// new assertion:
215+
actual.Should().NotBeNullOrWhiteSpace(); // fail message: Expected actual not to be <null> or whitespace, but found "".
216+
```
217+
218+
### scenario: StringShouldHaveLength
219+
220+
```cs
221+
// arrange
222+
var actual = "actual";
223+
var expected = 6;
224+
225+
// old assertion:
226+
actual.Length.Should().Be(expected);
227+
228+
// new assertion:
229+
actual.Should().HaveLength(expected);
230+
```
231+
232+
#### Failure messages
233+
234+
```cs
235+
// arrange
236+
var actual = "actual";
237+
var expected = 5;
238+
239+
// old assertion:
240+
actual.Length.Should().Be(expected); // fail message: Expected actual.Length to be 5, but found 6.
241+
242+
// new assertion:
243+
actual.Should().HaveLength(expected); // fail message: Expected actual with length 5, but found string "actual" with length 6.
244+
```
245+
163246
### scenario: CollectionShouldNotBeEmpty
164247

165248
```cs

src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs/FluentAssertionsAnalyzerTests.cs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,89 @@ public void StringShouldBeNullOrEmpty_Failure()
125125
actual.Should().BeNullOrEmpty();
126126
}
127127

128+
[TestMethod]
129+
public void StringShouldBeNullOrWhiteSpace()
130+
{
131+
// arrange
132+
var actual = string.Empty;
133+
134+
// old assertion:
135+
string.IsNullOrWhiteSpace(actual).Should().BeTrue();
136+
137+
// new assertion:
138+
actual.Should().BeNullOrWhiteSpace();
139+
}
140+
141+
[TestMethod, ExpectedException(typeof(AssertFailedException))]
142+
public void StringShouldBeNullOrWhiteSpace_Failure()
143+
{
144+
using var scope = new AssertionScope();
145+
// arrange
146+
var actual = "actual";
147+
148+
// old assertion:
149+
string.IsNullOrWhiteSpace(actual).Should().BeTrue();
150+
151+
// new assertion:
152+
actual.Should().BeNullOrWhiteSpace();
153+
}
154+
155+
[TestMethod]
156+
public void StringShouldNotBeNullOrWhiteSpace()
157+
{
158+
// arrange
159+
var actual = "actual";
160+
161+
// old assertion:
162+
string.IsNullOrWhiteSpace(actual).Should().BeFalse();
163+
164+
// new assertion:
165+
actual.Should().NotBeNullOrWhiteSpace();
166+
}
167+
168+
[TestMethod, ExpectedException(typeof(AssertFailedException))]
169+
public void StringShouldNotBeNullOrWhiteSpace_Failure()
170+
{
171+
using var scope = new AssertionScope();
172+
// arrange
173+
var actual = string.Empty;
174+
175+
// old assertion:
176+
string.IsNullOrWhiteSpace(actual).Should().BeFalse();
177+
178+
// new assertion:
179+
actual.Should().NotBeNullOrWhiteSpace();
180+
}
181+
182+
[TestMethod]
183+
public void StringShouldHaveLength()
184+
{
185+
// arrange
186+
var actual = "actual";
187+
var expected = 6;
188+
189+
// old assertion:
190+
actual.Length.Should().Be(expected);
191+
192+
// new assertion:
193+
actual.Should().HaveLength(expected);
194+
}
195+
196+
[TestMethod, ExpectedException(typeof(AssertFailedException))]
197+
public void StringShouldHaveLength_Failure()
198+
{
199+
using var scope = new AssertionScope();
200+
// arrange
201+
var actual = "actual";
202+
var expected = 5;
203+
204+
// old assertion:
205+
actual.Length.Should().Be(expected);
206+
207+
// new assertion:
208+
actual.Should().HaveLength(expected);
209+
}
210+
128211
[TestMethod]
129212
public void CollectionShouldNotBeEmpty()
130213
{

0 commit comments

Comments
 (0)