public void CanUnsubscribeNewSubscribersAfterItWasCompleted()
        {
            using (var subject = new EventEntrySubject())
            {
                subject.OnCompleted();

                var observer     = new MockObserver <int>();
                var subscription = subject.CreateSubscription(observer, entry => entry.EventId);

                subscription.Dispose();
            }
        }
        public void OnCompletedIsSentToAllNewSubscribersAfterItWasCompleted()
        {
            using (var subject = new EventEntrySubject())
            {
                subject.OnCompleted();

                var observer = new MockObserver <int>();
                subject.CreateSubscription(observer, entry => entry.EventId);

                Assert.IsTrue(observer.OnCompletedCalled);
            }
        }
        public void OnCompletedStopsPropagatingEvents()
        {
            using (var subject = new EventEntrySubject())
            {
                var observer = new MockObserver <int>();
                subject.CreateSubscription(observer, entry => entry.EventId);

                subject.OnCompleted();
                subject.OnNext(CreateEntry());

                Assert.AreEqual(0, observer.OnNextCalls.Count);
            }
        }
        public void DisposeCallsOnCompleted()
        {
            var observer = new MockObserver <int>();

            using (var subject = new EventEntrySubject())
            {
                subject.CreateSubscription(observer, entry => entry.EventId);

                Assert.IsFalse(observer.OnCompletedCalled);
            }

            Assert.IsTrue(observer.OnCompletedCalled);
        }
        public void ShouldCallOnError()
        {
            using (var subject = new EventEntrySubject())
            {
                var observer = new MockObserver <int>();
                subject.CreateSubscription(observer, entry => entry.EventId);
                var error = new Exception();
                subject.OnError(error);

                subject.OnNext(CreateEntry());

                Assert.AreSame(error, observer.OnErrorException);
                Assert.AreEqual(0, observer.OnNextCalls.Count);
            }
        }
        public void ShouldCallOnNext()
        {
            using (var subject = new EventEntrySubject())
            {
                var observer = new MockObserver <int>();

                var subscription = subject.CreateSubscription(observer, entry => entry.EventId);

                var entry1 = CreateEntry(1);
                var entry2 = CreateEntry(2);
                subject.OnNext(entry1);
                subject.OnNext(entry2);

                Assert.AreEqual(entry1.EventId, observer.OnNextCalls.ElementAt(0));
                Assert.AreEqual(entry2.EventId, observer.OnNextCalls.ElementAt(1));

                subscription.Dispose();
            }
        }