Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/FileImporters/HeightStructureUpdateDataStrategy.cs
===================================================================
diff -u -re3ec5f4669022733a11c4c3070747331bf36056f -r9b0d18547885c18342a9ab149538b137f0b004d0
--- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/FileImporters/HeightStructureUpdateDataStrategy.cs (.../HeightStructureUpdateDataStrategy.cs) (revision e3ec5f4669022733a11c4c3070747331bf36056f)
+++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/FileImporters/HeightStructureUpdateDataStrategy.cs (.../HeightStructureUpdateDataStrategy.cs) (revision 9b0d18547885c18342a9ab149538b137f0b004d0)
@@ -65,16 +65,16 @@
}
///
- /// Class for comparing by only the id.
+ /// Class for comparing by only the id.
///
- private class StructureIdEqualityComparer : IEqualityComparer
+ private class StructureIdEqualityComparer : IEqualityComparer
{
- public bool Equals(HeightStructure x, HeightStructure y)
+ public bool Equals(StructureBase x, StructureBase y)
{
return x.Id.Equals(y.Id);
}
- public int GetHashCode(HeightStructure obj)
+ public int GetHashCode(StructureBase obj)
{
return obj.Id.GetHashCode();
}
@@ -94,11 +94,8 @@
{
var affectedObjects = new List();
- foreach (StructuresCalculation affectedCalculation in GetAffectedCalculationsWithHeightStructure(structure))
- {
- affectedObjects.Add(affectedCalculation.InputParameters);
- affectedObjects.AddRange(RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(affectedCalculation));
- }
+ affectedObjects.AddRange(GetAffectedCalculationsWithHeightStructure(structure)
+ .Select(c => c.InputParameters));
affectedObjects.AddRange(StructuresHelper.UpdateCalculationToSectionResultAssignments(
FailureMechanism.SectionResults,
Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs
===================================================================
diff -u -rd93d1c16b0543964ba4202f9faa7a74a6cd4a467 -r9b0d18547885c18342a9ab149538b137f0b004d0
--- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision d93d1c16b0543964ba4202f9faa7a74a6cd4a467)
+++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision 9b0d18547885c18342a9ab149538b137f0b004d0)
@@ -101,10 +101,7 @@
FileFilterGenerator = CreateHeightStructureFileFilter(),
CreateFileImporter = (context, filePath) => CreateHeightStructuresImporter(
context, filePath, new ImportMessageProvider(), new HeightStructureReplaceDataStrategy(context.FailureMechanism)),
- VerifyUpdates = context =>
- VerifyStructuresShouldUpdate(
- context.FailureMechanism,
- RingtoetsCommonIOResources.VerifyStructuresShouldUpdate_When_importing_Calculation_with_Structure_data_output_will_be_cleared_confirm)
+ VerifyUpdates = VerifyStructuresShouldUpdateOnImport
};
yield return RingtoetsImportInfoFactory.CreateCalculationConfigurationImportInfo(
@@ -129,10 +126,7 @@
CreateFileImporter = (context, filePath) => CreateHeightStructuresImporter(
context, filePath, new UpdateMessageProvider(), new HeightStructureUpdateDataStrategy(context.FailureMechanism)),
CurrentPath = context => context.WrappedData.SourcePath,
- VerifyUpdates = context =>
- VerifyStructuresShouldUpdate(
- context.FailureMechanism,
- RingtoetsCommonIOResources.VerifyStructuresShouldUpdate_When_updating_Calculation_with_Structure_data_output_will_be_cleared_confirm)
+ VerifyUpdates = VerifyStructuresShouldUpdateOnUpdate
};
}
@@ -885,6 +879,55 @@
RingtoetsCommonIOResources.Shape_file_filter_Description);
}
+ private bool VerifyStructuresShouldUpdateOnImport(HeightStructuresContext context)
+ {
+ IFailureMechanism failureMechanism = context.FailureMechanism;
+
+ bool hasStructureAndOutput = failureMechanism.Calculations
+ .Cast>()
+ .Any(c => c.InputParameters.Structure != null
+ && c.HasOutput);
+
+ return !hasStructureAndOutput
+ || VerifyStructuresShouldUpdate(
+ failureMechanism,
+ RingtoetsCommonIOResources.VerifyStructuresShouldUpdate_When_importing_Calculation_with_Structure_data_output_will_be_cleared_confirm);
+ }
+
+ ///
+ /// Class for comparing by only the id.
+ ///
+ private class StructureIdEqualityComparer : IEqualityComparer
+ {
+ public bool Equals(StructureBase x, StructureBase y)
+ {
+ return x.Id.Equals(y.Id);
+ }
+
+ public int GetHashCode(StructureBase obj)
+ {
+ return obj.Id.GetHashCode();
+ }
+ }
+
+ private bool VerifyStructuresShouldUpdateOnUpdate(HeightStructuresContext context)
+ {
+ StructureCollection heightStructures = context.WrappedData;
+ IFailureMechanism failureMechanism = context.FailureMechanism;
+ var comparer = new StructureIdEqualityComparer();
+
+ bool hasRemovedStructure = context.FailureMechanism.Calculations
+ .Cast>()
+ .Any(c => c.InputParameters.Structure != null
+ && c.HasOutput
+ && !heightStructures.Contains(c.InputParameters.Structure, comparer));
+
+ return !hasRemovedStructure
+ || VerifyStructuresShouldUpdate(
+ failureMechanism,
+ RingtoetsCommonIOResources.VerifyStructuresShouldUpdate_When_updating_Calculation_with_Structure_data_output_will_be_cleared_confirm);
+ }
+
private bool VerifyStructuresShouldUpdate(IFailureMechanism failureMechanism, string query)
{
var changeHandler = new FailureMechanismCalculationChangeHandler(failureMechanism,
Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/FileImporters/HeightStructureUpdateDataStrategyTest.cs
===================================================================
diff -u -r922d8c8ebb07e20fb0fe567d65f7d2df2bd224c1 -r9b0d18547885c18342a9ab149538b137f0b004d0
--- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/FileImporters/HeightStructureUpdateDataStrategyTest.cs (.../HeightStructureUpdateDataStrategyTest.cs) (revision 922d8c8ebb07e20fb0fe567d65f7d2df2bd224c1)
+++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/FileImporters/HeightStructureUpdateDataStrategyTest.cs (.../HeightStructureUpdateDataStrategyTest.cs) (revision 9b0d18547885c18342a9ab149538b137f0b004d0)
@@ -261,7 +261,7 @@
}
[Test]
- public void UpdateStructuresWithImportedData_CalculationWithStructureImportedStructureWithSameId_UpdatesCalculation()
+ public void UpdateStructuresWithImportedData_CalculationWithStructureImportedStructureWithSameId_UpdatesCalculationInput()
{
// Setup
const string sameId = "sameId";
@@ -302,19 +302,18 @@
sourceFilePath);
// Assert
- Assert.IsFalse(calculation.HasOutput);
+ Assert.IsTrue(calculation.HasOutput);
AssertHeightStructures(readStructure, structure);
CollectionAssert.AreEqual(new IObservable[]
{
failureMechanism.HeightStructures,
structure,
- calculation.InputParameters,
- calculation
+ calculation.InputParameters
}, affectedObjects);
}
[Test]
- public void UpdateStructuresWithImportedData_MultipleCalculationWithAssignedStructure_OnlyUpdatesCalculationWithUpdatedStructure()
+ public void UpdateStructuresWithImportedData_MultipleCalculationWithAssignedStructure_OnlyUpdatesCalculationInputWithUpdatedStructure()
{
// Setup
const string affectedId = "affectedId";
@@ -372,7 +371,7 @@
readUnaffectedStructure
}, sourceFilePath);
// Assert
- Assert.IsFalse(affectedCalculation.HasOutput);
+ Assert.IsTrue(affectedCalculation.HasOutput);
HeightStructure inputParametersAffectedStructure = affectedCalculation.InputParameters.Structure;
Assert.AreSame(affectedStructure, inputParametersAffectedStructure);
AssertHeightStructures(affectedStructure, inputParametersAffectedStructure);
@@ -385,66 +384,12 @@
CollectionAssert.AreEquivalent(new IObservable[]
{
affectedStructure,
- affectedCalculation,
affectedCalculation.InputParameters,
targetDataCollection
}, affectedObjects);
}
[Test]
- public void UpdateStructuresWithImportedData_CalculationWithSameReference_OnlyReturnsDistinctCalculation()
- {
- // Setup
- const string affectedId = "affectedId";
- var affectedStructure = new TestHeightStructure(affectedId, "Old name");
- var affectedCalculation = new TestHeightStructuresCalculation
- {
- InputParameters =
- {
- Structure = affectedStructure
- },
- Output = new TestStructuresOutput()
- };
-
- var failureMechanism = new HeightStructuresFailureMechanism
- {
- CalculationsGroup =
- {
- Children =
- {
- affectedCalculation,
- affectedCalculation
- }
- }
- };
-
- StructureCollection structures = failureMechanism.HeightStructures;
- structures.AddRange(new[]
- {
- affectedStructure
- }, sourceFilePath);
-
- var structureToUpdateFrom = new TestHeightStructure(affectedId, "New name");
-
- var strategy = new HeightStructureUpdateDataStrategy(failureMechanism);
-
- // Call
- IEnumerable affectedObjects = strategy.UpdateStructuresWithImportedData(structures,
- new[]
- {
- structureToUpdateFrom
- }, sourceFilePath);
- // Assert
- CollectionAssert.AreEquivalent(new IObservable[]
- {
- affectedStructure,
- structures,
- affectedCalculation,
- affectedCalculation.InputParameters
- }, affectedObjects);
- }
-
- [Test]
public void UpdateStructuresWithImportedData_SectionResultWithStructureImportedStructureWithSameId_UpdatesCalculation()
{
// Setup
Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/ImportInfos/HeightStructuresContextImportInfoTest.cs
===================================================================
diff -u -rbc752890b4f52991a673a59c089db400be0e6fc3 -r9b0d18547885c18342a9ab149538b137f0b004d0
--- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/ImportInfos/HeightStructuresContextImportInfoTest.cs (.../HeightStructuresContextImportInfoTest.cs) (revision bc752890b4f52991a673a59c089db400be0e6fc3)
+++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/ImportInfos/HeightStructuresContextImportInfoTest.cs (.../HeightStructuresContextImportInfoTest.cs) (revision 9b0d18547885c18342a9ab149538b137f0b004d0)
@@ -20,6 +20,7 @@
// All rights reserved.
using System;
+using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using Core.Common.Base.IO;
@@ -36,6 +37,7 @@
using Ringtoets.Common.Data.Structures;
using Ringtoets.Common.Data.TestUtil;
using Ringtoets.HeightStructures.Data;
+using Ringtoets.HeightStructures.Data.TestUtil;
using Ringtoets.HeightStructures.Forms.PresentationObjects;
using Ringtoets.HeightStructures.IO;
using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources;
@@ -45,6 +47,123 @@
[TestFixture]
public class HeightStructuresContextImportInfoTest : NUnitFormTest
{
+ private static IEnumerable CalculationsThatWhereOutputShouldNotBeRemoved
+ {
+ get
+ {
+ yield return new TestCaseData(new StructuresCalculation
+ {
+ Name = "OutputWithoutStructure",
+ Output = new TestStructuresOutput()
+ });
+
+ yield return new TestCaseData(new StructuresCalculation
+ {
+ Name = "StructureWithoutOutput",
+ InputParameters =
+ {
+ Structure = new TestHeightStructure()
+ }
+ });
+ }
+ }
+
+ private static IEnumerable CalculationsThatWhereOutputShouldBeRemoved
+ {
+ get
+ {
+ yield return new TestCaseData(
+ new StructuresCalculation
+ {
+ Name = "NoImportedStructuresAndActionConfirmed",
+ InputParameters =
+ {
+ Structure = new TestHeightStructure()
+ },
+ Output = new TestStructuresOutput()
+ }, Enumerable.Empty()
+ , true
+ );
+
+ yield return new TestCaseData(
+ new StructuresCalculation
+ {
+ Name = "NoImportedStructuresAndActionNotConfirmed",
+ InputParameters =
+ {
+ Structure = new TestHeightStructure()
+ },
+ Output = new TestStructuresOutput()
+ }, Enumerable.Empty()
+ , true
+ );
+
+ yield return new TestCaseData(
+ new StructuresCalculation
+ {
+ Name = "StructureRemovedAndActionConfirmed",
+ InputParameters =
+ {
+ Structure = new TestHeightStructure("id")
+ },
+ Output = new TestStructuresOutput()
+ }, new[]
+ {
+ new TestHeightStructure("Different id")
+ }
+ , true
+ );
+
+ yield return new TestCaseData(
+ new StructuresCalculation
+ {
+ Name = "StructureRemovedAndActionNotConfirmed",
+ InputParameters =
+ {
+ Structure = new TestHeightStructure("id")
+ },
+ Output = new TestStructuresOutput()
+ }, new[]
+ {
+ new TestHeightStructure("Different id")
+ }
+ , true
+ );
+
+ yield return new TestCaseData(
+ new StructuresCalculation
+ {
+ Name = "StructureWithSameIdAndActionConfirmed",
+ InputParameters =
+ {
+ Structure = new TestHeightStructure("id")
+ },
+ Output = new TestStructuresOutput()
+ }, new[]
+ {
+ new TestHeightStructure("id")
+ }
+ , true
+ );
+
+ yield return new TestCaseData(
+ new StructuresCalculation
+ {
+ Name = "StructureWithSameIdAndActionNotConfirmed",
+ InputParameters =
+ {
+ Structure = new TestHeightStructure("id")
+ },
+ Output = new TestStructuresOutput()
+ }, new[]
+ {
+ new TestHeightStructure("id")
+ }
+ , true
+ );
+ }
+ }
+
[Test]
public void CreateFileImporter_Always_ReturnFileImporter()
{
@@ -191,7 +310,8 @@
}
[Test]
- public void VerifyUpdates_CalculationWithoutOutputs_ReturnsTrue()
+ [TestCaseSource(nameof(CalculationsThatWhereOutputShouldNotBeRemoved))]
+ public void VerifyUpdates_CalculationWithoutOutputs_ReturnsTrue(StructuresCalculation calculation)
{
// Setup
var mocks = new MockRepository();
@@ -205,8 +325,16 @@
{
plugin.Gui = gui;
- var failureMechanism = new HeightStructuresFailureMechanism();
- failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation());
+ var failureMechanism = new HeightStructuresFailureMechanism
+ {
+ CalculationsGroup =
+ {
+ Children =
+ {
+ calculation
+ }
+ }
+ };
var structures = new StructureCollection();
var context = new HeightStructuresContext(structures, failureMechanism, assessmentSection);
@@ -223,9 +351,11 @@
}
[Test]
- [TestCase(true)]
- [TestCase(false)]
- public void VerifyUpdates_CalculationWithOutputs_AlwaysReturnsExpectedInquiryMessage(bool isActionConfirmed)
+ [TestCaseSource(nameof(CalculationsThatWhereOutputShouldBeRemoved))]
+ public void VerifyUpdates_CalculationsThatWhereOutputShouldBeRemoved_ReturnsExpectedInquiryMessage(
+ StructuresCalculation calculation,
+ IEnumerable importedStructures,
+ bool isActionConfirmed)
{
// Setup
var mocks = new MockRepository();
@@ -239,13 +369,19 @@
{
plugin.Gui = gui;
- var failureMechanism = new HeightStructuresFailureMechanism();
- failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation
+ var failureMechanism = new HeightStructuresFailureMechanism
{
- Output = new TestStructuresOutput()
- });
+ CalculationsGroup =
+ {
+ Children =
+ {
+ calculation
+ }
+ }
+ };
var structures = new StructureCollection();
+ structures.AddRange(importedStructures, "path");
var context = new HeightStructuresContext(structures, failureMechanism, assessmentSection);
ImportInfo importInfo = GetImportInfo(plugin);
Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/UpdateInfos/HeightStructuresContextUpdateInfoTest.cs
===================================================================
diff -u -rb2fa3c06d32059473875aa82186750d50740606b -r9b0d18547885c18342a9ab149538b137f0b004d0
--- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/UpdateInfos/HeightStructuresContextUpdateInfoTest.cs (.../HeightStructuresContextUpdateInfoTest.cs) (revision b2fa3c06d32059473875aa82186750d50740606b)
+++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/UpdateInfos/HeightStructuresContextUpdateInfoTest.cs (.../HeightStructuresContextUpdateInfoTest.cs) (revision 9b0d18547885c18342a9ab149538b137f0b004d0)
@@ -20,6 +20,7 @@
// All rights reserved.
using System;
+using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using Core.Common.Base.IO;
@@ -35,6 +36,7 @@
using Ringtoets.Common.Data.Structures;
using Ringtoets.Common.Data.TestUtil;
using Ringtoets.HeightStructures.Data;
+using Ringtoets.HeightStructures.Data.TestUtil;
using Ringtoets.HeightStructures.Forms.PresentationObjects;
using Ringtoets.HeightStructures.IO;
using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources;
@@ -47,6 +49,101 @@
private UpdateInfo updateInfo;
private HeightStructuresPlugin plugin;
+ private static IEnumerable CalculationsThatWhereOutputShouldBeRemoved
+ {
+ get
+ {
+ yield return new TestCaseData(
+ new StructuresCalculation
+ {
+ Name = "NoImportedStructuresAndActionConfirmed",
+ InputParameters =
+ {
+ Structure = new TestHeightStructure()
+ },
+ Output = new TestStructuresOutput()
+ }, Enumerable.Empty()
+ , true
+ );
+
+ yield return new TestCaseData(
+ new StructuresCalculation
+ {
+ Name = "NoImportedStructuresAndActionNotConfirmed",
+ InputParameters =
+ {
+ Structure = new TestHeightStructure()
+ },
+ Output = new TestStructuresOutput()
+ }, Enumerable.Empty()
+ , true
+ );
+
+ yield return new TestCaseData(
+ new StructuresCalculation
+ {
+ Name = "StructureRemovedAndActionConfirmed",
+ InputParameters =
+ {
+ Structure = new TestHeightStructure("id")
+ },
+ Output = new TestStructuresOutput()
+ }, new[]
+ {
+ new TestHeightStructure("Different id")
+ }
+ , true
+ );
+
+ yield return new TestCaseData(
+ new StructuresCalculation
+ {
+ Name = "StructureRemovedAndActionNotConfirmed",
+ InputParameters =
+ {
+ Structure = new TestHeightStructure("id")
+ },
+ Output = new TestStructuresOutput()
+ }, new[]
+ {
+ new TestHeightStructure("Different id")
+ }
+ , true
+ );
+ }
+ }
+
+ private static IEnumerable CalculationsThatWhereOutputShouldNotBeRemoved
+ {
+ get
+ {
+ yield return new TestCaseData(new StructuresCalculation
+ {
+ Name = "OutputWithoutStructure",
+ Output = new TestStructuresOutput()
+ });
+
+ yield return new TestCaseData(new StructuresCalculation
+ {
+ Name = "StructureWithoutOutput",
+ InputParameters =
+ {
+ Structure = new TestHeightStructure()
+ }
+ });
+
+ yield return new TestCaseData(new StructuresCalculation
+ {
+ Name = "OutputAndStructureWithSameId",
+ InputParameters =
+ {
+ Structure = new TestHeightStructure()
+ },
+ Output = new TestStructuresOutput()
+ });
+ }
+ }
+
[SetUp]
public void SetUp()
{
@@ -167,7 +264,9 @@
}
[Test]
- public void VerifyUpdates_CalculationWithoutOutputs_ReturnsTrue()
+ [TestCaseSource(nameof(CalculationsThatWhereOutputShouldNotBeRemoved))]
+ public void VerifyUpdates_CalculationsThatWhereOutputShouldNotBeRemoved_ReturnsTrue(
+ StructuresCalculation calculation)
{
// Setup
var mocks = new MockRepository();
@@ -179,10 +278,23 @@
plugin.Gui = gui;
- var failureMechanism = new HeightStructuresFailureMechanism();
- failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation());
+ var failureMechanism = new HeightStructuresFailureMechanism
+ {
+ CalculationsGroup =
+ {
+ Children =
+ {
+ calculation
+ }
+ }
+ };
var structures = new StructureCollection();
+ structures.AddRange(new[]
+ {
+ new TestHeightStructure()
+ }, "path");
+
var context = new HeightStructuresContext(structures, failureMechanism, assessmentSection);
// Call
@@ -194,9 +306,11 @@
}
[Test]
- [TestCase(true)]
- [TestCase(false)]
- public void VerifyUpdates_CalculationWithOutputs_AlwaysReturnsExpectedInquiryMessage(bool isActionConfirmed)
+ [TestCaseSource(nameof(CalculationsThatWhereOutputShouldBeRemoved))]
+ public void VerifyUpdates_CalculationsThatWhereOutputShouldBeRemoved_ReturnsExpectedInquiryMessage(
+ StructuresCalculation calculation,
+ IEnumerable importedStructures,
+ bool isActionConfirmed)
{
// Setup
var mocks = new MockRepository();
@@ -208,13 +322,19 @@
plugin.Gui = gui;
- var failureMechanism = new HeightStructuresFailureMechanism();
- failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation
+ var failureMechanism = new HeightStructuresFailureMechanism
{
- Output = new TestStructuresOutput()
- });
+ CalculationsGroup =
+ {
+ Children =
+ {
+ calculation
+ }
+ }
+ };
var structures = new StructureCollection();
+ structures.AddRange(importedStructures, "path");
var context = new HeightStructuresContext(structures, failureMechanism, assessmentSection);
string textBoxMessage = null;