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>("destinationArray", "", () => { collection.CopyTo(array, 0); });

            headers.Add(knownStringHeader, "value1");
            array = new string[0];
            AssertExtensions.Throws <ArgumentException>("destinationArray", "", () => { collection.CopyTo(array, 0); });

            headers.Add(knownStringHeader, "value2");
            array = new string[1];
            AssertExtensions.Throws <ArgumentException>("destinationArray", "", () => { collection.CopyTo(array, 0); });

            array = new string[2];
            AssertExtensions.Throws <ArgumentException>("destinationArray", "", () => { collection.CopyTo(array, 1); });
        }
        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 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]);
        }
        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 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 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_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 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 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_OnlySpecialValue_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());
            headers.Add(knownHeader, specialValue.ToString());
            headers.Add(knownHeader, specialValue.ToString());

            Uri[] array = new Uri[4];
            array[0] = null;
            collection.CopyTo(array, 0);

            Assert.Equal(specialValue, array[0]);
            Assert.Equal(specialValue, array[1]);
            Assert.Equal(specialValue, array[2]);
            Assert.Equal(specialValue, array[3]);

            Assert.True(collection.IsSpecialValueSet, "Special value not set.");
        }
        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 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_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_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_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 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 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);
        }
        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); });
        }