Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/FileImporters/ClosingStructureUpdateDataStrategy.cs =================================================================== diff -u -r1010d4569cd91ef8661e423e01f833e932180fd4 -re3ec5f4669022733a11c4c3070747331bf36056f --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/FileImporters/ClosingStructureUpdateDataStrategy.cs (.../ClosingStructureUpdateDataStrategy.cs) (revision 1010d4569cd91ef8661e423e01f833e932180fd4) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/FileImporters/ClosingStructureUpdateDataStrategy.cs (.../ClosingStructureUpdateDataStrategy.cs) (revision e3ec5f4669022733a11c4c3070747331bf36056f) @@ -85,16 +85,9 @@ protected override IEnumerable UpdateObjectAndDependentData(ClosingStructure objectToUpdate, ClosingStructure objectToUpdateFrom) { - var affectedObjects = new List(); + objectToUpdate.CopyProperties(objectToUpdateFrom); - if (!objectToUpdate.Equals(objectToUpdateFrom)) - { - objectToUpdate.CopyProperties(objectToUpdateFrom); - - affectedObjects.AddRange(UpdateClosingStructureDependentData(objectToUpdate)); - } - - return affectedObjects; + return UpdateClosingStructureDependentData(objectToUpdate); } private IEnumerable UpdateClosingStructureDependentData(ClosingStructure structure) Index: Ringtoets/Common/src/Ringtoets.Common.Data/UpdateDataStrategies/UpdateDataStrategyBase.cs =================================================================== diff -u -r922d8c8ebb07e20fb0fe567d65f7d2df2bd224c1 -re3ec5f4669022733a11c4c3070747331bf36056f --- Ringtoets/Common/src/Ringtoets.Common.Data/UpdateDataStrategies/UpdateDataStrategyBase.cs (.../UpdateDataStrategyBase.cs) (revision 922d8c8ebb07e20fb0fe567d65f7d2df2bd224c1) +++ Ringtoets/Common/src/Ringtoets.Common.Data/UpdateDataStrategies/UpdateDataStrategyBase.cs (.../UpdateDataStrategyBase.cs) (revision e3ec5f4669022733a11c4c3070747331bf36056f) @@ -69,7 +69,7 @@ } /// - /// Updates the object and its dependent data with data from the imported data. + /// Updates the unequal object and its dependent data with data from the imported data. /// /// Object that needs to be updated. /// The object to update from. @@ -112,14 +112,7 @@ throw new ArgumentNullException(nameof(sourceFilePath)); } - try - { - return ModifyDataCollection(targetDataCollection, importedDataCollection, sourceFilePath); - } - catch (ArgumentException e) - { - throw new UpdateDataException(e.Message, e); - } + return ModifyDataCollection(targetDataCollection, importedDataCollection, sourceFilePath); } /// @@ -132,10 +125,12 @@ /// the /// The source file path. /// A with affected objects. - /// Thrown when duplicate items are being added to the - /// . - /// Thrown when duplicate items are found in the - /// . + /// Thrown when: + /// + /// duplicate items are being added to the . + /// duplicate items are found in the . + /// + /// private IEnumerable ModifyDataCollection(ObservableUniqueItemCollectionWithSourcePath targetDataCollection, IEnumerable importedDataCollection, string sourceFilePath) @@ -195,16 +190,22 @@ { TTargetData objectToUpdateFrom = importedDataCollection.Single(importedObject => equalityComparer.Equals(importedObject, objectToUpdate)); - if (!objectToUpdate.Equals(objectToUpdateFrom)) + + if (IsUpdateObjectDataUnequal(objectToUpdate, objectToUpdateFrom)) { affectedObjects.Add(objectToUpdate); + affectedObjects.AddRange(UpdateObjectAndDependentData(objectToUpdate, objectToUpdateFrom)); } - affectedObjects.AddRange(UpdateObjectAndDependentData(objectToUpdate, objectToUpdateFrom)); } return affectedObjects; } + private static bool IsUpdateObjectDataUnequal(TTargetData objectToUpdate, TTargetData objectToUpdateFrom) + { + return !objectToUpdate.Equals(objectToUpdateFrom); + } + /// /// Removes all the objects and their dependent data. /// Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/UpdateDataStrategies/UpdateDataStrategyBaseTest.cs =================================================================== diff -u -rb7f91e5d6aaac3c9a52cfda9b1bdd3a74ee4f8b1 -re3ec5f4669022733a11c4c3070747331bf36056f --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/UpdateDataStrategies/UpdateDataStrategyBaseTest.cs (.../UpdateDataStrategyBaseTest.cs) (revision b7f91e5d6aaac3c9a52cfda9b1bdd3a74ee4f8b1) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/UpdateDataStrategies/UpdateDataStrategyBaseTest.cs (.../UpdateDataStrategyBaseTest.cs) (revision e3ec5f4669022733a11c4c3070747331bf36056f) @@ -145,8 +145,10 @@ }; collection.AddRange(itemsRemoved, filePath); - var strategy = new ConcreteUpdateDataStrategy(new TestFailureMechanism()); - strategy.ItemsToRemove = itemsRemoved; + var strategy = new ConcreteUpdateDataStrategy(new TestFailureMechanism()) + { + ItemsToRemove = itemsRemoved + }; // Call IEnumerable affectedObjects = strategy.ConcreteUpdateData(collection, Enumerable.Empty(), filePath); @@ -258,34 +260,29 @@ currentCollection[1].DeepClone() }; - var strategy = new ConcreteUpdateDataStrategy(new TestFailureMechanism()); - strategy.ItemsToUpdate = currentCollection; + var strategy = new ConcreteUpdateDataStrategy(new TestFailureMechanism()) + { + ItemsToUpdate = currentCollection + }; // Call IEnumerable affectedObjects = strategy.ConcreteUpdateData(collection, importedItems, sourceFilePath); // Assert - Assert.IsTrue(strategy.IsUpdateDataCalled); + Assert.IsFalse(strategy.IsUpdateDataCalled); Assert.IsFalse(strategy.IsRemoveObjectAndDependentDataCalled); - int expectedNrOfUpdateCalls = currentCollection.Length; + const int expectedNrOfUpdateCalls = 0; List> updateArgumentCalls = strategy.UpdateDataCallArguments; - Assert.AreEqual(currentCollection.Length, updateArgumentCalls.Count); - for (var i = 0; i < expectedNrOfUpdateCalls; i++) - { - Assert.AreSame(currentCollection[i], updateArgumentCalls[i].Item1); - Assert.AreSame(importedItems[i], updateArgumentCalls[i].Item2); - } + Assert.AreEqual(expectedNrOfUpdateCalls, updateArgumentCalls.Count); CollectionAssert.IsEmpty(strategy.RemoveDataCallArguments); CollectionAssert.AreEqual(currentCollection, collection); CollectionAssert.AreEqual(new IObservable[] { - collection, - currentCollection[0], - currentCollection[1] + collection }, affectedObjects); } @@ -310,8 +307,10 @@ currentCollection[1].DeepClone() }; - var strategy = new ConcreteUpdateDataStrategy(new TestFailureMechanism()); - strategy.ItemsToUpdate = currentCollection; + var strategy = new ConcreteUpdateDataStrategy(new TestFailureMechanism()) + { + ItemsToUpdate = currentCollection + }; const string newSourceFilePath = "Something/Different/From/Onbekend"; @@ -321,16 +320,14 @@ newSourceFilePath); // Assert - Assert.IsTrue(strategy.IsUpdateDataCalled); + Assert.IsFalse(strategy.IsUpdateDataCalled); Assert.IsFalse(strategy.IsRemoveObjectAndDependentDataCalled); Assert.AreEqual(newSourceFilePath, collection.SourcePath); CollectionAssert.AreEqual(currentCollection, collection); CollectionAssert.AreEqual(new IObservable[] { - collection, - currentCollection[0], - currentCollection[1] + collection }, affectedObjects); } @@ -354,30 +351,30 @@ itemToAdd }; - var strategy = new ConcreteUpdateDataStrategy(new TestFailureMechanism()); - strategy.ItemsToUpdate = new[] + var strategy = new ConcreteUpdateDataStrategy(new TestFailureMechanism()) { - itemToUpdate + ItemsToUpdate = new[] + { + itemToUpdate + }, + ItemsToRemove = new[] + { + itemToRemove + } }; - strategy.ItemsToRemove = new[] - { - itemToRemove - }; // Call IEnumerable affectedObjects = strategy.ConcreteUpdateData(collection, importedItems, sourceFilePath); // Assert - Assert.IsTrue(strategy.IsUpdateDataCalled); + Assert.IsFalse(strategy.IsUpdateDataCalled); Assert.IsTrue(strategy.IsRemoveObjectAndDependentDataCalled); - const int expectedNrOfUpdateCalls = 1; + const int expectedNrOfUpdateCalls = 0; List> updateDataCallArguments = strategy.UpdateDataCallArguments; Assert.AreEqual(expectedNrOfUpdateCalls, updateDataCallArguments.Count); - Assert.AreSame(itemToUpdate, updateDataCallArguments[0].Item1); - Assert.AreSame(importedItems[0], updateDataCallArguments[0].Item2); List> removeDataCallArguments = strategy.RemoveDataCallArguments; Assert.AreEqual(1, removeDataCallArguments.Count); @@ -391,7 +388,6 @@ CollectionAssert.AreEqual(expectedCollection, collection); CollectionAssert.AreEquivalent(new IObservable[] { - itemToUpdate, itemToRemove, collection }, affectedObjects); @@ -415,8 +411,10 @@ new TestItem("Item four") }; - var strategy = new ConcreteUpdateDataStrategy(new TestFailureMechanism()); - strategy.ItemsToRemove = currentCollection; + var strategy = new ConcreteUpdateDataStrategy(new TestFailureMechanism()) + { + ItemsToRemove = currentCollection + }; // Call IEnumerable affectedObjects = strategy.ConcreteUpdateData(collection, @@ -475,29 +473,28 @@ } [Test] - public void UpdateTargetCollectionData_CalledWithSameObjectReferences_ReturnsOnlyDistinctObjects() + public void UpdateTargetCollectionData_SameObjectAddedToAffectedObjects_ReturnsOnlyDistinctObjects() { // Setup - var itemOne = new TestItem("Item one"); - var itemTwo = new TestItem("Item two"); + var itemOne = new TestItem(1); + var itemTwo = new TestItem(2); var currentCollection = new[] { - itemOne, - itemTwo + itemOne }; var collection = new TestUniqueItemCollection(); collection.AddRange(currentCollection, "path"); var importedItems = new[] { - itemOne, itemTwo }; var strategy = new ConcreteUpdateDataStrategy(new TestFailureMechanism()) { ItemsToUpdate = currentCollection, - ItemsToUpdateFrom = importedItems + ItemsToUpdateFrom = importedItems, + AddObjectToUpdateToAffectedItems = true }; // Call @@ -517,6 +514,8 @@ private class ConcreteUpdateDataStrategy : UpdateDataStrategyBase { + public bool AddObjectToUpdateToAffectedItems; + public ConcreteUpdateDataStrategy(TestFailureMechanism failureMechanism, IEqualityComparer comparer) : base(failureMechanism, comparer) {} @@ -552,7 +551,12 @@ IsUpdateDataCalled = true; UpdateDataCallArguments.Add(new Tuple(objectToUpdate, objectToUpdateFrom)); - return ItemsToUpdate.Concat(ItemsToUpdateFrom); + return AddObjectToUpdateToAffectedItems + ? ItemsToUpdate.Concat(ItemsToUpdateFrom).Concat(new[] + { + objectToUpdate + }) + : ItemsToUpdate.Concat(ItemsToUpdateFrom); } protected override IEnumerable RemoveObjectAndDependentData(TestItem removedObject) @@ -585,22 +589,70 @@ private class TestItem : Observable { + private readonly int id; + public TestItem(string name) { Name = name; } + public TestItem(int id) + { + Name = "TestItem"; + this.id = id; + } + + private TestItem(int id, string name) + { + Name = name; + this.id = id; + } + public string Name { get; } public TestItem DeepClone() { - return new TestItem(Name); + return new TestItem(id, Name); } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) + { + return false; + } + if (ReferenceEquals(this, obj)) + { + return true; + } + if (obj.GetType() != GetType()) + { + return false; + } + return Equals((TestItem) obj); + } + + public override int GetHashCode() + { + unchecked + { + int hashCode = Name.GetHashCode(); + hashCode = (hashCode * 397) ^ id.GetHashCode(); + + return hashCode; + } + } + public override string ToString() { return Name; } + + private bool Equals(TestItem other) + { + return id.Equals(other.id) + && Name.Equals(other.Name); + } } } } \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/FileImporters/GrassCoverErosionInwardsDikeProfileUpdateDataStrategy.cs =================================================================== diff -u -r4eaa942f6a986a04aacee22d1b8e142b0d07f389 -re3ec5f4669022733a11c4c3070747331bf36056f --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/FileImporters/GrassCoverErosionInwardsDikeProfileUpdateDataStrategy.cs (.../GrassCoverErosionInwardsDikeProfileUpdateDataStrategy.cs) (revision 4eaa942f6a986a04aacee22d1b8e142b0d07f389) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/FileImporters/GrassCoverErosionInwardsDikeProfileUpdateDataStrategy.cs (.../GrassCoverErosionInwardsDikeProfileUpdateDataStrategy.cs) (revision e3ec5f4669022733a11c4c3070747331bf36056f) @@ -59,13 +59,10 @@ protected override IEnumerable UpdateObjectAndDependentData(DikeProfile objectToUpdate, DikeProfile objectToUpdateFrom) { + objectToUpdate.CopyProperties(objectToUpdateFrom); + var affectedObjects = new List(); - if (!objectToUpdate.Equals(objectToUpdateFrom)) - { - objectToUpdate.CopyProperties(objectToUpdateFrom); - affectedObjects.Add(objectToUpdate); - affectedObjects.AddRange(UpdateDikeDependentData(objectToUpdate)); - } + affectedObjects.AddRange(UpdateDikeDependentData(objectToUpdate)); return affectedObjects; } Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/FileImporters/HeightStructureUpdateDataStrategy.cs =================================================================== diff -u -r9da080f738eb93fe40ed2a855753ea9c455063bc -re3ec5f4669022733a11c4c3070747331bf36056f --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/FileImporters/HeightStructureUpdateDataStrategy.cs (.../HeightStructureUpdateDataStrategy.cs) (revision 9da080f738eb93fe40ed2a855753ea9c455063bc) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/FileImporters/HeightStructureUpdateDataStrategy.cs (.../HeightStructureUpdateDataStrategy.cs) (revision e3ec5f4669022733a11c4c3070747331bf36056f) @@ -85,16 +85,9 @@ protected override IEnumerable UpdateObjectAndDependentData(HeightStructure objectToUpdate, HeightStructure objectToUpdateFrom) { - var affectedObjects = new List(); + objectToUpdate.CopyProperties(objectToUpdateFrom); - if (!objectToUpdate.Equals(objectToUpdateFrom)) - { - objectToUpdate.CopyProperties(objectToUpdateFrom); - - affectedObjects.AddRange(UpdateHeightStructureDependentData(objectToUpdate)); - } - - return affectedObjects; + return UpdateHeightStructureDependentData(objectToUpdate); } private IEnumerable UpdateHeightStructureDependentData(HeightStructure structure) Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/FileImporters/ForeshoreProfileUpdateDataStrategy.cs =================================================================== diff -u -r922d8c8ebb07e20fb0fe567d65f7d2df2bd224c1 -re3ec5f4669022733a11c4c3070747331bf36056f --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/FileImporters/ForeshoreProfileUpdateDataStrategy.cs (.../ForeshoreProfileUpdateDataStrategy.cs) (revision 922d8c8ebb07e20fb0fe567d65f7d2df2bd224c1) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/FileImporters/ForeshoreProfileUpdateDataStrategy.cs (.../ForeshoreProfileUpdateDataStrategy.cs) (revision e3ec5f4669022733a11c4c3070747331bf36056f) @@ -58,18 +58,16 @@ protected override IEnumerable UpdateObjectAndDependentData(ForeshoreProfile objectToUpdate, ForeshoreProfile objectToUpdateFrom) { + objectToUpdate.CopyProperties(objectToUpdateFrom); + var affectedObjects = new List(); - if (!objectToUpdate.Equals(objectToUpdateFrom)) - { - objectToUpdate.CopyProperties(objectToUpdateFrom); - IEnumerable> affectedCalculations = GetAffectedCalculationWithSurfaceLines(objectToUpdate); + IEnumerable> affectedCalculations = GetAffectedCalculationWithSurfaceLines(objectToUpdate); - foreach (ICalculation calculation in affectedCalculations) - { - affectedObjects.Add(calculation.InputParameters); - affectedObjects.AddRange(RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation)); - } + foreach (ICalculation calculation in affectedCalculations) + { + affectedObjects.Add(calculation.InputParameters); + affectedObjects.AddRange(RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation)); } return affectedObjects; Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/RingtoetsPipingSurfaceLineUpdateDataStrategy.cs =================================================================== diff -u -r922d8c8ebb07e20fb0fe567d65f7d2df2bd224c1 -re3ec5f4669022733a11c4c3070747331bf36056f --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/RingtoetsPipingSurfaceLineUpdateDataStrategy.cs (.../RingtoetsPipingSurfaceLineUpdateDataStrategy.cs) (revision 922d8c8ebb07e20fb0fe567d65f7d2df2bd224c1) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/RingtoetsPipingSurfaceLineUpdateDataStrategy.cs (.../RingtoetsPipingSurfaceLineUpdateDataStrategy.cs) (revision e3ec5f4669022733a11c4c3070747331bf36056f) @@ -81,18 +81,15 @@ protected override IEnumerable UpdateObjectAndDependentData(RingtoetsPipingSurfaceLine surfaceLineToUpdate, RingtoetsPipingSurfaceLine matchingSurfaceLine) { + surfaceLineToUpdate.CopyProperties(matchingSurfaceLine); + var affectedObjects = new List(); - if (!surfaceLineToUpdate.Equals(matchingSurfaceLine)) - { - surfaceLineToUpdate.CopyProperties(matchingSurfaceLine); + affectedObjects.AddRange(UpdateSurfaceLineDependentData(surfaceLineToUpdate)); + affectedObjects.AddRange(UpdateStochasticSoilModel(surfaceLineToUpdate)); - affectedObjects.AddRange(UpdateSurfaceLineDependentData(surfaceLineToUpdate)); - affectedObjects.AddRange(UpdateStochasticSoilModel(surfaceLineToUpdate)); + ValidateEntryAndExitPoints(surfaceLineToUpdate); - ValidateEntryAndExitPoints(surfaceLineToUpdate); - } - return affectedObjects; } Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelUpdateDataStrategy.cs =================================================================== diff -u -r922d8c8ebb07e20fb0fe567d65f7d2df2bd224c1 -re3ec5f4669022733a11c4c3070747331bf36056f --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelUpdateDataStrategy.cs (.../StochasticSoilModelUpdateDataStrategy.cs) (revision 922d8c8ebb07e20fb0fe567d65f7d2df2bd224c1) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelUpdateDataStrategy.cs (.../StochasticSoilModelUpdateDataStrategy.cs) (revision e3ec5f4669022733a11c4c3070747331bf36056f) @@ -83,10 +83,7 @@ protected override IEnumerable UpdateObjectAndDependentData(StochasticSoilModel soilModelToUpdate, StochasticSoilModel soilModelToUpdateFrom) { - var affectedObjects = new List(); - affectedObjects.AddRange(UpdateStochasticSoilModel(soilModelToUpdate, soilModelToUpdateFrom)); - - return affectedObjects; + return UpdateStochasticSoilModel(soilModelToUpdate, soilModelToUpdateFrom); } private IEnumerable UpdateStochasticSoilModel(StochasticSoilModel modelToUpdate, StochasticSoilModel modelToUpdateFrom)