示例#1
0
        public async Task ExecuteAsync_CanceledDuringExit_RunsEnterAndExitActionsAndThrowsOperationCanceledException()
        {
            var tracker = new TestTracker();

            using (var cts = new CancellationTokenSource())
            {
                var state = A.Fake <RuntimeStateBase>(builder =>
                                                      builder
                                                      .WithArgumentsForConstructor(new object[]
                {
                    "test",
                    tracker.StateEnterAction,
                    new Func <string, Task>(async s =>
                    {
                        await tracker.StateExitAction(s);
                        cts.Cancel();
                    }),
                    tracker.StateCanceledAction,
                })
                                                      .CallsBaseMethods());

                await Assert.ThrowsAsync <OperationCanceledException>(async() => await state.ExecuteAsync(cts.Token));
            }

            Assert.Equal(">test;<test;", tracker.ToString());
        }