コード例 #1
0
            public void AddsHeadersToRequestMessage()
            {
                var request = new Request
                {
                    Method  = HttpMethod.Post,
                    Headers =
                    {
                        { "foo",  "bar"   },
                        { "blah", "blase" }
                    }
                };
                var tester = new HttpClientAdapterTester();

                var requestMessage = tester.BuildRequestMessageTester(request);

                Assert.Equal(2, requestMessage.Headers.Count());
                var firstHeader = requestMessage.Headers.First();

                Assert.Equal("foo", firstHeader.Key);
                Assert.Equal("bar", firstHeader.Value.First());
                var lastHeader = requestMessage.Headers.Last();

                Assert.Equal("blah", lastHeader.Key);
                Assert.Equal("blase", lastHeader.Value.First());
                Assert.Null(requestMessage.Content);
            }
コード例 #2
0
            public void AddsHeadersToRequestMessage()
            {
                var request = new Request
                {
                    BaseAddress = GitHubClient.GitHubApiUrl,
                    Endpoint = _endpoint,
                    Method = HttpMethod.Post,
                    Headers =
                    {
                        { "foo", "bar" },
                        { "blah", "blase" }
                    }
                };
                var tester = new HttpClientAdapterTester();
                
                var requestMessage = tester.BuildRequestMessageTester(request);

                Assert.Equal(2, requestMessage.Headers.Count());
                var firstHeader = requestMessage.Headers.First();
                Assert.Equal("foo", firstHeader.Key);
                Assert.Equal("bar", firstHeader.Value.First());
                var lastHeader = requestMessage.Headers.Last();
                Assert.Equal("blah", lastHeader.Key);
                Assert.Equal("blase", lastHeader.Value.First());
                Assert.Null(requestMessage.Content);
            }
コード例 #3
0
            public async Task BuildsResponseFromResponseMessage(HttpStatusCode httpStatusCode)
            {
                var responseMessage = new HttpResponseMessage {
                    StatusCode = httpStatusCode,
                    Content    = new ByteArrayContent(Encoding.UTF8.GetBytes("{}")),
                    Headers    =
                    {
                        { "peanut", "butter" },
                        { "ele",    "phant"  }
                    }
                };
                var tester = new HttpClientAdapterTester();

                var response = await tester.BuildResponseTester <object>(responseMessage);

                var firstHeader = response.Headers.First();

                Assert.Equal("peanut", firstHeader.Key);
                Assert.Equal("butter", firstHeader.Value);
                var lastHeader = response.Headers.Last();

                Assert.Equal("ele", lastHeader.Key);
                Assert.Equal("phant", lastHeader.Value);
                Assert.Equal("{}", response.Body);
                Assert.Equal(httpStatusCode, response.StatusCode);
                Assert.Null(response.ContentType);
            }
コード例 #4
0
            public async Task SetsContentType(HttpStatusCode httpStatusCode)
            {
                var responseMessage = new HttpResponseMessage
                {
                    StatusCode = httpStatusCode,
                    Content    = new StringContent("{}", Encoding.UTF8, "application/json"),
                };
                var tester = new HttpClientAdapterTester();

                var response = await tester.BuildResponseTester <object>(responseMessage);

                Assert.Equal("application/json", response.ContentType);
            }
コード例 #5
0
            public async Task BuildsByteArrayResponseFromResponseMessage()
            {
                var responseMessage = new HttpResponseMessage
                {
                    StatusCode = HttpStatusCode.OK,
                    Content    = new ByteArrayContent(new byte[] { 0, 1, 1, 0, 1 }),
                };
                var tester = new HttpClientAdapterTester();

                var response = await tester.BuildResponseTester <byte[]>(responseMessage);

                Assert.Equal(new byte[] { 0, 1, 1, 0, 1 }, response.BodyAsObject);
                Assert.Null(response.Body);
                Assert.Null(response.ContentType);
            }
コード例 #6
0
            public void SetsBodyAndContentType()
            {
                var request = new Request
                {
                    Method      = HttpMethod.Post,
                    Body        = "{}",
                    ContentType = "text/plain"
                };
                var tester = new HttpClientAdapterTester();

                var requestMessage = tester.BuildRequestMessageTester(request);

                Assert.NotNull(requestMessage.Content);
                Assert.Equal("text/plain", requestMessage.Content.Headers.ContentType.MediaType);
            }
コード例 #7
0
            public void SetsStreamBodyAndContentType()
            {
                var request = new Request
                {
                    Method      = HttpMethod.Post,
                    Body        = new MemoryStream(),
                    ContentType = "text/plain"
                };
                var tester = new HttpClientAdapterTester();

                var requestMessage = tester.BuildRequestMessageTester(request);

                Assert.NotNull(requestMessage.Content);
                Assert.IsType <StreamContent>(requestMessage.Content);
            }
コード例 #8
0
            public void SetsBodyAndContentType()
            {
                var request = new Request
                {
                    Method = HttpMethod.Post,
                    Body = "{}",
                    ContentType = "text/plain"
                };
                var tester = new HttpClientAdapterTester();

                var requestMessage = tester.BuildRequestMessageTester(request);

                Assert.NotNull(requestMessage.Content);
                Assert.Equal("text/plain", requestMessage.Content.Headers.ContentType.MediaType);
            }
コード例 #9
0
            public async Task BuildsByteArrayResponseFromResponseMessage()
            {
                var responseMessage = new HttpResponseMessage
                {
                    StatusCode = HttpStatusCode.OK,
                    Content    = new ByteArrayContent(new byte[] { 0, 1, 1, 0, 1 }),
                };

                responseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
                var tester = new HttpClientAdapterTester();

                var response = await tester.BuildResponseTester(responseMessage);

                Assert.Equal(new byte[] { 0, 1, 1, 0, 1 }, response.Body);
                Assert.Equal("image/png", response.ContentType);
            }
コード例 #10
0
            public void SetsHttpContentBody()
            {
                var request = new Request
                {
                    Method = HttpMethod.Post,
                    Body   = new FormUrlEncodedContent(new Dictionary <string, string> {
                        { "foo", "bar" }
                    })
                };
                var tester = new HttpClientAdapterTester();

                var requestMessage = tester.BuildRequestMessageTester(request);

                Assert.NotNull(requestMessage.Content);
                Assert.IsType <FormUrlEncodedContent>(requestMessage.Content);
                Assert.Equal("application/x-www-form-urlencoded", requestMessage.Content.Headers.ContentType.MediaType);
            }
コード例 #11
0
            public void SetsStreamBodyAndContentType()
            {
                var request = new Request
                {
                    BaseAddress = GitHubClient.GitHubApiUrl,
                    Endpoint = _endpoint,
                    Method = HttpMethod.Post,
                    Body = new MemoryStream(),
                    ContentType = "text/plain"
                };
                var tester = new HttpClientAdapterTester();

                var requestMessage = tester.BuildRequestMessageTester(request);

                Assert.NotNull(requestMessage.Content);
                Assert.IsType<StreamContent>(requestMessage.Content);
                Assert.Equal("text/plain", requestMessage.Content.Headers.ContentType.MediaType);
            }
コード例 #12
0
            public void SetsStreamBodyAndContentType()
            {
                var request = new Request
                {
                    BaseAddress = GitHubClient.GitHubApiUrl,
                    Endpoint    = _endpoint,
                    Method      = HttpMethod.Post,
                    Body        = new MemoryStream(),
                    ContentType = "text/plain"
                };
                var tester = new HttpClientAdapterTester();

                var requestMessage = tester.BuildRequestMessageTester(request);

                Assert.NotNull(requestMessage.Content);
                Assert.IsType <StreamContent>(requestMessage.Content);
                Assert.Equal("text/plain", requestMessage.Content.Headers.ContentType.MediaType);
            }
コード例 #13
0
 public void EnsuresArguments()
 {
     var tester = new HttpClientAdapterTester();
     Assert.Throws<ArgumentNullException>(() => tester.BuildRequestMessageTester(null));
 }
コード例 #14
0
            public async Task BuildsResponseFromResponseMessage(HttpStatusCode httpStatusCode)
            {
                var responseMessage = new HttpResponseMessage {
                    StatusCode = httpStatusCode,
                    Content = new ByteArrayContent(Encoding.UTF8.GetBytes("{}")),
                    Headers =
                    {
                        {"peanut", "butter"},
                        {"ele", "phant"}
                    }
                };
                var tester = new HttpClientAdapterTester();

                var response = await tester.BuildResponseTester(responseMessage);
                
                var firstHeader = response.Headers.First();
                Assert.Equal("peanut", firstHeader.Key);
                Assert.Equal("butter", firstHeader.Value);
                var lastHeader = response.Headers.Last();
                Assert.Equal("ele", lastHeader.Key);
                Assert.Equal("phant", lastHeader.Value);
                Assert.Equal("{}", response.Body);
                Assert.Equal(httpStatusCode, response.StatusCode);
                Assert.Null(response.ContentType);
            }
コード例 #15
0
            public async Task BuildsByteArrayResponseFromResponseMessage()
            {
                var responseMessage = new HttpResponseMessage
                {
                    StatusCode = HttpStatusCode.OK,
                    Content = new ByteArrayContent(new byte[] { 0, 1, 1, 0, 1}),
                };
                responseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
                var tester = new HttpClientAdapterTester();

                var response = await tester.BuildResponseTester(responseMessage);

                Assert.Equal(new byte[] { 0, 1, 1, 0, 1 }, response.Body);
                Assert.Equal("image/png", response.ContentType);
            }
コード例 #16
0
            public async Task SetsContentType()
            {
                var responseMessage = new HttpResponseMessage
                {
                    StatusCode = HttpStatusCode.OK,
                    Content = new StringContent("{}", Encoding.UTF8, "application/json"),
                };
                var tester = new HttpClientAdapterTester();

                var response = await tester.BuildResponseTester(responseMessage);

                Assert.Equal("application/json", response.ContentType);
            }
コード例 #17
0
            public void EnsuresArguments()
            {
                var tester = new HttpClientAdapterTester();

                Assert.Throws <ArgumentNullException>(() => tester.BuildRequestMessageTester(null));
            }
コード例 #18
0
            public void SetsHttpContentBody()
            {
                var request = new Request
                {
                    BaseAddress = GitHubClient.GitHubApiUrl,
                    Endpoint = _endpoint,
                    Method = HttpMethod.Post,
                    Body = new FormUrlEncodedContent(new Dictionary<string, string> {{"foo", "bar"}})
                };
                var tester = new HttpClientAdapterTester();

                var requestMessage = tester.BuildRequestMessageTester(request);

                Assert.NotNull(requestMessage.Content);
                Assert.IsType<FormUrlEncodedContent>(requestMessage.Content);
                Assert.Equal("application/x-www-form-urlencoded", requestMessage.Content.Headers.ContentType.MediaType);
            }