WeakReference CollectRecipientCoreAlloc(Action <TestRecipient3> registerMethod, bool unregister, Action <TestRecipient3> checkMessageMethod)
        {
            TestRecipient3 recipient          = new TestRecipient3();
            WeakReference  recipientReference = new WeakReference(recipient);

            registerMethod(recipient);
            if (checkMessageMethod != null)
            {
                Messenger.Default.Send <string>("test");
                checkMessageMethod(recipient);
            }
            if (unregister)
            {
                Messenger.Default.Unregister(recipient);
            }
            return(recipientReference);
        }
        void CollectRecipientCore(Action <TestRecipient3> registerMethod, bool unregister, Action <TestRecipient3> checkMessageMethod)
        {
            TestRecipient3 recipient          = new TestRecipient3();
            WeakReference  recipientReference = new WeakReference(recipient);

            registerMethod(recipient);
            if (checkMessageMethod != null)
            {
                Messenger.Default.Send <string>("test");
                checkMessageMethod(recipient);
            }
            if (unregister)
            {
                Messenger.Default.Unregister(recipient);
            }
            recipient = null;
            GC.Collect();
            Assert.IsFalse(recipientReference.IsAlive);
        }
        public void TestBroadcastToOneInterface()
        {
            Messenger.Reset();

            var recipient11 = new TestRecipient1();
            var recipient12 = new TestRecipient1();
            var recipient21 = new TestRecipient2();
            var recipient22 = new TestRecipient2();
            var recipient31 = new TestRecipient3();
            var recipient32 = new TestRecipient3();

            Messenger.Default.Register<string>(recipient11, recipient11.ReceiveMessage);
            Messenger.Default.Register<string>(recipient12, recipient12.ReceiveMessage);
            Messenger.Default.Register<string>(recipient21, recipient21.DoSomething);
            Messenger.Default.Register<string>(recipient22, recipient22.DoSomething);
            Messenger.Default.Register<string>(recipient31, recipient31.DoSomething);
            Messenger.Default.Register<string>(recipient32, recipient32.DoSomething);

            const string testContent1 = "abcd";

            Assert.AreEqual(null, recipient11.ReceivedContentString);
            Assert.AreEqual(null, recipient12.ReceivedContentString);
            Assert.AreEqual(null, recipient21.ReceivedContentString);
            Assert.AreEqual(null, recipient22.ReceivedContentString);
            Assert.AreEqual(null, recipient31.ReceivedContentString);
            Assert.AreEqual(null, recipient32.ReceivedContentString);

            Messenger.Default.Send<string, ITestRecipient>(testContent1);

            Assert.AreEqual(null, recipient11.ReceivedContentString);
            Assert.AreEqual(null, recipient12.ReceivedContentString);
            Assert.AreEqual(testContent1, recipient21.ReceivedContentString);
            Assert.AreEqual(testContent1, recipient22.ReceivedContentString);
            Assert.AreEqual(testContent1, recipient31.ReceivedContentString);
            Assert.AreEqual(testContent1, recipient32.ReceivedContentString);
        }
        public void TestBroadcastToOneInterface()
        {
            Messenger.Reset();

            var recipient11 = new TestRecipient1();
            var recipient12 = new TestRecipient1();
            var recipient21 = new TestRecipient2();
            var recipient22 = new TestRecipient2();
            var recipient31 = new TestRecipient3();
            var recipient32 = new TestRecipient3();

            Messenger.Default.Register <string>(recipient11, recipient11.ReceiveMessage);
            Messenger.Default.Register <string>(recipient12, recipient12.ReceiveMessage);
            Messenger.Default.Register <string>(recipient21, recipient21.DoSomething);
            Messenger.Default.Register <string>(recipient22, recipient22.DoSomething);
            Messenger.Default.Register <string>(recipient31, recipient31.DoSomething);
            Messenger.Default.Register <string>(recipient32, recipient32.DoSomething);

            const string TestContent1 = "abcd";

            Assert.AreEqual(null, recipient11.ReceivedContentString);
            Assert.AreEqual(null, recipient12.ReceivedContentString);
            Assert.AreEqual(null, recipient21.ReceivedContentString);
            Assert.AreEqual(null, recipient22.ReceivedContentString);
            Assert.AreEqual(null, recipient31.ReceivedContentString);
            Assert.AreEqual(null, recipient32.ReceivedContentString);

            Messenger.Default.Send <string, ITestRecipient>(TestContent1);

            Assert.AreEqual(null, recipient11.ReceivedContentString);
            Assert.AreEqual(null, recipient12.ReceivedContentString);
            Assert.AreEqual(TestContent1, recipient21.ReceivedContentString);
            Assert.AreEqual(TestContent1, recipient22.ReceivedContentString);
            Assert.AreEqual(TestContent1, recipient31.ReceivedContentString);
            Assert.AreEqual(TestContent1, recipient32.ReceivedContentString);
        }
 protected override void ReceiveString(GenericMessage<string> m)
 {
     _innerRecipient = new TestRecipient3();
 }
Beispiel #6
0
 protected override void ReceiveString(GenericMessage <string> m)
 {
     _innerRecipient = new TestRecipient3();
 }