Exemple #1
0
        public void Methods_NullParameterPassed_ThrowsArgumentNullException()
        {
            SqlBulkCopyColumnMappingCollection collection = CreateCollection();

            collection.Add(new SqlBulkCopyColumnMapping());

            Assert.Throws <ArgumentNullException>(() => collection.CopyTo(null, 0));

            // Passing null to the public Add method should really throw ArgumentNullException
            // (which would be consistent with the explicit implementation of IList.Add), but
            // the full framework does not check for null in the public Add method. Instead it
            // accesses the parameter without first checking for null, resulting in
            // NullReferenceExpcetion being thrown.
            Assert.Throws <NullReferenceException>(() => collection.Add(null));

            // Passing null to the public Insert and Remove methods should really throw
            // ArgumentNullException (which would be consistent with the explicit
            // implementations of IList.Insert and IList.Remove), but the full framework
            // does not check for null in these methods.
            collection.Insert(0, null);
            collection.Remove(null);


            IList list = collection;

            Assert.Throws <ArgumentNullException>(() => list[0] = null);
            Assert.Throws <ArgumentNullException>(() => list.Add(null));
            Assert.Throws <ArgumentNullException>(() => list.CopyTo(null, 0));
            Assert.Throws <ArgumentNullException>(() => list.Insert(0, null));
            Assert.Throws <ArgumentNullException>(() => list.Remove(null));
        }
Exemple #2
0
        public void Insert_BehavesAsExpected()
        {
            var item1 = new SqlBulkCopyColumnMapping(0, 0);
            var item2 = new SqlBulkCopyColumnMapping(1, 1);
            var item3 = new SqlBulkCopyColumnMapping(2, 2);

            SqlBulkCopyColumnMappingCollection collection = CreateCollection();

            collection.Insert(0, item3);
            collection.Insert(0, item2);
            collection.Insert(0, item1);

            Assert.Equal(3, collection.Count);
            Assert.Same(item1, collection[0]);
            Assert.Same(item2, collection[1]);
            Assert.Same(item3, collection[2]);
        }
Exemple #3
0
        public void Members_InvalidRange_ThrowsArgumentOutOfRangeException()
        {
            SqlBulkCopyColumnMappingCollection collection = CreateCollection();

            var item = new SqlBulkCopyColumnMapping(0, 0);

            Assert.Throws <ArgumentOutOfRangeException>(() => collection[-1]);
            Assert.Throws <ArgumentOutOfRangeException>(() => collection[collection.Count]);
            Assert.Throws <ArgumentOutOfRangeException>(() => collection.Insert(-1, item));
            Assert.Throws <ArgumentOutOfRangeException>(() => collection.Insert(collection.Count + 1, item));
            Assert.Throws <ArgumentOutOfRangeException>(() => collection.RemoveAt(-1));
            Assert.Throws <ArgumentOutOfRangeException>(() => collection.RemoveAt(collection.Count));

            IList list = collection;

            Assert.Throws <ArgumentOutOfRangeException>(() => list[-1]);
            Assert.Throws <ArgumentOutOfRangeException>(() => list[collection.Count]);
            Assert.Throws <ArgumentOutOfRangeException>(() => list[-1] = item);
            Assert.Throws <ArgumentOutOfRangeException>(() => list[collection.Count] = item);
            Assert.Throws <ArgumentOutOfRangeException>(() => list.Insert(-1, item));
            Assert.Throws <ArgumentOutOfRangeException>(() => list.Insert(collection.Count + 1, item));
            Assert.Throws <ArgumentOutOfRangeException>(() => list.RemoveAt(-1));
            Assert.Throws <ArgumentOutOfRangeException>(() => list.RemoveAt(collection.Count));
        }
Exemple #4
0
        public void InsertAndClear_BehavesAsExpected()
        {
            var item1 = new SqlBulkCopyColumnMapping(0, 0);
            var item2 = new SqlBulkCopyColumnMapping(1, 1);
            var item3 = new SqlBulkCopyColumnMapping(2, 2);

            SqlBulkCopyColumnMappingCollection collection = CreateCollection();

            collection.Insert(0, item1);
            collection.Insert(1, item2);
            collection.Insert(2, item3);
            Assert.Equal(3, collection.Count);
            Assert.Same(item1, collection[0]);
            Assert.Same(item2, collection[1]);
            Assert.Same(item3, collection[2]);

            collection.Clear();
            Assert.Equal(0, collection.Count);

            collection.Add(item1);
            collection.Add(item3);
            Assert.Equal(2, collection.Count);
            Assert.Same(item1, collection[0]);
            Assert.Same(item3, collection[1]);

            collection.Insert(1, item2);
            Assert.Equal(3, collection.Count);
            Assert.Same(item1, collection[0]);
            Assert.Same(item2, collection[1]);
            Assert.Same(item3, collection[2]);

            collection.Clear();
            Assert.Equal(0, collection.Count);

            IList list = collection;

            list.Insert(0, item1);
            list.Insert(1, item2);
            list.Insert(2, item3);
            Assert.Equal(3, list.Count);
            Assert.Same(item1, list[0]);
            Assert.Same(item2, list[1]);
            Assert.Same(item3, list[2]);

            list.Clear();
            Assert.Equal(0, list.Count);

            list.Add(item1);
            list.Add(item3);
            Assert.Equal(2, list.Count);
            Assert.Same(item1, list[0]);
            Assert.Same(item3, list[1]);

            list.Insert(1, item2);
            Assert.Equal(3, list.Count);
            Assert.Same(item1, list[0]);
            Assert.Same(item2, list[1]);
            Assert.Same(item3, list[2]);

            list.Clear();
            Assert.Equal(0, list.Count);
        }