Skip to content

Commit 97095d4

Browse files
committed
Update to xunit v3
1 parent 6903901 commit 97095d4

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

Tingle.AzureCleaner.Tests/AzureCleanerTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ public async Task HandleAsync_Works()
103103

104104
await cleaner.HandleAsync(prId: 1,
105105
remoteUrl: "https://dev.azure.com/fabrikam/DefaultCollection/_git/Fabrikam",
106-
rawProjectUrl: "https://dev.azure.com/fabrikam/DefaultCollection/_apis/projects/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c");
106+
rawProjectUrl: "https://dev.azure.com/fabrikam/DefaultCollection/_apis/projects/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
107+
cancellationToken: TestContext.Current.CancellationToken);
107108
var possibleNames1 = Assert.Single(cleaner.DeleteAzureResourcesAsyncCalls);
108109
Assert.Equal(["review-app-1", "ra-1", "ra1"], possibleNames1);
109110
var (url, token, possibleNames2) = Assert.Single(cleaner.DeleteReviewAppsEnvironmentsAsyncCalls);

Tingle.AzureCleaner.Tests/EndpointTests.cs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
using Tingle.EventBus;
1313
using Tingle.EventBus.Transports.InMemory;
1414
using Xunit;
15-
using Xunit.Abstractions;
1615

1716
namespace Tingle.AzureCleaner.Tests;
1817

@@ -25,18 +24,18 @@ await TestAsync(async (harness, client) =>
2524
{
2625
// without Authorization header
2726
var request = new HttpRequestMessage(HttpMethod.Post, "/webhooks/azure");
28-
var response = await client.SendAsync(request);
27+
var response = await client.SendAsync(request, TestContext.Current.CancellationToken);
2928
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
30-
Assert.Empty(await response.Content.ReadAsStringAsync());
31-
Assert.Empty(await harness.PublishedAsync()); // Ensure no event was published
29+
Assert.Empty(await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken));
30+
Assert.Empty(await harness.PublishedAsync(cancellationToken: TestContext.Current.CancellationToken)); // Ensure no event was published
3231

3332
// with wrong value for Authorization header
3433
request = new HttpRequestMessage(HttpMethod.Post, "/webhooks/azure");
3534
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes("vsts:burp-bump5")));
36-
response = await client.SendAsync(request);
35+
response = await client.SendAsync(request, TestContext.Current.CancellationToken);
3736
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
38-
Assert.Empty(await response.Content.ReadAsStringAsync());
39-
Assert.Empty(await harness.PublishedAsync()); // Ensure no event was published
37+
Assert.Empty(await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken));
38+
Assert.Empty(await harness.PublishedAsync(cancellationToken: TestContext.Current.CancellationToken)); // Ensure no event was published
4039
});
4140
}
4241

@@ -47,10 +46,10 @@ await TestAsync(async (harness, client) =>
4746
{
4847
var request = new HttpRequestMessage(HttpMethod.Post, "/webhooks/azure");
4948
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes("vsts:burp-bump")));
50-
var response = await client.SendAsync(request);
49+
var response = await client.SendAsync(request, TestContext.Current.CancellationToken);
5150
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
52-
Assert.Empty(await response.Content.ReadAsStringAsync());
53-
Assert.Empty(await harness.PublishedAsync()); // Ensure no event was published
51+
Assert.Empty(await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken));
52+
Assert.Empty(await harness.PublishedAsync(cancellationToken: TestContext.Current.CancellationToken)); // Ensure no event was published
5453
});
5554
}
5655

@@ -62,16 +61,16 @@ await TestAsync(async (harness, client) =>
6261
var request = new HttpRequestMessage(HttpMethod.Post, "/webhooks/azure");
6362
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes("vsts:burp-bump")));
6463
request.Content = new StringContent("{}", Encoding.UTF8, "application/json");
65-
var response = await client.SendAsync(request);
64+
var response = await client.SendAsync(request, TestContext.Current.CancellationToken);
6665
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
67-
var body = await response.Content.ReadAsStringAsync();
66+
var body = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken);
6867
Assert.Contains("\"type\":\"https://tools.ietf.org/html/rfc9110#section-15.5.1\"", body);
6968
Assert.Contains("\"title\":\"One or more validation errors occurred.\"", body);
7069
Assert.Contains("\"status\":400", body);
7170
Assert.Contains("\"SubscriptionId\":[\"The SubscriptionId field is required.\"]", body);
7271
Assert.Contains("\"EventType\":[\"The EventType field is required.\"]", body);
7372
Assert.Contains("\"Resource\":[\"The Resource field is required.\"]", body);
74-
Assert.Empty(await harness.PublishedAsync()); // Ensure no event was published
73+
Assert.Empty(await harness.PublishedAsync(cancellationToken: TestContext.Current.CancellationToken)); // Ensure no event was published
7574
});
7675
}
7776

@@ -84,10 +83,10 @@ await TestAsync(async (harness, client) =>
8483
var request = new HttpRequestMessage(HttpMethod.Post, "/webhooks/azure");
8584
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes("vsts:burp-bump")));
8685
request.Content = new StreamContent(stream);
87-
var response = await client.SendAsync(request);
86+
var response = await client.SendAsync(request, TestContext.Current.CancellationToken);
8887
Assert.Equal(HttpStatusCode.UnsupportedMediaType, response.StatusCode);
89-
Assert.Empty(await response.Content.ReadAsStringAsync());
90-
Assert.Empty(await harness.PublishedAsync()); // Ensure no event was published
88+
Assert.Empty(await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken));
89+
Assert.Empty(await harness.PublishedAsync(cancellationToken: TestContext.Current.CancellationToken)); // Ensure no event was published
9190
});
9291
}
9392

@@ -101,15 +100,15 @@ await TestAsync(async (harness, client) =>
101100
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes("vsts:burp-bump")));
102101
request.Content = new StreamContent(stream);
103102
request.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json", "utf-8");
104-
var response = await client.SendAsync(request);
103+
var response = await client.SendAsync(request, TestContext.Current.CancellationToken);
105104
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
106105

107106
// Ensure event was published
108-
var evt_ctx = Assert.IsType<EventContext<AzdoCleanupEvent>>(Assert.Single(await harness.PublishedAsync()));
107+
var evt_ctx = Assert.IsType<EventContext<AzdoCleanupEvent>>(Assert.Single(await harness.PublishedAsync(cancellationToken: TestContext.Current.CancellationToken)));
109108
Assert.Equal(1, evt_ctx.Event.PullRequestId);
110109
Assert.Equal("https://dev.azure.com/fabrikam/DefaultCollection/_git/Fabrikam", evt_ctx.Event.RemoteUrl);
111110
Assert.Equal("https://dev.azure.com/fabrikam/DefaultCollection/_apis/projects/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c", evt_ctx.Event.RawProjectUrl);
112-
Assert.Empty(await response.Content.ReadAsStringAsync());
111+
Assert.Empty(await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken));
113112
});
114113
}
115114

@@ -154,7 +153,7 @@ private async Task TestAsync(Func<InMemoryTestHarness, HttpClient, Task> logic)
154153

155154
using var scope = server.Services.CreateScope();
156155
var provider = scope.ServiceProvider;
157-
156+
158157
var client = server.CreateClient();
159158

160159
var harness = provider.GetRequiredService<InMemoryTestHarness>();

Tingle.AzureCleaner.Tests/TestSamples.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ internal class TestSamples
44
{
55
public static class AzureDevOps
66
{
7-
public static Stream GetResourceAsStream(string resourceName)
7+
public static Stream GetResourceAsStream(string resourceName)
88
=> typeof(TestSamples).Assembly.GetManifestResourceStream($"{typeof(TestSamples).Namespace}.Samples.{resourceName}")!;
99

1010
public static Stream GetPullRequestUpdated() => GetResourceAsStream("git.pullrequest.updated.json");

Tingle.AzureCleaner.Tests/Tingle.AzureCleaner.Tests.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
</ItemGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="MartinCostello.Logging.XUnit" Version="0.4.0" />
13+
<PackageReference Include="MartinCostello.Logging.XUnit.v3" Version="0.5.0" />
1414
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="8.0.11" />
1515
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
16-
<PackageReference Include="xunit" Version="2.9.2" />
17-
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" PrivateAssets="All" />
16+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0" PrivateAssets="All" />
17+
<PackageReference Include="xunit.v3" Version="1.0.0" />
1818
<PackageReference Include="coverlet.collector" Version="6.0.2" PrivateAssets="All" />
1919
</ItemGroup>
2020

0 commit comments

Comments
 (0)