Beispiel #1
0
        public void AddCombinedHeadersWhenEmpty()
        {
            CombinedHttpHeaders headers      = NewCombinedHttpHeaders();
            CombinedHttpHeaders otherHeaders = NewCombinedHttpHeaders();

            otherHeaders.Add(HeaderName, "a");
            otherHeaders.Add(HeaderName, "b");
            headers.Add(otherHeaders);
            Assert.Equal("a,b", headers.Get(HeaderName, null)?.ToString());
        }
Beispiel #2
0
        public void SetCombinedHeadersWhenNotEmpty()
        {
            CombinedHttpHeaders headers = NewCombinedHttpHeaders();

            headers.Add(HeaderName, "a");
            CombinedHttpHeaders otherHeaders = NewCombinedHttpHeaders();

            otherHeaders.Add(HeaderName, "b");
            otherHeaders.Add(HeaderName, "c");
            headers.Set(otherHeaders);
            Assert.Equal("b,c", headers.Get(HeaderName, null)?.ToString());
        }
Beispiel #3
0
        public void SetUncombinedHeaders()
        {
            CombinedHttpHeaders headers = NewCombinedHttpHeaders();

            headers.Add(HeaderName, "a");
            var otherHeaders = new DefaultHttpHeaders();

            otherHeaders.Add(HeaderName, "b");
            otherHeaders.Add(HeaderName, "c");
            headers.Set(otherHeaders);
            Assert.Equal("b,c", headers.Get(HeaderName, null)?.ToString());
        }
Beispiel #4
0
        static void AssertCsvValues(CombinedHttpHeaders headers, HeaderValue headerValue)
        {
            Assert.True(ContentEquals(headerValue.AsCsv(), headers.Get(HeaderName, null)));

            List <ICharSequence>  expected = headerValue.AsList();
            IList <ICharSequence> values   = headers.GetAll(HeaderName);

            Assert.Equal(expected.Count, values.Count);
            for (int i = 0; i < expected.Count; i++)
            {
                Assert.True(expected[i].ContentEquals(values[i]));
            }
        }
Beispiel #5
0
        public void OwsTrimming()
        {
            CombinedHttpHeaders headers = NewCombinedHttpHeaders();

            headers.Set(HeaderName, new List <ICharSequence> {
                (StringCharSequence)"\ta", (StringCharSequence)"   ", (StringCharSequence)"  b ", (StringCharSequence)"\t \t"
            });
            headers.Add(HeaderName, new List <ICharSequence> {
                (StringCharSequence)" c, d \t"
            });

            var expected = new List <ICharSequence> {
                (StringCharSequence)"a", (StringCharSequence)"", (StringCharSequence)"b", (StringCharSequence)"", (StringCharSequence)"c, d"
            };
            IList <ICharSequence> actual = headers.GetAll(HeaderName);

            Assert.True(expected.SequenceEqual(actual));
            Assert.Equal("a,,b,,\"c, d\"", headers.Get(HeaderName, null)?.ToString());

            Assert.True(headers.ContainsValue(HeaderName, (StringCharSequence)"a", true));
            Assert.True(headers.ContainsValue(HeaderName, (StringCharSequence)" a ", true));
            Assert.True(headers.ContainsValue(HeaderName, (StringCharSequence)"a", true));
            Assert.False(headers.ContainsValue(HeaderName, (StringCharSequence)"a,b", true));

            Assert.False(headers.ContainsValue(HeaderName, (StringCharSequence)" c, d ", true));
            Assert.False(headers.ContainsValue(HeaderName, (StringCharSequence)"c, d", true));
            Assert.True(headers.ContainsValue(HeaderName, (StringCharSequence)" c ", true));
            Assert.True(headers.ContainsValue(HeaderName, (StringCharSequence)"d", true));

            Assert.True(headers.ContainsValue(HeaderName, (StringCharSequence)"\t", true));
            Assert.True(headers.ContainsValue(HeaderName, (StringCharSequence)"", true));

            Assert.False(headers.ContainsValue(HeaderName, (StringCharSequence)"e", true));

            CombinedHttpHeaders copiedHeaders = NewCombinedHttpHeaders();

            copiedHeaders.Add(headers);
            Assert.Equal(new List <ICharSequence> {
                (StringCharSequence)"a", (StringCharSequence)"", (StringCharSequence)"b", (StringCharSequence)"", (StringCharSequence)"c, d"
            }, copiedHeaders.GetAll(HeaderName));
        }
Beispiel #6
0
 static void AssertCsvValue(CombinedHttpHeaders headers, HeaderValue headerValue)
 {
     Assert.True(ContentEquals((StringCharSequence)headerValue.ToString(), headers.Get(HeaderName, null)));
     Assert.True(ContentEquals((StringCharSequence)headerValue.ToString(), headers.GetAll(HeaderName)[0]));
 }
Beispiel #7
0
        public void AddCharSequencesCsvMultipleTimes()
        {
            CombinedHttpHeaders headers = NewCombinedHttpHeaders();

            for (int i = 0; i < 5; ++i)
            {
                headers.Add(HeaderName, "value");
            }
            Assert.True(ContentEquals((StringCharSequence)"value,value,value,value,value", headers.Get(HeaderName, null)));
        }
Beispiel #8
0
        public void AddCharSequencesCsvWithValueContainingCommas()
        {
            CombinedHttpHeaders headers = NewCombinedHttpHeaders();

            headers.Add(HeaderName, HeaderValue.Eight.Subset(6));
            Assert.True(ContentEquals((StringCharSequence)HeaderValue.Eight.SubsetAsCsvString(6), headers.Get(HeaderName, null)));
            Assert.Equal(HeaderValue.Eight.Subset(6), headers.GetAll(HeaderName));
        }