public void TestSubscribeWithIDWithArg() { var subscriber = new MockSubscriber(); var sender = new MockSenderWithID(); Messenger.Subscribe <MockArgs> (subscriber, sender, subscriber.HandleMessage); var countBefore = subscriber.MessagesReceived; Messenger.Send(sender, new MockArgs()); Assert.AreEqual(0, countBefore); Assert.AreEqual(1, subscriber.MessagesReceived); }
public void TestSubscribersOfDifferentSignaturesDoNotReceiveSameMessages() { var firstSubscriber = new MockSubscriber(); var secondSubscriber = new MockSubscriber(); Messenger.Subscribe(firstSubscriber, MockSubscriber.Signature, firstSubscriber.HandleMessage); Messenger.Subscribe(secondSubscriber, MockSubscriber.Signature + "2", secondSubscriber.HandleMessage); Messenger.Send(MockSubscriber.Signature); Messenger.Send(MockSubscriber.Signature); Messenger.Send(MockSubscriber.Signature + "2"); Assert.AreEqual(firstSubscriber.MessagesReceived, 2); Assert.AreEqual(secondSubscriber.MessagesReceived, 1); }
public void TestSubscribeWithArg() { var subscriber = new MockSubscriber(); var otherSubscriber = new MockSubscriber(); Messenger.Subscribe <MockArgs> (this, MockSubscriber.Signature, subscriber.HandleMessage); var countBefore = subscriber.MessagesReceived; Messenger.Send(MockSubscriber.Signature, new MockArgs()); Assert.AreEqual(0, countBefore); Assert.AreEqual(1, subscriber.MessagesReceived); Assert.AreEqual(0, otherSubscriber.MessagesReceived); }
public void TestUnsubscribeWithArg() { var unsubscriber = new MockSubscriber(); Messenger.Subscribe <MockArgs> (this, MockSubscriber.Signature, unsubscriber.HandleMessage); var countAfterSubscribe = unsubscriber.MessagesReceived; Messenger.Send(MockSubscriber.Signature, new MockArgs()); var countAfterSend = unsubscriber.MessagesReceived; Messenger.Unsubscribe <MockArgs> (unsubscriber, MockSubscriber.Signature); Messenger.Send(MockSubscriber.Signature, new MockArgs()); Assert.AreEqual(0, countAfterSubscribe); Assert.AreEqual(1, countAfterSend); Assert.AreEqual(1, unsubscriber.MessagesReceived); }
public void TestUnsubscribeWithIDWithArg() { var unsubscriber = new MockSubscriber(); var sender = new MockSenderWithID(); Messenger.Subscribe <MockArgs> (unsubscriber, sender, unsubscriber.HandleMessage); var countAfterSubscribe = unsubscriber.MessagesReceived; Messenger.Send(sender, new MockArgs()); var countAfterSend = unsubscriber.MessagesReceived; Messenger.Unsubscribe <MockArgs> (unsubscriber, sender); Messenger.Send(sender, new MockArgs()); Assert.AreEqual(0, countAfterSubscribe); Assert.AreEqual(1, countAfterSend); Assert.AreEqual(1, unsubscriber.MessagesReceived); }