public async Task SuccessTest()
        {
            var tcg   = new TaskContinuationGenerator <TaskContinuationGeneratorTests, TaskContinuationGeneratorTests, Task>();
            var cTask = tcg.SetContinuation(this, GetPreviousTask(), null, CallTargetState.GetDefault());

            await cTask;

            async Task GetPreviousTask()
            {
                await Task.Delay(1000).ConfigureAwait(false);
            }
        }
示例#2
0
        public async Task CancelledTest()
        {
            // Normal
            var task = GetPreviousTask();
            await Assert.ThrowsAsync <CustomCancellationException>(() => task);

            Assert.Equal(TaskStatus.Canceled, task.Status);

            // Using the continuation
            var tcg = new TaskContinuationGenerator <TaskContinuationGeneratorTests, TaskContinuationGeneratorTests, Task>();

            task = tcg.SetContinuation(this, GetPreviousTask(), null, CallTargetState.GetDefault());
            await Assert.ThrowsAsync <CustomCancellationException>(() => task);

            Assert.Equal(TaskStatus.Canceled, task.Status);
        public async Task ExceptionGenericTest()
        {
            Exception ex = null;

            // Normal
            ex = await Assert.ThrowsAsync <CustomException>(() => GetPreviousTask());

            Assert.Equal("Internal Test Exception", ex.Message);

            // Using the continuation
            var tcg = new TaskContinuationGenerator <TaskContinuationGeneratorTests, TaskContinuationGeneratorTests, Task <bool>, bool>();

            ex = await Assert.ThrowsAsync <CustomException>(() => tcg.SetContinuation(this, GetPreviousTask(), null, CallTargetState.GetDefault()));

            Assert.Equal("Internal Test Exception", ex.Message);

            async Task <bool> GetPreviousTask()
            {
                await Task.Delay(1000).ConfigureAwait(false);

                throw new CustomException("Internal Test Exception");
            }
        }