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 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 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 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 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 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 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 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 Add_CallWithNullValue_Throw()
        {
            MockHeaders headers = new MockHeaders();
            HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, headers);

            Assert.Throws <ArgumentNullException>(() => { collection.Add(null); });
        }
예제 #11
0
        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_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++;
            }
        }
예제 #13
0
        // https://github.com/dotnet/corefx/blob/master/src/System.Net.Http/src/System/Net/Http/Headers/MediaTypeWithQualityHeaderValue.cs
        internal static void AddPreserved(this HttpHeaderValueCollection <MediaTypeWithQualityHeaderValue> collection, string value)
        {
            var header = new MediaTypeWithQualityHeaderValue("text/plain");

            ReflectionCache.MediaTypeHeader.MediaTypeField.SetValue(header, value);

            collection.Add(header);
        }
예제 #14
0
        // https://github.com/dotnet/corefx/blob/master/src/System.Net.Http/src/System/Net/Http/Headers/StringWithQualityHeaderValue.cs
        internal static void AddPreserved(this HttpHeaderValueCollection <StringWithQualityHeaderValue> collection, string value)
        {
            var header = (StringWithQualityHeaderValue)Activator.CreateInstance(ReflectionCache.StringWithQualityHeader.Type, true);

            ReflectionCache.StringWithQualityHeader.ValueField.SetValue(header, value);

            collection.Add(header);
        }
        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_AddValuesAndSpecialValueThenClear_EverythingCleared()
        {
            MockHeaders headers = new MockHeaders();
            HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, 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 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();
            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();
            Assert.True(collection.IsSpecialValueSet, "Special value not set.");
            Assert.Equal(3, headers.GetValues(knownUriHeader).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(knownUriHeader).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]);
        }
예제 #20
0
 public static HttpHeaderValueCollection <StringWithQualityHeaderValue> AddN(
     this HttpHeaderValueCollection <StringWithQualityHeaderValue> coll, params string[] mediaTypes)
 {
     if (mediaTypes.NotNulle() && coll != null)
     {
         for (int i = 0; i < mediaTypes.Length; i++)
         {
             coll.Add(new StringWithQualityHeaderValue(mediaTypes[i]));
         }
     }
     return(coll);
 }
        public void CopyTo_AddValuesAndSpecialValue_AllValuesCopied()
        {
            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/"));

            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 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 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());
        }
예제 #24
0
        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 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_AddSingleValue_ContainsSingleValue()
        {
            MockHeaders headers = new MockHeaders();
            HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, 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(knownUriHeader, specialValue.ToString());
            array[0] = null;
            collection.CopyTo(array, 0);
            Assert.Equal(specialValue, array[0]);
        }
예제 #27
0
        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.");
        }
예제 #28
0
        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.");
        }
예제 #29
0
        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); });
        }
예제 #30
0
        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());
        }
예제 #31
0
        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.");
        }
예제 #32
0
        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);
        }
예제 #33
0
 public static void Add(this HttpHeaderValueCollection <StringWithQualityHeaderValue> header, string value, double quality)
 {
     header.Add(new StringWithQualityHeaderValue(value, quality));
 }
예제 #34
0
 public static void Add(this HttpHeaderValueCollection <MediaTypeWithQualityHeaderValue> header, string mediaType)
 {
     header.Add(new MediaTypeWithQualityHeaderValue(mediaType));
 }
예제 #35
0
 /// <summary>
 /// 配置请求头的accept
 /// </summary>
 /// <param name="accept">请求头的accept</param>
 /// <returns></returns>
 protected override void ConfigureAccept(HttpHeaderValueCollection <MediaTypeWithQualityHeaderValue> accept)
 {
     accept.Add(new MediaTypeWithQualityHeaderValue(JsonContent.MediaType, 0.9d));
     accept.Add(new MediaTypeWithQualityHeaderValue(XmlContent.MediaType, 0.8d));
     accept.Add(new MediaTypeWithQualityHeaderValue("*/*", 0.1d));
 }
예제 #36
0
 /// <summary>
 /// 配置请求头的accept
 /// </summary>
 /// <param name="accept">请求头的accept</param>
 /// <returns></returns>
 protected override void ConfigureAccept(HttpHeaderValueCollection <MediaTypeWithQualityHeaderValue> accept)
 {
     accept.Add(new MediaTypeWithQualityHeaderValue(BsonContent.MediaType));
 }
예제 #37
0
        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);
            }
        }
예제 #38
0
        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++;
            }
        }
예제 #39
0
        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().");
        }
예제 #40
0
 static void CopyETags(ICollection<ETag> source, HttpHeaderValueCollection<EntityTagHeaderValue> target)
 {
     target.Clear();
     foreach (var tag in source)
         target.Add(ToEntityTagHeaderValue(tag));
 }
예제 #41
0
        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); });
        }
예제 #42
0
        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());
        }
예제 #43
0
        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]);
        }
예제 #44
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);
        }
예제 #45
0
        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]);
        }