diff --git a/Directory.Build.props b/Directory.Build.props index d10a9719..b360fe6a 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -12,6 +12,7 @@ $(WarningsAsErrors),SYSLIB1045 $(WarningsAsErrors),IL2026,IL2060,IL2091,IL2095,IL3050 + $(WarningsAsErrors),xUnit1051 diff --git a/src/Tingle.EventBus/Transports/EventBusTransport.cs b/src/Tingle.EventBus/Transports/EventBusTransport.cs index d9ac22f5..c7ca7b57 100644 --- a/src/Tingle.EventBus/Transports/EventBusTransport.cs +++ b/src/Tingle.EventBus/Transports/EventBusTransport.cs @@ -364,7 +364,7 @@ protected async Task ConsumeAsync(IServiceScope scope, IDictionary? extras = null) { var state = new Dictionary(); - + var wrapped = state.ToEventBusWrapper() .AddIfNotDefault(MetadataNames.Id, id) .AddIfNotDefault(MetadataNames.CorrelationId, correlationId) diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props index 31d1f4ff..c220066c 100644 --- a/tests/Directory.Build.props +++ b/tests/Directory.Build.props @@ -12,10 +12,10 @@ - + - + diff --git a/tests/Tingle.EventBus.Transports.Azure.EventHubs.Tests/IotHubEventSerializerTests.cs b/tests/Tingle.EventBus.Transports.Azure.EventHubs.Tests/IotHubEventSerializerTests.cs index bd4853a3..89bf7819 100644 --- a/tests/Tingle.EventBus.Transports.Azure.EventHubs.Tests/IotHubEventSerializerTests.cs +++ b/tests/Tingle.EventBus.Transports.Azure.EventHubs.Tests/IotHubEventSerializerTests.cs @@ -9,7 +9,6 @@ using Tingle.EventBus.Configuration; using Tingle.EventBus.Serialization; using Tingle.EventBus.Transports.Azure.EventHubs.IotHub; -using Xunit.Abstractions; namespace Tingle.EventBus.Transports.Azure.EventHubs.Tests; @@ -44,8 +43,15 @@ await TestSerializerAsync(async (provider, _, serializer) => { var ereg = EventRegistration.Create(); var stream = TestSamples.GetIotHubTelemetry(); + +/* Unmerged change from project 'Tingle.EventBus.Transports.Azure.EventHubs.Tests(net9.0)' +Before: var (ed, ctx) = CreateData(ereg, await BinaryData.FromStreamAsync(stream), "Telemetry"); - var envelope = await serializer.DeserializeAsync(ctx); +After: + var (ed, ctx) = CreateData(ereg, await BinaryData.FromStreamAsync(stream, TestContext.Current.CancellationToken), "Telemetry"); +*/ + var (ed, ctx) = CreateData(ereg, await BinaryData.FromStreamAsync(stream, TestContext.Current.CancellationToken), "Telemetry"); + var envelope = await serializer.DeserializeAsync(ctx, TestContext.Current.CancellationToken); Assert.NotNull(envelope); Assert.NotNull(envelope.Event); Assert.Null(envelope.Event.Event); @@ -62,7 +68,14 @@ await TestSerializerAsync(async (provider, _, serializer) => { var ereg = EventRegistration.Create(); var stream = TestSamples.GetIotHubTwinChangeEvents(); + +/* Unmerged change from project 'Tingle.EventBus.Transports.Azure.EventHubs.Tests(net9.0)' +Before: var (ed, ctx) = CreateData(ereg, await BinaryData.FromStreamAsync(stream), "twinChangeEvents", new Dictionary +After: + var (ed, ctx) = CreateData(ereg, await BinaryData.FromStreamAsync(stream, TestContext.Current.CancellationToken), "twinChangeEvents", new Dictionary +*/ + var (ed, ctx) = CreateData(ereg, await BinaryData.FromStreamAsync(stream, TestContext.Current.CancellationToken), "twinChangeEvents", new Dictionary { ["hubName"] = HubName, ["deviceId"] = DeviceId, @@ -70,7 +83,7 @@ await TestSerializerAsync(async (provider, _, serializer) => ["operationTimestamp"] = "2022-01-16T16:36:53.8146535Z", ["iothub-message-schema"] = "twinChangeNotification", }); - var envelope = await serializer.DeserializeAsync(ctx); + var envelope = await serializer.DeserializeAsync(ctx, TestContext.Current.CancellationToken); Assert.NotNull(envelope); Assert.NotNull(envelope.Event); Assert.Null(envelope.Event.Telemetry); @@ -96,7 +109,14 @@ await TestSerializerAsync(async (provider, _, serializer) => { var ereg = EventRegistration.Create(); var stream = TestSamples.GetIotHubDeviceLifecycleEvents(); + +/* Unmerged change from project 'Tingle.EventBus.Transports.Azure.EventHubs.Tests(net9.0)' +Before: var (ed, ctx) = CreateData(ereg, await BinaryData.FromStreamAsync(stream), "deviceLifecycleEvents", new Dictionary +After: + var (ed, ctx) = CreateData(ereg, await BinaryData.FromStreamAsync(stream, TestContext.Current.CancellationToken), "deviceLifecycleEvents", new Dictionary +*/ + var (ed, ctx) = CreateData(ereg, await BinaryData.FromStreamAsync(stream, TestContext.Current.CancellationToken), "deviceLifecycleEvents", new Dictionary { ["hubName"] = HubName, ["deviceId"] = DeviceId, @@ -104,7 +124,7 @@ await TestSerializerAsync(async (provider, _, serializer) => ["operationTimestamp"] = "2022-01-16T16:36:53.8146535Z", ["iothub-message-schema"] = "deviceLifecycleNotification", }); - var envelope = await serializer.DeserializeAsync(ctx); + var envelope = await serializer.DeserializeAsync(ctx, TestContext.Current.CancellationToken); Assert.NotNull(envelope); Assert.NotNull(envelope.Event); Assert.Null(envelope.Event.Telemetry); @@ -129,15 +149,18 @@ await TestSerializerAsync(async (provider, _, serializer) => { var ereg = EventRegistration.Create(); var stream = TestSamples.GetIotHubDeviceConnectionStateEvents(); - var (ed, ctx) = CreateData(ereg, await BinaryData.FromStreamAsync(stream), "deviceConnectionStateEvents", new Dictionary - { - ["hubName"] = HubName, - ["deviceId"] = DeviceId, - ["opType"] = "deviceConnected", - ["operationTimestamp"] = "2022-01-16T16:36:53.8146535Z", - ["iothub-message-schema"] = "deviceConnectionStateNotification", - }); - var envelope = await serializer.DeserializeAsync(ctx); + var (ed, ctx) = CreateData(ereg, + await BinaryData.FromStreamAsync(stream, TestContext.Current.CancellationToken), + "deviceConnectionStateEvents", + new Dictionary + { + ["hubName"] = HubName, + ["deviceId"] = DeviceId, + ["opType"] = "deviceConnected", + ["operationTimestamp"] = "2022-01-16T16:36:53.8146535Z", + ["iothub-message-schema"] = "deviceConnectionStateNotification", + }); + var envelope = await serializer.DeserializeAsync(ctx, TestContext.Current.CancellationToken); Assert.NotNull(envelope); Assert.NotNull(envelope.Event); Assert.Null(envelope.Event.Telemetry); @@ -159,7 +182,8 @@ await TestSerializerAsync(async (provider, _, serializer) => { var ereg = EventRegistration.Create(); var ctx = new DeserializationContext(BinaryData.FromString(""), ereg, false); - var ex = await Assert.ThrowsAsync(() => serializer.DeserializeAsync(ctx)); + var ex = await Assert.ThrowsAsync( + () => serializer.DeserializeAsync(ctx, TestContext.Current.CancellationToken)); Assert.Equal("Only events that inherit from 'Tingle.EventBus.Transports.Azure.EventHubs.IotHub.IotHubEvent' are supported for deserialization.", ex.Message); }); } @@ -172,7 +196,7 @@ await TestSerializerAsync(async (provider, publisher, serializer) => var ereg = EventRegistration.Create(); var context = new EventContext(publisher, new()); var ctx = new SerializationContext(context, ereg); - var ex = await Assert.ThrowsAsync(() => serializer.SerializeAsync(ctx)); + var ex = await Assert.ThrowsAsync(() => serializer.SerializeAsync(ctx, TestContext.Current.CancellationToken)); Assert.Equal("Serialization of IotHub events is not allowed.", ex.Message); }); } diff --git a/tests/Tingle.EventBus.Transports.InMemory.Tests/SampleEventConsumerTests.cs b/tests/Tingle.EventBus.Transports.InMemory.Tests/SampleEventConsumerTests.cs index 36d0f6fe..ee874f2e 100644 --- a/tests/Tingle.EventBus.Transports.InMemory.Tests/SampleEventConsumerTests.cs +++ b/tests/Tingle.EventBus.Transports.InMemory.Tests/SampleEventConsumerTests.cs @@ -3,7 +3,6 @@ using Microsoft.Extensions.Logging; using SimpleConsumer; using Tingle.EventBus.Transports.InMemory; -using Xunit.Abstractions; namespace Tingle.EventBus.Tests.InMemory; @@ -30,7 +29,7 @@ public async Task ConsumerWorksAsync() var provider = host.Services; var harness = provider.GetRequiredService(); - await harness.StartAsync(); + await harness.StartAsync(TestContext.Current.CancellationToken); try { // Ensure we start at 0 for the counter @@ -45,13 +44,13 @@ await publisher.PublishAsync(new SampleEvent Registration = "1234567890", VIN = "5YJ3E1EA5KF328931", Year = 2021 - }); + }, cancellationToken: TestContext.Current.CancellationToken); // Ensure no faults were published by the consumer Assert.False(harness.Failed().Any()); // Ensure the message was consumed - Assert.NotEmpty(await harness.ConsumedAsync(TimeSpan.FromSeconds(0.5f))); + Assert.NotEmpty(await harness.ConsumedAsync(TimeSpan.FromSeconds(0.5f), TestContext.Current.CancellationToken)); // Now you can ensure data saved to database correctly @@ -60,7 +59,7 @@ await publisher.PublishAsync(new SampleEvent } finally { - await harness.StopAsync(); + await harness.StopAsync(TestContext.Current.CancellationToken); } } } diff --git a/tests/Tingle.EventBus.Transports.InMemory.Tests/SequenceNumberGeneratorTests.cs b/tests/Tingle.EventBus.Transports.InMemory.Tests/SequenceNumberGeneratorTests.cs index b9e5da6d..532aa6ac 100644 --- a/tests/Tingle.EventBus.Transports.InMemory.Tests/SequenceNumberGeneratorTests.cs +++ b/tests/Tingle.EventBus.Transports.InMemory.Tests/SequenceNumberGeneratorTests.cs @@ -9,7 +9,7 @@ public async Task Generate_Works() { var sng = new SequenceNumberGenerator(); var current = sng.Generate(); - await Task.Delay(TimeSpan.FromSeconds(1)); + await Task.Delay(TimeSpan.FromSeconds(1), TestContext.Current.CancellationToken); var next = sng.Generate(); Assert.Equal(1, next - current); } diff --git a/tests/Tingle.EventBus.Transports.InMemory.Tests/SimpleCancellationTests.cs b/tests/Tingle.EventBus.Transports.InMemory.Tests/SimpleCancellationTests.cs index 7de1f121..c647bfa4 100644 --- a/tests/Tingle.EventBus.Transports.InMemory.Tests/SimpleCancellationTests.cs +++ b/tests/Tingle.EventBus.Transports.InMemory.Tests/SimpleCancellationTests.cs @@ -22,7 +22,7 @@ public async Task EventIsPublishedOnBusAsync() var provider = host.Services; var harness = provider.GetRequiredService(); - await harness.StartAsync(); + await harness.StartAsync(TestContext.Current.CancellationToken); try { var publisher = provider.GetRequiredService(); @@ -34,7 +34,9 @@ public async Task EventIsPublishedOnBusAsync() VIN = "5YJ3E1EA5KF328931", Year = 2021, }; - var schedulingId = (string?)await publisher.PublishAsync(@event: evt, scheduled: DateTimeOffset.UtcNow.AddDays(1)); + var schedulingId = (string?)await publisher.PublishAsync(@event: evt, + scheduled: DateTimeOffset.UtcNow.AddDays(1), + cancellationToken: TestContext.Current.CancellationToken); Assert.NotNull(schedulingId); // Ensure no failures @@ -43,7 +45,7 @@ public async Task EventIsPublishedOnBusAsync() // Ensure only one was published Assert.Single(harness.Published()); - await publisher.CancelAsync(schedulingId); + await publisher.CancelAsync(schedulingId, TestContext.Current.CancellationToken); // Ensure only one was cancelled var sn = Assert.Single(harness.Cancelled()); @@ -51,7 +53,7 @@ public async Task EventIsPublishedOnBusAsync() } finally { - await harness.StopAsync(); + await harness.StopAsync(TestContext.Current.CancellationToken); } } diff --git a/tests/Tingle.EventBus.Transports.InMemory.Tests/SimplePublisherTests.cs b/tests/Tingle.EventBus.Transports.InMemory.Tests/SimplePublisherTests.cs index 2a479a35..9a10b68b 100644 --- a/tests/Tingle.EventBus.Transports.InMemory.Tests/SimplePublisherTests.cs +++ b/tests/Tingle.EventBus.Transports.InMemory.Tests/SimplePublisherTests.cs @@ -27,7 +27,7 @@ public async Task EventIsPublishedOnBusAsync(int orderNumber) var provider = host.Services; var harness = provider.GetRequiredService(); - await harness.StartAsync(); + await harness.StartAsync(TestContext.Current.CancellationToken); try { var orderProcessor = provider.GetRequiredService(); @@ -52,7 +52,7 @@ public async Task EventIsPublishedOnBusAsync(int orderNumber) } finally { - await harness.StopAsync(); + await harness.StopAsync(TestContext.Current.CancellationToken); } }