Example #1
0
        public void OnNext_OnError_Race()
        {
            for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
            {
                var to = new TestObserver <int>();

                var s = ReactiveExtensions.ToSerialized(to);

                var ex = new InvalidOperationException();

                Action emit = () => {
                    for (int j = 0; j < 500; j++)
                    {
                        s.OnNext(j);
                    }
                };

                Action complete = () =>
                {
                    for (int j = 0; j < 250; j++)
                    {
                        s.OnNext(j);
                    }

                    s.OnError(ex);
                };

                TestHelper.Race(emit, complete);

                Assert.True(to.ItemCount >= 250);

                to.AssertError(typeof(InvalidOperationException))
                .AssertNotCompleted();
            }
        }
Example #2
0
        public void OnNext_OnError_Race()
        {
            var ex = new InvalidOperationException();

            for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
            {
                wip   = 0;
                error = null;

                var to = new TestObserver <int>();

                TestHelper.Race(() =>
                {
                    HalfSerializer.OnNext(to, 1, ref wip, ref error);
                },
                                () =>
                {
                    HalfSerializer.OnError(to, ex, ref wip, ref error);
                });

                to.AssertError(typeof(InvalidOperationException))
                .AssertNotCompleted();

                Assert.True(to.ItemCount <= 1);
            }
        }
        public void AssertError_Contains()
        {
            var to = new TestObserver <int>();

            to.OnError(new InvalidOperationException("part_of_message"));

            to.AssertError(typeof(InvalidOperationException), "_of_", true);
        }
        public void OnSuccess_After_Termination()
        {
            var to = new TestObserver <int>();

            to.OnCompleted();

            to.OnSuccess(1);

            to.AssertError(typeof(InvalidOperationException));
        }
        public void Sync_Fused_Bad_OnNext()
        {
            var to     = new TestObserver <int>(true, FusionSupport.Sync);
            var parent = new BadSyncFuseableDisposable(to);

            to.OnSubscribe(parent);

            to.AssertFuseable()
            .AssertFusionMode(FusionSupport.Sync);

            to.OnNext(1);

            Assert.AreEqual(1, to.ErrorCount);

            to.AssertError(typeof(InvalidOperationException));
        }
        public void AssertError_No_Error()
        {
            try
            {
                var to = new TestObserver <int>();

                to.AssertError(typeof(InvalidOperationException));
                Assert.Fail("Should have thrown");
            }
            catch (AssertionException)
            {
                throw;
            }
            catch (Exception ex)
            {
                var msg = ex.Message;
                Assert.True(msg.Contains("No error"));
            }
        }
        public void AssertError_Different_Exception()
        {
            var to = new TestObserver <int>();

            to.OnError(new IndexOutOfRangeException("part_of_message"));

            try
            {
                to.AssertError(typeof(InvalidOperationException), "_on_", true);
                Assert.Fail("Should have thrown");
            }
            catch (AssertionException)
            {
                throw;
            }
            catch (Exception ex)
            {
                var msg = ex.Message;
                Assert.True(msg.Contains("Exception not present"));
            }
        }
        public void AssertError_Doesnt_Contain()
        {
            var to = new TestObserver <int>();

            to.OnError(new InvalidOperationException("part_of_message"));

            try
            {
                to.AssertError(typeof(InvalidOperationException), "_on_", true);
                Assert.Fail("Should have thrown");
            }
            catch (AssertionException)
            {
                throw;
            }
            catch (Exception ex)
            {
                var msg = ex.Message;
                Assert.True(msg.Contains("Exception type present but not with the specified message"));
            }
        }