private Test CreateCopyToTest() { return(new TestCase("CopyTo", () => { AssertDistinctIntancesNotEmpty(); var collection = GetSafeDefaultInstance(); var handler = new CollectionHandler <TCollection, TItem>(collection, Context); var initialContent = new ReadOnlyCollection <TItem>(new List <TItem>(collection)); foreach (var item in DistinctInstances) { if (!IsReadOnly && !initialContent.Contains(item)) { handler.AddSingleItemOk(item); } } const int extension = 5; int count = collection.Count; var target = new TItem[count + extension]; AssertCopyToThrowException(() => collection.CopyTo(null, 0), "when called with a null argument.", "Argument Name", "array"); AssertCopyToThrowException(() => collection.CopyTo(target, -1), "when called with a negative index.", "Argument Name", "arrayIndex"); for (int i = 0; i <= extension; i++) { AssertCopyToNotThrowException(() => collection.CopyTo(target, i), "Expected the method to not throw an exception."); var clone = new TItem[count]; Array.Copy(target, i, clone, 0, count); Assert.AreElementsEqual(collection, clone); } AssertCopyToThrowException(() => collection.CopyTo(target, extension + 1), "when called with a too large array index.", "Argument Name", "arrayIndex"); })); }
private Test CreateAddItemsTest() { return(new TestCase("AddItems", () => { AssertDistinctIntancesNotEmpty(); var collection = GetSafeDefaultInstance(); var handler = new CollectionHandler <TCollection, TItem>(collection, Context); var initialContent = new ReadOnlyCollection <TItem>(new List <TItem>(collection)); foreach (var item in DistinctInstances) { if (!initialContent.Contains(item)) { handler.AddSingleItemOk(item); } if (AcceptEqualItems) { handler.AddDuplicateItemOk(item); } else { handler.AddDuplicateItemFails(item); } } })); }