コード例 #1
0
        public void RemoveAt_BehavesAsExpected()
        {
            var item1 = new SqlBulkCopyColumnMapping(0, 0);
            var item2 = new SqlBulkCopyColumnMapping(1, 1);
            var item3 = new SqlBulkCopyColumnMapping(2, 2);

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

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

            collection.RemoveAt(1);
            Assert.Equal(1, collection.Count);
            Assert.Same(item2, collection[0]);

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


            IList list = CreateCollection(item1, item2, item3);

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

            list.RemoveAt(1);
            Assert.Equal(1, list.Count);
            Assert.Same(item2, list[0]);

            list.RemoveAt(0);
            Assert.Equal(0, list.Count);
        }
コード例 #2
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));
        }