Пример #1
0
        public async Task ConvertsRequestMessageToRequest()
        {
            // ARRANGE
            var input  = GetRequestMessage();
            var mapper = new HttpMessageMapper();

            // ACT
            var output = await mapper.ToHttpAsync(input, CancellationToken.None);

            // ASSERT
            output.Method.Should().Be("GET");
            output.Url.Should().Be("http://example/path");
            output.Version.Should().Be("1.1");
            output.Headers.ShouldBeEquivalentTo(
                new[]
            {
                new HttpHeader {
                    Name = "User-Agent", Value = "HttpMessageMapper/2.0"
                },
                new HttpHeader {
                    Name = "Content-Type", Value = "application/json"
                },
                new HttpHeader {
                    Name = "Content-Length", Value = "99"
                }
            },
                o => o.WithStrictOrdering());
            (await new StreamReader(output.Content).ReadToEndAsync()).Should().Be("foobar");
        }
Пример #2
0
        public async Task ConvertsResponseMessageToResponse()
        {
            // ARRANGE
            var input  = GetResponseMessage();
            var mapper = new HttpMessageMapper();

            // ACT
            var output = await mapper.ToHttpAsync(input, CancellationToken.None);

            // ASSERT
            output.Version.Should().Be("1.1");
            output.StatusCode.Should().Be(404);
            output.ReasonPhrease.Should().Be("Not Found");
            output.Headers.ShouldBeEquivalentTo(
                new[]
            {
                new HttpHeader {
                    Name = "Server", Value = "HttpMessageMapper/2.0"
                },
                new HttpHeader {
                    Name = "Content-Type", Value = "application/json"
                },
                new HttpHeader {
                    Name = "Content-Length", Value = "99"
                }
            },
                o => o.WithStrictOrdering());
            (await new StreamReader(output.Content).ReadToEndAsync()).Should().Be("foobar");
        }
Пример #3
0
        public void AllowsNullHeadersOnResponse()
        {
            // ARRANGE
            var input = GetResponse();

            input.Headers = null;
            var mapper = new HttpMessageMapper();

            // ACT
            var output = mapper.ToHttpMessage(input);

            // ASSERT
            output.Headers.Should().BeEmpty();
        }
Пример #4
0
        public void AllowsNullContentOnResponse()
        {
            // ARRANGE
            var input = GetResponse();

            input.Content = null;
            var mapper = new HttpMessageMapper();

            // ACT
            var output = mapper.ToHttpMessage(input);

            // ASSERT
            output.Content.Should().BeNull();
            output.Headers.Should().HaveCount(1);
            output.Headers.Server.ToString().Should().Be("HttpMessageMapper");
        }
Пример #5
0
        public async Task AllowsNullContentOnResponseMessage()
        {
            // ARRANGE
            var input = GetResponseMessage();

            input.Content = null;
            var mapper = new HttpMessageMapper();

            // ACT
            var output = await mapper.ToHttpAsync(input, CancellationToken.None);

            // ASSERT
            output.Content.Should().BeNull();
            output.Headers.Should().HaveCount(1);
            output.Headers.ShouldBeEquivalentTo(
                new[] { new HttpHeader {
                            Name = "Server", Value = "HttpMessageMapper/2.0"
                        } },
                o => o.WithStrictOrdering());
        }
Пример #6
0
        public async Task ConvertsResponseToResponseMessage()
        {
            // ARRANGE
            var input  = GetResponse();
            var mapper = new HttpMessageMapper();

            // ACT
            var output = mapper.ToHttpMessage(input);

            // ASSERT
            output.Version.Should().Be(new Version(1, 1));
            output.StatusCode.Should().Be(HttpStatusCode.NotFound);
            output.ReasonPhrase.Should().Be("Not Found");
            output.Headers.Server.Should().HaveCount(1);
            output.Headers.Server.ElementAt(0).ToString().Should().Be("HttpMessageMapper");
            output.Content.Should().NotBeNull();
            output.Content.Headers.ContentType.ToString().Should().Be("application/json");
            output.Content.Headers.ContentLength.Should().Be(99);
            (await output.Content.ReadAsStringAsync()).Should().Be("foobar");
            output.RequestMessage.Should().BeNull();
        }
Пример #7
0
        public async Task ConvertsRequestToRequestMessage()
        {
            // ARRANGE
            var input  = GetRequest();
            var mapper = new HttpMessageMapper();

            // ACT
            var output = mapper.ToHttpMessage(input);

            // ASSERT
            output.Method.Should().Be(HttpMethod.Get);
            output.RequestUri.Should().Be(new Uri("http://example/path"));
            output.Version.Should().Be(new Version(1, 1));
            output.Headers.UserAgent.Should().HaveCount(1);
            output.Headers.UserAgent.ToString().Should().Be("HttpMessageMapper");
            output.Content.Should().NotBeNull();
            output.Content.Headers.ContentType.ToString().Should().Be("application/json");
            output.Content.Headers.ContentLength.Should().Be(99);
            (await output.Content.ReadAsStringAsync()).Should().Be("foobar");
            output.Properties.Should().BeEmpty();
        }