Index: Application/Ringtoets/src/Application.Ringtoets.Migration/Resources/Migration_5_17.1.sql =================================================================== diff -u -r70dc640733bde2e1641423189afb1a182af592ae -r352102f53efcda2247dd7ff8c2d833eccc709c4d --- Application/Ringtoets/src/Application.Ringtoets.Migration/Resources/Migration_5_17.1.sql (.../Migration_5_17.1.sql) (revision 70dc640733bde2e1641423189afb1a182af592ae) +++ Application/Ringtoets/src/Application.Ringtoets.Migration/Resources/Migration_5_17.1.sql (.../Migration_5_17.1.sql) (revision 352102f53efcda2247dd7ff8c2d833eccc709c4d) @@ -109,9 +109,9 @@ [Order] FROM (SELECT *, (SELECT count(*) FROM [SOURCEPROJECT].SurfaceLineEntity - WHERE SSM.SurfaceLineEntityId > SurfaceLineEntityId - AND SSM.Name IS Name) as Suffix - FROM [SOURCEPROJECT].SurfaceLineEntity SSM); + WHERE SL.SurfaceLineEntityId > SurfaceLineEntityId + AND SL.Name IS Name) as Suffix + FROM [SOURCEPROJECT].SurfaceLineEntity SL); INSERT INTO TechnicalInnovationSectionResultEntity SELECT * FROM [SOURCEPROJECT].TechnicalInnovationSectionResultEntity; INSERT INTO VersionEntity ( [VersionId], Index: Core/Common/test/Core.Common.Base.Test/ObservableUniqueItemCollectionWithSourcePathTest.cs =================================================================== diff -u -rc290911dd4647e3115e239c8baf814717c098a5a -r352102f53efcda2247dd7ff8c2d833eccc709c4d --- Core/Common/test/Core.Common.Base.Test/ObservableUniqueItemCollectionWithSourcePathTest.cs (.../ObservableUniqueItemCollectionWithSourcePathTest.cs) (revision c290911dd4647e3115e239c8baf814717c098a5a) +++ Core/Common/test/Core.Common.Base.Test/ObservableUniqueItemCollectionWithSourcePathTest.cs (.../ObservableUniqueItemCollectionWithSourcePathTest.cs) (revision 352102f53efcda2247dd7ff8c2d833eccc709c4d) @@ -30,7 +30,7 @@ [TestFixture] public class ObservableUniqueItemCollectionWithSourcePathTest { - private readonly Func getUniqueFeature = (item => item.Name); + private readonly Func getUniqueFeature = item => item.Name; private const string typeDescriptor = "TestItems"; private const string featureDescription = "Feature"; @@ -243,7 +243,7 @@ TestDelegate call = () => collection.AddRange(itemsToAdd, "some/path"); // Assert - string message = $"{typeDescriptor} moeten een unieke {featureDescription} hebben. Gevonden dubbele elementen: {duplicateNameOne}, {duplicateNameTwo}."; + string message = $"TestItems moeten een unieke Feature hebben. Gevonden dubbele elementen: {duplicateNameOne}, {duplicateNameTwo}."; TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, message); } Index: Ringtoets/Common/src/Ringtoets.Common.Data/UpdateDataStrategies/ReplaceDataStrategyBase.cs =================================================================== diff -u -rb1537a16c5961d9f66d5564c215f4bee59294f82 -r352102f53efcda2247dd7ff8c2d833eccc709c4d --- Ringtoets/Common/src/Ringtoets.Common.Data/UpdateDataStrategies/ReplaceDataStrategyBase.cs (.../ReplaceDataStrategyBase.cs) (revision b1537a16c5961d9f66d5564c215f4bee59294f82) +++ Ringtoets/Common/src/Ringtoets.Common.Data/UpdateDataStrategies/ReplaceDataStrategyBase.cs (.../ReplaceDataStrategyBase.cs) (revision 352102f53efcda2247dd7ff8c2d833eccc709c4d) @@ -27,7 +27,7 @@ namespace Ringtoets.Common.Data.UpdateDataStrategies { /// - /// Base class of the replace strategy algorithm to replace data from a + /// Base class of the algorithm that replaces data from a /// target collection with the data that was imported. /// /// The target data type. Index: Ringtoets/Common/src/Ringtoets.Common.Data/UpdateDataStrategies/UpdateDataStrategyBase.cs =================================================================== diff -u -re9a40c653a63e31757bf87930745200f9c22cb2e -r352102f53efcda2247dd7ff8c2d833eccc709c4d --- Ringtoets/Common/src/Ringtoets.Common.Data/UpdateDataStrategies/UpdateDataStrategyBase.cs (.../UpdateDataStrategyBase.cs) (revision e9a40c653a63e31757bf87930745200f9c22cb2e) +++ Ringtoets/Common/src/Ringtoets.Common.Data/UpdateDataStrategies/UpdateDataStrategyBase.cs (.../UpdateDataStrategyBase.cs) (revision 352102f53efcda2247dd7ff8c2d833eccc709c4d) @@ -51,7 +51,7 @@ /// Instantiates a object. /// /// The failure mechanism which needs to be updated. - /// The comparer which should be used to determine when two objects are equal + /// The comparer which should be used to determine when two objects are equal. /// Thrown when any input parameter is null. protected UpdateDataStrategyBase(TFailureMechanism failureMechanism, IEqualityComparer equalityComparer) { @@ -98,7 +98,7 @@ /// Thrown when duplicate items are being added to the /// . /// Thrown when duplicate items are found during the - /// update of the items to be updatd in the . + /// update of the items in the . protected IEnumerable UpdateTargetCollectionData(ObservableUniqueItemCollectionWithSourcePath targetDataCollection, IEnumerable importedDataCollection, string sourceFilePath) @@ -120,7 +120,7 @@ } /// - /// Identifies which models were changed, removed and added to the target collection + /// Identifies which items were changed, removed and added to the target collection /// when compared with the imported data and performs the necessary operations for /// the dependent data of the affected elements. /// @@ -134,39 +134,39 @@ /// Thrown when duplicate items are found during the /// update of the items to be updatd in the . private IEnumerable ModifyDataCollection(ObservableUniqueItemCollectionWithSourcePath targetDataCollection, - IEnumerable importedDataCollection, - string sourceFilePath) + IEnumerable importedDataCollection, + string sourceFilePath) { TTargetData[] importedObjects = importedDataCollection.ToArray(); - TTargetData[] addedObjects = GetAddedObjects(targetDataCollection, importedObjects).ToArray(); - TTargetData[] removedObjects = GetRemovedObjects(targetDataCollection, importedObjects).ToArray(); - TTargetData[] updatedObjects = GetUpdatedObjects(targetDataCollection, importedObjects).ToArray(); + TTargetData[] objectsToBeAdded = GetObjectsToBeAdded(targetDataCollection, importedObjects).ToArray(); + TTargetData[] objectsToBeRemoved = GetObjectsToBeRemoved(targetDataCollection, importedObjects).ToArray(); + TTargetData[] objectsToBeUpdated = GetObjectsToBeUpdated(targetDataCollection, importedObjects).ToArray(); var affectedObjects = new List(); - if (addedObjects.Any()) + if (objectsToBeAdded.Any()) { affectedObjects.Add(targetDataCollection); } - affectedObjects.AddRange(UpdateData(updatedObjects, importedObjects)); - affectedObjects.AddRange(RemoveData(removedObjects)); + affectedObjects.AddRange(UpdateData(objectsToBeUpdated, importedObjects)); + affectedObjects.AddRange(RemoveData(objectsToBeRemoved)); targetDataCollection.Clear(); - targetDataCollection.AddRange(addedObjects.Union(updatedObjects), sourceFilePath); + targetDataCollection.AddRange(objectsToBeAdded.Union(objectsToBeUpdated), sourceFilePath); return affectedObjects.Distinct(new ReferenceEqualityComparer()); } - private IEnumerable GetRemovedObjects(IEnumerable existingCollection, IEnumerable importedDataOjects) + private IEnumerable GetObjectsToBeRemoved(IEnumerable existingCollection, IEnumerable importedDataOjects) { return existingCollection.Except(importedDataOjects, equalityComparer); } - private IEnumerable GetUpdatedObjects(IEnumerable existingCollection, IEnumerable importedDataObjects) + private IEnumerable GetObjectsToBeUpdated(IEnumerable existingCollection, IEnumerable importedDataObjects) { return existingCollection.Intersect(importedDataObjects, equalityComparer); } - private IEnumerable GetAddedObjects(IEnumerable existingCollection, IEnumerable importedDataObjects) + private IEnumerable GetObjectsToBeAdded(IEnumerable existingCollection, IEnumerable importedDataObjects) { return importedDataObjects.Where(source => !existingCollection.Contains(source, equalityComparer)); } Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/UpdateDataStrategies/ReplaceDataStrategyBaseTest.cs =================================================================== diff -u -rb1537a16c5961d9f66d5564c215f4bee59294f82 -r352102f53efcda2247dd7ff8c2d833eccc709c4d --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/UpdateDataStrategies/ReplaceDataStrategyBaseTest.cs (.../ReplaceDataStrategyBaseTest.cs) (revision b1537a16c5961d9f66d5564c215f4bee59294f82) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/UpdateDataStrategies/ReplaceDataStrategyBaseTest.cs (.../ReplaceDataStrategyBaseTest.cs) (revision 352102f53efcda2247dd7ff8c2d833eccc709c4d) @@ -104,7 +104,7 @@ } [Test] - public void ReplaceData_CallsClearData() + public void ReplaceData_CallsClearData_ReturnsTrue() { // Setup var strategy = new ConcreteStrategyClass(new TestFailureMechanism()); @@ -215,6 +215,26 @@ Assert.AreEqual(expectedSourcePath, collection.SourcePath); } + [Test] + public void ReplaceData_ClearDataCalled_ReturnsExpectedItems() + { + // Setup + var failureMechanism = new TestFailureMechanism(); + var strategy = new ConcreteStrategyClass(failureMechanism); + + var collection = new ObservableUniqueItemCollectionWithSourcePath( + getUniqueFeature, typeDescriptor, featureDescription); + + // Call + IObservable[] affectedObjects = strategy.ConcreteReplaceData(collection, + Enumerable.Empty(), + "some/source").ToArray(); + + // Assert + Assert.AreEqual(1, affectedObjects.Length); + Assert.AreSame(failureMechanism, affectedObjects[0]); + } + #region Helper classes private class ConcreteStrategyClass : ReplaceDataStrategyBase @@ -232,7 +252,10 @@ protected override IEnumerable ClearData(TestFailureMechanism failureMechanism) { IsClearDataCalled = true; - return Enumerable.Empty(); + return new [] + { + failureMechanism + }; } } Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/UpdateDataStrategies/UpdateDataStrategyBaseTest.cs =================================================================== diff -u -r92d8502b4ffd316c6387a0b1378e4d097c43c58d -r352102f53efcda2247dd7ff8c2d833eccc709c4d --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/UpdateDataStrategies/UpdateDataStrategyBaseTest.cs (.../UpdateDataStrategyBaseTest.cs) (revision 92d8502b4ffd316c6387a0b1378e4d097c43c58d) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/UpdateDataStrategies/UpdateDataStrategyBaseTest.cs (.../UpdateDataStrategyBaseTest.cs) (revision 352102f53efcda2247dd7ff8c2d833eccc709c4d) @@ -115,24 +115,26 @@ } [Test] - public void UpdateTargetCollectionData_WithCollectionAndImportedDataEmpty_ClearsTargetCollection() + public void UpdateTargetCollectionData_WithNonEmtpyCollectionAndImportedDataEmpty_ClearsTargetCollection() { // Setup var collection = new ObservableUniqueItemCollectionWithSourcePath( getUniqueFeature, typeDescriptor, featureDescription); const string filePath = "path"; - collection.AddRange(new[] + var itemsRemoved = new[] { new TestItem("Name A"), new TestItem("Name B") - }, filePath); + }; + collection.AddRange(itemsRemoved, filePath); var strategy = new ConcreteUpdateDataStrategy(new TestFailureMechanism()); // Call - strategy.ConcreteUpdateData(collection, Enumerable.Empty(), filePath); + IEnumerable affectedObjects = strategy.ConcreteUpdateData(collection, Enumerable.Empty(), filePath); // Assert + CollectionAssert.AreEquivalent(itemsRemoved, affectedObjects); CollectionAssert.IsEmpty(collection); Assert.AreEqual(filePath, collection.SourcePath); } @@ -142,7 +144,7 @@ { // Setup var collection = new ObservableUniqueItemCollectionWithSourcePath( - getUniqueFeature, typeDescriptor, featureDescription); + getUniqueFeature, typeDescriptor, featureDescription); var strategy = new ConcreteUpdateDataStrategy(new TestFailureMechanism()); @@ -155,12 +157,70 @@ } [Test] + public void UpdateTargetCollectionData_GetObjectsToRemoveCall_ReturnsExpectedAffectedItems() + { + // Setup + var collection = new ObservableUniqueItemCollectionWithSourcePath( + getUniqueFeature, typeDescriptor, featureDescription); + const string filePath = "path"; + var expectedAffectedItems = new[] + { + new TestItem("Name A"), + new TestItem("Name B") + }; + collection.AddRange(expectedAffectedItems, filePath); + + var strategy = new ConcreteUpdateDataStrategy(new TestFailureMechanism()); + + // Call + IObservable[] affectedObjects = strategy.ConcreteUpdateData(collection, Enumerable.Empty(), filePath).ToArray(); + + // Assert + CollectionAssert.AreEquivalent(expectedAffectedItems, affectedObjects); + CollectionAssert.IsEmpty(collection); + Assert.AreEqual(filePath, collection.SourcePath); + } + + [Test] + public void UpdateTargetCollectionData_GetObjectsToUpdateCall_ReturnsExpectedAffectedItems() + { + // Setup + var collection = new ObservableUniqueItemCollectionWithSourcePath( + getUniqueFeature, typeDescriptor, featureDescription); + const string filePath = "path"; + var updatedItems = new[] + { + new TestItem("Name A"), + new TestItem("Name B") + }; + collection.AddRange(updatedItems, filePath); + + var strategy = new ConcreteUpdateDataStrategy(new TestFailureMechanism()); + + var importedItems = new[] + { + new TestItem("Name A"), + new TestItem("Name B") + }; + + // Call + IObservable[] affectedObjects = strategy.ConcreteUpdateData(collection, importedItems, filePath).ToArray(); + + // Assert + IEnumerable expectedAffectedObjects = updatedItems.Concat(importedItems); + + CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + CollectionAssert.AreEqual(updatedItems, collection); + Assert.AreEqual(filePath, collection.SourcePath); + } + + [Test] public void UpdateTargetCollectionData_WithEmptyCollectionAndImportedDataCollectionNotEmpty_AddsNewItems() { // Setup var collection = new ObservableUniqueItemCollectionWithSourcePath( getUniqueFeature, typeDescriptor, featureDescription); - var importedCollection = new[] + var importedItems = new[] { new TestItem("Name A"), new TestItem("Name B") @@ -169,11 +229,15 @@ var strategy = new ConcreteUpdateDataStrategy(new TestFailureMechanism()); // Call - IEnumerable affectedObjects = strategy.ConcreteUpdateData(collection, importedCollection, "path"); + IEnumerable affectedObjects = strategy.ConcreteUpdateData(collection, importedItems, "path"); // Assert - CollectionAssert.AreEqual(importedCollection, collection); - CollectionAssert.Contains(affectedObjects, collection); + CollectionAssert.AreEqual(importedItems, collection); + IEnumerable expectedAffectedObjects = importedItems.Concat(new IObservable[] + { + collection + }); + CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); Assert.AreEqual("path", collection.SourcePath); } @@ -183,6 +247,10 @@ // Setup var collection = new ObservableUniqueItemCollectionWithSourcePath( getUniqueFeature, typeDescriptor, featureDescription); + collection.AddRange(new[] + { + new TestItem("I am an expected item") + }, "path"); const string duplicateName = "Duplicate Name"; var importedCollection = new[] @@ -203,7 +271,7 @@ CollectionAssert.IsEmpty(collection); } - + private class ConcreteUpdateDataStrategy : UpdateDataStrategyBase { public bool IsUpdateDataCalled { get; private set; } @@ -225,13 +293,19 @@ protected override IEnumerable UpdateData(IEnumerable objectsToUpdate, IEnumerable importedDataCollection) { IsUpdateDataCalled = true; - return Enumerable.Empty(); + var affectedObjects = new List(); + affectedObjects.AddRange(objectsToUpdate); + affectedObjects.AddRange(importedDataCollection); + return affectedObjects; } protected override IEnumerable RemoveData(IEnumerable removedObjects) { IsRemoveDataCalled = true; - return Enumerable.Empty(); + + var affectedObjects = new List(); + affectedObjects.AddRange(removedObjects); + return affectedObjects; } private class NameComparer : IEqualityComparer @@ -248,7 +322,7 @@ } } - private class TestItem + private class TestItem : Observable { public string Name { get; } Index: Ringtoets/Piping/src/Ringtoets.Piping.Data/RingtoetsPipingSurfaceLineCollection.cs =================================================================== diff -u -rc290911dd4647e3115e239c8baf814717c098a5a -r352102f53efcda2247dd7ff8c2d833eccc709c4d --- Ringtoets/Piping/src/Ringtoets.Piping.Data/RingtoetsPipingSurfaceLineCollection.cs (.../RingtoetsPipingSurfaceLineCollection.cs) (revision c290911dd4647e3115e239c8baf814717c098a5a) +++ Ringtoets/Piping/src/Ringtoets.Piping.Data/RingtoetsPipingSurfaceLineCollection.cs (.../RingtoetsPipingSurfaceLineCollection.cs) (revision 352102f53efcda2247dd7ff8c2d833eccc709c4d) @@ -26,7 +26,8 @@ namespace Ringtoets.Piping.Data { /// - /// Collection to store . + /// Collection to store items. The + /// names of the items are unique within the collection. /// public class RingtoetsPipingSurfaceLineCollection : ObservableUniqueItemCollectionWithSourcePath { Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/IStochasticSoilModelUpdateModelStrategy.cs =================================================================== diff -u -re45d53ab48741d0112dca1ad6bb6cf199535c8b7 -r352102f53efcda2247dd7ff8c2d833eccc709c4d --- Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/IStochasticSoilModelUpdateModelStrategy.cs (.../IStochasticSoilModelUpdateModelStrategy.cs) (revision e45d53ab48741d0112dca1ad6bb6cf199535c8b7) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/IStochasticSoilModelUpdateModelStrategy.cs (.../IStochasticSoilModelUpdateModelStrategy.cs) (revision 352102f53efcda2247dd7ff8c2d833eccc709c4d) @@ -36,7 +36,7 @@ /// /// Adds the imported data to the . /// - /// The to which the imported data + /// The to which the imported data /// is added. /// The stochastic soil models which were imported. /// The path to the source file from which the soil models were imported. Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/RingtoetsPipingSurfaceLineUpdateStrategy.cs =================================================================== diff -u -re45d53ab48741d0112dca1ad6bb6cf199535c8b7 -r352102f53efcda2247dd7ff8c2d833eccc709c4d --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/RingtoetsPipingSurfaceLineUpdateStrategy.cs (.../RingtoetsPipingSurfaceLineUpdateStrategy.cs) (revision e45d53ab48741d0112dca1ad6bb6cf199535c8b7) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/RingtoetsPipingSurfaceLineUpdateStrategy.cs (.../RingtoetsPipingSurfaceLineUpdateStrategy.cs) (revision 352102f53efcda2247dd7ff8c2d833eccc709c4d) @@ -36,12 +36,7 @@ namespace Ringtoets.Piping.Plugin.FileImporter { /// - /// Strategy for updating the current surface lines with the imported surface lines: - /// - /// Adds imported surface lines that are not part of the current collection. - /// Removes surface lines that are part of the current collection, but are not part of the imported surface line collection. - /// Updates the surface lines that are part of the current collection and are part of the imported surface line collection. - /// + /// An for updating surface lines based on imported data. /// public class RingtoetsPipingSurfaceLineUpdateDataStrategy : UpdateDataStrategyBase, ISurfaceLineUpdateDataStrategy Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelUpdateDataStrategy.cs =================================================================== diff -u -re45d53ab48741d0112dca1ad6bb6cf199535c8b7 -r352102f53efcda2247dd7ff8c2d833eccc709c4d --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelUpdateDataStrategy.cs (.../StochasticSoilModelUpdateDataStrategy.cs) (revision e45d53ab48741d0112dca1ad6bb6cf199535c8b7) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelUpdateDataStrategy.cs (.../StochasticSoilModelUpdateDataStrategy.cs) (revision 352102f53efcda2247dd7ff8c2d833eccc709c4d) @@ -35,15 +35,7 @@ namespace Ringtoets.Piping.Plugin.FileImporter { /// - /// Strategy for updating the current stochastic soil models with the imported stochastic soil models. - /// - /// Adds stochastic soil models that are imported and are not part of current stochastic soil model collection. - /// Removes stochastic soil models that are part of the current stochastic soil model collection, but were not - /// amongst the imported stochastic soil models. - /// - /// Updates stochastic soil models that are part of the current stochastic soil model collection and are also - /// imported. - /// + /// An for updating stochastic soil models based on imported data. /// public class StochasticSoilModelUpdateDataStrategy : UpdateDataStrategyBase, IStochasticSoilModelUpdateModelStrategy