Пример #1
0
        public void Error()
        {
            var us = new UnicastSubject <int>();

            var n0 = Thread.CurrentThread.ManagedThreadId;

            var cdl = new CountdownEvent(1);

            var n1 = default(int);

            var to = us.DoOnDispose(() =>
            {
                n1 = Thread.CurrentThread.ManagedThreadId;
                cdl.Signal();
            })
                     .UnsubscribeOn(NewThreadScheduler.Default)
                     .Test();

            us.OnNext(1);

            us.OnError(new InvalidOperationException());

            to.AssertFailure(typeof(InvalidOperationException), 1);

            Assert.True(cdl.Wait(TimeSpan.FromSeconds(5)));

            Assert.AreNotEqual(n0, n1);
        }
        public void Dispose()
        {
            var us = new UnicastSubject <int>();

            var n0 = Thread.CurrentThread.Name;

            var cdl = new CountdownEvent(1);

            var n1 = default(string);

            var to = us.DoOnDispose(() =>
            {
                n1 = Thread.CurrentThread.Name;
                cdl.Signal();
            })
                     .UnsubscribeOn(NewThreadScheduler.Default)
                     .Test();

            us.OnNext(1);

            to.AssertValuesOnly(1);

            Assert.Null(n1);

            to.Dispose();

            Assert.True(cdl.Wait(TimeSpan.FromSeconds(5)));

            Assert.AreNotEqual(n0, n1);
        }
Пример #3
0
        public void Complete()
        {
            var us = new UnicastSubject <int>();

            var n0 = Thread.CurrentThread.ManagedThreadId;

            var cdl = new CountdownEvent(1);

            var n1 = default(int);

            var to = us.DoOnDispose(() =>
            {
                n1 = Thread.CurrentThread.ManagedThreadId;
                cdl.Signal();
            })
                     .UnsubscribeOn(NewThreadScheduler.Default)
                     .Test();

            us.OnNext(1);

            us.OnCompleted();

            to.AssertResult(1);

            Assert.True(cdl.Wait(TimeSpan.FromSeconds(5)));

            Assert.AreNotEqual(n0, n1);
        }
Пример #4
0
        public void Basic()
        {
            var count = 0;

            var up = new UnicastSubject <int>();

            var d = up.DoOnDispose(() => count++).Subscribe();

            Assert.True(up.HasObserver());
            Assert.AreEqual(0, count);

            d.Dispose();

            Assert.AreEqual(1, count);

            d.Dispose();

            Assert.AreEqual(1, count);

            Assert.False(up.HasObserver());
        }