当前位置: 首页>>代码示例>>C#>>正文


C# MockHeaders.Contains方法代码示例

本文整理汇总了C#中MockHeaders.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# MockHeaders.Contains方法的具体用法?C# MockHeaders.Contains怎么用?C# MockHeaders.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MockHeaders的用法示例。


在下文中一共展示了MockHeaders.Contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TryAddWithoutValidation_MultipleAddInvalidValuesToNonExistingHeader_AddHeader

        public void TryAddWithoutValidation_MultipleAddInvalidValuesToNonExistingHeader_AddHeader()
        {
            MockHeaders headers = new MockHeaders();
            headers.TryAddWithoutValidation(knownHeader, new string[] { invalidHeaderValue });

            // Make sure the header did not get added since we just tried to add an invalid value.
            Assert.True(headers.Contains(knownHeader));
            Assert.Equal(1, headers.First().Value.Count());
            Assert.Equal(invalidHeaderValue, headers.First().Value.ElementAt(0));
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:10,代码来源:HttpHeadersTest.cs

示例2: TryAddWithoutValidation_MultipleAddValidValueThenAddInvalidValuesToNonExistingHeader_AddHeader

        public void TryAddWithoutValidation_MultipleAddValidValueThenAddInvalidValuesToNonExistingHeader_AddHeader()
        {
            MockHeaders headers = new MockHeaders();
            headers.TryAddWithoutValidation(knownHeader, new string[] { rawPrefix + "1", invalidHeaderValue });

            Assert.True(headers.Contains(knownHeader));
            Assert.Equal(2, headers.First().Value.Count());
            Assert.Equal(parsedPrefix + "1", headers.First().Value.ElementAt(0));
            Assert.Equal(invalidHeaderValue, headers.First().Value.ElementAt(1));
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:10,代码来源:HttpHeadersTest.cs

示例3: GetParsedValues_AddInvalidValueToHeader_HeaderGetsRemovedAndNullReturned

        public void GetParsedValues_AddInvalidValueToHeader_HeaderGetsRemovedAndNullReturned()
        {
            MockHeaders headers = new MockHeaders();
            headers.TryAddWithoutValidation(knownHeader, invalidHeaderValue + "\r\ninvalid");

            Assert.Equal(0, headers.Parser.TryParseValueCallCount);

            object storeValue = headers.GetParsedValues(knownHeader);
            Assert.Null(storeValue);
            Assert.False(headers.Contains(knownHeader));
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:11,代码来源:HttpHeadersTest.cs

示例4: MockHeaders

        public void TryAddWithoutValidation_AddValueContainingNewLine_NewLineFollowedByWhitespaceIsOKButNewLineFollowedByNonWhitespaceIsRejected()
        {
            MockHeaders headers = new MockHeaders();

            // The header parser rejects both of the following values. Both values contain new line chars. According
            // to the RFC, LWS supports newlines followed by whitespaces. I.e. the first value gets rejected by the
            // parser, but added to the list of invalid values.
            headers.TryAddWithoutValidation(knownHeader, invalidHeaderValue + "\r\n other: value"); // OK, LWS is allowed
            Assert.Equal(1, headers.Count());
            Assert.Equal(1, headers.First().Value.Count());
            Assert.Equal(invalidHeaderValue + "\r\n other: value", headers.First().Value.First());
            Assert.Equal(1, headers.Parser.TryParseValueCallCount);

            // This value is considered invalid (newline char followed by non-whitepace). However, since
            // TryAddWithoutValidation() only causes the header value to be analyzed when it gets actually accessed, no
            // exception is thrown. Instead the value is discarded and a warning is logged.
            headers.Clear();
            headers.TryAddWithoutValidation(knownHeader, invalidHeaderValue + "\r\nother:value");
            Assert.False(headers.Contains(knownHeader));
            Assert.Equal(0, headers.Count());

            // Adding newline followed by whitespace to a custom header is OK.
            headers.Clear();
            headers.TryAddWithoutValidation("custom", "value\r\n other: value"); // OK, LWS is allowed
            Assert.Equal(1, headers.Count());
            Assert.Equal(1, headers.First().Value.Count());
            Assert.Equal("value\r\n other: value", headers.First().Value.First());

            // Adding newline followed by non-whitespace chars is invalid. The value is discarded and a warning is
            // logged.
            headers.Clear();
            headers.TryAddWithoutValidation("custom", "value\r\nother: value");
            Assert.False(headers.Contains("custom"));
            Assert.Equal(0, headers.Count());

            // Also ending a value with newline is invalid. Verify that valid values are added.
            headers.Clear();
            headers.Parser.TryParseValueCallCount = 0;
            headers.TryAddWithoutValidation(knownHeader, rawPrefix + "\rvalid");
            headers.TryAddWithoutValidation(knownHeader, invalidHeaderValue + "\r\n");
            headers.TryAddWithoutValidation(knownHeader, rawPrefix + "\n," + invalidHeaderValue + "\r\nother");
            Assert.Equal(1, headers.Count());
            Assert.Equal(1, headers.First().Value.Count());
            Assert.Equal(parsedPrefix + "\rvalid", headers.First().Value.First());
            Assert.Equal(4, headers.Parser.TryParseValueCallCount);

            headers.Clear();
            headers.TryAddWithoutValidation("custom", "value\r\ninvalid");
            headers.TryAddWithoutValidation("custom", "value\r\n valid");
            headers.TryAddWithoutValidation("custom", "validvalue, invalid\r\nvalue");
            Assert.Equal(1, headers.Count());
            Assert.Equal(1, headers.First().Value.Count());
            Assert.Equal("value\r\n valid", headers.First().Value.First());
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:54,代码来源:HttpHeadersTest.cs

示例5: Add_MultipleAddValidValueThenAddInvalidValuesToNonExistingHeader_ThrowAndDontAddHeader

        public void Add_MultipleAddValidValueThenAddInvalidValuesToNonExistingHeader_ThrowAndDontAddHeader()
        {
            MockHeaders headers = new MockHeaders();

            Assert.Throws<FormatException>(() => { headers.Add(knownHeader, new string[] { rawPrefix + "1", invalidHeaderValue }); });

            // Make sure the header got added due to the valid add. Note that the first value in the array
            // is valid, so it gets added.
            Assert.True(headers.Contains(knownHeader), "Header was not added even though we added 1 valid value.");
            Assert.Equal(1, headers.First().Value.Count());
            Assert.Equal(parsedPrefix + "1", headers.First().Value.ElementAt(0));
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:12,代码来源:HttpHeadersTest.cs

示例6: Contains_AddValuesWithInvalidNewlineChars_HeadersGetRemovedWhenCallingContains

        public void Contains_AddValuesWithInvalidNewlineChars_HeadersGetRemovedWhenCallingContains()
        {
            MockHeaders headers = new MockHeaders();

            headers.TryAddWithoutValidation(knownHeader, invalidHeaderValue + "\r\ninvalid");
            headers.TryAddWithoutValidation("custom", "invalid\r\nvalue");

            Assert.False(headers.Contains(knownHeader), "Store should not have an entry for 'knownHeader'.");
            Assert.False(headers.Contains("custom"), "Store should not have an entry for 'custom'.");
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:10,代码来源:HttpHeadersTest.cs

示例7: Add_MultipleAddInvalidValuesToNonExistingHeader_ThrowAndDontAddHeader

        public void Add_MultipleAddInvalidValuesToNonExistingHeader_ThrowAndDontAddHeader()
        {
            MockHeaders headers = new MockHeaders();

            Assert.Throws<FormatException>(() => { headers.Add(knownHeader, new string[] { invalidHeaderValue }); });

            // Make sure the header did not get added since we just tried to add an invalid value.
            Assert.False(headers.Contains(knownHeader), "Header was added even if we just added an invalid value.");
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:9,代码来源:HttpHeadersTest.cs

示例8: Contains_CallContainsForEmptyHeader_ReturnsFalse

 public void Contains_CallContainsForEmptyHeader_ReturnsFalse()
 {
     MockHeaders headers = new MockHeaders();
     headers.Add(knownHeader, string.Empty);
     Assert.False(headers.Contains(knownHeader));
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:6,代码来源:HttpHeadersTest.cs

示例9: Contains_CallContainsForExistingHeader_ReturnsTrue

        public void Contains_CallContainsForExistingHeader_ReturnsTrue()
        {
            MockHeaders headers = new MockHeaders();
            headers.Add("custom1", "customValue1");
            headers.Add("custom2", "customValue2");
            headers.Add("custom3", "customValue3");
            headers.Add("custom4", "customValue4");
            headers.TryAddWithoutValidation(knownHeader, rawPrefix);

            // Nothing got parsed so far since we just added custom headers and for the known header we called
            // TryAddWithoutValidation().
            Assert.Equal(0, headers.Parser.TryParseValueCallCount);

            Assert.True(headers.Contains(knownHeader));

            // Contains() should trigger parsing of values added with TryAddWithoutValidation(): If the value was invalid,
            // i.e. contains invalid newline chars, then the header will be removed from the collection.
            Assert.Equal(1, headers.Parser.TryParseValueCallCount);
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:19,代码来源:HttpHeadersTest.cs

示例10: Contains_CallContainsForNonExistingHeader_ReturnsFalse

 public void Contains_CallContainsForNonExistingHeader_ReturnsFalse()
 {
     MockHeaders headers = new MockHeaders();
     headers.Add(knownHeader, rawPrefix);
     Assert.False(headers.Contains("doesntexist"));
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:6,代码来源:HttpHeadersTest.cs

示例11: Contains_CallContainsFromUninitializedHeaderStore_ReturnsFalse

 public void Contains_CallContainsFromUninitializedHeaderStore_ReturnsFalse()
 {
     MockHeaders headers = new MockHeaders();
     Assert.False(headers.Contains("doesntexist"));
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:5,代码来源:HttpHeadersTest.cs

示例12: Contains_UseNullHeader_Throw

 public void Contains_UseNullHeader_Throw()
 {
     MockHeaders headers = new MockHeaders();
     
     Assert.Throws<ArgumentException>(() => { headers.Contains(null); });
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:6,代码来源:HttpHeadersTest.cs

示例13: Add_SingleAddInvalidValueToNonExistingHeader_ThrowAndDontAddHeader

        public void Add_SingleAddInvalidValueToNonExistingHeader_ThrowAndDontAddHeader()
        {
            // Since Add() immediately parses the value, it will throw an exception if the value is invalid.
            MockHeaders headers = new MockHeaders();
            Assert.Throws<FormatException>(() => { headers.Add(knownHeader, invalidHeaderValue); });

            // Make sure the header did not get added to the store.
            Assert.False(headers.Contains(knownHeader),
                "No header expected to be added since header value was invalid.");
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:10,代码来源:HttpHeadersTest.cs

示例14: Add_SingleAddValidValueThenAddInvalidValue_ThrowAndHeaderContainsValidValue

        public void Add_SingleAddValidValueThenAddInvalidValue_ThrowAndHeaderContainsValidValue()
        {
            MockHeaders headers = new MockHeaders();
            headers.Add(knownHeader, rawPrefix);

            Assert.Throws<FormatException>(() => { headers.Add(knownHeader, invalidHeaderValue); });

            // Make sure the header did not get removed due to the failed add.
            Assert.True(headers.Contains(knownHeader), "Header was removed even if there is a valid header value.");
            Assert.Equal(1, headers.First().Value.Count());
            Assert.Equal(parsedPrefix, headers.First().Value.ElementAt(0));
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:12,代码来源:HttpHeadersTest.cs

示例15: ContainsParsedValue_CallFromEmptyHeaderStore_ReturnsFalse

        public void ContainsParsedValue_CallFromEmptyHeaderStore_ReturnsFalse()
        {
            MockHeaders headers = new MockHeaders();

            // This will create a header entry with no value.
            headers.Add(knownHeader, string.Empty);

            Assert.False(headers.Contains(knownHeader), "Expected known header to be in the store.");

            // This will just return fals and not touch the header.
            Assert.False(headers.ContainsParsedValue(knownHeader, "x"),
                "Expected 'ContainsParsedValue' to return false.");
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:13,代码来源:HttpHeadersTest.cs


注:本文中的MockHeaders.Contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。