예제 #1
0
        public async Task BotPolicyTest_ExecuteAsync_Func_Task_Result()
        {
            var policy  = new BotPolicy <int>();
            var mockBot = this.CreateMockBot(policy);

            var source = new CancellationTokenSource();

            await policy.ExecuteAsync((ctx, t) => Task.FromResult(0), source.Token);

            mockBot.Verify(m => m.ExecuteAsync(It.IsAny <IAsyncBotOperation <int> >(), It.IsAny <ExecutionContext>(), source.Token));
        }
예제 #2
0
        public async Task BotPolicyTest_ExecuteAsync_Action()
        {
            var policy  = new BotPolicy();
            var mockBot = this.CreateMockBot(policy);

            var source = new CancellationTokenSource();

            await policy.ExecuteAsync((ctx, t) => { }, source.Token);

            mockBot.Verify(m => m.ExecuteAsync(It.IsAny <IAsyncBotOperation>(), It.IsAny <ExecutionContext>(), source.Token));
        }
예제 #3
0
        public async Task BotPolicyTest_ExecuteAsync_Func_Task_Result_Without_Parameters()
        {
            var policy  = new BotPolicy <int>();
            var mockBot = this.CreateMockBot(policy);

            mockBot.Setup(m => m.ExecuteAsync(It.IsAny <IAsyncBotOperation <int> >(), It.IsAny <ExecutionContext>(), CancellationToken.None))
            .Callback <IAsyncBotOperation <int>, ExecutionContext, CancellationToken>((op, ctx, t) => op.ExecuteAsync(ctx, t))
            .Returns(Task.FromResult(0))
            .Verifiable();

            await policy.ExecuteAsync(() => Task.FromResult(0));
        }
예제 #4
0
        public async Task BotPolicyTest_ExecuteAsync_Func_Task_Result_Without_Parameters_With_CorrelationId()
        {
            var policy        = new BotPolicy <int>();
            var mockBot       = this.CreateMockBot(policy);
            var correlationId = new object();

            mockBot.Setup(m => m.ExecuteAsync(It.IsAny <IAsyncBotOperation <int> >(), It.IsAny <ExecutionContext>(), CancellationToken.None))
            .Callback <IAsyncBotOperation <int>, ExecutionContext, CancellationToken>((o, ctx, t) => Assert.AreEqual(correlationId, ctx.CorrelationId))
            .Returns(Task.FromResult(0))
            .Verifiable();

            await policy.ExecuteAsync(() => Task.FromResult(0), correlationId);
        }