Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs =================================================================== diff -u -rdf53f0268b7c15f000796a38436b2c40069b9b07 -r29f8839db0d355e3213456f6abf8ea7a88d44518 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision df53f0268b7c15f000796a38436b2c40069b9b07) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision 29f8839db0d355e3213456f6abf8ea7a88d44518) @@ -101,7 +101,10 @@ FileFilterGenerator = CreateHeightStructureFileFilter(), CreateFileImporter = (context, filePath) => CreateHeightStructuresImporter( context, filePath, new ImportMessageProvider(), new HeightStructureReplaceDataStrategy(context.FailureMechanism)), - VerifyUpdates = VerifyStructuresShouldUpdateOnImport + VerifyUpdates = context => + VerifyStructuresShouldUpdate( + context.FailureMechanism, + RingtoetsCommonIOResources.VerifyStructuresShouldUpdate_When_importing_Calculation_with_Structure_data_output_will_be_cleared_confirm) }; yield return RingtoetsImportInfoFactory.CreateCalculationConfigurationImportInfo( @@ -126,7 +129,10 @@ CreateFileImporter = (context, filePath) => CreateHeightStructuresImporter( context, filePath, new UpdateMessageProvider(), new HeightStructureUpdateDataStrategy(context.FailureMechanism)), CurrentPath = context => context.WrappedData.SourcePath, - VerifyUpdates = VerifyStructuresShouldUpdateOnUpdate + VerifyUpdates = context => + VerifyStructuresShouldUpdate( + context.FailureMechanism, + RingtoetsCommonIOResources.VerifyStructuresShouldUpdate_When_updating_Calculation_with_Structure_data_output_will_be_cleared_confirm) }; } @@ -879,39 +885,6 @@ 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); - } - - 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/ImportInfos/HeightStructuresContextImportInfoTest.cs =================================================================== diff -u -r2d6ee27d724d879326635b641904ce2e25097aa9 -r29f8839db0d355e3213456f6abf8ea7a88d44518 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/ImportInfos/HeightStructuresContextImportInfoTest.cs (.../HeightStructuresContextImportInfoTest.cs) (revision 2d6ee27d724d879326635b641904ce2e25097aa9) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/ImportInfos/HeightStructuresContextImportInfoTest.cs (.../HeightStructuresContextImportInfoTest.cs) (revision 29f8839db0d355e3213456f6abf8ea7a88d44518) @@ -20,7 +20,6 @@ // All rights reserved. using System; -using System.Collections.Generic; using System.Drawing; using System.Linq; using Core.Common.Base.IO; @@ -37,7 +36,6 @@ 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,123 +45,6 @@ [TestFixture] public class HeightStructuresContextImportInfoTest : NUnitFormTest { - private static IEnumerable CalculationsWhereOutputShouldNotBeRemoved - { - 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 CalculationsWhereOutputShouldBeRemoved - { - 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() { @@ -310,8 +191,7 @@ } [Test] - [TestCaseSource(nameof(CalculationsWhereOutputShouldNotBeRemoved))] - public void VerifyUpdates_CalculationsWhereOutputShouldNotBeRemoved_ReturnsTrue(StructuresCalculation calculation) + public void VerifyUpdates_CalculationWithoutOutputs_ReturnsTrue() { // Setup var mocks = new MockRepository(); @@ -325,16 +205,8 @@ { plugin.Gui = gui; - var failureMechanism = new HeightStructuresFailureMechanism - { - CalculationsGroup = - { - Children = - { - calculation - } - } - }; + var failureMechanism = new HeightStructuresFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation()); var structures = new StructureCollection(); var context = new HeightStructuresContext(structures, failureMechanism, assessmentSection); @@ -351,11 +223,9 @@ } [Test] - [TestCaseSource(nameof(CalculationsWhereOutputShouldBeRemoved))] - public void VerifyUpdates_CalculationsWhereOutputShouldBeRemoved_ReturnsExpectedInquiryMessage( - StructuresCalculation calculation, - IEnumerable importedStructures, - bool isActionConfirmed) + [TestCase(true)] + [TestCase(false)] + public void VerifyUpdates_CalculationWithOutputs_AlwaysReturnsExpectedInquiryMessage(bool isActionConfirmed) { // Setup var mocks = new MockRepository(); @@ -369,19 +239,13 @@ { plugin.Gui = gui; - var failureMechanism = new HeightStructuresFailureMechanism + var failureMechanism = new HeightStructuresFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation { - CalculationsGroup = - { - Children = - { - calculation - } - } - }; + Output = new TestStructuresOutput() + }); 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 -r2d6ee27d724d879326635b641904ce2e25097aa9 -r29f8839db0d355e3213456f6abf8ea7a88d44518 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/UpdateInfos/HeightStructuresContextUpdateInfoTest.cs (.../HeightStructuresContextUpdateInfoTest.cs) (revision 2d6ee27d724d879326635b641904ce2e25097aa9) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/UpdateInfos/HeightStructuresContextUpdateInfoTest.cs (.../HeightStructuresContextUpdateInfoTest.cs) (revision 29f8839db0d355e3213456f6abf8ea7a88d44518) @@ -20,7 +20,6 @@ // All rights reserved. using System; -using System.Collections.Generic; using System.Drawing; using System.Linq; using Core.Common.Base.IO; @@ -36,7 +35,6 @@ 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; @@ -49,101 +47,6 @@ private UpdateInfo updateInfo; private HeightStructuresPlugin plugin; - private static IEnumerable CalculationsWhereOutputShouldBeRemoved - { - 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 CalculationsWhereOutputShouldNotBeRemoved - { - 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() { @@ -264,9 +167,7 @@ } [Test] - [TestCaseSource(nameof(CalculationsWhereOutputShouldNotBeRemoved))] - public void VerifyUpdates_CalculationsWhereOutputShouldNotBeRemoved_ReturnsTrue( - StructuresCalculation calculation) + public void VerifyUpdates_CalculationWithoutOutputs_ReturnsTrue() { // Setup var mocks = new MockRepository(); @@ -278,23 +179,10 @@ plugin.Gui = gui; - var failureMechanism = new HeightStructuresFailureMechanism - { - CalculationsGroup = - { - Children = - { - calculation - } - } - }; + var failureMechanism = new HeightStructuresFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation()); var structures = new StructureCollection(); - structures.AddRange(new[] - { - new TestHeightStructure() - }, "path"); - var context = new HeightStructuresContext(structures, failureMechanism, assessmentSection); // Call @@ -306,11 +194,9 @@ } [Test] - [TestCaseSource(nameof(CalculationsWhereOutputShouldBeRemoved))] - public void VerifyUpdates_CalculationsWhereOutputShouldBeRemoved_ReturnsExpectedInquiryMessage( - StructuresCalculation calculation, - IEnumerable importedStructures, - bool isActionConfirmed) + [TestCase(true)] + [TestCase(false)] + public void VerifyUpdates_CalculationWithOutputs_AlwaysReturnsExpectedInquiryMessage(bool isActionConfirmed) { // Setup var mocks = new MockRepository(); @@ -322,19 +208,13 @@ plugin.Gui = gui; - var failureMechanism = new HeightStructuresFailureMechanism + var failureMechanism = new HeightStructuresFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation { - CalculationsGroup = - { - Children = - { - calculation - } - } - }; + Output = new TestStructuresOutput() + }); var structures = new StructureCollection(); - structures.AddRange(importedStructures, "path"); var context = new HeightStructuresContext(structures, failureMechanism, assessmentSection); string textBoxMessage = null;