diff --git a/src/Bottles.Docs/snippets/Bottles.Tests/Services/Remote/BigRemoteServicesIntegrationTester.cs b/src/Bottles.Docs/snippets/Bottles.Tests/Services/Remote/BigRemoteServicesIntegrationTester.cs index a55bc34..14d9fc0 100644 --- a/src/Bottles.Docs/snippets/Bottles.Tests/Services/Remote/BigRemoteServicesIntegrationTester.cs +++ b/src/Bottles.Docs/snippets/Bottles.Tests/Services/Remote/BigRemoteServicesIntegrationTester.cs @@ -207,6 +207,28 @@ public void coordinate_message_history_via_remote_service() } } + [Test] + public void coordinate_message_history_via_remote_service_and_clear_data_does_not_remove_listeners() + { + + using (var runner = RemoteServiceRunner.For()) + { + runner.WaitForServiceToStart(); + runner.WaitForServiceToStart(); + + MessageHistory.StartListening(runner); + MessageHistory.ClearHistory(); + + var foo = new Foo(); + + EventAggregator.SentMessage(foo); + + + EventAggregator.Messaging.WaitForMessage(() => runner.SendRemotely(foo)) + .ShouldNotBeNull(); + } + } + [Test] public void spin_up_the_remote_service_for_the_sample_and_send_messages_back_and_forth() { diff --git a/src/Bottles.Tests/Services/Messaging/Tracking/MessageHistoryTester.cs b/src/Bottles.Tests/Services/Messaging/Tracking/MessageHistoryTester.cs index 36a2a34..be8eef8 100644 --- a/src/Bottles.Tests/Services/Messaging/Tracking/MessageHistoryTester.cs +++ b/src/Bottles.Tests/Services/Messaging/Tracking/MessageHistoryTester.cs @@ -164,6 +164,28 @@ public void sends_the_all_clear_message_when_it_gets_everything() MessageHistory.Record(MessageTrack.ForReceived(foo3)); assertAllCompleteMessage(); } + + [Test] + public void clear_history_removes_all() + { + var foo1 = new Foo(); + var foo2 = new Foo(); + var foo3 = new Foo(); + + MessageHistory.Record(MessageTrack.ForReceived(foo1)); + MessageHistory.Record(MessageTrack.ForReceived(foo2)); + MessageHistory.Record(MessageTrack.ForReceived(foo3)); + + MessageHistory.Record(MessageTrack.ForSent(foo1)); + MessageHistory.Record(MessageTrack.ForSent(foo2)); + MessageHistory.Record(MessageTrack.ForSent(foo3)); + + MessageHistory.ClearHistory(); + + MessageHistory.Outstanding().Any().ShouldBeFalse(); + MessageHistory.Received().Any().ShouldBeFalse(); + MessageHistory.All().Any().ShouldBeFalse(); + } } public class Foo diff --git a/src/Bottles.Tests/Services/Remote/BigRemoteServicesIntegrationTester.cs b/src/Bottles.Tests/Services/Remote/BigRemoteServicesIntegrationTester.cs index a55bc34..14d9fc0 100644 --- a/src/Bottles.Tests/Services/Remote/BigRemoteServicesIntegrationTester.cs +++ b/src/Bottles.Tests/Services/Remote/BigRemoteServicesIntegrationTester.cs @@ -207,6 +207,28 @@ public void coordinate_message_history_via_remote_service() } } + [Test] + public void coordinate_message_history_via_remote_service_and_clear_data_does_not_remove_listeners() + { + + using (var runner = RemoteServiceRunner.For()) + { + runner.WaitForServiceToStart(); + runner.WaitForServiceToStart(); + + MessageHistory.StartListening(runner); + MessageHistory.ClearHistory(); + + var foo = new Foo(); + + EventAggregator.SentMessage(foo); + + + EventAggregator.Messaging.WaitForMessage(() => runner.SendRemotely(foo)) + .ShouldNotBeNull(); + } + } + [Test] public void spin_up_the_remote_service_for_the_sample_and_send_messages_back_and_forth() { diff --git a/src/Bottles/Services/Messaging/Tracking/MessageHistory.cs b/src/Bottles/Services/Messaging/Tracking/MessageHistory.cs index 00ce3d6..d7dce13 100644 --- a/src/Bottles/Services/Messaging/Tracking/MessageHistory.cs +++ b/src/Bottles/Services/Messaging/Tracking/MessageHistory.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using System.Threading; using Bottles.Services.Remote; @@ -23,7 +22,6 @@ public static void StartListening(params RemoteServiceRunner[] runners) { ClearAll(); - _hubs.Clear(); _hubs.AddRange(runners.Select(x => x.Messaging)); _hubs.Add(EventAggregator.Messaging); _listener = new MessageTrackListener(); @@ -33,7 +31,7 @@ public static void StartListening(params RemoteServiceRunner[] runners) public static void ClearAll() { - clearData(); + ClearHistory(); if (_listener != null) { @@ -44,7 +42,7 @@ public static void ClearAll() _hubs.Clear(); } - private static void clearData() + public static void ClearHistory() { _lock.Write(() => { _sent.Clear(); @@ -108,7 +106,7 @@ public void Receive(MessageTrack message) public static bool WaitForWorkToFinish(Action action, int timeoutMilliseconds = 5000) { - clearData(); + ClearHistory(); action(); return Wait.Until(() => !Outstanding().Any() && All().Any(), timeoutInMilliseconds: timeoutMilliseconds); }