Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Views/ClosingStructuresFailureMechanismSectionResultRow.cs =================================================================== diff -u -r86a78a8673ee3eba70b79c466451daec043c6fbc -ra64465cf500bb46f741f340072e93f3e2072cc00 --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Views/ClosingStructuresFailureMechanismSectionResultRow.cs (.../ClosingStructuresFailureMechanismSectionResultRow.cs) (revision 86a78a8673ee3eba70b79c466451daec043c6fbc) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Views/ClosingStructuresFailureMechanismSectionResultRow.cs (.../ClosingStructuresFailureMechanismSectionResultRow.cs) (revision a64465cf500bb46f741f340072e93f3e2072cc00) @@ -91,6 +91,11 @@ { return SectionResult.DetailedAssessmentResult; } + set + { + SectionResult.DetailedAssessmentResult = value; + UpdateInternalData(); + } } /// Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismSectionResultRowTest.cs =================================================================== diff -u -r86a78a8673ee3eba70b79c466451daec043c6fbc -ra64465cf500bb46f741f340072e93f3e2072cc00 --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismSectionResultRowTest.cs (.../ClosingStructuresFailureMechanismSectionResultRowTest.cs) (revision 86a78a8673ee3eba70b79c466451daec043c6fbc) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismSectionResultRowTest.cs (.../ClosingStructuresFailureMechanismSectionResultRowTest.cs) (revision a64465cf500bb46f741f340072e93f3e2072cc00) @@ -29,6 +29,7 @@ using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators; using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators.Assembly; using Ringtoets.ClosingStructures.Data; +using Ringtoets.ClosingStructures.Data.TestUtil; using Ringtoets.ClosingStructures.Forms.Views; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; @@ -83,15 +84,21 @@ public void Constructor_WithParameters_ExpectedValues() { // Setup + var failureMechanism = new ClosingStructuresFailureMechanism(); + var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); - var result = new ClosingStructuresFailureMechanismSectionResult(section); + var result = new ClosingStructuresFailureMechanismSectionResult(section) + { + Calculation = new TestClosingStructuresCalculation + { + Output = new TestStructuresOutput() + } + }; - var failureMechanism = new ClosingStructuresFailureMechanism(); - // Call using (new AssemblyToolCalculatorFactoryConfig()) { @@ -262,126 +269,126 @@ } [Test] - public void SimpleAssessmentResult_AlwaysOnChange_NotifyObserversOfResultAndResultPropertyChanged() + public void GetSectionResultCalculation_NoCalculationSetOnSectionResult_ReturnNull() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); - var observer = mocks.StrictMock(); - observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); + var failureMechanism = new ClosingStructuresFailureMechanism(); + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new ClosingStructuresFailureMechanismSectionResult(section); - result.Attach(observer); - var newValue = new Random(21).NextEnumValue(); - var row = new ClosingStructuresFailureMechanismSectionResultRow(result, - new ClosingStructuresFailureMechanism(), - assessmentSection); + // Precondition + Assert.IsNull(result.Calculation); + var row = new ClosingStructuresFailureMechanismSectionResultRow(result, failureMechanism, assessmentSection); + // Call - row.SimpleAssessmentResult = newValue; + StructuresCalculation calculation = row.GetSectionResultCalculation(); // Assert - Assert.AreEqual(newValue, result.SimpleAssessmentResult); + Assert.IsNull(calculation); mocks.VerifyAll(); } [Test] - public void DetailedAssessmentProbability_NoCalculationSet_ReturnNaN() + public void GetSectionResultCalculation_WithCalculationSetOnSectionResult_ReturnCalculation() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); var failureMechanism = new ClosingStructuresFailureMechanism(); + var expectedCalculation = new StructuresCalculation(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); - var sectionResult = new ClosingStructuresFailureMechanismSectionResult(section); + var result = new ClosingStructuresFailureMechanismSectionResult(section) + { + Calculation = expectedCalculation + }; - // Precondition - Assert.IsNull(sectionResult.Calculation); + var row = new ClosingStructuresFailureMechanismSectionResultRow(result, failureMechanism, assessmentSection); - var resultRow = new ClosingStructuresFailureMechanismSectionResultRow(sectionResult, failureMechanism, assessmentSection); - // Call - double detailedAssessmentProbability = resultRow.DetailedAssessmentProbability; + StructuresCalculation calculation = row.GetSectionResultCalculation(); // Assert - Assert.IsNaN(detailedAssessmentProbability); + Assert.AreSame(expectedCalculation, calculation); mocks.VerifyAll(); } + #region Registration + [Test] - [TestCase(CalculationScenarioStatus.Failed)] - [TestCase(CalculationScenarioStatus.NotCalculated)] - public void DetailedAssessmentProbability_CalculationNotDone_ReturnNaN(CalculationScenarioStatus status) + public void SimpleAssessmentResult_SetNewValue_NotifyObserversAndPropertyChanged() { // Setup - var failureMechanism = new ClosingStructuresFailureMechanism(); - var mocks = new MockRepository(); - IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + var assessmentSection = mocks.Stub(); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); - var calculation = new StructuresCalculation(); - if (status == CalculationScenarioStatus.Failed) - { - calculation.Output = new TestStructuresOutput(double.NaN); - } - FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); - var sectionResult = new ClosingStructuresFailureMechanismSectionResult(section) - { - Calculation = calculation - }; + var result = new ClosingStructuresFailureMechanismSectionResult(section); + result.Attach(observer); - var resultRow = new ClosingStructuresFailureMechanismSectionResultRow(sectionResult, failureMechanism, assessmentSection); + var newValue = new Random(21).NextEnumValue(); - // Call - double detailedAssessmentProbability = resultRow.DetailedAssessmentProbability; + using (new AssemblyToolCalculatorFactoryConfig()) + { + var row = new ClosingStructuresFailureMechanismSectionResultRow(result, + new ClosingStructuresFailureMechanism(), + assessmentSection); - // Assert - Assert.IsNaN(detailedAssessmentProbability); - mocks.VerifyAll(); + // Call + row.SimpleAssessmentResult = newValue; + + // Assert + Assert.AreEqual(newValue, result.SimpleAssessmentResult); + mocks.VerifyAll(); + } } [Test] - public void DetailedAssessmentProbability_CalculationSuccessful_ReturnDetailedAssessmentProbability() + public void DetailedAssessmentResult_SetNewValue_NotifyObserversAndPropertyChanged() { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); - const double reliability = 0.586789; - var calculation = new StructuresCalculation - { - Output = new TestStructuresOutput(reliability) - }; + var random = new Random(39); + var newValue = random.NextEnumValue(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); - var sectionResult = new ClosingStructuresFailureMechanismSectionResult(section) + var result = new ClosingStructuresFailureMechanismSectionResult(section); + result.Attach(observer); + + using (new AssemblyToolCalculatorFactoryConfig()) { - Calculation = calculation - }; + var row = new ClosingStructuresFailureMechanismSectionResultRow( + result, failureMechanism, assessmentSection); - var resultRow = new ClosingStructuresFailureMechanismSectionResultRow(sectionResult, failureMechanism, assessmentSection); + // Call + row.DetailedAssessmentResult = newValue; - // Call - double detailedAssessmentProbability = resultRow.DetailedAssessmentProbability; - - // Assert - Assert.AreEqual(0.2786727127146118, detailedAssessmentProbability); - mocks.VerifyAll(); + // Assert + Assert.AreEqual(newValue, result.DetailedAssessmentResult); + mocks.VerifyAll(); + } } [Test] - public void GetSectionResultCalculation_NoCalculationSetOnSectionResult_ReturnNull() + public void DetailedAssessmentProbability_NoCalculationSet_ReturnNaN() { // Setup var mocks = new MockRepository(); @@ -391,46 +398,94 @@ var failureMechanism = new ClosingStructuresFailureMechanism(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); - var result = new ClosingStructuresFailureMechanismSectionResult(section); + var sectionResult = new ClosingStructuresFailureMechanismSectionResult(section); // Precondition - Assert.IsNull(result.Calculation); + Assert.IsNull(sectionResult.Calculation); - var row = new ClosingStructuresFailureMechanismSectionResultRow(result, failureMechanism, assessmentSection); + using (new AssemblyToolCalculatorFactoryConfig()) + { + var resultRow = new ClosingStructuresFailureMechanismSectionResultRow(sectionResult, failureMechanism, assessmentSection); - // Call - StructuresCalculation calculation = row.GetSectionResultCalculation(); + // Call + double detailedAssessmentProbability = resultRow.DetailedAssessmentProbability; - // Assert - Assert.IsNull(calculation); - mocks.VerifyAll(); + // Assert + Assert.IsNaN(detailedAssessmentProbability); + mocks.VerifyAll(); + } } [Test] - public void GetSectionResultCalculation_WithCalculationSetOnSectionResult_ReturnCalculation() + [TestCase(CalculationScenarioStatus.Failed)] + [TestCase(CalculationScenarioStatus.NotCalculated)] + public void DetailedAssessmentProbability_CalculationNotDone_ReturnNaN(CalculationScenarioStatus status) { // Setup + var failureMechanism = new ClosingStructuresFailureMechanism(); + var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); + var calculation = new StructuresCalculation(); + if (status == CalculationScenarioStatus.Failed) + { + calculation.Output = new TestStructuresOutput(double.NaN); + } + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var sectionResult = new ClosingStructuresFailureMechanismSectionResult(section) + { + Calculation = calculation + }; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var resultRow = new ClosingStructuresFailureMechanismSectionResultRow(sectionResult, failureMechanism, assessmentSection); + + // Call + double detailedAssessmentProbability = resultRow.DetailedAssessmentProbability; + + // Assert + Assert.IsNaN(detailedAssessmentProbability); + mocks.VerifyAll(); + } + } + + [Test] + public void DetailedAssessmentProbability_CalculationSuccessful_ReturnDetailedAssessmentProbability() + { + // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); - var expectedCalculation = new StructuresCalculation(); + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + const double reliability = 0.586789; + var calculation = new StructuresCalculation + { + Output = new TestStructuresOutput(reliability) + }; + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); - var result = new ClosingStructuresFailureMechanismSectionResult(section) + var sectionResult = new ClosingStructuresFailureMechanismSectionResult(section) { - Calculation = expectedCalculation + Calculation = calculation }; - var row = new ClosingStructuresFailureMechanismSectionResultRow(result, failureMechanism, assessmentSection); + using (new AssemblyToolCalculatorFactoryConfig()) + { + var resultRow = new ClosingStructuresFailureMechanismSectionResultRow(sectionResult, failureMechanism, assessmentSection); - // Call - StructuresCalculation calculation = row.GetSectionResultCalculation(); + // Call + double detailedAssessmentProbability = resultRow.DetailedAssessmentProbability; - // Assert - Assert.AreSame(expectedCalculation, calculation); - mocks.VerifyAll(); + // Assert + Assert.AreEqual(0.2786727127146118, detailedAssessmentProbability); + mocks.VerifyAll(); + } } [Test] @@ -456,5 +511,7 @@ Assert.AreEqual(assessmentLayerThree, sectionResult.TailorMadeAssessmentProbability); mocks.VerifyAll(); } + + #endregion } } \ No newline at end of file