Exemple #1
0
        public void String_without_carriage_return_and_line_feed_throws_ArgumentException()
        {
            var httpHeader = new HttpHeadersSingleSegment(new Utf8String(new UTF8Encoding().GetBytes(HeaderWithoutCrlf)));

            Action action = () => { var count = httpHeader.Count; };

            action.ShouldThrow <ArgumentException>();
        }
Exemple #2
0
        public void String_without_column_throws_ArgumentException()
        {
            var httpHeader = new HttpHeadersSingleSegment(new Utf8String(new UTF8Encoding().GetBytes(HeaderWithoutColumn)));

            Action action = () => { var count = httpHeader.Count; };

            action.ShouldThrow <ArgumentException>();
        }
        //[Fact(Skip = "System.TypeLoadException : The generic type 'System.Collections.Generic.KeyValuePair`2' was used with an invalid instantiation in assembly 'System.Private.CoreLib")]
        public void Its_Enumerator_iterates_through_all_headers()
        {
            var httpHeaders = new HttpHeadersSingleSegment(new Span <byte>(new UTF8Encoding().GetBytes(HeadersString)));
            var count       = 0;

            foreach (var httpHeader in httpHeaders)
            {
                count++;
            }

            count.Should().Be(8);
        }
        //[Fact(Skip = "System.TypeLoadException : The generic type 'System.Collections.Generic.KeyValuePair`2' was used with an invalid instantiation in assembly 'System.Private.CoreLib")]
        public void String_without_column_throws_ArgumentException()
        {
            var httpHeader = new HttpHeadersSingleSegment(new Utf8String(new UTF8Encoding().GetBytes(HeaderWithoutColumn)));

            try
            {
                var count = httpHeader.Count;
                Assert.True(false);
            }
            catch (Exception ex)
            {
                Assert.True(ex is ArgumentException);
            }
        }
        //[Fact(Skip = "System.TypeLoadException : The generic type 'System.Collections.Generic.KeyValuePair`2' was used with an invalid instantiation in assembly 'System.Private.CoreLib")]
        public void String_without_carriage_return_and_line_feed_throws_ArgumentException()
        {
            var httpHeader = new HttpHeadersSingleSegment(new Utf8String(new UTF8Encoding().GetBytes(HeaderWithoutCrlf)));

            try
            {
                var count = httpHeader.Count;
                Assert.True(false);
            }
            catch (Exception ex)
            {
                Assert.True(ex is ArgumentException);
            }
        }
        //[Fact(Skip = "System.TypeLoadException : The generic type 'System.Collections.Generic.KeyValuePair`2' was used with an invalid instantiation in assembly 'System.Private.CoreLib")]
        public void Its_enumerator_Current_returns_the_same_item_until_MoveNext_gets_called()
        {
            var httpHeader = new HttpHeadersSingleSegment(new Span <byte>(new UTF8Encoding().GetBytes(HeadersString)));
            var enumerator = httpHeader.GetEnumerator();

            enumerator.MoveNext();

            var current = enumerator.Current;

            current.Should().Be(enumerator.Current);

            enumerator.MoveNext();

            current.Should().NotBe(enumerator.Current);
        }
Exemple #7
0
        public GivenAnHttpHeaders()
        {
            Span <byte> headers;
            var         bytes = new UTF8Encoding().GetBytes(HeadersString);

            unsafe
            {
                fixed(byte *buffer = bytes)
                {
                    headers = new Span <byte>(buffer, bytes.Length);
                }
            }

            _httpHeaders = new HttpHeadersSingleSegment(headers);
        }
Exemple #8
0
        //[Fact(Skip = "System.TypeLoadException : The generic type 'System.Collections.Generic.KeyValuePair`2' was used with an invalid instantiation in assembly 'System.Private.CoreLib")]
        public void Its_enumerator_Current_returns_the_same_item_until_MoveNext_gets_called()
        {
            var httpHeader = new HttpHeadersSingleSegment(new Span <byte>(new UTF8Encoding().GetBytes(HeadersString)));
            var enumerator = httpHeader.GetEnumerator();

            enumerator.MoveNext();

            var current = enumerator.Current;

            Assert.True(current.Key == enumerator.Current.Key);
            Assert.True(current.Value == enumerator.Current.Value);

            enumerator.MoveNext();

            current = enumerator.Current;
            Assert.True(current.Key == enumerator.Current.Key);
            Assert.True(current.Value == enumerator.Current.Value);
        }
        //[Fact(Skip = "System.TypeLoadException : The generic type 'System.Collections.Generic.KeyValuePair`2' was used with an invalid instantiation in assembly 'System.Private.CoreLib")]
        public void It_parsers_Utf8String_as_well()
        {
            var httpHeader = new HttpHeadersSingleSegment(new Utf8String(new UTF8Encoding().GetBytes(HeadersString)));

            httpHeader.Count.Should().Be(8);
        }
        //[Fact(Skip = "System.TypeLoadException : The generic type 'System.Collections.Generic.KeyValuePair`2' was used with an invalid instantiation in assembly 'System.Private.CoreLib")]
        public void It_returns_empty_string_when_header_is_not_present()
        {
            var httpHeader = new HttpHeadersSingleSegment(new Span <byte>(new UTF8Encoding().GetBytes(HeadersString)));

            httpHeader["Content-Length"].Length.Should().Be(0);
        }
        //[Fact(Skip = "System.TypeLoadException : The generic type 'System.Collections.Generic.KeyValuePair`2' was used with an invalid instantiation in assembly 'System.Private.CoreLib")]
        public void It_can_get_the_value_of_a_particular_header()
        {
            var httpHeader = new HttpHeadersSingleSegment(new Span <byte>(new UTF8Encoding().GetBytes(HeadersString)));

            Assert.Equal(httpHeader["Host"].ToString(), " localhost:8080");
        }
        //[Fact(Skip = "System.TypeLoadException : The generic type 'System.Collections.Generic.KeyValuePair`2' was used with an invalid instantiation in assembly 'System.Private.CoreLib")]
        public void It_counts_the_number_of_headers_correctly()
        {
            var httpHeader = new HttpHeadersSingleSegment(new Span <byte>(new UTF8Encoding().GetBytes(HeadersString)));

            Assert.Equal(httpHeader.Count, 8);
        }