Index: Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRowTest.cs =================================================================== diff -u -r8e3a27cd0c9f5e4ffcb6c5e8e29442a127c042b0 -r822de3c3b6d0755e71125c3a644b94a6ecba86b6 --- Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRowTest.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultRowTest.cs) (revision 8e3a27cd0c9f5e4ffcb6c5e8e29442a127c042b0) +++ Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRowTest.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultRowTest.cs) (revision 822de3c3b6d0755e71125c3a644b94a6ecba86b6) @@ -32,7 +32,6 @@ using Riskeer.AssemblyTool.KernelWrapper.TestUtil.Calculators; using Riskeer.AssemblyTool.KernelWrapper.TestUtil.Calculators.Assembly; using Riskeer.Common.Data.AssessmentSection; -using Riskeer.Common.Data.Calculation; using Riskeer.Common.Data.FailureMechanism; using Riskeer.Common.Data.TestUtil; using Riskeer.Common.Forms.Helpers; @@ -49,26 +48,21 @@ [TestFixture] public class GrassCoverErosionInwardsFailureMechanismSectionResultRowTest { - private static GrassCoverErosionInwardsFailureMechanismSectionResultRow.ConstructionProperties ConstructionProperties - { - get + private static GrassCoverErosionInwardsFailureMechanismSectionResultRow.ConstructionProperties ConstructionProperties => + new GrassCoverErosionInwardsFailureMechanismSectionResultRow.ConstructionProperties { - return new GrassCoverErosionInwardsFailureMechanismSectionResultRow.ConstructionProperties - { - SimpleAssessmentResultIndex = 1, - DetailedAssessmentResultIndex = 2, - DetailedAssessmentProbabilityIndex = 3, - TailorMadeAssessmentResultIndex = 4, - TailorMadeAssessmentProbabilityIndex = 5, - SimpleAssemblyCategoryGroupIndex = 6, - DetailedAssemblyCategoryGroupIndex = 7, - TailorMadeAssemblyCategoryGroupIndex = 8, - CombinedAssemblyCategoryGroupIndex = 9, - CombinedAssemblyProbabilityIndex = 10, - ManualAssemblyProbabilityIndex = 11 - }; - } - } + SimpleAssessmentResultIndex = 1, + DetailedAssessmentResultIndex = 2, + DetailedAssessmentProbabilityIndex = 3, + TailorMadeAssessmentResultIndex = 4, + TailorMadeAssessmentProbabilityIndex = 5, + SimpleAssemblyCategoryGroupIndex = 6, + DetailedAssemblyCategoryGroupIndex = 7, + TailorMadeAssemblyCategoryGroupIndex = 8, + CombinedAssemblyCategoryGroupIndex = 9, + CombinedAssemblyProbabilityIndex = 10, + ManualAssemblyProbabilityIndex = 11 + }; [Test] public void Constructor_FailureMechanismNull_ThrowsArgumentNullException() @@ -82,12 +76,11 @@ var result = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); // Call - TestDelegate test = () => new GrassCoverErosionInwardsFailureMechanismSectionResultRow( - result, null, assessmentSection, ConstructionProperties); + void Call() => new GrassCoverErosionInwardsFailureMechanismSectionResultRow(result, null, assessmentSection, ConstructionProperties); // Assert - string paramName = Assert.Throws(test).ParamName; - Assert.AreEqual("failureMechanism", paramName); + var exception = Assert.Throws(Call); + Assert.AreEqual("failureMechanism", exception.ParamName); mocks.VerifyAll(); } @@ -99,12 +92,12 @@ var result = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); // Call - TestDelegate test = () => new GrassCoverErosionInwardsFailureMechanismSectionResultRow( - result, new GrassCoverErosionInwardsFailureMechanism(), null, ConstructionProperties); + void Call() => new GrassCoverErosionInwardsFailureMechanismSectionResultRow(result, new GrassCoverErosionInwardsFailureMechanism(), + null, ConstructionProperties); // Assert - string paramName = Assert.Throws(test).ParamName; - Assert.AreEqual("assessmentSection", paramName); + var exception = Assert.Throws(Call); + Assert.AreEqual("assessmentSection", exception.ParamName); } [Test] @@ -119,11 +112,11 @@ var result = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); // Call - TestDelegate test = () => new GrassCoverErosionInwardsFailureMechanismSectionResultRow( - result, new GrassCoverErosionInwardsFailureMechanism(), assessmentSection, null); + void Call() => new GrassCoverErosionInwardsFailureMechanismSectionResultRow(result, new GrassCoverErosionInwardsFailureMechanism(), + assessmentSection, null); // Assert - var exception = Assert.Throws(test); + var exception = Assert.Throws(Call); Assert.AreEqual("constructionProperties", exception.ParamName); mocks.VerifyAll(); } @@ -278,11 +271,11 @@ result, failureMechanism, assessmentSection, ConstructionProperties); // Call - TestDelegate test = () => row.ManualAssemblyProbability = value; + void Call() => row.ManualAssemblyProbability = value; // Assert const string expectedMessage = "De waarde voor de faalkans moet in het bereik [0,0, 1,0] liggen."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(Call, expectedMessage); mocks.VerifyAll(); } } @@ -984,9 +977,7 @@ } [Test] - [TestCase(CalculationScenarioStatus.Failed)] - [TestCase(CalculationScenarioStatus.NotCalculated)] - public void DetailedAssessmentProbability_CalculationNotDone_ReturnNaN(CalculationScenarioStatus status) + public void DetailedAssessmentProbability_CalculationWithoutOutput_ReturnNaN() { // Setup var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); @@ -996,13 +987,44 @@ mocks.ReplayAll(); var calculation = new GrassCoverErosionInwardsCalculation(); - if (status == CalculationScenarioStatus.Failed) + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var sectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(section) { - calculation.Output = new GrassCoverErosionInwardsOutput(new TestOvertoppingOutput(double.NaN), - new TestDikeHeightOutput(double.NaN), - new TestOvertoppingRateOutput(double.NaN)); + Calculation = calculation + }; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var resultRow = new GrassCoverErosionInwardsFailureMechanismSectionResultRow( + sectionResult, failureMechanism, assessmentSection, ConstructionProperties); + + // Call + double detailedAssessmentProbability = resultRow.DetailedAssessmentProbability; + + // Assert + Assert.IsNaN(detailedAssessmentProbability); + mocks.VerifyAll(); } + } + [Test] + public void DetailedAssessmentProbability_CalculationWithNaNOutput_ReturnNaN() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + var calculation = new GrassCoverErosionInwardsCalculation + { + Output = new GrassCoverErosionInwardsOutput(new TestOvertoppingOutput(double.NaN), + new TestDikeHeightOutput(double.NaN), + new TestOvertoppingRateOutput(double.NaN)) + }; + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var sectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(section) { @@ -1152,11 +1174,11 @@ result, failureMechanism, assessmentSection, ConstructionProperties); // Call - TestDelegate test = () => row.TailorMadeAssessmentProbability = value; + void Call() => row.TailorMadeAssessmentProbability = value; // Assert const string expectedMessage = "De waarde voor de faalkans moet in het bereik [0,0, 1,0] liggen."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(Call, expectedMessage); mocks.VerifyAll(); } }