public void RemoveParsedValue_AddTwoValuesToKnownHeaderAndCompareWithValueThatDiffersInCase_CustomComparerUsedForComparison() { MockHeaders headers = new MockHeaders(); headers.AddParsedValue(knownHeader, "differentvalue"); 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. // Note that since we added 2 values a different code path than in the previous test is used. In this // case we have stored the values as List<string> internally. Assert.True(headers.RemoveParsedValue(knownHeader, "VALUE")); Assert.Equal(1, headers.GetValues(knownHeader).Count()); Assert.Equal(2, headers.Parser.MockComparer.EqualsCount); }
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 RemoveParsedValue_RemoveFromUninitializedHeaderStore_ReturnsFalse() { MockHeaders headers = new MockHeaders(); // If we never add a header value, the whole header (and also the header store) doesn't exist. // Make sure we considered this case. Assert.False(headers.RemoveParsedValue(knownHeader, "doesntexist")); }
public void RemoveParsedValue_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.RemoveParsedValue(knownHeader, "VALUE")); Assert.False(headers.Contains(knownHeader), "Header should be removed after removing value."); Assert.Equal(1, headers.Parser.MockComparer.EqualsCount); }
public void RemoveParsedValue_RemoveFromNonExistingHeader_ReturnsFalse() { MockHeaders headers = new MockHeaders(); headers.Add(knownHeader, rawPrefix); // Header 'non-existing-header' can't be found, so false is returned. Assert.False(headers.RemoveParsedValue("non-existing-header", "doesntexist")); }
public void RemoveParsedValue_AddTwoValuesAndRemoveSecondOne_FirstValueRemains() { MockHeaders headers = new MockHeaders(); headers.Add(knownHeader, rawPrefix + "1"); headers.Add(knownHeader, rawPrefix + "2"); // Remove the parsed value (note the original string 'raw2' was "parsed" to 'parsed2') Assert.True(headers.RemoveParsedValue(knownHeader, parsedPrefix + "2")); Assert.Equal(2, 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(1, headers.First().Value.Count()); Assert.Equal(parsedPrefix + "1", headers.First().Value.ElementAt(0)); Assert.Equal(2, headers.Parser.TryParseValueCallCount); }
public void RemoveParsedValue_AddTwoValuesAndRemoveThem_NoHeader() { MockHeaders headers = new MockHeaders(); headers.Add(knownHeader, rawPrefix + "1"); headers.Add(knownHeader, rawPrefix + "2"); // Remove the parsed value (note the original string 'raw1' was "parsed" to 'parsed1') Assert.True(headers.RemoveParsedValue(knownHeader, parsedPrefix + "1")); Assert.True(headers.RemoveParsedValue(knownHeader, parsedPrefix + "2")); Assert.Equal(2, headers.Parser.TryParseValueCallCount); // Note that when the last value of a header gets removed, the whole header gets removed. Assert.Equal(0, headers.Count()); Assert.Equal(2, 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 RemoveParsedValue_AddValueAndRemoveIt_NoHeader() { MockHeaders headers = new MockHeaders(); headers.Add(knownHeader, rawPrefix + "1"); // Remove the parsed value (note the original string 'raw1' was "parsed" to 'parsed1') Assert.True(headers.RemoveParsedValue(knownHeader, parsedPrefix + "1")); Assert.Equal(1, headers.Parser.TryParseValueCallCount); // Note that when the last value of a header gets removed, the whole header gets removed. Assert.Equal(0, headers.Count()); 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")); }