Пример #1
0
        public void TestOnCompleted()
        {
            int sum = 0;

            PubSubSubject <int> subject = new PubSubSubject <int>();

            subject.Subscribe(Observer.Create <int>(x => sum += x));

            subject.OnNext(10);
            Assert.Equal(10, sum);

            subject.OnNext(10);
            Assert.Equal(20, sum);

            // Check that after calling OnCompleted, OnNext will do nothing
            subject.OnCompleted();
            subject.OnNext(10);
            Assert.Equal(20, sum);
        }
Пример #2
0
        public void TestPubSubSubjectSingleThread()
        {
            int sum = 0;

            // Observer that adds sum of numbers up to and including x
            PubSubSubject<int> subject = new PubSubSubject<int>();
            subject.Subscribe(Observer.Create<int>(
                x =>
                {
                    for (int i = 0; i <= x; i++)
                    {
                        sum += i;
                    }
                }));

            subject.OnNext(10);
            subject.OnCompleted();
            Assert.Equal(sum, 55);
        }
Пример #3
0
        public void TestPubSubSubjectSingleThread()
        {
            int sum = 0;

            // Observer that adds sum of numbers up to and including x
            PubSubSubject <int> subject = new PubSubSubject <int>();

            subject.Subscribe(Observer.Create <int>(
                                  x =>
            {
                for (int i = 0; i <= x; i++)
                {
                    sum += i;
                }
            }));

            subject.OnNext(10);
            subject.OnCompleted();
            Assert.Equal(sum, 55);
        }
Пример #4
0
        public void TestOnCompleted()
        {
            int sum = 0;

            PubSubSubject<int> subject = new PubSubSubject<int>();
            subject.Subscribe(Observer.Create<int>(x => sum += x));

            subject.OnNext(10);
            Assert.Equal(10, sum);

            subject.OnNext(10);
            Assert.Equal(20, sum);

            // Check that after calling OnCompleted, OnNext will do nothing
            subject.OnCompleted();
            subject.OnNext(10);
            Assert.Equal(20, sum);
        }