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);