public void Then_Should_Throw_Exception_After_Tasks_Fail()
        {
            var exceptionToThrow = new ArgumentNullException();
            var firstTask        = new PandaTask();
            var secondTask       = new PandaTask();

            var continiueTask = firstTask.Then(() => secondTask).Fail(_ => throw exceptionToThrow);

            Assert.IsNull(continiueTask.Error);

            Exception finalException = null;

            try
            {
                secondTask.Reject();
                firstTask.Reject();
            }
            catch (Exception e) when(e is ArgumentNullException nullException)
            {
                finalException = nullException;
            }

            Assert.That(exceptionToThrow, Is.EqualTo(finalException));
            Assert.IsAssignableFrom <TaskRejectedException>(continiueTask.Error);
        }
        public void ThenWithTaskTest()
        {
            //arrange
            Func <IPandaTask> expectedCallback = () => null;

            //act
            IPandaTask newtask      = _task.Then(expectedCallback);
            var        castedTask   = newtask as ContinuationTaskFromPandaTask;
            var        realCallback = RuntimeReflection.GetValue <Func <IPandaTask>, ContinuationTaskFromPandaTask>(@"_nextActionDelegate", castedTask);

            //assert
            Assert.NotNull(castedTask);
            Assert.False(castedTask.FromCatch);

            Assert.AreEqual(expectedCallback, realCallback);
        }
        public void Then_Should_Throw_Exception_After_Tasks_Resolve()
        {
            var firstTask  = new PandaTask();
            var secondTask = new PandaTask();

            var continiueTask = firstTask.Then(() => secondTask).Done(() => throw new ArgumentNullException());

            Assert.Throws <ArgumentNullException>(() =>
            {
                secondTask.Resolve();
                firstTask.Resolve();
            });

            Assert.IsNull(continiueTask.Error);
        }
        public void Then_Should_Save_Exception_In_Stack_After_Tasks_Fail()
        {
            var rejectException = new Exception("some text");
            var firstTask       = new PandaTask();
            var secondTask      = new PandaTask();

            var continiueTask = firstTask.Then(() => secondTask).Fail(_ => throw new ArgumentNullException());

            try
            {
                secondTask.Reject(rejectException);
                firstTask.Reject(rejectException);
            }
            catch {}

            Assert.That(continiueTask.Error, Is.EqualTo(rejectException));
        }
        public void ThenResultRejectFirstTest()
        {
            //arrange
            var firstTask = new PandaTask();
            var nextTask  = new PandaTask <int>();

            IPandaTask <int> resultTask = firstTask.Then(() => nextTask);

            //act
            var testError = new Exception();

            firstTask.Reject(testError);

            //assert
            Assert.AreEqual(PandaTaskStatus.Rejected, resultTask.Status);
            Assert.AreEqual(testError, resultTask.Error);
        }
        public void ThenResultResolveTest()
        {
            //arrange
            var firstTask = new PandaTask();
            var nextTask  = new PandaTask <int>();

            IPandaTask <int> resultTask = firstTask.Then(() => nextTask);

            //act
            firstTask.Resolve();
            const int testValue = 1;

            nextTask.SetValue(testValue);

            //assert
            Assert.AreEqual(PandaTaskStatus.Resolved, resultTask.Status);
            Assert.AreEqual(testValue, resultTask.Result);
        }