Exemplo n.º 1
0
        public void ThrowsIfCompletedTwice()
        {
            var f = new Future <object>();

            try {
                f.Complete(5);
                f.Complete(10);
                Assert.Fail();
            } catch (InvalidOperationException) {
            }
        }
Exemplo n.º 2
0
        public void FailedIsFalseIfFutureHasValue()
        {
            var f = new Future <object>();

            f.Complete(5);
            Assert.IsFalse(f.Failed);
        }
Exemplo n.º 3
0
        public void CanGetResult()
        {
            var f = new Future <object>();

            f.Complete(5);
            Assert.AreEqual(5, f.Result);
        }
Exemplo n.º 4
0
        public void CanCompleteFuture()
        {
            var f = new Future <object>();

            f.Complete();
            Assert.IsTrue(f.Completed);
        }
Exemplo n.º 5
0
        public void CanCompleteWithNull()
        {
            var f = new Future <object>();

            f.Complete();
            Assert.AreEqual(null, f.Result);
        }
Exemplo n.º 6
0
        public void InvokesOnResolvedWhenCompleted()
        {
            var    f1             = new Future <int>();
            var    f2             = new Future <int>();
            var    f3             = new Future <int>();
            object completeResult = null;
            var    handler        = (OnFutureResolved <int>)(
                (f) => {
                completeResult =
                    (f.Disposed)
                            ? "disposed"
                            : (f.Failed
                                ? f.Error
                                : (object)f.Result
                               );
            }
                );

            f1.RegisterOnResolved2(handler);
            f1.Complete(5);
            Assert.AreEqual(5, completeResult);
            f2.RegisterOnResolved2(handler);
            f2.Dispose();
            Assert.AreEqual("disposed", completeResult);
            f3.RegisterOnResolved2(handler);
            var exc = new Exception("test");

            f3.SetResult(0, exc);
            Assert.AreEqual(exc, completeResult);
        }
Exemplo n.º 7
0
        public void InvokesOnCompletesWhenCompleted()
        {
            var    f = new Future <object>();
            object completeResult = null;

            f.RegisterOnComplete((_) => { completeResult = _.Error ?? _.Result; });
            f.Complete(5);
            Assert.AreEqual(5, completeResult);
        }
Exemplo n.º 8
0
        public void IfCompletedDisposeHasNoEffect()
        {
            var f = new Future <object>();

            f.Complete(5);
            f.Dispose();
            Assert.AreEqual(5, f.Result);
            Assert.IsFalse(f.Disposed);
        }
Exemplo n.º 9
0
        public void CanBindFutureToOtherFuture()
        {
            var a = new Future <object>();
            var b = new Future <object>();

            b.Bind(a);
            a.Complete(5);
            Assert.AreEqual(5, b.Result);
        }
Exemplo n.º 10
0
        public void IfOnCompleteRegisteredAfterAlreadyCompletedCalledAnyway()
        {
            var    f = new Future <object>();
            object completeResult = null;

            f.Complete(5);
            f.RegisterOnComplete((_) => { completeResult = _.Error ?? _.Result; });
            Assert.AreEqual(5, completeResult);
        }
Exemplo n.º 11
0
        public void CannotBeCompletedIfDisposedFirst()
        {
            var f = new Future <object>();

            f.Dispose();
            Assert.IsTrue(f.Disposed);
            f.Complete(5);
            Assert.IsTrue(f.Disposed);
            Assert.IsFalse(f.Completed);
        }
Exemplo n.º 12
0
        public void FutureWrapsExceptionIfOnCompleteHandlerThrows()
        {
            var f = new Future <object>();

            f.RegisterOnComplete((_) => {
                throw new Exception("pancakes");
            });

            try {
                f.Complete(1);
                Assert.Fail("Exception was swallowed");
            } catch (FutureHandlerException fhe) {
                Assert.IsInstanceOf <Exception>(fhe.InnerException);
                Assert.AreEqual("pancakes", fhe.InnerException.Message);
            }
        }
Exemplo n.º 13
0
        public void BindToProperty()
        {
            var tc = new TestClass();
            var ts = new TestStruct();

            var f = new Future <int>();

            f.Bind(() => tc.Property);

            try {
                f.Bind(() => ts.Property);
                Assert.Fail("Did not throw InvalidOperationException");
            } catch (InvalidOperationException) {
            }

            f.Complete(5);

            Assert.AreEqual(5, tc.Property);
            Assert.AreNotEqual(5, ts.Property);
        }
Exemplo n.º 14
0
            public void OnComplete(IFuture f)
            {
                bool completed = false;

                lock (State) {
                    if (State.Count == Trigger)
                    {
                        completed = true;
                        State.Clear();
                    }
                    else
                    {
                        State.Remove(f);
                    }
                }

                if (completed)
                {
                    Composite.Complete(f);
                }
            }
Exemplo n.º 15
0
 public override void Invoke()
 {
     Future.Complete(WorkItem());
 }