Index: Ringtoets/Integration/src/Ringtoets.Integration.IO/Factories/ExportableMacroStabilityInwardsFailureMechanismFactory.cs =================================================================== diff -u --- Ringtoets/Integration/src/Ringtoets.Integration.IO/Factories/ExportableMacroStabilityInwardsFailureMechanismFactory.cs (revision 0) +++ Ringtoets/Integration/src/Ringtoets.Integration.IO/Factories/ExportableMacroStabilityInwardsFailureMechanismFactory.cs (revision a2ea180503092e239c6919517c536ce1d30db295) @@ -0,0 +1,122 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Ringtoets.AssemblyTool.Data; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Exceptions; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Integration.IO.Assembly; +using Ringtoets.MacroStabilityInwards.Data; + +namespace Ringtoets.Integration.IO.Factories +{ + /// + /// Factory to create instances of + /// with assembly results for macro stability inwards. + /// + public static class ExportableMacroStabilityInwardsFailureMechanismFactory + { + /// + /// Creates a + /// with assmebly results based on the input parameters. + /// + /// The MmcroStabilityInwards failure mechanism 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 CreateExportableMacroStabilityInwardsFailureMechanism( + MacroStabilityInwardsFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + FailureMechanismAssembly failureMechanismAssembly = MacroStabilityInwardsFailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism, assessmentSection); + + Dictionary failureMechanismSectionsLookup = + failureMechanism.SectionResults + .ToDictionary(s => s, sectionResult => CreateExportableFailureMechanismSection(sectionResult.Section)); + + return new ExportableFailureMechanism( + new ExportableFailureMechanismAssemblyResultWithProbability(ExportableAssemblyMethod.WBI1B1, + failureMechanismAssembly.Group, + failureMechanismAssembly.Probability), + failureMechanismSectionsLookup.Values, CreateExportableMacroStabilityInwardsFailureMechanismSectionResults(failureMechanismSectionsLookup, + failureMechanism, assessmentSection), + ExportableFailureMechanismType.STBI, + ExportableFailureMechanismGroup.Group2); + } + + /// + /// Creates a collection of + /// with assembly results based on the sections in . + /// + /// The mapping between the + /// and + /// The MacroStabilityInwards failure mechanism the sections belong to. + /// The assessment section the sections belong to. + /// A collection of . + /// Thrown when assembly results cannot be created. + private static IEnumerable CreateExportableMacroStabilityInwardsFailureMechanismSectionResults( + Dictionary failureMechanismSections, + MacroStabilityInwardsFailureMechanism macroStabilityInwardsFailureMechanism, + IAssessmentSection assessmentSection) + { + IEnumerable macroStabilityInwardsCalculationScenarios = + macroStabilityInwardsFailureMechanism.Calculations.Cast(); + + var exportableResults = new List(); + foreach (KeyValuePair failureMechanismSectionPair in failureMechanismSections) + { + MacroStabilityInwardsFailureMechanismSectionResult failureMechanismSectionResult = failureMechanismSectionPair.Key; + FailureMechanismSectionAssembly simpleAssembly = + MacroStabilityInwardsFailureMechanismAssemblyFactory.AssembleSimpleAssessment(failureMechanismSectionResult); + + FailureMechanismSectionAssembly detailedAssembly = + MacroStabilityInwardsFailureMechanismAssemblyFactory.AssembleDetailedAssessment(failureMechanismSectionResult, + macroStabilityInwardsCalculationScenarios, + macroStabilityInwardsFailureMechanism, + assessmentSection); + FailureMechanismSectionAssembly tailorMadeAssembly = + MacroStabilityInwardsFailureMechanismAssemblyFactory.AssembleTailorMadeAssessment(failureMechanismSectionResult, + macroStabilityInwardsFailureMechanism, + assessmentSection); + FailureMechanismSectionAssembly combinedAssembly = + MacroStabilityInwardsFailureMechanismAssemblyFactory.AssembleCombinedAssessment(failureMechanismSectionResult, + macroStabilityInwardsCalculationScenarios, + macroStabilityInwardsFailureMechanism, + assessmentSection); + + exportableResults.Add( + new ExportableAggregatedFailureMechanismSectionAssemblyResultWithProbability( + failureMechanismSectionPair.Value, + CreateExportableSectionAssemblyResultWithProbability(simpleAssembly, ExportableAssemblyMethod.WBI0E1), + CreateExportableSectionAssemblyResultWithProbability(detailedAssembly, ExportableAssemblyMethod.WBI0G5), + CreateExportableSectionAssemblyResultWithProbability(tailorMadeAssembly, ExportableAssemblyMethod.WBI0T5), + CreateExportableSectionAssemblyResultWithProbability(combinedAssembly, ExportableAssemblyMethod.WBI1B1))); + } + + return exportableResults; + } + + private static ExportableSectionAssemblyResultWithProbability CreateExportableSectionAssemblyResultWithProbability(FailureMechanismSectionAssembly assembly, + ExportableAssemblyMethod exportableAssemblyMethod) + { + return new ExportableSectionAssemblyResultWithProbability(exportableAssemblyMethod, assembly.Group, assembly.Probability); + } + + private static ExportableFailureMechanismSection CreateExportableFailureMechanismSection(FailureMechanismSection failureMechanismSection) + { + return new ExportableFailureMechanismSection(failureMechanismSection.Points, double.NaN, double.NaN); + } + } +} \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.IO/Ringtoets.Integration.IO.csproj =================================================================== diff -u -r0021d57d71421c62a6475e9c5be470babd7463ec -ra2ea180503092e239c6919517c536ce1d30db295 --- Ringtoets/Integration/src/Ringtoets.Integration.IO/Ringtoets.Integration.IO.csproj (.../Ringtoets.Integration.IO.csproj) (revision 0021d57d71421c62a6475e9c5be470babd7463ec) +++ Ringtoets/Integration/src/Ringtoets.Integration.IO/Ringtoets.Integration.IO.csproj (.../Ringtoets.Integration.IO.csproj) (revision a2ea180503092e239c6919517c536ce1d30db295) @@ -37,6 +37,7 @@ + @@ -98,6 +99,11 @@ Ringtoets.Common.Util False + + {83d6b73e-91d5-46b0-9218-955da1f75f7c} + Ringtoets.MacroStabilityInwards.Data + False + {CE994CC9-6F6A-48AC-B4BE-02C30A21F4DB} Ringtoets.Piping.Data Index: Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Factories/ExportableMacroStabilityInwardsFailureMechanismFactoryTest.cs =================================================================== diff -u --- Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Factories/ExportableMacroStabilityInwardsFailureMechanismFactoryTest.cs (revision 0) +++ Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Factories/ExportableMacroStabilityInwardsFailureMechanismFactoryTest.cs (revision a2ea180503092e239c6919517c536ce1d30db295) @@ -0,0 +1,141 @@ +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.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Integration.IO.Assembly; +using Ringtoets.Integration.IO.Factories; +using Ringtoets.Integration.IO.TestUtil; +using Ringtoets.MacroStabilityInwards.Data; + +namespace Ringtoets.Integration.IO.Test.Factories +{ + [TestFixture] + public class ExportableMacroStabilityInwardsFailureMechanismFactoryTest + { + [Test] + public void CreateExportableMacroStabilityInwardsFailureMechanism_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => + ExportableMacroStabilityInwardsFailureMechanismFactory.CreateExportableMacroStabilityInwardsFailureMechanism(null, + assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + + mocks.VerifyAll(); + } + + [Test] + public void CreateExportableMacroStabilityInwardsFailureMechanism_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => + ExportableMacroStabilityInwardsFailureMechanismFactory.CreateExportableMacroStabilityInwardsFailureMechanism(new MacroStabilityInwardsFailureMechanism(), + null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void CreateExportableMacroStabilityInwardsFailureMechanism_WithValidArguments_ReturnsExportableFailureMechanism() + { + // Setup + var random = new Random(21); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + 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 assemblyResult = + ExportableMacroStabilityInwardsFailureMechanismFactory.CreateExportableMacroStabilityInwardsFailureMechanism(failureMechanism, assessmentSection); + + // Assert + Assert.AreEqual(failureMechanismAssemblyCalculator.FailureMechanismAssemblyOutput.Group, assemblyResult.FailureMechanismAssembly.AssemblyCategory); + Assert.AreEqual(failureMechanismAssemblyCalculator.FailureMechanismAssemblyOutput.Probability, assemblyResult.FailureMechanismAssembly.Probability); + Assert.AreEqual(ExportableFailureMechanismType.STBI, assemblyResult.Code); + Assert.AreEqual(ExportableFailureMechanismGroup.Group2, assemblyResult.Group); + + ExportableFailureMechanismSectionTestHelper.AssertExportableFailureMechanismSections(failureMechanism.Sections, assemblyResult.Sections); + AssertExportableFailureMechanismSectionResults(failureMechanismSectionAssemblyCalculator.SimpleAssessmentAssemblyOutput, + failureMechanismSectionAssemblyCalculator.DetailedAssessmentAssemblyOutput, + failureMechanismSectionAssemblyCalculator.TailorMadeAssessmentAssemblyOutput, + failureMechanismSectionAssemblyCalculator.CombinedAssemblyOutput, + assemblyResult.Sections, + assemblyResult.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.WBI0G5, + actualResult.DetailedAssembly); + + ExportableSectionAssemblyResultTestHelper.AssertExportableSectionAssemblyResult(expectedTailorMadeAssembly, + ExportableAssemblyMethod.WBI0T5, + actualResult.TailorMadeAssembly); + + ExportableSectionAssemblyResultTestHelper.AssertExportableSectionAssemblyResult(expectedCombinedAssembly, + ExportableAssemblyMethod.WBI1B1, + actualResult.CombinedAssembly); + } + } +} \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Ringtoets.Integration.IO.Test.csproj =================================================================== diff -u -r0021d57d71421c62a6475e9c5be470babd7463ec -ra2ea180503092e239c6919517c536ce1d30db295 --- Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Ringtoets.Integration.IO.Test.csproj (.../Ringtoets.Integration.IO.Test.csproj) (revision 0021d57d71421c62a6475e9c5be470babd7463ec) +++ Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Ringtoets.Integration.IO.Test.csproj (.../Ringtoets.Integration.IO.Test.csproj) (revision a2ea180503092e239c6919517c536ce1d30db295) @@ -39,6 +39,7 @@ + @@ -89,6 +90,10 @@ {54DF6303-BF9A-4AE9-BE09-4AF50EF27412} Ringtoets.Common.Util.TestUtil + + {83D6B73E-91D5-46B0-9218-955DA1F75F7C} + Ringtoets.MacroStabilityInwards.Data + {ce994cc9-6f6a-48ac-b4be-02c30a21f4db} Ringtoets.Piping.Data