public void Basic() { MaybeSource.Never <int>() .Test() .AssertSubscribed() .AssertEmpty(); }
public void Dispose_Cleanup_Crash() { MaybeSource.Using(() => 1, v => MaybeSource.Never <int>(), v => { throw new InvalidOperationException(); }, false ) .Test() .Cancel() .AssertEmpty(); }
public void OnDispose_Basic() { var count = 0; MaybeSource.Never <int>() .DoOnDispose(() => count++) .Test(true) .AssertEmpty(); Assert.AreEqual(1, count); }
public void Resource_Supplier_Crash() { var cleanup = -1; var run = 0; MaybeSource.Using <int, int>(() => { throw new InvalidOperationException(); }, v => { run = 1; return(MaybeSource.Never <int>()); }, v => cleanup = run ) .Test() .AssertFailure(typeof(InvalidOperationException)); Assert.AreEqual(-1, cleanup); Assert.AreEqual(0, run); }
public void Dispose() { var cleanup = -1; var run = 0; MaybeSource.Using(() => 1, v => MaybeSource.Never <int>(), v => cleanup = run ) .DoOnCompleted(() => run = 1) .Test() .Dispose(); Assert.AreEqual(0, cleanup); Assert.AreEqual(0, run); }
public void Enumerable_Null_Entry() { var src = MaybeSource.Never <int>(); new List <IMaybeSource <int> >() { src, src, null, src, src } .Amb() .Test() .AssertFailure(typeof(NullReferenceException)); }
public void Array_Null_Entry() { var src = MaybeSource.Never <int>(); new[] { src, src, null, src, src } .Amb() .Test() .AssertFailure(typeof(NullReferenceException)); }
public void OnDispose_Crash() { var count = 0; MaybeSource.Never <int>() .DoOnDispose(() => { count++; throw new InvalidOperationException(); }) .Test(true) .AssertEmpty(); ; Assert.AreEqual(1, count); }
public void Array_Second_Wins_Success() { var count = 0; var m = MaybeSource.FromFunc <int>(() => ++ count); new[] { MaybeSource.Never <int>(), m } .AmbAll() .Test() .AssertResult(1); Assert.AreEqual(1, count); }
public void Enumerable_Second_Wins_Empty() { var count = 0; var m = MaybeSource.FromAction <int>(() => ++ count); new List <IMaybeSource <int> >() { MaybeSource.Never <int>(), m } .Amb() .Test() .AssertResult(); Assert.AreEqual(1, count); }
public void Array_Second_Wins_Error() { var count = 0; var m = MaybeSource.FromFunc <int>(() => { count++; throw new InvalidOperationException(); }); MaybeSource.Amb( MaybeSource.Never <int>(), m ) .Test() .AssertFailure(typeof(InvalidOperationException)); Assert.AreEqual(1, count); }
public void Dispose() { var name = ""; var cdl = new CountdownEvent(1); MaybeSource.Never <int>() .DoOnDispose(() => { name = Thread.CurrentThread.Name; cdl.Signal(); }) .UnsubscribeOn(NewThreadScheduler.Default) .Test() .Dispose(); Assert.True(cdl.Wait(5000)); Assert.AreNotEqual("", name); Assert.AreNotEqual(Thread.CurrentThread.Name, name); }
public void Enumerable_Many() { var list = new List <IMaybeSource <int> >(); for (int i = 0; i < 100; i++) { if (i != 99) { list.Add(MaybeSource.Never <int>()); } else { list.Add(MaybeSource.Just(1)); } } list .Amb() .Test() .AssertResult(1); }
public void Dispose_Fallback() { var ts = new TestScheduler(); var us = new MaybeSubject <int>(); var to = MaybeSource.Never <int>() .Timeout(TimeSpan.FromSeconds(1), ts, us) .Test(); ts.AdvanceTimeBy(100); Assert.False(us.HasObserver()); ts.AdvanceTimeBy(900); Assert.True(us.HasObserver()); to.Dispose(); Assert.False(us.HasObserver()); to.AssertEmpty(); }