public void Inner_Error_Delayed() { var subj = new Subject <int>(); var ms = new MaybeSubject <int>(); var to = subj.ConcatMap(v => ms, true).Test(); Assert.True(subj.HasObservers); Assert.False(ms.HasObserver()); subj.OnNext(1); Assert.True(subj.HasObservers); Assert.True(ms.HasObserver()); ms.OnError(new InvalidOperationException()); Assert.True(subj.HasObservers); Assert.False(ms.HasObserver()); to.AssertEmpty(); subj.OnCompleted(); to.AssertFailure(typeof(InvalidOperationException)); }
public void Max_Delayed_Race_Success_Error() { var ex = new InvalidOperationException(); for (int i = 0; i < TestHelper.RACE_LOOPS; i++) { var ms1 = new MaybeSubject <int>(); var ms2 = new MaybeSubject <int>(); var to = new[] { ms1, ms2 } .ToObservable() .FlatMap(v => v, true) .Test(); TestHelper.Race(() => { ms1.OnSuccess(1); }, () => { ms2.OnError(ex); }); to.AssertFailure(typeof(InvalidOperationException), 1); } }
public void Limited_Delayed_Dispose_Inner_Error() { for (int k = 1; k < 10; k++) { var subj = new Subject <int>(); var ms = new MaybeSubject <int>(); var to = subj.FlatMap(v => ms, true, k).Test(); Assert.True(subj.HasObservers); Assert.False(ms.HasObserver()); subj.OnNext(1); Assert.True(ms.HasObserver()); ms.OnError(new InvalidOperationException()); Assert.True(subj.HasObservers); Assert.False(ms.HasObserver()); subj.OnCompleted(); to.AssertFailure(typeof(InvalidOperationException)); } }
public void Crash_OnError() { var cs = new MaybeSubject <int>(); cs.SubscribeSafe(new FailingMaybeObserver(false, true, true, true)); Assert.True(cs.HasObserver()); cs.OnError(new InvalidOperationException("main")); }
public void Error_Dispose_Other() { var ms = new MaybeSubject <int>(); var to1 = new TestObserver <int>(); var count = 0; ms.Subscribe(v => { count = 1; }, e => { to1.Dispose(); }, () => { count = 2; }); ms.Subscribe(to1); ms.OnError(new InvalidOperationException()); to1.AssertEmpty(); Assert.AreEqual(0, count); }
public void Array_Max_Error_Dispose_Second() { var ms1 = new MaybeSubject <int>(); var ms2 = new MaybeSubject <int>(); var to = MaybeSource.ConcatEager(ms1, ms2) .Test(); Assert.True(ms1.HasObserver()); Assert.True(ms2.HasObserver()); ms2.OnError(new InvalidOperationException()); Assert.False(ms1.HasObserver()); Assert.False(ms2.HasObserver()); to.AssertFailure(typeof(InvalidOperationException)); }
public void Limited_Eager_Error_First() { var ms1 = new MaybeSubject <int>(); var ms2 = new MaybeSubject <int>(); var to = new[] { ms1, ms2 }.ToObservable() .FlatMap(v => v, maxConcurrency: 1) .Test(); Assert.True(ms1.HasObserver()); Assert.False(ms2.HasObserver()); ms1.OnError(new InvalidOperationException()); Assert.False(ms2.HasObserver()); to.AssertFailure(typeof(InvalidOperationException)); }
public void Error() { var cs1 = new MaybeSubject <int>(); var cs2 = new MaybeSubject <int>(); var to = cs1 .TakeUntil(cs2) .Test(); Assert.True(cs1.HasObserver()); Assert.True(cs2.HasObserver()); cs1.OnError(new InvalidOperationException()); Assert.False(cs1.HasObserver()); Assert.False(cs2.HasObserver()); to.AssertFailure(typeof(InvalidOperationException)); }
public void No_Timeout_Error() { var ts = new TestScheduler(); var us = new MaybeSubject <int>(); var to = us .Timeout(TimeSpan.FromSeconds(1), ts) .Test(); to.AssertEmpty(); ts.AdvanceTimeBy(100); Assert.True(us.HasObserver()); us.OnError(new InvalidOperationException()); ts.AdvanceTimeBy(900); to.AssertFailure(typeof(InvalidOperationException)); }
public void Max_Eager_Dispose_Inner_Error() { var subj = new Subject <int>(); var ms = new MaybeSubject <int>(); var to = subj.FlatMap(v => ms).Test(); Assert.True(subj.HasObservers); Assert.False(ms.HasObserver()); subj.OnNext(1); Assert.True(ms.HasObserver()); ms.OnError(new InvalidOperationException()); Assert.False(subj.HasObservers); Assert.False(ms.HasObserver()); to.AssertFailure(typeof(InvalidOperationException)); }
public void Error() { var ms = new MaybeSubject <int>(); Assert.False(ms.HasObserver()); Assert.False(ms.HasCompleted()); Assert.False(ms.HasException()); Assert.IsNull(ms.GetException()); Assert.False(ms.HasValue()); Assert.False(ms.TryGetValue(out var _)); var to = ms.Test(); Assert.True(ms.HasObserver()); Assert.False(ms.HasCompleted()); Assert.False(ms.HasException()); Assert.IsNull(ms.GetException()); Assert.False(ms.HasValue()); Assert.False(ms.TryGetValue(out var _)); to.AssertSubscribed().AssertEmpty(); ms.OnError(new InvalidOperationException()); Assert.False(ms.HasObserver()); Assert.False(ms.HasCompleted()); Assert.True(ms.HasException()); Assert.IsNotNull(ms.GetException()); Assert.True(typeof(InvalidOperationException).IsAssignableFrom(ms.GetException().GetType())); Assert.False(ms.HasValue()); Assert.False(ms.TryGetValue(out var _)); to.AssertFailure(typeof(InvalidOperationException)); ms.Test().AssertSubscribed().AssertFailure(typeof(InvalidOperationException)); ms.Test(true).AssertSubscribed().AssertEmpty(); }
public void Enumerable_Max_Error_Dispose_First() { var ms1 = new MaybeSubject <int>(); var ms2 = new MaybeSubject <int>(); var to = MaybeSource.ConcatEager( new List <IMaybeSource <int> >() { ms1, ms2 } ) .Test(); Assert.True(ms1.HasObserver()); Assert.True(ms2.HasObserver()); ms1.OnError(new InvalidOperationException()); Assert.False(ms1.HasObserver()); Assert.False(ms2.HasObserver()); to.AssertFailure(typeof(InvalidOperationException)); }
public void Enumerable_Limited_Dispose_On_Error() { var ms1 = new MaybeSubject <int>(); var ms2 = new MaybeSubject <int>(); var to = new List <IMaybeSource <int> >() { ms1, ms2 } .Merge(maxConcurrency: 2) .Test(); Assert.True(ms1.HasObserver()); Assert.True(ms2.HasObserver()); ms2.OnError(new InvalidOperationException()); Assert.False(ms1.HasObserver()); Assert.False(ms2.HasObserver()); to.AssertFailure(typeof(InvalidOperationException)); }
public void Array_Max_Dispose_On_Error() { var ms1 = new MaybeSubject <int>(); var ms2 = new MaybeSubject <int>(); var to = new[] { ms1, ms2 } .MergeAll() .Test(); Assert.True(ms1.HasObserver()); Assert.True(ms2.HasObserver()); ms2.OnError(new InvalidOperationException()); Assert.False(ms1.HasObserver()); Assert.False(ms2.HasObserver()); to.AssertFailure(typeof(InvalidOperationException)); }
public void Delayed_Switch_Error_Complete() { var subj = new Subject <MaybeSubject <int> >(); var ms1 = new MaybeSubject <int>(); var ms2 = new MaybeSubject <int>(); var ms3 = new MaybeSubject <int>(); var to = subj.SwitchMap(v => v, true).Test(); to.AssertEmpty(); subj.OnNext(ms1); Assert.True(ms1.HasObserver()); ms1.OnError(new InvalidOperationException()); to.AssertEmpty(); subj.OnNext(ms2); Assert.True(ms2.HasObserver()); subj.OnNext(ms3); Assert.False(ms2.HasObserver()); Assert.True(ms3.HasObserver()); subj.OnCompleted(); Assert.True(ms3.HasObserver()); ms3.OnCompleted(); to.AssertFailure(typeof(InvalidOperationException)); }
public void Action_Error_Async() { for (int i = 0; i < TestHelper.RACE_LOOPS; i++) { var cs = new MaybeSubject <int>(); var to = new TestObserver <int>(); var cdl = new CountdownEvent(1); Task.Factory.StartNew(() => { while (!cs.HasObserver()) { ; } cs.OnError(new InvalidOperationException()); }); cs.BlockingSubscribe(to.OnSuccess, to.OnError, to.OnCompleted); to.AssertFailure(typeof(InvalidOperationException)); } }