Beispiel #1
0
        public async Task BeforeRequestAsync_Parameter_Timespan_Test()
        {
            var context = new TestActionContext(
                httpApi: null,
                httpApiConfig: new HttpApiConfig(),
                apiActionDescriptor: new ApiActionDescriptor(typeof(IMyApi).GetMethod("PostAsync")));

            IApiParameterAttribute attr = new TimeoutAttribute();


            var parameter = context.ApiActionDescriptor.Parameters[0].Clone(TimeSpan.FromMilliseconds(5));
            await attr.BeforeRequestAsync(context, parameter);

            await Task.Delay(10);

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

            Assert.True(canceled);


            parameter = context.ApiActionDescriptor.Parameters[0].Clone(Guid.NewGuid());
            await Assert.ThrowsAsync <HttpApiConfigException>(()
                                                              => attr.BeforeRequestAsync(context, parameter));


            parameter = context.ApiActionDescriptor.Parameters[0].Clone(null);
            await attr.BeforeRequestAsync(context, parameter);

            Assert.True(context.CancellationTokens.Count == 1);
        }
        public async Task BeforeRequestAsyncTest()
        {
            var context = new ApiActionContext
            {
                HttpApiConfig       = new HttpApiConfig(),
                RequestMessage      = new HttpApiRequestMessage(),
                ApiActionDescriptor = ApiDescriptorCache.GetApiActionDescriptor(typeof(IMyApi).GetMethod("PostAsync"))
            };

            var attr = new TimeoutAttribute(5000);
            await attr.BeforeRequestAsync(context);

            Assert.True(context.RequestMessage.Timeout == TimeSpan.FromSeconds(5));
        }
Beispiel #3
0
        public async Task BeforeRequestAsyncTest()
        {
            var context = new TestActionContext(
                httpApi: null,
                httpApiConfig: new HttpApiConfig(),
                apiActionDescriptor: new ApiActionDescriptor(typeof(IMyApi).GetMethod("PostAsync")));

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

            await Task.Delay(100);

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

            Assert.True(canceled);
        }
Beispiel #4
0
        public async Task BeforeRequestAsyncTest()
        {
            var context = new ApiActionContext
            {
                HttpApiConfig       = new HttpApiConfig(),
                RequestMessage      = new HttpApiRequestMessage(),
                ApiActionDescriptor = ApiDescriptorCache.GetApiActionDescriptor(typeof(IMyApi).GetMethod("PostAsync"))
            };

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

            await Task.Delay(100);

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

            Assert.True(canceled);
        }
Beispiel #5
0
        public async Task BeforeRequestAsync_Parameter_Double_Test()
        {
            var context = new TestActionContext(
                httpApi: null,
                httpApiConfig: new HttpApiConfig(),
                apiActionDescriptor: new ApiActionDescriptor(typeof(IMyApi).GetMethod("PostAsync")));

            IApiParameterAttribute attr = new TimeoutAttribute();

            var parameter = context.ApiActionDescriptor.Parameters[0].Clone(10);
            await attr.BeforeRequestAsync(context, parameter);

            await Task.Delay(20);

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

            Assert.True(canceled);
        }