public void Remove_BehavesAsExpected() { var item1 = new SqlBulkCopyColumnMapping(0, 0); var item2 = new SqlBulkCopyColumnMapping(1, 1); SqlBulkCopyColumnMappingCollection collection = CreateCollection(item1, item2); collection.Remove(item1); Assert.Equal(1, collection.Count); Assert.Same(item2, collection[0]); collection.Remove(item2); Assert.Equal(0, collection.Count); // The explicit implementation of IList.Remove throws ArgumentException if // the item isn't in the collection, but the public Remove method does not // throw in the full framework. collection.Remove(item2); collection.Remove(new SqlBulkCopyColumnMapping(2, 2)); IList list = CreateCollection(item1, item2); list.Remove(item1); Assert.Equal(1, list.Count); Assert.Same(item2, list[0]); list.Remove(item2); Assert.Equal(0, list.Count); Assert.Throws <ArgumentException>(() => list.Remove(item2)); Assert.Throws <ArgumentException>(() => list.Remove(new SqlBulkCopyColumnMapping(2, 2))); Assert.Throws <ArgumentException>(() => list.Remove("bogus")); }
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)); }