public void UpdateTargetCollectionData_CollectionOrderChangedAndElementRemoved_UpdatesCollectionInCorrectOrder()
        {
            // Setup
            var currentCollection = new[]
            {
                new TestItem("Item one"),
                new TestItem("Item two"),
                new TestItem("Item three")
            };
            var collection = new TestUniqueItemCollection();

            collection.AddRange(currentCollection, sourceFilePath);

            var importedItems = new[]
            {
                new TestItem("Item three"),
                new TestItem("Item one")
            };

            TestUpdateDataStrategy strategy = CreateDefaultTestStrategy(collection);

            // Call
            strategy.ConcreteUpdateData(importedItems,
                                        sourceFilePath);

            // Assert
            CollectionAssert.AreEqual(importedItems, collection);
        }
        public void UpdateTargetCollectionData_CollectionNotEmptyAndImportedDataHasDuplicateDefinitions_ThrowsUpdateDataException()
        {
            // Setup
            const string name = "Double Defined Name";
            var          currentCollection = new[]
            {
                new TestItem(name)
            };
            var collection = new TestUniqueItemCollection();

            collection.AddRange(currentCollection, sourceFilePath);

            var importedItems = new[]
            {
                new TestItem(name),
                new TestItem(name)
            };

            TestUpdateDataStrategy strategy = CreateDefaultTestStrategy(collection);

            // Call
            void Call() => strategy.ConcreteUpdateData(importedItems, sourceFilePath);

            // Assert
            var exception = Assert.Throws <UpdateDataException>(Call);

            Assert.AreEqual("Geïmporteerde data moet unieke elementen bevatten.", exception.Message);
        }
        public void UpdateTargetCollectionData_ImportedDataContainsDuplicateData_ThrowsUpdateDataException()
        {
            // Setup
            var collection = new TestUniqueItemCollection();
            var testItem   = new TestItem("I am an expected item");

            collection.AddRange(new[]
            {
                testItem
            }, sourceFilePath);

            const string duplicateName      = "Duplicate Name";
            var          importedCollection = new[]
            {
                new TestItem(duplicateName),
                new TestItem(duplicateName)
            };

            TestUpdateDataStrategy strategy = CreateDefaultTestStrategy(collection);

            // Call
            void Call() => strategy.ConcreteUpdateData(importedCollection, sourceFilePath);

            // Assert
            var          exception = Assert.Throws <UpdateDataException>(Call);
            const string message   = "Geïmporteerde data moet unieke elementen bevatten.";

            Assert.AreEqual(message, exception.Message);

            CollectionAssert.AreEqual(new[]
            {
                testItem
            }, collection);
        }
        public void UpdateTargetCollectionData_WithEmptyCollectionAndImportedDataCollectionNotEmpty_AddsNewItems()
        {
            // Setup
            var collection    = new TestUniqueItemCollection();
            var importedItems = new[]
            {
                new TestItem("Name A"),
                new TestItem("Name B")
            };

            TestUpdateDataStrategy strategy = CreateDefaultTestStrategy(collection);

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.ConcreteUpdateData(importedItems, sourceFilePath);

            // Assert
            Assert.IsFalse(strategy.IsUpdateDataCalled);
            Assert.IsFalse(strategy.IsRemoveObjectAndDependentDataCalled);

            CollectionAssert.IsEmpty(strategy.UpdateDataCallArguments);
            CollectionAssert.IsEmpty(strategy.RemoveDataCallArguments);

            CollectionAssert.AreEqual(importedItems, collection);
            CollectionAssert.AreEquivalent(new[]
            {
                collection
            }, affectedObjects);
        }
        public void UpdateTargetCollectionData_ImportedDataCollectionNull_ThrowsArgumentNullException()
        {
            // Setup
            TestUpdateDataStrategy strategy = CreateDefaultTestStrategy(new TestUniqueItemCollection());

            // Call
            void Call() => strategy.ConcreteUpdateData(null, string.Empty);

            // Assert
            string paramName = Assert.Throws <ArgumentNullException>(Call).ParamName;

            Assert.AreEqual("importedDataCollection", paramName);
        }
        public void UpdateTargetCollectionData_SourceFilePathNull_ThrowsArgumentNullException()
        {
            // Setup
            var collection = new TestUniqueItemCollection();
            TestUpdateDataStrategy strategy = CreateDefaultTestStrategy(collection);

            // Call
            void Call() => strategy.ConcreteUpdateData(Enumerable.Empty <TestItem>(), null);

            // Assert
            string paramName = Assert.Throws <ArgumentNullException>(Call).ParamName;

            Assert.AreEqual("sourceFilePath", paramName);
        }
        public void UpdateTargetCollectionData_CollectionNotEmptyAndImportedDataDoesNotOverlap_UpdatesCollection()
        {
            // Setup
            var currentCollection = new[]
            {
                new TestItem("Item one"),
                new TestItem("Item two")
            };
            var collection = new TestUniqueItemCollection();

            collection.AddRange(currentCollection, sourceFilePath);

            var importedItems = new[]
            {
                new TestItem("Item three"),
                new TestItem("Item four")
            };

            TestUpdateDataStrategy strategy = CreateDefaultTestStrategy(collection);

            strategy.ItemsToRemove = currentCollection;

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.ConcreteUpdateData(importedItems,
                                                                                    sourceFilePath);

            // Assert
            Assert.IsFalse(strategy.IsUpdateDataCalled);
            Assert.IsTrue(strategy.IsRemoveObjectAndDependentDataCalled);

            CollectionAssert.AreEqual(importedItems, collection);
            IEnumerable <IObservable> expectedAffectedObjects = currentCollection.Concat(new IObservable[]
            {
                collection
            });

            CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects);

            CollectionAssert.IsEmpty(strategy.UpdateDataCallArguments);
            int nrOfExpectedRemoveCalls = currentCollection.Length;
            List <Tuple <TestItem> > removeDataCallArguments = strategy.RemoveDataCallArguments;

            Assert.AreEqual(nrOfExpectedRemoveCalls, removeDataCallArguments.Count);
            for (var i = 0; i < nrOfExpectedRemoveCalls; i++)
            {
                Assert.AreSame(currentCollection[i], removeDataCallArguments[i].Item1);
            }
        }
        public void UpdateTargetCollectionData_CollectionNotEmptyAndImportedDataFullyOverlaps_UpdatesCollection()
        {
            // Setup
            const string itemOneName = "Item one";
            const string itemTwoName = "Item Two";

            var currentCollection = new[]
            {
                new TestItem(itemOneName),
                new TestItem(itemTwoName)
            };
            var collection = new TestUniqueItemCollection();

            collection.AddRange(currentCollection, sourceFilePath);

            TestItem[] importedItems =
            {
                currentCollection[0].DeepClone(),
                currentCollection[1].DeepClone()
            };

            TestUpdateDataStrategy strategy = CreateDefaultTestStrategy(collection);

            strategy.ItemsToUpdate = currentCollection;

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.ConcreteUpdateData(importedItems,
                                                                                    sourceFilePath);

            // Assert
            Assert.IsFalse(strategy.IsUpdateDataCalled);
            Assert.IsFalse(strategy.IsRemoveObjectAndDependentDataCalled);

            const int expectedNrOfUpdateCalls = 0;
            List <Tuple <TestItem, TestItem> > updateArgumentCalls = strategy.UpdateDataCallArguments;

            Assert.AreEqual(expectedNrOfUpdateCalls, updateArgumentCalls.Count);
            CollectionAssert.IsEmpty(strategy.RemoveDataCallArguments);

            CollectionAssert.AreEqual(currentCollection, collection);
            CollectionAssert.AreEqual(new IObservable[]
            {
                collection
            }, affectedObjects);
        }
        public void UpdateTargetCollectionData_WithNonEmptyCollectionAndImportedDataEmpty_ClearsTargetCollection()
        {
            // Setup
            var          collection   = new TestUniqueItemCollection();
            const string filePath     = "path";
            var          itemsRemoved = new[]
            {
                new TestItem("Name A"),
                new TestItem("Name B")
            };

            collection.AddRange(itemsRemoved, filePath);

            TestUpdateDataStrategy strategy = CreateDefaultTestStrategy(collection);

            strategy.ItemsToRemove = itemsRemoved;

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.ConcreteUpdateData(Enumerable.Empty <TestItem>(), filePath);

            // Assert
            Assert.IsFalse(strategy.IsUpdateDataCalled);
            Assert.IsTrue(strategy.IsRemoveObjectAndDependentDataCalled);

            CollectionAssert.IsEmpty(strategy.UpdateDataCallArguments);
            int nrOfExpectedRemovedDataCalls = itemsRemoved.Length;
            List <Tuple <TestItem> > removeDataCallArguments = strategy.RemoveDataCallArguments;

            Assert.AreEqual(nrOfExpectedRemovedDataCalls, removeDataCallArguments.Count);
            for (var i = 0; i < nrOfExpectedRemovedDataCalls; i++)
            {
                Assert.AreSame(itemsRemoved[i], removeDataCallArguments[i].Item1);
            }

            IEnumerable <IObservable> expectedAffectedObjects = itemsRemoved.Concat(new IObservable[]
            {
                collection
            });

            CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects);
            CollectionAssert.IsEmpty(collection);
            Assert.AreEqual(filePath, collection.SourcePath);
        }
예제 #10
0
        public void UpdateTargetCollectionData_WithEmptyCollectionAndImportedData_SetsSourcePath()
        {
            // Setup
            var collection = new TestUniqueItemCollection();

            const string           filePath = "path";
            TestUpdateDataStrategy strategy = CreateDefaultTestStrategy(collection);

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.ConcreteUpdateData(Enumerable.Empty <TestItem>(), filePath);

            // Assert
            Assert.IsFalse(strategy.IsUpdateDataCalled);
            Assert.IsFalse(strategy.IsRemoveObjectAndDependentDataCalled);

            CollectionAssert.IsEmpty(affectedObjects);
            CollectionAssert.IsEmpty(collection);
            Assert.AreEqual(filePath, collection.SourcePath);
        }
예제 #11
0
        public void UpdateTargetCollectionData_CollectionNotEmptyAndNoPathAndImportedDataFullyOverlaps_UpdatesCollectionAndFilePath()
        {
            // Setup
            const string itemOneName = "Item one";
            const string itemTwoName = "Item Two";

            var currentCollection = new[]
            {
                new TestItem(itemOneName),
                new TestItem(itemTwoName)
            };
            var collection = new TestUniqueItemCollection();

            collection.AddRange(currentCollection, "Onbekend");

            TestItem[] importedItems =
            {
                currentCollection[0].DeepClone(),
                currentCollection[1].DeepClone()
            };

            TestUpdateDataStrategy strategy = CreateDefaultTestStrategy(collection);

            strategy.ItemsToUpdate = currentCollection;

            const string newSourceFilePath = "Something/Different/From/Onbekend";

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.ConcreteUpdateData(importedItems,
                                                                                    newSourceFilePath);

            // Assert
            Assert.IsFalse(strategy.IsUpdateDataCalled);
            Assert.IsFalse(strategy.IsRemoveObjectAndDependentDataCalled);

            Assert.AreEqual(newSourceFilePath, collection.SourcePath);
            CollectionAssert.AreEqual(currentCollection, collection);
            CollectionAssert.AreEqual(new IObservable[]
            {
                collection
            }, affectedObjects);
        }
예제 #12
0
        public void UpdateTargetCollectionData_SameObjectAddedToAffectedObjects_ReturnsOnlyDistinctObjects()
        {
            // Setup
            var itemOne = new TestItem(1);
            var itemTwo = new TestItem(2);

            TestItem[] currentCollection =
            {
                itemOne
            };
            var collection = new TestUniqueItemCollection();

            collection.AddRange(currentCollection, "path");

            TestItem[] importedItems =
            {
                itemTwo
            };

            TestUpdateDataStrategy strategy = CreateDefaultTestStrategy(collection);

            strategy.ItemsToUpdate     = currentCollection;
            strategy.ItemsToUpdateFrom = importedItems;
            strategy.AddObjectToUpdateToAffectedItems = true;

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.ConcreteUpdateData(importedItems,
                                                                                    "path");

            IEnumerable <IObservable> expectedAffectedObjects = new IObservable[]
            {
                collection,
                itemOne,
                itemTwo
            };

            CollectionAssert.AreEqual(expectedAffectedObjects, affectedObjects);
        }
예제 #13
0
        public void UpdateTargetCollectionData_CollectionNotEmptyAndImportedDataPartiallyOverlaps_UpdatesCollection()
        {
            // Setup
            var itemToUpdate = new TestItem("Item one");
            var itemToRemove = new TestItem("Item Two");
            var collection   = new TestUniqueItemCollection();

            collection.AddRange(new[]
            {
                itemToUpdate,
                itemToRemove
            }, sourceFilePath);

            var itemToAdd = new TestItem("Item Four");

            TestItem[] importedItems =
            {
                itemToUpdate.DeepClone(),
                itemToAdd
            };

            TestUpdateDataStrategy strategy = CreateDefaultTestStrategy(collection);

            strategy.ItemsToUpdate = new[]
            {
                itemToUpdate
            };
            strategy.ItemsToRemove = new[]
            {
                itemToRemove
            };

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.ConcreteUpdateData(importedItems,
                                                                                    sourceFilePath);

            // Assert
            Assert.IsFalse(strategy.IsUpdateDataCalled);
            Assert.IsTrue(strategy.IsRemoveObjectAndDependentDataCalled);

            const int expectedNrOfUpdateCalls = 0;
            List <Tuple <TestItem, TestItem> > updateDataCallArguments = strategy.UpdateDataCallArguments;

            Assert.AreEqual(expectedNrOfUpdateCalls, updateDataCallArguments.Count);

            List <Tuple <TestItem> > removeDataCallArguments = strategy.RemoveDataCallArguments;

            Assert.AreEqual(1, removeDataCallArguments.Count);
            Assert.AreSame(itemToRemove, removeDataCallArguments[0].Item1);

            TestItem[] expectedCollection =
            {
                itemToUpdate,
                itemToAdd
            };
            CollectionAssert.AreEqual(expectedCollection, collection);
            CollectionAssert.AreEquivalent(new IObservable[]
            {
                itemToRemove,
                collection
            }, affectedObjects);
        }