Esempio n. 1
0
        public async Task ExecuteAsync_CanceledDuringEnter_RunsEnterAndCanceledActionsAndThrowsOperationCanceledException()
        {
            var tracker = new TestTracker();

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

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

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