Skip to content

Commit dfe883c

Browse files
committed
don't use Arg.Any for CancellationToken
1 parent 3ff5464 commit dfe883c

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

tests/MetricPusherHostedServiceTests.cs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ public class MetricPusherHostedServiceTests
99
public async Task WithDefaultInterval_PushMetricPeriodically()
1010
{
1111
var pusher = Substitute.For<IMetricPusher>();
12-
var ct = Arg.Any<CancellationToken>();
1312

1413
var hostedService = new MetricPusherHostedService(pusher);
1514

16-
await hostedService.StartAsync(ct);
17-
await Task.Delay(GetDelay(1), ct);
18-
await hostedService.StopAsync(ct);
15+
await hostedService.StartAsync(CancellationToken.None);
16+
await Task.Delay(GetDelay(1));
17+
await hostedService.StopAsync(CancellationToken.None);
1918

2019
await pusher.Received(3).PushAsync();
2120
}
@@ -28,13 +27,11 @@ public async Task WithDefaultInterval_PushMetricPeriodically()
2827
public async Task WithGivenInterval_PushMetricPeriodically(int seconds)
2928
{
3029
var pusher = Substitute.For<IMetricPusher>();
31-
var ct = Arg.Any<CancellationToken>();
32-
3330
var hostedService = new MetricPusherHostedService(pusher, TimeSpan.FromSeconds(seconds));
3431

35-
await hostedService.StartAsync(ct);
36-
await Task.Delay(GetDelay(seconds), ct);
37-
await hostedService.StopAsync(ct);
32+
await hostedService.StartAsync(CancellationToken.None);
33+
await Task.Delay(GetDelay(seconds));
34+
await hostedService.StopAsync(CancellationToken.None);
3835

3936
await pusher.Received(3).PushAsync();
4037
}
@@ -44,13 +41,12 @@ public async Task OnPushError_HandlesException()
4441
{
4542
var pusher = Substitute.For<IMetricPusher>();
4643
pusher.PushAsync().Returns(Task.FromException(new Exception("Simulated Push Exception")));
47-
var ct = Arg.Any<CancellationToken>();
4844

4945
var hostedService = new TestableMetricPusherHostedService(pusher);
5046

51-
await hostedService.StartAsync(ct);
52-
await Task.Delay(100, ct);
53-
await hostedService.StopAsync(ct);
47+
await hostedService.StartAsync(CancellationToken.None);
48+
await Task.Delay(100);
49+
await hostedService.StopAsync(CancellationToken.None);
5450

5551
hostedService.ErrorHandled.Should().BeTrue();
5652
}

0 commit comments

Comments
 (0)