Esempio n. 1
0
        public void CountSubscriptionsForIsCorrect()
        {
            var messenger = new MvxMessengerHub();

            Assert.AreEqual(false, messenger.HasSubscriptionsFor <MvxSubscriberChangeMessage>());
            Assert.AreEqual(false, messenger.HasSubscriptionsFor <TestMessage>());
            var changeToken = messenger.Subscribe <MvxSubscriberChangeMessage>(message => { });

            Assert.AreEqual(1, messenger.CountSubscriptionsFor <MvxSubscriberChangeMessage>());
            Assert.AreEqual(0, messenger.CountSubscriptionsFor <TestMessage>());
            var token = messenger.Subscribe <TestMessage>(m =>
            {
                // stuff
            });

            Assert.AreEqual(1, messenger.CountSubscriptionsFor <MvxSubscriberChangeMessage>());
            Assert.AreEqual(1, messenger.CountSubscriptionsFor <TestMessage>());
            var token2 = messenger.Subscribe <TestMessage>(m =>
            {
                // stuff
            });

            Assert.AreEqual(1, messenger.CountSubscriptionsFor <MvxSubscriberChangeMessage>());
            Assert.AreEqual(2, messenger.CountSubscriptionsFor <TestMessage>());
            messenger.Unsubscribe <TestMessage>(token);
            Assert.AreEqual(1, messenger.CountSubscriptionsFor <MvxSubscriberChangeMessage>());
            Assert.AreEqual(1, messenger.CountSubscriptionsFor <TestMessage>());
            messenger.Unsubscribe <TestMessage>(token2);
            Assert.AreEqual(1, messenger.CountSubscriptionsFor <MvxSubscriberChangeMessage>());
            Assert.AreEqual(0, messenger.CountSubscriptionsFor <TestMessage>());
        }
Esempio n. 2
0
        public void GetSubscriptionTagsIsCorrect()
        {
            var testTag1  = "TestTag1";
            var testTag2  = "TestTag2";
            var messenger = new MvxMessengerHub();

            Assert.IsEmpty(messenger.GetSubscriptionTagsFor <MvxSubscriberChangeMessage>());
            Assert.IsEmpty(messenger.GetSubscriptionTagsFor <TestMessage>());
            var changeToken = messenger.Subscribe <MvxSubscriberChangeMessage>(message => { });

            Assert.AreEqual(1, messenger.GetSubscriptionTagsFor <MvxSubscriberChangeMessage>().Count);
            Assert.AreEqual(null, messenger.GetSubscriptionTagsFor <MvxSubscriberChangeMessage>()[0]);
            Assert.IsEmpty(messenger.GetSubscriptionTagsFor <TestMessage>());
            var token = messenger.Subscribe <TestMessage>(m =>
            {
                // stuff
            }, tag: testTag1);

            Assert.AreEqual(1, messenger.GetSubscriptionTagsFor <MvxSubscriberChangeMessage>().Count);
            Assert.AreEqual(null, messenger.GetSubscriptionTagsFor <MvxSubscriberChangeMessage>()[0]);
            Assert.AreEqual(1, messenger.GetSubscriptionTagsFor <TestMessage>().Count);
            Assert.AreEqual(testTag1, messenger.GetSubscriptionTagsFor <TestMessage>()[0]);
            var token2 = messenger.Subscribe <TestMessage>(m =>
            {
                // stuff
            }, tag: testTag1);

            Assert.AreEqual(1, messenger.GetSubscriptionTagsFor <MvxSubscriberChangeMessage>().Count);
            Assert.AreEqual(null, messenger.GetSubscriptionTagsFor <MvxSubscriberChangeMessage>()[0]);
            Assert.AreEqual(2, messenger.GetSubscriptionTagsFor <TestMessage>().Count);
            Assert.AreEqual(testTag1, messenger.GetSubscriptionTagsFor <TestMessage>()[0]);
            Assert.AreEqual(testTag1, messenger.GetSubscriptionTagsFor <TestMessage>()[1]);
            var token3 = messenger.Subscribe <TestMessage>(m =>
            {
                // stuff
            }, tag: testTag2);

            Assert.AreEqual(1, messenger.GetSubscriptionTagsFor <MvxSubscriberChangeMessage>().Count);
            Assert.AreEqual(null, messenger.GetSubscriptionTagsFor <MvxSubscriberChangeMessage>()[0]);
            Assert.AreEqual(3, messenger.GetSubscriptionTagsFor <TestMessage>().Count);
            Assert.AreEqual(2, messenger.GetSubscriptionTagsFor <TestMessage>().Where(x => x == testTag1).Count());
            Assert.AreEqual(1, messenger.GetSubscriptionTagsFor <TestMessage>().Where(x => x == testTag2).Count());
            messenger.Unsubscribe <TestMessage>(token);
            Assert.AreEqual(1, messenger.GetSubscriptionTagsFor <MvxSubscriberChangeMessage>().Count);
            Assert.AreEqual(null, messenger.GetSubscriptionTagsFor <MvxSubscriberChangeMessage>()[0]);
            Assert.AreEqual(2, messenger.GetSubscriptionTagsFor <TestMessage>().Count);
            Assert.AreEqual(1, messenger.GetSubscriptionTagsFor <TestMessage>().Where(x => x == testTag1).Count());
            Assert.AreEqual(1, messenger.GetSubscriptionTagsFor <TestMessage>().Where(x => x == testTag2).Count());
            messenger.Unsubscribe <TestMessage>(token2);
            Assert.AreEqual(1, messenger.GetSubscriptionTagsFor <MvxSubscriberChangeMessage>().Count);
            Assert.AreEqual(null, messenger.GetSubscriptionTagsFor <MvxSubscriberChangeMessage>()[0]);
            Assert.AreEqual(1, messenger.GetSubscriptionTagsFor <TestMessage>().Count);
            Assert.AreEqual(0, messenger.GetSubscriptionTagsFor <TestMessage>().Where(x => x == testTag1).Count());
            Assert.AreEqual(1, messenger.GetSubscriptionTagsFor <TestMessage>().Where(x => x == testTag2).Count());
            messenger.Unsubscribe <TestMessage>(token3);
            Assert.AreEqual(1, messenger.GetSubscriptionTagsFor <MvxSubscriberChangeMessage>().Count);
            Assert.AreEqual(null, messenger.GetSubscriptionTagsFor <MvxSubscriberChangeMessage>()[0]);
            Assert.AreEqual(0, messenger.GetSubscriptionTagsFor <TestMessage>().Count);
        }
Esempio n. 3
0
        public void UnknownUnsubscribeDoesNotCauseException()
        {
            var messenger = new MvxMessengerHub();

            messenger.Unsubscribe <TestMessage>(new MvxSubscriptionToken(Guid.NewGuid(), () => { }, new object()));
            messenger.Subscribe <TestMessage>(m =>
            {
                // stuff
            });
            messenger.Unsubscribe <TestMessage>(new MvxSubscriptionToken(Guid.NewGuid(), () => { }, new object()));
            messenger.Unsubscribe <TestMessage>(new MvxSubscriptionToken(Guid.Empty, () => { }, new object()));
        }
Esempio n. 4
0
        public void HasSubscriptionsForTagIsCorrect()
        {
            var testTag        = "TestTag";
            var notExistingTag = "NotExistingTag";
            var messenger      = new MvxMessengerHub();

            Assert.AreEqual(false, messenger.HasSubscriptionsFor <MvxSubscriberChangeMessage>());
            Assert.AreEqual(false, messenger.HasSubscriptionsForTag <MvxSubscriberChangeMessage>(testTag));
            Assert.AreEqual(false, messenger.HasSubscriptionsFor <TestMessage>());
            Assert.AreEqual(false, messenger.HasSubscriptionsForTag <TestMessage>(null));
            Assert.AreEqual(false, messenger.HasSubscriptionsForTag <TestMessage>(notExistingTag));
            var changeToken = messenger.Subscribe <MvxSubscriberChangeMessage>(message => { });

            Assert.AreEqual(true, messenger.HasSubscriptionsForTag <MvxSubscriberChangeMessage>(null));
            Assert.AreEqual(false, messenger.HasSubscriptionsForTag <MvxSubscriberChangeMessage>(testTag));
            Assert.AreEqual(false, messenger.HasSubscriptionsForTag <TestMessage>(testTag));
            Assert.AreEqual(false, messenger.HasSubscriptionsForTag <TestMessage>(null));
            Assert.AreEqual(false, messenger.HasSubscriptionsForTag <TestMessage>(notExistingTag));
            var token = messenger.Subscribe <TestMessage>(m =>
            {
                // stuff
            }, tag: testTag);

            Assert.AreEqual(true, messenger.HasSubscriptionsForTag <MvxSubscriberChangeMessage>(null));
            Assert.AreEqual(false, messenger.HasSubscriptionsForTag <MvxSubscriberChangeMessage>(testTag));
            Assert.AreEqual(true, messenger.HasSubscriptionsForTag <TestMessage>(testTag));
            Assert.AreEqual(false, messenger.HasSubscriptionsForTag <TestMessage>(null));
            Assert.AreEqual(false, messenger.HasSubscriptionsForTag <TestMessage>(notExistingTag));
            messenger.Unsubscribe <TestMessage>(token);
            Assert.AreEqual(true, messenger.HasSubscriptionsForTag <MvxSubscriberChangeMessage>(null));
            Assert.AreEqual(false, messenger.HasSubscriptionsForTag <MvxSubscriberChangeMessage>(testTag));
            Assert.AreEqual(false, messenger.HasSubscriptionsForTag <TestMessage>(testTag));
            Assert.AreEqual(false, messenger.HasSubscriptionsForTag <TestMessage>(null));
            Assert.AreEqual(false, messenger.HasSubscriptionsForTag <TestMessage>(notExistingTag));
        }
Esempio n. 5
0
        public void UnsubscribePreventsMessagesBeingReceived()
        {
            var messenger = new MvxMessengerHub();
            Action <TestMessage> action = _ => Assert.That(false, "This event should not fire!");

            var id = messenger.Subscribe(action);

            messenger.Unsubscribe <TestMessage>(id);
            messenger.Publish(new TestMessage(this));
        }
Esempio n. 6
0
        public void SubscribeAndUnsubscribeCauseChangeMessages()
        {
            var messenger = new MvxMessengerHub();
            MvxSubscriberChangeMessage subscriberChangeMessage = null;
            var changeToken = messenger.Subscribe <MvxSubscriberChangeMessage>(message => subscriberChangeMessage = message);
            var token       = messenger.Subscribe <TestMessage>(m =>
            {
                // stuff
            });

            Assert.NotNull(subscriberChangeMessage);
            Assert.AreEqual(1, subscriberChangeMessage.SubscriberCount);
            Assert.AreEqual(typeof(TestMessage), subscriberChangeMessage.MessageType);
            subscriberChangeMessage = null;
            messenger.Unsubscribe <TestMessage>(token);
            Assert.NotNull(subscriberChangeMessage);
            Assert.AreEqual(0, subscriberChangeMessage.SubscriberCount);
            Assert.AreEqual(typeof(TestMessage), subscriberChangeMessage.MessageType);
        }
Esempio n. 7
0
        public void HasSubscriptionsForIsCorrect()
        {
            var messenger = new MvxMessengerHub();

            Assert.False(messenger.HasSubscriptionsFor <MvxSubscriberChangeMessage>());
            Assert.False(messenger.HasSubscriptionsFor <TestMessage>());
            var changeToken = messenger.Subscribe <MvxSubscriberChangeMessage>(message => { });

            Assert.True(messenger.HasSubscriptionsFor <MvxSubscriberChangeMessage>());
            Assert.False(messenger.HasSubscriptionsFor <TestMessage>());
            var token = messenger.Subscribe <TestMessage>(m =>
            {
                // stuff
            });

            Assert.True(messenger.HasSubscriptionsFor <MvxSubscriberChangeMessage>());
            Assert.True(messenger.HasSubscriptionsFor <TestMessage>());
            messenger.Unsubscribe <TestMessage>(token);
            Assert.True(messenger.HasSubscriptionsFor <MvxSubscriberChangeMessage>());
            Assert.False(messenger.HasSubscriptionsFor <TestMessage>());
        }
 public void SubscribeAndUnsubscribeCauseChangeMessages()
 {
     var messenger = new MvxMessengerHub();
     MvxSubscriberChangeMessage subscriberChangeMessage = null;
     var changeToken = messenger.Subscribe<MvxSubscriberChangeMessage>(message => subscriberChangeMessage = message);
     var token = messenger.Subscribe<TestMessage>(m =>
     {
         // stuff
     });
     Assert.NotNull(subscriberChangeMessage);
     Assert.AreEqual(1, subscriberChangeMessage.SubscriberCount);
     Assert.AreEqual(typeof(TestMessage), subscriberChangeMessage.MessageType);
     subscriberChangeMessage = null;
     messenger.Unsubscribe<TestMessage>(token);
     Assert.NotNull(subscriberChangeMessage);
     Assert.AreEqual(0, subscriberChangeMessage.SubscriberCount);
     Assert.AreEqual(typeof(TestMessage), subscriberChangeMessage.MessageType);
 }
 public void GetSubscriptionTagsIsCorrect()
 {
     var testTag1 = "TestTag1";
     var testTag2 = "TestTag2";
     var messenger = new MvxMessengerHub();
     Assert.IsEmpty(messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>());
     Assert.IsEmpty(messenger.GetSubscriptionTagsFor<TestMessage>());
     var changeToken = messenger.Subscribe<MvxSubscriberChangeMessage>(message => { });
     Assert.AreEqual(1, messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>().Count);
     Assert.AreEqual(null, messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>()[0]);
     Assert.IsEmpty(messenger.GetSubscriptionTagsFor<TestMessage>());
     var token = messenger.Subscribe<TestMessage>(m =>
     {
         // stuff
     }, tag: testTag1);
     Assert.AreEqual(1, messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>().Count);
     Assert.AreEqual(null, messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>()[0]);
     Assert.AreEqual(1, messenger.GetSubscriptionTagsFor<TestMessage>().Count);
     Assert.AreEqual(testTag1, messenger.GetSubscriptionTagsFor<TestMessage>()[0]);
     var token2 = messenger.Subscribe<TestMessage>(m =>
     {
         // stuff
     }, tag: testTag1);
     Assert.AreEqual(1, messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>().Count);
     Assert.AreEqual(null, messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>()[0]);
     Assert.AreEqual(2, messenger.GetSubscriptionTagsFor<TestMessage>().Count);
     Assert.AreEqual(testTag1, messenger.GetSubscriptionTagsFor<TestMessage>()[0]);
     Assert.AreEqual(testTag1, messenger.GetSubscriptionTagsFor<TestMessage>()[1]);
     var token3 = messenger.Subscribe<TestMessage>(m =>
     {
         // stuff
     }, tag: testTag2);
     Assert.AreEqual(1, messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>().Count);
     Assert.AreEqual(null, messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>()[0]);
     Assert.AreEqual(3, messenger.GetSubscriptionTagsFor<TestMessage>().Count);
     Assert.AreEqual(2, messenger.GetSubscriptionTagsFor<TestMessage>().Where(x => x == testTag1).Count());
     Assert.AreEqual(1, messenger.GetSubscriptionTagsFor<TestMessage>().Where(x => x == testTag2).Count());
     messenger.Unsubscribe<TestMessage>(token);
     Assert.AreEqual(1, messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>().Count);
     Assert.AreEqual(null, messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>()[0]);
     Assert.AreEqual(2, messenger.GetSubscriptionTagsFor<TestMessage>().Count);
     Assert.AreEqual(1, messenger.GetSubscriptionTagsFor<TestMessage>().Where(x => x == testTag1).Count());
     Assert.AreEqual(1, messenger.GetSubscriptionTagsFor<TestMessage>().Where(x => x == testTag2).Count());
     messenger.Unsubscribe<TestMessage>(token2);
     Assert.AreEqual(1, messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>().Count);
     Assert.AreEqual(null, messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>()[0]);
     Assert.AreEqual(1, messenger.GetSubscriptionTagsFor<TestMessage>().Count);
     Assert.AreEqual(0, messenger.GetSubscriptionTagsFor<TestMessage>().Where(x => x == testTag1).Count());
     Assert.AreEqual(1, messenger.GetSubscriptionTagsFor<TestMessage>().Where(x => x == testTag2).Count());
     messenger.Unsubscribe<TestMessage>(token3);
     Assert.AreEqual(1, messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>().Count);
     Assert.AreEqual(null, messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>()[0]);
     Assert.AreEqual(0, messenger.GetSubscriptionTagsFor<TestMessage>().Count);
 }
Esempio n. 10
0
 public void CountSubscriptionsForTagIsCorrect()
 {
     var testTag1 = "TestTag1";
     var testTag2 = "TestTag2";
     var notExistingTag = "NotExistingTag";
     var messenger = new MvxMessengerHub();
     Assert.AreEqual(0, messenger.CountSubscriptionsForTag<MvxSubscriberChangeMessage>(null));
     Assert.AreEqual(0, messenger.CountSubscriptionsForTag<MvxSubscriberChangeMessage>(testTag1));
     Assert.AreEqual(0, messenger.CountSubscriptionsForTag<TestMessage>(testTag1));
     Assert.AreEqual(0, messenger.CountSubscriptionsForTag<TestMessage>(testTag2));
     Assert.AreEqual(0, messenger.CountSubscriptionsForTag<TestMessage>(notExistingTag));
     var changeToken = messenger.Subscribe<MvxSubscriberChangeMessage>(message => { });
     Assert.AreEqual(1, messenger.CountSubscriptionsForTag<MvxSubscriberChangeMessage>(null));
     Assert.AreEqual(0, messenger.CountSubscriptionsForTag<MvxSubscriberChangeMessage>(testTag1));
     Assert.AreEqual(0, messenger.CountSubscriptionsForTag<TestMessage>(testTag1));
     Assert.AreEqual(0, messenger.CountSubscriptionsForTag<TestMessage>(testTag2));
     Assert.AreEqual(0, messenger.CountSubscriptionsForTag<TestMessage>(notExistingTag));
     var token = messenger.Subscribe<TestMessage>(m =>
     {
         // stuff
     }, tag:testTag1);
     Assert.AreEqual(1, messenger.CountSubscriptionsForTag<MvxSubscriberChangeMessage>(null));
     Assert.AreEqual(0, messenger.CountSubscriptionsForTag<MvxSubscriberChangeMessage>(testTag1));
     Assert.AreEqual(1, messenger.CountSubscriptionsForTag<TestMessage>(testTag1));
     Assert.AreEqual(0, messenger.CountSubscriptionsForTag<TestMessage>(testTag2));
     Assert.AreEqual(0, messenger.CountSubscriptionsForTag<TestMessage>(notExistingTag));
     var token2 = messenger.Subscribe<TestMessage>(m =>
     {
         // stuff
     }, tag:testTag1);
     Assert.AreEqual(1, messenger.CountSubscriptionsForTag<MvxSubscriberChangeMessage>(null));
     Assert.AreEqual(0, messenger.CountSubscriptionsForTag<MvxSubscriberChangeMessage>(testTag1));
     Assert.AreEqual(2, messenger.CountSubscriptionsForTag<TestMessage>(testTag1));
     Assert.AreEqual(0, messenger.CountSubscriptionsForTag<TestMessage>(testTag2));
     Assert.AreEqual(0, messenger.CountSubscriptionsForTag<TestMessage>(notExistingTag));
     var token3 = messenger.Subscribe<TestMessage>(m =>
     {
         // stuff
     }, tag: testTag2);
     Assert.AreEqual(1, messenger.CountSubscriptionsForTag<MvxSubscriberChangeMessage>(null));
     Assert.AreEqual(0, messenger.CountSubscriptionsForTag<MvxSubscriberChangeMessage>(testTag1));
     Assert.AreEqual(2, messenger.CountSubscriptionsForTag<TestMessage>(testTag1));
     Assert.AreEqual(1, messenger.CountSubscriptionsForTag<TestMessage>(testTag2));
     Assert.AreEqual(0, messenger.CountSubscriptionsForTag<TestMessage>(notExistingTag));
     messenger.Unsubscribe<TestMessage>(token);
     Assert.AreEqual(1, messenger.CountSubscriptionsForTag<MvxSubscriberChangeMessage>(null));
     Assert.AreEqual(0, messenger.CountSubscriptionsForTag<MvxSubscriberChangeMessage>(testTag1));
     Assert.AreEqual(1, messenger.CountSubscriptionsForTag<TestMessage>(testTag1));
     Assert.AreEqual(1, messenger.CountSubscriptionsForTag<TestMessage>(testTag2));
     Assert.AreEqual(0, messenger.CountSubscriptionsForTag<TestMessage>(notExistingTag));
     messenger.Unsubscribe<TestMessage>(token2);
     Assert.AreEqual(1, messenger.CountSubscriptionsForTag<MvxSubscriberChangeMessage>(null));
     Assert.AreEqual(0, messenger.CountSubscriptionsForTag<MvxSubscriberChangeMessage>(testTag1));
     Assert.AreEqual(0, messenger.CountSubscriptionsForTag<TestMessage>(testTag1));
     Assert.AreEqual(1, messenger.CountSubscriptionsForTag<TestMessage>(testTag2));
     Assert.AreEqual(0, messenger.CountSubscriptionsForTag<TestMessage>(notExistingTag));
     messenger.Unsubscribe<TestMessage>(token3);
     Assert.AreEqual(1, messenger.CountSubscriptionsForTag<MvxSubscriberChangeMessage>(null));
     Assert.AreEqual(0, messenger.CountSubscriptionsForTag<MvxSubscriberChangeMessage>(testTag1));
     Assert.AreEqual(0, messenger.CountSubscriptionsForTag<TestMessage>(testTag1));
     Assert.AreEqual(0, messenger.CountSubscriptionsForTag<TestMessage>(testTag2));
     Assert.AreEqual(0, messenger.CountSubscriptionsForTag<TestMessage>(notExistingTag));
 }
Esempio n. 11
0
 public void HasSubscriptionsForTagIsCorrect()
 {
     var testTag = "TestTag";
     var notExistingTag = "NotExistingTag";
     var messenger = new MvxMessengerHub();
     Assert.AreEqual(false, messenger.HasSubscriptionsFor<MvxSubscriberChangeMessage>());
     Assert.AreEqual(false, messenger.HasSubscriptionsForTag<MvxSubscriberChangeMessage>(testTag));
     Assert.AreEqual(false, messenger.HasSubscriptionsFor<TestMessage>());
     Assert.AreEqual(false, messenger.HasSubscriptionsForTag<TestMessage>(null));
     Assert.AreEqual(false, messenger.HasSubscriptionsForTag<TestMessage>(notExistingTag));
     var changeToken = messenger.Subscribe<MvxSubscriberChangeMessage>(message => { });
     Assert.AreEqual(true, messenger.HasSubscriptionsForTag<MvxSubscriberChangeMessage>(null));
     Assert.AreEqual(false, messenger.HasSubscriptionsForTag<MvxSubscriberChangeMessage>(testTag));
     Assert.AreEqual(false, messenger.HasSubscriptionsForTag<TestMessage>(testTag));
     Assert.AreEqual(false, messenger.HasSubscriptionsForTag<TestMessage>(null));
     Assert.AreEqual(false, messenger.HasSubscriptionsForTag<TestMessage>(notExistingTag));
     var token = messenger.Subscribe<TestMessage>(m =>
     {
         // stuff
     }, tag: testTag);
     Assert.AreEqual(true, messenger.HasSubscriptionsForTag<MvxSubscriberChangeMessage>(null));
     Assert.AreEqual(false, messenger.HasSubscriptionsForTag<MvxSubscriberChangeMessage>(testTag));
     Assert.AreEqual(true, messenger.HasSubscriptionsForTag<TestMessage>(testTag));
     Assert.AreEqual(false, messenger.HasSubscriptionsForTag<TestMessage>(null));
     Assert.AreEqual(false, messenger.HasSubscriptionsForTag<TestMessage>(notExistingTag));
     messenger.Unsubscribe<TestMessage>(token);
     Assert.AreEqual(true, messenger.HasSubscriptionsForTag<MvxSubscriberChangeMessage>(null));
     Assert.AreEqual(false, messenger.HasSubscriptionsForTag<MvxSubscriberChangeMessage>(testTag));
     Assert.AreEqual(false, messenger.HasSubscriptionsForTag<TestMessage>(testTag));
     Assert.AreEqual(false, messenger.HasSubscriptionsForTag<TestMessage>(null));
     Assert.AreEqual(false, messenger.HasSubscriptionsForTag<TestMessage>(notExistingTag));
 }
Esempio n. 12
0
 public void CountSubscriptionsForIsCorrect()
 {
     var messenger = new MvxMessengerHub();
     Assert.AreEqual(false, messenger.HasSubscriptionsFor<MvxSubscriberChangeMessage>());
     Assert.AreEqual(false, messenger.HasSubscriptionsFor<TestMessage>());
     var changeToken = messenger.Subscribe<MvxSubscriberChangeMessage>(message => { });
     Assert.AreEqual(1, messenger.CountSubscriptionsFor<MvxSubscriberChangeMessage>());
     Assert.AreEqual(0, messenger.CountSubscriptionsFor<TestMessage>());
     var token = messenger.Subscribe<TestMessage>(m =>
     {
         // stuff
     });
     Assert.AreEqual(1, messenger.CountSubscriptionsFor<MvxSubscriberChangeMessage>());
     Assert.AreEqual(1, messenger.CountSubscriptionsFor<TestMessage>());
     var token2 = messenger.Subscribe<TestMessage>(m =>
     {
         // stuff
     });
     Assert.AreEqual(1, messenger.CountSubscriptionsFor<MvxSubscriberChangeMessage>());
     Assert.AreEqual(2, messenger.CountSubscriptionsFor<TestMessage>());
     messenger.Unsubscribe<TestMessage>(token);
     Assert.AreEqual(1, messenger.CountSubscriptionsFor<MvxSubscriberChangeMessage>());
     Assert.AreEqual(1, messenger.CountSubscriptionsFor<TestMessage>());
     messenger.Unsubscribe<TestMessage>(token2);
     Assert.AreEqual(1, messenger.CountSubscriptionsFor<MvxSubscriberChangeMessage>());
     Assert.AreEqual(0, messenger.CountSubscriptionsFor<TestMessage>());
 }
Esempio n. 13
0
 public void UnknownUnsubscribeDoesNotCauseException()
 {
     var messenger = new MvxMessengerHub();
     messenger.Unsubscribe<TestMessage>(new MvxSubscriptionToken(Guid.NewGuid(), () => { }, new object()));
     messenger.Subscribe<TestMessage>(m =>
         {
             // stuff
         });
     messenger.Unsubscribe<TestMessage>(new MvxSubscriptionToken(Guid.NewGuid(), () => { }, new object()));
     messenger.Unsubscribe<TestMessage>(new MvxSubscriptionToken(Guid.Empty, () => { }, new object()));
 }
Esempio n. 14
0
        public void UnsubscribePreventsMessagesBeingReceived()
        {
            var messenger = new MvxMessengerHub();
            Action<TestMessage> action = _ => Assert.That(false, "This event should not fire!");

            var id = messenger.Subscribe(action);
            messenger.Unsubscribe<TestMessage>(id);
            messenger.Publish(new TestMessage(this));
        }
Esempio n. 15
0
        public void CountSubscriptionsForTagIsCorrect()
        {
            var testTag1       = "TestTag1";
            var testTag2       = "TestTag2";
            var notExistingTag = "NotExistingTag";
            var messenger      = new MvxMessengerHub();

            Assert.AreEqual(0, messenger.CountSubscriptionsForTag <MvxSubscriberChangeMessage>(null));
            Assert.AreEqual(0, messenger.CountSubscriptionsForTag <MvxSubscriberChangeMessage>(testTag1));
            Assert.AreEqual(0, messenger.CountSubscriptionsForTag <TestMessage>(testTag1));
            Assert.AreEqual(0, messenger.CountSubscriptionsForTag <TestMessage>(testTag2));
            Assert.AreEqual(0, messenger.CountSubscriptionsForTag <TestMessage>(notExistingTag));
            var changeToken = messenger.Subscribe <MvxSubscriberChangeMessage>(message => { });

            Assert.AreEqual(1, messenger.CountSubscriptionsForTag <MvxSubscriberChangeMessage>(null));
            Assert.AreEqual(0, messenger.CountSubscriptionsForTag <MvxSubscriberChangeMessage>(testTag1));
            Assert.AreEqual(0, messenger.CountSubscriptionsForTag <TestMessage>(testTag1));
            Assert.AreEqual(0, messenger.CountSubscriptionsForTag <TestMessage>(testTag2));
            Assert.AreEqual(0, messenger.CountSubscriptionsForTag <TestMessage>(notExistingTag));
            var token = messenger.Subscribe <TestMessage>(m =>
            {
                // stuff
            }, tag: testTag1);

            Assert.AreEqual(1, messenger.CountSubscriptionsForTag <MvxSubscriberChangeMessage>(null));
            Assert.AreEqual(0, messenger.CountSubscriptionsForTag <MvxSubscriberChangeMessage>(testTag1));
            Assert.AreEqual(1, messenger.CountSubscriptionsForTag <TestMessage>(testTag1));
            Assert.AreEqual(0, messenger.CountSubscriptionsForTag <TestMessage>(testTag2));
            Assert.AreEqual(0, messenger.CountSubscriptionsForTag <TestMessage>(notExistingTag));
            var token2 = messenger.Subscribe <TestMessage>(m =>
            {
                // stuff
            }, tag: testTag1);

            Assert.AreEqual(1, messenger.CountSubscriptionsForTag <MvxSubscriberChangeMessage>(null));
            Assert.AreEqual(0, messenger.CountSubscriptionsForTag <MvxSubscriberChangeMessage>(testTag1));
            Assert.AreEqual(2, messenger.CountSubscriptionsForTag <TestMessage>(testTag1));
            Assert.AreEqual(0, messenger.CountSubscriptionsForTag <TestMessage>(testTag2));
            Assert.AreEqual(0, messenger.CountSubscriptionsForTag <TestMessage>(notExistingTag));
            var token3 = messenger.Subscribe <TestMessage>(m =>
            {
                // stuff
            }, tag: testTag2);

            Assert.AreEqual(1, messenger.CountSubscriptionsForTag <MvxSubscriberChangeMessage>(null));
            Assert.AreEqual(0, messenger.CountSubscriptionsForTag <MvxSubscriberChangeMessage>(testTag1));
            Assert.AreEqual(2, messenger.CountSubscriptionsForTag <TestMessage>(testTag1));
            Assert.AreEqual(1, messenger.CountSubscriptionsForTag <TestMessage>(testTag2));
            Assert.AreEqual(0, messenger.CountSubscriptionsForTag <TestMessage>(notExistingTag));
            messenger.Unsubscribe <TestMessage>(token);
            Assert.AreEqual(1, messenger.CountSubscriptionsForTag <MvxSubscriberChangeMessage>(null));
            Assert.AreEqual(0, messenger.CountSubscriptionsForTag <MvxSubscriberChangeMessage>(testTag1));
            Assert.AreEqual(1, messenger.CountSubscriptionsForTag <TestMessage>(testTag1));
            Assert.AreEqual(1, messenger.CountSubscriptionsForTag <TestMessage>(testTag2));
            Assert.AreEqual(0, messenger.CountSubscriptionsForTag <TestMessage>(notExistingTag));
            messenger.Unsubscribe <TestMessage>(token2);
            Assert.AreEqual(1, messenger.CountSubscriptionsForTag <MvxSubscriberChangeMessage>(null));
            Assert.AreEqual(0, messenger.CountSubscriptionsForTag <MvxSubscriberChangeMessage>(testTag1));
            Assert.AreEqual(0, messenger.CountSubscriptionsForTag <TestMessage>(testTag1));
            Assert.AreEqual(1, messenger.CountSubscriptionsForTag <TestMessage>(testTag2));
            Assert.AreEqual(0, messenger.CountSubscriptionsForTag <TestMessage>(notExistingTag));
            messenger.Unsubscribe <TestMessage>(token3);
            Assert.AreEqual(1, messenger.CountSubscriptionsForTag <MvxSubscriberChangeMessage>(null));
            Assert.AreEqual(0, messenger.CountSubscriptionsForTag <MvxSubscriberChangeMessage>(testTag1));
            Assert.AreEqual(0, messenger.CountSubscriptionsForTag <TestMessage>(testTag1));
            Assert.AreEqual(0, messenger.CountSubscriptionsForTag <TestMessage>(testTag2));
            Assert.AreEqual(0, messenger.CountSubscriptionsForTag <TestMessage>(notExistingTag));
        }