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);
            }
            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);
            }
            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);
            }
            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);
            }
            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);
            }
            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);
            }
Example #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);
            }
            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);
            }
            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);
            }
            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);
            }
            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);
            }
            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);
            }
 public void EnsuresArguments()
 {
     var tester = new HttpClientAdapterTester();
     Assert.Throws<ArgumentNullException>(() => tester.BuildRequestMessageTester(null));
 }
            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);
            }
            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);
            }
            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);
            }
            public void EnsuresArguments()
            {
                var tester = new HttpClientAdapterTester();

                Assert.Throws <ArgumentNullException>(() => tester.BuildRequestMessageTester(null));
            }
            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);
            }