コード例 #1
0
        public void Add_HeaderIsRepeating_AddsSameHeader()
        {
            // Arrange
            var headers = new HttpHeaderCollection(_initialHeaders);

            // Act
            var sameHeader = new HttpHeader(headers.ElementAt(0).Name, headers.ElementAt(0).Value);

            headers.Add(sameHeader);

            // Assert
            Assert.That(headers.Count(), Is.EqualTo(7));
            Assert.That(headers.Last(), Is.SameAs(sameHeader));

            var headersString = headers.ToString();

            Assert.That(headersString, Is.EqualTo(@"Accept: text/html, application/xhtml+xml, image/jxr, */*
Accept-Language: ru-RU
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299
Accept-Encoding: gzip, deflate
Host: allitebooks.com
Connection: Keep-Alive
Accept: text/html, application/xhtml+xml, image/jxr, */*

"));

            var binary = headers.ToArray();

            Assert.That(binary, Is.EquivalentTo(headersString.ToAsciiBytes()));
        }
コード例 #2
0
        public void Constructor_CollectionOfHeaders_CreatesCollectionWithCopiedHeaders()
        {
            // Arrange

            // Act
            var headers = new HttpHeaderCollection(_initialHeaders);

            // Assert
            Assert.That(headers.Count(), Is.EqualTo(6));

            for (int i = 0; i < 6; i++)
            {
                Assert.That(headers.ElementAt(i), Is.SameAs(_initialHeaders[i]));
            }

            var headersString = headers.ToString();

            Assert.That(headersString, Is.EqualTo(_initialHeadersString));

            var binary = headers.ToArray();

            Assert.That(binary, Is.EquivalentTo(_initialHeadersString.ToAsciiBytes()));
        }