Пример #1
0
        public async Task OnRequestAsync_Parameter_Timespan_Test()
        {
            var apiAction = new ApiActionDescriptor(typeof(ITestApi).GetMethod("PostAsync"));
            var context   = new TestRequestContext(apiAction, 5);

            var attr = new TimeoutAttribute();

            var parameterContext = new ApiParameterContext(context, 0);
            await attr.OnRequestAsync(parameterContext, () => Task.CompletedTask);

            await Task.Delay(20);

            var canceled = context.CancellationTokens[0].IsCancellationRequested;

            Assert.True(canceled);

            context.Arguments[0] = Guid.NewGuid();

            await Assert.ThrowsAsync <HttpApiInvalidOperationException>(()
                                                                        => attr.OnRequestAsync(parameterContext, () => Task.CompletedTask));

            context.Arguments[0] = null;

            await attr.OnRequestAsync(parameterContext, () => Task.CompletedTask);

            Assert.True(context.CancellationTokens.Count == 1);
        }
Пример #2
0
        public async Task OnRequestAsync()
        {
            var apiAction = new ApiActionDescriptor(typeof(ITestApi).GetMethod("PostAsync"));
            var context   = new TestRequestContext(apiAction, 10);

            var attr = new TimeoutAttribute(50);
            await attr.OnRequestAsync(context);

            await Task.Delay(100);

            var canceled = context.CancellationTokens[0].IsCancellationRequested;

            Assert.True(canceled);
        }
Пример #3
0
        public async Task OnRequestAsync_Parameter_Double_Test()
        {
            var apiAction = new ApiActionDescriptor(typeof(ITestApi).GetMethod("PostAsync"));
            var context   = new TestRequestContext(apiAction, 1);

            var attr             = new TimeoutAttribute();
            var parameterContext = new ApiParameterContext(context, 0);
            await attr.OnRequestAsync(parameterContext, () => Task.CompletedTask);

            await Task.Delay(20);

            var canceled = context.CancellationTokens[0].IsCancellationRequested;

            Assert.True(canceled);
        }