Ejemplo n.º 1
0
        public void SubjectDeliversData()
        {
            var subject = new EventFlowSubject <int>();
            var obs1    = new Mock <IObserver <int> >();
            var obs2    = new Mock <IObserver <int> >();

            var s1 = subject.Subscribe(obs1.Object);
            var s2 = subject.Subscribe(obs2.Object);

            subject.OnNext(7);
            s2.Dispose();
            subject.OnNext(8);
            subject.OnCompleted();
            subject.OnNext(9);
            subject.Dispose();
            subject.OnNext(10);

            obs1.Verify(o => o.OnNext(It.IsAny <int>()), Times.Exactly(2));
            obs1.Verify(o => o.OnNext(It.Is <int>(i => i == 7)), Times.Exactly(1));
            obs1.Verify(o => o.OnNext(It.Is <int>(i => i == 8)), Times.Exactly(1));
            obs1.Verify(o => o.OnCompleted(), Times.Exactly(1));
            obs1.Verify(o => o.OnError(It.IsAny <Exception>()), Times.Exactly(0));

            obs2.Verify(o => o.OnNext(It.IsAny <int>()), Times.Exactly(1));
            obs1.Verify(o => o.OnNext(It.Is <int>(i => i == 7)), Times.Exactly(1));
            obs1.Verify(o => o.OnCompleted(), Times.Exactly(1));
            obs1.Verify(o => o.OnError(It.IsAny <Exception>()), Times.Exactly(0));
        }
Ejemplo n.º 2
0
        public void SubjectCompletesImmediatelyAfterDisposed()
        {
            var subject = new EventFlowSubject <int>();
            var obs1    = new Mock <IObserver <int> >();

            subject.Dispose();
            var s1 = subject.Subscribe(obs1.Object);

            s1.Dispose(); // No exception

            obs1.Verify(o => o.OnNext(It.IsAny <int>()), Times.Exactly(0));
            obs1.Verify(o => o.OnCompleted(), Times.Exactly(1));
            obs1.Verify(o => o.OnError(It.IsAny <Exception>()), Times.Exactly(0));
        }
Ejemplo n.º 3
0
 public void Dispose()
 {
     _listenerSubscription.Dispose();
     _listenerObserver.Dispose();
     _subject.Dispose();
 }
Ejemplo n.º 4
0
 protected override void CloseTarget()
 {
     _eventFlowSubject.Dispose();
 }