Index: Riskeer/ClosingStructures/src/Riskeer.ClosingStructures.Forms/Views/ClosingStructuresScenarioRow.cs
===================================================================
diff -u -rf5cd3b2ee9b7436f606ee6bc027b795accf0549d -ra6476ef37b0f23a37f0e287ad4097c8122ecf4d7
--- Riskeer/ClosingStructures/src/Riskeer.ClosingStructures.Forms/Views/ClosingStructuresScenarioRow.cs (.../ClosingStructuresScenarioRow.cs) (revision f5cd3b2ee9b7436f606ee6bc027b795accf0549d)
+++ Riskeer/ClosingStructures/src/Riskeer.ClosingStructures.Forms/Views/ClosingStructuresScenarioRow.cs (.../ClosingStructuresScenarioRow.cs) (revision a6476ef37b0f23a37f0e287ad4097c8122ecf4d7)
@@ -21,53 +21,64 @@
using System;
using Riskeer.ClosingStructures.Data;
+using Riskeer.Common.Data.AssessmentSection;
+using Riskeer.Common.Data.Probability;
using Riskeer.Common.Data.Structures;
-using Riskeer.Common.Forms;
+using Riskeer.Common.Forms.Views;
namespace Riskeer.ClosingStructures.Forms.Views
{
///
/// Container of a ,
/// which takes care of the representation of properties in a grid.
///
- public class ClosingStructuresScenarioRow : IScenarioRow>
+ public class ClosingStructuresScenarioRow : ScenarioRow>
{
- private readonly ClosingStructuresFailureMechanismSectionResult sectionResult;
+ private readonly ClosingStructuresFailureMechanism failureMechanism;
+ private readonly IAssessmentSection assessmentSection;
+ private ProbabilityAssessmentOutput probabilityAssessmentOutput;
///
- /// Initializes a new instance of the class.
+ /// Creates a new instance of .
+ /// The this row contains.
+ /// The failure mechanism that the calculation belongs to.
+ /// The assessment section that the calculation belongs to.
+ /// Thrown when any parameter is null.
///
- /// The section result.
- /// Thrown when is null.
- public ClosingStructuresScenarioRow(ClosingStructuresFailureMechanismSectionResult sectionResult)
+ public ClosingStructuresScenarioRow(StructuresCalculationScenario calculationScenario,
+ ClosingStructuresFailureMechanism failureMechanism,
+ IAssessmentSection assessmentSection)
+ : base(calculationScenario)
{
- if (sectionResult == null)
+ if (failureMechanism == null)
{
- throw new ArgumentNullException(nameof(sectionResult));
+ throw new ArgumentNullException(nameof(failureMechanism));
}
- this.sectionResult = sectionResult;
+ if (assessmentSection == null)
+ {
+ throw new ArgumentNullException(nameof(assessmentSection));
+ }
+
+ this.failureMechanism = failureMechanism;
+ this.assessmentSection = assessmentSection;
+
+ CreateProbabilityAssessmentOutput();
}
- public string Name
+ public override double FailureProbability => probabilityAssessmentOutput?.Probability ?? double.NaN;
+
+ public override void Update()
{
- get
- {
- return sectionResult.Section.Name;
- }
+ CreateProbabilityAssessmentOutput();
}
- public StructuresCalculation Calculation
+ private void CreateProbabilityAssessmentOutput()
{
- get
- {
- return sectionResult.Calculation;
- }
- set
- {
- sectionResult.Calculation = value;
- sectionResult.NotifyObservers();
- }
+ probabilityAssessmentOutput = CalculationScenario.HasOutput
+ ? ClosingStructuresProbabilityAssessmentOutputFactory.Create(
+ CalculationScenario.Output, failureMechanism, assessmentSection)
+ : null;
}
}
}
\ No newline at end of file
Index: Riskeer/ClosingStructures/test/Riskeer.ClosingStructures.Forms.Test/Views/ClosingStructuresScenarioRowTest.cs
===================================================================
diff -u -rd28e27005c5da2025e65e0544e70f89e5c08b67e -ra6476ef37b0f23a37f0e287ad4097c8122ecf4d7
--- Riskeer/ClosingStructures/test/Riskeer.ClosingStructures.Forms.Test/Views/ClosingStructuresScenarioRowTest.cs (.../ClosingStructuresScenarioRowTest.cs) (revision d28e27005c5da2025e65e0544e70f89e5c08b67e)
+++ Riskeer/ClosingStructures/test/Riskeer.ClosingStructures.Forms.Test/Views/ClosingStructuresScenarioRowTest.cs (.../ClosingStructuresScenarioRowTest.cs) (revision a6476ef37b0f23a37f0e287ad4097c8122ecf4d7)
@@ -20,101 +20,205 @@
// All rights reserved.
using System;
-using Core.Common.Base;
-using Core.Common.Base.Geometry;
using NUnit.Framework;
using Rhino.Mocks;
using Riskeer.ClosingStructures.Data;
using Riskeer.ClosingStructures.Forms.Views;
-using Riskeer.Common.Data.FailureMechanism;
+using Riskeer.Common.Data.AssessmentSection;
+using Riskeer.Common.Data.Probability;
using Riskeer.Common.Data.Structures;
-using Riskeer.Common.Forms;
+using Riskeer.Common.Data.TestUtil;
+using Riskeer.Common.Forms.Views;
namespace Riskeer.ClosingStructures.Forms.Test.Views
{
[TestFixture]
public class ClosingStructuresScenarioRowTest
{
[Test]
- public void Constructor_ExpectedValues()
+ public void Constructor_FailureMechanismNull_ThrowsArgumentNullException()
{
// Setup
- var section = new FailureMechanismSection("testName", new[]
- {
- new Point2D(1.1, 2.2),
- new Point2D(3.3, 4.4)
- });
- var sectionResult = new ClosingStructuresFailureMechanismSectionResult(section);
+ var mocks = new MockRepository();
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
// Call
- var row = new ClosingStructuresScenarioRow(sectionResult);
+ void Call() => new ClosingStructuresScenarioRow(new StructuresCalculationScenario(), null, assessmentSection);
// Assert
- Assert.AreSame(sectionResult.Section.Name, row.Name);
- Assert.AreSame(sectionResult.Calculation, row.Calculation);
- Assert.IsInstanceOf>>(row);
+ var exception = Assert.Throws(Call);
+ Assert.AreEqual("failureMechanism", exception.ParamName);
+ mocks.VerifyAll();
}
[Test]
- public void Constructor_SectionResultIsNull_ThrowArgumentNullException()
+ public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException()
{
// Call
- TestDelegate call = () => new ClosingStructuresScenarioRow(null);
+ void Call() => new ClosingStructuresScenarioRow(new StructuresCalculationScenario(), new ClosingStructuresFailureMechanism(), null);
// Assert
- string paramName = Assert.Throws(call).ParamName;
- Assert.AreSame("sectionResult", paramName);
+ var exception = Assert.Throws(Call);
+ Assert.AreEqual("assessmentSection", exception.ParamName);
}
[Test]
- public void Calculation_SetNewValue_UpdatesSectionResultCalculation()
+ public void Constructor_ExpectedValues()
{
// Setup
- var section = new FailureMechanismSection("haha", new[]
- {
- new Point2D(1.1, 2.2),
- new Point2D(3.3, 4.4)
- });
- var sectionResult = new ClosingStructuresFailureMechanismSectionResult(section);
+ var mocks = new MockRepository();
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
- var row = new ClosingStructuresScenarioRow(sectionResult);
+ var calculation = new StructuresCalculationScenario();
- var calculation = new StructuresCalculation();
-
// Call
- row.Calculation = calculation;
+ var row = new ClosingStructuresScenarioRow(calculation, new ClosingStructuresFailureMechanism(), assessmentSection);
// Assert
- Assert.AreSame(calculation, row.Calculation);
- Assert.AreSame(calculation, sectionResult.Calculation);
+ Assert.IsInstanceOf>>(row);
+ Assert.AreSame(calculation, row.CalculationScenario);
+ mocks.VerifyAll();
}
[Test]
- public void Calculation_SetNewValue_NotifyObserversOnSectionResult()
+ public void Constructor_WithCalculationWithOutput_PropertiesFromCalculation()
{
// Setup
+ var failureMechanism = new ClosingStructuresFailureMechanism();
+
var mocks = new MockRepository();
- var observer = mocks.StrictMock();
- observer.Expect(o => o.UpdateObserver());
+ IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
mocks.ReplayAll();
- var section = new FailureMechanismSection("testSection", new[]
+ var calculation = new StructuresCalculationScenario
{
- new Point2D(1.1, 2.2),
- new Point2D(3.3, 4.4)
- });
- var sectionResult = new ClosingStructuresFailureMechanismSectionResult(section);
- sectionResult.Attach(observer);
+ Output = new TestStructuresOutput()
+ };
- var row = new ClosingStructuresScenarioRow(sectionResult);
+ // Call
+ var row = new ClosingStructuresScenarioRow(calculation, failureMechanism, assessmentSection);
- var calculation = new StructuresCalculation();
+ // Assert
+ ProbabilityAssessmentOutput expectedDerivedOutput = ClosingStructuresProbabilityAssessmentOutputFactory.Create(
+ calculation.Output, failureMechanism, assessmentSection);
+ Assert.AreEqual(expectedDerivedOutput.Probability, row.FailureProbability);
+ mocks.VerifyAll();
+ }
+ [Test]
+ public void Constructor_WithCalculationWithoutOutput_PropertiesFromCalculation()
+ {
+ // Setup
+ var failureMechanism = new ClosingStructuresFailureMechanism();
+
+ var mocks = new MockRepository();
+ IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
+ mocks.ReplayAll();
+
+ var calculation = new StructuresCalculationScenario();
+
// Call
- row.Calculation = calculation;
+ var row = new ClosingStructuresScenarioRow(calculation, failureMechanism, assessmentSection);
// Assert
- mocks.VerifyAll(); // Assert observer is notified
+ Assert.IsNaN(row.FailureProbability);
+ mocks.VerifyAll();
}
+
+ [Test]
+ public void GivenScenarioRow_WhenOutputSetAndUpdate_ThenDerivedOutputUpdated()
+ {
+ // Given
+ var failureMechanism = new ClosingStructuresFailureMechanism();
+
+ var mocks = new MockRepository();
+ IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
+ mocks.ReplayAll();
+
+ var calculation = new StructuresCalculationScenario();
+
+ var row = new ClosingStructuresScenarioRow(calculation, failureMechanism, assessmentSection);
+
+ // Precondition
+ Assert.IsNaN(row.FailureProbability);
+
+ // When
+ calculation.Output = new TestStructuresOutput();
+ row.Update();
+
+ // Then
+ ProbabilityAssessmentOutput expectedDerivedOutput = ClosingStructuresProbabilityAssessmentOutputFactory.Create(
+ calculation.Output, failureMechanism, assessmentSection);
+ Assert.AreEqual(expectedDerivedOutput.Probability, row.FailureProbability);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void GivenScenarioRow_WhenOutputSetToNullAndUpdate_ThenDerivedOutputUpdated()
+ {
+ // Given
+ var failureMechanism = new ClosingStructuresFailureMechanism();
+
+ var mocks = new MockRepository();
+ IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
+ mocks.ReplayAll();
+
+ var calculation = new StructuresCalculationScenario
+ {
+ Output = new TestStructuresOutput()
+ };
+
+ var row = new ClosingStructuresScenarioRow(calculation, failureMechanism, assessmentSection);
+
+ // Precondition
+ ProbabilityAssessmentOutput expectedDerivedOutput = ClosingStructuresProbabilityAssessmentOutputFactory.Create(
+ calculation.Output, failureMechanism, assessmentSection);
+ Assert.AreEqual(expectedDerivedOutput.Probability, row.FailureProbability);
+
+ // When
+ calculation.Output = null;
+ row.Update();
+
+ // Then
+ Assert.IsNaN(row.FailureProbability);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void GivenScenarioRow_WhenOutputChangedAndUpdate_ThenDerivedOutputUpdated()
+ {
+ // Given
+ var failureMechanism = new ClosingStructuresFailureMechanism();
+
+ var mocks = new MockRepository();
+ IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
+ mocks.ReplayAll();
+
+ var calculation = new StructuresCalculationScenario
+ {
+ Output = new TestStructuresOutput()
+ };
+
+ var row = new ClosingStructuresScenarioRow(calculation, failureMechanism, assessmentSection);
+
+ // Precondition
+ ProbabilityAssessmentOutput expectedDerivedOutput = ClosingStructuresProbabilityAssessmentOutputFactory.Create(
+ calculation.Output, failureMechanism, assessmentSection);
+ Assert.AreEqual(expectedDerivedOutput.Probability, row.FailureProbability);
+
+ var random = new Random(11);
+
+ // When
+ calculation.Output = new TestStructuresOutput(random.NextDouble());
+ row.Update();
+
+ // Then
+ ProbabilityAssessmentOutput newExpectedDerivedOutput = ClosingStructuresProbabilityAssessmentOutputFactory.Create(
+ calculation.Output, failureMechanism, assessmentSection);
+ Assert.AreEqual(newExpectedDerivedOutput.Probability, row.FailureProbability);
+ mocks.VerifyAll();
+ }
}
}
\ No newline at end of file