Inheritance: System.Net.Http.HttpMessageHandler
コード例 #1
1
ファイル: RequestBuilder.cs プロジェクト: uilquegb/refit
        public static Func<object[], TestHttpMessageHandler> RunRequest(this IRequestBuilder builder, string methodName, string returnContent = null)
        {
            var factory = builder.BuildRestResultFuncForMethod(methodName);
            var testHttpMessageHandler = new TestHttpMessageHandler();
            if (returnContent != null) {
                testHttpMessageHandler.Content = new StringContent(returnContent);
            }

            return paramList => {
                var task = (Task)factory(new HttpClient(testHttpMessageHandler) { BaseAddress = new Uri("http://api/") }, paramList);
                task.Wait();
                return testHttpMessageHandler;
            };
        }
コード例 #2
0
ファイル: RestService.cs プロジェクト: whyong88/refit
        public async Task ValueTypesArentValidButTheyWorkAnyway()
        {
            var handler = new TestHttpMessageHandler("true");

            var fixture = RestService.For <IBrokenWebApi>(new HttpClient(handler)
            {
                BaseAddress = new Uri("http://nowhere.com")
            });

            var result = await fixture.PostAValue("Does this work?");

            Assert.True(result);
        }
コード例 #3
0
ファイル: RequestBuilder.cs プロジェクト: lion-liu/refit
        public void HttpClientShouldNotPrefixEmptyAbsolutePathToTheRequestUri()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRestResultFuncForMethod("FetchSomeStuff");
            var testHttpMessageHandler = new TestHttpMessageHandler();

            var task = (Task)factory(new HttpClient(testHttpMessageHandler)
            {
                BaseAddress = new Uri("http://api/")
            }, new object[] { 42 });

            task.Wait();

            Assert.Equal("http://api/foo/bar/42", testHttpMessageHandler.RequestMessage.RequestUri.ToString());
        }
コード例 #4
0
ファイル: RequestBuilder.cs プロジェクト: lion-liu/refit
        public static Func <object[], HttpRequestMessage> BuildRequestFactoryForMethod(this IRequestBuilder builder, string methodName)
        {
            var factory = builder.BuildRestResultFuncForMethod(methodName);
            var testHttpMessageHandler = new TestHttpMessageHandler();


            return(paramList => {
                var task = (Task)factory(new HttpClient(testHttpMessageHandler)
                {
                    BaseAddress = new Uri("http://api/")
                }, paramList);
                task.Wait();
                return testHttpMessageHandler.RequestMessage;
            });
        }
コード例 #5
0
ファイル: RequestBuilder.cs プロジェクト: lion-liu/refit
        public static Func <object[], TestHttpMessageHandler> RunRequest(this IRequestBuilder builder, string methodName, string returnContent = null)
        {
            var factory = builder.BuildRestResultFuncForMethod(methodName);
            var testHttpMessageHandler = new TestHttpMessageHandler();

            if (returnContent != null)
            {
                testHttpMessageHandler.Content = new StringContent(returnContent);
            }

            return(paramList => {
                var task = (Task)factory(new HttpClient(testHttpMessageHandler)
                {
                    BaseAddress = new Uri("http://api/")
                }, paramList);
                task.Wait();
                return testHttpMessageHandler;
            });
        }
コード例 #6
0
ファイル: RequestBuilder.cs プロジェクト: lion-liu/refit
        public void HttpContentTest()
        {
            var fixture = new RequestBuilderImplementation(typeof(IHttpContentApi));
            var factory = fixture.BuildRestResultFuncForMethod("PostFileUpload");
            var testHttpMessageHandler = new TestHttpMessageHandler();
            var retContent             = new StreamContent(new MemoryStream());

            testHttpMessageHandler.Content = retContent;

            var mpc = new MultipartContent("foosubtype");

            var task = (Task <HttpContent>)factory(new HttpClient(testHttpMessageHandler)
            {
                BaseAddress = new Uri("http://api/")
            }, new object[] { mpc });

            task.Wait();

            Assert.Equal(testHttpMessageHandler.RequestMessage.Content, mpc);
            Assert.Equal(retContent, task.Result);
        }
コード例 #7
0
ファイル: RequestBuilder.cs プロジェクト: vitalyal/refit
        public void ReadStringContentWithMetadata()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRestResultFuncForMethod("FetchSomeStringWithMetadata");
            var testHttpMessageHandler = new TestHttpMessageHandler();

            var task = (Task <ApiResponse <string> >)factory(new HttpClient(testHttpMessageHandler)
            {
                BaseAddress = new Uri("http://api/")
            }, new object[] { 42 });

            task.Wait();

            Assert.NotNull(task.Result.Headers);
            Assert.True(task.Result.IsSuccessStatusCode);
            Assert.NotNull(task.Result.ReasonPhrase);
            Assert.False(task.Result.StatusCode == default(HttpStatusCode));
            Assert.NotNull(task.Result.Version);

            Assert.Equal("test", task.Result.Content);
        }
コード例 #8
0
ファイル: RequestBuilder.cs プロジェクト: uilquegb/refit
        public static Func<object[], HttpRequestMessage> BuildRequestFactoryForMethod(this IRequestBuilder builder, string methodName)
        {
            var factory = builder.BuildRestResultFuncForMethod(methodName);
            var testHttpMessageHandler = new TestHttpMessageHandler();


            return paramList => {
               var task = (Task)factory(new HttpClient(testHttpMessageHandler) { BaseAddress = new Uri("http://api/")}, paramList);
               task.Wait();
               return testHttpMessageHandler.RequestMessage;
           };
        }
コード例 #9
0
ファイル: RequestBuilder.cs プロジェクト: uilquegb/refit
        public void HttpClientShouldNotPrefixEmptyAbsolutePathToTheRequestUri()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRestResultFuncForMethod("FetchSomeStuff");
            var testHttpMessageHandler = new TestHttpMessageHandler();

            var task = (Task)factory(new HttpClient(testHttpMessageHandler) { BaseAddress = new Uri("http://api/") }, new object[] { 42 });
            task.Wait();

            Assert.AreEqual("http://api/foo/bar/42", testHttpMessageHandler.RequestMessage.RequestUri.ToString());            
        }
コード例 #10
0
ファイル: RequestBuilder.cs プロジェクト: uilquegb/refit
        public void HttpContentTest()
        {
            var fixture = new RequestBuilderImplementation(typeof(IHttpContentApi));
            var factory = fixture.BuildRestResultFuncForMethod("PostFileUpload");
            var testHttpMessageHandler = new TestHttpMessageHandler();
            var retContent = new StreamContent(new MemoryStream());
            testHttpMessageHandler.Content = retContent;

            var mpc = new MultipartContent("foosubtype");

            var task = (Task<HttpContent>)factory(new HttpClient(testHttpMessageHandler) { BaseAddress = new Uri("http://api/") }, new object[] { mpc });
            task.Wait();

            Assert.AreEqual(testHttpMessageHandler.RequestMessage.Content, mpc);
            Assert.AreEqual(retContent, task.Result);
        }