diff --git a/src/Dependency.Versions.props b/src/Dependency.Versions.props index 41463d64..632a792d 100644 --- a/src/Dependency.Versions.props +++ b/src/Dependency.Versions.props @@ -1,6 +1,6 @@ - 2.4.1 + 1.1.0 1.0.1 12.0.2 diff --git a/src/ReactiveDomain.Foundation.Tests/ReactiveDomain.Foundation.Tests.csproj b/src/ReactiveDomain.Foundation.Tests/ReactiveDomain.Foundation.Tests.csproj index 376120fe..5998b0e0 100644 --- a/src/ReactiveDomain.Foundation.Tests/ReactiveDomain.Foundation.Tests.csproj +++ b/src/ReactiveDomain.Foundation.Tests/ReactiveDomain.Foundation.Tests.csproj @@ -3,6 +3,9 @@ $(TestTargetFrameworks) true + Exe + true + true @@ -15,16 +18,8 @@ - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + + diff --git a/src/ReactiveDomain.Foundation.Tests/StreamListenerTests/when_using_listener_start_with_future_stream.cs b/src/ReactiveDomain.Foundation.Tests/StreamListenerTests/when_using_listener_start_with_future_stream.cs index e92a24c4..7fddfe53 100644 --- a/src/ReactiveDomain.Foundation.Tests/StreamListenerTests/when_using_listener_start_with_future_stream.cs +++ b/src/ReactiveDomain.Foundation.Tests/StreamListenerTests/when_using_listener_start_with_future_stream.cs @@ -42,7 +42,7 @@ public void validation_throws_on_mising_stream() new PrefixedCamelCaseStreamNameBuilder(), _eventSerializer); listener.EventStream.Subscribe(new AdHocHandler(Handle)); - Assert.Throws(() => listener.Start(missingStream, validateStream: true)); + Assert.Throws(() => listener.Start(missingStream, validateStream: true, cancelWaitToken: TestContext.Current.CancellationToken)); listener.Dispose(); } [Fact] @@ -55,7 +55,7 @@ public void can_subscribe_to_missing_stream() new PrefixedCamelCaseStreamNameBuilder(), _eventSerializer); listener.EventStream.Subscribe(new AdHocHandler(Handle)); - listener.Start(missingStream, validateStream: false); + listener.Start(missingStream, validateStream: false, cancelWaitToken: TestContext.Current.CancellationToken); Assert.True(listener.IsLive); listener.Dispose(); } diff --git a/src/ReactiveDomain.Foundation.Tests/when_using_read_model_base.cs b/src/ReactiveDomain.Foundation.Tests/when_using_read_model_base.cs index 54e45d32..ba6973df 100644 --- a/src/ReactiveDomain.Foundation.Tests/when_using_read_model_base.cs +++ b/src/ReactiveDomain.Foundation.Tests/when_using_read_model_base.cs @@ -61,7 +61,7 @@ public void can_start_streams_by_aggregate() var aggId = Guid.NewGuid(); var s1 = Namer.GenerateForAggregate(typeof(TestAggregate), aggId); AppendEvents(1, _conn, s1, 7); - Start(aggId); + Start(aggId, cancelWaitToken: TestContext.Current.CancellationToken); AssertEx.AtLeastModelVersion(this, 2, msg: $"Expected 2 got {Version}"); // 1 message + CatchupSubscriptionBecameLive AssertEx.IsOrBecomesTrue(() => Sum == 7); } @@ -73,7 +73,7 @@ public void can_start_streams_by_aggregate_category() AppendEvents(1, _conn, s1, 7); var s2 = Namer.GenerateForAggregate(typeof(ReadModelTestCategoryAggregate), Guid.NewGuid()); AppendEvents(1, _conn, s2, 5); - Start(null, true); + Start(null, true, cancelWaitToken: TestContext.Current.CancellationToken); AssertEx.AtLeastModelVersion(this, 3, msg: $"Expected 3 got {Version}"); AssertEx.IsOrBecomesTrue(() => Sum == 12); @@ -81,7 +81,7 @@ public void can_start_streams_by_aggregate_category() [Fact] public void can_read_one_stream() { - Start(_stream1); + Start(_stream1, cancelWaitToken: TestContext.Current.CancellationToken); AssertEx.AtLeastModelVersion(this, 11, msg: $"Expected 11 got {Version}"); AssertEx.IsOrBecomesTrue(() => Sum == 20); //confirm checkpoints @@ -91,8 +91,8 @@ public void can_read_one_stream() [Fact] public void can_read_two_streams() { - Start(_stream1); - Start(_stream2); + Start(_stream1, cancelWaitToken: TestContext.Current.CancellationToken); + Start(_stream2, cancelWaitToken: TestContext.Current.CancellationToken); AssertEx.AtLeastModelVersion(this, 22, msg: $"Expected 22 got {Version}"); AssertEx.IsOrBecomesTrue(() => Sum == 50); //confirm checkpoints @@ -104,25 +104,25 @@ public void can_read_two_streams() [Fact] public void can_wait_for_one_stream_to_go_live() { - Start(_stream1, null, true); + Start(_stream1, null, true, cancelWaitToken: TestContext.Current.CancellationToken); AssertEx.AtLeastModelVersion(this, 11, TimeSpan.FromMilliseconds(100), msg: $"Expected 11 got {Version}"); AssertEx.IsOrBecomesTrue(() => Sum == 20, 100); } [Fact] public void can_wait_for_two_streams_to_go_live() { - Start(_stream1, null, true); + Start(_stream1, null, true, cancelWaitToken: TestContext.Current.CancellationToken); AssertEx.AtLeastModelVersion(this, 11, TimeSpan.FromMilliseconds(100), msg: $"Expected 11 got {Version}"); AssertEx.IsOrBecomesTrue(() => Sum == 20, 150); - Start(_stream2, null, true); + Start(_stream2, null, true, cancelWaitToken: TestContext.Current.CancellationToken); AssertEx.AtLeastModelVersion(this, 21, TimeSpan.FromMilliseconds(100), msg: $"Expected 21 got {Version}"); AssertEx.IsOrBecomesTrue(() => Sum == 50, 150); } [Fact] public void can_listen_to_one_stream() { - Start(_stream1); + Start(_stream1, cancelWaitToken: TestContext.Current.CancellationToken); AssertEx.AtLeastModelVersion(this, 11, msg: $"Expected 11 got {Version}"); AssertEx.IsOrBecomesTrue(() => Sum == 20); //add more messages @@ -137,8 +137,8 @@ public void can_listen_to_one_stream() [Fact] public void can_listen_to_two_streams() { - Start(_stream1); - Start(_stream2); + Start(_stream1, cancelWaitToken: TestContext.Current.CancellationToken); + Start(_stream2, cancelWaitToken: TestContext.Current.CancellationToken); AssertEx.AtLeastModelVersion(this, 22, msg: $"Expected 22 got {Version}"); AssertEx.IsOrBecomesTrue(() => Sum == 50); //add more messages @@ -159,7 +159,7 @@ public void can_use_checkpoint_on_one_stream() var checkPoint = 8L;//Zero based, ignore the first 9 events Sum = 18; //start at the checkpoint - Start(_stream1, checkPoint); + Start(_stream1, checkPoint, cancelWaitToken: TestContext.Current.CancellationToken); //add the one recorded event AssertEx.AtLeastModelVersion(this, 2, TimeSpan.FromMilliseconds(100), msg: $"Expected 2 got {Version}"); AssertEx.IsOrBecomesTrue(() => Sum == 20); @@ -180,8 +180,8 @@ public void can_use_checkpoint_on_two_streams() var checkPoint1 = 8L;//Zero based, ignore the first 9 events var checkPoint2 = 5L;//Zero based, ignore the first 6 events Sum = (9 * 2) + (6 * 3); - Start(_stream1, checkPoint1); - Start(_stream2, checkPoint2); + Start(_stream1, checkPoint1, cancelWaitToken: TestContext.Current.CancellationToken); + Start(_stream2, checkPoint2, cancelWaitToken: TestContext.Current.CancellationToken); //add the recorded events 2 on stream 1 & 5 on stream 2 AssertEx.AtLeastModelVersion(this, 7, msg: $"Expected 7 got {Version}"); AssertEx.IsOrBecomesTrue(() => Sum == 50, msg: $"Expected 50 got {Sum}"); @@ -202,8 +202,8 @@ public void can_listen_to_the_same_stream_twice() Assert.Equal(0, Version); //weird but true //n.b. Don't do this on purpose - Start(_stream1); - Start(_stream1); + Start(_stream1, cancelWaitToken: TestContext.Current.CancellationToken); + Start(_stream1, cancelWaitToken: TestContext.Current.CancellationToken); //double events AssertEx.AtLeastModelVersion(this, 22, msg: $"Expected 22 got {Version}"); AssertEx.IsOrBecomesTrue(() => Sum == 40); diff --git a/src/ReactiveDomain.Foundation.Tests/when_using_read_model_base_with_reader.cs b/src/ReactiveDomain.Foundation.Tests/when_using_read_model_base_with_reader.cs index f8a24e6c..3420ed48 100644 --- a/src/ReactiveDomain.Foundation.Tests/when_using_read_model_base_with_reader.cs +++ b/src/ReactiveDomain.Foundation.Tests/when_using_read_model_base_with_reader.cs @@ -60,7 +60,7 @@ public void can_start_streams_by_aggregate() var aggId = Guid.NewGuid(); var s1 = Namer.GenerateForAggregate(typeof(TestAggregate), aggId); AppendEvents(1, _conn, s1, 7); - Start(aggId); + Start(aggId, cancelWaitToken: TestContext.Current.CancellationToken); AssertEx.IsOrBecomesTrue(() => Count == 1, 1000, msg: $"Expected 1 got {Count}"); AssertEx.IsOrBecomesTrue(() => Sum == 7); } @@ -72,7 +72,7 @@ public void can_start_streams_by_aggregate_category() AppendEvents(1, _conn, s1, 7); var s2 = Namer.GenerateForAggregate(typeof(ReadModelTestCategoryAggregate), Guid.NewGuid()); AppendEvents(1, _conn, s2, 5); - Start(null, true); + Start(null, true, cancelWaitToken: TestContext.Current.CancellationToken); AssertEx.IsOrBecomesTrue(() => Count == 2, 1000, msg: $"Expected 2 got {Count}"); AssertEx.IsOrBecomesTrue(() => Sum == 12); @@ -80,7 +80,7 @@ public void can_start_streams_by_aggregate_category() [Fact] public void can_read_one_stream() { - Start(_stream1); + Start(_stream1, cancelWaitToken: TestContext.Current.CancellationToken); AssertEx.IsOrBecomesTrue(() => Count == 10, 1000, msg: $"Expected 10 got {Count}"); AssertEx.IsOrBecomesTrue(() => Sum == 20); //confirm checkpoints @@ -90,8 +90,8 @@ public void can_read_one_stream() [Fact] public void can_read_two_streams() { - Start(_stream1); - Start(_stream2); + Start(_stream1, cancelWaitToken: TestContext.Current.CancellationToken); + Start(_stream2, cancelWaitToken: TestContext.Current.CancellationToken); AssertEx.IsOrBecomesTrue(() => Count == 20, 1000, msg: $"Expected 20 got {Count}"); AssertEx.IsOrBecomesTrue(() => Sum == 50); //confirm checkpoints @@ -103,25 +103,25 @@ public void can_read_two_streams() [Fact] public void can_wait_for_one_stream_to_go_live() { - Start(_stream1, null, true); + Start(_stream1, null, true, cancelWaitToken: TestContext.Current.CancellationToken); AssertEx.IsOrBecomesTrue(() => Count == 10, 100, msg: $"Expected 10 got {Count}"); AssertEx.IsOrBecomesTrue(() => Sum == 20, 100); } [Fact] public void can_wait_for_two_streams_to_go_live() { - Start(_stream1, null, true); + Start(_stream1, null, true, cancelWaitToken: TestContext.Current.CancellationToken); AssertEx.IsOrBecomesTrue(() => Count == 10, 100, msg: $"Expected 10 got {Count}"); AssertEx.IsOrBecomesTrue(() => Sum == 20, 100); - Start(_stream2, null, true); + Start(_stream2, null, true, cancelWaitToken: TestContext.Current.CancellationToken); AssertEx.IsOrBecomesTrue(() => Count == 20, 100, msg: $"Expected 20 got {Count}"); AssertEx.IsOrBecomesTrue(() => Sum == 50, 100); } [Fact] public void can_listen_to_one_stream() { - Start(_stream1); + Start(_stream1, cancelWaitToken: TestContext.Current.CancellationToken); AssertEx.IsOrBecomesTrue(() => Count == 10, 1000, msg: $"Expected 10 got {Count}"); AssertEx.IsOrBecomesTrue(() => Sum == 20); //add more messages @@ -136,8 +136,8 @@ public void can_listen_to_one_stream() [Fact] public void can_listen_to_two_streams() { - Start(_stream1); - Start(_stream2); + Start(_stream1, cancelWaitToken: TestContext.Current.CancellationToken); + Start(_stream2, cancelWaitToken: TestContext.Current.CancellationToken); AssertEx.IsOrBecomesTrue(() => Count == 20, 1000, msg: $"Expected 20 got {Count}"); AssertEx.IsOrBecomesTrue(() => Sum == 50); //add more messages @@ -159,7 +159,7 @@ public void can_use_checkpoint_on_one_stream() Count = 9; Sum = 18; //start at the checkpoint - Start(_stream1, checkPoint); + Start(_stream1, checkPoint, cancelWaitToken: TestContext.Current.CancellationToken); //add the one recorded event AssertEx.IsOrBecomesTrue(() => Count == 10, 100, msg: $"Expected 10 got {Count}"); AssertEx.IsOrBecomesTrue(() => Sum == 20); @@ -179,8 +179,8 @@ public void can_use_checkpoint_on_two_streams() var checkPoint2 = 5L;//Zero based, ignore the first 6 events Count = (9) + (6); Sum = (9 * 2) + (6 * 3); - Start(_stream1, checkPoint1); - Start(_stream2, checkPoint2); + Start(_stream1, checkPoint1, cancelWaitToken: TestContext.Current.CancellationToken); + Start(_stream2, checkPoint2, cancelWaitToken: TestContext.Current.CancellationToken); //add the recorded events 2 on stream 1 & 5 on stream 2 AssertEx.IsOrBecomesTrue(() => Count == 20, 1000, msg: $"Expected 20 got {Count}"); AssertEx.IsOrBecomesTrue(() => Sum == 50, msg: $"Expected 50 got {Sum}"); @@ -201,8 +201,8 @@ public void can_listen_to_the_same_stream_twice() Assert.Equal(0, Count); //weird but true //n.b. Don't do this on purpose - Start(_stream1); - Start(_stream1); + Start(_stream1, cancelWaitToken: TestContext.Current.CancellationToken); + Start(_stream1, cancelWaitToken: TestContext.Current.CancellationToken); //double events AssertEx.IsOrBecomesTrue(() => Count == 20, 1000, msg: $"Expected 20 got {Count}"); AssertEx.IsOrBecomesTrue(() => Sum == 40); diff --git a/src/ReactiveDomain.Foundation.Tests/when_using_snapshot_read_model.cs b/src/ReactiveDomain.Foundation.Tests/when_using_snapshot_read_model.cs index 86e90bf2..e830180e 100644 --- a/src/ReactiveDomain.Foundation.Tests/when_using_snapshot_read_model.cs +++ b/src/ReactiveDomain.Foundation.Tests/when_using_snapshot_read_model.cs @@ -120,7 +120,7 @@ public void can_restore_state_without_checkpoints() { AssertEx.IsOrBecomesTrue(() => rm.Sum == 20); //can manually start - rm.Start(_aggId, 9, true); + rm.Start(_aggId, 9, true, cancelWaitToken: TestContext.Current.CancellationToken); AssertEx.IsOrBecomesTrue(() => rm.Count == 11, 1000); AssertEx.IsOrBecomesTrue(() => rm.Sum == 25); AppendEvents(1, _conn, _stream, 5); diff --git a/src/ReactiveDomain.IdentityStorage.Tests/ReactiveDomain.IdentityStorage.Tests.csproj b/src/ReactiveDomain.IdentityStorage.Tests/ReactiveDomain.IdentityStorage.Tests.csproj index f584fea7..f31b8903 100644 --- a/src/ReactiveDomain.IdentityStorage.Tests/ReactiveDomain.IdentityStorage.Tests.csproj +++ b/src/ReactiveDomain.IdentityStorage.Tests/ReactiveDomain.IdentityStorage.Tests.csproj @@ -2,20 +2,15 @@ $(TestTargetFrameworks) - true - + true + Exe + true + true + - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + + diff --git a/src/ReactiveDomain.Messaging.Tests/LaterServiceTests.cs b/src/ReactiveDomain.Messaging.Tests/LaterServiceTests.cs index 2964ae1f..11929062 100644 --- a/src/ReactiveDomain.Messaging.Tests/LaterServiceTests.cs +++ b/src/ReactiveDomain.Messaging.Tests/LaterServiceTests.cs @@ -120,7 +120,7 @@ public void DelayPublishLoadTest() { delay.Handle(new DelaySendEnvelope(timeSource, TimeSpan.FromMilliseconds(50), new TestMessage())); } timeSource.AdvanceTime(50); - cd.Wait(1000); + cd.Wait(1000, TestContext.Current.CancellationToken); } Assert.True(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - start <= 15000, $"elapsed {DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - start}"); } @@ -135,7 +135,7 @@ public void DelayPublishLoadTestSystemTime() { for (int i = 0; i < iterations; i++) { delay.Handle(new DelaySendEnvelope(TimeSource.System, TimeSpan.FromMilliseconds(50), new TestMessage())); } - cd.Wait(1000); + cd.Wait(1000, TestContext.Current.CancellationToken); } Assert.True(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - start <= 15000, $"elapsed {DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - start}"); } diff --git a/src/ReactiveDomain.Messaging.Tests/ReactiveDomain.Messaging.Tests.csproj b/src/ReactiveDomain.Messaging.Tests/ReactiveDomain.Messaging.Tests.csproj index 13d7a15f..31f71d39 100644 --- a/src/ReactiveDomain.Messaging.Tests/ReactiveDomain.Messaging.Tests.csproj +++ b/src/ReactiveDomain.Messaging.Tests/ReactiveDomain.Messaging.Tests.csproj @@ -3,6 +3,9 @@ $(TestTargetFrameworks) true + Exe + true + true @@ -10,16 +13,8 @@ - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + + diff --git a/src/ReactiveDomain.Messaging.Tests/when_sending_commands_via_single_queued_dispatcher.cs b/src/ReactiveDomain.Messaging.Tests/when_sending_commands_via_single_queued_dispatcher.cs index c03327a3..a48dfa34 100644 --- a/src/ReactiveDomain.Messaging.Tests/when_sending_commands_via_single_queued_dispatcher.cs +++ b/src/ReactiveDomain.Messaging.Tests/when_sending_commands_via_single_queued_dispatcher.cs @@ -31,7 +31,7 @@ public when_sending_commands_via_single_queued_dispatcher() { [Fact] public void send_cmd_msg_sequence_is_correct() { - var t1 = Task.Run(() => _dispatcher.Send(new TestCommands.Command1())); + var t1 = Task.Run(() => _dispatcher.Send(new TestCommands.Command1()), TestContext.Current.CancellationToken); AssertEx.EnsureRunning(t1); AssertEx.IsOrBecomesTrue(() => Interlocked.Read(ref _gotAck) == 1); Assert.True(_commandHandleStarted == 0); diff --git a/src/ReactiveDomain.Messaging.Tests/when_sending_remote_handled_commands.cs b/src/ReactiveDomain.Messaging.Tests/when_sending_remote_handled_commands.cs index aabde63f..6e7ca944 100644 --- a/src/ReactiveDomain.Messaging.Tests/when_sending_remote_handled_commands.cs +++ b/src/ReactiveDomain.Messaging.Tests/when_sending_remote_handled_commands.cs @@ -42,12 +42,12 @@ public void can_cancel_commands_from_either_bus() { { var ts1 = new CancellationTokenSource(); CommandResponse response1 = null; - var t1 = Task.Run(()=> Assert.False(_fixture.LocalBus.TrySend(new TestCommands.RemoteCancel(ts1.Token), out response1))); + var t1 = Task.Run(()=> Assert.False(_fixture.LocalBus.TrySend(new TestCommands.RemoteCancel(ts1.Token), out response1)), TestContext.Current.CancellationToken); ts1.Cancel(); var ts2 = new CancellationTokenSource(); CommandResponse response2 = null; - var t2 = Task.Run(() => Assert.False(_fixture.RemoteBus.TrySend(new TestCommands.RemoteCancel(ts2.Token), out response2))); + var t2 = Task.Run(() => Assert.False(_fixture.RemoteBus.TrySend(new TestCommands.RemoteCancel(ts2.Token), out response2)), TestContext.Current.CancellationToken); ts2.Cancel(); AssertEx.EnsureComplete(t1, t2); diff --git a/src/ReactiveDomain.Policy.Tests/ReactiveDomain.Policy.Tests.csproj b/src/ReactiveDomain.Policy.Tests/ReactiveDomain.Policy.Tests.csproj index 38d4c103..763ab12c 100644 --- a/src/ReactiveDomain.Policy.Tests/ReactiveDomain.Policy.Tests.csproj +++ b/src/ReactiveDomain.Policy.Tests/ReactiveDomain.Policy.Tests.csproj @@ -3,23 +3,18 @@ $(TestTargetFrameworks) true - + Exe + true + true + - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + + diff --git a/src/ReactiveDomain.PolicyStorage.Tests/ReactiveDomain.PolicyStorage.Tests.csproj b/src/ReactiveDomain.PolicyStorage.Tests/ReactiveDomain.PolicyStorage.Tests.csproj index fe9e312f..4f267ee7 100644 --- a/src/ReactiveDomain.PolicyStorage.Tests/ReactiveDomain.PolicyStorage.Tests.csproj +++ b/src/ReactiveDomain.PolicyStorage.Tests/ReactiveDomain.PolicyStorage.Tests.csproj @@ -4,6 +4,9 @@ $(TestTargetFrameworks) true ReactiveDomain.Policy.Tests + Exe + true + true @@ -15,16 +18,8 @@ - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + + diff --git a/src/ReactiveDomain.Testing/EventStore/StreamReaderTests.cs b/src/ReactiveDomain.Testing/EventStore/StreamReaderTests.cs index 5db13438..2e4bbe76 100644 --- a/src/ReactiveDomain.Testing/EventStore/StreamReaderTests.cs +++ b/src/ReactiveDomain.Testing/EventStore/StreamReaderTests.cs @@ -7,7 +7,6 @@ using System.Threading; using System.Threading.Tasks; using Xunit; -using Xunit.Abstractions; // ReSharper disable UnusedParameter.Local diff --git a/src/ReactiveDomain.Testing/ReactiveDomain.Testing.csproj b/src/ReactiveDomain.Testing/ReactiveDomain.Testing.csproj index 8ce6fd94..a8ceee8f 100644 --- a/src/ReactiveDomain.Testing/ReactiveDomain.Testing.csproj +++ b/src/ReactiveDomain.Testing/ReactiveDomain.Testing.csproj @@ -4,6 +4,9 @@ $(LibTargetFrameworks) True true + Exe + true + true @@ -11,16 +14,8 @@ - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + + diff --git a/src/ReactiveDomain.Testing/Specifications/TestQueueTests.cs b/src/ReactiveDomain.Testing/Specifications/TestQueueTests.cs index 09fd645a..f5f47d12 100644 --- a/src/ReactiveDomain.Testing/Specifications/TestQueueTests.cs +++ b/src/ReactiveDomain.Testing/Specifications/TestQueueTests.cs @@ -1,9 +1,6 @@ - - -using ReactiveDomain.Messaging; +using ReactiveDomain.Messaging; using ReactiveDomain.Messaging.Bus; using System; -using System.Threading; using System.Threading.Tasks; using Xunit; @@ -133,8 +130,8 @@ public void waiting_for_message_throws_on_clear() { using (var tq = new TestQueue(_dispatcher, new[] { typeof(Event), typeof(Command) })) { - Task.Run(() => Assert.Throws(() => tq.WaitFor(TimeSpan.FromMilliseconds(100)))) - .ContinueWith(t => tq.Clear()); + Task.Run(() => Assert.Throws(() => tq.WaitFor(TimeSpan.FromMilliseconds(100))), TestContext.Current.CancellationToken) + .ContinueWith(t => tq.Clear(), TestContext.Current.CancellationToken); tq.AssertEmpty(); } } @@ -143,8 +140,8 @@ public void waiting_for_id_throws_on_clear() { using (var tq = new TestQueue(_dispatcher, new[] { typeof(Event), typeof(Command) })) { - Task.Run(() => Assert.Throws(() => tq.WaitForMsgId(Guid.NewGuid(), TimeSpan.FromMilliseconds(100)))) - .ContinueWith(t => tq.Clear()); + Task.Run(() => Assert.Throws(() => tq.WaitForMsgId(Guid.NewGuid(), TimeSpan.FromMilliseconds(100))), TestContext.Current.CancellationToken) + .ContinueWith(t => tq.Clear(), TestContext.Current.CancellationToken); tq.AssertEmpty(); } } @@ -157,8 +154,8 @@ public void can_wait_for_a_specific_message() var evt = new TestEvent(); var evt2 = new TestEvent(); //before - var t1 = Task.Run(() => tq.WaitForMsgId(evt.MsgId, TimeSpan.FromMilliseconds(1000))); - var t2 = Task.Run(() => tq.WaitForMsgId(evt2.MsgId, TimeSpan.FromMilliseconds(1000))); + var t1 = Task.Run(() => tq.WaitForMsgId(evt.MsgId, TimeSpan.FromMilliseconds(1000)), TestContext.Current.CancellationToken); + var t2 = Task.Run(() => tq.WaitForMsgId(evt2.MsgId, TimeSpan.FromMilliseconds(1000)), TestContext.Current.CancellationToken); AssertEx.EnsureRunning(t1,t2); _dispatcher.Publish(evt); @@ -179,8 +176,8 @@ public void can_wait_for_a_specific_message_twice() using (var tq = new TestQueue(_dispatcher)) { var evt = new TestEvent(); - var t1 = Task.Run(() => tq.WaitForMsgId(evt.MsgId, TimeSpan.FromMilliseconds(1000))); - var t2 = Task.Run(() => tq.WaitForMsgId(evt.MsgId, TimeSpan.FromMilliseconds(1000))); + var t1 = Task.Run(() => tq.WaitForMsgId(evt.MsgId, TimeSpan.FromMilliseconds(1000)), TestContext.Current.CancellationToken); + var t2 = Task.Run(() => tq.WaitForMsgId(evt.MsgId, TimeSpan.FromMilliseconds(1000)), TestContext.Current.CancellationToken); tq.Handle(evt); tq.AssertNext(evt.CorrelationId) @@ -214,8 +211,8 @@ public void can_wait_for_multiple_messages_not_yet_received() var evt = new TestEvent(); var evt2 = new TestEvent(); - var t1 = Task.Run(() => tq.WaitForMsgId(evt.MsgId, TimeSpan.FromMilliseconds(200))); - var t2 = Task.Run(() => tq.WaitForMsgId(evt2.MsgId, TimeSpan.FromMilliseconds(200))); + var t1 = Task.Run(() => tq.WaitForMsgId(evt.MsgId, TimeSpan.FromMilliseconds(200)), TestContext.Current.CancellationToken); + var t2 = Task.Run(() => tq.WaitForMsgId(evt2.MsgId, TimeSpan.FromMilliseconds(200)), TestContext.Current.CancellationToken); _dispatcher.Publish(evt); _dispatcher.Publish(evt2); diff --git a/src/ReactiveDomain.Transport.Tests/ReactiveDomain.Transport.Tests.csproj b/src/ReactiveDomain.Transport.Tests/ReactiveDomain.Transport.Tests.csproj index a76cbf88..dd4ff901 100644 --- a/src/ReactiveDomain.Transport.Tests/ReactiveDomain.Transport.Tests.csproj +++ b/src/ReactiveDomain.Transport.Tests/ReactiveDomain.Transport.Tests.csproj @@ -3,18 +3,13 @@ $(TestTargetFrameworks) true + Exe + true + true - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + + diff --git a/src/ReactiveDomain.Transport.Tests/TcpBusClientSideTests.cs b/src/ReactiveDomain.Transport.Tests/TcpBusClientSideTests.cs index f7ee4db7..a282ddcb 100644 --- a/src/ReactiveDomain.Transport.Tests/TcpBusClientSideTests.cs +++ b/src/ReactiveDomain.Transport.Tests/TcpBusClientSideTests.cs @@ -1,15 +1,13 @@ -using System; +using Newtonsoft.Json; +using ReactiveDomain.Messaging; +using ReactiveDomain.Messaging.Bus; +using ReactiveDomain.Testing; +using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; -using System.Threading; using System.Threading.Tasks; -using Newtonsoft.Json; -using ReactiveDomain.Messaging; -using ReactiveDomain.Messaging.Bus; -using ReactiveDomain.Testing; -using ReactiveDomain.Transport.Serialization; using Xunit; namespace ReactiveDomain.Transport.Tests @@ -77,7 +75,7 @@ public TcpBusClientSideTests() } [Fact] - public void can_send_command() + public async Task can_send_command() { var handler = new WoftamCommandHandler(_longProp); _subscriptions.Add(_localBus.Subscribe(handler)); @@ -86,13 +84,12 @@ public void can_send_command() _tcpBusClientSide.Handle(MessageBuilder.New(() => new WoftamCommand(ShortProp))); // expect to receive it on the client side - var gotMessage = _tcs.Task.Wait(TimeSpan.FromMilliseconds(1000)); - Assert.True(gotMessage); - Assert.IsType(_tcs.Task.Result); + var result = await _tcs.Task.WaitAsync(TimeSpan.FromMilliseconds(1000), TestContext.Current.CancellationToken); + Assert.IsType(result); } [Fact] - public void can_handle_split_frames() // Also tests custom deserializer + public async Task can_handle_split_frames() // Also tests custom deserializer { var handler = new WoftamCommandHandler(_longProp) { ReturnCustomResponse = true }; _subscriptions.Add(_localBus.Subscribe(handler)); @@ -103,9 +100,8 @@ public void can_handle_split_frames() // Also tests custom deserializer _tcpBusClientSide.Handle(MessageBuilder.New(() => new WoftamCommand(ShortProp))); // expect to receive it on the client side - var gotMessage = _tcs.Task.Wait(TimeSpan.FromMilliseconds(1000)); - Assert.True(gotMessage); - var response = Assert.IsType(_tcs.Task.Result); + var result = await _tcs.Task.WaitAsync(TimeSpan.FromMilliseconds(1000), TestContext.Current.CancellationToken); + var response = Assert.IsType(result); Assert.Equal(_longProp, response.PropertyA); } diff --git a/src/ReactiveDomain.Transport.Tests/TcpBusServerSideTests.cs b/src/ReactiveDomain.Transport.Tests/TcpBusServerSideTests.cs index 645bad3e..58b99789 100644 --- a/src/ReactiveDomain.Transport.Tests/TcpBusServerSideTests.cs +++ b/src/ReactiveDomain.Transport.Tests/TcpBusServerSideTests.cs @@ -1,11 +1,10 @@ -using System; +using ReactiveDomain.Messaging; +using ReactiveDomain.Messaging.Bus; +using ReactiveDomain.Testing; +using System; using System.Linq; using System.Net; -using System.Threading; using System.Threading.Tasks; -using ReactiveDomain.Messaging; -using ReactiveDomain.Messaging.Bus; -using ReactiveDomain.Testing; using Xunit; namespace ReactiveDomain.Transport.Tests @@ -23,7 +22,7 @@ public class TcpBusServerSideTests private readonly TaskCompletionSource _tcs = new TaskCompletionSource(); [Fact] - public void can_handle_split_frames() + public async Task can_handle_split_frames() { // 16kb large enough to cause the transport to split up the frame. // it would be better if we did the splitting manually so we were sure it really happened. @@ -56,8 +55,7 @@ public void can_handle_split_frames() tcpBusClientSide.Handle(new WoftamEvent(prop1, prop2)); // expect to receive it in the server - var gotMessage = _tcs.Task.Wait(TimeSpan.FromMilliseconds(1000)); - Assert.True(gotMessage); + await _tcs.Task.WaitAsync(TimeSpan.FromMilliseconds(1000), TestContext.Current.CancellationToken); var evt = Assert.IsType(_tcs.Task.Result); Assert.Equal(prop1, evt.Property1); Assert.Equal(prop2, evt.Property2); @@ -67,7 +65,7 @@ public void can_handle_split_frames() } [Fact] - public void can_filter_out_message_types() + public async Task can_filter_out_message_types() { // server side var serverInbound = new QueuedHandler( @@ -94,8 +92,7 @@ public void can_filter_out_message_types() tcpBusClientSide.Handle(new WoftamCommand("abc")); // expect to receive it in the server but drop it on the floor - var gotMessage = _tcs.Task.Wait(TimeSpan.FromMilliseconds(1000)); - Assert.False(gotMessage); + _ = await Assert.ThrowsAsync(async () => await _tcs.Task.WaitAsync(TimeSpan.FromMilliseconds(1000), TestContext.Current.CancellationToken)); tcpBusClientSide.Dispose(); tcpBusServerSide.Dispose();