diff --git a/server/Tingle.Dependabot.Tests/PeriodicTasks/MissedTriggerCheckerTaskTests.cs b/server/Tingle.Dependabot.Tests/PeriodicTasks/MissedTriggerCheckerTaskTests.cs index afef3117..aff83e73 100644 --- a/server/Tingle.Dependabot.Tests/PeriodicTasks/MissedTriggerCheckerTaskTests.cs +++ b/server/Tingle.Dependabot.Tests/PeriodicTasks/MissedTriggerCheckerTaskTests.cs @@ -10,7 +10,6 @@ using Tingle.EventBus; using Tingle.EventBus.Transports.InMemory; using Xunit; -using Xunit.Abstractions; namespace Tingle.Dependabot.Tests.PeriodicTasks; @@ -28,10 +27,11 @@ public async Task CheckAsync_MissedScheduleIsDetected() var lastUpdate1 = DateTimeOffset.Parse("2023-01-23T03:30:00+00:00"); await TestAsync(lastUpdate0, lastUpdate1, async (harness, context, pt) => { - await pt.CheckAsync(referencePoint); + await pt.CheckAsync(referencePoint, TestContext.Current.CancellationToken); // Ensure the message was published - var evt_context = Assert.IsType>(Assert.Single(await harness.PublishedAsync())); + var evt_context = Assert.IsType>( + Assert.Single(await harness.PublishedAsync(cancellationToken: TestContext.Current.CancellationToken))); var inner = evt_context.Event; Assert.NotNull(inner); Assert.Equal(RepositoryId, inner.RepositoryId); @@ -48,10 +48,11 @@ public async Task CheckAsync_MissedScheduleIsDetected_NotRun_Before() var lastUpdate1 = (DateTimeOffset?)null; await TestAsync(lastUpdate0, lastUpdate1, async (harness, context, pt) => { - await pt.CheckAsync(referencePoint); + await pt.CheckAsync(referencePoint, TestContext.Current.CancellationToken); // Ensure the message was published - var evt_context = Assert.IsType>(Assert.Single(await harness.PublishedAsync())); + var evt_context = Assert.IsType>( + Assert.Single(await harness.PublishedAsync(cancellationToken: TestContext.Current.CancellationToken))); var inner = evt_context.Event; Assert.NotNull(inner); Assert.Equal(RepositoryId, inner.RepositoryId); @@ -68,10 +69,10 @@ public async Task CheckAsync_NoMissedSchedule() var lastUpdate1 = DateTimeOffset.Parse("2023-01-24T03:30:00+00:00"); await TestAsync(lastUpdate0, lastUpdate1, async (harness, context, pt) => { - await pt.CheckAsync(referencePoint); + await pt.CheckAsync(referencePoint, TestContext.Current.CancellationToken); // Ensure nothing was published - Assert.Empty(await harness.PublishedAsync()); + Assert.Empty(await harness.PublishedAsync(cancellationToken: TestContext.Current.CancellationToken)); }); } diff --git a/server/Tingle.Dependabot.Tests/PeriodicTasks/SynchronizationTaskTests.cs b/server/Tingle.Dependabot.Tests/PeriodicTasks/SynchronizationTaskTests.cs index 80142328..956eb77c 100644 --- a/server/Tingle.Dependabot.Tests/PeriodicTasks/SynchronizationTaskTests.cs +++ b/server/Tingle.Dependabot.Tests/PeriodicTasks/SynchronizationTaskTests.cs @@ -9,7 +9,6 @@ using Tingle.EventBus; using Tingle.EventBus.Transports.InMemory; using Xunit; -using Xunit.Abstractions; namespace Tingle.Dependabot.Tests.PeriodicTasks; @@ -22,10 +21,11 @@ public async Task SynchronizationInnerAsync_Works() { await TestAsync(async (harness, pt) => { - await pt.SyncAsync(); + await pt.SyncAsync(TestContext.Current.CancellationToken); // Ensure the message was published - var evt_context = Assert.IsType>(Assert.Single(await harness.PublishedAsync())); + var evt_context = Assert.IsType>( + Assert.Single(await harness.PublishedAsync(cancellationToken: TestContext.Current.CancellationToken))); var inner = evt_context.Event; Assert.NotNull(inner); Assert.Null(inner.RepositoryId); diff --git a/server/Tingle.Dependabot.Tests/PeriodicTasks/UpdateJobsCleanerTaskTests.cs b/server/Tingle.Dependabot.Tests/PeriodicTasks/UpdateJobsCleanerTaskTests.cs index 3065a5a8..7dce037c 100644 --- a/server/Tingle.Dependabot.Tests/PeriodicTasks/UpdateJobsCleanerTaskTests.cs +++ b/server/Tingle.Dependabot.Tests/PeriodicTasks/UpdateJobsCleanerTaskTests.cs @@ -10,7 +10,6 @@ using Tingle.EventBus; using Tingle.EventBus.Transports.InMemory; using Xunit; -using Xunit.Abstractions; namespace Tingle.Dependabot.Tests.PeriodicTasks; @@ -38,7 +37,7 @@ await context.UpdateJobs.AddAsync(new UpdateJob Resources = new(0.25, 0.2), AuthKey = Guid.NewGuid().ToString("n"), Status = UpdateJobStatus.Succeeded, - }); + }, TestContext.Current.CancellationToken); await context.UpdateJobs.AddAsync(new UpdateJob { Id = Guid.NewGuid().ToString(), @@ -52,7 +51,7 @@ await context.UpdateJobs.AddAsync(new UpdateJob Resources = new(0.25, 0.2), AuthKey = Guid.NewGuid().ToString("n"), Status = UpdateJobStatus.Succeeded, - }); + }, TestContext.Current.CancellationToken); await context.UpdateJobs.AddAsync(new UpdateJob { Id = targetId, @@ -66,13 +65,14 @@ await context.UpdateJobs.AddAsync(new UpdateJob Resources = new(0.25, 0.2), AuthKey = Guid.NewGuid().ToString("n"), Status = UpdateJobStatus.Running, - }); - await context.SaveChangesAsync(); + }, TestContext.Current.CancellationToken); + await context.SaveChangesAsync(TestContext.Current.CancellationToken); - await pt.CleanupAsync(); + await pt.CleanupAsync(TestContext.Current.CancellationToken); // Ensure the message was published - var evt_context = Assert.IsType>(Assert.Single(await harness.PublishedAsync())); + var evt_context = Assert.IsType>( + Assert.Single(await harness.PublishedAsync(cancellationToken: TestContext.Current.CancellationToken))); var inner = evt_context.Event; Assert.NotNull(inner); Assert.Equal(targetId, inner.JobId); @@ -96,7 +96,7 @@ await context.UpdateJobs.AddAsync(new UpdateJob Directories = null, Resources = new(0.25, 0.2), AuthKey = Guid.NewGuid().ToString("n"), - }); + }, TestContext.Current.CancellationToken); await context.UpdateJobs.AddAsync(new UpdateJob { Id = Guid.NewGuid().ToString(), @@ -109,7 +109,7 @@ await context.UpdateJobs.AddAsync(new UpdateJob Directories = null, Resources = new(0.25, 0.2), AuthKey = Guid.NewGuid().ToString("n"), - }); + }, TestContext.Current.CancellationToken); await context.UpdateJobs.AddAsync(new UpdateJob { Id = Guid.NewGuid().ToString(), @@ -122,11 +122,11 @@ await context.UpdateJobs.AddAsync(new UpdateJob Directories = ["**/*"], Resources = new(0.25, 0.2), AuthKey = Guid.NewGuid().ToString("n"), - }); - await context.SaveChangesAsync(); + }, TestContext.Current.CancellationToken); + await context.SaveChangesAsync(TestContext.Current.CancellationToken); - await pt.CleanupAsync(); - Assert.Equal(1, await context.UpdateJobs.CountAsync()); + await pt.CleanupAsync(TestContext.Current.CancellationToken); + Assert.Equal(1, await context.UpdateJobs.CountAsync(TestContext.Current.CancellationToken)); }); } diff --git a/server/Tingle.Dependabot.Tests/Tingle.Dependabot.Tests.csproj b/server/Tingle.Dependabot.Tests/Tingle.Dependabot.Tests.csproj index 9f46eb61..6383c633 100644 --- a/server/Tingle.Dependabot.Tests/Tingle.Dependabot.Tests.csproj +++ b/server/Tingle.Dependabot.Tests/Tingle.Dependabot.Tests.csproj @@ -11,12 +11,12 @@ - + - - + + diff --git a/server/Tingle.Dependabot.Tests/WebhooksControllerIntegrationTests.cs b/server/Tingle.Dependabot.Tests/WebhooksControllerIntegrationTests.cs index 000a0935..4c8ea633 100644 --- a/server/Tingle.Dependabot.Tests/WebhooksControllerIntegrationTests.cs +++ b/server/Tingle.Dependabot.Tests/WebhooksControllerIntegrationTests.cs @@ -13,7 +13,6 @@ using Tingle.EventBus; using Tingle.EventBus.Transports.InMemory; using Xunit; -using Xunit.Abstractions; namespace Tingle.Dependabot.Tests; @@ -28,18 +27,18 @@ await TestAsync(async (harness, client) => { // without Authorization header var request = new HttpRequestMessage(HttpMethod.Post, "/webhooks/azure"); - var response = await client.SendAsync(request); + var response = await client.SendAsync(request, TestContext.Current.CancellationToken); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); - Assert.Empty(await response.Content.ReadAsStringAsync()); - Assert.Empty(await harness.PublishedAsync()); + Assert.Empty(await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken)); + Assert.Empty(await harness.PublishedAsync(cancellationToken: TestContext.Current.CancellationToken)); // password does not match what is on record request = new HttpRequestMessage(HttpMethod.Post, "/webhooks/azure"); request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes($"{ProjectId}:burp-bump5"))); - response = await client.SendAsync(request); + response = await client.SendAsync(request, TestContext.Current.CancellationToken); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); - Assert.Empty(await response.Content.ReadAsStringAsync()); - Assert.Empty(await harness.PublishedAsync()); + Assert.Empty(await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken)); + Assert.Empty(await harness.PublishedAsync(cancellationToken: TestContext.Current.CancellationToken)); }); } @@ -51,14 +50,14 @@ await TestAsync(async (harness, client) => var request = new HttpRequestMessage(HttpMethod.Post, "/webhooks/azure"); request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes($"{ProjectId}:burp-bump"))); request.Content = new StringContent("", Encoding.UTF8, "application/json"); - var response = await client.SendAsync(request); + var response = await client.SendAsync(request, TestContext.Current.CancellationToken); Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); - var body = await response.Content.ReadAsStringAsync(); + var body = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken); Assert.Contains("\"type\":\"https://tools.ietf.org/html/rfc9110#section-15.5.1\"", body); Assert.Contains("\"title\":\"One or more validation errors occurred.\"", body); Assert.Contains("\"status\":400", body); Assert.Contains("\"errors\":{\"\":[\"A non-empty request body is required.\"],\"model\":[\"The model field is required.\"]}", body); - Assert.Empty(await harness.PublishedAsync()); + Assert.Empty(await harness.PublishedAsync(cancellationToken: TestContext.Current.CancellationToken)); }); } @@ -70,16 +69,16 @@ await TestAsync(async (harness, client) => var request = new HttpRequestMessage(HttpMethod.Post, "/webhooks/azure"); request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes($"{ProjectId}:burp-bump"))); request.Content = new StringContent("{}", Encoding.UTF8, "application/json"); - var response = await client.SendAsync(request); + var response = await client.SendAsync(request, TestContext.Current.CancellationToken); Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); - var body = await response.Content.ReadAsStringAsync(); + var body = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken); Assert.Contains("\"type\":\"https://tools.ietf.org/html/rfc9110#section-15.5.1\"", body); Assert.Contains("\"title\":\"One or more validation errors occurred.\"", body); Assert.Contains("\"status\":400", body); Assert.Contains("\"SubscriptionId\":[\"The SubscriptionId field is required.\"]", body); Assert.Contains("\"EventType\":[\"The EventType field is required.\"]", body); Assert.Contains("\"Resource\":[\"The Resource field is required.\"]", body); - Assert.Empty(await harness.PublishedAsync()); + Assert.Empty(await harness.PublishedAsync(cancellationToken: TestContext.Current.CancellationToken)); }); } @@ -92,13 +91,13 @@ await TestAsync(async (harness, client) => var request = new HttpRequestMessage(HttpMethod.Post, "/webhooks/azure"); request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes($"{ProjectId}:burp-bump"))); request.Content = new StreamContent(stream); - var response = await client.SendAsync(request); + var response = await client.SendAsync(request, TestContext.Current.CancellationToken); Assert.Equal(HttpStatusCode.UnsupportedMediaType, response.StatusCode); - var body = await response.Content.ReadAsStringAsync(); + var body = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken); Assert.Contains("\"type\":\"https://tools.ietf.org/html/rfc9110#section-15.5.16\"", body); Assert.Contains("\"title\":\"Unsupported Media Type\"", body); Assert.Contains("\"status\":415", body); - Assert.Empty(await harness.PublishedAsync()); + Assert.Empty(await harness.PublishedAsync(cancellationToken: TestContext.Current.CancellationToken)); }); } @@ -112,12 +111,13 @@ await TestAsync(async (harness, client) => request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes($"{ProjectId}:burp-bump"))); request.Content = new StreamContent(stream); request.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json", "utf-8"); - var response = await client.SendAsync(request); + var response = await client.SendAsync(request, TestContext.Current.CancellationToken); Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.Empty(await response.Content.ReadAsStringAsync()); + Assert.Empty(await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken)); // Ensure the message was published - var context = Assert.IsType>(Assert.Single(await harness.PublishedAsync(TimeSpan.FromSeconds(1f)))); + var context = Assert.IsType>( + Assert.Single(await harness.PublishedAsync(TimeSpan.FromSeconds(1f), TestContext.Current.CancellationToken))); var inner = context.Event; Assert.NotNull(inner); Assert.Null(inner.RepositoryId); @@ -136,10 +136,10 @@ await TestAsync(async (harness, client) => request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes($"{ProjectId}:burp-bump"))); request.Content = new StreamContent(stream); request.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json", "utf-8"); - var response = await client.SendAsync(request); + var response = await client.SendAsync(request, TestContext.Current.CancellationToken); Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.Empty(await response.Content.ReadAsStringAsync()); - Assert.Empty(await harness.PublishedAsync()); + Assert.Empty(await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken)); + Assert.Empty(await harness.PublishedAsync(cancellationToken: TestContext.Current.CancellationToken)); }); } @@ -153,10 +153,10 @@ await TestAsync(async (harness, client) => request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes($"{ProjectId}:burp-bump"))); request.Content = new StreamContent(stream); request.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json", "utf-8"); - var response = await client.SendAsync(request); + var response = await client.SendAsync(request, TestContext.Current.CancellationToken); Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.Empty(await response.Content.ReadAsStringAsync()); - Assert.Empty(await harness.PublishedAsync()); + Assert.Empty(await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken)); + Assert.Empty(await harness.PublishedAsync(cancellationToken: TestContext.Current.CancellationToken)); }); } @@ -170,10 +170,10 @@ await TestAsync(async (harness, client) => request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes($"{ProjectId}:burp-bump"))); request.Content = new StreamContent(stream); request.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json", "utf-8"); - var response = await client.SendAsync(request); + var response = await client.SendAsync(request, TestContext.Current.CancellationToken); Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.Empty(await response.Content.ReadAsStringAsync()); - Assert.Empty(await harness.PublishedAsync()); + Assert.Empty(await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken)); + Assert.Empty(await harness.PublishedAsync(cancellationToken: TestContext.Current.CancellationToken)); }); }