Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/FileImporters/HeightStructureUpdateDataStrategy.cs
===================================================================
diff -u -r4954f3a3c5eab3aff1b2d4c5a58364f06fe4bbd2 -rf21dfc68719af2540c7c07392fdd3d045907098d
--- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/FileImporters/HeightStructureUpdateDataStrategy.cs (.../HeightStructureUpdateDataStrategy.cs) (revision 4954f3a3c5eab3aff1b2d4c5a58364f06fe4bbd2)
+++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/FileImporters/HeightStructureUpdateDataStrategy.cs (.../HeightStructureUpdateDataStrategy.cs) (revision f21dfc68719af2540c7c07392fdd3d045907098d)
@@ -21,13 +21,16 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using Core.Common.Base;
using Ringtoets.Common.Data;
using Ringtoets.Common.Data.Exceptions;
+using Ringtoets.Common.Data.Structures;
using Ringtoets.Common.Data.UpdateDataStrategies;
using Ringtoets.Common.IO.Exceptions;
using Ringtoets.Common.IO.Properties;
using Ringtoets.Common.IO.Structures;
+using Ringtoets.Common.Utils;
using Ringtoets.HeightStructures.Data;
using Ringtoets.HeightStructures.Service;
@@ -74,6 +77,22 @@
#endregion
+ ///
+ /// Class for comparing by only the id.
+ ///
+ private class StructureIdEqualityComparer : IEqualityComparer
+ {
+ public bool Equals(HeightStructure x, HeightStructure y)
+ {
+ return x.Id.Equals(y.Id);
+ }
+
+ public int GetHashCode(HeightStructure obj)
+ {
+ return obj.Id.GetHashCode();
+ }
+ }
+
#region Updating Data Functions
protected override IEnumerable UpdateObjectAndDependentData(HeightStructure objectToUpdate,
@@ -84,27 +103,43 @@
if (!objectToUpdate.Equals(objectToUpdateFrom))
{
objectToUpdate.CopyProperties(objectToUpdateFrom);
+
+ affectedObjects.AddRange(UpdateHeightStructureDependentData(objectToUpdate));
}
return affectedObjects;
}
- #endregion
-
- ///
- /// Class for comparing by only the id.
- ///
- private class StructureIdEqualityComparer : IEqualityComparer
+ private IEnumerable UpdateHeightStructureDependentData(HeightStructure structure)
{
- public bool Equals(HeightStructure x, HeightStructure y)
- {
- return x.Id.Equals(y.Id);
- }
+ var affectedObjects = new List();
- public int GetHashCode(HeightStructure obj)
+ foreach (StructuresCalculation affectedCalculation in GetAffectedCalculationsWithHeightStructure(structure))
{
- return obj.Id.GetHashCode();
+ affectedObjects.Add(affectedCalculation.InputParameters);
+ if (affectedCalculation.HasOutput)
+ {
+ affectedObjects.Add(affectedCalculation);
+ }
}
+
+ affectedObjects.AddRange(StructuresHelper.UpdateCalculationToSectionResultAssignments(
+ FailureMechanism.SectionResults,
+ FailureMechanism.Calculations.Cast>())
+ );
+
+ return affectedObjects;
}
+
+ private IEnumerable> GetAffectedCalculationsWithHeightStructure(HeightStructure structure)
+ {
+ IEnumerable> affectedCalculations =
+ FailureMechanism.Calculations
+ .Cast>()
+ .Where(calc => ReferenceEquals(calc.InputParameters.Structure, structure));
+ return affectedCalculations;
+ }
+
+ #endregion
}
}
\ No newline at end of file
Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/FileImporters/HeightStructureUpdateDataStrategyTest.cs
===================================================================
diff -u -r4954f3a3c5eab3aff1b2d4c5a58364f06fe4bbd2 -rf21dfc68719af2540c7c07392fdd3d045907098d
--- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/FileImporters/HeightStructureUpdateDataStrategyTest.cs (.../HeightStructureUpdateDataStrategyTest.cs) (revision 4954f3a3c5eab3aff1b2d4c5a58364f06fe4bbd2)
+++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/FileImporters/HeightStructureUpdateDataStrategyTest.cs (.../HeightStructureUpdateDataStrategyTest.cs) (revision f21dfc68719af2540c7c07392fdd3d045907098d)
@@ -29,9 +29,12 @@
using NUnit.Framework;
using Ringtoets.Common.Data;
using Ringtoets.Common.Data.Exceptions;
+using Ringtoets.Common.Data.FailureMechanism;
+using Ringtoets.Common.Data.Structures;
using Ringtoets.Common.Data.UpdateDataStrategies;
using Ringtoets.Common.IO.Exceptions;
using Ringtoets.Common.IO.Structures;
+using Ringtoets.Common.Utils;
using Ringtoets.HeightStructures.Data;
using Ringtoets.HeightStructures.Data.TestUtil;
using Ringtoets.HeightStructures.Plugin.FileImporters;
@@ -321,17 +324,149 @@
var strategy = new HeightStructureUpdateDataStrategy(new HeightStructuresFailureMechanism());
// Call
- strategy.UpdateStructuresWithImportedData(targetCollection,
- new[]
- {
- readStructure
- },
- sourceFilePath);
+ IEnumerable affectedObjects = strategy.UpdateStructuresWithImportedData(targetCollection,
+ new[]
+ {
+ readStructure
+ },
+ sourceFilePath);
// Assert
AssertHeightStructures(readStructure, structure);
+ CollectionAssert.AreEqual(new[]
+ {
+ targetCollection
+ }, affectedObjects);
}
+ [Test]
+ public void UpdateStructuresWithImportedData_CalculationWithStructureImportedStructureWithSameId_UpdatesCalculation()
+ {
+ // Setup
+ const string sameId = "sameId";
+ HeightStructure readStructure = new TestHeightStructure("new structure", sameId);
+ HeightStructure structure = new TestHeightStructure("original structure", sameId);
+
+ var calculation = new TestHeightStructuresCalculation
+ {
+ InputParameters =
+ {
+ Structure = structure
+ }
+ };
+ var failureMechanism = new HeightStructuresFailureMechanism
+ {
+ CalculationsGroup =
+ {
+ Children =
+ {
+ calculation
+ }
+ }
+ };
+ failureMechanism.HeightStructures.AddRange(new[]
+ {
+ structure
+ }, sourceFilePath);
+
+ var strategy = new HeightStructureUpdateDataStrategy(failureMechanism);
+
+ // Call
+ IEnumerable affectedObjects = strategy.UpdateStructuresWithImportedData(failureMechanism.HeightStructures,
+ new[]
+ {
+ readStructure
+ },
+ sourceFilePath);
+
+ // Assert
+ AssertHeightStructures(readStructure, structure);
+ CollectionAssert.AreEqual(new IObservable[]
+ {
+ failureMechanism.HeightStructures,
+ calculation.InputParameters
+ }, affectedObjects);
+ }
+
+ [Test]
+ public void UpdateStructuresWithImportedData_SectionResultWithStructureImportedStructureWithSameId_UpdatesCalculation()
+ {
+ // Setup
+ const string sameId = "sameId";
+ var originalMatchingPoint = new Point2D(0, 0);
+ var updatedMatchingPoint = new Point2D(20, 20);
+ HeightStructure readStructure = new TestHeightStructure(updatedMatchingPoint, sameId);
+ HeightStructure structure = new TestHeightStructure(originalMatchingPoint, sameId);
+
+ var calculation = new TestHeightStructuresCalculation
+ {
+ InputParameters =
+ {
+ Structure = structure
+ }
+ };
+ var failureMechanism = new HeightStructuresFailureMechanism
+ {
+ CalculationsGroup =
+ {
+ Children =
+ {
+ calculation
+ }
+ }
+ };
+ failureMechanism.HeightStructures.AddRange(new[]
+ {
+ structure
+ }, sourceFilePath);
+
+ var intersectionPoint = new Point2D(10, 10);
+ failureMechanism.AddSection(new FailureMechanismSection("OldSection", new[]
+ {
+ originalMatchingPoint,
+ intersectionPoint
+ }));
+ failureMechanism.AddSection(new FailureMechanismSection("NewSection", new[]
+ {
+ intersectionPoint,
+ updatedMatchingPoint
+ }));
+
+ StructuresHelper.UpdateCalculationToSectionResultAssignments(failureMechanism.SectionResults,
+ failureMechanism.Calculations.Cast>());
+
+ HeightStructuresFailureMechanismSectionResult[] sectionResults = failureMechanism.SectionResults.ToArray();
+ Assert.AreSame(calculation, sectionResults[0].Calculation);
+ Assert.IsNull(sectionResults[1].Calculation);
+
+ var strategy = new HeightStructureUpdateDataStrategy(failureMechanism);
+
+ // Call
+ IEnumerable affectedObjects = strategy.UpdateStructuresWithImportedData(
+ failureMechanism.HeightStructures,
+ new[]
+ {
+ readStructure
+ },
+ sourceFilePath);
+
+ // Assert
+ AssertHeightStructures(readStructure, structure);
+
+ var expectedAffectedObjects = new List
+ {
+ failureMechanism.HeightStructures,
+ calculation.InputParameters
+ };
+ expectedAffectedObjects.AddRange(failureMechanism.SectionResults);
+ CollectionAssert.AreEqual(expectedAffectedObjects, affectedObjects);
+
+ sectionResults = failureMechanism.SectionResults.ToArray();
+ Assert.AreEqual(2, sectionResults.Length);
+ Assert.IsNull(sectionResults[0].Calculation);
+ Assert.AreSame(calculation, sectionResults[1].Calculation);
+ }
+
private static void AssertHeightStructures(HeightStructure readStructure, HeightStructure structure)
{
Assert.AreEqual(readStructure.Name, structure.Name);
Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/Ringtoets.HeightStructures.Plugin.Test.csproj
===================================================================
diff -u -ra8e42210f83110977d18ff743cc7b5808d2f884b -rf21dfc68719af2540c7c07392fdd3d045907098d
--- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/Ringtoets.HeightStructures.Plugin.Test.csproj (.../Ringtoets.HeightStructures.Plugin.Test.csproj) (revision a8e42210f83110977d18ff743cc7b5808d2f884b)
+++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/Ringtoets.HeightStructures.Plugin.Test.csproj (.../Ringtoets.HeightStructures.Plugin.Test.csproj) (revision f21dfc68719af2540c7c07392fdd3d045907098d)
@@ -133,6 +133,10 @@
{52BA7627-CBAB-4209-BE77-3B5F31378277}
Ringtoets.Common.IO
+
+ {6A074D65-A81C-4C1C-8E24-F36C916E4ED7}
+ Ringtoets.Common.Utils
+
{4843D6E5-066F-4795-94F5-1D53932DD03C}
Ringtoets.Common.Data.TestUtil