Index: Ringtoets/Integration/src/Ringtoets.Integration.IO/Factories/ExportableAssessmentSectionFactory.cs =================================================================== diff -u -r1c901589bffe379b7fa408fab2777ab04578e18e -r6056937ae2b62d8d74261b245888702f00b69747 --- Ringtoets/Integration/src/Ringtoets.Integration.IO/Factories/ExportableAssessmentSectionFactory.cs (.../ExportableAssessmentSectionFactory.cs) (revision 1c901589bffe379b7fa408fab2777ab04578e18e) +++ Ringtoets/Integration/src/Ringtoets.Integration.IO/Factories/ExportableAssessmentSectionFactory.cs (.../ExportableAssessmentSectionFactory.cs) (revision 6056937ae2b62d8d74261b245888702f00b69747) @@ -74,7 +74,8 @@ ExportablePipingFailureMechanismFactory.CreateExportablePipingFailureMechanism(assessmentSection.Piping, assessmentSection), ExportableMacroStabilityInwardsFailureMechanismFactory.CreateExportableMacroStabilityInwardsFailureMechanism(assessmentSection.MacroStabilityInwards, assessmentSection), ExportableGrassCoverErosionInwardsFailureMechanismFactory.CreateExportableGrassCoverErosionInwardsFailureMechanism(assessmentSection.GrassCoverErosionInwards, assessmentSection), - ExportableHeightStructuresFailureMechanismFactory.CreateExportableHeightStructuresFailureMechanism(assessmentSection.HeightStructures, assessmentSection) + ExportableHeightStructuresFailureMechanismFactory.CreateExportableHeightStructuresFailureMechanism(assessmentSection.HeightStructures, assessmentSection), + ExportableClosingStructuresFailureMechanismFactory.CreateExportableClosingStructuresFailureMechanism(assessmentSection.ClosingStructures, assessmentSection) }; } } Index: Ringtoets/Integration/src/Ringtoets.Integration.IO/Factories/ExportableClosingStructuresFailureMechanismFactory.cs =================================================================== diff -u --- Ringtoets/Integration/src/Ringtoets.Integration.IO/Factories/ExportableClosingStructuresFailureMechanismFactory.cs (revision 0) +++ Ringtoets/Integration/src/Ringtoets.Integration.IO/Factories/ExportableClosingStructuresFailureMechanismFactory.cs (revision 6056937ae2b62d8d74261b245888702f00b69747) @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Ringtoets.AssemblyTool.Data; +using Ringtoets.ClosingStructures.Data; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Exceptions; +using Ringtoets.Integration.IO.Assembly; + +namespace Ringtoets.Integration.IO.Factories +{ + /// + /// Factory to create instances of + /// with assembly results for closing structures. + /// + public static class ExportableClosingStructuresFailureMechanismFactory + { + private const ExportableFailureMechanismType failureMechanismCode = ExportableFailureMechanismType.BSKW; + private const ExportableFailureMechanismGroup failureMechanismGroup = ExportableFailureMechanismGroup.Group1; + private const ExportableAssemblyMethod failureMechanismAssemblyMethod = ExportableAssemblyMethod.WBI1B1; + + /// + /// Creates a + /// with assmebly results based on the input parameters. + /// + /// The to create a + /// for. + /// The assessment section this failure mechanism belongs to. + /// A with assembly results. + /// Thrown when any parameter is null. + /// Thrown when assembly results cannot be created. + public static ExportableFailureMechanism CreateExportableClosingStructuresFailureMechanism( + ClosingStructuresFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + if (!failureMechanism.IsRelevant) + { + return ExportableFailureMechanismFactory.CreateDefaultExportableFailureMechanismWithProbability(failureMechanismCode, + failureMechanismGroup, + failureMechanismAssemblyMethod); + } + + FailureMechanismAssembly failureMechanismAssembly = ClosingStructuresFailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism, assessmentSection); + + Dictionary failureMechanismSectionsLookup = + failureMechanism.SectionResults + .ToDictionary(sectionResult => sectionResult, + sectionResult => ExportableFailureMechanismSectionFactory.CreateExportableFailureMechanismSection(sectionResult.Section)); + + return new ExportableFailureMechanism( + new ExportableFailureMechanismAssemblyResultWithProbability(failureMechanismAssemblyMethod, + failureMechanismAssembly.Group, + failureMechanismAssembly.Probability), + failureMechanismSectionsLookup.Values, CreateExportablePipingFailureMechanismSectionResults(failureMechanismSectionsLookup, + failureMechanism, + assessmentSection), + failureMechanismCode, + failureMechanismGroup); + } + + /// + /// Creates a collection of + /// with assembly results based on the sections in . + /// + /// The mapping between the + /// and . + /// The the sections belong to. + /// The assessment section the sections belong to. + /// A collection of . + /// Thrown when assembly results cannot be created. + private static IEnumerable CreateExportablePipingFailureMechanismSectionResults( + Dictionary failureMechanismSections, + ClosingStructuresFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) + { + var exportableResults = new List(); + foreach (KeyValuePair failureMechanismSectionPair in failureMechanismSections) + { + ClosingStructuresFailureMechanismSectionResult failureMechanismSectionResult = failureMechanismSectionPair.Key; + FailureMechanismSectionAssembly simpleAssembly = + ClosingStructuresFailureMechanismAssemblyFactory.AssembleSimpleAssessment(failureMechanismSectionResult); + + FailureMechanismSectionAssembly detailedAssembly = + ClosingStructuresFailureMechanismAssemblyFactory.AssembleDetailedAssessment(failureMechanismSectionResult, + failureMechanism, + assessmentSection); + FailureMechanismSectionAssembly tailorMadeAssembly = + ClosingStructuresFailureMechanismAssemblyFactory.AssembleTailorMadeAssessment(failureMechanismSectionResult, + failureMechanism, + assessmentSection); + FailureMechanismSectionAssembly combinedAssembly = + ClosingStructuresFailureMechanismAssemblyFactory.AssembleCombinedAssessment(failureMechanismSectionResult, + failureMechanism, + assessmentSection); + + exportableResults.Add( + new ExportableAggregatedFailureMechanismSectionAssemblyResultWithProbability( + failureMechanismSectionPair.Value, + ExportableSectionAssemblyResultFactory.CreateExportableSectionAssemblyResultWithProbability(simpleAssembly, ExportableAssemblyMethod.WBI0E1), + ExportableSectionAssemblyResultFactory.CreateExportableSectionAssemblyResultWithProbability(detailedAssembly, ExportableAssemblyMethod.WBI0G3), + ExportableSectionAssemblyResultFactory.CreateExportableSectionAssemblyResultWithProbability(tailorMadeAssembly, ExportableAssemblyMethod.WBI0T3), + ExportableSectionAssemblyResultFactory.CreateExportableSectionAssemblyResultWithProbability(combinedAssembly, ExportableAssemblyMethod.WBI0A1))); + } + + return exportableResults; + } + } +} \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.IO/Ringtoets.Integration.IO.csproj =================================================================== diff -u -r1c901589bffe379b7fa408fab2777ab04578e18e -r6056937ae2b62d8d74261b245888702f00b69747 --- Ringtoets/Integration/src/Ringtoets.Integration.IO/Ringtoets.Integration.IO.csproj (.../Ringtoets.Integration.IO.csproj) (revision 1c901589bffe379b7fa408fab2777ab04578e18e) +++ Ringtoets/Integration/src/Ringtoets.Integration.IO/Ringtoets.Integration.IO.csproj (.../Ringtoets.Integration.IO.csproj) (revision 6056937ae2b62d8d74261b245888702f00b69747) @@ -37,6 +37,7 @@ + @@ -89,6 +90,11 @@ Ringtoets.AssemblyTool.KernelWrapper False + + {c6309704-d67b-434c-bc98-9f8910bc1d10} + Ringtoets.ClosingStructures.Data + False + {D4200F43-3F72-4F42-AF0A-8CED416A38EC} Ringtoets.Common.Data Index: Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Factories/ExportableAssessmentSectionFactoryTest.cs =================================================================== diff -u -rafd3fc3d57bb7568d0232d9be934602b79c37aa2 -r6056937ae2b62d8d74261b245888702f00b69747 --- Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Factories/ExportableAssessmentSectionFactoryTest.cs (.../ExportableAssessmentSectionFactoryTest.cs) (revision afd3fc3d57bb7568d0232d9be934602b79c37aa2) +++ Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Factories/ExportableAssessmentSectionFactoryTest.cs (.../ExportableAssessmentSectionFactoryTest.cs) (revision 6056937ae2b62d8d74261b245888702f00b69747) @@ -7,6 +7,7 @@ using Ringtoets.AssemblyTool.KernelWrapper.Calculators; using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators; using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators.Assembly; +using Ringtoets.ClosingStructures.Data; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.TestUtil; using Ringtoets.GrassCoverErosionInwards.Data; @@ -55,6 +56,9 @@ FailureMechanismTestHelper.AddSections(assessmentSection.Piping, random.Next(1, 10)); FailureMechanismTestHelper.AddSections(assessmentSection.MacroStabilityInwards, random.Next(1, 10)); + FailureMechanismTestHelper.AddSections(assessmentSection.GrassCoverErosionInwards, random.Next(1, 10)); + FailureMechanismTestHelper.AddSections(assessmentSection.HeightStructures, random.Next(1, 10)); + FailureMechanismTestHelper.AddSections(assessmentSection.ClosingStructures, random.Next(1, 10)); using (new AssemblyToolCalculatorFactoryConfig()) { @@ -73,7 +77,7 @@ Assert.AreEqual(assessmentSectionAssemblyCalculator.AssembleAssessmentSectionCategoryGroupOutput, exportableAssessmentSectionAssemblyResult.AssemblyCategory); Assert.AreEqual(ExportableAssemblyMethod.WBI2C1, exportableAssessmentSectionAssemblyResult.AssemblyMethod); - AssertExportableFailureMechanismsWithProbability(exportableAssessmentSection.FailureMechanismsWithProbability, + AssertExportableFailureMechanismsWithProbability(exportableAssessmentSection.FailureMechanismsWithProbability, failureMechanismAssemblyCalculator, assessmentSection); @@ -87,9 +91,8 @@ FailureMechanismAssemblyCalculatorStub failureMechanismAssemblyCalculator, AssessmentSection assessmentSection) { - Assert.AreEqual(4, exportableFailureMechanisms.Count()); + Assert.AreEqual(5, exportableFailureMechanisms.Count()); - ExportableFailureMechanism exportablePiping = exportableFailureMechanisms.First(); Assert.AreEqual(failureMechanismAssemblyCalculator.FailureMechanismAssemblyOutput.Group, exportablePiping.FailureMechanismAssembly.AssemblyCategory); Assert.AreEqual(failureMechanismAssemblyCalculator.FailureMechanismAssemblyOutput.Probability, exportablePiping.FailureMechanismAssembly.Probability); @@ -125,6 +128,15 @@ HeightStructuresFailureMechanism heightStructures = assessmentSection.HeightStructures; Assert.AreEqual(heightStructures.Sections.Count(), heightStructures.Sections.Count()); Assert.AreEqual(heightStructures.SectionResults.Count(), exportableHeightStructures.SectionAssemblyResults.Count()); + + ExportableFailureMechanism exportableClosingStructures = exportableFailureMechanisms.ElementAt(4); + Assert.AreEqual(failureMechanismAssemblyCalculator.FailureMechanismAssemblyOutput.Group, exportableClosingStructures.FailureMechanismAssembly.AssemblyCategory); + Assert.AreEqual(failureMechanismAssemblyCalculator.FailureMechanismAssemblyOutput.Probability, exportableClosingStructures.FailureMechanismAssembly.Probability); + Assert.AreEqual(ExportableFailureMechanismType.BSKW, exportableClosingStructures.Code); + Assert.AreEqual(ExportableFailureMechanismGroup.Group1, exportableClosingStructures.Group); + ClosingStructuresFailureMechanism closingStructures = assessmentSection.ClosingStructures; + Assert.AreEqual(closingStructures.Sections.Count(), closingStructures.Sections.Count()); + Assert.AreEqual(closingStructures.SectionResults.Count(), exportableClosingStructures.SectionAssemblyResults.Count()); } } } \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Factories/ExportableClosingStructuresFailureMechanismFactoryTest.cs =================================================================== diff -u --- Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Factories/ExportableClosingStructuresFailureMechanismFactoryTest.cs (revision 0) +++ Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Factories/ExportableClosingStructuresFailureMechanismFactoryTest.cs (revision 6056937ae2b62d8d74261b245888702f00b69747) @@ -0,0 +1,175 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.AssemblyTool.Data; +using Ringtoets.AssemblyTool.KernelWrapper.Calculators; +using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators; +using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators.Assembly; +using Ringtoets.ClosingStructures.Data; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Integration.IO.Assembly; +using Ringtoets.Integration.IO.Factories; +using Ringtoets.Integration.IO.TestUtil; + +namespace Ringtoets.Integration.IO.Test.Factories +{ + [TestFixture] + public class ExportableClosingStructuresFailureMechanismFactoryTest + { + [Test] + public void CreateExportableClosingStructuresFailureMechanism_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => + ExportableClosingStructuresFailureMechanismFactory.CreateExportableClosingStructuresFailureMechanism(null, + assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + + mocks.VerifyAll(); + } + + [Test] + public void CreateExportableClosingStructuresFailureMechanism_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => + ExportableClosingStructuresFailureMechanismFactory.CreateExportableClosingStructuresFailureMechanism(new ClosingStructuresFailureMechanism(), + null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void CreateExportableClosingStructuresFailureMechanism_WithFailureMechanismNotRelevant_ReturnsDefaultExportableFailureMechanism() + { + // Setup + var random = new Random(21); + var failureMechanism = new ClosingStructuresFailureMechanism + { + IsRelevant = false + }; + FailureMechanismTestHelper.AddSections(failureMechanism, random.Next(2, 10)); + + var assessmentSection = new AssessmentSectionStub(); + + // Call + ExportableFailureMechanism exportableFailureMechanism = + ExportableClosingStructuresFailureMechanismFactory.CreateExportableClosingStructuresFailureMechanism(failureMechanism, assessmentSection); + + // Assert + Assert.AreEqual(ExportableFailureMechanismType.BSKW, exportableFailureMechanism.Code); + Assert.AreEqual(ExportableFailureMechanismGroup.Group1, exportableFailureMechanism.Group); + + ExportableFailureMechanismAssemblyResultWithProbability failureMechanismAssemblyResult = exportableFailureMechanism.FailureMechanismAssembly; + Assert.AreEqual(ExportableAssemblyMethod.WBI1B1, failureMechanismAssemblyResult.AssemblyMethod); + Assert.AreEqual(FailureMechanismAssemblyCategoryGroup.NotApplicable, failureMechanismAssemblyResult.AssemblyCategory); + Assert.AreEqual(0, failureMechanismAssemblyResult.Probability); + + CollectionAssert.IsEmpty(exportableFailureMechanism.Sections); + CollectionAssert.IsEmpty(exportableFailureMechanism.SectionAssemblyResults); + } + + [Test] + public void CreateExportableClosingStructuresFailureMechanism_WithFailureMechanismRelevant_ReturnsExportableFailureMechanism() + { + // Setup + var random = new Random(21); + var failureMechanism = new ClosingStructuresFailureMechanism(); + FailureMechanismTestHelper.AddSections(failureMechanism, random.Next(2, 10)); + + var assessmentSection = new AssessmentSectionStub(); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismAssemblyCalculatorStub failureMechanismAssemblyCalculator = calculatorfactory.LastCreatedFailureMechanismAssemblyCalculator; + FailureMechanismSectionAssemblyCalculatorStub failureMechanismSectionAssemblyCalculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + // Call + ExportableFailureMechanism exportableFailureMechanism = + ExportableClosingStructuresFailureMechanismFactory.CreateExportableClosingStructuresFailureMechanism(failureMechanism, assessmentSection); + + // Assert + Assert.AreEqual(ExportableFailureMechanismType.BSKW, exportableFailureMechanism.Code); + Assert.AreEqual(ExportableFailureMechanismGroup.Group1, exportableFailureMechanism.Group); + + FailureMechanismAssembly calculatorOutput = failureMechanismAssemblyCalculator.FailureMechanismAssemblyOutput; + ExportableFailureMechanismAssemblyResultWithProbability exportableFailureMechanismAssembly = exportableFailureMechanism.FailureMechanismAssembly; + Assert.AreEqual(calculatorOutput.Group, exportableFailureMechanismAssembly.AssemblyCategory); + Assert.AreEqual(calculatorOutput.Probability, exportableFailureMechanismAssembly.Probability); + Assert.AreEqual(ExportableAssemblyMethod.WBI1B1, exportableFailureMechanismAssembly.AssemblyMethod); + + ExportableFailureMechanismSectionTestHelper.AssertExportableFailureMechanismSections(failureMechanism.Sections, exportableFailureMechanism.Sections); + AssertExportableFailureMechanismSectionResults(failureMechanismSectionAssemblyCalculator.SimpleAssessmentAssemblyOutput, + failureMechanismSectionAssemblyCalculator.DetailedAssessmentAssemblyOutput, + failureMechanismSectionAssemblyCalculator.TailorMadeAssessmentAssemblyOutput, + failureMechanismSectionAssemblyCalculator.CombinedAssemblyOutput, + exportableFailureMechanism.Sections, + exportableFailureMechanism.SectionAssemblyResults.Cast()); + } + } + + private static void AssertExportableFailureMechanismSectionResults(FailureMechanismSectionAssembly expectedSimpleAssembly, + FailureMechanismSectionAssembly expectedDetailedAssembly, + FailureMechanismSectionAssembly expectedTailorMadeAssembly, + FailureMechanismSectionAssembly expectedCombinedAssembly, + IEnumerable sections, + IEnumerable results) + { + int expectedNrOfResults = sections.Count(); + Assert.AreEqual(expectedNrOfResults, results.Count()); + + for (var i = 0; i < expectedNrOfResults; i++) + { + ExportableFailureMechanismSection section = sections.ElementAt(i); + ExportableAggregatedFailureMechanismSectionAssemblyResultWithProbability result = results.ElementAt(i); + + AssertExportableFailureMechanismSectionResult(expectedSimpleAssembly, + expectedDetailedAssembly, + expectedTailorMadeAssembly, + expectedCombinedAssembly, + section, + result); + } + } + + private static void AssertExportableFailureMechanismSectionResult(FailureMechanismSectionAssembly expectedSimpleAssembly, + FailureMechanismSectionAssembly expectedDetailedAssembly, + FailureMechanismSectionAssembly expectedTailorMadeAssembly, + FailureMechanismSectionAssembly expectedCombinedAssembly, + ExportableFailureMechanismSection expectedSection, + ExportableAggregatedFailureMechanismSectionAssemblyResultWithProbability actualResult) + { + Assert.AreSame(expectedSection, actualResult.FailureMechanismSection); + + ExportableSectionAssemblyResultTestHelper.AssertExportableSectionAssemblyResult(expectedSimpleAssembly, + ExportableAssemblyMethod.WBI0E1, + actualResult.SimpleAssembly); + + ExportableSectionAssemblyResultTestHelper.AssertExportableSectionAssemblyResult(expectedDetailedAssembly, + ExportableAssemblyMethod.WBI0G3, + actualResult.DetailedAssembly); + + ExportableSectionAssemblyResultTestHelper.AssertExportableSectionAssemblyResult(expectedTailorMadeAssembly, + ExportableAssemblyMethod.WBI0T3, + actualResult.TailorMadeAssembly); + + ExportableSectionAssemblyResultTestHelper.AssertExportableSectionAssemblyResult(expectedCombinedAssembly, + ExportableAssemblyMethod.WBI0A1, + actualResult.CombinedAssembly); + } + } +} \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Ringtoets.Integration.IO.Test.csproj =================================================================== diff -u -r1c901589bffe379b7fa408fab2777ab04578e18e -r6056937ae2b62d8d74261b245888702f00b69747 --- Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Ringtoets.Integration.IO.Test.csproj (.../Ringtoets.Integration.IO.Test.csproj) (revision 1c901589bffe379b7fa408fab2777ab04578e18e) +++ Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Ringtoets.Integration.IO.Test.csproj (.../Ringtoets.Integration.IO.Test.csproj) (revision 6056937ae2b62d8d74261b245888702f00b69747) @@ -39,6 +39,7 @@ + @@ -75,6 +76,10 @@ {0AB432BB-E2CC-42EA-A72C-7AFEF7536B38} Ringtoets.AssemblyTool.KernelWrapper.TestUtil + + {C6309704-D67B-434C-BC98-9F8910BC1D10} + Ringtoets.ClosingStructures.Data + {D4200F43-3F72-4F42-AF0A-8CED416A38EC} Ringtoets.Common.Data