Fisheye: Tag 773fa9dbb96e3e391ee0abff808550fc2e70d7d0 refers to a dead (removed) revision in file `Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/ClosingStructuresFailureMechanismSection2aAssessmentResultExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/ClosingStructuresFailureMechanismSectionDetailedAssessmentResultExtensions.cs =================================================================== diff -u --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/ClosingStructuresFailureMechanismSectionDetailedAssessmentResultExtensions.cs (revision 0) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/ClosingStructuresFailureMechanismSectionDetailedAssessmentResultExtensions.cs (revision 773fa9dbb96e3e391ee0abff808550fc2e70d7d0) @@ -0,0 +1,73 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Probability; + +namespace Ringtoets.ClosingStructures.Data +{ + /// + /// Extension methods for obtaining detailed assessment probabilities from output for an assessment of the + /// closing structures failure mechanism. + /// + public static class ClosingStructuresFailureMechanismSectionDetailedAssessmentResultExtensions + { + /// + /// Gets the value for the detailed assessment of safety per failure mechanism section as a probability. + /// + /// The section result to get the detailed assessment probability for. + /// The failure mechanism the calculations belong to. + /// The assessment section the calculations belong to. + /// The calculated detailed assessment probability; or when there is no + /// calculation assigned to the section result or the calculation is not performed. + /// Thrown when any parameter is null. + public static double GetDetailedAssessmentProbability(this ClosingStructuresFailureMechanismSectionResult sectionResult, + ClosingStructuresFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) + { + if (sectionResult == null) + { + throw new ArgumentNullException(nameof(sectionResult)); + } + + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + if (sectionResult.Calculation == null || !sectionResult.Calculation.HasOutput) + { + return double.NaN; + } + + ProbabilityAssessmentOutput derivedOutput = ClosingStructuresProbabilityAssessmentOutputFactory.Create(sectionResult.Calculation.Output, + failureMechanism, assessmentSection); + + return derivedOutput.Probability; + } + } +} \ No newline at end of file Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/ClosingStructuresFailureMechanismSectionResultAssemblyFactory.cs =================================================================== diff -u -rc78222de817c2a2de6f85b64fab4ed128e030e8d -r773fa9dbb96e3e391ee0abff808550fc2e70d7d0 --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/ClosingStructuresFailureMechanismSectionResultAssemblyFactory.cs (.../ClosingStructuresFailureMechanismSectionResultAssemblyFactory.cs) (revision c78222de817c2a2de6f85b64fab4ed128e030e8d) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/ClosingStructuresFailureMechanismSectionResultAssemblyFactory.cs (.../ClosingStructuresFailureMechanismSectionResultAssemblyFactory.cs) (revision 773fa9dbb96e3e391ee0abff808550fc2e70d7d0) @@ -20,10 +20,13 @@ // All rights reserved. using System; +using System.Collections.Generic; using Ringtoets.AssemblyTool.Data; using Ringtoets.AssemblyTool.KernelWrapper.Calculators; using Ringtoets.AssemblyTool.KernelWrapper.Calculators.Assembly; using Ringtoets.AssemblyTool.KernelWrapper.Kernels; +using Ringtoets.Common.Data.AssemblyTool; +using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Exceptions; namespace Ringtoets.ClosingStructures.Data @@ -63,5 +66,56 @@ throw new AssemblyFactoryException(e.Message, e); } } + + /// + /// Assembles the detailed assessment result. + /// + /// The failure mechanism section result to + /// assemble the detailed assembly for. + /// The failure mechanism belonging to this calculation. + /// The belonging to this calculation. + /// A . + /// Thrown when any parameter is null. + /// Thrown when + /// cannot be assembled. + public static FailureMechanismSectionAssembly AssembleDetailedAssembly( + ClosingStructuresFailureMechanismSectionResult failureMechanismSectionResult, + ClosingStructuresFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) + { + if (failureMechanismSectionResult == null) + { + throw new ArgumentNullException(nameof(failureMechanismSectionResult)); + } + + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + IAssemblyToolCalculatorFactory calculatorFactory = AssemblyToolCalculatorFactory.Instance; + IFailureMechanismSectionAssemblyCalculator calculator = calculatorFactory.CreateFailureMechanismSectionAssemblyCalculator(AssemblyToolKernelFactory.Instance); + + try + { + IEnumerable categories = AssemblyToolCategoriesFactory.CreateFailureMechanismSectionAssemblyCategories( + assessmentSection.FailureMechanismContribution.SignalingNorm, + assessmentSection.FailureMechanismContribution.LowerLimitNorm, + failureMechanism.Contribution, + failureMechanism.GeneralInput.N); + + return calculator.AssembleDetailedAssessment(failureMechanismSectionResult.GetDetailedAssessmentProbability(failureMechanism, assessmentSection), + categories); + } + catch (FailureMechanismSectionAssemblyCalculatorException e) + { + throw new AssemblyFactoryException(e.Message, e); + } + } } } \ No newline at end of file Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/Ringtoets.ClosingStructures.Data.csproj =================================================================== diff -u -rd7696913d8f9239cb80eb2c3bac6cc0ccf23d479 -r773fa9dbb96e3e391ee0abff808550fc2e70d7d0 --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/Ringtoets.ClosingStructures.Data.csproj (.../Ringtoets.ClosingStructures.Data.csproj) (revision d7696913d8f9239cb80eb2c3bac6cc0ccf23d479) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/Ringtoets.ClosingStructures.Data.csproj (.../Ringtoets.ClosingStructures.Data.csproj) (revision 773fa9dbb96e3e391ee0abff808550fc2e70d7d0) @@ -13,7 +13,7 @@ - + Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Views/ClosingStructuresFailureMechanismResultView.cs =================================================================== diff -u -rc7425b8f799095f2dc812351e14103931c672fba -r773fa9dbb96e3e391ee0abff808550fc2e70d7d0 --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Views/ClosingStructuresFailureMechanismResultView.cs (.../ClosingStructuresFailureMechanismResultView.cs) (revision c7425b8f799095f2dc812351e14103931c672fba) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Views/ClosingStructuresFailureMechanismResultView.cs (.../ClosingStructuresFailureMechanismResultView.cs) (revision 773fa9dbb96e3e391ee0abff808550fc2e70d7d0) @@ -42,7 +42,7 @@ public class ClosingStructuresFailureMechanismResultView : FailureMechanismResultView { - private const int assessmentLayerTwoAIndex = 2; + private const int detailedAssessmentIndex = 2; private readonly IAssessmentSection assessmentSection; private readonly RecursiveObserver calculationInputObserver; private readonly RecursiveObserver calculationOutputObserver; @@ -126,7 +126,7 @@ nameof(EnumDisplayWrapper.DisplayName)); DataGridViewControl.AddTextBoxColumn( - nameof(ClosingStructuresFailureMechanismSectionResultRow.AssessmentLayerTwoA), + nameof(ClosingStructuresFailureMechanismSectionResultRow.DetailedAssessmentProbability), RingtoetsCommonFormsResources.FailureMechanismResultView_DetailedAssessment_ColumnHeader); DataGridViewControl.AddTextBoxColumn( nameof(ClosingStructuresFailureMechanismSectionResultRow.AssessmentLayerThree), @@ -156,7 +156,7 @@ private void ShowAssessmentLayerErrors(object sender, DataGridViewCellFormattingEventArgs e) { - if (e.ColumnIndex != assessmentLayerTwoAIndex) + if (e.ColumnIndex != detailedAssessmentIndex) { return; } @@ -166,9 +166,9 @@ StructuresCalculation normativeCalculation = resultRow.GetSectionResultCalculation(); FailureMechanismSectionResultRowHelper.SetDetailedAssessmentError(currentDataGridViewCell, - resultRow.AssessmentLayerOne, - resultRow.AssessmentLayerTwoA, - normativeCalculation); + resultRow.AssessmentLayerOne, + resultRow.DetailedAssessmentProbability, + normativeCalculation); } } } \ No newline at end of file Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Views/ClosingStructuresFailureMechanismSectionResultRow.cs =================================================================== diff -u -r6f13804bd7731f68a54aecc1805577344470ef20 -r773fa9dbb96e3e391ee0abff808550fc2e70d7d0 --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Views/ClosingStructuresFailureMechanismSectionResultRow.cs (.../ClosingStructuresFailureMechanismSectionResultRow.cs) (revision 6f13804bd7731f68a54aecc1805577344470ef20) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Views/ClosingStructuresFailureMechanismSectionResultRow.cs (.../ClosingStructuresFailureMechanismSectionResultRow.cs) (revision 773fa9dbb96e3e391ee0abff808550fc2e70d7d0) @@ -48,7 +48,7 @@ /// Thrown when any parameter is null. public ClosingStructuresFailureMechanismSectionResultRow(ClosingStructuresFailureMechanismSectionResult sectionResult, ClosingStructuresFailureMechanism failureMechanism, - IAssessmentSection assessmentSection) + IAssessmentSection assessmentSection) : base(sectionResult) { if (failureMechanism == null) @@ -100,14 +100,14 @@ } /// - /// Gets the value representing the result of the layer 2a assessment. + /// Gets the value representing the detailed assessment probability. /// [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] - public double AssessmentLayerTwoA + public double DetailedAssessmentProbability { get { - return SectionResult.GetAssessmentLayerTwoA(failureMechanism, assessmentSection); + return SectionResult.GetDetailedAssessmentProbability(failureMechanism, assessmentSection); } } Fisheye: Tag 773fa9dbb96e3e391ee0abff808550fc2e70d7d0 refers to a dead (removed) revision in file `Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/ClosingStructuresFailureMechanismSection2aAssessmentResultExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/ClosingStructuresFailureMechanismSectionDetailedAssessmentResultExtensionsTest.cs =================================================================== diff -u --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/ClosingStructuresFailureMechanismSectionDetailedAssessmentResultExtensionsTest.cs (revision 0) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/ClosingStructuresFailureMechanismSectionDetailedAssessmentResultExtensionsTest.cs (revision 773fa9dbb96e3e391ee0abff808550fc2e70d7d0) @@ -0,0 +1,161 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.ClosingStructures.Data.TestUtil; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.TestUtil; + +namespace Ringtoets.ClosingStructures.Data.Test +{ + [TestFixture] + public class ClosingStructuresFailureMechanismSectionDetailedAssessmentResultExtensionsTest + { + [Test] + public void GetDetailedAssessmentProbability_SectionResultNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => ClosingStructuresFailureMechanismSectionDetailedAssessmentResultExtensions.GetDetailedAssessmentProbability( + null, + new ClosingStructuresFailureMechanism(), + assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("sectionResult", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new ClosingStructuresFailureMechanismSectionResult(section); + + // Call + TestDelegate call = () => failureMechanismSectionResult.GetDetailedAssessmentProbability(null, assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Setup + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new ClosingStructuresFailureMechanismSectionResult(section); + + // Call + TestDelegate call = () => failureMechanismSectionResult.GetDetailedAssessmentProbability(new ClosingStructuresFailureMechanism(), null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void GetDetailedAssessmentProbability_SectionResultWithoutCalculation_ReturnsNaN() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new ClosingStructuresFailureMechanismSectionResult(section); + + // Call + double detailedAssessmentProbability = failureMechanismSectionResult.GetDetailedAssessmentProbability(new ClosingStructuresFailureMechanism(), + assessmentSection); + + // Assert + Assert.IsNaN(detailedAssessmentProbability); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_CalculationWithoutOutput_ReturnsNaN() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new ClosingStructuresFailureMechanismSectionResult(section) + { + Calculation = new TestClosingStructuresCalculation() + }; + + // Call + double detailedAssessmentProbability = failureMechanismSectionResult.GetDetailedAssessmentProbability(new ClosingStructuresFailureMechanism(), + assessmentSection); + + // Assert + Assert.IsNaN(detailedAssessmentProbability); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_CalculationWithOutput_ReturnsDerivedProbability() + { + // Setup + var failureMechanism = new ClosingStructuresFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new ClosingStructuresFailureMechanismSectionResult(section) + { + Calculation = new TestClosingStructuresCalculation + { + Output = new TestStructuresOutput(0.45) + } + }; + + // Call + double detailedAssessmentProbability = failureMechanismSectionResult.GetDetailedAssessmentProbability(new ClosingStructuresFailureMechanism(), + assessmentSection); + + // Assert + Assert.AreEqual(0.32635522028792008, detailedAssessmentProbability); + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/ClosingStructuresFailureMechanismSectionResultAssemblyFactoryTest.cs =================================================================== diff -u -rc78222de817c2a2de6f85b64fab4ed128e030e8d -r773fa9dbb96e3e391ee0abff808550fc2e70d7d0 --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/ClosingStructuresFailureMechanismSectionResultAssemblyFactoryTest.cs (.../ClosingStructuresFailureMechanismSectionResultAssemblyFactoryTest.cs) (revision c78222de817c2a2de6f85b64fab4ed128e030e8d) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/ClosingStructuresFailureMechanismSectionResultAssemblyFactoryTest.cs (.../ClosingStructuresFailureMechanismSectionResultAssemblyFactoryTest.cs) (revision 773fa9dbb96e3e391ee0abff808550fc2e70d7d0) @@ -20,13 +20,17 @@ // All rights reserved. using System; +using System.Linq; using Core.Common.TestUtil; using NUnit.Framework; +using Rhino.Mocks; using Ringtoets.AssemblyTool.Data; using Ringtoets.AssemblyTool.KernelWrapper.Calculators; using Ringtoets.AssemblyTool.KernelWrapper.Calculators.Assembly; using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators; using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators.Assembly; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Contribution; using Ringtoets.Common.Data.Exceptions; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.TestUtil; @@ -37,6 +41,8 @@ [TestFixture] public class ClosingStructuresFailureMechanismSectionResultAssemblyFactoryTest { + #region Simple Assessment + [Test] public void AssembleSimpleAssessment_FailureMechanismSectionResultNull_ThrowsArgumentNullException() { @@ -117,5 +123,180 @@ Assert.AreEqual(innerException.Message, exception.Message); } } + + #endregion + + #region Detailed Assessment + + [Test] + public void AssembleDetailedAssembly_FailureMechanismSectionResultNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => ClosingStructuresFailureMechanismSectionResultAssemblyFactory.AssembleDetailedAssembly( + null, + new ClosingStructuresFailureMechanism(), + assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanismSectionResult", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void AssembleDetailedAssembly_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => ClosingStructuresFailureMechanismSectionResultAssemblyFactory.AssembleDetailedAssembly( + new ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), + null, + assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void AssembleDetailedAssembly_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ClosingStructuresFailureMechanismSectionResultAssemblyFactory.AssembleDetailedAssembly( + new ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), + new ClosingStructuresFailureMechanism(), + null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void AssembleDetailedAssembly_WithInput_SetsInputOnCalculator() + { + // Setup + var random = new Random(21); + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.FailureMechanismContribution).Return(new FailureMechanismContribution( + Enumerable.Empty(), + random.Next(0, 100), + random.NextRoundedDouble(0.06, 0.1), + random.NextRoundedDouble(0.00001, 0.05))); + mocks.ReplayAll(); + + var failureMechanism = new ClosingStructuresFailureMechanism(); + var sectionResult = new ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + SimpleAssessmentResult = random.NextEnumValue() + }; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + // Call + ClosingStructuresFailureMechanismSectionResultAssemblyFactory.AssembleDetailedAssembly( + sectionResult, + failureMechanism, + assessmentSection); + + // Assert + Assert.AreEqual(sectionResult.GetDetailedAssessmentProbability(failureMechanism, assessmentSection), + calculator.DetailedAssessmentProbabilityInput); + Assert.IsNotNull(calculator.DetailedAssessmentCategoriesInput); + mocks.VerifyAll(); + } + } + + [Test] + public void AssembleDetailedAssembly_AssemblyRan_ReturnsOutput() + { + // Setup + var random = new Random(21); + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.FailureMechanismContribution).Return(new FailureMechanismContribution( + Enumerable.Empty(), + random.Next(0, 100), + random.NextRoundedDouble(0.06, 0.1), + random.NextRoundedDouble(0.00001, 0.05))); + mocks.ReplayAll(); + + var sectionResult = new ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + SimpleAssessmentResult = random.NextEnumValue() + }; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + // Call + FailureMechanismSectionAssembly actualOutput = + ClosingStructuresFailureMechanismSectionResultAssemblyFactory.AssembleDetailedAssembly( + sectionResult, + new ClosingStructuresFailureMechanism(), + assessmentSection); + + // Assert + FailureMechanismSectionAssembly calculatorOutput = calculator.DetailedAssessmentAssemblyOutput; + Assert.AreSame(calculatorOutput, actualOutput); + } + } + + [Test] + public void AssembleDetailedAssembly_CalculatorThrowsExceptions_ThrowsAssemblyFactoryException() + { + // Setup + var random = new Random(21); + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.FailureMechanismContribution).Return(new FailureMechanismContribution( + Enumerable.Empty(), + random.Next(0, 100), + random.NextRoundedDouble(0.06, 0.1), + random.NextRoundedDouble(0.00001, 0.05))); + mocks.ReplayAll(); + + var sectionResult = new ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + SimpleAssessmentResult = random.NextEnumValue() + }; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + calculator.ThrowExceptionOnCalculate = true; + + // Call + TestDelegate call = () => ClosingStructuresFailureMechanismSectionResultAssemblyFactory.AssembleDetailedAssembly( + sectionResult, + new ClosingStructuresFailureMechanism(), + assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Exception innerException = exception.InnerException; + Assert.IsInstanceOf(innerException); + Assert.AreEqual(innerException.Message, exception.Message); + } + } + + #endregion } } \ No newline at end of file Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/Ringtoets.ClosingStructures.Data.Test.csproj =================================================================== diff -u -rd7696913d8f9239cb80eb2c3bac6cc0ccf23d479 -r773fa9dbb96e3e391ee0abff808550fc2e70d7d0 --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/Ringtoets.ClosingStructures.Data.Test.csproj (.../Ringtoets.ClosingStructures.Data.Test.csproj) (revision d7696913d8f9239cb80eb2c3bac6cc0ccf23d479) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/Ringtoets.ClosingStructures.Data.Test.csproj (.../Ringtoets.ClosingStructures.Data.Test.csproj) (revision 773fa9dbb96e3e391ee0abff808550fc2e70d7d0) @@ -20,7 +20,7 @@ - + Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismResultViewTest.cs =================================================================== diff -u -r4fd4b13639f6d6f3657c02916f60571bf940ee9c -r773fa9dbb96e3e391ee0abff808550fc2e70d7d0 --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismResultViewTest.cs (.../ClosingStructuresFailureMechanismResultViewTest.cs) (revision 4fd4b13639f6d6f3657c02916f60571bf940ee9c) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismResultViewTest.cs (.../ClosingStructuresFailureMechanismResultViewTest.cs) (revision 773fa9dbb96e3e391ee0abff808550fc2e70d7d0) @@ -47,7 +47,7 @@ { private const int nameColumnIndex = 0; private const int assessmentLayerOneIndex = 1; - private const int assessmentLayerTwoAIndex = 2; + private const int detailedAssessmentIndex = 2; private const int assessmentLayerThreeIndex = 3; private Form testForm; @@ -116,14 +116,14 @@ Assert.AreEqual(4, cells.Count); Assert.AreEqual("Section 1", cells[nameColumnIndex].FormattedValue); Assert.AreEqual(AssessmentLayerOneState.NotAssessed, cells[assessmentLayerOneIndex].Value); - Assert.AreEqual("-", cells[assessmentLayerTwoAIndex].FormattedValue); + Assert.AreEqual("-", cells[detailedAssessmentIndex].FormattedValue); Assert.AreEqual("-", cells[assessmentLayerThreeIndex].FormattedValue); cells = rows[1].Cells; Assert.AreEqual(4, cells.Count); Assert.AreEqual("Section 2", cells[nameColumnIndex].FormattedValue); Assert.AreEqual(AssessmentLayerOneState.NotAssessed, cells[assessmentLayerOneIndex].Value); - Assert.AreEqual("-", cells[assessmentLayerTwoAIndex].FormattedValue); + Assert.AreEqual("-", cells[detailedAssessmentIndex].FormattedValue); Assert.AreEqual("-", cells[assessmentLayerThreeIndex].FormattedValue); } } @@ -150,25 +150,25 @@ DataGridViewCellCollection cells = rows[0].Cells; Assert.AreEqual(4, cells.Count); Assert.AreEqual("Section 1", cells[nameColumnIndex].FormattedValue); - DataGridViewCell cellAssessmentLayerTwoA = cells[assessmentLayerTwoAIndex]; + DataGridViewCell cellDetailedAssessment = cells[detailedAssessmentIndex]; DataGridViewCell cellAssessmentLayerThree = cells[assessmentLayerThreeIndex]; DataGridViewCell dataGridViewCell = cells[assessmentLayerOneIndex]; Assert.AreEqual(assessmentLayerOneState, dataGridViewCell.Value); - Assert.AreEqual("-", cellAssessmentLayerTwoA.FormattedValue); + Assert.AreEqual("-", cellDetailedAssessment.FormattedValue); Assert.AreEqual("-", cellAssessmentLayerThree.FormattedValue); Assert.IsEmpty(dataGridViewCell.ErrorText); if (assessmentLayerOneState == AssessmentLayerOneState.Sufficient) { - DataGridViewTestHelper.AssertCellIsDisabled(cellAssessmentLayerTwoA); + DataGridViewTestHelper.AssertCellIsDisabled(cellDetailedAssessment); DataGridViewTestHelper.AssertCellIsDisabled(cellAssessmentLayerThree); Assert.IsTrue(cellAssessmentLayerThree.ReadOnly); } else { - DataGridViewTestHelper.AssertCellIsEnabled(cellAssessmentLayerTwoA, true); + DataGridViewTestHelper.AssertCellIsEnabled(cellDetailedAssessment, true); DataGridViewTestHelper.AssertCellIsEnabled(cellAssessmentLayerThree); Assert.IsFalse(cellAssessmentLayerThree.ReadOnly); @@ -189,11 +189,11 @@ Assert.AreEqual(4, dataGridView.ColumnCount); Assert.IsInstanceOf(dataGridView.Columns[assessmentLayerOneIndex]); - Assert.IsInstanceOf(dataGridView.Columns[assessmentLayerTwoAIndex]); + Assert.IsInstanceOf(dataGridView.Columns[detailedAssessmentIndex]); Assert.IsInstanceOf(dataGridView.Columns[assessmentLayerThreeIndex]); Assert.AreEqual("Eenvoudige toets", dataGridView.Columns[assessmentLayerOneIndex].HeaderText); - Assert.AreEqual("Gedetailleerde toets per vak", dataGridView.Columns[assessmentLayerTwoAIndex].HeaderText); + Assert.AreEqual("Gedetailleerde toets per vak", dataGridView.Columns[detailedAssessmentIndex].HeaderText); Assert.AreEqual("Toets op maat", dataGridView.Columns[assessmentLayerThreeIndex].HeaderText); Assert.AreEqual(DataGridViewAutoSizeColumnsMode.AllCells, dataGridView.AutoSizeColumnsMode); @@ -253,33 +253,33 @@ Assert.AreEqual("Section 1", cells[nameColumnIndex].FormattedValue); Assert.AreEqual(result1.AssessmentLayerOne, cells[assessmentLayerOneIndex].Value); - Assert.AreEqual("-", cells[assessmentLayerTwoAIndex].FormattedValue); + Assert.AreEqual("-", cells[detailedAssessmentIndex].FormattedValue); Assert.AreEqual(ProbabilityFormattingHelper.Format(result1.AssessmentLayerThree), cells[assessmentLayerThreeIndex].FormattedValue); - DataGridViewTestHelper.AssertCellIsDisabled(cells[assessmentLayerTwoAIndex]); + DataGridViewTestHelper.AssertCellIsDisabled(cells[detailedAssessmentIndex]); DataGridViewTestHelper.AssertCellIsDisabled(cells[assessmentLayerThreeIndex]); cells = rows[1].Cells; Assert.AreEqual(4, cells.Count); Assert.AreEqual("Section 2", cells[nameColumnIndex].FormattedValue); Assert.AreEqual(result2.AssessmentLayerOne, cells[assessmentLayerOneIndex].Value); - Assert.AreEqual("-", cells[assessmentLayerTwoAIndex].FormattedValue); + Assert.AreEqual("-", cells[detailedAssessmentIndex].FormattedValue); Assert.AreEqual(ProbabilityFormattingHelper.Format(result2.AssessmentLayerThree), cells[assessmentLayerThreeIndex].FormattedValue); - DataGridViewTestHelper.AssertCellIsEnabled(cells[assessmentLayerTwoAIndex], true); + DataGridViewTestHelper.AssertCellIsEnabled(cells[detailedAssessmentIndex], true); DataGridViewTestHelper.AssertCellIsEnabled(cells[assessmentLayerThreeIndex]); cells = rows[2].Cells; Assert.AreEqual(4, cells.Count); Assert.AreEqual("Section 3", cells[nameColumnIndex].FormattedValue); Assert.AreEqual(result3.AssessmentLayerOne, cells[assessmentLayerOneIndex].Value); - Assert.AreEqual("-", cells[assessmentLayerTwoAIndex].FormattedValue); + Assert.AreEqual("-", cells[detailedAssessmentIndex].FormattedValue); Assert.AreEqual(ProbabilityFormattingHelper.Format(result3.AssessmentLayerThree), cells[assessmentLayerThreeIndex].FormattedValue); - DataGridViewTestHelper.AssertCellIsEnabled(cells[assessmentLayerTwoAIndex], true); + DataGridViewTestHelper.AssertCellIsEnabled(cells[detailedAssessmentIndex], true); DataGridViewTestHelper.AssertCellIsEnabled(cells[assessmentLayerThreeIndex]); } } @@ -319,15 +319,15 @@ DataGridViewCellCollection cells = rows[0].Cells; Assert.AreEqual(4, cells.Count); - DataGridViewTestHelper.AssertCellIsDisabled(cells[assessmentLayerTwoAIndex]); + DataGridViewTestHelper.AssertCellIsDisabled(cells[detailedAssessmentIndex]); DataGridViewTestHelper.AssertCellIsDisabled(cells[assessmentLayerThreeIndex]); } } [Test] [TestCase(AssessmentLayerOneState.NotAssessed)] [TestCase(AssessmentLayerOneState.NoVerdict)] - public void GivenSectionResultWithoutCalculation_ThenLayerTwoAErrorTooltip(AssessmentLayerOneState assessmentLayerOneState) + public void GivenSectionResultWithoutCalculation_ThenDetailedAssessmentErrorTooltip(AssessmentLayerOneState assessmentLayerOneState) { // Given var sectionResult = new ClosingStructuresFailureMechanismSectionResult(CreateSimpleFailureMechanismSection()) @@ -344,7 +344,7 @@ var gridTester = new ControlTester("dataGridView"); var dataGridView = (DataGridView) gridTester.TheObject; - DataGridViewCell dataGridViewCell = dataGridView.Rows[0].Cells[assessmentLayerTwoAIndex]; + DataGridViewCell dataGridViewCell = dataGridView.Rows[0].Cells[detailedAssessmentIndex]; // When object formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. @@ -358,7 +358,7 @@ [Test] [TestCase(AssessmentLayerOneState.NotAssessed)] [TestCase(AssessmentLayerOneState.NoVerdict)] - public void GivenSectionResultAndCalculationNotCalculated_ThenLayerTwoAErrorTooltip( + public void GivenSectionResultAndCalculationNotCalculated_ThenDetailedAssessmentErrorTooltip( AssessmentLayerOneState assessmentLayerOneState) { // Given @@ -376,7 +376,7 @@ var gridTester = new ControlTester("dataGridView"); var dataGridView = (DataGridView) gridTester.TheObject; - DataGridViewCell dataGridViewCell = dataGridView.Rows[0].Cells[assessmentLayerTwoAIndex]; + DataGridViewCell dataGridViewCell = dataGridView.Rows[0].Cells[detailedAssessmentIndex]; // When object formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. @@ -390,7 +390,7 @@ [Test] [TestCase(AssessmentLayerOneState.NotAssessed)] [TestCase(AssessmentLayerOneState.NoVerdict)] - public void GivenSectionResultAndFailedCalculation_ThenLayerTwoAErrorTooltip(AssessmentLayerOneState assessmentLayerOneState) + public void GivenSectionResultAndFailedCalculation_ThenDetailedAssessmentErrorTooltip(AssessmentLayerOneState assessmentLayerOneState) { // Given var sectionResult = new ClosingStructuresFailureMechanismSectionResult(CreateSimpleFailureMechanismSection()) @@ -411,7 +411,7 @@ var gridTester = new ControlTester("dataGridView"); var dataGridView = (DataGridView) gridTester.TheObject; - DataGridViewCell dataGridViewCell = dataGridView.Rows[0].Cells[assessmentLayerTwoAIndex]; + DataGridViewCell dataGridViewCell = dataGridView.Rows[0].Cells[detailedAssessmentIndex]; // When object formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. @@ -425,7 +425,7 @@ [Test] [TestCase(AssessmentLayerOneState.NotAssessed)] [TestCase(AssessmentLayerOneState.NoVerdict)] - public void GivenSectionResultAndSuccessfulCalculation_ThenLayerTwoANoError(AssessmentLayerOneState assessmentLayerOneState) + public void GivenSectionResultAndSuccessfulCalculation_ThenDetailedAssessmentNoError(AssessmentLayerOneState assessmentLayerOneState) { // Given var sectionResult = new ClosingStructuresFailureMechanismSectionResult(CreateSimpleFailureMechanismSection()) @@ -445,7 +445,7 @@ var gridTester = new ControlTester("dataGridView"); var dataGridView = (DataGridView) gridTester.TheObject; - DataGridViewCell dataGridViewCell = dataGridView.Rows[0].Cells[assessmentLayerTwoAIndex]; + DataGridViewCell dataGridViewCell = dataGridView.Rows[0].Cells[detailedAssessmentIndex]; // When object formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. @@ -458,7 +458,7 @@ [Test] [TestCaseSource(nameof(AssessmentLayerOneStateIsSufficientVariousSections))] - public void GivenSectionResultAndAssessmentLayerOneStateSufficient_ThenLayerTwoANoError( + public void GivenSectionResultAndAssessmentLayerOneStateSufficient_ThenDetailedAssessmentNoError( ClosingStructuresFailureMechanismSectionResult sectionResult, string expectedValue) { // Given @@ -470,7 +470,7 @@ var gridTester = new ControlTester("dataGridView"); var dataGridView = (DataGridView) gridTester.TheObject; - DataGridViewCell dataGridViewCell = dataGridView.Rows[0].Cells[assessmentLayerTwoAIndex]; + DataGridViewCell dataGridViewCell = dataGridView.Rows[0].Cells[detailedAssessmentIndex]; // When object formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. @@ -484,7 +484,7 @@ [Test] [TestCase(AssessmentLayerOneState.NotAssessed)] [TestCase(AssessmentLayerOneState.NoVerdict)] - public void GivenSectionResultAndSuccessfulCalculation_WhenChangingCalculationToFailed_ThenLayerTwoAHasError( + public void GivenSectionResultAndSuccessfulCalculation_WhenChangingCalculationToFailed_ThenDetailedAssessmentHasError( AssessmentLayerOneState assessmentLayerOneState) { // Given @@ -505,7 +505,7 @@ var gridTester = new ControlTester("dataGridView"); var dataGridView = (DataGridView) gridTester.TheObject; - DataGridViewCell dataGridViewCell = dataGridView.Rows[0].Cells[assessmentLayerTwoAIndex]; + DataGridViewCell dataGridViewCell = dataGridView.Rows[0].Cells[detailedAssessmentIndex]; // Precondition object formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismSectionResultRowTest.cs =================================================================== diff -u -r6f13804bd7731f68a54aecc1805577344470ef20 -r773fa9dbb96e3e391ee0abff808550fc2e70d7d0 --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismSectionResultRowTest.cs (.../ClosingStructuresFailureMechanismSectionResultRowTest.cs) (revision 6f13804bd7731f68a54aecc1805577344470ef20) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismSectionResultRowTest.cs (.../ClosingStructuresFailureMechanismSectionResultRowTest.cs) (revision 773fa9dbb96e3e391ee0abff808550fc2e70d7d0) @@ -58,11 +58,11 @@ // Assert Assert.IsInstanceOf>(row); Assert.AreEqual(result.AssessmentLayerOne, row.AssessmentLayerOne); - Assert.AreEqual(result.GetAssessmentLayerTwoA(failureMechanism, assessmentSection), row.AssessmentLayerTwoA); + Assert.AreEqual(result.GetDetailedAssessmentProbability(failureMechanism, assessmentSection), row.DetailedAssessmentProbability); Assert.AreEqual(row.AssessmentLayerThree, result.AssessmentLayerThree); TestHelper.AssertTypeConverter( - nameof(ClosingStructuresFailureMechanismSectionResultRow.AssessmentLayerTwoA)); + nameof(ClosingStructuresFailureMechanismSectionResultRow.DetailedAssessmentProbability)); TestHelper.AssertTypeConverter( nameof(ClosingStructuresFailureMechanismSectionResultRow.AssessmentLayerThree)); mocks.VerifyAll(); @@ -133,7 +133,7 @@ } [Test] - public void AssessmentLayerTwoA_NoCalculationSet_ReturnNaN() + public void DetailedAssessmentProbability_NoCalculationSet_ReturnNaN() { // Setup var mocks = new MockRepository(); @@ -151,17 +151,17 @@ var resultRow = new ClosingStructuresFailureMechanismSectionResultRow(sectionResult, failureMechanism, assessmentSection); // Call - double assessmentLayerTwoA = resultRow.AssessmentLayerTwoA; + double detailedAssessmentProbability = resultRow.DetailedAssessmentProbability; // Assert - Assert.IsNaN(assessmentLayerTwoA); + Assert.IsNaN(detailedAssessmentProbability); mocks.VerifyAll(); } [Test] [TestCase(CalculationScenarioStatus.Failed)] [TestCase(CalculationScenarioStatus.NotCalculated)] - public void AssessmentLayerTwoA_CalculationNotDone_ReturnNaN(CalculationScenarioStatus status) + public void DetailedAssessmentProbability_CalculationNotDone_ReturnNaN(CalculationScenarioStatus status) { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); @@ -185,15 +185,15 @@ var resultRow = new ClosingStructuresFailureMechanismSectionResultRow(sectionResult, failureMechanism, assessmentSection); // Call - double assessmentLayerTwoA = resultRow.AssessmentLayerTwoA; + double detailedAssessmentProbability = resultRow.DetailedAssessmentProbability; // Assert - Assert.IsNaN(assessmentLayerTwoA); + Assert.IsNaN(detailedAssessmentProbability); mocks.VerifyAll(); } [Test] - public void AssessmentLayerTwoA_CalculationSuccessful_ReturnAssessmentLayerTwoA() + public void DetailedAssessmentProbability_CalculationSuccessful_ReturnDetailedAssessmentProbability() { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); @@ -217,10 +217,10 @@ var resultRow = new ClosingStructuresFailureMechanismSectionResultRow(sectionResult, failureMechanism, assessmentSection); // Call - double assessmentLayerTwoA = resultRow.AssessmentLayerTwoA; + double detailedAssessmentProbability = resultRow.DetailedAssessmentProbability; // Assert - Assert.AreEqual(0.2786727127146118, assessmentLayerTwoA); + Assert.AreEqual(0.2786727127146118, detailedAssessmentProbability); mocks.VerifyAll(); }