Skip to content

Commit

Permalink
Update to xunit v3
Browse files Browse the repository at this point in the history
  • Loading branch information
mburumaxwell committed Dec 25, 2024
1 parent 963a319 commit a5be85c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<PropertyGroup>
<WarningsAsErrors>$(WarningsAsErrors),IL2026,IL2060,IL2091,IL2095,IL3050</WarningsAsErrors>
<WarningsAsErrors>$(WarningsAsErrors),xUnit1051</WarningsAsErrors>
</PropertyGroup>

</Project>
5 changes: 2 additions & 3 deletions tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@

<ItemGroup>
<Using Include="Xunit" />
<Using Include="Xunit.Abstractions" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="MartinCostello.Logging.XUnit" Version="0.5.0" />
<PackageReference Include="MartinCostello.Logging.XUnit.v3" Version="0.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0" />
<PackageReference Include="xunit.v3" Version="1.0.0" />
<PackageReference Include="coverlet.collector" Version="6.0.2" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public async Task IgnoresRequestThatDoesNotMatchPath()
using var server = new TestServer(builder);
var client = server.CreateClient();

var response = await client.GetAsync("/frob");
var response = await client.GetAsync("/frob", TestContext.Current.CancellationToken);
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
}

Expand All @@ -74,11 +74,11 @@ public async Task MatchIsCaseInsensitive()
using var server = new TestServer(builder);
var client = server.CreateClient();

var response = await client.GetAsync("/PERIODIC-tasks/registrations");
var response = await client.GetAsync("/PERIODIC-tasks/registrations", TestContext.Current.CancellationToken);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal("application/json; charset=utf-8", response.Content.Headers.ContentType!.ToString());
Assert.NotEqual(0, response.Content.Headers.ContentLength);
Assert.Equal("[]", await response.Content.ReadAsStringAsync());
Assert.Equal("[]", await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken));
}

[Fact]
Expand Down Expand Up @@ -106,7 +106,7 @@ public async Task ListingWorks()
using var server = new TestServer(builder);
var client = server.CreateClient();

var response = await client.GetFromJsonAsync<PeriodicTaskRegistration[]>("/periodic-tasks/registrations");
var response = await client.GetFromJsonAsync<PeriodicTaskRegistration[]>("/periodic-tasks/registrations", TestContext.Current.CancellationToken);
Assert.NotNull(response);
var actual = Assert.Single(response);
Assert.Equal(registration, actual);
Expand Down Expand Up @@ -137,7 +137,7 @@ public async Task GetWorks()
using var server = new TestServer(builder);
var client = server.CreateClient();

var actual = await client.GetFromJsonAsync<PeriodicTaskRegistration>("/periodic-tasks/registrations/dummy");
var actual = await client.GetFromJsonAsync<PeriodicTaskRegistration>("/periodic-tasks/registrations/dummy", TestContext.Current.CancellationToken);
Assert.NotNull(actual);
Assert.Equal(registration, actual);
}
Expand Down Expand Up @@ -167,7 +167,7 @@ public async Task GetHistoryWorks()
using var server = new TestServer(builder);
var client = server.CreateClient();

var response = await client.GetFromJsonAsync<PeriodicTaskExecutionAttempt[]>("/periodic-tasks/registrations/dummy/history");
var response = await client.GetFromJsonAsync<PeriodicTaskExecutionAttempt[]>("/periodic-tasks/registrations/dummy/history", TestContext.Current.CancellationToken);
Assert.NotNull(response);
Assert.Empty(response);
}
Expand Down Expand Up @@ -203,13 +203,13 @@ public async Task ExecuteWorks()

var client = server.CreateClient();
var content = new StringContent("{\"name\":\"dummy\",\"wait\":true}", Encoding.UTF8, "application/json");
var response = await client.PostAsync("/periodic-tasks/execute", content);
var attempt = await response.Content.ReadFromJsonAsync<PeriodicTaskExecutionAttempt>();
var response = await client.PostAsync("/periodic-tasks/execute", content, TestContext.Current.CancellationToken);
var attempt = await response.Content.ReadFromJsonAsync<PeriodicTaskExecutionAttempt>(TestContext.Current.CancellationToken);
Assert.NotNull(attempt);
Assert.Equal("dummy", attempt.Name);
Assert.NotEqual(0, response.Content.Headers.ContentLength);

attempt = Assert.Single(await attemptsStore.GetAttemptsAsync());
attempt = Assert.Single(await attemptsStore.GetAttemptsAsync(cancellationToken: TestContext.Current.CancellationToken));
Assert.Equal("dummy", attempt.Name);
Assert.True(attempt.Successful);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task ConsumeAsyncWorks()
var publisher = provider.GetRequiredService<IEventPublisher>();
var harness = provider.GetRequiredService<InMemoryTestHarness>();

await harness.StartAsync();
await harness.StartAsync(TestContext.Current.CancellationToken);
try
{
var evt = new TriggerPeriodicTaskEvent
Expand All @@ -49,20 +49,20 @@ public async Task ConsumeAsyncWorks()
Wait = true,
};

await publisher.PublishAsync(evt);
await publisher.PublishAsync(evt, cancellationToken: TestContext.Current.CancellationToken);

Assert.Empty(await harness.FailedAsync(TimeSpan.FromSeconds(3)));
Assert.Empty(await harness.FailedAsync(TimeSpan.FromSeconds(3), TestContext.Current.CancellationToken));

var evt_ctx_con = Assert.IsType<EventContext<TriggerPeriodicTaskEvent>>(Assert.Single(harness.Consumed()));
Assert.Equal(evt.Name, evt_ctx_con.Event.Name);

var attempt = Assert.Single(await attemptsStore.GetAttemptsAsync());
var attempt = Assert.Single(await attemptsStore.GetAttemptsAsync(cancellationToken: TestContext.Current.CancellationToken));
Assert.Equal(evt.Name, attempt.Name);
Assert.True(attempt.Successful);
}
finally
{
await harness.StopAsync();
await harness.StopAsync(TestContext.Current.CancellationToken);
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Tingle.PeriodicTasks.Tests/CronScheduleTimerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public async Task CronScheduleTimer_Works()
Interlocked.Increment(ref invocations);
await t.StopAsync(ct);
});
await timer.StartAsync();
await Task.Delay(TimeSpan.FromSeconds(7));
await timer.StartAsync(TestContext.Current.CancellationToken);
await Task.Delay(TimeSpan.FromSeconds(7), TestContext.Current.CancellationToken);
Assert.Equal(1, invocations);
}
}

0 comments on commit a5be85c

Please sign in to comment.