public void Add_CallWithNullValue_Throw() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers); Assert.Throws<ArgumentNullException>(() => { collection.Add(null); }); }
public void GetEnumerator_AddValuesAndSpecialValue_AllValuesReturned() { MockHeaders headers = new MockHeaders(); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, headers, specialValue); collection.Add(new Uri("http://www.example.org/1/")); collection.Add(new Uri("http://www.example.org/2/")); collection.SetSpecialValue(); collection.Add(new Uri("http://www.example.org/3/")); System.Collections.IEnumerable enumerable = collection; // The special value we added above, must be part of the collection returned by GetEnumerator(). int i = 1; bool specialFound = false; foreach (var item in enumerable) { if (item.Equals(specialValue)) { specialFound = true; } else { Assert.Equal(new Uri("http://www.example.org/" + i + "/"), item); i++; } } Assert.True(specialFound); Assert.True(collection.IsSpecialValueSet, "Special value not set."); }
public void CopyTo_ArrayTooSmall_Throw() { MockHeaders headers = new MockHeaders(); HttpHeaderValueCollection <string> collection = new HttpHeaderValueCollection <string>(knownStringHeader, headers); string[] array = new string[1]; array[0] = null; collection.CopyTo(array, 0); // no exception Assert.Null(array[0]); Assert.Throws <ArgumentNullException>(() => { collection.CopyTo(null, 0); }); Assert.Throws <ArgumentOutOfRangeException>(() => { collection.CopyTo(array, -1); }); Assert.Throws <ArgumentOutOfRangeException>(() => { collection.CopyTo(array, 2); }); headers.Add(knownStringHeader, "special"); array = new string[0]; AssertExtensions.Throws <ArgumentException>(null, () => { collection.CopyTo(array, 0); }); headers.Add(knownStringHeader, "special"); headers.Add(knownStringHeader, "special"); array = new string[1]; AssertExtensions.Throws <ArgumentException>(() => { collection.CopyTo(array, 0); }); headers.Add(knownStringHeader, "value1"); array = new string[0]; AssertExtensions.Throws <ArgumentException>(() => { collection.CopyTo(array, 0); }); headers.Add(knownStringHeader, "value2"); array = new string[1]; AssertExtensions.Throws <ArgumentException>(() => { collection.CopyTo(array, 0); }); array = new string[2]; AssertExtensions.Throws <ArgumentException>(() => { collection.CopyTo(array, 1); }); }
public void IsReadOnly_CallProperty_AlwaysFalse() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(string))); HttpHeaderValueCollection<string> collection = new HttpHeaderValueCollection<string>(knownHeader, headers); Assert.False(collection.IsReadOnly); }
public void Remove_CallWithNullValue_Throw() { MockHeaders headers = new MockHeaders(); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownHeader, headers); Assert.Throws <ArgumentNullException>(() => { collection.Remove(null); }); }
public void GetEnumerator_AddValuesAndSpecialValueAndGetEnumeratorFromInterface_AllValuesReturned() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownHeader, headers, specialValue); collection.Add(new Uri("http://www.example.org/1/")); collection.Add(new Uri("http://www.example.org/2/")); collection.Add(new Uri("http://www.example.org/3/")); collection.SetSpecialValue(); System.Collections.IEnumerable enumerable = collection; // The "special value" should be ignored and not part of the resulting collection. int i = 1; bool specialFound = false; foreach (var item in enumerable) { if (item.Equals(specialValue)) { specialFound = true; } else { Assert.Equal(new Uri("http://www.example.org/" + i + "/"), item); i++; } } Assert.True(specialFound); Assert.True(collection.IsSpecialValueSet, "Special value not set."); }
public void Contains_CallWithNullValue_Throw() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownHeader, headers); Assert.Throws <ArgumentNullException>(() => { collection.Contains(null); }); }
public void IsReadOnly_CallProperty_AlwaysFalse() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(string))); HttpHeaderValueCollection <string> collection = new HttpHeaderValueCollection <string>(knownHeader, headers); Assert.False(collection.IsReadOnly); }
public void CopyTo_EmptyToEmpty_Success() { MockHeaders headers = new MockHeaders(); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, headers); Uri[] array = new Uri[0]; collection.CopyTo(array, 0); }
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 GetEnumerator_NoValues_EmptyEnumerator() { MockHeaders headers = new MockHeaders(); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, headers); IEnumerator <Uri> enumerator = collection.GetEnumerator(); Assert.False(enumerator.MoveNext(), "No items expected in enumerator."); }
public void ParseAdd_CallWithNullValue_NothingAdded() { MockHeaders headers = new MockHeaders(); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, headers); collection.ParseAdd(null); Assert.Equal(0, collection.Count); Assert.Equal(string.Empty, collection.ToString()); }
public void IsSpecialValueSet_NoSpecialValueUsed_ReturnsFalse() { // Create a new collection _without_ specifying a special value. MockHeaders headers = new MockHeaders(); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, headers, null, null); Assert.False(collection.IsSpecialValueSet, "Special value is set even though collection doesn't define a special value."); }
public void Ctor_ProvideValidator_ValidatorIsUsedWhenRemovingValues() { // Use different ctor overload than in previous test to make sure all ctor overloads work correctly. MockHeaders headers = new MockHeaders(); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, headers, specialValue, MockValidator); // When we remove 'invalidValue' our MockValidator will throw. Assert.Throws <MockException>(() => { collection.Remove(invalidValue); }); }
public void ParseAdd_CallWithNullValue_NothingAdded() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownHeader, headers); collection.ParseAdd(null); Assert.False(collection.IsSpecialValueSet); Assert.Equal(0, collection.Count); Assert.Equal(String.Empty, collection.ToString()); }
public void TryParseAdd_UseSpecialValue_Added() { MockHeaders headers = new MockHeaders(); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, headers, specialValue); Assert.True(collection.TryParseAdd(specialValue.AbsoluteUri)); Assert.True(collection.IsSpecialValueSet); Assert.Equal(specialValue.ToString(), collection.ToString()); }
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 Add_AddValues_AllValuesAdded() { MockHeaders headers = new MockHeaders(); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, headers); collection.Add(new Uri("http://www.example.org/1/")); collection.Add(new Uri("http://www.example.org/2/")); collection.Add(new Uri("http://www.example.org/3/")); Assert.Equal(3, collection.Count); }
public void CopyTo_AddSingleValue_ContainsSingleValue() { MockHeaders headers = new MockHeaders(); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, headers); collection.Add(new Uri("http://www.example.org/")); Uri[] array = new Uri[1]; collection.CopyTo(array, 0); Assert.Equal(new Uri("http://www.example.org/"), array[0]); }
public void Add_AddValues_AllValuesAdded() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownHeader, headers, specialValue); collection.Add(new Uri("http://www.example.org/1/")); collection.Add(new Uri("http://www.example.org/2/")); collection.Add(new Uri("http://www.example.org/3/")); Assert.Equal(3, collection.Count); }
public void TryParseAdd_AddValues_AllAdded() { MockHeaders headers = new MockHeaders(); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, headers, specialValue); Assert.True(collection.TryParseAdd("http://www.example.org/1/")); Assert.True(collection.TryParseAdd("http://www.example.org/2/")); Assert.True(collection.TryParseAdd("http://www.example.org/3/")); Assert.Equal(3, collection.Count); }
public void Add_AddValues_AllValuesAdded() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers, specialValue); collection.Add(new Uri("http://www.example.org/1/")); collection.Add(new Uri("http://www.example.org/2/")); collection.Add(new Uri("http://www.example.org/3/")); Assert.Equal(3, collection.Count); }
public void Ctor_ProvideValidator_ValidatorIsUsedWhenAddingValues() { MockHeaders headers = new MockHeaders(); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, headers, MockValidator); // Adding an arbitrary Uri should not throw. collection.Add(new Uri("http://some/")); // When we add 'invalidValue' our MockValidator will throw. Assert.Throws <MockException>(() => { collection.Add(invalidValue); }); }
public void Contains_AddValuesThenCallContains_ReturnsTrueForExistingItemsFalseOtherwise() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownHeader, headers); collection.Add(new Uri("http://www.example.org/1/")); collection.Add(new Uri("http://www.example.org/2/")); collection.Add(new Uri("http://www.example.org/3/")); Assert.True(collection.Contains(new Uri("http://www.example.org/2/")), "Expected true for existing item."); Assert.False(collection.Contains(new Uri("http://www.example.org/4/")), "Expected false for non-existing item."); }
public void CopyTo_CallWithStartIndexPlusElementCountGreaterArrayLength_Throw() { MockHeaders headers = new MockHeaders(); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, headers); collection.Add(new Uri("http://www.example.org/1/")); collection.Add(new Uri("http://www.example.org/2/")); Uri[] array = new Uri[2]; // startIndex + Count = 1 + 2 > array.Length AssertExtensions.Throws <ArgumentException>("destinationArray", "", () => { collection.CopyTo(array, 1); }); }
public void Remove_AddValuesThenCallRemove_ReturnsTrueWhenRemovingExistingValuesFalseOtherwise() { MockHeaders headers = new MockHeaders(); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, headers); collection.Add(new Uri("http://www.example.org/1/")); collection.Add(new Uri("http://www.example.org/2/")); collection.Add(new Uri("http://www.example.org/3/")); Assert.True(collection.Remove(new Uri("http://www.example.org/2/")), "Expected true for existing item."); Assert.False(collection.Remove(new Uri("http://www.example.org/4/")), "Expected false for non-existing item."); }
public void CopyTo_NoValues_DoesNotChangeArray() { MockHeaders headers = new MockHeaders(); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, headers); Uri[] array = new Uri[4]; collection.CopyTo(array, 0); for (int i = 0; i < array.Length; i++) { Assert.Null(array[i]); } }
public void RemoveSpecialValue_AddValueAndSpecialValueThenRemoveSpecialValue_SpecialValueGetsRemoved() { MockHeaders headers = new MockHeaders(); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, headers, specialValue); collection.Add(new Uri("http://www.example.org/")); collection.SetSpecialValue(); Assert.True(collection.IsSpecialValueSet, "Special value not set."); Assert.Equal(2, headers.GetValues(knownUriHeader).Count()); collection.RemoveSpecialValue(); Assert.False(collection.IsSpecialValueSet, "Special value is set."); Assert.Equal(1, headers.GetValues(knownUriHeader).Count()); }
public void Clear_AddValuesThenClear_NoElementsInCollection() { MockHeaders headers = new MockHeaders(); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, headers); collection.Add(new Uri("http://www.example.org/1/")); collection.Add(new Uri("http://www.example.org/2/")); collection.Add(new Uri("http://www.example.org/3/")); Assert.Equal(3, collection.Count); collection.Clear(); Assert.Equal(0, collection.Count); }
public void GetEnumerator_AddSingleValueAndGetEnumerator_AllValuesReturned() { MockHeaders headers = new MockHeaders(); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, headers); collection.Add(new Uri("http://www.example.org/")); bool started = false; foreach (var item in collection) { Assert.False(started, "We have more than one element returned by the enumerator."); Assert.Equal(new Uri("http://www.example.org/"), item); } }
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 Count_AddMultipleValuesThenQueryCount_ReturnsValueCountWithSpecialValues() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(string))); HttpHeaderValueCollection<string> collection = new HttpHeaderValueCollection<string>(knownHeader, headers, "special"); Assert.Equal(0, collection.Count); collection.Add("value1"); headers.Add(knownHeader, "special"); Assert.Equal(2, collection.Count); headers.Add(knownHeader, "special"); headers.Add(knownHeader, "value2"); headers.Add(knownHeader, "special"); Assert.Equal(5, collection.Count); }
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 GetEnumerator_AddValuesAndGetEnumerator_AllValuesReturned() { MockHeaders headers = new MockHeaders(); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, headers); collection.Add(new Uri("http://www.example.org/1/")); collection.Add(new Uri("http://www.example.org/2/")); collection.Add(new Uri("http://www.example.org/3/")); int i = 1; foreach (var item in collection) { Assert.Equal(new Uri("http://www.example.org/" + i + "/"), item); i++; } }
public void Count_AddMultipleValuesThenQueryCount_ReturnsValueCountWithSpecialValues() { MockHeaders headers = new MockHeaders(); HttpHeaderValueCollection <string> collection = new HttpHeaderValueCollection <string>(knownStringHeader, headers, "special"); Assert.Equal(0, collection.Count); collection.Add("value1"); headers.Add(knownStringHeader, "special"); Assert.Equal(2, collection.Count); headers.Add(knownStringHeader, "special"); headers.Add(knownStringHeader, "value2"); headers.Add(knownStringHeader, "special"); Assert.Equal(5, collection.Count); }
public void CopyTo_OnlySpecialValueEmptyDestination_Copied() { MockHeaders headers = new MockHeaders(); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, headers, specialValue); collection.SetSpecialValue(); headers.Add(knownUriHeader, specialValue.ToString()); Uri[] array = new Uri[2]; collection.CopyTo(array, 0); Assert.Equal(specialValue, array[0]); Assert.Equal(specialValue, array[1]); Assert.True(collection.IsSpecialValueSet, "Special value not set."); }
public void RemoveSpecialValue_AddRemoveSpecialValue_SpecialValueGetsRemoved() { MockHeaders headers = new MockHeaders(); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, headers, specialValue); collection.SetSpecialValue(); Assert.True(collection.IsSpecialValueSet, "Special value not set."); Assert.Equal(1, headers.GetValues(knownUriHeader).Count()); collection.RemoveSpecialValue(); Assert.False(collection.IsSpecialValueSet, "Special value is set."); // Since the only header value was the "special value", removing it will remove the whole header // from the collection. Assert.False(headers.Contains(knownUriHeader)); }
public void CopyTo_AddMultipleValues_ContainsAllValuesInTheRightOrder() { MockHeaders headers = new MockHeaders(); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, headers); collection.Add(new Uri("http://www.example.org/1/")); collection.Add(new Uri("http://www.example.org/2/")); collection.Add(new Uri("http://www.example.org/3/")); Uri[] array = new Uri[5]; collection.CopyTo(array, 1); Assert.Null(array[0]); Assert.Equal(new Uri("http://www.example.org/1/"), array[1]); Assert.Equal(new Uri("http://www.example.org/2/"), array[2]); Assert.Equal(new Uri("http://www.example.org/3/"), array[3]); Assert.Null(array[4]); }
public void Clear_AddValuesThenClear_NoElementsInCollection() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers); collection.Add(new Uri("http://www.example.org/1/")); collection.Add(new Uri("http://www.example.org/2/")); collection.Add(new Uri("http://www.example.org/3/")); Assert.Equal(3, collection.Count); collection.Clear(); Assert.Equal(0, collection.Count); }
public void GetEnumerator_AddValuesAndSpecialValue_AllValuesReturned() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers, specialValue); collection.Add(new Uri("http://www.example.org/1/")); collection.Add(new Uri("http://www.example.org/2/")); collection.SetSpecialValue(); collection.Add(new Uri("http://www.example.org/3/")); System.Collections.IEnumerable enumerable = collection; // The special value we added above, must be part of the collection returned by GetEnumerator(). int i = 1; bool specialFound = false; foreach (var item in enumerable) { if (item.Equals(specialValue)) { specialFound = true; } else { Assert.Equal(new Uri("http://www.example.org/" + i + "/"), item); i++; } } Assert.True(specialFound); Assert.True(collection.IsSpecialValueSet, "Special value not set."); }
public void IsSpecialValueSet_NoSpecialValueUsed_ReturnsFalse() { // Create a new collection _without_ specifying a special value. MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers, null, null); Assert.False(collection.IsSpecialValueSet, "Special value is set even though collection doesn't define a special value."); }
public void CopyTo_NoValues_DoesNotChangeArray() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers); Uri[] array = new Uri[4]; collection.CopyTo(array, 0); for (int i = 0; i < array.Length; i++) { Assert.Null(array[i]); } }
public void GetEnumerator_AddValuesAndGetEnumeratorFromInterface_AllValuesReturned() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers); collection.Add(new Uri("http://www.example.org/1/")); collection.Add(new Uri("http://www.example.org/2/")); collection.Add(new Uri("http://www.example.org/3/")); System.Collections.IEnumerable enumerable = collection; int i = 1; foreach (var item in enumerable) { Assert.Equal(new Uri("http://www.example.org/" + i + "/"), item); i++; } }
public void RemoveSpecialValue_AddTwoValuesAndSpecialValueThenRemoveSpecialValue_SpecialValueGetsRemoved() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers, specialValue); collection.Add(new Uri("http://www.example.org/1/")); collection.Add(new Uri("http://www.example.org/2/")); collection.SetSpecialValue(); Assert.True(collection.IsSpecialValueSet, "Special value not set."); Assert.Equal(3, headers.GetValues(knownHeader).Count()); // The difference between this test and the previous one is that HttpHeaders in this case will use // a List<T> to store the two remaining values, whereas in the previous case it will just store // the remaining value (no list). collection.RemoveSpecialValue(); Assert.False(collection.IsSpecialValueSet, "Special value is set."); Assert.Equal(2, headers.GetValues(knownHeader).Count()); }
public void Ctor_ProvideValidator_ValidatorIsUsedWhenRemovingValues() { // Use different ctor overload than in previous test to make sure all ctor overloads work correctly. MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers, specialValue, MockValidator); // When we remove 'invalidValue' our MockValidator will throw. Assert.Throws<MockException>(() => { collection.Remove(invalidValue); }); }
public void Remove_CallWithNullValue_Throw() { MockHeaders headers = new MockHeaders(); HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers); Assert.Throws<ArgumentNullException>(() => { collection.Remove(null); }); }
public void Remove_AddValuesThenCallRemove_ReturnsTrueWhenRemovingExistingValuesFalseOtherwise() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers); collection.Add(new Uri("http://www.example.org/1/")); collection.Add(new Uri("http://www.example.org/2/")); collection.Add(new Uri("http://www.example.org/3/")); Assert.True(collection.Remove(new Uri("http://www.example.org/2/")), "Expected true for existing item."); Assert.False(collection.Remove(new Uri("http://www.example.org/4/")), "Expected false for non-existing item."); }
public void CopyTo_OnlySpecialValueEmptyDestination_Copied() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers, specialValue); collection.SetSpecialValue(); headers.Add(knownHeader, specialValue.ToString()); Uri[] array = new Uri[2]; collection.CopyTo(array, 0); Assert.Equal(specialValue, array[0]); Assert.Equal(specialValue, array[1]); Assert.True(collection.IsSpecialValueSet, "Special value not set."); }
public void CopyTo_ArrayTooSmall_Throw() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(string))); HttpHeaderValueCollection<string> collection = new HttpHeaderValueCollection<string>(knownHeader, headers, "special"); string[] array = new string[1]; array[0] = null; collection.CopyTo(array, 0); // no exception Assert.Null(array[0]); Assert.Throws<ArgumentNullException>(() => { collection.CopyTo(null, 0); }); Assert.Throws<ArgumentOutOfRangeException>(() => { collection.CopyTo(array, -1); }); Assert.Throws<ArgumentOutOfRangeException>(() => { collection.CopyTo(array, 2); }); headers.Add(knownHeader, "special"); array = new string[0]; Assert.Throws<ArgumentException>(() => { collection.CopyTo(array, 0); }); headers.Add(knownHeader, "special"); headers.Add(knownHeader, "special"); array = new string[1]; Assert.Throws<ArgumentException>(() => { collection.CopyTo(array, 0); }); headers.Add(knownHeader, "value1"); array = new string[0]; Assert.Throws<ArgumentException>(() => { collection.CopyTo(array, 0); }); headers.Add(knownHeader, "value2"); array = new string[1]; Assert.Throws<ArgumentException>(() => { collection.CopyTo(array, 0); }); array = new string[2]; Assert.Throws<ArgumentException>(() => { collection.CopyTo(array, 1); }); }
public void CopyTo_AddValuesAndSpecialValue_AllValuesCopied() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers, specialValue); collection.Add(new Uri("http://www.example.org/1/")); collection.Add(new Uri("http://www.example.org/2/")); collection.SetSpecialValue(); collection.Add(new Uri("http://www.example.org/3/")); Uri[] array = new Uri[5]; collection.CopyTo(array, 1); Assert.Null(array[0]); Assert.Equal(new Uri("http://www.example.org/1/"), array[1]); Assert.Equal(new Uri("http://www.example.org/2/"), array[2]); Assert.Equal(specialValue, array[3]); Assert.Equal(new Uri("http://www.example.org/3/"), array[4]); Assert.True(collection.IsSpecialValueSet, "Special value not set."); }
public void CopyTo_CallWithStartIndexPlusElementCountGreaterArrayLength_Throw() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers); collection.Add(new Uri("http://www.example.org/1/")); collection.Add(new Uri("http://www.example.org/2/")); Uri[] array = new Uri[2]; // startIndex + Count = 1 + 2 > array.Length Assert.Throws<ArgumentException>(() => { collection.CopyTo(array, 1); }); }
public void CopyTo_AddSingleValue_ContainsSingleValue() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers, specialValue); collection.Add(new Uri("http://www.example.org/")); Uri[] array = new Uri[1]; collection.CopyTo(array, 0); Assert.Equal(new Uri("http://www.example.org/"), array[0]); // Now only set the special value: nothing should be added to the array. headers.Clear(); headers.Add(knownHeader, specialValue.ToString()); array[0] = null; collection.CopyTo(array, 0); Assert.Equal(specialValue, array[0]); }
public void RemoveSpecialValue_AddRemoveSpecialValue_SpecialValueGetsRemoved() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers, specialValue); collection.SetSpecialValue(); Assert.True(collection.IsSpecialValueSet, "Special value not set."); Assert.Equal(1, headers.GetValues(knownHeader).Count()); collection.RemoveSpecialValue(); Assert.False(collection.IsSpecialValueSet, "Special value is set."); // Since the only header value was the "special value", removing it will remove the whole header // from the collection. Assert.False(headers.Contains(knownHeader)); }
public void Clear_AddValuesAndSpecialValueThenClear_EverythingCleared() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers, specialValue); collection.SetSpecialValue(); collection.Add(new Uri("http://www.example.org/1/")); collection.Add(new Uri("http://www.example.org/2/")); collection.Add(new Uri("http://www.example.org/3/")); Assert.Equal(4, collection.Count); Assert.True(collection.IsSpecialValueSet, "Special value not set."); collection.Clear(); Assert.Equal(0, collection.Count); Assert.False(collection.IsSpecialValueSet, "Special value was removed by Clear()."); }
public void RemoveSpecialValue_AddValueAndSpecialValueThenRemoveSpecialValue_SpecialValueGetsRemoved() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers, specialValue); collection.Add(new Uri("http://www.example.org/")); collection.SetSpecialValue(); Assert.True(collection.IsSpecialValueSet, "Special value not set."); Assert.Equal(2, headers.GetValues(knownHeader).Count()); collection.RemoveSpecialValue(); Assert.False(collection.IsSpecialValueSet, "Special value is set."); Assert.Equal(1, headers.GetValues(knownHeader).Count()); }
public void GetEnumerator_AddSingleValueAndGetEnumerator_AllValuesReturned() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers); collection.Add(new Uri("http://www.example.org/")); bool started = false; foreach (var item in collection) { Assert.False(started, "We have more than one element returned by the enumerator."); Assert.Equal(new Uri("http://www.example.org/"), item); } }
public void Ctor_ProvideValidator_ValidatorIsUsedWhenAddingValues() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers, MockValidator); // Adding an arbitrary Uri should not throw. collection.Add(new Uri("http://some/")); // When we add 'invalidValue' our MockValidator will throw. Assert.Throws<MockException>(() => { collection.Add(invalidValue); }); }
public void GetEnumerator_NoValues_EmptyEnumerator() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers); IEnumerator<Uri> enumerator = collection.GetEnumerator(); Assert.False(enumerator.MoveNext(), "No items expected in enumerator."); }
public void CopyTo_AddMultipleValues_ContainsAllValuesInTheRightOrder() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers); collection.Add(new Uri("http://www.example.org/1/")); collection.Add(new Uri("http://www.example.org/2/")); collection.Add(new Uri("http://www.example.org/3/")); Uri[] array = new Uri[5]; collection.CopyTo(array, 1); Assert.Null(array[0]); Assert.Equal(new Uri("http://www.example.org/1/"), array[1]); Assert.Equal(new Uri("http://www.example.org/2/"), array[2]); Assert.Equal(new Uri("http://www.example.org/3/"), array[3]); Assert.Null(array[4]); }
public void CopyTo_EmptyToEmpty_Success() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers); Uri[] array = new Uri[0]; collection.CopyTo(array, 0); }