Skip to content

Commit

Permalink
Passing all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phdesign committed Jul 14, 2015
1 parent 7acf4ef commit 5ff5bc1
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions EventAggregator.Tests/EventAggregatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IObserve<TestEvent>>();

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<IEvent>()), 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<IObserve<IEvent>>();
var observer2 = new Mock<IObserver<IEvent>>();

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<IEvent>()), Times.Exactly(2));
observer2.Verify(x => x.OnNext(It.IsAny<IEvent>()), Times.Exactly(2));
}

public class TestEvent : IEvent { }
Expand Down

0 comments on commit 5ff5bc1

Please sign in to comment.