コード例 #1
0
ファイル: MessengerTest.cs プロジェクト: joeforshaw/Messenger
        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);
        }
コード例 #2
0
ファイル: MessengerTest.cs プロジェクト: joeforshaw/Messenger
        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);
        }
コード例 #3
0
ファイル: MessengerTest.cs プロジェクト: joeforshaw/Messenger
        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);
        }
コード例 #4
0
ファイル: MessengerTest.cs プロジェクト: joeforshaw/Messenger
        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);
        }
コード例 #5
0
ファイル: MessengerTest.cs プロジェクト: joeforshaw/Messenger
        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);
        }