public void DoubleSetValueTest()
        {
            //arrange
            var testTask = new PandaTask <int>();

            testTask.SetValue(0);

            //act-assert
            Assert.Throws <InvalidOperationException>(() => testTask.SetValue(0));
        }
        public void SetValueTest()
        {
            //arrange
            var testTask = new PandaTask <int>();

            int callbackResult = 0;

            testTask.Done(x => callbackResult = x);

            bool rejected = false;

            testTask.Fail(x => rejected = true);

            //act
            const int testValue = 32;

            testTask.SetValue(testValue);

            //assert
            Assert.False(rejected);
            Assert.Null(testTask.Error);
            Assert.AreEqual(testValue, callbackResult);
            Assert.AreEqual(testValue, testTask.Result);
            Assert.AreEqual(PandaTaskStatus.Resolved, testTask.Status);
        }
        public void SetValueTest()
        {
            //arrange
            PandaTask <int> testTask = ConstructTask <int, int>();

            //act-assert
            Assert.Throws <InvalidOperationException>(() => testTask.SetValue(42));
        }
        public void RejectAfterSetTest()
        {
            //arrange
            var testTask = new PandaTask <int>();

            testTask.SetValue(0);

            //act-assert
            Assert.Throws <InvalidOperationException>(testTask.Reject);
        }
        public void ChainCatchTest()
        {
            //arrange
            var testTask   = new PandaTask <int>();
            var testTask2  = new PandaTask <int>();
            var resultTask = testTask.Catch(x => testTask2);

            //act
            const int testValue = 1;

            testTask.SetValue(testValue);

            //assert
            Assert.AreEqual(testValue, resultTask.Result);
        }
        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);
        }
        public void ResolveFromRejectTest()
        {
            //arrange
            var firstTask  = new PandaTask <int>();
            var secondTask = new PandaTask <int>();

            const int       realResult = 3;
            PandaTask <int> testTask   = ConstructTask(firstTask, true, () =>
            {
                secondTask.SetValue(realResult);
                return(secondTask);
            });

            //act
            firstTask.Reject();

            //assert
            Assert.AreEqual(realResult, testTask.Result);
            Assert.AreEqual(PandaTaskStatus.Resolved, testTask.Status);
        }
        public void ResolveTaskTest()
        {
            //arrange
            var firstTask  = new PandaTask <int>();
            var secondTask = new PandaTask <int>();

            const int       offset   = 3;
            PandaTask <int> testTask = ConstructTask(firstTask, false, () =>
            {
                secondTask.SetValue(firstTask.Result + offset);
                return(secondTask);
            });

            //act
            firstTask.Resolve();

            //assert
            Assert.AreEqual(firstTask.Result + offset, testTask.Result);
            Assert.AreEqual(PandaTaskStatus.Resolved, testTask.Status);
        }
        public void RejectResultTest()
        {
            //arrange
            var firstTask  = new PandaTask <int>();
            var secondTask = new PandaTask <int>();

            const int       realResult     = 3;
            bool            callbackCalled = false;
            PandaTask <int> testTask       = new ContinuationTaskFromPandaTask <int>(firstTask, () =>
            {
                callbackCalled = true;
                return(secondTask);
            }, true);

            //act
            firstTask.SetValue(realResult);

            //assert
            Assert.False(callbackCalled);
            Assert.AreEqual(realResult, testTask.Result);
            Assert.AreEqual(PandaTaskStatus.Resolved, testTask.Status);
        }