Exemple #1
0
        public void StreamResponseAsApiResponseTest()
        {
            var fixture = new RequestBuilderImplementation(typeof(IStreamApi));
            var factory = fixture.BuildRestResultFuncForMethod("GetRemoteFileWithMetadata");
            var testHttpMessageHandler = new TestHttpMessageHandler();
            var streamResponse         = new MemoryStream();
            var reponseContent         = "A remote file";

            testHttpMessageHandler.Content = new StreamContent(streamResponse);

            var writer = new StreamWriter(streamResponse);

            writer.Write(reponseContent);
            writer.Flush();
            streamResponse.Seek(0L, SeekOrigin.Begin);

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

            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);

            using (var reader = new StreamReader(task.Result.Content))
                Assert.Equal(reponseContent, reader.ReadToEnd());
        }
Exemple #2
0
        public void StreamResponseTest()
        {
            var fixture = new RequestBuilderImplementation(typeof(IStreamApi));
            var factory = fixture.BuildRestResultFuncForMethod("GetRemoteFile");
            var testHttpMessageHandler = new TestHttpMessageHandler();
            var streamResponse         = new MemoryStream();
            var reponseContent         = "A remote file";

            testHttpMessageHandler.Content = new StreamContent(streamResponse);

            var writer = new StreamWriter(streamResponse);

            writer.Write(reponseContent);
            writer.Flush();
            streamResponse.Seek(0L, SeekOrigin.Begin);

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

            task.Wait();

            using (var reader = new StreamReader(task.Result))
                Assert.Equal(reponseContent, reader.ReadToEnd());
        }
Exemple #3
0
        public void HttpContentAsApiResponseTest()
        {
            var fixture = new RequestBuilderImplementation(typeof(IHttpContentApi));
            var factory = fixture.BuildRestResultFuncForMethod("PostFileUploadWithMetadata");
            var testHttpMessageHandler = new TestHttpMessageHandler();
            var retContent             = new StreamContent(new MemoryStream());

            testHttpMessageHandler.Content = retContent;

            var mpc = new MultipartContent("foosubtype");

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

            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(testHttpMessageHandler.RequestMessage.Content, mpc);
            Assert.Equal(retContent, task.Result.Content);
        }
Exemple #4
0
        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());
        }
Exemple #5
0
        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);
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        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());            
        }
Exemple #8
0
        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);
        }