Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/Configurations/HeightStructuresCalculationConfigurationImporterTest.cs =================================================================== diff -u -r4bf59bb3506b840b284efe0c0f4431b7876e0e5b -rf4c28926da2401b1fddbbe7f907fd663f0f5f4dc --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/Configurations/HeightStructuresCalculationConfigurationImporterTest.cs (.../HeightStructuresCalculationConfigurationImporterTest.cs) (revision 4bf59bb3506b840b284efe0c0f4431b7876e0e5b) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/Configurations/HeightStructuresCalculationConfigurationImporterTest.cs (.../HeightStructuresCalculationConfigurationImporterTest.cs) (revision f4c28926da2401b1fddbbe7f907fd663f0f5f4dc) @@ -29,6 +29,7 @@ using NUnit.Framework; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Data.TestUtil; @@ -159,7 +160,8 @@ new CalculationGroup(), Enumerable.Empty(), Enumerable.Empty(), - Enumerable.Empty()); + Enumerable.Empty(), + new HeightStructuresFailureMechanism()); // Assert Assert.IsInstanceOf>(importer); @@ -173,7 +175,8 @@ new CalculationGroup(), null, Enumerable.Empty(), - Enumerable.Empty()); + Enumerable.Empty(), + new HeightStructuresFailureMechanism()); // Assert var exception = Assert.Throws(test); @@ -188,7 +191,8 @@ new CalculationGroup(), Enumerable.Empty(), null, - Enumerable.Empty()); + Enumerable.Empty(), + new HeightStructuresFailureMechanism()); // Assert var exception = Assert.Throws(test); @@ -203,14 +207,31 @@ new CalculationGroup(), Enumerable.Empty(), Enumerable.Empty(), - null); + null, + new HeightStructuresFailureMechanism()); // Assert var exception = Assert.Throws(test); Assert.AreEqual("structures", exception.ParamName); } [Test] + public void Constructor_FailureMechanismNull_ThrowArgumentNullException() + { + // Call + TestDelegate test = () => new HeightStructuresCalculationConfigurationImporter("", + new CalculationGroup(), + Enumerable.Empty(), + Enumerable.Empty(), + Enumerable.Empty(), + null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] [SetCulture("nl-NL")] [TestCaseSource(nameof(ValidConfigurationInvalidData))] public void Import_ValidConfigurationInvalidData_LogMessageAndContinueImport(string file, string expectedErrorMessage) @@ -232,7 +253,8 @@ new HeightStructure[] { structure - }); + }, + new HeightStructuresFailureMechanism()); var successful = false; // Call @@ -261,7 +283,8 @@ { foreshoreProfile }, - Enumerable.Empty()); + Enumerable.Empty(), + new HeightStructuresFailureMechanism()); var successful = false; @@ -302,7 +325,8 @@ new[] { structure - }); + }, + new HeightStructuresFailureMechanism()); // Call bool successful = importer.Import(); @@ -387,7 +411,8 @@ new[] { structure - }); + }, + new HeightStructuresFailureMechanism()); var expectedCalculation = new StructuresCalculation { @@ -455,7 +480,8 @@ new[] { structure - }); + }, + new HeightStructuresFailureMechanism()); var expectedCalculation = new StructuresCalculation { @@ -519,7 +545,8 @@ new[] { structure - }); + }, + new HeightStructuresFailureMechanism()); var expectedCalculation = new StructuresCalculation { @@ -552,7 +579,8 @@ calculationGroup, Enumerable.Empty(), Enumerable.Empty(), - Enumerable.Empty()); + Enumerable.Empty(), + new HeightStructuresFailureMechanism()); var successful = false; // Call @@ -565,6 +593,50 @@ CollectionAssert.IsEmpty(calculationGroup.Children); } + [Test] + public void DoPostImport_WithNewSectionResults_AssignsCalculationToSectionResult() + { + // Setup + string filePath = Path.Combine(importerPath, "validConfigurationFullCalculation.xml"); + var calculationGroup = new CalculationGroup(); + + var failureMechanism = new HeightStructuresFailureMechanism(); + + failureMechanism.AddSection(new FailureMechanismSection("name", new[] + { + new Point2D(0, 0), + new Point2D(10, 10) + })); + + var calculation = new StructuresCalculation + { + InputParameters = + { + Structure = new TestHeightStructure(new Point2D(5, 5)) + } + }; + failureMechanism.CalculationsGroup.Children.Add( + calculation); + + var importer = new HeightStructuresCalculationConfigurationImporter( + filePath, + calculationGroup, + Enumerable.Empty(), + Enumerable.Empty(), + Enumerable.Empty(), + failureMechanism); + + // Preconditions + Assert.AreEqual(1, failureMechanism.SectionResults.Count()); + Assert.IsNull(failureMechanism.SectionResults.ElementAt(0).Calculation); + + // Call + importer.DoPostImport(); + + // Assert + Assert.AreSame(calculation, failureMechanism.SectionResults.ElementAt(0).Calculation); + } + private static void AssertCalculation(StructuresCalculation expectedCalculation, StructuresCalculation actualCalculation) { Assert.AreEqual(expectedCalculation.Name, actualCalculation.Name);