Skip to content

Commit abed3eb

Browse files
committed
Migrate to TUnit framework
1 parent 3a9f378 commit abed3eb

4 files changed

Lines changed: 223 additions & 216 deletions

File tree

tests/BinanceBot.Market.Tests/BinanceBot.Market.Tests.csproj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@
1111
<PackageReference Include="coverlet.collector" Version="6.0.2" />
1212
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
1313
<PackageReference Include="Moq" Version="4.20.72" />
14-
<PackageReference Include="xunit" Version="2.9.2" />
15-
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
14+
<PackageReference Include="TUnit" Version="0.6.*" />
15+
<PackageReference Include="TUnit.Assertions" Version="0.6.*" />
1616
</ItemGroup>
1717

1818
<ItemGroup>
1919
<ProjectReference Include="..\..\src\BinanceBot.Market\BinanceBot.Market.csproj" />
2020
</ItemGroup>
2121

2222
<ItemGroup>
23-
<Using Include="Xunit" />
23+
<Using Include="TUnit.Assertions" />
24+
<Using Include="TUnit.Assertions.Extensions" />
25+
<Using Include="TUnit.Core" />
2426
</ItemGroup>
2527

2628
</Project>

tests/BinanceBot.Market.Tests/Core/MarketDepthTests.cs

Lines changed: 72 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ private static MarketDepth CreateTestMarketDepth() =>
1010
private static MarketDepth CreateTestMarketDepthPerpetual() =>
1111
new MarketDepth(new MarketSymbol("BTC", "USDT", ContractType.Futures));
1212

13-
[Theory]
14-
[InlineData(ContractType.Spot)]
15-
[InlineData(ContractType.Futures)]
16-
public void Constructor_WithValidSymbol_CreatesInstance(ContractType contractType)
13+
[Test]
14+
[Arguments(ContractType.Spot)]
15+
[Arguments(ContractType.Futures)]
16+
public async Task Constructor_WithValidSymbol_CreatesInstance(ContractType contractType)
1717
{
1818
// Arrange
1919
var symbol = new MarketSymbol("BTC", "USDT", contractType);
@@ -22,22 +22,23 @@ public void Constructor_WithValidSymbol_CreatesInstance(ContractType contractTyp
2222
var marketDepth = new MarketDepth(symbol);
2323

2424
// Assert
25-
Assert.Equal(symbol, marketDepth.Symbol);
26-
Assert.Equal(contractType, marketDepth.Symbol.ContractType);
27-
Assert.Null(marketDepth.LastUpdateId);
28-
Assert.Empty(marketDepth.Asks);
29-
Assert.Empty(marketDepth.Bids);
25+
await Assert.That(marketDepth.Symbol).IsEqualTo(symbol);
26+
await Assert.That(marketDepth.Symbol.ContractType).IsEqualTo(contractType);
27+
await Assert.That(marketDepth.LastUpdateId).IsNull();
28+
await Assert.That(marketDepth.Asks).IsEmpty();
29+
await Assert.That(marketDepth.Bids).IsEmpty();
3030
}
3131

32-
[Fact]
33-
public void Constructor_WithNullSymbol_ThrowsArgumentException()
32+
[Test]
33+
public async Task Constructor_WithNullSymbol_ThrowsArgumentException()
3434
{
3535
// Act & Assert
36-
Assert.Throws<ArgumentException>(() => new MarketDepth(null));
36+
await Assert.ThrowsAsync<ArgumentException>(() =>
37+
Task.FromResult(new MarketDepth(null)));
3738
}
3839

39-
[Fact]
40-
public void UpdateDepth_WithValidData_UpdatesOrderBook()
40+
[Test]
41+
public async Task UpdateDepth_WithValidData_UpdatesOrderBook()
4142
{
4243
// Arrange
4344
var marketDepth = CreateTestMarketDepth();
@@ -56,15 +57,15 @@ public void UpdateDepth_WithValidData_UpdatesOrderBook()
5657
marketDepth.UpdateDepth(asks, bids, 123456);
5758

5859
// Assert
59-
Assert.Equal(123456, marketDepth.LastUpdateId);
60-
Assert.Equal(2, marketDepth.Asks.Count());
61-
Assert.Equal(2, marketDepth.Bids.Count());
62-
Assert.Equal(50000m, marketDepth.BestAsk.Price);
63-
Assert.Equal(49900m, marketDepth.BestBid.Price);
60+
await Assert.That(marketDepth.LastUpdateId).IsEqualTo(123456);
61+
await Assert.That(marketDepth.Asks.Count()).IsEqualTo(2);
62+
await Assert.That(marketDepth.Bids.Count()).IsEqualTo(2);
63+
await Assert.That(marketDepth.BestAsk.Price).IsEqualTo(50000m);
64+
await Assert.That(marketDepth.BestBid.Price).IsEqualTo(49900m);
6465
}
6566

66-
[Fact]
67-
public void UpdateDepth_WithValidData_UpdatesOrderBook_Perpetual()
67+
[Test]
68+
public async Task UpdateDepth_WithValidData_UpdatesOrderBook_Perpetual()
6869
{
6970
// Arrange
7071
var marketDepth = CreateTestMarketDepthPerpetual();
@@ -83,16 +84,16 @@ public void UpdateDepth_WithValidData_UpdatesOrderBook_Perpetual()
8384
marketDepth.UpdateDepth(asks, bids, 123456);
8485

8586
// Assert
86-
Assert.Equal(ContractType.Futures, marketDepth.Symbol.ContractType);
87-
Assert.Equal(123456, marketDepth.LastUpdateId);
88-
Assert.Equal(2, marketDepth.Asks.Count());
89-
Assert.Equal(2, marketDepth.Bids.Count());
90-
Assert.Equal(50000m, marketDepth.BestAsk.Price);
91-
Assert.Equal(49900m, marketDepth.BestBid.Price);
87+
await Assert.That(marketDepth.Symbol.ContractType).IsEqualTo(ContractType.Futures);
88+
await Assert.That(marketDepth.LastUpdateId).IsEqualTo(123456);
89+
await Assert.That(marketDepth.Asks.Count()).IsEqualTo(2);
90+
await Assert.That(marketDepth.Bids.Count()).IsEqualTo(2);
91+
await Assert.That(marketDepth.BestAsk.Price).IsEqualTo(50000m);
92+
await Assert.That(marketDepth.BestBid.Price).IsEqualTo(49900m);
9293
}
9394

94-
[Fact]
95-
public void UpdateDepth_WithOldUpdateTime_IgnoresUpdate()
95+
[Test]
96+
public async Task UpdateDepth_WithOldUpdateTime_IgnoresUpdate()
9697
{
9798
// Arrange
9899
var marketDepth = CreateTestMarketDepth();
@@ -114,12 +115,12 @@ public void UpdateDepth_WithOldUpdateTime_IgnoresUpdate()
114115
marketDepth.UpdateDepth(newAsks, bids, 123400);
115116

116117
// Assert - should still have old data
117-
Assert.Equal(123456, marketDepth.LastUpdateId);
118-
Assert.Equal(50000m, marketDepth.BestAsk.Price);
118+
await Assert.That(marketDepth.LastUpdateId).IsEqualTo(123456);
119+
await Assert.That(marketDepth.BestAsk.Price).IsEqualTo(50000m);
119120
}
120121

121-
[Fact]
122-
public void UpdateDepth_RemovesPriceLevelWithZeroQuantity()
122+
[Test]
123+
public async Task UpdateDepth_RemovesPriceLevelWithZeroQuantity()
123124
{
124125
// Arrange
125126
var marketDepth = CreateTestMarketDepth();
@@ -142,22 +143,22 @@ public void UpdateDepth_RemovesPriceLevelWithZeroQuantity()
142143
marketDepth.UpdateDepth(updateAsks, bids, 123457);
143144

144145
// Assert
145-
Assert.Single(marketDepth.Asks);
146-
Assert.Equal(50100m, marketDepth.BestAsk.Price);
146+
await Assert.That(marketDepth.Asks.Count()).IsEqualTo(1);
147+
await Assert.That(marketDepth.BestAsk.Price).IsEqualTo(50100m);
147148
}
148149

149-
[Fact]
150-
public void BestPair_WhenOrderBookIsEmpty_ReturnsNull()
150+
[Test]
151+
public async Task BestPair_WhenOrderBookIsEmpty_ReturnsNull()
151152
{
152153
// Arrange
153154
var marketDepth = CreateTestMarketDepth();
154155

155156
// Act & Assert
156-
Assert.Null(marketDepth.BestPair);
157+
await Assert.That(marketDepth.BestPair).IsNull();
157158
}
158159

159-
[Fact]
160-
public void BestPair_WhenOrderBookHasData_ReturnsPair()
160+
[Test]
161+
public async Task BestPair_WhenOrderBookHasData_ReturnsPair()
161162
{
162163
// Arrange
163164
var marketDepth = CreateTestMarketDepth();
@@ -175,14 +176,14 @@ public void BestPair_WhenOrderBookHasData_ReturnsPair()
175176
var bestPair = marketDepth.BestPair;
176177

177178
// Assert
178-
Assert.NotNull(bestPair);
179-
Assert.Equal(50000m, bestPair.Ask.Price);
180-
Assert.Equal(49900m, bestPair.Bid.Price);
181-
Assert.Equal(100m, bestPair.PriceSpread);
179+
await Assert.That(bestPair).IsNotNull();
180+
await Assert.That(bestPair!.Ask.Price).IsEqualTo(50000m);
181+
await Assert.That(bestPair.Bid.Price).IsEqualTo(49900m);
182+
await Assert.That(bestPair.PriceSpread).IsEqualTo(100m);
182183
}
183184

184-
[Fact]
185-
public void BestPair_WhenOrderBookHasData_ReturnsPair_Perpetual()
185+
[Test]
186+
public async Task BestPair_WhenOrderBookHasData_ReturnsPair_Perpetual()
186187
{
187188
// Arrange
188189
var marketDepth = CreateTestMarketDepthPerpetual();
@@ -200,15 +201,15 @@ public void BestPair_WhenOrderBookHasData_ReturnsPair_Perpetual()
200201
var bestPair = marketDepth.BestPair;
201202

202203
// Assert
203-
Assert.NotNull(bestPair);
204-
Assert.Equal(50000m, bestPair.Ask.Price);
205-
Assert.Equal(49900m, bestPair.Bid.Price);
206-
Assert.Equal(100m, bestPair.PriceSpread);
207-
Assert.Equal(ContractType.Futures, marketDepth.Symbol.ContractType);
204+
await Assert.That(bestPair).IsNotNull();
205+
await Assert.That(bestPair!.Ask.Price).IsEqualTo(50000m);
206+
await Assert.That(bestPair.Bid.Price).IsEqualTo(49900m);
207+
await Assert.That(bestPair.PriceSpread).IsEqualTo(100m);
208+
await Assert.That(marketDepth.Symbol.ContractType).IsEqualTo(ContractType.Futures);
208209
}
209210

210-
[Fact]
211-
public void MarketDepthChanged_RaisesEvent_WhenDepthUpdated()
211+
[Test]
212+
public async Task MarketDepthChanged_RaisesEvent_WhenDepthUpdated()
212213
{
213214
// Arrange
214215
var marketDepth = CreateTestMarketDepth();
@@ -228,13 +229,13 @@ public void MarketDepthChanged_RaisesEvent_WhenDepthUpdated()
228229
marketDepth.UpdateDepth(asks, bids, 123456);
229230

230231
// Assert
231-
Assert.NotNull(eventArgs);
232-
Assert.Equal(123456, eventArgs.UpdateTime);
233-
Assert.Single(eventArgs.Asks);
232+
await Assert.That(eventArgs).IsNotNull();
233+
await Assert.That(eventArgs!.UpdateTime).IsEqualTo(123456);
234+
await Assert.That(eventArgs.Asks.Count()).IsEqualTo(1);
234235
}
235236

236-
[Fact]
237-
public void MarketBestPairChanged_RaisesEvent_WhenBestPairChanges()
237+
[Test]
238+
public async Task MarketBestPairChanged_RaisesEvent_WhenBestPairChanges()
238239
{
239240
// Arrange
240241
var marketDepth = CreateTestMarketDepth();
@@ -254,11 +255,11 @@ public void MarketBestPairChanged_RaisesEvent_WhenBestPairChanges()
254255
marketDepth.UpdateDepth(asks, bids, 123456);
255256

256257
// Assert
257-
Assert.True(eventRaised);
258+
await Assert.That(eventRaised).IsTrue();
258259
}
259260

260-
[Fact]
261-
public void Asks_AreSortedAscending()
261+
[Test]
262+
public async Task Asks_AreSortedAscending()
262263
{
263264
// Arrange
264265
var marketDepth = CreateTestMarketDepth();
@@ -278,11 +279,11 @@ public void Asks_AreSortedAscending()
278279

279280
// Assert
280281
var askPrices = marketDepth.Asks.Select(a => a.Price).ToList();
281-
Assert.Equal(new[] { 50000m, 50100m, 50200m }, askPrices);
282+
await Assert.That(askPrices).IsEquivalentTo(new[] { 50000m, 50100m, 50200m });
282283
}
283284

284-
[Fact]
285-
public void Bids_AreSortedDescending()
285+
[Test]
286+
public async Task Bids_AreSortedDescending()
286287
{
287288
// Arrange
288289
var marketDepth = CreateTestMarketDepth();
@@ -302,11 +303,11 @@ public void Bids_AreSortedDescending()
302303

303304
// Assert
304305
var bidPrices = marketDepth.Bids.Select(b => b.Price).ToList();
305-
Assert.Equal(new[] { 49900m, 49800m, 49700m }, bidPrices);
306+
await Assert.That(bidPrices).IsEquivalentTo(new[] { 49900m, 49800m, 49700m });
306307
}
307308

308-
[Fact]
309-
public void UpdateDepth_WithZeroOrNegativeUpdateTime_ThrowsArgumentOutOfRangeException()
309+
[Test]
310+
public async Task UpdateDepth_WithZeroOrNegativeUpdateTime_ThrowsArgumentOutOfRangeException()
310311
{
311312
// Arrange
312313
var marketDepth = CreateTestMarketDepth();
@@ -316,7 +317,9 @@ public void UpdateDepth_WithZeroOrNegativeUpdateTime_ThrowsArgumentOutOfRangeExc
316317
};
317318

318319
// Act & Assert
319-
Assert.Throws<ArgumentOutOfRangeException>(() => marketDepth.UpdateDepth(asks, null, 0));
320-
Assert.Throws<ArgumentOutOfRangeException>(() => marketDepth.UpdateDepth(asks, null, -1));
320+
await Assert.ThrowsAsync<ArgumentOutOfRangeException>(() =>
321+
Task.Run(() => marketDepth.UpdateDepth(asks, null, 0)));
322+
await Assert.ThrowsAsync<ArgumentOutOfRangeException>(() =>
323+
Task.Run(() => marketDepth.UpdateDepth(asks, null, -1)));
321324
}
322325
}

0 commit comments

Comments
 (0)