public void GivenCollectionWithItems_WhenAddRangeWithItemsAlreadyInCollection_ThenThrowsArgumentException() { // Given const string filePath = "some/file/path"; var collection = new ConcreteObservableUniqueItemCollectionWithSourcePath <TestItem>( getUniqueFeature, typeDescriptor, featureDescription); const string duplicateNameOne = "Item A"; const string duplicateNameTwo = "Item B"; var expectedCollection = new[] { new TestItem(duplicateNameOne), new TestItem(duplicateNameTwo), new TestItem("Item C"), new TestItem("Item D") }; collection.AddRange(expectedCollection, filePath); // When TestDelegate call = () => collection.AddRange(new[] { new TestItem(duplicateNameOne), new TestItem(duplicateNameTwo) }, "other/path"); // Then string message = $"TestItems moeten een unieke Feature hebben. Gevonden dubbele elementen: {duplicateNameOne}, {duplicateNameTwo}."; TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(call, message); CollectionAssert.AreEqual(expectedCollection, collection); Assert.AreEqual(filePath, collection.SourcePath); }
public void Remove_ElementInCollection_ReturnsTrue() { // Setup var elementToBeRemoved = new TestItem("Item X"); var collection = new ConcreteObservableUniqueItemCollectionWithSourcePath <TestItem>( getUniqueFeature, typeDescriptor, featureDescription); var expectedCollections = new[] { new TestItem("Item A"), new TestItem("Item B"), new TestItem("Item C"), new TestItem("Item D") }; collection.AddRange(expectedCollections.Concat(new[] { elementToBeRemoved }), "path"); // Call bool removeSuccessful = collection.Remove(elementToBeRemoved); // Assert Assert.IsTrue(removeSuccessful); CollectionAssert.AreEqual(expectedCollections, collection); }
public void AddRange_AddMultipleDuplicateItems_ThrowsArgumentException() { // Setup const string duplicateNameOne = "Duplicate name it is"; const string duplicateNameTwo = "Duplicate name again"; var itemsToAdd = new[] { new TestItem(duplicateNameOne), new TestItem(duplicateNameOne), new TestItem(duplicateNameTwo), new TestItem(duplicateNameTwo) }; var collection = new ConcreteObservableUniqueItemCollectionWithSourcePath <TestItem>( getUniqueFeature, typeDescriptor, featureDescription); // Call TestDelegate call = () => collection.AddRange(itemsToAdd, "some/path"); // Assert string message = $"TestItems moeten een unieke Feature hebben. Gevonden dubbele elementen: {duplicateNameOne}, {duplicateNameTwo}."; TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(call, message); }
public void AddRange_ItemsNull_ThrowArgumentNullException() { // Setup var collection = new ConcreteObservableUniqueItemCollectionWithSourcePath <TestItem>( getUniqueFeature, typeDescriptor, featureDescription); // Call TestDelegate call = () => collection.AddRange(null, "path"); // Assert string paramName = Assert.Throws <ArgumentNullException>(call).ParamName; Assert.AreEqual("items", paramName); }
public void AddRange_NotAnActualFilePath_ThrowArgumentNull() { // Setup var collection = new ConcreteObservableUniqueItemCollectionWithSourcePath <TestItem>( getUniqueFeature, typeDescriptor, featureDescription); const string invalidFilePath = @" "; // Call TestDelegate call = () => collection.AddRange(Enumerable.Empty <TestItem>(), invalidFilePath); // Assert string message = $"'{invalidFilePath}' is not a valid file path."; string paramName = TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(call, message).ParamName; Assert.AreEqual("filePath", paramName); }
public void AddRange_AddNewItem_CollectionContainsItem() { // Setup var collection = new ConcreteObservableUniqueItemCollectionWithSourcePath <TestItem>( getUniqueFeature, typeDescriptor, featureDescription); var item = new TestItem("Item A"); // Call const string filePath = "some/file/path"; collection.AddRange(new[] { item }, filePath); // Assert CollectionAssert.Contains(collection, item); Assert.AreEqual(filePath, collection.SourcePath); }
public void Count_CollectionFilledWithElements_ReturnsExpectedNumberOfElements() { // Setup var collection = new ConcreteObservableUniqueItemCollectionWithSourcePath <TestItem>( getUniqueFeature, typeDescriptor, featureDescription); collection.AddRange(new[] { new TestItem("Item A"), new TestItem("Item B"), new TestItem("Item C"), new TestItem("Item D") }, "path"); // Call int nrOfElements = collection.Count; // Assert Assert.AreEqual(4, nrOfElements); }
public void AddRange_ItemsHasNullElement_ThrowArgumentException() { // Setup var collection = new ConcreteObservableUniqueItemCollectionWithSourcePath <TestItem>( getUniqueFeature, typeDescriptor, featureDescription); var items = new[] { new TestItem("Item A"), null, new TestItem("Item B") }; // Call TestDelegate call = () => collection.AddRange(items, "path"); // Assert const string message = "Collection cannot contain null."; string paramName = TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(call, message).ParamName; Assert.AreEqual("items", paramName); }
public void Remove_RemoveLastElement_ReturnsTrueAndClearSourcePath() { // Setup var elementToBeRemoved = new TestItem("Item X"); var collection = new ConcreteObservableUniqueItemCollectionWithSourcePath <TestItem>( getUniqueFeature, typeDescriptor, featureDescription); collection.AddRange(new[] { elementToBeRemoved }, "path"); // Precondition Assert.IsNotNull(collection.SourcePath); // Call bool removeSuccessful = collection.Remove(elementToBeRemoved); // Assert Assert.IsTrue(removeSuccessful); Assert.IsNull(collection.SourcePath); }
public void Indexer_GetElementAtIndex_ReturnsExpectedElement() { // Setup var elementToRetrieve = new TestItem("Item X"); var collection = new ConcreteObservableUniqueItemCollectionWithSourcePath <TestItem>( getUniqueFeature, typeDescriptor, featureDescription); collection.AddRange(new[] { new TestItem("Item A"), new TestItem("Item B"), new TestItem("Item C"), new TestItem("Item D"), elementToRetrieve }, "path"); // Call object retrievedElement = collection[4]; // Assert Assert.AreSame(elementToRetrieve, retrievedElement); }
public void AddRange_AddingNewItems_CollectionContainsExpectedElements() { // Setup var collection = new ConcreteObservableUniqueItemCollectionWithSourcePath <TestItem>( getUniqueFeature, typeDescriptor, featureDescription); var expectedCollection = new[] { new TestItem("Item A"), new TestItem("Item B"), new TestItem("Item C"), new TestItem("Item D") }; const string filePath = "some/file/path"; // Call collection.AddRange(expectedCollection, filePath); // Assert CollectionAssert.AreEqual(expectedCollection, collection); Assert.AreEqual(filePath, collection.SourcePath); }
public void Clear_CollectionFullyDefined_ClearsSourcePathAndCollection() { // Setup var collection = new ConcreteObservableUniqueItemCollectionWithSourcePath <TestItem>( getUniqueFeature, typeDescriptor, featureDescription); var expectedObjectCollection = new[] { new TestItem("Item A"), new TestItem("Item B"), new TestItem("Item C"), new TestItem("Item D") }; collection.AddRange(expectedObjectCollection, "path"); // Call collection.Clear(); // Assert Assert.IsNull(collection.SourcePath); Assert.AreEqual(0, collection.Count); CollectionAssert.IsEmpty(collection); }