Exemplo n.º 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");
        }
Exemplo n.º 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");
        }
Exemplo n.º 3
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());
        }