System.Net.Http.Tests.HttpHeaderValueCollectionTest.CopyTo_ArrayTooSmall_Throw C# (CSharp) Method

CopyTo_ArrayTooSmall_Throw() private method

private CopyTo_ArrayTooSmall_Throw ( ) : void
return void
        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); });
        }
HttpHeaderValueCollectionTest