Skip to content

Commit b42badf

Browse files
authored
Merge pull request #29 from ildoc/fix/drop_fa
Replaced FluentAssertions with Shouldly
2 parents 5e4b752 + a3099bd commit b42badf

13 files changed

+103
-96
lines changed

src/Extensions/RandomExtensions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Drawing;
4+
using System.Linq;
35

46
namespace Extensions
57
{
@@ -10,9 +12,9 @@ public static class RandomExtensions
1012
public static DateTime NextDatetime(this Random random, in DateTime from, in DateTime to) =>
1113
from + new TimeSpan((long)(random.NextDouble() * (to - from).Ticks));
1214

13-
public static T OneOf<T>(this Random random, params T[] values)
15+
public static T OneOf<T>(this Random random, IEnumerable<T> values)
1416
{
15-
return values[random.Next(values.Length)];
17+
return values.ElementAt(random.Next(values.Count()));
1618
}
1719

1820
public static string NextHexColor(this Random random)

tests/Extensions.Tests/CharExtensionsTests.cs

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

34
namespace Extensions.Tests
45
{
@@ -10,7 +11,7 @@ public class CharExtensionsTests
1011
[InlineData(' ', ' ')]
1112
public void ShouldTransformToUppercase(char value, char expected)
1213
{
13-
Assert.Equal(expected, value.ToUpper());
14+
value.ToUpper().ShouldBe(expected);
1415
}
1516

1617
[Theory]
@@ -19,7 +20,7 @@ public void ShouldTransformToUppercase(char value, char expected)
1920
[InlineData(' ', ' ')]
2021
public void ShouldTransformToLowercase(char value, char expected)
2122
{
22-
Assert.Equal(expected, value.ToLower());
23+
value.ToLower().ShouldBe(expected);
2324
}
2425

2526
[Theory]
@@ -28,7 +29,7 @@ public void ShouldTransformToLowercase(char value, char expected)
2829
[InlineData(' ', false)]
2930
public void ShouldReturnIfIsAlphabet(char value, bool expected)
3031
{
31-
Assert.Equal(expected, value.IsAsciiAlphabetLetter());
32+
value.IsAsciiAlphabetLetter().ShouldBe(expected);
3233
}
3334
}
3435
}

tests/Extensions.Tests/DateTimeExtensionsTests.cs

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

55
namespace Extensions.Tests
@@ -11,23 +11,23 @@ public void DayStartMinusOneMillisecondIsPreviousDay()
1111
{
1212
var date = DateTime.Now;
1313

14-
Assert.True(date.DayStart().AddMilliseconds(-1).Date == date.AddDays(-1).Date);
14+
date.DayStart().AddMilliseconds(-1).Date.ShouldBe(date.AddDays(-1).Date);
1515
}
1616

1717
[Fact]
1818
public void DayEndPlusOneMillisecondIsNextDay()
1919
{
2020
var date = DateTime.Now;
2121

22-
Assert.True(date.DayEnd().AddMilliseconds(1).Date == date.AddDays(1).Date);
22+
date.DayEnd().AddMilliseconds(1).Date.ShouldBe(date.AddDays(1).Date);
2323
}
2424

2525
[Fact]
2626
public void ShouldCalculateAgeOnSpecificDate()
2727
{
2828
var birthday = new DateTime(1990, 6, 22);
2929

30-
birthday.ToAgeAtDate(new DateTime(2022, 4, 12)).Should().Be(31);
30+
birthday.ToAgeAtDate(new DateTime(2022, 4, 12)).ShouldBe(31);
3131
}
3232
}
3333

@@ -43,7 +43,7 @@ public class ObjectExtensionsTests
4343
[InlineData(-1.3, true)]
4444
public void ShouldCheckIfNumber(object o, bool expected)
4545
{
46-
o.IsNumber().Should().Be(expected);
46+
o.IsNumber().ShouldBe(expected);
4747
}
4848
}
4949
}

tests/Extensions.Tests/DictionaryExtensionsTests.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Collections.Generic;
2-
using FluentAssertions;
32
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
3+
using Shouldly;
44
using Xunit;
55

66
namespace Extensions.Tests
@@ -16,42 +16,42 @@ public void ShouldRunActionForEachItemWhileRemoving()
1616

1717
_dict.RemoveAllWithAction(x => x.Key >= 3, x => str += x.Value);
1818

19-
_dict.Should().HaveCount(2);
20-
str.Should().Be("cccddd");
19+
_dict.Count.ShouldBe(2);
20+
str.ShouldBe("cccddd");
2121
}
2222

2323
[Fact]
2424
public void ShouldRemoveItemsWhere()
2525
{
2626
_dict.RemoveAll(x => x.Key >= 3);
27-
_dict.Count.Should().Be(2);
27+
_dict.Count.ShouldBe(2);
2828
}
2929

3030
[Fact]
3131
public void ShouldTryGetValueIfExists()
3232
{
33-
_dict.GetValue(2).Should().Be("bbb");
33+
_dict.GetValue(2).ShouldBe("bbb");
3434
}
3535

3636
[Fact]
3737
public void ShouldThrowIfValueDontExists()
3838
{
39-
var message = Assert.Throws<KeyNotFoundException>(() => _dict.GetValue(5)).Message;
40-
message.Should().Be("'5' not found in Dictionary");
39+
var message = Should.Throw<KeyNotFoundException>(() => _dict.GetValue(5)).Message;
40+
message.ShouldBe("'5' not found in Dictionary");
4141
}
4242

4343
[Fact]
4444
public void ShouldReturnDefaultIfValueDontExists()
4545
{
46-
_dict.GetValueOrDefault(4).Should().Be("ddd");
47-
_dict.GetValueOrDefault(5).Should().Be(default);
46+
_dict.GetValueOrDefault(4).ShouldBe("ddd");
47+
_dict.GetValueOrDefault(5).ShouldBe(default);
4848
}
4949

5050
[Fact]
5151
public void ShouldSwapKeyValues()
5252
{
5353
var outputdict = new Dictionary<string, int> { { "aaa", 1 }, { "bbb", 2 }, { "ccc", 3 }, { "ddd", 4 } };
54-
_dict.SwapKeyValue().Should().BeEquivalentTo(outputdict);
54+
_dict.SwapKeyValue().ShouldBeEquivalentTo(outputdict);
5555
}
5656

5757
[Fact]
@@ -60,7 +60,7 @@ public void ShouldRunActionForEachItem()
6060
var str = "";
6161
_dict.Each(x => str += x.Value);
6262

63-
str.Should().Be("aaabbbcccddd");
63+
str.ShouldBe("aaabbbcccddd");
6464
}
6565

6666
[Fact]
@@ -73,7 +73,7 @@ public void ShouldConvertToDictionary()
7373
new KeyValuePair<int, string>(4,"ddd"),
7474
};
7575

76-
list.ToDictionary().Should().BeEquivalentTo(_dict);
76+
list.ToDictionary().ShouldBeEquivalentTo(_dict);
7777
}
7878
}
7979
}

tests/Extensions.Tests/EnumExtensionsTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.ComponentModel;
2-
using FluentAssertions;
2+
using Shouldly;
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-
testEnumValue.GetDescription().Should().Be(expected);
23+
testEnumValue.GetDescription().ShouldBe(expected);
2424
}
2525
}
2626
}

tests/Extensions.Tests/Extensions.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="FluentAssertions" Version="7.0.0" />
1110
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
11+
<PackageReference Include="Shouldly" Version="4.2.1" />
1212
<PackageReference Include="xunit" Version="2.9.3" />
1313
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1">
1414
<PrivateAssets>all</PrivateAssets>

tests/Extensions.Tests/GenericExtensionsTests.cs

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

66
namespace Extensions.Tests
@@ -12,7 +12,7 @@ public class GenericExtensionsTests
1212
[InlineData(false, false)]
1313
public void BoolShouldResolveAsBool(bool value, bool expected)
1414
{
15-
value.ToBool().Should().Be(expected);
15+
value.ToBool().ShouldBe(expected);
1616
}
1717

1818
[Theory]
@@ -22,7 +22,7 @@ public void BoolShouldResolveAsBool(bool value, bool expected)
2222
[InlineData(-7, true)]
2323
public void IntShouldResolveAsBool(int? value, bool expected)
2424
{
25-
value.ToBool().Should().Be(expected);
25+
value.ToBool().ShouldBe(expected);
2626
}
2727

2828
[Theory]
@@ -32,7 +32,7 @@ public void IntShouldResolveAsBool(int? value, bool expected)
3232
[InlineData("asd", false)]
3333
public void StringShouldResolveAsBool(string value, bool expected)
3434
{
35-
value.ToBool().Should().Be(expected);
35+
value.ToBool().ShouldBe(expected);
3636
}
3737

3838
[Theory]
@@ -42,7 +42,7 @@ public void StringShouldResolveAsBool(string value, bool expected)
4242
[InlineData(-7f, true)]
4343
public void FloatShouldResolveAsBool(float? value, bool expected)
4444
{
45-
value.ToBool().Should().Be(expected);
45+
value.ToBool().ShouldBe(expected);
4646
}
4747

4848
[Theory]
@@ -52,37 +52,37 @@ public void FloatShouldResolveAsBool(float? value, bool expected)
5252
[InlineData(-7.0, true)]
5353
public void DoubleShouldResolveAsBool(double? value, bool expected)
5454
{
55-
value.ToBool().Should().Be(expected);
55+
value.ToBool().ShouldBe(expected);
5656
}
5757

5858
[Fact]
5959
public void ObjectShouldResolveAsTrue()
6060
{
61-
new { Id = 7 }.ToBool().Should().BeTrue();
61+
new { Id = 7 }.ToBool().ShouldBeTrue();
6262
}
6363

6464
[Fact]
6565
public void NullShouldResolveAsFlase()
6666
{
6767
object value = null;
6868

69-
value.ToBool().Should().BeFalse();
69+
value.ToBool().ShouldBeFalse();
7070
}
7171

7272
[Theory]
7373
[InlineData('b', "abcd", true)]
7474
[InlineData('f', "abcd", false)]
7575
public void ShouldCheckIfValueIsInString(char value, string fullString, bool expected)
7676
{
77-
value.IsIn(fullString).Should().Be(expected);
77+
value.IsIn(fullString).ShouldBe(expected);
7878
}
7979

8080
[Theory]
8181
[InlineData('b', "abcd", false)]
8282
[InlineData('f', "abcd", true)]
8383
public void ShouldCheckIfValueIsNotInString(char value, string fullString, bool expected)
8484
{
85-
value.IsNotIn(fullString).Should().Be(expected);
85+
value.IsNotIn(fullString).ShouldBe(expected);
8686
}
8787

8888
[Fact]
@@ -91,8 +91,8 @@ public void ShouldCheckIfStringIsInStrings()
9191
var value = "test";
9292
var strings = new List<string> { "this", "is", "a", "test" };
9393

94-
value.IsIn(strings).Should().BeTrue();
95-
value.IsNotIn(strings).Should().BeFalse();
94+
value.IsIn(strings).ShouldBeTrue();
95+
value.IsNotIn(strings).ShouldBeFalse();
9696
}
9797

9898
[Fact]
@@ -101,8 +101,8 @@ public void ShouldCheckIfStringIsNotInStrings()
101101
var value = "not";
102102
var strings = new List<string> { "this", "is", "a", "test" };
103103

104-
value.IsIn(strings).Should().BeFalse();
105-
value.IsNotIn(strings).Should().BeTrue();
104+
value.IsIn(strings).ShouldBeFalse();
105+
value.IsNotIn(strings).ShouldBeTrue();
106106
}
107107

108108
[Fact]
@@ -117,7 +117,9 @@ public void ShouldCastFromAnonymousObject()
117117

118118
var casted = anon.AnonymousCastTo<TestClass>();
119119

120-
casted.Should().BeEquivalentTo(anon);
120+
casted.Id.ShouldBe(anon.Id);
121+
casted.Description.ShouldBe(anon.Description);
122+
casted.TimeStamp.ShouldBe(anon.TimeStamp);
121123
}
122124

123125
[Fact]
@@ -132,7 +134,7 @@ public void ShouldClone()
132134

133135
var b = a.Clone();
134136

135-
b.Should().BeEquivalentTo(a);
137+
b.ShouldBeEquivalentTo(a);
136138
}
137139

138140
[Theory]
@@ -143,7 +145,7 @@ public void ShouldClone()
143145
[InlineData("asd", "asd", true)]
144146
public void ShouldReturnEqual(object a, object b, bool expected)
145147
{
146-
a.IsEqualTo(b).Should().Be(expected);
148+
a.IsEqualTo(b).ShouldBe(expected);
147149
}
148150

149151
private class TestClass

tests/Extensions.Tests/ICollectionExtensionsTests.cs

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

55
namespace Extensions.Tests
@@ -15,8 +15,8 @@ public void AddIf()
1515
list.AddIf(_ => false, "Buzz"); // Doesn't add "Buzz" value
1616

1717

18-
list.Should().Contain("Fizz");
19-
list.Should().NotContain("Buzz");
18+
list.ShouldContain("Fizz");
19+
list.ShouldNotContain("Buzz");
2020
}
2121

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

3232
// Unit Test
33-
list.Should().HaveCount(2);
33+
list.Count.ShouldBe(2);
3434
}
3535
}
3636
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.Collections.Generic;
2-
using FluentAssertions;
2+
using Shouldly;
33
using Xunit;
44

55
namespace Extensions.Tests
@@ -10,14 +10,14 @@ public class IEnumerableExtensionsTests
1010
public void ShouldJoinListString()
1111
{
1212
var list = new List<string> { "questa", "è", "una", "lista" };
13-
list.Join(", ").Should().Be("questa, è, una, lista");
13+
list.Join(", ").ShouldBe("questa, è, una, lista");
1414
}
1515

1616
[Fact]
1717
public void ShouldJoinListChar()
1818
{
1919
var list = new List<string> { "questa", "è", "una", "lista" };
20-
list.Join(',').Should().Be("questa,è,una,lista");
20+
list.Join(',').ShouldBe("questa,è,una,lista");
2121
}
2222
}
2323
}

0 commit comments

Comments
 (0)