コード例 #1
0
        public void Observer_OC_SubscriberNotCalledAfterBeingRemoved()
        {
            Newspaper_OC  herald      = new Newspaper_OC("Herald");
            Subscriber_OC subscriber1 = new Subscriber_OC();

            herald.RegisterObserver(subscriber1);

            // not called before being resistered:
            herald.NewIssue("issue number 1");
            herald.UnregisterObserver(subscriber1);
            herald.NewIssue("issue number 2");
            Assert.AreEqual(1, subscriber1.LatestIssueNumber);
        }
コード例 #2
0
        public void Observer_OC_TwoSubscribers_SubcribersCalled()
        {
            Newspaper_OC  herald      = new Newspaper_OC("Herald");
            Subscriber_OC subscriber1 = new Subscriber_OC();
            Subscriber_OC subscriber2 = new Subscriber_OC();

            herald.RegisterObserver(subscriber1);
            herald.RegisterObserver(subscriber2);

            herald.NewIssue("issue number 1");
            herald.NewIssue("issue number 2");

            Assert.AreEqual(2, subscriber1.LatestIssueNumber);
            Assert.AreEqual(2, subscriber2.LatestIssueNumber);
        }
コード例 #3
0
        public void Observer_OC_SubscriberNotCalledBeforeRegistered()
        {
            Newspaper_OC  herald      = new Newspaper_OC("Herald");
            Subscriber_OC subscriber1 = new Subscriber_OC();

            // not called before being resistered:
            herald.NewIssue("issue number 1");
            Assert.AreEqual(0, subscriber1.LatestIssueNumber);
        }