public void ReplaceIfNull()
        {
            var bd1 = new BooleanDisposable();
            var bd2 = new BooleanDisposable();

            var field = default(IDisposable);

            Assert.True(DisposableHelper.ReplaceIfNull(ref field, bd1));

            Assert.False(bd1.IsDisposed());
            Assert.False(bd2.IsDisposed());

            Assert.False(DisposableHelper.ReplaceIfNull(ref field, bd2));

            Assert.False(bd1.IsDisposed());
            Assert.False(bd2.IsDisposed());

            Assert.True(DisposableHelper.Dispose(ref field));

            Assert.True(bd1.IsDisposed());
            Assert.False(bd2.IsDisposed());

            var bd3 = new BooleanDisposable();

            Assert.False(DisposableHelper.SetIfNull(ref field, bd3));

            Assert.True(bd3.IsDisposed());
        }
Esempio n. 2
0
        public void ReferenceCount()
        {
            var cs = new CompletableSubject(true);

            var bd = new BooleanDisposable();

            cs.OnSubscribe(bd);

            Assert.False(bd.IsDisposed());

            var to1 = cs.Test();

            Assert.False(bd.IsDisposed());

            var to2 = cs.Test();

            to1.Dispose();

            Assert.False(bd.IsDisposed());

            to2.Dispose();

            Assert.True(bd.IsDisposed());

            cs.Test().AssertFailure(typeof(OperationCanceledException));
        }
        public void RefCount()
        {
            var ps = new PublishSubject <int>(true);

            var d = new BooleanDisposable();

            ps.OnSubscribe(d);

            Assert.False(d.IsDisposed());

            var to = ps.Test();

            Assert.True(ps.HasObservers);

            to.Dispose();

            Assert.False(ps.HasObservers);

            Assert.True(d.IsDisposed());
        }
Esempio n. 4
0
        public void Error()
        {
            var cs = new CompletableSubject();

            Assert.False(cs.HasObserver());
            Assert.False(cs.HasCompleted());
            Assert.False(cs.HasException());
            Assert.IsNull(cs.GetException());

            var to = cs.Test();

            Assert.True(cs.HasObserver());

            to.AssertEmpty();

            var bd = new BooleanDisposable();

            cs.OnSubscribe(bd);
            cs.OnError(new InvalidOperationException());
            cs.OnError(new IndexOutOfRangeException());

            Assert.True(bd.IsDisposed());

            to.AssertFailure(typeof(InvalidOperationException));

            Assert.False(cs.HasObserver());
            Assert.False(cs.HasCompleted());
            Assert.True(cs.HasException());
            Assert.IsNotNull(cs.GetException());
            Assert.True(typeof(InvalidOperationException).IsAssignableFrom(cs.GetException()));

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

            Assert.False(cs.HasObserver());
            Assert.False(cs.HasCompleted());
            Assert.True(cs.HasException());
            Assert.IsNotNull(cs.GetException());
            Assert.True(typeof(InvalidOperationException).IsAssignableFrom(cs.GetException()));
        }
Esempio n. 5
0
        public void Basic()
        {
            var cs = new CompletableSubject();

            Assert.False(cs.HasObservers);
            Assert.False(cs.HasCompleted());
            Assert.False(cs.HasException());
            Assert.IsNull(cs.GetException());

            var to = cs.Test();

            Assert.True(cs.HasObserver());

            to.AssertEmpty();

            var bd = new BooleanDisposable();

            cs.OnSubscribe(bd);

            cs.OnCompleted();
            cs.OnError(new IndexOutOfRangeException());

            Assert.True(bd.IsDisposed());

            to.AssertResult();

            Assert.False(cs.HasObservers);
            Assert.True(cs.HasCompleted());
            Assert.False(cs.HasException());
            Assert.IsNull(cs.GetException());

            cs.Test().AssertResult();

            Assert.False(cs.HasObserver());
            Assert.True(cs.HasCompleted());
            Assert.False(cs.HasException());
            Assert.IsNull(cs.GetException());
        }