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); }
public void TryAddWithoutValidation_UseInvalidHeader_False() { MockHeaders headers = new MockHeaders(); // Spaces are not allowed in header names. This test is used to validate private method // HttpHeaders.CheckHeaders(). Since that helper method is used in all other public methods, this // test is not repeated for other public methods. Assert.False(headers.TryAddWithoutValidation("invalid header", "value")); }
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); }
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); }
public void ContainsParsedValue_ContainsParsedValueForExistingHeaderButNonAvailableValue_ReturnsFalse() { MockHeaders headers = new MockHeaders(); headers.TryAddWithoutValidation(knownHeader, rawPrefix); Assert.Equal(0, headers.Parser.TryParseValueCallCount); Assert.False(headers.ContainsParsedValue(knownHeader, "custom1")); // ContainsParsedValue() must trigger raw value parsing for the header it was asked for. Assert.Equal(1, headers.Parser.TryParseValueCallCount); }
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); }
public void Add_SingleFirstTryAddWithoutValidationThenAddToSingleValueHeader_AddThrows() { MockHeaderParser parser = new MockHeaderParser(false); // doesn't support multiple values. MockHeaders headers = new MockHeaders(parser); headers.TryAddWithoutValidation(knownHeader, rawPrefix + "1"); Assert.Throws<FormatException>(() => {headers.Add(knownHeader, rawPrefix + "2"); }); }
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); }
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); }
public void TryAddWithoutValidation_AddNullValueForUnknownHeader_EmptyStringAddedAsValue() { MockHeaders headers = new MockHeaders(); headers.TryAddWithoutValidation(customHeader, (string)null); Assert.Equal(1, headers.Count()); Assert.Equal(1, headers.First().Value.Count()); // 'null' values are internally stored as string.Empty. Since we added a custom header, there is no // parser and the empty string is just added to the list of 'parsed values'. Assert.Equal(string.Empty, headers.First().Value.First()); Assert.Equal(0, headers.Parser.TryParseValueCallCount); }
public void AddHeaders_SourceHasInvalidHeaderValues_InvalidHeadersRemovedFromSourceAndNotCopiedToDestination() { Dictionary<string, HttpHeaderParser> parserStore = new Dictionary<string, HttpHeaderParser>(); parserStore.Add("known", new MockHeaderParser()); MockHeaders source = new MockHeaders(parserStore); source.TryAddWithoutValidation("known", invalidHeaderValue + "\r\ninvalid"); source.TryAddWithoutValidation("custom", "invalid\r\nvalue"); MockHeaders destination = new MockHeaders(parserStore); destination.AddHeaders(source); Assert.Equal(0, source.Count()); Assert.False(source.Contains("known"), "source contains 'known' header."); Assert.False(source.Contains("custom"), "source contains 'custom' header."); Assert.Equal(0, destination.Count()); Assert.False(destination.Contains("known"), "destination contains 'known' header."); Assert.False(destination.Contains("custom"), "destination contains 'custom' header."); }
public void TryAddWithoutValidation_AddNullValueForKnownHeader_ParserRejectsNullEmptyStringAdded() { MockHeaders headers = new MockHeaders(); headers.TryAddWithoutValidation(knownHeader, (string)null); Assert.Equal(0, headers.Parser.TryParseValueCallCount); // MockParser is called with an empty string and decides that it is OK to have empty values but they // shouldn't be added to the list of header values. HttpHeaders will remove the header since it doesn't // have values. Assert.Equal(0, headers.Count()); Assert.Equal(1, headers.Parser.TryParseValueCallCount); }
public void AddHeaders_SourceAndDestinationStoreHaveMultipleHeaders_OnlyHeadersNotInDestinationAreCopiedFromSource() { Dictionary<string, HttpHeaderParser> parserStore = new Dictionary<string, HttpHeaderParser>(); parserStore.Add("known1", new MockHeaderParser()); parserStore.Add("known2", new MockHeaderParser()); parserStore.Add("known3", new MockHeaderParser()); parserStore.Add("known4", new CustomTypeHeaderParser()); // Add header values to the source store. MockHeaders source = new MockHeaders(parserStore); source.Add("custom1", "source10"); source.Add("custom1", "source11"); source.TryAddWithoutValidation("custom2", "source2"); source.Add("known1", rawPrefix + "3"); source.TryAddWithoutValidation("known1", rawPrefix + "4"); source.TryAddWithoutValidation("known2", rawPrefix + "5"); source.TryAddWithoutValidation("known2", invalidHeaderValue); source.TryAddWithoutValidation("known2", rawPrefix + "7"); // this header value gets removed when it gets parsed. source.TryAddWithoutValidation("known3", (string)null); source.Add("known3", string.Empty); DateTimeOffset known4Value1 = new DateTimeOffset(2010, 6, 15, 18, 31, 34, TimeSpan.Zero); DateTimeOffset known4Value2 = new DateTimeOffset(2010, 4, 8, 11, 21, 04, TimeSpan.Zero); source.AddParsedValue("known4", known4Value1); source.AddParsedValue("known4", known4Value2); source.Add("custom5", "source5"); source.TryAddWithoutValidation("custom6", (string)null); // This header value gets added even though it doesn't have values. But since this is a custom header we // assume it supports empty values. source.TryAddWithoutValidation("custom7", (string)null); source.Add("custom7", string.Empty); // Add header values to the destination store. MockHeaders destination = new MockHeaders(parserStore); destination.Add("custom2", "destination1"); destination.Add("known1", rawPrefix + "9"); // Now add all headers that are in source but not destination to destination. destination.AddHeaders(source); Assert.Equal(8, destination.Count()); Assert.Equal(2, destination.GetValues("custom1").Count()); Assert.Equal("source10", destination.GetValues("custom1").ElementAt(0)); Assert.Equal("source11", destination.GetValues("custom1").ElementAt(1)); // This value was set in destination. The header in source was ignored. Assert.Equal(1, destination.GetValues("custom2").Count()); Assert.Equal("destination1", destination.GetValues("custom2").First()); // This value was set in destination. The header in source was ignored. Assert.Equal(1, destination.GetValues("known1").Count()); Assert.Equal(parsedPrefix + "9", destination.GetValues("known1").First()); // The header in source gets first parsed and then copied to destination. Note that here we have one // invalid value. Assert.Equal(3, destination.GetValues("known2").Count()); Assert.Equal(parsedPrefix + "5", destination.GetValues("known2").ElementAt(0)); Assert.Equal(parsedPrefix + "7", destination.GetValues("known2").ElementAt(1)); Assert.Equal(invalidHeaderValue, destination.GetValues("known2").ElementAt(2)); // Header 'known3' should not be copied, since it doesn't contain any values. Assert.False(destination.Contains("known3"), "'known3' header value count."); Assert.Equal(2, destination.GetValues("known4").Count()); Assert.Equal(known4Value1.ToString(), destination.GetValues("known4").ElementAt(0)); Assert.Equal(known4Value2.ToString(), destination.GetValues("known4").ElementAt(1)); Assert.Equal("source5", destination.GetValues("custom5").First()); Assert.Equal(string.Empty, destination.GetValues("custom6").First()); // Unlike 'known3', 'custom7' was added even though it only had empty values. The reason is that 'custom7' // is a custom header so we just add whatever value we get passed in. Assert.Equal(2, destination.GetValues("custom7").Count()); Assert.Equal("", destination.GetValues("custom7").ElementAt(0)); Assert.Equal("", destination.GetValues("custom7").ElementAt(1)); }
public void ContainsParsedValue_AddOneValueToKnownHeaderAndCompareWithValueThatDiffersInCase_CustomComparerUsedForComparison() { MockHeaders headers = new MockHeaders(); headers.AddParsedValue(knownHeader, "value"); // Our custom comparer (MockComparer) does case-insensitive value comparison. Verify that our custom // comparer is used to compare the header value. Assert.True(headers.ContainsParsedValue(knownHeader, "VALUE")); Assert.Equal(1, headers.Parser.MockComparer.EqualsCount); headers.Clear(); headers.TryAddWithoutValidation(knownHeader, invalidHeaderValue); Assert.False(headers.ContainsParsedValue(knownHeader, invalidHeaderValue)); }
public void ContainsParsedValue_ContainsParsedValueForExistingHeaderWithAvailableValue_ReturnsTrue() { MockHeaders headers = new MockHeaders(); headers.TryAddWithoutValidation(knownHeader, rawPrefix + "1"); headers.TryAddWithoutValidation(knownHeader, rawPrefix + "2"); headers.TryAddWithoutValidation(knownHeader, rawPrefix + "3"); headers.TryAddWithoutValidation(knownHeader, rawPrefix + "4"); Assert.Equal(0, headers.Parser.TryParseValueCallCount); Assert.True(headers.ContainsParsedValue(knownHeader, parsedPrefix + "3")); // ContainsParsedValue() must trigger raw value parsing for the header it was asked for. Assert.Equal(4, headers.Parser.TryParseValueCallCount); }
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)); }
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)); }
public void TryAddWithoutValidation_UseNullHeader_False() { MockHeaders headers = new MockHeaders(); Assert.False(headers.TryAddWithoutValidation(null, "value")); }
public void TryAddWithoutValidation_MultipleAddNullValueCollection_Throws() { MockHeaders headers = new MockHeaders(); string[] values = null; Assert.Throws<ArgumentNullException>(() => { headers.TryAddWithoutValidation(knownHeader, values); }); }
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); }
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); }
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)); }
public void Add_SingleAddThenTryAddWithoutValidationThenAdd_ThreeParsedValuesAdded() { MockHeaders headers = new MockHeaders(); headers.Add(knownHeader, rawPrefix + "1"); headers.TryAddWithoutValidation(knownHeader, rawPrefix + "2"); headers.Add(knownHeader, rawPrefix + "3"); // The second Add() triggers also parsing of the value added by TryAddWithoutValidation() 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); }
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); }
public void Add_SingleFirstAddThenTryAddWithoutValidationToSingleValueHeader_BothParsedAndInvalidValue() { MockHeaderParser parser = new MockHeaderParser(false); // doesn't support multiple values. MockHeaders headers = new MockHeaders(parser); headers.Add(knownHeader, rawPrefix + "1"); headers.TryAddWithoutValidation(knownHeader, rawPrefix + "2"); Assert.Equal(1, headers.Parser.TryParseValueCallCount); // Add() succeeds since we don't have a value added yet. TryAddWithoutValidation() also succeeds, however // the value is added to the 'invalid values' list when retrieved. Assert.Equal(1, headers.Count()); Assert.Equal(2, headers.First().Value.Count()); Assert.Equal(parsedPrefix + "1", headers.First().Value.ElementAt(0)); Assert.Equal(rawPrefix + "2", headers.First().Value.ElementAt(1)); // Note that TryParseValue() is not called because HttpHeaders sees that there is already a value // so it adds the raw value to 'invalid values'. Assert.Equal(1, headers.Parser.TryParseValueCallCount); }
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); }
public void RemoveParsedValue_AddInvalidValueAndRemoveValidValue_InvalidValueRemains() { MockHeaders headers = new MockHeaders(); headers.TryAddWithoutValidation(knownHeader, invalidHeaderValue); // Remove a valid value which is not in the store. Assert.False(headers.RemoveParsedValue(knownHeader, parsedPrefix)); Assert.Equal(1, headers.Parser.TryParseValueCallCount); // Note that when the last value of a header gets removed, the whole header gets removed. Assert.Equal(1, headers.Count()); Assert.Equal(invalidHeaderValue, headers.GetValues(knownHeader).First()); Assert.Equal(1, headers.Parser.TryParseValueCallCount); // Remove the value again: It shouldn't be found in the store. Assert.False(headers.RemoveParsedValue(knownHeader, parsedPrefix + "1")); }
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()); }
public void RemoveParsedValue_FirstAddInvalidNewlineCharsValueThenAddValidValueThenCallAddParsedValue_HeaderRemoved() { MockHeaders headers = new MockHeaders(); // Add header value with invalid newline chars. headers.TryAddWithoutValidation(knownHeader, invalidHeaderValue + "\r\ninvalid"); headers.TryAddWithoutValidation(knownHeader, rawPrefix + "1"); Assert.Equal(0, headers.Parser.TryParseValueCallCount); headers.RemoveParsedValue(knownHeader, parsedPrefix + "1"); Assert.False(headers.Contains(knownHeader), "Store should not have an entry for 'knownHeader'."); }
public void ContainsParsedValue_ContainsParsedValueForNonExistingHeader_ReturnsFalse() { MockHeaders headers = new MockHeaders(); headers.TryAddWithoutValidation(knownHeader, rawPrefix); Assert.Equal(0, headers.Parser.TryParseValueCallCount); Assert.False(headers.ContainsParsedValue(customHeader, "custom1")); // ContainsParsedValue() must not trigger raw value parsing for headers other than the requested one. // In this case we expect ContainsParsedValue(customeHeader) not to trigger raw value parsing for // 'knownHeader'. Assert.Equal(0, headers.Parser.TryParseValueCallCount); }