Пример #1
0
        public void ContainsAndContainsKeyWork()
        {
            IDictionary <string, StringValues> headers = new HttpRequestHeaders();
            var kv1  = new KeyValuePair <string, StringValues>("host", new[] { "localhost" });
            var kv2  = new KeyValuePair <string, StringValues>("custom", new[] { "value" });
            var kv3  = new KeyValuePair <string, StringValues>("Content-Length", new[] { "0" });
            var kv1b = new KeyValuePair <string, StringValues>("host", new[] { "not-localhost" });
            var kv2b = new KeyValuePair <string, StringValues>("custom", new[] { "not-value" });
            var kv3b = new KeyValuePair <string, StringValues>("Content-Length", new[] { "1" });

            Assert.False(headers.ContainsKey("host"));
            Assert.False(headers.ContainsKey("custom"));
            Assert.False(headers.ContainsKey("Content-Length"));
            Assert.False(headers.Contains(kv1));
            Assert.False(headers.Contains(kv2));
            Assert.False(headers.Contains(kv3));

            headers["host"] = kv1.Value;
            Assert.True(headers.ContainsKey("host"));
            Assert.False(headers.ContainsKey("custom"));
            Assert.False(headers.ContainsKey("Content-Length"));
            Assert.True(headers.Contains(kv1));
            Assert.False(headers.Contains(kv2));
            Assert.False(headers.Contains(kv3));
            Assert.False(headers.Contains(kv1b));
            Assert.False(headers.Contains(kv2b));
            Assert.False(headers.Contains(kv3b));

            headers["custom"] = kv2.Value;
            Assert.True(headers.ContainsKey("host"));
            Assert.True(headers.ContainsKey("custom"));
            Assert.False(headers.ContainsKey("Content-Length"));
            Assert.True(headers.Contains(kv1));
            Assert.True(headers.Contains(kv2));
            Assert.False(headers.Contains(kv3));
            Assert.False(headers.Contains(kv1b));
            Assert.False(headers.Contains(kv2b));
            Assert.False(headers.Contains(kv3b));

            headers["Content-Length"] = kv3.Value;
            Assert.True(headers.ContainsKey("host"));
            Assert.True(headers.ContainsKey("custom"));
            Assert.True(headers.ContainsKey("Content-Length"));
            Assert.True(headers.Contains(kv1));
            Assert.True(headers.Contains(kv2));
            Assert.True(headers.Contains(kv3));
            Assert.False(headers.Contains(kv1b));
            Assert.False(headers.Contains(kv2b));
            Assert.False(headers.Contains(kv3b));
        }