public void IteratorSetValueShouldChangeHeaderValue() { TestDefaultHeaders headers = NewInstance(); headers.Add(Of("name1"), new[] { Of("value1"), Of("value2"), Of("value3") }); headers.Add(Of("name2"), Of("value4")); Assert.Equal(4, headers.Size); foreach (HeaderEntry <ICharSequence, ICharSequence> header in headers) { if (Of("name1").Equals(header.Key) && Of("value2").Equals(header.Value)) { header.SetValue(Of("updatedvalue2")); Assert.Equal(Of("updatedvalue2"), header.Value); } if (Of("name1").Equals(header.Key) && Of("value3").Equals(header.Value)) { header.SetValue(Of("updatedvalue3")); Assert.Equal(Of("updatedvalue3"), header.Value); } } Assert.Equal(4, headers.Size); Assert.True(headers.Contains(Of("name1"), Of("updatedvalue2"))); Assert.False(headers.Contains(Of("name1"), Of("value2"))); Assert.True(headers.Contains(Of("name1"), Of("updatedvalue3"))); Assert.False(headers.Contains(Of("name1"), Of("value3"))); }
public void SetAllShouldOverwriteSomeAndLeaveOthersUntouched() { TestDefaultHeaders h1 = NewInstance(); h1.Add(Of("name1"), Of("value1")); h1.Add(Of("name2"), Of("value2")); h1.Add(Of("name2"), Of("value3")); h1.Add(Of("name3"), Of("value4")); TestDefaultHeaders h2 = NewInstance(); h2.Add(Of("name1"), Of("value5")); h2.Add(Of("name2"), Of("value6")); h2.Add(Of("name1"), Of("value7")); TestDefaultHeaders expected = NewInstance(); expected.Add(Of("name1"), Of("value5")); expected.Add(Of("name2"), Of("value6")); expected.Add(Of("name1"), Of("value7")); expected.Add(Of("name3"), Of("value4")); h1.SetAll(h2); Assert.True(expected.Equals(h1)); }
public void RemovingANameForASecondTimeShouldReturnFalse() { TestDefaultHeaders headers = NewInstance(); headers.Add(Of("name1"), Of("value1")); headers.Add(Of("name2"), Of("value2")); Assert.True(headers.Remove(Of("name2"))); Assert.False(headers.Remove(Of("name2"))); }
public void HeadersWithSameNamesButDifferentValuesShouldNotBeEquivalent() { TestDefaultHeaders headers1 = NewInstance(); headers1.Add(Of("name1"), Of("value1")); TestDefaultHeaders headers2 = NewInstance(); headers1.Add(Of("name1"), Of("value2")); Assert.False(headers1.Equals(headers2)); }
public void SubsetOfHeadersShouldNotBeEquivalent() { TestDefaultHeaders headers1 = NewInstance(); headers1.Add(Of("name1"), Of("value1")); headers1.Add(Of("name2"), Of("value2")); TestDefaultHeaders headers2 = NewInstance(); headers1.Add(Of("name1"), Of("value1")); Assert.False(headers1.Equals(headers2)); }
public void AfterClearHeadersShouldBeEmpty() { TestDefaultHeaders headers = NewInstance(); headers.Add(Of("name1"), Of("value1")); headers.Add(Of("name2"), Of("value2")); Assert.Equal(2, headers.Size); headers.Clear(); Assert.Equal(0, headers.Size); Assert.True(headers.IsEmpty); Assert.False(headers.Contains(Of("name1"))); Assert.False(headers.Contains(Of("name2"))); }
public void SetHeadersShouldClearAndOverwrite() { TestDefaultHeaders headers1 = NewInstance(); headers1.Add(Of("name"), Of("value")); TestDefaultHeaders headers2 = NewInstance(); headers2.Add(Of("name"), Of("newvalue")); headers2.Add(Of("name1"), Of("value1")); headers1.Set(headers2); Assert.True(headers1.Equals(headers2)); }
public void MultipleValuesPerNameShouldBeAllowed() { TestDefaultHeaders headers = NewInstance(); headers.Add(Of("name"), Of("value1")); headers.Add(Of("name"), Of("value2")); headers.Add(Of("name"), Of("value3")); Assert.Equal(3, headers.Size); IList <ICharSequence> values = headers.GetAll(Of("name")); Assert.Equal(3, values.Count); Assert.True(values.Contains(Of("value1"))); Assert.True(values.Contains(Of("value2"))); Assert.True(values.Contains(Of("value3"))); }
public void WhenNameContainsMultipleValuesGetShouldReturnTheFirst() { TestDefaultHeaders headers = NewInstance(); headers.Add(Of("name1"), new [] { Of("value1"), Of("value2") }); Assert.True(headers.TryGet(Of("name1"), out ICharSequence value)); Assert.Equal(Of("value1"), value); }
public void SetSelfIsNoOp() { TestDefaultHeaders headers = NewInstance(); headers.Add(Of("name"), Of("value")); headers.Set(headers); Assert.Equal(1, headers.Size); }
public void GetWithDefaultValue() { TestDefaultHeaders headers = NewInstance(); headers.Add(Of("name1"), Of("value1")); Assert.Equal(Of("value1"), headers.Get(Of("name1"), Of("defaultvalue"))); Assert.Equal(Of("defaultvalue"), headers.Get(Of("noname"), Of("defaultvalue"))); }
public void GetAndRemove() { TestDefaultHeaders headers = NewInstance(); headers.Add(Of("name1"), Of("value1")); headers.Add(Of("name2"), new [] { Of("value2"), Of("value3") }); headers.Add(Of("name3"), new [] { Of("value4"), Of("value5"), Of("value6") }); Assert.Equal(Of("value1"), headers.GetAndRemove(Of("name1"), Of("defaultvalue"))); Assert.True(headers.TryGetAndRemove(Of("name2"), out ICharSequence value)); Assert.Equal(Of("value2"), value); Assert.False(headers.TryGetAndRemove(Of("name2"), out value)); Assert.Null(value); Assert.True(new [] { Of("value4"), Of("value5"), Of("value6") }.SequenceEqual(headers.GetAllAndRemove(Of("name3")))); Assert.Equal(0, headers.Size); Assert.False(headers.TryGetAndRemove(Of("noname"), out value)); Assert.Null(value); Assert.Equal(Of("defaultvalue"), headers.GetAndRemove(Of("noname"), Of("defaultvalue"))); }
public void IteratorShouldReturnAllNameValuePairs() { TestDefaultHeaders headers1 = NewInstance(); headers1.Add(Of("name1"), new[] { Of("value1"), Of("value2") }); headers1.Add(Of("name2"), Of("value3")); headers1.Add(Of("name3"), new[] { Of("value4"), Of("value5"), Of("value6") }); headers1.Add(Of("name1"), new[] { Of("value7"), Of("value8") }); Assert.Equal(8, headers1.Size); TestDefaultHeaders headers2 = NewInstance(); foreach (HeaderEntry <ICharSequence, ICharSequence> entry in headers1) { headers2.Add(entry.Key, entry.Value); } Assert.True(headers1.Equals(headers2)); }
public void HeadersWithSameNamesAndValuesShouldBeEquivalent() { TestDefaultHeaders headers1 = NewInstance(); headers1.Add(Of("name1"), Of("value1")); headers1.Add(Of("name2"), Of("value2")); headers1.Add(Of("name2"), Of("value3")); TestDefaultHeaders headers2 = NewInstance(); headers2.Add(Of("name1"), Of("value1")); headers2.Add(Of("name2"), Of("value2")); headers2.Add(Of("name2"), Of("value3")); Assert.True(headers1.Equals(headers2)); Assert.True(headers2.Equals(headers1)); Assert.Equal(headers1.GetHashCode(), headers2.GetHashCode()); Assert.Equal(headers1.GetHashCode(), headers1.GetHashCode()); Assert.Equal(headers2.GetHashCode(), headers2.GetHashCode()); }
public void AddShouldIncreaseAndRemoveShouldDecreaseTheSize() { TestDefaultHeaders headers = NewInstance(); Assert.Equal(0, headers.Size); headers.Add(Of("name1"), new[] { Of("value1"), Of("value2") }); Assert.Equal(2, headers.Size); headers.Add(Of("name2"), new[] { Of("value3"), Of("value4") }); Assert.Equal(4, headers.Size); headers.Add(Of("name3"), Of("value5")); Assert.Equal(5, headers.Size); headers.Remove(Of("name3")); Assert.Equal(4, headers.Size); headers.Remove(Of("name1")); Assert.Equal(2, headers.Size); headers.Remove(Of("name2")); Assert.Equal(0, headers.Size); Assert.True(headers.IsEmpty); }
public void MultipleValuesPerNameIterator() { TestDefaultHeaders headers = NewInstance(); headers.Add(Of("name"), Of("value1")); headers.Add(Of("name"), Of("value2")); headers.Add(Of("name"), Of("value3")); Assert.Equal(3, headers.Size); var values = new List <ICharSequence>(); foreach (ICharSequence value in headers.ValueIterator(Of("name"))) { values.Add(value); } Assert.Equal(3, values.Count); Assert.Contains(Of("value1"), values); Assert.Contains(Of("value2"), values); Assert.Contains(Of("value3"), values); }
public void SetAllHeadersShouldOnlyOverwriteHeaders() { TestDefaultHeaders headers1 = NewInstance(); headers1.Add(Of("name"), Of("value")); headers1.Add(Of("name1"), Of("value1")); TestDefaultHeaders headers2 = NewInstance(); headers2.Add(Of("name"), Of("newvalue")); headers2.Add(Of("name2"), Of("value2")); TestDefaultHeaders expected = NewInstance(); expected.Add(Of("name"), Of("newvalue")); expected.Add(Of("name1"), Of("value1")); expected.Add(Of("name2"), Of("value2")); headers1.SetAll(headers2); Assert.True(headers1.Equals(expected)); }
public void Contains() { TestDefaultHeaders headers = NewInstance(); headers.AddBoolean(Of("boolean"), true); Assert.True(headers.ContainsBoolean(Of("boolean"), true)); Assert.False(headers.ContainsBoolean(Of("boolean"), false)); headers.AddLong(Of("long"), long.MaxValue); Assert.True(headers.ContainsLong(Of("long"), long.MaxValue)); Assert.False(headers.ContainsLong(Of("long"), long.MinValue)); headers.AddInt(Of("int"), int.MinValue); Assert.True(headers.ContainsInt(Of("int"), int.MinValue)); Assert.False(headers.ContainsInt(Of("int"), int.MaxValue)); headers.AddShort(Of("short"), short.MaxValue); Assert.True(headers.ContainsShort(Of("short"), short.MaxValue)); Assert.False(headers.ContainsShort(Of("short"), short.MinValue)); headers.AddChar(Of("char"), char.MaxValue); Assert.True(headers.ContainsChar(Of("char"), char.MaxValue)); Assert.False(headers.ContainsChar(Of("char"), char.MinValue)); headers.AddByte(Of("byte"), byte.MaxValue); Assert.True(headers.ContainsByte(Of("byte"), byte.MaxValue)); Assert.False(headers.ContainsByte(Of("byte"), byte.MinValue)); headers.AddDouble(Of("double"), double.MaxValue); Assert.True(headers.ContainsDouble(Of("double"), double.MaxValue)); Assert.False(headers.ContainsDouble(Of("double"), double.MinValue)); headers.AddFloat(Of("float"), float.MaxValue); Assert.True(headers.ContainsFloat(Of("float"), float.MaxValue)); Assert.False(headers.ContainsFloat(Of("float"), float.MinValue)); long millis = (long)Math.Floor(DateTime.UtcNow.Ticks / (double)TimeSpan.TicksPerMillisecond); headers.AddTimeMillis(Of("millis"), millis); Assert.True(headers.ContainsTimeMillis(Of("millis"), millis)); // This test doesn't work on midnight, January 1, 1970 UTC Assert.False(headers.ContainsTimeMillis(Of("millis"), 0)); headers.AddObject(Of("object"), "Hello World"); Assert.True(headers.ContainsObject(Of("object"), "Hello World")); Assert.False(headers.ContainsObject(Of("object"), "")); headers.Add(Of("name"), Of("value")); Assert.True(headers.Contains(Of("name"), Of("value"))); Assert.False(headers.Contains(Of("name"), Of("value1"))); }
public void CanMixConvertedAndNormalValues() { TestDefaultHeaders headers = NewInstance(); headers.Add(Of("name"), Of("value")); headers.AddInt(Of("name"), 100); headers.AddBoolean(Of("name"), false); Assert.Equal(3, headers.Size); Assert.True(headers.Contains(Of("name"))); Assert.True(headers.Contains(Of("name"), Of("value"))); Assert.True(headers.ContainsInt(Of("name"), 100)); Assert.True(headers.ContainsBoolean(Of("name"), false)); }
public void ConvertToString() { TestDefaultHeaders headers = NewInstance(); headers.Add(Of("name1"), Of("value1")); headers.Add(Of("name1"), Of("value2")); headers.Add(Of("name2"), Of("value3")); Assert.Equal("TestDefaultHeaders[name1: value1, name1: value2, name2: value3]", headers.ToString()); headers = NewInstance(); headers.Add(Of("name1"), Of("value1")); headers.Add(Of("name2"), Of("value2")); headers.Add(Of("name3"), Of("value3")); Assert.Equal("TestDefaultHeaders[name1: value1, name2: value2, name3: value3]", headers.ToString()); headers = NewInstance(); headers.Add(Of("name1"), Of("value1")); Assert.Equal("TestDefaultHeaders[name1: value1]", headers.ToString()); headers = NewInstance(); Assert.Equal("TestDefaultHeaders[]", headers.ToString()); }
public void AddSelf() { TestDefaultHeaders headers = NewInstance(); Assert.Throws <ArgumentException>(() => headers.Add(headers)); }