Index: Ringtoets/Integration/src/Ringtoets.Integration.IO/Factories/ExportableAssessmentSectionFactory.cs =================================================================== diff -u -r784a997e0cfd099464824db725372ac59cf832c5 -r70fa7a4fc5a4d3e2ad8a2812041dfa55903800ab --- Ringtoets/Integration/src/Ringtoets.Integration.IO/Factories/ExportableAssessmentSectionFactory.cs (.../ExportableAssessmentSectionFactory.cs) (revision 784a997e0cfd099464824db725372ac59cf832c5) +++ Ringtoets/Integration/src/Ringtoets.Integration.IO/Factories/ExportableAssessmentSectionFactory.cs (.../ExportableAssessmentSectionFactory.cs) (revision 70fa7a4fc5a4d3e2ad8a2812041dfa55903800ab) @@ -99,7 +99,8 @@ ExportableDuneErosionFailureMechanismFactory.CreateExportableDuneErosionFailureMechanism(assessmentSection.DuneErosion), ExportableMacroStabilityOutwardsFailureMechanismFactory.CreateExportableMacroStabilityOutwardsFailureMechanism(assessmentSection.MacroStabilityOutwards, assessmentSection), ExportableMicrostabilityFailureMechanismFactory.CreateExportableMicrostabilityFailureMechanism(assessmentSection.Microstability), - ExportableGrassCoverSlipOffOutwardsFailureMechanismFactory.CreateExportableGrassCoverSlipOffOutwardsFailureMechanism(assessmentSection.GrassCoverSlipOffOutwards) + ExportableGrassCoverSlipOffOutwardsFailureMechanismFactory.CreateExportableGrassCoverSlipOffOutwardsFailureMechanism(assessmentSection.GrassCoverSlipOffOutwards), + ExportableGrassCoverSlipOffInwardsFailureMechanismFactory.CreateExportableGrassCoverSlipOffInwardsFailureMechanism(assessmentSection.GrassCoverSlipOffInwards) }; } } Index: Ringtoets/Integration/src/Ringtoets.Integration.IO/Factories/ExportableGrassCoverSlipOffInwardsFailureMechanismFactory.cs =================================================================== diff -u --- Ringtoets/Integration/src/Ringtoets.Integration.IO/Factories/ExportableGrassCoverSlipOffInwardsFailureMechanismFactory.cs (revision 0) +++ Ringtoets/Integration/src/Ringtoets.Integration.IO/Factories/ExportableGrassCoverSlipOffInwardsFailureMechanismFactory.cs (revision 70fa7a4fc5a4d3e2ad8a2812041dfa55903800ab) @@ -0,0 +1,100 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Ringtoets.AssemblyTool.Data; +using Ringtoets.Common.Data.Exceptions; +using Ringtoets.Integration.Data.StandAlone; +using Ringtoets.Integration.Data.StandAlone.AssemblyFactories; +using Ringtoets.Integration.Data.StandAlone.SectionResults; +using Ringtoets.Integration.IO.Assembly; + +namespace Ringtoets.Integration.IO.Factories +{ + /// + /// Factory to create instances of + /// with assembly results for grass cover slip off inwards. + /// + public static class ExportableGrassCoverSlipOffInwardsFailureMechanismFactory + { + private const ExportableFailureMechanismType failureMechanismCode = ExportableFailureMechanismType.GABI; + private const ExportableFailureMechanismGroup failureMechanismGroup = ExportableFailureMechanismGroup.Group4; + private const ExportableAssemblyMethod failureMechanismAssemblyMethod = ExportableAssemblyMethod.WBI1A1; + + /// + /// Creates a + /// with assembly results based on the input parameters. + /// + /// The to create a + /// for. + /// A with assembly results. + /// Thrown when any parameter is null. + /// Thrown when assembly results cannot be created. + public static ExportableFailureMechanism CreateExportableGrassCoverSlipOffInwardsFailureMechanism( + GrassCoverSlipOffInwardsFailureMechanism failureMechanism) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (!failureMechanism.IsRelevant) + { + return ExportableFailureMechanismFactory.CreateDefaultExportableFailureMechanismWithoutProbability(failureMechanismCode, + failureMechanismGroup, + failureMechanismAssemblyMethod); + } + + FailureMechanismAssemblyCategoryGroup failureMechanismAssembly = GrassCoverSlipOffInwardsFailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism); + + Dictionary failureMechanismSectionsLookup = + failureMechanism.SectionResults + .ToDictionary(sectionResult => sectionResult, + sectionResult => ExportableFailureMechanismSectionFactory.CreateExportableFailureMechanismSection(sectionResult.Section)); + + return new ExportableFailureMechanism( + new ExportableFailureMechanismAssemblyResult(failureMechanismAssemblyMethod, + failureMechanismAssembly), + failureMechanismSectionsLookup.Values, + CreateFailureMechanismSectionResults(failureMechanismSectionsLookup), + failureMechanismCode, + failureMechanismGroup); + } + + /// + /// Creates a collection of + /// with assembly results based on the sections in . + /// + /// The mapping between the + /// and . + /// A collection of . + /// Thrown when assembly results cannot be created. + private static IEnumerable CreateFailureMechanismSectionResults( + Dictionary failureMechanismSections) + { + var exportableResults = new List(); + foreach (KeyValuePair failureMechanismSectionPair in failureMechanismSections) + { + GrassCoverSlipOffInwardsFailureMechanismSectionResult failureMechanismSectionResult = failureMechanismSectionPair.Key; + FailureMechanismSectionAssemblyCategoryGroup simpleAssembly = + GrassCoverSlipOffInwardsFailureMechanismAssemblyFactory.AssembleSimpleAssessment(failureMechanismSectionResult); + + FailureMechanismSectionAssemblyCategoryGroup detailedAssembly = + GrassCoverSlipOffInwardsFailureMechanismAssemblyFactory.AssembleDetailedAssessment(failureMechanismSectionResult); + FailureMechanismSectionAssemblyCategoryGroup tailorMadeAssembly = + GrassCoverSlipOffInwardsFailureMechanismAssemblyFactory.AssembleTailorMadeAssessment(failureMechanismSectionResult); + FailureMechanismSectionAssemblyCategoryGroup combinedAssembly = + GrassCoverSlipOffInwardsFailureMechanismAssemblyFactory.AssembleCombinedAssessment(failureMechanismSectionResult); + + exportableResults.Add( + new ExportableAggregatedFailureMechanismSectionAssemblyResult( + failureMechanismSectionPair.Value, + ExportableSectionAssemblyResultFactory.CreateExportableSectionAssemblyResult(simpleAssembly, ExportableAssemblyMethod.WBI0E1), + ExportableSectionAssemblyResultFactory.CreateExportableSectionAssemblyResult(detailedAssembly, ExportableAssemblyMethod.WBI0G1), + ExportableSectionAssemblyResultFactory.CreateExportableSectionAssemblyResult(tailorMadeAssembly, ExportableAssemblyMethod.WBI0T1), + ExportableSectionAssemblyResultFactory.CreateExportableSectionAssemblyResult(combinedAssembly, ExportableAssemblyMethod.WBI0A1))); + } + + return exportableResults; + } + } +} \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.IO/Ringtoets.Integration.IO.csproj =================================================================== diff -u -r784a997e0cfd099464824db725372ac59cf832c5 -r70fa7a4fc5a4d3e2ad8a2812041dfa55903800ab --- Ringtoets/Integration/src/Ringtoets.Integration.IO/Ringtoets.Integration.IO.csproj (.../Ringtoets.Integration.IO.csproj) (revision 784a997e0cfd099464824db725372ac59cf832c5) +++ Ringtoets/Integration/src/Ringtoets.Integration.IO/Ringtoets.Integration.IO.csproj (.../Ringtoets.Integration.IO.csproj) (revision 70fa7a4fc5a4d3e2ad8a2812041dfa55903800ab) @@ -43,6 +43,7 @@ + Index: Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Factories/ExportableAssessmentSectionFactoryTest.cs =================================================================== diff -u -r784a997e0cfd099464824db725372ac59cf832c5 -r70fa7a4fc5a4d3e2ad8a2812041dfa55903800ab --- Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Factories/ExportableAssessmentSectionFactoryTest.cs (.../ExportableAssessmentSectionFactoryTest.cs) (revision 784a997e0cfd099464824db725372ac59cf832c5) +++ Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Factories/ExportableAssessmentSectionFactoryTest.cs (.../ExportableAssessmentSectionFactoryTest.cs) (revision 70fa7a4fc5a4d3e2ad8a2812041dfa55903800ab) @@ -66,6 +66,7 @@ FailureMechanismTestHelper.AddSections(assessmentSection.MacroStabilityOutwards, random.Next(1, 10)); FailureMechanismTestHelper.AddSections(assessmentSection.Microstability, random.Next(1, 10)); FailureMechanismTestHelper.AddSections(assessmentSection.GrassCoverSlipOffOutwards, random.Next(1, 10)); + FailureMechanismTestHelper.AddSections(assessmentSection.GrassCoverSlipOffInwards, random.Next(1, 10)); using (new AssemblyToolCalculatorFactoryConfig()) { @@ -164,7 +165,7 @@ FailureMechanismAssemblyCalculatorStub failureMechanismAssemblyCalculator, AssessmentSection assessmentSection) { - Assert.AreEqual(7, exportableFailureMechanisms.Count()); + Assert.AreEqual(8, exportableFailureMechanisms.Count()); FailureMechanismAssemblyCategoryGroup expectedFailureMechanismAssemblyOutput = failureMechanismAssemblyCalculator.FailureMechanismAssemblyCategoryGroupOutput.Value; AssertExportableFailureMechanismWithoutProbability(expectedFailureMechanismAssemblyOutput, @@ -208,6 +209,12 @@ ExportableFailureMechanismGroup.Group4, assessmentSection.GrassCoverSlipOffOutwards, exportableFailureMechanisms.ElementAt(6)); + + AssertExportableFailureMechanismWithoutProbability(expectedFailureMechanismAssemblyOutput, + ExportableFailureMechanismType.GABI, + ExportableFailureMechanismGroup.Group4, + assessmentSection.GrassCoverSlipOffInwards, + exportableFailureMechanisms.ElementAt(7)); } private static void AssertExportableFailureMechanismWithoutProbability(FailureMechanismAssemblyCategoryGroup expectedAssemblyOutput, Index: Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Factories/ExportableGrassCoverSlipOffInwardsFailureMechanismFactoryTest.cs =================================================================== diff -u --- Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Factories/ExportableGrassCoverSlipOffInwardsFailureMechanismFactoryTest.cs (revision 0) +++ Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Factories/ExportableGrassCoverSlipOffInwardsFailureMechanismFactoryTest.cs (revision 70fa7a4fc5a4d3e2ad8a2812041dfa55903800ab) @@ -0,0 +1,145 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using NUnit.Framework; +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.TestUtil; +using Ringtoets.Integration.Data.StandAlone; +using Ringtoets.Integration.IO.Assembly; +using Ringtoets.Integration.IO.Factories; +using Ringtoets.Integration.IO.TestUtil; + +namespace Ringtoets.Integration.IO.Test.Factories +{ + [TestFixture] + public class ExportableGrassCoverSlipOffInwardsFailureMechanismFactoryTest + { + [Test] + public void CreateExportableGrassCoverSlipOffInwardsFailureMechanism_FailureMechanismNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => + ExportableGrassCoverSlipOffInwardsFailureMechanismFactory.CreateExportableGrassCoverSlipOffInwardsFailureMechanism(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] + public void CreateExportableGrassCoverSlipOffInwardsFailureMechanism_WithFailureMechanismNotRelevant_ReturnsDefaultExportableFailureMechanism() + { + // Setup + var random = new Random(21); + var failureMechanism = new GrassCoverSlipOffInwardsFailureMechanism + { + IsRelevant = false + }; + FailureMechanismTestHelper.AddSections(failureMechanism, random.Next(2, 10)); + + // Call + ExportableFailureMechanism exportableFailureMechanism = + ExportableGrassCoverSlipOffInwardsFailureMechanismFactory.CreateExportableGrassCoverSlipOffInwardsFailureMechanism(failureMechanism); + + // Assert + Assert.AreEqual(ExportableFailureMechanismType.GABI, exportableFailureMechanism.Code); + Assert.AreEqual(ExportableFailureMechanismGroup.Group4, exportableFailureMechanism.Group); + + ExportableFailureMechanismAssemblyResult failureMechanismAssemblyResult = exportableFailureMechanism.FailureMechanismAssembly; + Assert.AreEqual(ExportableAssemblyMethod.WBI1A1, failureMechanismAssemblyResult.AssemblyMethod); + Assert.AreEqual(FailureMechanismAssemblyCategoryGroup.NotApplicable, failureMechanismAssemblyResult.AssemblyCategory); + + CollectionAssert.IsEmpty(exportableFailureMechanism.Sections); + CollectionAssert.IsEmpty(exportableFailureMechanism.SectionAssemblyResults); + } + + [Test] + public void CreateExportableGrassCoverSlipOffInwardsFailureMechanism_WithFailureMechanismRelevant_ReturnsExportableFailureMechanism() + { + // Setup + var random = new Random(21); + var failureMechanism = new GrassCoverSlipOffInwardsFailureMechanism(); + FailureMechanismTestHelper.AddSections(failureMechanism, random.Next(2, 10)); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismAssemblyCalculatorStub failureMechanismAssemblyCalculator = calculatorfactory.LastCreatedFailureMechanismAssemblyCalculator; + FailureMechanismSectionAssemblyCalculatorStub failureMechanismSectionAssemblyCalculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + // Call + ExportableFailureMechanism exportableFailureMechanism = + ExportableGrassCoverSlipOffInwardsFailureMechanismFactory.CreateExportableGrassCoverSlipOffInwardsFailureMechanism(failureMechanism); + + // Assert + Assert.AreEqual(ExportableFailureMechanismType.GABI, exportableFailureMechanism.Code); + Assert.AreEqual(ExportableFailureMechanismGroup.Group4, exportableFailureMechanism.Group); + + ExportableFailureMechanismAssemblyResult exportableFailureMechanismAssembly = exportableFailureMechanism.FailureMechanismAssembly; + Assert.AreEqual(failureMechanismAssemblyCalculator.FailureMechanismAssemblyCategoryGroupOutput, exportableFailureMechanismAssembly.AssemblyCategory); + Assert.AreEqual(ExportableAssemblyMethod.WBI1A1, exportableFailureMechanismAssembly.AssemblyMethod); + + ExportableFailureMechanismSectionTestHelper.AssertExportableFailureMechanismSections(failureMechanism.Sections, exportableFailureMechanism.Sections); + AssertExportableFailureMechanismSectionResults(failureMechanismSectionAssemblyCalculator.SimpleAssessmentAssemblyOutput.Group, + failureMechanismSectionAssemblyCalculator.DetailedAssessmentAssemblyGroupOutput.Value, + failureMechanismSectionAssemblyCalculator.TailorMadeAssemblyCategoryOutput.Value, + failureMechanismSectionAssemblyCalculator.CombinedAssemblyCategoryOutput.Value, + exportableFailureMechanism.Sections, + exportableFailureMechanism.SectionAssemblyResults.Cast()); + } + } + + private static void AssertExportableFailureMechanismSectionResults(FailureMechanismSectionAssemblyCategoryGroup expectedSimpleAssembly, + FailureMechanismSectionAssemblyCategoryGroup expectedDetailedAssembly, + FailureMechanismSectionAssemblyCategoryGroup expectedTailorMadeAssembly, + FailureMechanismSectionAssemblyCategoryGroup 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); + ExportableAggregatedFailureMechanismSectionAssemblyResult result = results.ElementAt(i); + + AssertExportableFailureMechanismSectionResult(expectedSimpleAssembly, + expectedDetailedAssembly, + expectedTailorMadeAssembly, + expectedCombinedAssembly, + section, + result); + } + } + + private static void AssertExportableFailureMechanismSectionResult(FailureMechanismSectionAssemblyCategoryGroup expectedSimpleAssembly, + FailureMechanismSectionAssemblyCategoryGroup expectedDetailedAssembly, + FailureMechanismSectionAssemblyCategoryGroup expectedTailorMadeAssembly, + FailureMechanismSectionAssemblyCategoryGroup expectedCombinedAssembly, + ExportableFailureMechanismSection expectedSection, + ExportableAggregatedFailureMechanismSectionAssemblyResult actualResult) + { + Assert.AreSame(expectedSection, actualResult.FailureMechanismSection); + + ExportableSectionAssemblyResultTestHelper.AssertExportableSectionAssemblyResult(expectedSimpleAssembly, + ExportableAssemblyMethod.WBI0E1, + actualResult.SimpleAssembly); + + ExportableSectionAssemblyResultTestHelper.AssertExportableSectionAssemblyResult(expectedDetailedAssembly, + ExportableAssemblyMethod.WBI0G1, + actualResult.DetailedAssembly); + + ExportableSectionAssemblyResultTestHelper.AssertExportableSectionAssemblyResult(expectedTailorMadeAssembly, + ExportableAssemblyMethod.WBI0T1, + 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 -r784a997e0cfd099464824db725372ac59cf832c5 -r70fa7a4fc5a4d3e2ad8a2812041dfa55903800ab --- Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Ringtoets.Integration.IO.Test.csproj (.../Ringtoets.Integration.IO.Test.csproj) (revision 784a997e0cfd099464824db725372ac59cf832c5) +++ Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Ringtoets.Integration.IO.Test.csproj (.../Ringtoets.Integration.IO.Test.csproj) (revision 70fa7a4fc5a4d3e2ad8a2812041dfa55903800ab) @@ -45,6 +45,7 @@ +