Index: Riskeer/Common/src/Riskeer.Common.Forms/Views/AdoptableFailureMechanismSectionResultRow.cs =================================================================== diff -u -r6e3bc0437167a40cf4a79f0f04e31dc61ef4407f -rc20f5b24ecc1b1d69e499cffb5d117b3026810da --- Riskeer/Common/src/Riskeer.Common.Forms/Views/AdoptableFailureMechanismSectionResultRow.cs (.../AdoptableFailureMechanismSectionResultRow.cs) (revision 6e3bc0437167a40cf4a79f0f04e31dc61ef4407f) +++ Riskeer/Common/src/Riskeer.Common.Forms/Views/AdoptableFailureMechanismSectionResultRow.cs (.../AdoptableFailureMechanismSectionResultRow.cs) (revision c20f5b24ecc1b1d69e499cffb5d117b3026810da) @@ -46,7 +46,7 @@ private readonly int sectionProbabilityIndex; private readonly int assemblyGroupIndex; - private readonly Func calculateInitialFailureMechanismResultProbabilityFunc; + private readonly IFailureMechanismSectionResultCalculateProbabilityStrategy calculateProbabilityStrategy; private readonly IFailureMechanismSectionResultRowWithCalculatedProbabilityErrorProvider failureMechanismSectionResultRowErrorProvider; private readonly Func performAssemblyFunc; @@ -55,24 +55,23 @@ /// /// The that is /// the source of this row. - /// The - /// to calculate the initial mechanism result probability. + /// The strategy used to calculate probabilities. /// The error provider to use for /// the failure mechanism section result row. /// Function to perform the assembly. /// The property values required to create an instance of /// . /// Throw when any parameter is null. public AdoptableFailureMechanismSectionResultRow(AdoptableFailureMechanismSectionResult sectionResult, - Func calculateInitialFailureMechanismResultProbabilityFunc, + IFailureMechanismSectionResultCalculateProbabilityStrategy calculateProbabilityStrategy, IFailureMechanismSectionResultRowWithCalculatedProbabilityErrorProvider failureMechanismSectionResultRowErrorProvider, Func performAssemblyFunc, ConstructionProperties constructionProperties) : base(sectionResult) { - if (calculateInitialFailureMechanismResultProbabilityFunc == null) + if (calculateProbabilityStrategy == null) { - throw new ArgumentNullException(nameof(calculateInitialFailureMechanismResultProbabilityFunc)); + throw new ArgumentNullException(nameof(calculateProbabilityStrategy)); } if (failureMechanismSectionResultRowErrorProvider == null) @@ -90,7 +89,7 @@ throw new ArgumentNullException(nameof(constructionProperties)); } - this.calculateInitialFailureMechanismResultProbabilityFunc = calculateInitialFailureMechanismResultProbabilityFunc; + this.calculateProbabilityStrategy = calculateProbabilityStrategy; this.failureMechanismSectionResultRowErrorProvider = failureMechanismSectionResultRowErrorProvider; this.performAssemblyFunc = performAssemblyFunc; @@ -140,7 +139,7 @@ public double InitialFailureMechanismResultSectionProbability { get => SectionResult.InitialFailureMechanismResultType == AdoptableInitialFailureMechanismResultType.Adopt - ? calculateInitialFailureMechanismResultProbabilityFunc() + ? calculateProbabilityStrategy.CalculateSectionProbability() : SectionResult.ManualInitialFailureMechanismResultSectionProbability; set { @@ -205,7 +204,7 @@ if (SectionResult.InitialFailureMechanismResultType == AdoptableInitialFailureMechanismResultType.Adopt) { ColumnStateDefinitions[initialFailureMechanismResultSectionProbabilityIndex].ErrorText = failureMechanismSectionResultRowErrorProvider.GetCalculatedProbabilityValidationError( - calculateInitialFailureMechanismResultProbabilityFunc); + calculateProbabilityStrategy.CalculateSectionProbability); } if (SectionResult.InitialFailureMechanismResultType == AdoptableInitialFailureMechanismResultType.Manual) Index: Riskeer/Common/src/Riskeer.Common.Forms/Views/StructuresFailureMechanismResultView.cs =================================================================== diff -u -r6e3bc0437167a40cf4a79f0f04e31dc61ef4407f -rc20f5b24ecc1b1d69e499cffb5d117b3026810da --- Riskeer/Common/src/Riskeer.Common.Forms/Views/StructuresFailureMechanismResultView.cs (.../StructuresFailureMechanismResultView.cs) (revision 6e3bc0437167a40cf4a79f0f04e31dc61ef4407f) +++ Riskeer/Common/src/Riskeer.Common.Forms/Views/StructuresFailureMechanismResultView.cs (.../StructuresFailureMechanismResultView.cs) (revision c20f5b24ecc1b1d69e499cffb5d117b3026810da) @@ -94,7 +94,7 @@ return new AdoptableFailureMechanismSectionResultRow( sectionResult, - () => sectionResult.GetInitialFailureMechanismResultProbability(calculationScenarios), + CreateCalculateStrategy(sectionResult, calculationScenarios), CreateErrorProvider(sectionResult, calculationScenarios), () => StructuresFailureMechanismAssemblyFactory.AssembleSection(sectionResult, FailureMechanism, AssessmentSection), new AdoptableFailureMechanismSectionResultRow.ConstructionProperties @@ -158,5 +158,13 @@ sectionResult, calculationScenarios, (scenario, lineSegments) => scenario.IsStructureIntersectionWithReferenceLineInSection(lineSegments)); } + + private static StructuresFailureMechanismSectionResultCalculateProbabilityStrategy CreateCalculateStrategy( + AdoptableFailureMechanismSectionResult sectionResult, + IEnumerable> calculationScenarios) + { + return new StructuresFailureMechanismSectionResultCalculateProbabilityStrategy( + sectionResult, calculationScenarios); + } } } \ No newline at end of file Index: Riskeer/Common/test/Riskeer.Common.Forms.Test/Views/AdoptableFailureMechanismSectionResultRowTest.cs =================================================================== diff -u -r6e3bc0437167a40cf4a79f0f04e31dc61ef4407f -rc20f5b24ecc1b1d69e499cffb5d117b3026810da --- Riskeer/Common/test/Riskeer.Common.Forms.Test/Views/AdoptableFailureMechanismSectionResultRowTest.cs (.../AdoptableFailureMechanismSectionResultRowTest.cs) (revision 6e3bc0437167a40cf4a79f0f04e31dc61ef4407f) +++ Riskeer/Common/test/Riskeer.Common.Forms.Test/Views/AdoptableFailureMechanismSectionResultRowTest.cs (.../AdoptableFailureMechanismSectionResultRowTest.cs) (revision c20f5b24ecc1b1d69e499cffb5d117b3026810da) @@ -58,7 +58,7 @@ }; [Test] - public void Constructor_CalculateInitialFailureMechanismResultProbabilityFuncNull_ThrowsArgumentNullException() + public void Constructor_CalculateProbabilityStrategyNull_ThrowsArgumentNullException() { // Setup var mocks = new MockRepository(); @@ -76,21 +76,25 @@ // Assert var exception = Assert.Throws(Call); - Assert.AreEqual("calculateInitialFailureMechanismResultProbabilityFunc", exception.ParamName); + Assert.AreEqual("calculateProbabilityStrategy", exception.ParamName); mocks.VerifyAll(); } [Test] - public void Constructor_FailureMechanismSectionResultErrorProviderNull_ThrowsArgumentNullException() + public void Constructor_FailureMechanismSectionResultRowErrorProviderNull_ThrowsArgumentNullException() { // Setup + var mocks = new MockRepository(); + var calculateStrategy = mocks.Stub(); + mocks.ReplayAll(); + Func performAssemblyFunc = FailureMechanismSectionAssemblyResultWrapperTestFactory.Create; FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new AdoptableFailureMechanismSectionResult(section); // Call - void Call() => new AdoptableFailureMechanismSectionResultRow(result, () => double.NaN, null, performAssemblyFunc, + void Call() => new AdoptableFailureMechanismSectionResultRow(result, calculateStrategy, null, performAssemblyFunc, ConstructionProperties); // Assert @@ -103,14 +107,15 @@ { // Setup var mocks = new MockRepository(); + var calculateStrategy = mocks.Stub(); var errorProvider = mocks.Stub(); mocks.ReplayAll(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new AdoptableFailureMechanismSectionResult(section); // Call - void Call() => new AdoptableFailureMechanismSectionResultRow(result, () => double.NaN, errorProvider, + void Call() => new AdoptableFailureMechanismSectionResultRow(result, calculateStrategy, errorProvider, null, ConstructionProperties); // Assert @@ -124,6 +129,7 @@ { // Setup var mocks = new MockRepository(); + var calculateStrategy = mocks.Stub(); var errorProvider = mocks.Stub(); mocks.ReplayAll(); @@ -133,7 +139,7 @@ var result = new AdoptableFailureMechanismSectionResult(section); // Call - void Call() => new AdoptableFailureMechanismSectionResultRow(result, () => double.NaN, errorProvider, + void Call() => new AdoptableFailureMechanismSectionResultRow(result, calculateStrategy, errorProvider, performAssemblyFunc, null); // Assert @@ -146,7 +152,11 @@ public void Constructor_ExpectedValues() { // Setup + double initialFailureMechanismResultProbability = new Random(21).NextDouble(); + var mocks = new MockRepository(); + var calculateStrategy = mocks.Stub(); + calculateStrategy.Stub(c => c.CalculateSectionProbability()).Return(initialFailureMechanismResultProbability); var errorProvider = mocks.Stub(); mocks.ReplayAll(); @@ -155,10 +165,9 @@ FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new AdoptableFailureMechanismSectionResult(section); - double initialFailureMechanismResultProbability = new Random(21).NextDouble(); // Call - var row = new AdoptableFailureMechanismSectionResultRow(result, () => initialFailureMechanismResultProbability, errorProvider, + var row = new AdoptableFailureMechanismSectionResultRow(result, calculateStrategy, errorProvider, performAssemblyFunc, ConstructionProperties); // Assert @@ -195,16 +204,19 @@ public void GivenRowWithInitialFailureMechanismResultTypeAdopt_WhenValueChanged_ThenInitialProbabilitiesChanged(AdoptableInitialFailureMechanismResultType newValue) { // Given + double sectionProbability = new Random(21).NextDouble(); + var mocks = new MockRepository(); + var calculateStrategy = mocks.Stub(); + calculateStrategy.Stub(c => c.CalculateSectionProbability()).Return(sectionProbability); var errorProvider = mocks.Stub(); mocks.ReplayAll(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new AdoptableFailureMechanismSectionResult(section); - double sectionProbability = new Random(21).NextDouble(); Func performAssemblyFunc = FailureMechanismSectionAssemblyResultWrapperTestFactory.Create; - var row = new AdoptableFailureMechanismSectionResultRow(result, () => sectionProbability, errorProvider, + var row = new AdoptableFailureMechanismSectionResultRow(result, calculateStrategy, errorProvider, performAssemblyFunc, ConstructionProperties); // Precondition @@ -225,6 +237,7 @@ // Given const string errorText = "error"; var mocks = new MockRepository(); + var calculateStrategy = mocks.Stub(); var errorProvider = mocks.StrictMock(); errorProvider.Expect(ep => ep.GetCalculatedProbabilityValidationError(null)) .IgnoreArguments() @@ -237,7 +250,7 @@ Func performAssemblyFunc = FailureMechanismSectionAssemblyResultWrapperTestFactory.Create; // When - var row = new AdoptableFailureMechanismSectionResultRow(result, () => double.NaN, errorProvider, + var row = new AdoptableFailureMechanismSectionResultRow(result, calculateStrategy, errorProvider, performAssemblyFunc, ConstructionProperties); // Then @@ -256,6 +269,7 @@ const string errorText = "error"; var mocks = new MockRepository(); + var calculateStrategy = mocks.Stub(); var errorProvider = mocks.StrictMock(); errorProvider.Expect(ep => ep.GetManualProbabilityValidationError(sectionProbability)) .Return(errorText); @@ -271,7 +285,7 @@ Func performAssemblyFunc = FailureMechanismSectionAssemblyResultWrapperTestFactory.Create; // When - var row = new AdoptableFailureMechanismSectionResultRow(result, () => double.NaN, errorProvider, + var row = new AdoptableFailureMechanismSectionResultRow(result, calculateStrategy, errorProvider, performAssemblyFunc, ConstructionProperties); // Then @@ -290,6 +304,7 @@ { // Given var mocks = new MockRepository(); + var calculateStrategy = mocks.Stub(); var errorProvider = mocks.StrictMock(); errorProvider.Stub(ep => ep.GetCalculatedProbabilityValidationError(null)) .IgnoreArguments() @@ -306,7 +321,7 @@ Func performAssemblyFunc = FailureMechanismSectionAssemblyResultWrapperTestFactory.Create; // When - var row = new AdoptableFailureMechanismSectionResultRow(result, () => double.NaN, errorProvider, + var row = new AdoptableFailureMechanismSectionResultRow(result, calculateStrategy, errorProvider, performAssemblyFunc, ConstructionProperties); // Then @@ -325,6 +340,7 @@ const string errorText = "error"; var mocks = new MockRepository(); + var calculateStrategy = mocks.Stub(); var errorProvider = mocks.StrictMock(); errorProvider.Stub(ep => ep.GetCalculatedProbabilityValidationError(null)) .IgnoreArguments() @@ -343,7 +359,7 @@ Func performAssemblyFunc = FailureMechanismSectionAssemblyResultWrapperTestFactory.Create; // When - var row = new AdoptableFailureMechanismSectionResultRow(result, () => double.NaN, errorProvider, + var row = new AdoptableFailureMechanismSectionResultRow(result, calculateStrategy, errorProvider, performAssemblyFunc, ConstructionProperties); // Then @@ -360,6 +376,7 @@ { // Given var mocks = new MockRepository(); + var calculateStrategy = mocks.Stub(); var errorProvider = mocks.StrictMock(); errorProvider.Stub(ep => ep.GetCalculatedProbabilityValidationError(null)) .IgnoreArguments() @@ -378,7 +395,7 @@ Func performAssemblyFunc = FailureMechanismSectionAssemblyResultWrapperTestFactory.Create; // When - var row = new AdoptableFailureMechanismSectionResultRow(result, () => double.NaN, errorProvider, + var row = new AdoptableFailureMechanismSectionResultRow(result, calculateStrategy, errorProvider, performAssemblyFunc, ConstructionProperties); // Then @@ -463,6 +480,7 @@ { // Setup var mocks = new MockRepository(); + var calculateStrategy = mocks.Stub(); var errorProvider = mocks.Stub(); var observer = mocks.StrictMock(); observer.Expect(o => o.UpdateObserver()); @@ -473,7 +491,7 @@ result.Attach(observer); Func performAssemblyFunc = FailureMechanismSectionAssemblyResultWrapperTestFactory.Create; - var row = new AdoptableFailureMechanismSectionResultRow(result, () => double.NaN, errorProvider, + var row = new AdoptableFailureMechanismSectionResultRow(result, calculateStrategy, errorProvider, performAssemblyFunc, ConstructionProperties); // Call @@ -490,6 +508,7 @@ { // Setup var mocks = new MockRepository(); + var calculateStrategy = mocks.Stub(); var errorProvider = mocks.Stub(); mocks.ReplayAll(); @@ -498,7 +517,7 @@ Func performAssemblyFunc = FailureMechanismSectionAssemblyResultWrapperTestFactory.Create; - var row = new AdoptableFailureMechanismSectionResultRow(result, () => double.NaN, errorProvider, + var row = new AdoptableFailureMechanismSectionResultRow(result, calculateStrategy, errorProvider, performAssemblyFunc, ConstructionProperties); // Call @@ -520,6 +539,7 @@ { // Setup var mocks = new MockRepository(); + var calculateStrategy = mocks.Stub(); var errorProvider = mocks.Stub(); mocks.ReplayAll(); @@ -530,7 +550,7 @@ Func performAssemblyFunc = () => assemblyResultWrapper; // Call - var row = new AdoptableFailureMechanismSectionResultRow(result, () => double.NaN, errorProvider, + var row = new AdoptableFailureMechanismSectionResultRow(result, calculateStrategy, errorProvider, performAssemblyFunc, ConstructionProperties); // Assert @@ -547,6 +567,7 @@ { // Given var mocks = new MockRepository(); + var calculateStrategy = mocks.Stub(); var errorProvider = mocks.Stub(); mocks.ReplayAll(); @@ -567,7 +588,7 @@ return assemblyResultWrapper; }; - var row = new AdoptableFailureMechanismSectionResultRow(result, () => double.NaN, errorProvider, + var row = new AdoptableFailureMechanismSectionResultRow(result, calculateStrategy, errorProvider, performAssemblyFunc, ConstructionProperties); // Precondition @@ -593,6 +614,7 @@ { // Given var mocks = new MockRepository(); + var calculateStrategy = mocks.Stub(); var errorProvider = mocks.Stub(); mocks.ReplayAll(); @@ -612,7 +634,7 @@ return FailureMechanismSectionAssemblyResultWrapperTestFactory.Create(); }; - var row = new AdoptableFailureMechanismSectionResultRow(result, () => double.NaN, errorProvider, + var row = new AdoptableFailureMechanismSectionResultRow(result, calculateStrategy, errorProvider, performAssemblyFunc, ConstructionProperties); // Precondition @@ -635,6 +657,7 @@ { // Given var mocks = new MockRepository(); + var calculateStrategy = mocks.Stub(); var errorProvider = mocks.Stub(); mocks.ReplayAll(); @@ -654,7 +677,7 @@ return FailureMechanismSectionAssemblyResultWrapperTestFactory.Create(); }; - var row = new AdoptableFailureMechanismSectionResultRow(result, () => double.NaN, errorProvider, + var row = new AdoptableFailureMechanismSectionResultRow(result, calculateStrategy, errorProvider, performAssemblyFunc, ConstructionProperties); // Precondition @@ -683,6 +706,7 @@ { // Setup var mocks = new MockRepository(); + var calculateStrategy = mocks.Stub(); var errorProvider = mocks.Stub(); mocks.ReplayAll(); @@ -692,7 +716,7 @@ Func performAssemblyFunc = FailureMechanismSectionAssemblyResultWrapperTestFactory.Create; // Call - var row = new AdoptableFailureMechanismSectionResultRow(result, () => double.NaN, errorProvider, + var row = new AdoptableFailureMechanismSectionResultRow(result, calculateStrategy, errorProvider, performAssemblyFunc, ConstructionProperties); // Assert @@ -711,6 +735,7 @@ { // Setup var mocks = new MockRepository(); + var calculateStrategy = mocks.Stub(); var errorProvider = mocks.Stub(); errorProvider.Stub(ep => ep.GetManualProbabilityValidationError(double.NaN)) .Return(string.Empty); @@ -727,7 +752,7 @@ Func performAssemblyFunc = FailureMechanismSectionAssemblyResultWrapperTestFactory.Create; // Call - var row = new AdoptableFailureMechanismSectionResultRow(result, () => double.NaN, errorProvider, + var row = new AdoptableFailureMechanismSectionResultRow(result, calculateStrategy, errorProvider, performAssemblyFunc, ConstructionProperties); // Assert @@ -754,6 +779,7 @@ { // Setup var mocks = new MockRepository(); + var calculateStrategy = mocks.Stub(); var errorProvider = mocks.Stub(); errorProvider.Stub(ep => ep.GetCalculatedProbabilityValidationError(null)) .IgnoreArguments() @@ -771,7 +797,7 @@ Func performAssemblyFunc = FailureMechanismSectionAssemblyResultWrapperTestFactory.Create; // Call - var row = new AdoptableFailureMechanismSectionResultRow(result, () => double.NaN, errorProvider, + var row = new AdoptableFailureMechanismSectionResultRow(result, calculateStrategy, errorProvider, performAssemblyFunc, ConstructionProperties); // Assert @@ -792,6 +818,7 @@ { // Setup var mocks = new MockRepository(); + var calculateStrategy = mocks.Stub(); var errorProvider = mocks.Stub(); errorProvider.Stub(ep => ep.GetCalculatedProbabilityValidationError(null)) .IgnoreArguments() @@ -810,7 +837,7 @@ Func performAssemblyFunc = FailureMechanismSectionAssemblyResultWrapperTestFactory.Create; // Call - var row = new AdoptableFailureMechanismSectionResultRow(result, () => double.NaN, errorProvider, + var row = new AdoptableFailureMechanismSectionResultRow(result, calculateStrategy, errorProvider, performAssemblyFunc, ConstructionProperties); // Assert @@ -829,6 +856,7 @@ { // Setup var mocks = new MockRepository(); + var calculateStrategy = mocks.Stub(); var errorProvider = mocks.Stub(); mocks.ReplayAll(); @@ -841,7 +869,7 @@ AssemblyMethod.BOI0A1, AssemblyMethod.BOI0B1); // Call - var row = new AdoptableFailureMechanismSectionResultRow(result, () => double.NaN, errorProvider, + var row = new AdoptableFailureMechanismSectionResultRow(result, calculateStrategy, errorProvider, performAssemblyFunc, ConstructionProperties); // Assert