Exemplo n.º 1
0
        public void SetHttpHeaders_transforms_HTTP_headers_correctly_from_a_given_OnPremiseTargetRequest_and_sets_them_on_a_given_HttpContent()
        {
            var sut         = new HttpResponseMessageBuilder();
            var httpHeaders = new Dictionary <string, string>
            {
                { "Content-MD5", "Q2hlY2sgSW50ZWdyaXR5IQ==" },               // will be discarded
                { "Content-Range", "bytes 21010-47021/47022" },              // will be discarded
                { "Content-Disposition", "attachment" },
                { "Content-Length", "300" },
                { "Content-Location", "http://tt.invalid" },
                { "Content-Type", "application/json" },
                { "Expires", "Thu, 01 Dec 1994 16:00:00 GMT" },
                { "Last-Modified", "Thu, 01 Dec 1994 15:00:00 GMT" }
            };
            var httpContent = new ByteArrayContent(new byte[] { });

            sut.SetHttpHeaders(httpHeaders, httpContent);

            httpContent.Headers.Should().HaveCount(6);
            httpContent.Headers.ContentMD5.Should().BeNull();
            httpContent.Headers.ContentRange.Should().BeNull();
            httpContent.Headers.ContentDisposition.Should().Be(ContentDispositionHeaderValue.Parse("attachment"));
            httpContent.Headers.ContentLength.Should().Be(300L);
            httpContent.Headers.ContentLocation.Should().Be("http://tt.invalid");
            httpContent.Headers.ContentType.Should().Be(MediaTypeHeaderValue.Parse("application/json"));
            httpContent.Headers.Expires.Should().Be(new DateTime(1994, 12, 1, 16, 0, 0));
            httpContent.Headers.LastModified.Should().Be(new DateTime(1994, 12, 1, 15, 0, 0));
        }
Exemplo n.º 2
0
        public void SetHttpHeaders_does_nothing_when_no_HttpHeaders_are_provided()
        {
            var sut         = new HttpResponseMessageBuilder();
            var httpContent = new ByteArrayContent(new byte[] { });

            sut.SetHttpHeaders(null, httpContent);

            httpContent.Headers.Should().BeEmpty();
        }
Exemplo n.º 3
0
        public void SetHttpHeaders_sets_unknown_HTTP_headers_without_validation_correctly_from_a_OnPremiseTargetRequest_on_a_given_HttpContent()
        {
            var sut         = new HttpResponseMessageBuilder();
            var httpHeaders = new Dictionary <string, string>
            {
                { "X-Foo", "X-Bar" },
                { "Foo", "Bar" }
            };
            var httpContent = new ByteArrayContent(new byte[] { });

            sut.SetHttpHeaders(httpHeaders, httpContent);

            httpContent.Headers.Should().HaveCount(2);
            httpContent.Headers.GetValues("X-Foo").Single().Should().Be("X-Bar");
            httpContent.Headers.GetValues("Foo").Single().Should().Be("Bar");
        }