Esempio n. 1
0
        public void OnSuccessAborted()
        {
            var token  = new AsyncToken <TestResult>();
            var called = false;

            token.OnSuccess(_ => called = true);
            token.Abort();
            token.Succeed(new TestResult());
            token.OnSuccess(_ => called = true);

            Assert.IsFalse(called);
        }
Esempio n. 2
0
        public void MultiOrderedOnSuccessCalled()
        {
            var token = new AsyncToken <TestResult>();

            var successACalled = false;
            var successBCalled = false;
            var successCCalled = false;

            token
            .OnSuccess(result => successACalled = true)
            .OnSuccess(result =>
            {
                Assert.IsTrue(successACalled);

                successBCalled = true;
            })
            .OnSuccess(result =>
            {
                Assert.IsTrue(successACalled);
                Assert.IsTrue(successBCalled);

                successCCalled = true;
            });
            token.Succeed(new TestResult());

            Assert.IsTrue(successCCalled);
        }
Esempio n. 3
0
        public void OnSuccessNotCalledAfterResolved()
        {
            var token  = new AsyncToken <TestResult>();
            var called = false;

            token.Fail(new Exception());
            token.OnSuccess(_ => called = true);

            Assert.IsFalse(called);
        }
Esempio n. 4
0
        public void OnSuccessCalledAfterResolved()
        {
            var token  = new AsyncToken <TestResult>();
            var called = false;

            token.Succeed(new TestResult());
            token.OnSuccess(_ => called = true);

            Assert.IsTrue(called);
        }
Esempio n. 5
0
        public void AbortInCallbackNotRespected()
        {
            var token  = new AsyncToken <TestResult>();
            var called = false;

            token
            .OnSuccess(_ => token.Abort())
            .OnSuccess(_ => called = true)
            .OnFinally(_ => called = true);
            token.Succeed(new TestResult());

            Assert.IsTrue(called);
        }
Esempio n. 6
0
        public void OnFinallyCalledInOrderOnSuccess()
        {
            var token         = new AsyncToken <TestResult>();
            var successCalled = false;
            var finallyCalled = false;

            token
            .OnSuccess(_ => successCalled = true)
            .OnFinally(_ =>
            {
                Assert.IsTrue(successCalled);

                finallyCalled = true;
            });
            token.Succeed(new TestResult());

            Assert.IsTrue(finallyCalled);
        }
Esempio n. 7
0
        public void OnSuccessCalledExclusively()
        {
            var token         = new AsyncToken <TestResult>();
            var value         = new TestResult();
            var successCalled = false;
            var failureCalled = false;

            token
            .OnSuccess(returnedValue =>
            {
                successCalled = true;

                Assert.AreSame(value, returnedValue);
            })
            .OnFailure(exception =>
            {
                failureCalled = true;
            });
            token.Succeed(value);

            Assert.IsTrue(successCalled);
            Assert.IsFalse(failureCalled);
        }
        public async Task TaskSuccess()
        {
            var token = new AsyncToken <float>();

            var callbackResult = 0f;

            token.OnSuccess(val => callbackResult = val);

            var taskResult = 0f;
            var task       = token
                             .AsTask()
                             .ContinueWith(cTask =>
            {
                taskResult = cTask.Result;
            });

            var expectedValue = 2.26f;

            token.Succeed(expectedValue);
            await task;

            Assert.AreEqual(expectedValue, callbackResult);
            Assert.AreEqual(expectedValue, taskResult);
        }