Index: Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Calculators/Assembly/AssessmentSectionAssemblyCalculator.cs =================================================================== diff -u -r361b49b111f552cb7ded1369db9e4b2269733efd -rd300264590cc3df96f6968a54ff20578a83f6419 --- Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Calculators/Assembly/AssessmentSectionAssemblyCalculator.cs (.../AssessmentSectionAssemblyCalculator.cs) (revision 361b49b111f552cb7ded1369db9e4b2269733efd) +++ Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Calculators/Assembly/AssessmentSectionAssemblyCalculator.cs (.../AssessmentSectionAssemblyCalculator.cs) (revision d300264590cc3df96f6968a54ff20578a83f6419) @@ -106,5 +106,21 @@ throw new AssessmentSectionAssemblyCalculatorException(e.Message, e); } } + + public IEnumerable AssembleCombinedFailureMechanismSections( + IEnumerable input, double assessmentSectionLength) + { + try + { + ICommonFailureMechanismSectionAssembler kernel = factory.CreateCombinedFailureMechanismSectionAssemblyKernel(); + AssemblyResult output = kernel.AssembleCommonFailureMechanismSections(FailureMechanismSectionListCreator.Create(input), assessmentSectionLength, false); + + return CombinedFailureMechanismSectionAssemblyCreator.Create(output).ToArray(); + } + catch (Exception e) + { + throw new AssessmentSectionAssemblyCalculatorException(e.Message, e); + } + } } } \ No newline at end of file Index: Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Calculators/Assembly/IAssessmentSectionAssemblyCalculator.cs =================================================================== diff -u -r9287290eb9547d3635da4bc014dc14413837ac57 -rd300264590cc3df96f6968a54ff20578a83f6419 --- Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Calculators/Assembly/IAssessmentSectionAssemblyCalculator.cs (.../IAssessmentSectionAssemblyCalculator.cs) (revision 9287290eb9547d3635da4bc014dc14413837ac57) +++ Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Calculators/Assembly/IAssessmentSectionAssemblyCalculator.cs (.../IAssessmentSectionAssemblyCalculator.cs) (revision d300264590cc3df96f6968a54ff20578a83f6419) @@ -64,5 +64,17 @@ /// an error occurs while assembling. AssessmentSectionAssemblyCategoryGroup AssembleAssessmentSection(AssessmentSectionAssemblyCategoryGroup failureMechanismsWithoutProbability, AssessmentSectionAssembly failureMechanismsWithProbability); + + /// + /// Assembles the combined assessment section for the given input. + /// + /// The collection of collections of failure mechanism assembly category groups + /// to assemble for. + /// The length of the assessment section. + /// A collection of . + /// Thrown when + /// an error occurs while assembling. + IEnumerable AssembleCombinedFailureMechanismSections(IEnumerable input, + double assessmentSectionLength); } } \ No newline at end of file Index: Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Calculators/Assembly/IFailureMechanismAssemblyCalculator.cs =================================================================== diff -u -r9287290eb9547d3635da4bc014dc14413837ac57 -rd300264590cc3df96f6968a54ff20578a83f6419 --- Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Calculators/Assembly/IFailureMechanismAssemblyCalculator.cs (.../IFailureMechanismAssemblyCalculator.cs) (revision 9287290eb9547d3635da4bc014dc14413837ac57) +++ Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Calculators/Assembly/IFailureMechanismAssemblyCalculator.cs (.../IFailureMechanismAssemblyCalculator.cs) (revision d300264590cc3df96f6968a54ff20578a83f6419) @@ -48,6 +48,6 @@ /// Thrown when /// an error occurs while assembling. FailureMechanismAssembly Assemble(IEnumerable sectionAssemblies, - AssemblyCategoriesInput assemblyCategoriesInput); + AssemblyCategoriesInput assemblyCategoriesInput); } } \ No newline at end of file Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Calculators/Assembly/AssessmentSectionAssemblyCalculatorTest.cs =================================================================== diff -u -r361b49b111f552cb7ded1369db9e4b2269733efd -rd300264590cc3df96f6968a54ff20578a83f6419 --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Calculators/Assembly/AssessmentSectionAssemblyCalculatorTest.cs (.../AssessmentSectionAssemblyCalculatorTest.cs) (revision 361b49b111f552cb7ded1369db9e4b2269733efd) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Calculators/Assembly/AssessmentSectionAssemblyCalculatorTest.cs (.../AssessmentSectionAssemblyCalculatorTest.cs) (revision d300264590cc3df96f6968a54ff20578a83f6419) @@ -23,13 +23,15 @@ using System.ComponentModel; using System.Linq; using Assembly.Kernel.Model; +using Assembly.Kernel.Model.FmSectionTypes; using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.AssemblyTool.Data; using Ringtoets.AssemblyTool.KernelWrapper.Calculators.Assembly; using Ringtoets.AssemblyTool.KernelWrapper.Creators; using Ringtoets.AssemblyTool.KernelWrapper.Kernels; +using Ringtoets.AssemblyTool.KernelWrapper.TestUtil; using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Kernels; using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Kernels.Assembly; @@ -489,6 +491,182 @@ } } + [Test] + public void AssembleCombinedFailureMechanismSections_WithInvalidInput_ThrowsAssessmentSectionAssemblyCalculatorException() + { + // Setup + var random = new Random(21); + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + var calculator = new AssessmentSectionAssemblyCalculator(factory); + + // Call + TestDelegate test = () => calculator.AssembleCombinedFailureMechanismSections(new[] + { + new CombinedAssemblyFailureMechanismInput(random.NextDouble(1, 2), random.NextDouble(), new[] + { + new CombinedAssemblyFailureMechanismSection(0, 1, (FailureMechanismSectionAssemblyCategoryGroup) 99) + }) + }, random.Next()); + + // Assert + var exception = Assert.Throws(test); + Exception innerException = exception.InnerException; + Assert.IsInstanceOf(innerException); + Assert.AreEqual(innerException.Message, exception.Message); + } + } + + [Test] + public void AssembleCombinedFailureMechanismSections_WithValidInput_InputCorrectlySetToKernel() + { + // Setup + var random = new Random(39); + var input = new[] + { + new CombinedAssemblyFailureMechanismInput(random.NextDouble(1, 2), random.NextDouble(), new[] + { + new CombinedAssemblyFailureMechanismSection(0, 1, random.NextEnumValue()) + }) + }; + double assessmentSectionLength = random.NextDouble(); + + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + CombinedFailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedCombinedFailureMechanismSectionAssemblyKernel; + kernel.AssemblyResult = new AssemblyResult(new[] + { + new FailureMechanismSectionList(new FailureMechanism(random.NextDouble(1, 2), random.NextDouble()), new[] + { + new FmSectionWithDirectCategory(0, 1, random.NextEnumValue()) + }) + }, new[] + { + new FmSectionWithDirectCategory(0, 1, random.NextEnumValue()) + }); + + var calculator = new AssessmentSectionAssemblyCalculator(factory); + + // Call + calculator.AssembleCombinedFailureMechanismSections(input, assessmentSectionLength); + + // Assert + Assert.AreEqual(assessmentSectionLength, kernel.AssessmentSectionLengthInput.Value); + CombinedFailureMechanismSectionsInputAssert.AssertCombinedFailureMechanismInput(input, kernel.FailureMechanismSectionListsInput.ToArray()); + Assert.IsFalse(kernel.PartialAssembly); + } + } + + [Test] + public void AssembleCombinedFailureMechanismSections_KernelWithCompleteOutput_OutputCorrectlyReturnedByCalculator() + { + // Setup + var random = new Random(39); + + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + CombinedFailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedCombinedFailureMechanismSectionAssemblyKernel; + kernel.AssemblyResult = new AssemblyResult(new[] + { + new FailureMechanismSectionList(new FailureMechanism(random.NextDouble(1, 2), random.NextDouble()), new[] + { + new FmSectionWithDirectCategory(0, 1, random.NextEnumValue()) + }) + }, new[] + { + new FmSectionWithDirectCategory(0, 1, random.NextEnumValue()) + }); + + var calculator = new AssessmentSectionAssemblyCalculator(factory); + + // Call + CombinedFailureMechanismSectionAssembly[] output = calculator.AssembleCombinedFailureMechanismSections(new[] + { + new CombinedAssemblyFailureMechanismInput(random.NextDouble(1, 2), random.NextDouble(), new[] + { + new CombinedAssemblyFailureMechanismSection(0, 1, random.NextEnumValue()) + }) + }, random.NextDouble()).ToArray(); + + // Assert + CombinedFailureMechanismSectionAssemblyAssert.AssertAssembly(kernel.AssemblyResult, output); + } + } + + [Test] + public void AssembleCombinedFailureMechanismSections_KernelWithInvalidOutput_ThrowsAssessmentSectionAssemblyCalculatorException() + { + // Setup + var random = new Random(21); + + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + CombinedFailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedCombinedFailureMechanismSectionAssemblyKernel; + kernel.AssemblyResult = new AssemblyResult(new[] + { + new FailureMechanismSectionList(new FailureMechanism(random.NextDouble(1, 2), random.NextDouble()), new[] + { + new FmSectionWithDirectCategory(0, 1, (EFmSectionCategory) 99) + }) + }, new[] + { + new FmSectionWithDirectCategory(0, 1, random.NextEnumValue()) + }); + + var calculator = new AssessmentSectionAssemblyCalculator(factory); + + // Call + TestDelegate test = () => calculator.AssembleCombinedFailureMechanismSections(new[] + { + new CombinedAssemblyFailureMechanismInput(random.NextDouble(1, 2), random.NextDouble(), new[] + { + new CombinedAssemblyFailureMechanismSection(0, 1, random.NextEnumValue()) + }) + }, random.NextDouble()).ToArray(); + + // Assert + var exception = Assert.Throws(test); + Exception innerException = exception.InnerException; + Assert.IsInstanceOf(innerException); + Assert.AreEqual(innerException.Message, exception.Message); + } + } + + [Test] + public void AssembleCombinedFailureMechanismSections_KernelThrowsException_ThrowsAssessmentSectionAssemblyCalculatorException() + { + // Setup + var random = new Random(21); + + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + CombinedFailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedCombinedFailureMechanismSectionAssemblyKernel; + kernel.ThrowException = true; + + var calculator = new AssessmentSectionAssemblyCalculator(factory); + + // Call + TestDelegate test = () => calculator.AssembleCombinedFailureMechanismSections(new[] + { + new CombinedAssemblyFailureMechanismInput(random.NextDouble(1, 2), random.NextDouble(), new[] + { + new CombinedAssemblyFailureMechanismSection(0, 1, random.NextEnumValue()) + }) + }, random.NextDouble()).ToArray(); + + // Assert + var exception = Assert.Throws(test); + Exception innerException = exception.InnerException; + Assert.IsInstanceOf(innerException); + Assert.AreEqual(innerException.Message, exception.Message); + } + } + private static EFailureMechanismCategory GetGroup(FailureMechanismAssemblyCategoryGroup originalGroup) { switch (originalGroup)