Ejemplo n.º 1
0
 public void Basic()
 {
     MaybeSource.Never <int>()
     .Test()
     .AssertSubscribed()
     .AssertEmpty();
 }
Ejemplo n.º 2
0
 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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        public void Enumerable_Null_Entry()
        {
            var src = MaybeSource.Never <int>();

            new List <IMaybeSource <int> >()
            {
                src,
                src,
                null,
                src,
                src
            }
            .Amb()
            .Test()
            .AssertFailure(typeof(NullReferenceException));
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
0
        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();
        }