From 5ff5bc1cf156e492098278dffb11677786bba38b Mon Sep 17 00:00:00 2001 From: Paul Heasley Date: Wed, 15 Jul 2015 07:16:15 +1000 Subject: [PATCH] Passing all tests --- EventAggregator.Tests/EventAggregatorTests.cs | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/EventAggregator.Tests/EventAggregatorTests.cs b/EventAggregator.Tests/EventAggregatorTests.cs index 524b4d6..b3c47fd 100644 --- a/EventAggregator.Tests/EventAggregatorTests.cs +++ b/EventAggregator.Tests/EventAggregatorTests.cs @@ -34,14 +34,55 @@ public void ObserverShouldOnlyReceiveSubscribedNotifications() observer2.Verify(x => x.OnNext(otherEvent), Times.Once); } + [TestMethod] public void ObserverStopsReceivingEventsWhenUnsubscribed() { - + // Arrange + + var eventAggregator = new EventAggregator(); + var observer1 = new Mock>(); + + var unsubscribe = eventAggregator.Subscribe(observer1.Object); + var testEvent1 = new TestEvent(); + var testEvent2 = new TestEvent(); + + // Act + + eventAggregator.Publish(testEvent1); + unsubscribe.Dispose(); + eventAggregator.Publish(testEvent2); + + // Assert + + observer1.Verify(x => x.OnNext(It.IsAny()), Times.Once); + observer1.Verify(x => x.OnNext(testEvent1), Times.Once); + observer1.Verify(x => x.OnNext(testEvent2), Times.Never); } + [TestMethod] public void BaseObserverReceivesAllEvents() { - + // Arrange + + var eventAggregator = new EventAggregator(); + var observer1 = new Mock>(); + var observer2 = new Mock>(); + + eventAggregator.Subscribe(observer1.Object); + eventAggregator.Subscribe(observer2.Object); + + var testEvent = new TestEvent(); + var otherEvent = new OtherEvent(); + + // Act + + eventAggregator.Publish(testEvent); + eventAggregator.Publish(otherEvent); + + // Assert + + observer1.Verify(x => x.OnNext(It.IsAny()), Times.Exactly(2)); + observer2.Verify(x => x.OnNext(It.IsAny()), Times.Exactly(2)); } public class TestEvent : IEvent { }