Skip to content

Commit e3c9a17

Browse files
committed
fluent assertions
1 parent a58f933 commit e3c9a17

File tree

10 files changed

+44
-27
lines changed

10 files changed

+44
-27
lines changed

src/Extensions/StringExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public static string ToTitleCase(this string title)
230230
/// <returns>The string value including the suffix</returns>
231231
public static string EnsureEndsWith(this string value, string suffix)
232232
{
233-
return value?.EndsWith(suffix)==true ? value : value?.Insert(value.Length, suffix);
233+
return value?.EndsWith(suffix) == true ? value : value?.Insert(value.Length, suffix);
234234
}
235235

236236
/// <summary>
@@ -241,7 +241,7 @@ public static string EnsureEndsWith(this string value, string suffix)
241241
/// <returns>The string value including the prefix</returns>
242242
public static string EnsureStartsWith(this string value, string prefix)
243243
{
244-
return value?.StartsWith(prefix) ==true ? value : value?.Insert(0, prefix);
244+
return value?.StartsWith(prefix) == true ? value : value?.Insert(0, prefix);
245245
}
246246

247247
/// <summary>

src/Infrastructure/Settings/Extensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Infrastructure.Settings
66
{
77
public static class Extensions
88
{
9-
public static IServiceCollection AddApplicationSettings<T>(this IServiceCollection services) where T:DbContext, IDbContextWithSettings
9+
public static IServiceCollection AddApplicationSettings<T>(this IServiceCollection services) where T : DbContext, IDbContextWithSettings
1010
{
1111
services.AddTransient<IApplicationSettingsManager, ApplicationSettingsManager<T>>();
1212

tests/Extensions.Tests/CharExtensionsTests.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
using System;
2-
using System.Text;
3-
using System.Threading.Tasks;
4-
using Xunit;
1+
using Xunit;
52

63
namespace Extensions.Tests
74
{
85
public class CharExtensionsTests
96
{
107
[Theory]
11-
[InlineData('a','A')]
12-
[InlineData('A','A')]
13-
[InlineData(' ',' ')]
8+
[InlineData('a', 'A')]
9+
[InlineData('A', 'A')]
10+
[InlineData(' ', ' ')]
1411
public void ShouldTransformToUppercase(char value, char expected)
1512
{
1613
Assert.Equal(expected, value.ToUpper());

tests/Extensions.Tests/DateTimeExtensionsTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using FluentAssertions;
23
using Xunit;
34

45
namespace Extensions.Tests
@@ -25,7 +26,8 @@ public void DayEndPlusOneMillisecondIsNextDay()
2526
public void ShouldCalculateAgeOnSpecificDate()
2627
{
2728
var birthday = new DateTime(1990, 6, 22);
28-
Assert.Equal(31, birthday.ToAgeAtDate(new DateTime(2022, 4, 12)));
29+
30+
birthday.ToAgeAtDate(new DateTime(2022, 4, 12)).Should().Be(31);
2931
}
3032
}
3133
}

tests/Extensions.Tests/EnumExtensionsTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using System;
2-
using System.ComponentModel;
1+
using System.ComponentModel;
2+
using FluentAssertions;
33
using Xunit;
44

55
namespace Extensions.Tests
@@ -20,7 +20,7 @@ public enum TestEnum
2020
[InlineData(TestEnum.ValueB, "ValueB")]
2121
public void ShouldGetDescription(TestEnum testEnumValue, string expected)
2222
{
23-
Assert.Equal(expected, testEnumValue.GetDescription());
23+
testEnumValue.GetDescription().Should().Be(expected);
2424
}
2525
}
2626
}

tests/Extensions.Tests/Extensions.Tests.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
10+
<PackageReference Include="FluentAssertions" Version="6.6.0" />
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
1112
<PackageReference Include="xunit" Version="2.4.1" />
12-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
13+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
1314
<PrivateAssets>all</PrivateAssets>
1415
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1516
</PackageReference>

tests/Extensions.Tests/GenericExtensionsTests.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using FluentAssertions;
34
using Xunit;
45

56
namespace Extensions.Tests
@@ -116,9 +117,22 @@ public void ShouldCastFromAnonymousObject()
116117

117118
var casted = anon.AnonymousCastTo<TestClass>();
118119

119-
Assert.Equal(casted.Id, anon.Id);
120-
Assert.Equal(casted.Description, anon.Description);
121-
Assert.Equal(casted.TimeStamp, anon.TimeStamp);
120+
casted.Should().BeEquivalentTo(anon);
121+
}
122+
123+
[Fact]
124+
public void ShouldClone()
125+
{
126+
var a = new TestClass
127+
{
128+
Id = 7,
129+
Description = "test",
130+
TimeStamp = DateTime.Now
131+
};
132+
133+
var b = a.Clone();
134+
135+
b.Should().BeEquivalentTo(a);
122136
}
123137

124138
[Theory]

tests/Extensions.Tests/ICollectionExtensionsTests.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using FluentAssertions;
23
using Xunit;
34

45
namespace Extensions.Tests
@@ -13,8 +14,9 @@ public void AddIf()
1314
list.AddIf(_ => true, "Fizz"); // Add "Fizz" value
1415
list.AddIf(_ => false, "Buzz"); // Doesn't add "Buzz" value
1516

16-
Assert.Contains("Fizz", list);
17-
Assert.DoesNotContain("Buzz", list);
17+
18+
list.Should().Contain("Fizz");
19+
list.Should().NotContain("Buzz");
1820
}
1921

2022
[Fact]
@@ -28,7 +30,7 @@ public void AddIfNotContains()
2830
list.AddIfNotContains("FizzExisting"); // Doesn't add "FizzExisting" value, the Collection already contains it.
2931

3032
// Unit Test
31-
Assert.Equal(2, list.Count);
33+
list.Count.Should().Be(2);
3234
}
3335
}
3436
}

tests/Extensions.Tests/IQueryableExtensionsTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ private class TestItem
1515

1616
private readonly IQueryable<TestItem> _items = new List<TestItem> {
1717
new TestItem{ Id = 1, Name = "aaa"},
18-
new TestItem{ Id = 2, Name ="bbb"},
19-
new TestItem{ Id = 3, Name ="ccc"},
20-
new TestItem{ Id=4, Name="ddd"}
18+
new TestItem{ Id = 2, Name = "bbb"},
19+
new TestItem{ Id = 3, Name = "ccc"},
20+
new TestItem{ Id = 4, Name = "ddd"}
2121
}.AsQueryable();
2222

2323
[Theory]

tests/Extensions.Tests/IntExtensionsTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Xunit;
1+
using FluentAssertions;
2+
using Xunit;
23

34
namespace Extensions.Tests
45
{
@@ -11,7 +12,7 @@ public void ShouldExecuteXTimes()
1112

1213
3.Times(() => count++);
1314

14-
Assert.Equal(3, count);
15+
count.Should().Be(3);
1516
}
1617
}
1718
}

0 commit comments

Comments
 (0)