public void DoubleResolveTest()
        {
            //arrange
            var task = new PandaTask();

            task.Resolve();

            //act-assert
            Assert.Throws <InvalidOperationException>(task.Resolve);
        }
        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 RejectFromCatchReolveTest()
        {
            //arrange
            PandaTask nextTask = new PandaTask();
            Tuple <ContinuationTaskFromPandaTask, PandaTask> taskPair = ConstructTask(true, () => nextTask);

            taskPair.Item2.Reject( );

            //act
            nextTask.Resolve();

            //assert
            Assert.Null(taskPair.Item1.Error);
            Assert.AreEqual(PandaTaskStatus.Resolved, taskPair.Item1.Status);
        }
Exemplo n.º 4
0
        public void ResolveAfterDisposeTest()
        {
            //arrange
            var innerTask = new PandaTask();
            var task      = new WhenAllPandaTask(new[] { innerTask }, CancellationStrategy.Aggregate);

            task.Dispose();

            //act
            innerTask.Resolve();

            //assert
            Assert.AreEqual(PandaTaskStatus.Rejected, task.Status);
            Assert.IsInstanceOf <ObjectDisposedException>(task.Error.GetBaseException());
        }
        public void MultipleDoneTest(int callbackCount)
        {
            //arrange
            bool[] done = new bool[callbackCount];
            for (int i = 0; i < done.Length; i++)
            {
                int index = i;
                _task.Done(() => done[index] = true);
            }

            //act
            _task.Resolve();

            //assert
            Assert.True(done.All(x => x));
        }
        public void ThenResultRejectSecondTest()
        {
            //arrange
            var firstTask = new PandaTask();
            var nextTask  = new PandaTask <int>();

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

            //act
            firstTask.Resolve();
            var testError = new Exception();

            nextTask.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);
        }
        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);
        }
Exemplo n.º 9
0
        public void ChangeCollectionCompleteErrorTest()
        {
            //arrange
            var source = new PandaTask();
            var tasks  = new List <IPandaTask>
            {
                PandaTasksUtilities.CompletedTask,
                source
            };

            var allTask = new WhenAllPandaTask(tasks, CancellationStrategy.Aggregate);

            tasks.Add(PandaTasksUtilities.CanceledTask);

            //act
            source.Resolve();

            //assert
            Assert.AreEqual(PandaTaskStatus.Resolved, allTask.Status);
        }
        public void ResolveSecondTest()
        {
            //arrange
            PandaTask nextTask = new PandaTask();
            Tuple <ContinuationTaskFromPandaTask, PandaTask> taskPair = ConstructTask(false, () => nextTask);

            bool doneCall  = false;
            bool catchCall = false;

            taskPair.Item1.Done(() => doneCall = true).Fail(ex => catchCall = true);

            taskPair.Item2.Resolve();

            //act
            nextTask.Resolve();

            //assert
            Assert.True(doneCall);
            Assert.False(catchCall);

            Assert.Null(taskPair.Item1.Error);
            Assert.AreEqual(taskPair.Item1.Status, PandaTaskStatus.Resolved);
        }