Index: Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Forms/Views/StabilityPointStructuresScenarioRow.cs =================================================================== diff -u -r86594ccd7329d320872573a1d066fe18959d3cea -r1247659c87fbaeb6c5d0c29b9bb64aafd9adbac5 --- Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Forms/Views/StabilityPointStructuresScenarioRow.cs (.../StabilityPointStructuresScenarioRow.cs) (revision 86594ccd7329d320872573a1d066fe18959d3cea) +++ Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Forms/Views/StabilityPointStructuresScenarioRow.cs (.../StabilityPointStructuresScenarioRow.cs) (revision 1247659c87fbaeb6c5d0c29b9bb64aafd9adbac5) @@ -20,54 +20,65 @@ // All rights reserved. using System; +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.StabilityPointStructures.Data; namespace Riskeer.StabilityPointStructures.Forms.Views { /// - /// Container of a , + /// Representation of a /// which takes care of the representation of properties in a grid. /// - public class StabilityPointStructuresScenarioRow : IScenarioRow> + public class StabilityPointStructuresScenarioRow : ScenarioRow> { - private readonly StabilityPointStructuresFailureMechanismSectionResult sectionResult; + private readonly StabilityPointStructuresFailureMechanism 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 StabilityPointStructuresScenarioRow(StabilityPointStructuresFailureMechanismSectionResult sectionResult) + public StabilityPointStructuresScenarioRow(StructuresCalculationScenario calculationScenario, + StabilityPointStructuresFailureMechanism 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 + ? StabilityPointStructuresProbabilityAssessmentOutputFactory.Create( + CalculationScenario.Output, failureMechanism, assessmentSection) + : null; } } } \ No newline at end of file Index: Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Forms/Views/StabilityPointStructuresScenariosView.cs =================================================================== diff -u -r86594ccd7329d320872573a1d066fe18959d3cea -r1247659c87fbaeb6c5d0c29b9bb64aafd9adbac5 --- Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Forms/Views/StabilityPointStructuresScenariosView.cs (.../StabilityPointStructuresScenariosView.cs) (revision 86594ccd7329d320872573a1d066fe18959d3cea) +++ Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Forms/Views/StabilityPointStructuresScenariosView.cs (.../StabilityPointStructuresScenariosView.cs) (revision 1247659c87fbaeb6c5d0c29b9bb64aafd9adbac5) @@ -118,24 +118,24 @@ private void UpdateDataGridViewDataSource() { - scenarioSelectionControl.EndEdit(); - - if (failureMechanism?.SectionResults == null || data?.Children == null) - { - scenarioSelectionControl.ClearDataSource(); - } - else - { - ICalculation[] calculations = data.GetCalculations().ToArray(); - - IDictionary> calculationsPerSegment = - StructuresHelper.CollectCalculationsPerSection(failureMechanism.Sections, - calculations.Cast>()); - - List scenarioRows = failureMechanism.SectionResults.Select(sr => new StabilityPointStructuresScenarioRow(sr)).ToList(); - - scenarioSelectionControl.UpdateDataGridViewDataSource(calculations, scenarioRows, calculationsPerSegment); - } + // scenarioSelectionControl.EndEdit(); + // + // if (failureMechanism?.SectionResults == null || data?.Children == null) + // { + // scenarioSelectionControl.ClearDataSource(); + // } + // else + // { + // ICalculation[] calculations = data.GetCalculations().ToArray(); + // + // IDictionary> calculationsPerSegment = + // StructuresHelper.CollectCalculationsPerSection(failureMechanism.Sections, + // calculations.Cast>()); + // + // List scenarioRows = failureMechanism.SectionResults.Select(sr => new StabilityPointStructuresScenarioRow(sr)).ToList(); + // + // scenarioSelectionControl.UpdateDataGridViewDataSource(calculations, scenarioRows, calculationsPerSegment); + // } } } } \ No newline at end of file Index: Riskeer/StabilityPointStructures/test/Riskeer.StabilityPointStructures.Forms.Test/Views/StabilityPointStructuresScenarioRowTest.cs =================================================================== diff -u -r86594ccd7329d320872573a1d066fe18959d3cea -r1247659c87fbaeb6c5d0c29b9bb64aafd9adbac5 --- Riskeer/StabilityPointStructures/test/Riskeer.StabilityPointStructures.Forms.Test/Views/StabilityPointStructuresScenarioRowTest.cs (.../StabilityPointStructuresScenarioRowTest.cs) (revision 86594ccd7329d320872573a1d066fe18959d3cea) +++ Riskeer/StabilityPointStructures/test/Riskeer.StabilityPointStructures.Forms.Test/Views/StabilityPointStructuresScenarioRowTest.cs (.../StabilityPointStructuresScenarioRowTest.cs) (revision 1247659c87fbaeb6c5d0c29b9bb64aafd9adbac5) @@ -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.StabilityPointStructures.Data; using Riskeer.StabilityPointStructures.Forms.Views; @@ -36,85 +36,189 @@ public class StabilityPointStructuresScenarioRowTest { [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 StabilityPointStructuresFailureMechanismSectionResult(section); + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); // Call - var row = new StabilityPointStructuresScenarioRow(sectionResult); + void Call() => new StabilityPointStructuresScenarioRow(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 StabilityPointStructuresScenarioRow(null); + void Call() => new StabilityPointStructuresScenarioRow(new StructuresCalculationScenario(), new StabilityPointStructuresFailureMechanism(), 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 StabilityPointStructuresFailureMechanismSectionResult(section); + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); - var row = new StabilityPointStructuresScenarioRow(sectionResult); + var calculation = new StructuresCalculationScenario(); - var calculation = new StructuresCalculation(); - // Call - row.Calculation = calculation; + var row = new StabilityPointStructuresScenarioRow(calculation, new StabilityPointStructuresFailureMechanism(), 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 StabilityPointStructuresFailureMechanism(); + 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 StabilityPointStructuresFailureMechanismSectionResult(section); - sectionResult.Attach(observer); + Output = new TestStructuresOutput() + }; - var row = new StabilityPointStructuresScenarioRow(sectionResult); + // Call + var row = new StabilityPointStructuresScenarioRow(calculation, failureMechanism, assessmentSection); - var calculation = new StructuresCalculation(); + // Assert + ProbabilityAssessmentOutput expectedDerivedOutput = StabilityPointStructuresProbabilityAssessmentOutputFactory.Create( + calculation.Output, failureMechanism, assessmentSection); + Assert.AreEqual(expectedDerivedOutput.Probability, row.FailureProbability); + mocks.VerifyAll(); + } + [Test] + public void Constructor_WithCalculationWithoutOutput_PropertiesFromCalculation() + { + // Setup + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + var calculation = new StructuresCalculationScenario(); + // Call - row.Calculation = calculation; + var row = new StabilityPointStructuresScenarioRow(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 StabilityPointStructuresFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + var calculation = new StructuresCalculationScenario(); + + var row = new StabilityPointStructuresScenarioRow(calculation, failureMechanism, assessmentSection); + + // Precondition + Assert.IsNaN(row.FailureProbability); + + // When + calculation.Output = new TestStructuresOutput(); + row.Update(); + + // Then + ProbabilityAssessmentOutput expectedDerivedOutput = StabilityPointStructuresProbabilityAssessmentOutputFactory.Create( + calculation.Output, failureMechanism, assessmentSection); + Assert.AreEqual(expectedDerivedOutput.Probability, row.FailureProbability); + mocks.VerifyAll(); + } + + [Test] + public void GivenScenarioRow_WhenOutputSetToNullAndUpdate_ThenDerivedOutputUpdated() + { + // Given + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + var calculation = new StructuresCalculationScenario + { + Output = new TestStructuresOutput() + }; + + var row = new StabilityPointStructuresScenarioRow(calculation, failureMechanism, assessmentSection); + + // Precondition + ProbabilityAssessmentOutput expectedDerivedOutput = StabilityPointStructuresProbabilityAssessmentOutputFactory.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 StabilityPointStructuresFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + var calculation = new StructuresCalculationScenario + { + Output = new TestStructuresOutput() + }; + + var row = new StabilityPointStructuresScenarioRow(calculation, failureMechanism, assessmentSection); + + // Precondition + ProbabilityAssessmentOutput expectedDerivedOutput = StabilityPointStructuresProbabilityAssessmentOutputFactory.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 = StabilityPointStructuresProbabilityAssessmentOutputFactory.Create( + calculation.Output, failureMechanism, assessmentSection); + Assert.AreEqual(newExpectedDerivedOutput.Probability, row.FailureProbability); + mocks.VerifyAll(); + } } } \ No newline at end of file