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

            context.RequestMessage.RequestUri = new Uri("http://www.webapi.com/");
            context.RequestMessage.Method     = HttpMethod.Post;

            var attr = new HttpHeadAttribute();
            await attr.BeforeRequestAsync(context);

            Assert.True(context.RequestMessage.Method == HttpMethod.Head);

            var attr2 = new HttpHeadAttribute("/login");
            await attr2.BeforeRequestAsync(context);

            Assert.True(context.RequestMessage.Method == HttpMethod.Head);
            Assert.True(context.RequestMessage.RequestUri == new Uri("http://www.webapi.com/login"));

            var attr3 = new HttpHeadAttribute("http://www.baidu.com");
            await attr3.BeforeRequestAsync(context);

            Assert.True(context.RequestMessage.Method == HttpMethod.Head);
            Assert.True(context.RequestMessage.RequestUri == new Uri("http://www.baidu.com"));
        }
Ejemplo n.º 2
0
        public async Task OnRequestAsyncTest()
        {
            var apiAction = new ApiActionDescriptor(typeof(ITestApi).GetMethod("PostAsync"));
            var context   = new TestRequestContext(apiAction, string.Empty);

            context.HttpContext.RequestMessage.RequestUri = new Uri("http://www.webapi.com/");
            context.HttpContext.RequestMessage.Method     = HttpMethod.Post;

            var attr = new HttpHeadAttribute();
            await attr.OnRequestAsync(context);

            Assert.True(context.HttpContext.RequestMessage.Method == HttpMethod.Head);

            var attr2 = new HttpHeadAttribute("/login");
            await attr2.OnRequestAsync(context);

            Assert.True(context.HttpContext.RequestMessage.Method == HttpMethod.Head);
            Assert.True(context.HttpContext.RequestMessage.RequestUri == new Uri("http://www.webapi.com/login"));

            var attr3 = new HttpHeadAttribute("http://www.baidu.com");
            await attr3.OnRequestAsync(context);

            Assert.True(context.HttpContext.RequestMessage.Method == HttpMethod.Head);
            Assert.True(context.HttpContext.RequestMessage.RequestUri == new Uri("http://www.baidu.com"));
        }
Ejemplo n.º 3
0
        public async Task BeforeRequestAsyncTest()
        {
            var context = new ApiActionContext
            {
                RequestMessage = new HttpApiRequestMessage
                {
                    RequestUri = new Uri("http://www.webapi.com/")
                },
                ApiActionDescriptor = ApiDescriptorCache.GetApiActionDescriptor(typeof(IMyApi).GetMethod("PostAsync"))
            };

            var attr = new HttpHeadAttribute();
            await attr.BeforeRequestAsync(context);

            Assert.True(context.RequestMessage.Method == HttpMethod.Head);

            var attr2 = new HttpHeadAttribute("/login");
            await attr2.BeforeRequestAsync(context);

            Assert.True(context.RequestMessage.Method == HttpMethod.Head);
            Assert.True(context.RequestMessage.RequestUri == new Uri("http://www.webapi.com/login"));

            var attr3 = new HttpHeadAttribute("http://www.baidu.com");
            await attr3.BeforeRequestAsync(context);

            Assert.True(context.RequestMessage.Method == HttpMethod.Head);
            Assert.True(context.RequestMessage.RequestUri == new Uri("http://www.baidu.com"));
        }