本文整理汇总了C#中MockHeaders.Count方法的典型用法代码示例。如果您正苦于以下问题:C# MockHeaders.Count方法的具体用法?C# MockHeaders.Count怎么用?C# MockHeaders.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MockHeaders
的用法示例。
在下文中一共展示了MockHeaders.Count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryAddWithoutValidation_AddSingleValue_ValueParsed
public void TryAddWithoutValidation_AddSingleValue_ValueParsed()
{
MockHeaders headers = new MockHeaders();
headers.TryAddWithoutValidation(knownHeader, rawPrefix);
Assert.Equal(1, headers.Count());
Assert.Equal(1, headers.First().Value.Count());
Assert.Equal(parsedPrefix, headers.First().Value.First());
Assert.Equal(1, headers.Parser.TryParseValueCallCount);
}
示例2: TryAddWithoutValidation_AddTwoSingleValues_BothValuesParsed
public void TryAddWithoutValidation_AddTwoSingleValues_BothValuesParsed()
{
MockHeaders headers = new MockHeaders();
headers.TryAddWithoutValidation(knownHeader, rawPrefix + "1");
headers.TryAddWithoutValidation(knownHeader, rawPrefix + "2");
Assert.Equal(0, headers.Parser.TryParseValueCallCount);
Assert.Equal(1, headers.Count());
Assert.Equal(2, headers.First().Value.Count());
Assert.Equal(parsedPrefix + "1", headers.First().Value.ElementAt(0));
Assert.Equal(parsedPrefix + "2", headers.First().Value.ElementAt(1));
Assert.Equal(2, headers.Parser.TryParseValueCallCount);
}
示例3: TryAddWithoutValidation_AddTwoValidValuesAsOneString_BothValuesParsed
public void TryAddWithoutValidation_AddTwoValidValuesAsOneString_BothValuesParsed()
{
MockHeaders headers = new MockHeaders();
headers.TryAddWithoutValidation(knownHeader, rawPrefix + "1," + rawPrefix + "2");
Assert.Equal(0, headers.Parser.TryParseValueCallCount);
Assert.Equal(1, headers.Count());
Assert.Equal(2, headers.First().Value.Count());
Assert.Equal(parsedPrefix + "1", headers.First().Value.ElementAt(0));
Assert.Equal(parsedPrefix + "2", headers.First().Value.ElementAt(1));
// The parser gets called for each value in the raw string. I.e. if we have 1 raw string containing two
// values, the parser gets called twice.
Assert.Equal(2, headers.Parser.TryParseValueCallCount);
}
示例4: Add_SingleFirstAddThenTryAddWithoutValidation_TwoParsedValuesAdded
public void Add_SingleFirstAddThenTryAddWithoutValidation_TwoParsedValuesAdded()
{
MockHeaders headers = new MockHeaders();
headers.Add(knownHeader, rawPrefix + "1");
headers.TryAddWithoutValidation(knownHeader, rawPrefix + "2");
// Add() should trigger parsing. Since TryAddWithoutValidation() is called afterwards the second value is
// not parsed yet.
Assert.Equal(1, headers.Parser.TryParseValueCallCount);
Assert.Equal(1, headers.Count());
Assert.Equal(2, headers.First().Value.Count());
Assert.Equal(parsedPrefix + "1", headers.First().Value.ElementAt(0));
Assert.Equal(parsedPrefix + "2", headers.First().Value.ElementAt(1));
// Value is already parsed. There shouldn't be additional calls to the parser.
Assert.Equal(2, headers.Parser.TryParseValueCallCount);
}
示例5: Add_SingleFirstTryAddWithoutValidationForEmptyValueThenAdd_OneParsedValueAddedEmptyIgnored
public void Add_SingleFirstTryAddWithoutValidationForEmptyValueThenAdd_OneParsedValueAddedEmptyIgnored()
{
MockHeaders headers = new MockHeaders();
headers.TryAddWithoutValidation(knownHeader, string.Empty);
headers.Add(knownHeader, rawPrefix + "1");
// Add() should trigger parsing. TryAddWithoutValidation() doesn't trigger parsing, but Add() triggers
// parsing of raw header values (TryParseValue() is called)
Assert.Equal(2, headers.Parser.TryParseValueCallCount);
Assert.Equal(1, headers.Count());
Assert.Equal(1, headers.First().Value.Count());
Assert.Equal(parsedPrefix + "1", headers.First().Value.ElementAt(0));
// Value is already parsed. There shouldn't be additional calls to the parser.
Assert.Equal(2, headers.Parser.TryParseValueCallCount);
}
示例6: AddHeaders_SourceHasEmptyHeaderStore_DestinationRemainsUnchanged
public void AddHeaders_SourceHasEmptyHeaderStore_DestinationRemainsUnchanged()
{
Dictionary<string, HttpHeaderParser> parserStore = new Dictionary<string, HttpHeaderParser>();
parserStore.Add("known1", new MockHeaderParser());
MockHeaders source = new MockHeaders(parserStore);
MockHeaders destination = new MockHeaders(parserStore);
destination.Add("known1", rawPrefix);
destination.AddHeaders(source);
Assert.Equal(1, destination.Count());
}
示例7: TryAddWithoutValidation_AddTwoValuesOneValidOneInvalidAsOneString_RawStringAddedAsInvalid
public void TryAddWithoutValidation_AddTwoValuesOneValidOneInvalidAsOneString_RawStringAddedAsInvalid()
{
MockHeaders headers = new MockHeaders();
headers.TryAddWithoutValidation(knownHeader, rawPrefix + "1," + invalidHeaderValue);
Assert.Equal(0, headers.Parser.TryParseValueCallCount);
Assert.Equal(1, headers.Count());
Assert.Equal(1, headers.First().Value.Count());
// We expect the value to be returned without change since it couldn't be parsed in its entirety.
Assert.Equal(rawPrefix + "1," + invalidHeaderValue, headers.First().Value.ElementAt(0));
// The parser gets called twice, but the second time it returns false, because it tries to parse
// 'invalidHeaderValue'.
Assert.Equal(2, headers.Parser.TryParseValueCallCount);
}
示例8: AddHeaders_DestinationHasEmptyHeaderStore_DestinationHeaderStoreGetsCreatedAndValuesAdded
public void AddHeaders_DestinationHasEmptyHeaderStore_DestinationHeaderStoreGetsCreatedAndValuesAdded()
{
Dictionary<string, HttpHeaderParser> parserStore = new Dictionary<string, HttpHeaderParser>();
parserStore.Add("known1", new MockHeaderParser());
MockHeaders source = new MockHeaders(parserStore);
source.Add("known1", rawPrefix);
MockHeaders destination = new MockHeaders(parserStore);
destination.AddHeaders(source);
Assert.Equal(1, destination.Count());
}
示例9: Add_MultipleAddThreeValidValuesAsOneString_BothValuesParsed
public void Add_MultipleAddThreeValidValuesAsOneString_BothValuesParsed()
{
MockHeaders headers = new MockHeaders();
headers.Add(knownHeader, rawPrefix + "1," + rawPrefix + "2," + rawPrefix + "3");
Assert.Equal(3, headers.Parser.TryParseValueCallCount);
Assert.Equal(1, headers.Count());
Assert.Equal(3, headers.First().Value.Count());
Assert.Equal(parsedPrefix + "1", headers.First().Value.ElementAt(0));
Assert.Equal(parsedPrefix + "2", headers.First().Value.ElementAt(1));
Assert.Equal(parsedPrefix + "3", headers.First().Value.ElementAt(2));
}
示例10: Add_MultipleAddThreeValidValuesWithOneCall_ValuesParsedCorrectly
public void Add_MultipleAddThreeValidValuesWithOneCall_ValuesParsedCorrectly()
{
MockHeaders headers = new MockHeaders();
string[] values = new string[] { rawPrefix + "1", rawPrefix + "2", rawPrefix + "3" };
headers.Add(knownHeader, values);
// Add() should trigger parsing.
Assert.Equal(3, headers.Parser.TryParseValueCallCount);
Assert.Equal(1, headers.Count());
Assert.Equal(3, headers.First().Value.Count());
Assert.Equal(parsedPrefix + "1", headers.First().Value.ElementAt(0));
Assert.Equal(parsedPrefix + "2", headers.First().Value.ElementAt(1));
Assert.Equal(parsedPrefix + "3", headers.First().Value.ElementAt(2));
// Value is already parsed. There shouldn't be additional calls to the parser.
Assert.Equal(3, headers.Parser.TryParseValueCallCount);
}
示例11: TryAddWithoutValidation_AddMultipleValueStringToSingleValueHeaders_MultipleValueStringAddedAsInvalid
public void TryAddWithoutValidation_AddMultipleValueStringToSingleValueHeaders_MultipleValueStringAddedAsInvalid()
{
MockHeaderParser parser = new MockHeaderParser(false); // doesn't support multiple values.
MockHeaders headers = new MockHeaders(parser);
headers.TryAddWithoutValidation(knownHeader, rawPrefix + "1," + rawPrefix + "2");
Assert.Equal(0, headers.Parser.TryParseValueCallCount);
// Since parsing the header value fails because it is composed of 2 values, the original string is added
// to the list of 'invalid values'. Therefore we only have 1 header value (the original string).
Assert.Equal(1, headers.Count());
Assert.Equal(1, headers.First().Value.Count());
Assert.Equal(rawPrefix + "1," + rawPrefix + "2", headers.First().Value.First());
Assert.Equal(1, headers.Parser.TryParseValueCallCount);
}
示例12: TryAddWithoutValidation_AddMultipleValueToSingleValueHeaders_FirstHeaderAddedOthersAreInvalid
public void TryAddWithoutValidation_AddMultipleValueToSingleValueHeaders_FirstHeaderAddedOthersAreInvalid()
{
MockHeaderParser parser = new MockHeaderParser(false); // doesn't support multiple values.
MockHeaders headers = new MockHeaders(parser);
headers.TryAddWithoutValidation(knownHeader, rawPrefix + "1");
headers.TryAddWithoutValidation(knownHeader, rawPrefix + "2");
Assert.Equal(0, headers.Parser.TryParseValueCallCount);
Assert.Equal(1, headers.Count());
Assert.Equal(2, headers.First().Value.Count());
// Note that the first value was parsed and added to the 'parsed values' list. The second value however
// was added to the 'invalid values' list since the header doesn't support multiple values.
Assert.Equal(parsedPrefix + "1", headers.First().Value.ElementAt(0));
Assert.Equal(rawPrefix + "2", headers.First().Value.ElementAt(1));
// The parser is only called once for the first value. HttpHeaders doesn't invoke the parser for
// additional values if the parser only supports one value.
Assert.Equal(1, headers.Parser.TryParseValueCallCount);
}
示例13: TryAddWithoutValidation_AddNullAndEmptyValuesToUnknownHeader_TwoEmptyStringsAddedAsValues
public void TryAddWithoutValidation_AddNullAndEmptyValuesToUnknownHeader_TwoEmptyStringsAddedAsValues()
{
MockHeaders headers = new MockHeaders();
headers.TryAddWithoutValidation(customHeader, (string)null);
headers.TryAddWithoutValidation(customHeader, string.Empty);
Assert.Equal(1, headers.Count());
Assert.Equal(2, headers.First().Value.Count());
// TryAddWithoutValidation() adds 'null' as string.empty to distinguish between an empty raw value and no raw
// value. For custom headers we just add what the user gives us. I.e. the result is a header with two empty
// values.
Assert.Equal(string.Empty, headers.First().Value.ElementAt(0));
Assert.Equal(string.Empty, headers.First().Value.ElementAt(1));
}
示例14: TryAddWithoutValidation_AddNullAndEmptyValuesToKnownHeader_HeaderRemovedFromCollection
public void TryAddWithoutValidation_AddNullAndEmptyValuesToKnownHeader_HeaderRemovedFromCollection()
{
MockHeaders headers = new MockHeaders();
headers.TryAddWithoutValidation(knownHeader, (string)null);
headers.TryAddWithoutValidation(knownHeader, string.Empty);
Assert.Equal(0, headers.Parser.TryParseValueCallCount);
Assert.Equal(0, headers.Count());
// TryAddWithoutValidation() adds 'null' as string.empty to distinguish between an empty raw value and no raw
// value. When the parser is called later, the parser can decide whether empty strings are valid or not.
// In our case the MockParser returns 'success' with a parsed value of 'null' indicating that it is OK to
// have empty values, but they should be ignored.
Assert.Equal(2, headers.Parser.EmptyValueCount);
Assert.Equal(2, headers.Parser.TryParseValueCallCount);
}
示例15: TryAddWithoutValidation_AddValueForUnknownHeader_ValueAddedToStore
public void TryAddWithoutValidation_AddValueForUnknownHeader_ValueAddedToStore()
{
MockHeaders headers = new MockHeaders();
headers.TryAddWithoutValidation(customHeader, "custom value");
Assert.Equal(1, headers.Count());
Assert.Equal(1, headers.First().Value.Count());
Assert.Equal("custom value", headers.First().Value.First());
Assert.Equal(0, headers.Parser.TryParseValueCallCount);
}