示例#1
0
        public void Disposed_Serialized()
        {
            var sad = new SingleAssignmentDisposable();

            ObservableSource.Create <int>(emitter =>
            {
                emitter.SetResource(sad);
            }, true)
            .Test()
            .Cancel()
            .AssertEmpty();

            Assert.True(sad.IsDisposed());
        }
示例#2
0
        public void Race()
        {
            for (int j = 0; j < TestHelper.RACE_LOOPS; j++)
            {
                var sad = new SingleAssignmentDisposable();

                var to = ObservableSource.Create <int>(emitter =>
                {
                    emitter.SetResource(sad);

                    TestHelper.Race(() =>
                    {
                        for (int i = 0; i < 1000; i++)
                        {
                            if (emitter.IsDisposed())
                            {
                                return;
                            }
                            emitter.OnNext(i);
                        }
                        emitter.OnCompleted();
                    },
                                    () =>
                    {
                        for (int i = 1000; i < 2000; i++)
                        {
                            if (emitter.IsDisposed())
                            {
                                return;
                            }
                            emitter.OnNext(i);
                        }
                        emitter.OnCompleted();
                    });
                }, true)
                         .Test()
                ;

                Assert.True(to.ItemCount >= 500, "" + to.ItemCount);
                to.AssertCompleted()
                .AssertNoError();

                Assert.True(sad.IsDisposed());
            }
        }
示例#3
0
        public void Handler_Crash()
        {
            var sad = new SingleAssignmentDisposable();

            ObservableSource.Create <int>(emitter =>
            {
                emitter.SetResource(sad);

                for (int i = 1; i < 6; i++)
                {
                    emitter.OnNext(i);
                }
                throw new InvalidOperationException();
            })
            .Test()
            .AssertFailure(typeof(InvalidOperationException), 1, 2, 3, 4, 5);

            Assert.True(sad.IsDisposed());
        }
示例#4
0
        public void Basic_Serialized()
        {
            var sad = new SingleAssignmentDisposable();

            ObservableSource.Create <int>(emitter =>
            {
                emitter.SetResource(sad);

                for (int i = 1; i < 6; i++)
                {
                    emitter.OnNext(i);
                }
                emitter.OnCompleted();
            }, true)
            .Test()
            .AssertResult(1, 2, 3, 4, 5);

            Assert.True(sad.IsDisposed());
        }