public void Race()
        {
            for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
            {
                var us = new UnicastSubject <int>();

                var to = new TestObserver <int>();

                TestHelper.Race(() =>
                {
                    for (int j = 0; j < 1000; j++)
                    {
                        us.OnNext(j);
                    }
                    us.OnCompleted();
                },
                                () =>
                {
                    foreach (var v in us.BlockingEnumerable())
                    {
                        to.OnNext(v);
                    }
                    to.OnCompleted();
                });

                to.AssertValueCount(1000)
                .AssertNoError()
                .AssertCompleted();
            }
        }
        public void Dispose()
        {
            var us = new UnicastSubject <int>();

            var en = us.BlockingEnumerable().GetEnumerator();

            Assert.True(us.HasObserver());

            en.Dispose();

            Assert.False(us.HasObserver());

            Assert.False(en.MoveNext());
        }
        public void Race_With_Error()
        {
            var exc = new InvalidOperationException();

            for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
            {
                var us = new UnicastSubject <int>();

                var to = new TestObserver <int>();

                TestHelper.Race(() =>
                {
                    for (int j = 0; j < 1000; j++)
                    {
                        us.OnNext(j);
                    }
                    us.OnError(exc);
                },
                                () =>
                {
                    try
                    {
                        foreach (var v in us.BlockingEnumerable())
                        {
                            to.OnNext(v);
                        }
                    } catch (Exception ex)
                    {
                        to.OnError(ex);
                    }
                });

                to.AssertValueCount(1000)
                .AssertError(typeof(InvalidOperationException))
                .AssertNotCompleted();
            }
        }