Skip to content

Commit 4d9444e

Browse files
committed
Migrate to Shouldly
1 parent 01805a5 commit 4d9444e

File tree

94 files changed

+1944
-2063
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+1944
-2063
lines changed

BitFaster.Caching.UnitTests.Std/BitFaster.Caching.UnitTests.Std.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
<PrivateAssets>all</PrivateAssets>
1111
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1212
</PackageReference>
13-
<PackageReference Include="FluentAssertions" Version="7.0.0" />
13+
<PackageReference Include="Shouldly" Version="4.3.0" />
1414
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
15-
<PackageReference Include="Moq" Version="4.20.70" />
15+
<PackageReference Include="Moq" Version="4.20.72" />
1616
<PackageReference Include="ObjectLayoutInspector" Version="0.1.4" />
1717
<PackageReference Include="xunit" Version="2.9.3" />
18-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
18+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1">
1919
<PrivateAssets>all</PrivateAssets>
2020
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2121
</PackageReference>
22-
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
22+
<PackageReference Include="Xunit.SkippableFact" Version="1.5.23" />
2323
</ItemGroup>
2424

2525
<ItemGroup>

BitFaster.Caching.UnitTests.Std/DurationTests.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
using System.Diagnostics;
33
using System.Runtime.InteropServices;
44
using BitFaster.Caching.Lru;
5-
using FluentAssertions;
65
using Xunit;
76
using Xunit.Abstractions;
7+
using Shouldly;
88

99
namespace BitFaster.Caching.UnitTests.Std
1010
{
@@ -25,13 +25,11 @@ public void SinceEpoch()
2525
// On .NET Standard, only windows uses TickCount64
2626
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
2727
{
28-
Duration.SinceEpoch().raw.Should().BeCloseTo(Duration.GetTickCount64(), 15);
28+
Duration.SinceEpoch().raw.ShouldBe(Duration.GetTickCount64());
2929
}
3030
else
3131
{
32-
// eps is 1/200 of a second
33-
ulong eps = (ulong)(Stopwatch.Frequency / 200);
34-
Duration.SinceEpoch().raw.Should().BeCloseTo(Stopwatch.GetTimestamp(), eps);
32+
Duration.SinceEpoch().raw.ShouldBe(Stopwatch.GetTimestamp());
3533
}
3634
}
3735

@@ -41,12 +39,12 @@ public void ToTimeSpan()
4139
// On .NET Standard, only windows uses TickCount64
4240
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
4341
{
44-
new Duration(1000).ToTimeSpan().Should().BeCloseTo(TimeSpan.FromMilliseconds(1000), TimeSpan.FromMilliseconds(10));
42+
new Duration(1000).ToTimeSpan().ShouldBe(TimeSpan.FromMilliseconds(1000), TimeSpan.FromMilliseconds(10));
4543
}
4644
else
4745
{
4846
// for Stopwatch.GetTimestamp() this is number of ticks
49-
new Duration(1 * Stopwatch.Frequency).ToTimeSpan().Should().BeCloseTo(TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(10));
47+
new Duration(1 * Stopwatch.Frequency).ToTimeSpan().ShouldBe(TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(10));
5048
}
5149
}
5250

@@ -57,12 +55,12 @@ public void FromTimeSpan()
5755
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
5856
{
5957
Duration.FromTimeSpan(TimeSpan.FromSeconds(1)).raw
60-
.Should().Be((long)TimeSpan.FromSeconds(1).TotalMilliseconds);
58+
.ShouldBe((long)TimeSpan.FromSeconds(1).TotalMilliseconds);
6159
}
6260
else
6361
{
6462
Duration.FromTimeSpan(TimeSpan.FromSeconds(1)).raw
65-
.Should().Be(Stopwatch.Frequency);
63+
.ShouldBe(Stopwatch.Frequency);
6664
}
6765
}
6866

BitFaster.Caching.UnitTests/Atomic/AsyncAtomicFactoryTests.cs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Threading;
33
using System.Threading.Tasks;
44
using BitFaster.Caching.Atomic;
5-
using FluentAssertions;
5+
using Shouldly;
66
using Xunit;
77

88
namespace BitFaster.Caching.UnitTests.Atomic
@@ -14,53 +14,53 @@ public void DefaultCtorValueIsNotCreated()
1414
{
1515
var a = new AsyncAtomicFactory<int, int>();
1616

17-
a.IsValueCreated.Should().BeFalse();
18-
a.ValueIfCreated.Should().Be(0);
17+
a.IsValueCreated.ShouldBeFalse();
18+
a.ValueIfCreated.ShouldBe(0);
1919
}
2020

2121
[Fact]
2222
public void WhenValuePassedToCtorValueIsStored()
2323
{
2424
var a = new AsyncAtomicFactory<int, int>(1);
2525

26-
a.ValueIfCreated.Should().Be(1);
27-
a.IsValueCreated.Should().BeTrue();
26+
a.ValueIfCreated.ShouldBe(1);
27+
a.IsValueCreated.ShouldBeTrue();
2828
}
2929

3030
[Fact]
3131
public async Task WhenValueCreatedValueReturned()
3232
{
3333
var a = new AsyncAtomicFactory<int, int>();
34-
(await a.GetValueAsync(1, k => Task.FromResult(2))).Should().Be(2);
34+
(await a.GetValueAsync(1, k => Task.FromResult(2))).ShouldBe(2);
3535

36-
a.ValueIfCreated.Should().Be(2);
37-
a.IsValueCreated.Should().BeTrue();
36+
a.ValueIfCreated.ShouldBe(2);
37+
a.IsValueCreated.ShouldBeTrue();
3838
}
3939

4040
[Fact]
4141
public async Task WhenValueCreatedWithArgValueReturned()
4242
{
4343
var a = new AsyncAtomicFactory<int, int>();
44-
(await a.GetValueAsync(1, (k, a) => Task.FromResult(k + a), 7)).Should().Be(8);
44+
(await a.GetValueAsync(1, (k, a) => Task.FromResult(k + a), 7)).ShouldBe(8);
4545

46-
a.ValueIfCreated.Should().Be(8);
47-
a.IsValueCreated.Should().BeTrue();
46+
a.ValueIfCreated.ShouldBe(8);
47+
a.IsValueCreated.ShouldBeTrue();
4848
}
4949

5050
[Fact]
5151
public async Task WhenValueCreatedGetValueReturnsOriginalValue()
5252
{
5353
var a = new AsyncAtomicFactory<int, int>();
5454
await a.GetValueAsync(1, k => Task.FromResult(2));
55-
(await a.GetValueAsync(1, k => Task.FromResult(3))).Should().Be(2);
55+
(await a.GetValueAsync(1, k => Task.FromResult(3))).ShouldBe(2);
5656
}
5757

5858
[Fact]
5959
public async Task WhenValueCreatedArgGetValueReturnsOriginalValue()
6060
{
6161
var a = new AsyncAtomicFactory<int, int>();
6262
await a.GetValueAsync(1, (k, a) => Task.FromResult(k + a), 7);
63-
(await a.GetValueAsync(1, (k, a) => Task.FromResult(k + a), 9)).Should().Be(8);
63+
(await a.GetValueAsync(1, (k, a) => Task.FromResult(k + a), 9)).ShouldBe(8);
6464
}
6565

6666
[Fact]
@@ -70,9 +70,9 @@ public async Task WhenValueCreateThrowsValueIsNotStored()
7070

7171
Func<Task> getOrAdd = async () => { await a.GetValueAsync(1, k => throw new ArithmeticException()); };
7272

73-
await getOrAdd.Should().ThrowAsync<ArithmeticException>();
73+
var ex = await getOrAdd.ShouldThrowAsync<ArithmeticException>();;
7474

75-
(await a.GetValueAsync(1, k => Task.FromResult(3))).Should().Be(3);
75+
(await a.GetValueAsync(1, k => Task.FromResult(3))).ShouldBe(3);
7676
}
7777

7878
[Fact]
@@ -108,26 +108,26 @@ public async Task WhenCallersRunConcurrentlyResultIsFromWinner()
108108
await enter.Task;
109109
resume.SetResult(true);
110110

111-
(await first).Should().Be(result);
112-
(await second).Should().Be(result);
111+
(await first).ShouldBe(result);
112+
(await second).ShouldBe(result);
113113

114-
winnerCount.Should().Be(1);
114+
winnerCount.ShouldBe(1);
115115
}
116116

117117
[Fact]
118118
public void WhenValueNotCreatedHashCodeIsZero()
119119
{
120120
new AsyncAtomicFactory<int, int>()
121121
.GetHashCode()
122-
.Should().Be(0);
122+
.ShouldBe(0);
123123
}
124124

125125
[Fact]
126126
public void WhenValueCreatedHashCodeIsValueHashCode()
127127
{
128128
new AsyncAtomicFactory<int, int>(1)
129129
.GetHashCode()
130-
.Should().Be(1);
130+
.ShouldBe(1);
131131
}
132132

133133
[Fact]
@@ -136,7 +136,7 @@ public void WhenValueNotCreatedEqualsFalse()
136136
var a = new AsyncAtomicFactory<int, int>();
137137
var b = new AsyncAtomicFactory<int, int>();
138138

139-
a.Equals(b).Should().BeFalse();
139+
a.Equals(b).ShouldBeFalse();
140140
}
141141

142142
[Fact]
@@ -145,15 +145,15 @@ public void WhenOtherValueNotCreatedEqualsFalse()
145145
var a = new AsyncAtomicFactory<int, int>(1);
146146
var b = new AsyncAtomicFactory<int, int>();
147147

148-
a.Equals(b).Should().BeFalse();
148+
a.Equals(b).ShouldBeFalse();
149149
}
150150

151151
[Fact]
152152
public void WhenArgNullEqualsFalse()
153153
{
154154
new AsyncAtomicFactory<int, int>(1)
155155
.Equals(null)
156-
.Should().BeFalse();
156+
.ShouldBeFalse();
157157
}
158158

159159
[Fact]
@@ -163,7 +163,7 @@ public void WhenArgObjectValuesAreSameEqualsTrue()
163163

164164
new AsyncAtomicFactory<int, int>(1)
165165
.Equals(other)
166-
.Should().BeTrue();
166+
.ShouldBeTrue();
167167
}
168168
}
169169
}

0 commit comments

Comments
 (0)