Esempio n. 1
0
        public void Should_return_all_accept_headers_when_multiple_are_available()
        {
            // Given
            var rawHeaders = 
                new Dictionary<string, IEnumerable<string>>
                {
                    { "Accept", new[] { "text/plain", "text/ninja" } }
                };

            // When
            var headers = new RequestHeaders(rawHeaders).Accept.ToList();

            // Then
            headers.ShouldHaveCount(2);
            headers[0].Item1.ShouldEqual("text/plain");
            headers[1].Item1.ShouldEqual("text/ninja");
        }
Esempio n. 2
0
        public void Should_default_accept_language_header_values_to_quality_one_if_not_explicitly_defined()
        {
            // Given
            var values = new[] { "en-US" };
            var rawHeaders = new Dictionary<string, IEnumerable<string>> { { "Accept-Language", values } };

            // When
            var headers = new RequestHeaders(rawHeaders).AcceptLanguage.ToList();

            // Then
            headers.ShouldHaveCount(1);
            headers[0].Item1.ShouldEqual("en-US");
            headers[0].Item2.ShouldEqual(1m);
        }
Esempio n. 3
0
        public void Should_parse_accept_language_header_value_quality_when_available()
        {
            // Given
            var values = new[] { "en-US;q=0.3" };
            var rawHeaders = new Dictionary<string, IEnumerable<string>> { { "Accept-Language", values } };

            // When
            var headers = new RequestHeaders(rawHeaders).AcceptLanguage.ToList();

            // Then
            headers.ShouldHaveCount(1);
            headers[0].Item1.ShouldEqual("en-US");
            headers[0].Item2.ShouldEqual(0.3m);
        }
Esempio n. 4
0
        public void Should_parse_accept_language_header_values_when_containing_multiple_values()
        {
            // Given
            var values = new[] { "en-US, sv-SE" };
            var rawHeaders = new Dictionary<string, IEnumerable<string>> { { "Accept-Language", values } };

            // When
            var headers = new RequestHeaders(rawHeaders).AcceptLanguage.ToList();

            // Then
            headers.ShouldHaveCount(2);
            headers[0].Item1.ShouldEqual("en-US");
            headers[1].Item1.ShouldEqual("sv-SE");
        }
Esempio n. 5
0
        public void Should_return_accept_language_headers_when_available()
        {
            // Given
            var expectedValues = new[] { "en-US", "sv-SE" };
            var rawHeaders = new Dictionary<string, IEnumerable<string>> { { "Accept-Language", expectedValues } };

            // When
            var headers = new RequestHeaders(rawHeaders).AcceptLanguage.ToList();

            // Then
            headers.ShouldHaveCount(2);
            headers[0].Item1.ShouldEqual("en-US");
            headers[1].Item1.ShouldEqual("sv-SE");
        }
Esempio n. 6
0
        public void Should_not_strip_additional_accept_header_parameters()
        {
            // Given
            var values = new[] { "text/plain, text/ninja;q=0.3;a=1;b=2" };
            var rawHeaders = new Dictionary<string, IEnumerable<string>> { { "Accept", values } };

            // When
            var headers = new RequestHeaders(rawHeaders).Accept.ToList();

            // Then
            headers.ShouldHaveCount(2);
            headers.ShouldHave(t => t.Item1 == "text/plain" && t.Item2 == 1.0m);
            headers.ShouldHave(t => t.Item1 == "text/ninja;a=1;b=2" && t.Item2 == 0.3m);
         }
Esempio n. 7
0
        public void Should_parse_accept_header_values_when_containing_multiple_values()
        {
            // Given
            var values = new[] { "text/plain, text/ninja" };
            var rawHeaders = new Dictionary<string, IEnumerable<string>> { { "Accept", values } };

            // When
            var headers = new RequestHeaders(rawHeaders).Accept.ToList();

            // Then
            headers.ShouldHaveCount(2);
            headers[0].Item1.ShouldEqual("text/plain");
            headers[1].Item1.ShouldEqual("text/ninja");
        }
Esempio n. 8
0
        public void Should_ignore_case_of_accept_language_header_name_when_retrieving_values(string headerName)
        {
            // Given
            var expectedValues = new[] { "en-US", "sv-SE" };
            var rawHeaders = new Dictionary<string, IEnumerable<string>> { { headerName, expectedValues } };

            // When
            var headers = new RequestHeaders(rawHeaders).AcceptLanguage.ToList();

            // Then
            headers.ShouldHaveCount(2);
        }
Esempio n. 9
0
        public void Should_return_accept_encoding_headers_when_available()
        {
            // Given
            var expectedValues = new[] { "compress", "sdch" };
            var rawHeaders = new Dictionary<string, IEnumerable<string>> { { "Accept-Encoding", expectedValues } };

            // When
            var headers = new RequestHeaders(rawHeaders).AcceptEncoding.ToList();

            // Then
            headers.ShouldHaveCount(2);
            headers[0].ShouldEqual("compress");
            headers[1].ShouldEqual("sdch");
        }
Esempio n. 10
0
        public void Should_sort_accept_charset_header_values_decending_based_on_quality()
        {
            // Given
            var values = new[] { "utf-8;q=0.3, iso-8859-5, iso-8859-15;q=0.7" };
            var rawHeaders = new Dictionary<string, IEnumerable<string>> { { "Accept-Charset", values } };

            // When
            var headers = new RequestHeaders(rawHeaders).AcceptCharset.ToList();

            // Then
            headers.ShouldHaveCount(3);
            headers[0].Item1.ShouldEqual("iso-8859-5");
            headers[1].Item1.ShouldEqual("iso-8859-15");
            headers[2].Item1.ShouldEqual("utf-8");
        }
Esempio n. 11
0
        public void Should_ignore_accept_charset_header_values_with_invalid_quality()
        {
            // Given
            var values = new[] { "utf-8, iso-8859-5;q=a" };
            var rawHeaders = new Dictionary<string, IEnumerable<string>> { { "Accept-Charset", values } };

            // When
            var headers = new RequestHeaders(rawHeaders).AcceptCharset.ToList();

            // Then
            headers.ShouldHaveCount(2);
            headers.ShouldHave(t => t.Item1 == "utf-8" && t.Item2 == 1.0m);
            headers.ShouldHave(t => t.Item1 == "iso-8859-5" && t.Item2 == 1.0m);
        }
Esempio n. 12
0
        public void Should_parse_accept_charset_header_values_when_containing_multiple_values()
        {
            // Given
            var values = new[] { "utf-8, iso-8859-5" };
            var rawHeaders = new Dictionary<string, IEnumerable<string>> { { "Accept-Charset", values } };

            // When
            var headers = new RequestHeaders(rawHeaders).AcceptCharset.ToList();

            // Then
            headers.ShouldHaveCount(2);
            headers[0].Item1.ShouldEqual("utf-8");
            headers[1].Item1.ShouldEqual("iso-8859-5");
        }
Esempio n. 13
0
        public void Should_return_accept_charset_headers_when_available()
        {
            // Given
            var expectedValues = new[] { "utf-8", "iso-8859-5" };
            var rawHeaders = new Dictionary<string, IEnumerable<string>> { { "Accept-Charset", expectedValues } };

            // When
            var headers = new RequestHeaders(rawHeaders).AcceptCharset.ToList();

            // Then
            headers.ShouldHaveCount(2);
            headers[0].Item1.ShouldEqual("utf-8");
            headers[1].Item1.ShouldEqual("iso-8859-5");
        }
Esempio n. 14
0
        public void Should_sort_accept_header_values_decending_based_on_quality()
        {
            // Given
            var values = new[] { "text/plain;q=0.3, text/ninja, text/html;q=0.7" };
            var rawHeaders = new Dictionary<string, IEnumerable<string>> { { "Accept", values } };

            // When
            var headers = new RequestHeaders(rawHeaders).Accept.ToList();

            // Then
            headers.ShouldHaveCount(3);
            headers[0].Item1.ShouldEqual("text/ninja");
            headers[1].Item1.ShouldEqual("text/html");
            headers[2].Item1.ShouldEqual("text/plain");
        }
Esempio n. 15
0
        public void Should_ignore_accept_language_header_values_with_invalid_quality()
        {
            // Given
            var values = new[] { "en-US, sv-SE;q=a" };
            var rawHeaders = new Dictionary<string, IEnumerable<string>> { { "Accept-Language", values } };

            // When
            var headers = new RequestHeaders(rawHeaders).AcceptLanguage.ToList();

            // Then
            headers.ShouldHaveCount(2);
            headers.ShouldHave(t => t.Item1 == "en-US" && t.Item2 == 1.0m);
            headers.ShouldHave(t => t.Item1 == "sv-SE" && t.Item2 == 1.0m);
        }
Esempio n. 16
0
        public void Should_sort_accept_language_header_values_decending_based_on_quality()
        {
            // Given
            var values = new[] { "en-US;q=0.3, da, sv-SE;q=0.7" };
            var rawHeaders = new Dictionary<string, IEnumerable<string>> { { "Accept-Language", values } };

            // When
            var headers = new RequestHeaders(rawHeaders).AcceptLanguage.ToList();

            // Then
            headers.ShouldHaveCount(3);
            headers[0].Item1.ShouldEqual("da");
            headers[1].Item1.ShouldEqual("sv-SE");
            headers[2].Item1.ShouldEqual("en-US");
        }
Esempio n. 17
0
        public void Should_parse_accept_encoding_header_values_when_containing_multiple_values()
        {
            // Given
            var values = new[] { "compress, sdch" };
            var rawHeaders = new Dictionary<string, IEnumerable<string>> { { "Accept-Encoding", values } };

            // When
            var headers = new RequestHeaders(rawHeaders).AcceptEncoding.ToList();

            // Then
            headers.ShouldHaveCount(2);
            headers[0].ShouldEqual("compress");
            headers[1].ShouldEqual("sdch");
        }
Esempio n. 18
0
        public void Should_ignore_case_of_accept_encoding_header_name_when_retrieving_values(string headerName)
        {
            // Given
            var expectedValues = new[] { "compress", "sdch" };
            var rawHeaders = new Dictionary<string, IEnumerable<string>> { { headerName, expectedValues } };

            // When
            var headers = new RequestHeaders(rawHeaders).AcceptEncoding.ToList();

            // Then
            headers.ShouldHaveCount(2);
            headers[0].ShouldEqual("compress");
            headers[1].ShouldEqual("sdch");
        }
Esempio n. 19
0
        public void Should_return_empty_enumerable_when_accept_language_headers_are_not_available()
        {
            // Given
            var rawHeaders = new Dictionary<string, IEnumerable<string>>();

            // When
            var headers = new RequestHeaders(rawHeaders).AcceptLanguage.ToList();

            // Then
            headers.ShouldHaveCount(0);
        }
Esempio n. 20
0
        public void Should_parse_ifmatch_header_values_when_containing_multiple_values()
        {
            // Given
            var values = new[] { "xyzzy", "c3piozzzz" };
            var rawHeaders = new Dictionary<string, IEnumerable<string>> { { "If-Match", values } };

            // When
            var headers = new RequestHeaders(rawHeaders).IfMatch.ToList();

            // Then
            headers.ShouldHaveCount(2);
            headers[0].ShouldEqual("xyzzy");
            headers[1].ShouldEqual("c3piozzzz");
        }
Esempio n. 21
0
        public void Should_ignore_accept_header_values_with_invalid_quality()
        {
            // Given
            var values = new[] { "text/plain, text/ninja;q=a" };
            var rawHeaders = new Dictionary<string, IEnumerable<string>> { { "Accept", values } };

            // When
            var headers = new RequestHeaders(rawHeaders).Accept.ToList();

            // Then
            headers.ShouldHaveCount(2);
            headers.ShouldHave(t => t.Item1 == "text/plain" && t.Item2 == 1.0m);
            headers.ShouldHave(t => t.Item1 == "text/ninja" && t.Item2 == 1.0m);
        }