コード例 #1
0
        public void Task_Finally_Action__CancelledByFirst()
        {
            var source = new CancellationTokenSource();
            var token  = source.Token;
            var syncer = new CatchTest.Syncer();

            var mock = new Mock <IAfter>();

            Task task = SimpleTaskFactory
                        .Run(() =>
            {
                syncer.Step(1);
                syncer.Step(4);
                token.ThrowIfCancellationRequested();
            }, token)
                        .Finally(() => mock.Object.NextAction());

            syncer.Step(2);
            source.Cancel();
            syncer.Step(3);

            try
            {
                task.Wait();
                Assert.Fail("task must bubble up the exception");
            }
            catch (AggregateException e)
            {
                Assert.IsInstanceOf <OperationCanceledException>(e.InnerException);
                mock.Verify(then => then.NextAction(), Times.Once);
                Assert.Pass();
            }
        }
コード例 #2
0
ファイル: FinallyTest.cs プロジェクト: jrgcubano/NAsync
        public void Task_Finally_Action__CancelledByFirst()
        {
            var source = new CancellationTokenSource();
            var token = source.Token;
            var syncer = new CatchTest.Syncer();

            var mock = new Mock<IAfter>();

            Task task = SimpleTaskFactory
                .Run(() =>
                {
                    syncer.Step(1);
                    syncer.Step(4);
                    token.ThrowIfCancellationRequested();
                }, token)
                .Finally(() => mock.Object.NextAction());

            syncer.Step(2);
            source.Cancel();
            syncer.Step(3);

            try
            {
                task.Wait();
                Assert.Fail("task must bubble up the exception");
            }
            catch (AggregateException e)
            {
                Assert.IsInstanceOf<OperationCanceledException>(e.InnerException);
                mock.Verify(then => then.NextAction(), Times.Once);
                Assert.Pass();
            }

        }