Index: Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/HeightStructuresScenarioRow.cs
===================================================================
diff -u -r86594ccd7329d320872573a1d066fe18959d3cea -r6b101883cf554150bd1454ba54784cf325a6e07c
--- Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/HeightStructuresScenarioRow.cs (.../HeightStructuresScenarioRow.cs) (revision 86594ccd7329d320872573a1d066fe18959d3cea)
+++ Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/HeightStructuresScenarioRow.cs (.../HeightStructuresScenarioRow.cs) (revision 6b101883cf554150bd1454ba54784cf325a6e07c)
@@ -20,9 +20,10 @@
// All rights reserved.
using System;
-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.Forms.Views;
using Riskeer.HeightStructures.Data;
namespace Riskeer.HeightStructures.Forms.Views
@@ -31,50 +32,53 @@
/// Container of a ,
/// which takes care of the representation of properties in a grid.
///
- internal class HeightStructuresScenarioRow : IScenarioRow>
+ internal class HeightStructuresScenarioRow : ScenarioRow>
{
- private readonly HeightStructuresFailureMechanismSectionResult sectionResult;
+ private readonly HeightStructuresFailureMechanism 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 HeightStructuresScenarioRow(HeightStructuresFailureMechanismSectionResult sectionResult)
+ public HeightStructuresScenarioRow(StructuresCalculationScenario calculationScenario,
+ HeightStructuresFailureMechanism 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();
}
- ///
- /// Gets the name of the .
- ///
- public string Name
+ public override double FailureProbability => probabilityAssessmentOutput?.Probability ?? double.NaN;
+
+ public override void Update()
{
- get
- {
- return sectionResult.Section.Name;
- }
+ CreateProbabilityAssessmentOutput();
}
- ///
- /// Gets or sets the normative calculation for the section.
- ///
- public StructuresCalculation Calculation
+ private void CreateProbabilityAssessmentOutput()
{
- get
- {
- return sectionResult.Calculation;
- }
- set
- {
- sectionResult.Calculation = value;
- sectionResult.NotifyObservers();
- }
+ probabilityAssessmentOutput = CalculationScenario.HasOutput
+ ? HeightStructuresProbabilityAssessmentOutputFactory.Create(
+ CalculationScenario.Output, failureMechanism, assessmentSection)
+ : null;
}
}
}
\ No newline at end of file
Index: Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/HeightStructuresScenariosView.cs
===================================================================
diff -u -r86594ccd7329d320872573a1d066fe18959d3cea -r6b101883cf554150bd1454ba54784cf325a6e07c
--- Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/HeightStructuresScenariosView.cs (.../HeightStructuresScenariosView.cs) (revision 86594ccd7329d320872573a1d066fe18959d3cea)
+++ Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/HeightStructuresScenariosView.cs (.../HeightStructuresScenariosView.cs) (revision 6b101883cf554150bd1454ba54784cf325a6e07c)
@@ -131,10 +131,10 @@
IDictionary> calculationsPerSegment =
StructuresHelper.CollectCalculationsPerSection(failureMechanism.Sections, calculations.Cast>());
- List scenarioRows =
- FailureMechanism.SectionResults.Select(sectionResult => new HeightStructuresScenarioRow(sectionResult)).ToList();
-
- scenarioSelectionControl.UpdateDataGridViewDataSource(calculations, scenarioRows, calculationsPerSegment);
+ // List scenarioRows =
+ // FailureMechanism.SectionResults.Select(sectionResult => new HeightStructuresScenarioRow(sectionResult)).ToList();
+ //
+ // scenarioSelectionControl.UpdateDataGridViewDataSource(calculations, scenarioRows, calculationsPerSegment);
}
}
}
Index: Riskeer/HeightStructures/test/Riskeer.HeightStructures.Forms.Test/Views/HeightStructuresScenarioRowTest.cs
===================================================================
diff -u -r86594ccd7329d320872573a1d066fe18959d3cea -r6b101883cf554150bd1454ba54784cf325a6e07c
--- Riskeer/HeightStructures/test/Riskeer.HeightStructures.Forms.Test/Views/HeightStructuresScenarioRowTest.cs (.../HeightStructuresScenarioRowTest.cs) (revision 86594ccd7329d320872573a1d066fe18959d3cea)
+++ Riskeer/HeightStructures/test/Riskeer.HeightStructures.Forms.Test/Views/HeightStructuresScenarioRowTest.cs (.../HeightStructuresScenarioRowTest.cs) (revision 6b101883cf554150bd1454ba54784cf325a6e07c)
@@ -20,13 +20,13 @@
// All rights reserved.
using System;
-using Core.Common.Base;
-using Core.Common.Base.Geometry;
using NUnit.Framework;
using Rhino.Mocks;
-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;
using Riskeer.HeightStructures.Data;
using Riskeer.HeightStructures.Forms.Views;
@@ -36,85 +36,190 @@
public class HeightStructuresScenarioRowTest
{
[Test]
- public void ParameteredConstructor_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 HeightStructuresFailureMechanismSectionResult(section);
+ var mocks = new MockRepository();
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
// Call
- var row = new HeightStructuresScenarioRow(sectionResult);
+ void Call() => new HeightStructuresScenarioRow(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 ParameteredConstructor_SectionResultIsNull_ThrowArgumentNullException()
+ public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException()
{
// Call
- TestDelegate call = () => new HeightStructuresScenarioRow(null);
+ void Call() => new HeightStructuresScenarioRow(new StructuresCalculationScenario(),
+ new HeightStructuresFailureMechanism(), 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 HeightStructuresFailureMechanismSectionResult(section);
+ var mocks = new MockRepository();
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
- var row = new HeightStructuresScenarioRow(sectionResult);
+ var calculation = new StructuresCalculationScenario();
- var calculation = new StructuresCalculation();
-
// Call
- row.Calculation = calculation;
+ var row = new HeightStructuresScenarioRow(calculation, new HeightStructuresFailureMechanism(), 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 HeightStructuresFailureMechanism();
+
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 HeightStructuresFailureMechanismSectionResult(section);
- sectionResult.Attach(observer);
+ Output = new TestStructuresOutput()
+ };
- var row = new HeightStructuresScenarioRow(sectionResult);
+ // Call
+ var row = new HeightStructuresScenarioRow(calculation, failureMechanism, assessmentSection);
- var calculation = new StructuresCalculation();
+ // Assert
+ ProbabilityAssessmentOutput expectedDerivedOutput = HeightStructuresProbabilityAssessmentOutputFactory.Create(
+ calculation.Output, failureMechanism, assessmentSection);
+ Assert.AreEqual(expectedDerivedOutput.Probability, row.FailureProbability);
+ mocks.VerifyAll();
+ }
+ [Test]
+ public void Constructor_WithCalculationWithoutOutput_PropertiesFromCalculation()
+ {
+ // Setup
+ var failureMechanism = new HeightStructuresFailureMechanism();
+
+ var mocks = new MockRepository();
+ IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
+ mocks.ReplayAll();
+
+ var calculation = new StructuresCalculationScenario();
+
// Call
- row.Calculation = calculation;
+ var row = new HeightStructuresScenarioRow(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 HeightStructuresFailureMechanism();
+
+ var mocks = new MockRepository();
+ IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
+ mocks.ReplayAll();
+
+ var calculation = new StructuresCalculationScenario();
+
+ var row = new HeightStructuresScenarioRow(calculation, failureMechanism, assessmentSection);
+
+ // Precondition
+ Assert.IsNaN(row.FailureProbability);
+
+ // When
+ calculation.Output = new TestStructuresOutput();
+ row.Update();
+
+ // Then
+ ProbabilityAssessmentOutput expectedDerivedOutput = HeightStructuresProbabilityAssessmentOutputFactory.Create(
+ calculation.Output, failureMechanism, assessmentSection);
+ Assert.AreEqual(expectedDerivedOutput.Probability, row.FailureProbability);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void GivenScenarioRow_WhenOutputSetToNullAndUpdate_ThenDerivedOutputUpdated()
+ {
+ // Given
+ var failureMechanism = new HeightStructuresFailureMechanism();
+
+ var mocks = new MockRepository();
+ IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
+ mocks.ReplayAll();
+
+ var calculation = new StructuresCalculationScenario
+ {
+ Output = new TestStructuresOutput()
+ };
+
+ var row = new HeightStructuresScenarioRow(calculation, failureMechanism, assessmentSection);
+
+ // Precondition
+ ProbabilityAssessmentOutput expectedDerivedOutput = HeightStructuresProbabilityAssessmentOutputFactory.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 HeightStructuresFailureMechanism();
+
+ var mocks = new MockRepository();
+ IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
+ mocks.ReplayAll();
+
+ var calculation = new StructuresCalculationScenario
+ {
+ Output = new TestStructuresOutput()
+ };
+
+ var row = new HeightStructuresScenarioRow(calculation, failureMechanism, assessmentSection);
+
+ // Precondition
+ ProbabilityAssessmentOutput expectedDerivedOutput = HeightStructuresProbabilityAssessmentOutputFactory.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 = HeightStructuresProbabilityAssessmentOutputFactory.Create(
+ calculation.Output, failureMechanism, assessmentSection);
+ Assert.AreEqual(newExpectedDerivedOutput.Probability, row.FailureProbability);
+ mocks.VerifyAll();
+ }
}
}
\ No newline at end of file