Esempio n. 1
0
        public void GetResult_Empty()
        {
            var s = new AsyncSubject <int>();

            s.OnCompleted();
            ReactiveAssert.Throws <InvalidOperationException>(() => s.GetResult());
        }
Esempio n. 2
0
            /// <summary>
            /// Gets the result produced by the observable sequence.
            /// </summary>
            /// <returns>The result produced by the observable sequence.</returns>
            public T GetResult()
            {
                if (_subject != null)
                {
                    return(_subject.GetResult());
                }

                _exception.ThrowIfNotNull();

                return(_result);
            }
            /// <summary>
            /// Gets the result produced by the observable sequence.
            /// </summary>
            /// <returns>The result produced by the observable sequence.</returns>
            public T GetResult()
            {
                if (_subject != null)
                {
                    return(_subject.GetResult());
                }

                _exception?.Throw();

                return(_result !);
            }
Esempio n. 4
0
            public void Dispose()
            {
                if (subject.IsCompleted)
                {
                    var disposable = subject.GetResult();
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }

                subject.Dispose();
            }
Esempio n. 5
0
        private void GetResult_Blocking_Throw(AsyncSubject <int> s)
        {
            Assert.IsFalse(s.IsCompleted);

            var e = new ManualResetEvent(false);

            var ex = new Exception();

            new Thread(() => { e.WaitOne(); s.OnError(ex); }).Start();

            var y = default(Exception);
            var t = new Thread(() =>
            {
                try
                {
                    s.GetResult();
                }
                catch (Exception ex_)
                {
                    y = ex_;
                }
            });

            t.Start();

            while (t.ThreadState != ThreadState.WaitSleepJoin)
            {
                ;
            }

            e.Set();
            t.Join();

            Assert.AreSame(ex, y);
            Assert.IsTrue(s.IsCompleted);
        }
Esempio n. 6
0
        private void GetResult_Blocking(AsyncSubject <int> s)
        {
            Assert.IsFalse(s.IsCompleted);

            var e = new ManualResetEvent(false);

            new Thread(() => { e.WaitOne(); s.OnNext(42); s.OnCompleted(); }).Start();

            var y = default(int);
            var t = new Thread(() => { y = s.GetResult(); });

            t.Start();

            while (t.ThreadState != ThreadState.WaitSleepJoin)
            {
                ;
            }

            e.Set();
            t.Join();

            Assert.AreEqual(42, y);
            Assert.IsTrue(s.IsCompleted);
        }
Esempio n. 7
0
        private void GetResult_Blocking_Throw(AsyncSubject<int> s)
        {
            Assert.IsFalse(s.IsCompleted);

            var e = new ManualResetEvent(false);

            var ex = new Exception();

            new Thread(() => { e.WaitOne(); s.OnError(ex); }).Start();

            var y = default(Exception);
            var t = new Thread(() =>
            {
                try
                {
                    s.GetResult();
                }
                catch (Exception ex_)
                {
                    y = ex_;
                }
            });
            t.Start();

            while (t.ThreadState != ThreadState.WaitSleepJoin)
                ;

            e.Set();
            t.Join();

            Assert.AreSame(ex, y);
            Assert.IsTrue(s.IsCompleted);
        }
Esempio n. 8
0
        private void GetResult_Blocking(AsyncSubject<int> s)
        {
            Assert.IsFalse(s.IsCompleted);

            var e = new ManualResetEvent(false);

            new Thread(() => { e.WaitOne(); s.OnNext(42); s.OnCompleted(); }).Start();

            var y = default(int);
            var t = new Thread(() => { y = s.GetResult(); });
            t.Start();

            while (t.ThreadState != ThreadState.WaitSleepJoin)
                ;

            e.Set();
            t.Join();

            Assert.AreEqual(42, y);
            Assert.IsTrue(s.IsCompleted);
        }
Esempio n. 9
0
 public void GetResult_Empty()
 {
     var s = new AsyncSubject<int>();
     s.OnCompleted();
     ReactiveAssert.Throws<InvalidOperationException>(() => s.GetResult());
 }