예제 #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));
        }
예제 #2
0
        public void CopyTo_ItemsAdded_ItemsCopiedToArray()
        {
            var item1 = new SqlBulkCopyColumnMapping(0, 0);
            var item2 = new SqlBulkCopyColumnMapping(1, 1);
            var item3 = new SqlBulkCopyColumnMapping(2, 2);

            SqlBulkCopyColumnMappingCollection collection = CreateCollection(item1, item2, item3);

            var array1 = new SqlBulkCopyColumnMapping[collection.Count];

            collection.CopyTo(array1, 0);

            Assert.Same(item1, array1[0]);
            Assert.Same(item2, array1[1]);
            Assert.Same(item3, array1[2]);

            var array2 = new SqlBulkCopyColumnMapping[collection.Count];

            ((ICollection)collection).CopyTo(array2, 0);

            Assert.Same(item1, array2[0]);
            Assert.Same(item2, array2[1]);
            Assert.Same(item3, array2[2]);
        }