Beispiel #1
0
        public void NullSetTest2()
        {
            var subj2  = new SubscriberSubject2();
            var target = subj2.Publisher1 = subj2.Publisher2 = new PublisherSubject1();

            subj2.SubscribePublisher1();
            subj2.SubscribePublisher2();
            Assert.AreEqual(2, target.GetInvocationList().Count());
            subj2.Publisher1.DisposedHandlers += (s, e) => { subj2.Publisher2 = null; };
            subj2.Publisher1.Dispose();
            subj2.Publisher1 = null;
            Assert.AreEqual(0, target.GetInvocationList().Count());
        }
Beispiel #2
0
        public void MultipleSubscriptionsTest3()
        {
            var subj2  = new SubscriberSubject2();
            var target = subj2.Publisher1 = subj2.Publisher2 = new PublisherSubject1();

            subj2.SubscribePublisher1();
            subj2.SubscribePublisher2();
            target.OneProperty = "Joe1";
            Assert.AreEqual(1, subj2.Pub1PropertyChanges);
            Assert.AreEqual(1, subj2.Pub2PropertyChanges);
            target.Dispose();
            target.OneProperty = "Joe2";
            Assert.AreEqual(1, subj2.Pub1PropertyChanges);
            Assert.AreEqual(1, subj2.Pub2PropertyChanges);
        }
Beispiel #3
0
        public void GetListsTest1()
        {
            var subj1  = new SubscriberSubject1();
            var subj2  = new SubscriberSubject2();
            var target = subj1.Publisher1 = subj2.Publisher1 = new PublisherSubject1();

            subj1.SubscribePublisher1();
            subj2.SubscribePublisher1();
            Assert.AreEqual(2, target.GetInvocationList().Count());
            Assert.AreEqual(2, target.GetSubscribersTypesList().Count());
            Assert.AreEqual(1, target.GetMethodsNamesList().Count());
            target.Dispose();
            Assert.AreEqual(0, target.GetInvocationList().Count());
            Assert.AreEqual(0, target.GetSubscribersTypesList().Count());
            Assert.AreEqual(0, target.GetMethodsNamesList().Count());
        }
Beispiel #4
0
        public void MultipleSubscriptionsTest1()
        {
            var subj2  = new SubscriberSubject2();
            var target = subj2.Publisher1 = subj2.Publisher2 = new PublisherSubject1();

            Assert.AreEqual(0, target.GetInvocationList().Count());
            subj2.SubscribePublisher1();
            subj2.SubscribePublisher2();
            Assert.AreEqual(2, target.GetInvocationList().Count());
            Assert.AreEqual(1, target.GetSubscribersTypesList().Count());
            Assert.AreEqual(2, target.GetMethodsNamesList().Count());

            target.OneProperty = "Joe1";
            Assert.AreEqual(1, subj2.Pub1PropertyChanges);
            Assert.AreEqual(1, subj2.Pub2PropertyChanges);
            subj2.UnSubscribePublisher1();
            target.OneProperty = "Joe2";
            Assert.AreEqual(1, subj2.Pub1PropertyChanges);
            Assert.AreEqual(2, subj2.Pub2PropertyChanges);
        }
Beispiel #5
0
        public void UnsubscribedAllTest2()
        {
            var subj1 = new SubscriberSubject1();
            var subj2 = new SubscriberSubject2();

            subj1.Publisher1 = new PublisherSubject1();
            subj2.Publisher1 = subj1.Publisher1;
            var target = subj1.Publisher1;

            Assert.IsTrue(target == subj1.Publisher1);
            Assert.IsTrue(subj1.Publisher1 == subj2.Publisher1);
            Assert.IsTrue(target == subj2.Publisher1);
            subj1.SubscribePublisher1();
            subj2.SubscribePublisher1();
            Assert.AreEqual(0, subj1.Pub1PropertyChanges);
            Assert.AreEqual(0, subj2.Pub1PropertyChanges);
            target.OneProperty = "Joe1";
            Assert.AreEqual(1, subj1.Pub1PropertyChanges);
            Assert.AreEqual(1, subj2.Pub1PropertyChanges);
            target.Dispose();
            target.OneProperty = "Joe2";
            Assert.AreEqual(1, subj1.Pub1PropertyChanges);
            Assert.AreEqual(1, subj2.Pub1PropertyChanges);
        }