示例#1
0
        public void Error_First()
        {
            var count = 0;

            ObservableSource.Error <int>(new InvalidOperationException())
            .Concat(ObservableSource.FromFunc(() => ++ count))
            .Test()
            .AssertFailure(typeof(InvalidOperationException));

            Assert.AreEqual(0, count);
        }
        public void Other_Error_Other()
        {
            var count = 0;

            ObservableSource.FromFunc(() => ++ count)
            .DelaySubscription(ObservableSource.Error <int>(new InvalidOperationException()))
            .Test()
            .AssertFailure(typeof(InvalidOperationException));

            Assert.AreEqual(0, count);
        }
        public void Dynamic_Source()
        {
            var count = 0;

            var source = ObservableSource.FromFunc(() => ++ count) as IDynamicValue <int>;

            for (int i = 0; i < 10; i++)
            {
                var v = source.GetValue(out var success);
                Assert.True(success);
                Assert.AreEqual(i + 1, v);
            }
        }
        public void Regular_Basic()
        {
            var count = 0;

            var source = ObservableSource.FromFunc(() => ++ count);

            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual(i, count);

                source.Test().AssertResult(i + 1);

                Assert.AreEqual(i + 1, count);
            }
        }
        public void Fused_Basic()
        {
            var count = 0;

            var source = ObservableSource.FromFunc(() => ++ count);

            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual(i, count);

                source.Test(fusionMode: FusionSupport.Any)
                .AssertFuseable()
                .AssertFusionMode(FusionSupport.Async)
                .AssertResult(i + 1);

                Assert.AreEqual(i + 1, count);
            }
        }
        public void Dispose_Task()
        {
            var ts    = new TestScheduler();
            var count = 0;

            var to = ObservableSource.FromFunc(() => ++ count)
                     .SubscribeOn(ts)
                     .Test();

            to.AssertEmpty();

            Assert.True(ts.HasTasks());

            to.Dispose();

            ts.AdvanceTimeBy(1);

            Assert.AreEqual(0, count);
        }
        public void Different_Thread_Error()
        {
            var name = Thread.CurrentThread.ManagedThreadId;

            var nameOn = -1;

            ObservableSource.FromFunc <int>(() =>
            {
                nameOn = Thread.CurrentThread.ManagedThreadId;
                throw new InvalidOperationException();
            })
            .SubscribeOn(ThreadPoolScheduler.Instance)
            .Test()
            .AwaitDone(TimeSpan.FromSeconds(5))
            .AssertFailure(typeof(InvalidOperationException));

            Assert.AreNotEqual(-1, nameOn);
            Assert.AreNotEqual(name, nameOn);
        }
        public void Different_Thread()
        {
            var name = Thread.CurrentThread.ManagedThreadId;

            var nameOn = -1;

            ObservableSource.FromFunc <int>(() =>
            {
                nameOn = Thread.CurrentThread.ManagedThreadId;
                return(1);
            })
            .SubscribeOn(ThreadPoolScheduler.Instance)
            .Test()
            .AwaitDone(TimeSpan.FromSeconds(5))
            .AssertResult(1);

            Assert.AreNotEqual(-1, nameOn);
            Assert.AreNotEqual(name, nameOn);
        }
        public void Regular_Error()
        {
            var count = 0;

            var source = ObservableSource.FromFunc <int>(() =>
            {
                ++count;
                throw new InvalidOperationException();
            });

            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual(i, count);

                source.Test()
                .AssertFailure(typeof(InvalidOperationException));

                Assert.AreEqual(i + 1, count);
            }
        }
        public void Fused_Error()
        {
            var count = 0;

            var source = ObservableSource.FromFunc <int>(() =>
            {
                ++count;
                throw new InvalidOperationException();
            });

            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual(i, count);

                source.Test(fusionMode: FusionSupport.Any)
                .AssertFuseable()
                .AssertFusionMode(FusionSupport.Async)
                .AssertFailure(typeof(InvalidOperationException));

                Assert.AreEqual(i + 1, count);
            }
        }
        public void Dynamic_Source_Error()
        {
            var count = 0;

            var source = ObservableSource.FromFunc <int>(() =>
            {
                count++;
                throw new InvalidOperationException();
            }) as IDynamicValue <int>;

            for (int i = 0; i < 10; i++)
            {
                try
                {
                    source.GetValue(out var success);
                    Assert.Fail();
                }
                catch (InvalidOperationException)
                {
                    // expected
                }
            }
        }