예제 #1
0
        public void ShouldCallDoneRegisteredBeforeResolved()
        {
            var deferred = new Deferred <TWrapper <int> >();
            var callback = new DoneCallback <TWrapper <int> >();

            deferred.Done(callback.Create());
            deferred.Resolve(3.Wrap());
            Assert.That(deferred.IsResolved, Is.True);
            Assert.That(callback.IsCalled, Is.True);
            Assert.That(callback.Result.val, Is.EqualTo(3));
        }
예제 #2
0
        public void ExceptionThrownInDoneShouldBeReportedToSinkExceptionHandler()
        {
            Promises.ResetSinkExceptionHandler(e => exceptions.Add(e));
            var source = new Deferred <TWrapper <int> > ();

            source.Done(_ => {
                throw new Exception();
            });
            source.Done(_ => {
                throw new Exception();
            });
            source.Resolve(1.Wrap());
            source.Done(_ => {
                throw new Exception();
            });
            source.Done(_ => {
                throw new Exception();
            });
            Assert.That(exceptions.Count, Is.EqualTo(4));
        }
예제 #3
0
        public void FailCallbackTest()
        {
            CallCounter counter = new CallCounter();
            Deferred<None> d = new Deferred<None>();

            d.Done(p =>
                counter.Done++
            ).Fail(p =>
                counter.Fail++
            ).Progress(p =>
                counter.Progress++
            );

            d.Reject();

            Assert.AreEqual(0, counter.Done);
            Assert.AreEqual(1, counter.Fail);
            Assert.AreEqual(0, counter.Progress);
        }
예제 #4
0
        public void NextCallBackTest()
        {
            CallCounter counter = new CallCounter();
            Deferred<None> d = new Deferred<None>();

            d.Done(p =>
                counter.Done++
            ).Next<None>(df => {
                Assert.AreEqual(1, counter.Done);
                counter.Next++;
                df.Reject();
            }).Fail(p =>
                counter.Fail++
            ).Next<None>(df =>
                counter.Next++
            );

            d.Resolve();
            Assert.AreEqual(1, counter.Done);
            Assert.AreEqual(1, counter.Fail);
            Assert.AreEqual(1, counter.Next);
        }
예제 #5
0
        public void GetResultTest()
        {
            CallCounter counter = new CallCounter();
            Deferred<System.String> d = new Deferred<System.String>();

            d.Done(p => {
                Assert.AreEqual("UniDeffered", p.GetResult<System.String>());
                counter.Done++;
            });

            d.Resolve("UniDeffered");
            Assert.AreEqual(1, counter.Done);
        }