Esempio n. 1
0
        public void NotificationTest()
        {
            var subj1  = new SubscriberSubject1();
            var target = subj1.Publisher1;

            subj1.SubscribePublisher1();
            Assert.AreEqual(0, subj1.Pub1PropertyChanges);
            target.OneProperty = string.Empty;
            Assert.AreEqual(1, subj1.Pub1PropertyChanges);
        }
Esempio n. 2
0
        public void SubscriptionCountsTest2()
        {
            var subj1  = new SubscriberSubject1();
            var target = subj1.Publisher1;

            subj1.SubscribePublisher1();
            Assert.AreEqual(1, target.GetMethodsNamesList().Count());
            target.Dispose();
            Assert.AreEqual(0, target.GetMethodsNamesList().Count());
        }
Esempio n. 3
0
        public void InstantiateADisposableObservableObject()
        {
            var subj1  = new SubscriberSubject1();
            var target = subj1.Publisher1;

            Assert.IsNotNull(subj1);
            Assert.IsFalse(target.GetInvocationList().Any());
            subj1.SubscribePublisher1();
            Assert.IsTrue(target.GetInvocationList().Any());
            Assert.AreEqual(1, target.GetInvocationList().Count());
        }
Esempio n. 4
0
        public void SubscriptionTest1()
        {
            var subj1  = new SubscriberSubject1();
            var target = subj1.Publisher1;

            subj1.SubscribePublisher1();
            Assert.AreEqual(0, subj1.Pub1PropertyChanges);
            target.OneProperty = "Joe1";
            Assert.AreEqual(1, subj1.Pub1PropertyChanges);
            target.OneProperty = "Joe2";
            Assert.AreEqual(2, subj1.Pub1PropertyChanges);
        }
Esempio n. 5
0
        public void UnsubscribedTest2()
        {
            var subj1  = new SubscriberSubject1();
            var target = subj1.Publisher1;

            subj1.SubscribePublisher1();
            Assert.AreEqual(0, subj1.Pub1PropertyChanges);
            target.OneProperty = "Joe1";
            Assert.AreEqual(1, subj1.Pub1PropertyChanges);
            target.Dispose();
            //target = new PublisherSubject1();
            target.OneProperty = "Joe2";
            Assert.AreEqual(1, subj1.Pub1PropertyChanges);
        }
Esempio n. 6
0
        public void NullSetTest1()
        {
            var subj1 = new SubscriberSubject1();

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

            Assert.AreEqual(target.GetHashCode(), subj1.Publisher1.GetHashCode());
            subj1.SubscribePublisher1();
            Assert.AreEqual(1, target.GetInvocationList().Count());
            subj1.Publisher1.Dispose();
            subj1.Publisher1 = null;
            Assert.AreEqual(0, target.GetInvocationList().Count());
        }
Esempio n. 7
0
        public void SubscriptionDisposingEventTest2()
        {
            var subj1  = new SubscriberSubject1();
            var target = subj1.Publisher1;

            subj1.SubscribePublisher1();
            Assert.AreEqual(1, target.GetMethodsNamesList().Count());
            var cancelHandlerInvoked   = false;
            CancelEventHandler handler = (s, e) => { cancelHandlerInvoked = true; e.Cancel = true; };

            subj1.Publisher1.DisposingHandlers += handler;
            target.Dispose();
            Assert.IsTrue(cancelHandlerInvoked);
            Assert.AreEqual(1, target.GetMethodsNamesList().Count());
        }
Esempio n. 8
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());
        }
Esempio n. 9
0
        public void UnsubscribedTest3()
        {
            var subj1Instance1 = new SubscriberSubject1();
            var subj1Instance2 = new SubscriberSubject1();
            var target         = subj1Instance1.Publisher1 = subj1Instance2.Publisher1 = new PublisherSubject1();

            subj1Instance1.SubscribePublisher1();
            subj1Instance2.SubscribePublisher1();
            Assert.AreEqual(0, subj1Instance1.Pub1PropertyChanges);
            Assert.AreEqual(0, subj1Instance2.Pub1PropertyChanges);
            target.OneProperty = "Joe1";
            Assert.AreEqual(1, subj1Instance1.Pub1PropertyChanges);
            Assert.AreEqual(1, subj1Instance2.Pub1PropertyChanges);
            subj1Instance1.UnSubscribePublisher1();
            target.OneProperty = "Joe2";
            Assert.AreEqual(1, subj1Instance1.Pub1PropertyChanges);
            Assert.AreEqual(2, subj1Instance2.Pub1PropertyChanges);
        }
Esempio n. 10
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);
        }