Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Views/ClosingStructuresFailureMechanismSectionResultRow.cs =================================================================== diff -u -r8dddc6b41ea847c80b1be688b7a97a2fbd79be79 -rf665294814c085178591a35d0d811a1df72feb55 --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Views/ClosingStructuresFailureMechanismSectionResultRow.cs (.../ClosingStructuresFailureMechanismSectionResultRow.cs) (revision 8dddc6b41ea847c80b1be688b7a97a2fbd79be79) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Views/ClosingStructuresFailureMechanismSectionResultRow.cs (.../ClosingStructuresFailureMechanismSectionResultRow.cs) (revision f665294814c085178591a35d0d811a1df72feb55) @@ -61,7 +61,7 @@ /// Creates a new instance of . /// /// The to wrap - /// so that it can be displayed as a row. + /// so that it can be displayed as a row. /// The failure mechanism the result belongs to. /// The assessment section the result belongs to. /// The property values required to create an instance of Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj =================================================================== diff -u -rd7696913d8f9239cb80eb2c3bac6cc0ccf23d479 -rf665294814c085178591a35d0d811a1df72feb55 --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj (.../Ringtoets.Piping.Forms.csproj) (revision d7696913d8f9239cb80eb2c3bac6cc0ccf23d479) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj (.../Ringtoets.Piping.Forms.csproj) (revision f665294814c085178591a35d0d811a1df72feb55) @@ -142,6 +142,11 @@ Core.Components.OxyPlot.Forms False + + {420ED9C3-0C33-47EA-B893-121A9C0DB4F1} + Ringtoets.AssemblyTool.Data + False + {d4200f43-3f72-4f42-af0a-8ced416a38ec} Ringtoets.Common.Data Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingFailureMechanismResultView.cs =================================================================== diff -u -r1c200c32948d83b6a93a92da6a728120634e6e4f -rf665294814c085178591a35d0d811a1df72feb55 --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingFailureMechanismResultView.cs (.../PipingFailureMechanismResultView.cs) (revision 1c200c32948d83b6a93a92da6a728120634e6e4f) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingFailureMechanismResultView.cs (.../PipingFailureMechanismResultView.cs) (revision f665294814c085178591a35d0d811a1df72feb55) @@ -21,16 +21,12 @@ using System; using System.Linq; -using System.Windows.Forms; using Core.Common.Base; -using Core.Common.Util; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; -using Ringtoets.Common.Forms.Helpers; +using Ringtoets.Common.Forms.Builders; using Ringtoets.Common.Forms.Views; -using Ringtoets.Common.Primitives; using Ringtoets.Piping.Data; -using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.Piping.Forms.Views { @@ -40,8 +36,18 @@ public class PipingFailureMechanismResultView : FailureMechanismResultView { - private const int detailedAssessmentIndex = 2; - private const double tolerance = 1e-6; + private const int simpleAssessmentResultIndex = 1; + private const int detailedAssessmentResultIndex = 2; + private const int detailedAssessmentProbabilityIndex = 3; + private const int tailorMadeAssessmentResultIndex = 4; + private const int tailorMadeAssessmentProbabilityIndex = 5; + private const int simpleAssemblyCategoryGroupIndex = 6; + private const int detailedAssemblyCategoryGroupIndex = 7; + private const int tailorMadeAssemblyCategoryGroupIndex = 8; + private const int combinedAssemblyCategoryGroupIndex = 9; + private const int combinedAssemblyProbabilityIndex = 10; + private const int manualAssemblyProbabilityIndex = 12; + private readonly RecursiveObserver calculationInputObserver; private readonly RecursiveObserver calculationOutputObserver; private readonly RecursiveObserver calculationGroupObserver; @@ -68,7 +74,7 @@ failureMechanismObserver = new Observer(UpdateDataGridViewDataSource) { Observable = failureMechanism - }; + }; // The concat is needed to observe the input of calculations in child groups. calculationInputObserver = new RecursiveObserver( @@ -93,9 +99,6 @@ protected override void Dispose(bool disposing) { - DataGridViewControl.CellFormatting -= ShowDetailedAssessmentErrors; - DataGridViewControl.CellFormatting -= DisableIrrelevantFieldsFormatting; - calculationInputObserver.Dispose(); calculationOutputObserver.Dispose(); calculationGroupObserver.Dispose(); @@ -106,115 +109,80 @@ protected override PipingFailureMechanismSectionResultRow CreateFailureMechanismSectionResultRow(PipingFailureMechanismSectionResult sectionResult) { - return new PipingFailureMechanismSectionResultRow(sectionResult, FailureMechanism.Calculations.Cast(), - FailureMechanism, assessmentSection); + return new PipingFailureMechanismSectionResultRow( + sectionResult, + FailureMechanism.Calculations.Cast(), + FailureMechanism, + assessmentSection, + new PipingFailureMechanismSectionResultRow.ConstructionProperties + { + SimpleAssessmentResultIndex = simpleAssessmentResultIndex, + DetailedAssessmentResultIndex = detailedAssessmentResultIndex, + DetailedAssessmentProbabilityIndex = detailedAssessmentProbabilityIndex, + TailorMadeAssessmentResultIndex = tailorMadeAssessmentResultIndex, + TailorMadeAssessmentProbabilityIndex = tailorMadeAssessmentProbabilityIndex, + SimpleAssemblyCategoryGroupIndex = simpleAssemblyCategoryGroupIndex, + DetailedAssemblyCategoryGroupIndex = detailedAssemblyCategoryGroupIndex, + TailorMadeAssemblyCategoryGroupIndex = tailorMadeAssemblyCategoryGroupIndex, + CombinedAssemblyCategoryGroupIndex = combinedAssemblyCategoryGroupIndex, + CombinedAssemblyProbabilityIndex = combinedAssemblyProbabilityIndex, + ManualAssemblyProbabilityIndex = manualAssemblyProbabilityIndex + }); } protected override void AddDataGridColumns() { - DataGridViewControl.AddTextBoxColumn( - nameof(PipingFailureMechanismSectionResultRow.Name), - RingtoetsCommonFormsResources.Section_DisplayName, - true); + FailureMechanismSectionResultViewColumnBuilder.AddSectionNameColumn( + DataGridViewControl, + nameof(PipingFailureMechanismSectionResultRow.Name)); - EnumDisplayWrapper[] simpleAssessmentDataSource = - Enum.GetValues(typeof(SimpleAssessmentResultType)) - .OfType() - .Select(sa => new EnumDisplayWrapper(sa)) - .ToArray(); + FailureMechanismSectionResultViewColumnBuilder.AddSimpleAssessmentResultColumn( + DataGridViewControl, + nameof(PipingFailureMechanismSectionResultRow.SimpleAssessmentResult)); - DataGridViewControl.AddComboBoxColumn( - nameof(PipingFailureMechanismSectionResultRow.SimpleAssessmentResult), - RingtoetsCommonFormsResources.FailureMechanismResultView_SimpleAssessmentResult_DisplayName, - simpleAssessmentDataSource, - nameof(EnumDisplayWrapper.Value), - nameof(EnumDisplayWrapper.DisplayName)); + FailureMechanismSectionResultViewColumnBuilder.AddDetailedAssessmentResultColumn( + DataGridViewControl, + nameof(PipingFailureMechanismSectionResultRow.DetailedAssessmentResult)); - DataGridViewControl.AddTextBoxColumn( - nameof(PipingFailureMechanismSectionResultRow.DetailedAssessmentProbability), - RingtoetsCommonFormsResources.FailureMechanismResultView_DetailedAssessmentResult_DisplayName, - true); - DataGridViewControl.AddTextBoxColumn( - nameof(PipingFailureMechanismSectionResultRow.TailorMadeAssessmentProbability), - RingtoetsCommonFormsResources.FailureMechanismResultView_TailorMadeAssessmentResult_DisplayName); - } + FailureMechanismSectionResultViewColumnBuilder.AddDetailedAssessmentProbabilityColumn( + DataGridViewControl, + nameof(PipingFailureMechanismSectionResultRow.DetailedAssessmentProbability)); - protected override void BindEvents() - { - base.BindEvents(); + FailureMechanismSectionResultViewColumnBuilder.AddTailorMadeAssessmentProbabilityCalculationResultColumn( + DataGridViewControl, + nameof(PipingFailureMechanismSectionResultRow.TailorMadeAssessmentResult)); - DataGridViewControl.CellFormatting += ShowDetailedAssessmentErrors; - DataGridViewControl.CellFormatting += DisableIrrelevantFieldsFormatting; - } + FailureMechanismSectionResultViewColumnBuilder.AddTailorMadeAssessmentProbabilityColumn( + DataGridViewControl, + nameof(PipingFailureMechanismSectionResultRow.TailorMadeAssessmentProbability)); - #region Event handling + FailureMechanismSectionResultViewColumnBuilder.AddSimpleAssemblyCategoryGroupColumn( + DataGridViewControl, + nameof(PipingFailureMechanismSectionResultRow.SimpleAssemblyCategoryGroup)); - private void DisableIrrelevantFieldsFormatting(object sender, DataGridViewCellFormattingEventArgs eventArgs) - { + FailureMechanismSectionResultViewColumnBuilder.AddDetailedAssemblyCategoryGroupColumn( + DataGridViewControl, + nameof(PipingFailureMechanismSectionResultRow.DetailedAssemblyCategoryGroup)); - if (eventArgs.ColumnIndex > SimpleAssessmentColumnIndex) - { - SimpleAssessmentResultType simpleAssessmentResult = GetDataAtRow(eventArgs.RowIndex).SimpleAssessmentResult; - if (FailureMechanismSectionResultRowHelper.SimpleAssessmentIsSufficient(simpleAssessmentResult)) - { - DataGridViewControl.DisableCell(eventArgs.RowIndex, eventArgs.ColumnIndex); - } - else - { - DataGridViewControl.RestoreCell(eventArgs.RowIndex, eventArgs.ColumnIndex); - } - } - } + FailureMechanismSectionResultViewColumnBuilder.AddTailorMadeAssemblyCategoryGroupColumn( + DataGridViewControl, + nameof(PipingFailureMechanismSectionResultRow.TailorMadeAssemblyCategoryGroup)); - private void ShowDetailedAssessmentErrors(object sender, DataGridViewCellFormattingEventArgs e) - { - if (e.ColumnIndex != detailedAssessmentIndex) - { - return; - } + FailureMechanismSectionResultViewColumnBuilder.AddCombinedAssemblyCategoryGroupColumn( + DataGridViewControl, + nameof(PipingFailureMechanismSectionResultRow.CombinedAssemblyCategoryGroup)); - DataGridViewCell currentDataGridViewCell = DataGridViewControl.GetCell(e.RowIndex, e.ColumnIndex); + FailureMechanismSectionResultViewColumnBuilder.AddCombinedAssemblyProbabilityColumn( + DataGridViewControl, + nameof(PipingFailureMechanismSectionResultRow.CombinedAssemblyProbability)); - PipingFailureMechanismSectionResultRow resultRow = GetDataAtRow(e.RowIndex); - PipingFailureMechanismSectionResult rowObject = resultRow.GetSectionResult; - if (rowObject.SimpleAssessmentResult == SimpleAssessmentResultType.ProbabilityNegligible - || rowObject.SimpleAssessmentResult == SimpleAssessmentResultType.NotApplicable) - { - currentDataGridViewCell.ErrorText = string.Empty; - return; - } + FailureMechanismSectionResultViewColumnBuilder.AddUseManualAssemblyCategoryGroupColumn( + DataGridViewControl, + nameof(PipingFailureMechanismSectionResultRow.UseManualAssemblyProbability)); - PipingCalculationScenario[] relevantScenarios = rowObject.GetCalculationScenarios(FailureMechanism.Calculations.OfType()).ToArray(); - bool relevantScenarioAvailable = relevantScenarios.Length != 0; - - if (!relevantScenarioAvailable) - { - currentDataGridViewCell.ErrorText = RingtoetsCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_Not_any_calculation_set; - return; - } - - if (Math.Abs(rowObject.GetTotalContribution(relevantScenarios) - 1.0) > tolerance) - { - currentDataGridViewCell.ErrorText = RingtoetsCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_Scenario_contribution_for_this_section_not_100; - return; - } - - CalculationScenarioStatus calculationScenarioStatus = rowObject.GetCalculationScenarioStatus(relevantScenarios); - if (calculationScenarioStatus == CalculationScenarioStatus.NotCalculated) - { - currentDataGridViewCell.ErrorText = RingtoetsCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_Not_all_calculations_have_been_executed; - return; - } - - if (double.IsNaN(resultRow.DetailedAssessmentProbability)) - { - currentDataGridViewCell.ErrorText = RingtoetsCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_All_calculations_must_have_valid_output; - return; - } - - currentDataGridViewCell.ErrorText = string.Empty; + FailureMechanismSectionResultViewColumnBuilder.AddManualAssemblyProbabilityColumn( + DataGridViewControl, + nameof(PipingFailureMechanismSectionResultRow.ManualAssemblyProbability)); } - - #endregion } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingFailureMechanismSectionResultRow.cs =================================================================== diff -u -r1c200c32948d83b6a93a92da6a728120634e6e4f -rf665294814c085178591a35d0d811a1df72feb55 --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingFailureMechanismSectionResultRow.cs (.../PipingFailureMechanismSectionResultRow.cs) (revision 1c200c32948d83b6a93a92da6a728120634e6e4f) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingFailureMechanismSectionResultRow.cs (.../PipingFailureMechanismSectionResultRow.cs) (revision f665294814c085178591a35d0d811a1df72feb55) @@ -22,23 +22,45 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Linq; +using Core.Common.Controls.DataGrid; +using Ringtoets.AssemblyTool.Data; using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Exceptions; +using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.TypeConverters; using Ringtoets.Common.Forms.Views; using Ringtoets.Common.Primitives; using Ringtoets.Piping.Data; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.Piping.Forms.Views { /// - /// Container of a , which takes care of the - /// representation of properties in a grid. + /// This class represents a row of . /// public class PipingFailureMechanismSectionResultRow : FailureMechanismSectionResultRow { + private readonly int simpleAssessmentResultIndex; + private readonly int detailedAssessmentResultIndex; + private readonly int detailedAssessmentProbabilityIndex; + private readonly int tailorMadeAssessmentResultIndex; + private readonly int tailorMadeAssessmentProbabilityIndex; + private readonly int simpleAssemblyCategoryGroupIndex; + private readonly int detailedAssemblyCategoryGroupIndex; + private readonly int tailorMadeAssemblyCategoryGroupIndex; + private readonly int combinedAssemblyCategoryGroupIndex; + private readonly int combinedAssemblyProbabilityIndex; + private readonly int manualAssemblyProbabilityIndex; + private readonly IEnumerable calculations; private readonly PipingFailureMechanism failureMechanism; private readonly IAssessmentSection assessmentSection; + private FailureMechanismSectionAssemblyCategoryGroup simpleAssemblyCategoryGroup; + private FailureMechanismSectionAssemblyCategoryGroup detailedAssemblyCategoryGroup; + private FailureMechanismSectionAssemblyCategoryGroup tailorMadeAssemblyCategoryGroup; + private FailureMechanismSectionAssemblyCategoryGroup combinedAssemblyCategoryGroup; /// /// Creates a new instance of . @@ -48,11 +70,16 @@ /// All calculations in the failure mechanism. /// The failure mechanism the section result belongs to. /// The assessment section the section result belongs to. + /// The property values required to create an instance of + /// . /// Throw when any parameter is null. + /// Thrown when + /// is a valid value, but unsupported. internal PipingFailureMechanismSectionResultRow(PipingFailureMechanismSectionResult sectionResult, IEnumerable calculations, PipingFailureMechanism failureMechanism, - IAssessmentSection assessmentSection) + IAssessmentSection assessmentSection, + ConstructionProperties constructionProperties) : base(sectionResult) { if (calculations == null) @@ -70,14 +97,37 @@ throw new ArgumentNullException(nameof(assessmentSection)); } + if (constructionProperties == null) + { + throw new ArgumentNullException(nameof(constructionProperties)); + } + this.calculations = calculations; this.failureMechanism = failureMechanism; this.assessmentSection = assessmentSection; + + simpleAssessmentResultIndex = constructionProperties.SimpleAssessmentResultIndex; + detailedAssessmentResultIndex = constructionProperties.DetailedAssessmentResultIndex; + detailedAssessmentProbabilityIndex = constructionProperties.DetailedAssessmentProbabilityIndex; + tailorMadeAssessmentResultIndex = constructionProperties.TailorMadeAssessmentResultIndex; + tailorMadeAssessmentProbabilityIndex = constructionProperties.TailorMadeAssessmentProbabilityIndex; + simpleAssemblyCategoryGroupIndex = constructionProperties.SimpleAssemblyCategoryGroupIndex; + detailedAssemblyCategoryGroupIndex = constructionProperties.DetailedAssemblyCategoryGroupIndex; + tailorMadeAssemblyCategoryGroupIndex = constructionProperties.TailorMadeAssemblyCategoryGroupIndex; + combinedAssemblyCategoryGroupIndex = constructionProperties.CombinedAssemblyCategoryGroupIndex; + combinedAssemblyProbabilityIndex = constructionProperties.CombinedAssemblyProbabilityIndex; + manualAssemblyProbabilityIndex = constructionProperties.ManualAssemblyProbabilityIndex; + + CreateColumnStateDefinitions(); + + Update(); } /// /// Gets or sets the value representing the simple assessment result. /// + /// Thrown when + /// is a valid value, but unsupported. public SimpleAssessmentResultType SimpleAssessmentResult { get @@ -87,16 +137,66 @@ set { SectionResult.SimpleAssessmentResult = value; - SectionResult.NotifyObservers(); + UpdateInternalData(); } } /// - /// Gets or sets the value of the tailor made assessment of safety. + /// Gets or sets the value representing the detailed assessment result. /// - /// Thrown when - /// is outside of the valid ranges. + /// Thrown when + /// is a valid value, but unsupported. + public DetailedAssessmentResultType DetailedAssessmentResult + { + get + { + return SectionResult.DetailedAssessmentResult; + } + set + { + SectionResult.DetailedAssessmentResult = value; + UpdateInternalData(); + } + } + + /// + /// Gets the detailed assessment probability a of the . + /// [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] + public double DetailedAssessmentProbability + { + get + { + return SectionResult.GetDetailedAssessmentProbability(calculations, failureMechanism, assessmentSection); + } + } + + /// + /// Gets or sets the value representing the tailor made assessment result. + /// + /// Thrown when + /// is a valid value, but unsupported. + public TailorMadeAssessmentProbabilityCalculationResultType TailorMadeAssessmentResult + { + get + { + return SectionResult.TailorMadeAssessmentResult; + } + set + { + SectionResult.TailorMadeAssessmentResult = value; + UpdateInternalData(); + } + } + + /// + /// Gets or sets the value of the tailored assessment of safety. + /// + /// Thrown when is + /// not in the range [0,1]. + /// Thrown when + /// is a valid value, but unsupported. + [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] public double TailorMadeAssessmentProbability { get @@ -106,32 +206,384 @@ set { SectionResult.TailorMadeAssessmentProbability = value; + UpdateInternalData(); } } /// - /// Gets the detailed assessment probability a of the . + /// Gets the simple assembly category group. /// + public string SimpleAssemblyCategoryGroup + { + get + { + return FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(simpleAssemblyCategoryGroup); + } + } + + /// + /// Gets the detailed assembly category group. + /// + public string DetailedAssemblyCategoryGroup + { + get + { + return FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(detailedAssemblyCategoryGroup); + } + } + + /// + /// Gets the tailor made assembly category group. + /// + public string TailorMadeAssemblyCategoryGroup + { + get + { + return FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(tailorMadeAssemblyCategoryGroup); + } + } + + /// + /// Gets the combined assembly category group. + /// + public string CombinedAssemblyCategoryGroup + { + get + { + return FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(combinedAssemblyCategoryGroup); + } + } + + /// + /// Gets the combined assembly probability. + /// [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] - public double DetailedAssessmentProbability + public double CombinedAssemblyProbability { get; private set; } + + /// + /// Gets or sets the indicator whether the combined assembly probability + /// should be overwritten by . + /// + /// Thrown when + /// is a valid value, but unsupported. + public bool UseManualAssemblyProbability { get { - return SectionResult.GetDetailedAssessmentProbability(calculations, failureMechanism, assessmentSection); + return SectionResult.UseManualAssemblyProbability; } + set + { + SectionResult.UseManualAssemblyProbability = value; + UpdateInternalData(); + } } /// - /// Gets the that is the source of this row. + /// Gets or sets the manually entered assembly probability. /// - public PipingFailureMechanismSectionResult GetSectionResult + /// Thrown when is + /// not in the range [0,1]. + /// Thrown when + /// is a valid value, but unsupported. + [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] + public double ManualAssemblyProbability { get { - return SectionResult; + return SectionResult.ManualAssemblyProbability; } + set + { + SectionResult.ManualAssemblyProbability = value; + UpdateInternalData(); + } } - public override void Update() {} + /// + /// Thrown when + /// is a valid value, but unsupported. + public override void Update() + { + UpdateDerivedData(); + UpdateColumnStateDefinitions(); + UpdateDetailedAssessmentProbabilityError(); + } + + private void UpdateDetailedAssessmentProbabilityError() + { + if (FailureMechanismSectionResultRowHelper.SimpleAssessmentIsSufficient(SimpleAssessmentResult) + || !FailureMechanismSectionResultRowHelper.DetailedAssessmentResultIsProbability(DetailedAssessmentResult) + || UseManualAssemblyProbability) + { + ColumnStateDefinitions[detailedAssessmentProbabilityIndex].ErrorText = string.Empty; + } + else + { + ColumnStateDefinitions[detailedAssessmentProbabilityIndex].ErrorText = GetDetailedAssessmentProbabilityError(); + } + } + + private string GetDetailedAssessmentProbabilityError() + { + PipingCalculationScenario[] relevantScenarios = SectionResult.GetCalculationScenarios(calculations).ToArray(); + bool relevantScenarioAvailable = relevantScenarios.Length != 0; + + if (!relevantScenarioAvailable) + { + return RingtoetsCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_Not_any_calculation_set; + } + + if (Math.Abs(SectionResult.GetTotalContribution(relevantScenarios) - 1.0) > 1e-6) + { + return RingtoetsCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_Scenario_contribution_for_this_section_not_100; + } + + CalculationScenarioStatus calculationScenarioStatus = SectionResult.GetCalculationScenarioStatus(relevantScenarios); + if (calculationScenarioStatus == CalculationScenarioStatus.NotCalculated) + { + return RingtoetsCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_Not_all_calculations_have_been_executed; + } + + if (double.IsNaN(SectionResult.GetDetailedAssessmentProbability(calculations, failureMechanism, assessmentSection))) + { + return RingtoetsCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_All_calculations_must_have_valid_output; + } + + return string.Empty; + } + + private void CreateColumnStateDefinitions() + { + ColumnStateDefinitions.Add(simpleAssessmentResultIndex, new DataGridViewColumnStateDefinition()); + ColumnStateDefinitions.Add(detailedAssessmentResultIndex, new DataGridViewColumnStateDefinition()); + ColumnStateDefinitions.Add(detailedAssessmentProbabilityIndex, new DataGridViewColumnStateDefinition()); + ColumnStateDefinitions.Add(tailorMadeAssessmentResultIndex, new DataGridViewColumnStateDefinition()); + ColumnStateDefinitions.Add(tailorMadeAssessmentProbabilityIndex, new DataGridViewColumnStateDefinition()); + ColumnStateDefinitions.Add(simpleAssemblyCategoryGroupIndex, new DataGridViewColumnStateDefinition + { + ReadOnly = true + }); + ColumnStateDefinitions.Add(detailedAssemblyCategoryGroupIndex, new DataGridViewColumnStateDefinition + { + ReadOnly = true + }); + ColumnStateDefinitions.Add(tailorMadeAssemblyCategoryGroupIndex, new DataGridViewColumnStateDefinition + { + ReadOnly = true + }); + ColumnStateDefinitions.Add(combinedAssemblyCategoryGroupIndex, new DataGridViewColumnStateDefinition + { + ReadOnly = true + }); + ColumnStateDefinitions.Add(combinedAssemblyProbabilityIndex, new DataGridViewColumnStateDefinition + { + ReadOnly = true + }); + ColumnStateDefinitions.Add(manualAssemblyProbabilityIndex, new DataGridViewColumnStateDefinition()); + } + + private void UpdateDerivedData() + { + ResetErrorTexts(); + TryGetSimpleAssemblyCategoryGroup(); + TryGetDetailedAssemblyCategoryGroup(); + TryGetTailorMadeAssemblyCategoryGroup(); + TryGetCombinedAssemblyCategoryGroup(); + } + + private void ResetErrorTexts() + { + ColumnStateDefinitions[simpleAssemblyCategoryGroupIndex].ErrorText = string.Empty; + ColumnStateDefinitions[detailedAssemblyCategoryGroupIndex].ErrorText = string.Empty; + ColumnStateDefinitions[tailorMadeAssemblyCategoryGroupIndex].ErrorText = string.Empty; + ColumnStateDefinitions[combinedAssemblyCategoryGroupIndex].ErrorText = string.Empty; + ColumnStateDefinitions[combinedAssemblyProbabilityIndex].ErrorText = string.Empty; + } + + private void TryGetSimpleAssemblyCategoryGroup() + { + try + { + simpleAssemblyCategoryGroup = PipingFailureMechanismSectionResultAssemblyFactory.AssembleSimpleAssessment(SectionResult).Group; + } + catch (AssemblyException e) + { + simpleAssemblyCategoryGroup = FailureMechanismSectionAssemblyCategoryGroup.None; + ColumnStateDefinitions[simpleAssemblyCategoryGroupIndex].ErrorText = e.Message; + } + } + + private void TryGetDetailedAssemblyCategoryGroup() + { + try + { + detailedAssemblyCategoryGroup = PipingFailureMechanismSectionResultAssemblyFactory.AssembleDetailedAssembly( + SectionResult, + calculations, + failureMechanism, + assessmentSection).Group; + } + catch (AssemblyException e) + { + detailedAssemblyCategoryGroup = FailureMechanismSectionAssemblyCategoryGroup.None; + ColumnStateDefinitions[detailedAssemblyCategoryGroupIndex].ErrorText = e.Message; + } + } + + private void TryGetTailorMadeAssemblyCategoryGroup() + { + try + { + tailorMadeAssemblyCategoryGroup = PipingFailureMechanismSectionResultAssemblyFactory.AssembleTailorMadeAssembly( + SectionResult, + failureMechanism, + assessmentSection).Group; + } + catch (AssemblyException e) + { + tailorMadeAssemblyCategoryGroup = FailureMechanismSectionAssemblyCategoryGroup.None; + ColumnStateDefinitions[tailorMadeAssemblyCategoryGroupIndex].ErrorText = e.Message; + } + } + + private void TryGetCombinedAssemblyCategoryGroup() + { + try + { + FailureMechanismSectionAssembly combinedAssembly = + PipingFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssembly( + SectionResult, + calculations, + failureMechanism, + assessmentSection); + + combinedAssemblyCategoryGroup = combinedAssembly.Group; + CombinedAssemblyProbability = combinedAssembly.Probability; + } + catch (AssemblyException e) + { + combinedAssemblyCategoryGroup = FailureMechanismSectionAssemblyCategoryGroup.None; + CombinedAssemblyProbability = double.NaN; + ColumnStateDefinitions[combinedAssemblyCategoryGroupIndex].ErrorText = e.Message; + ColumnStateDefinitions[combinedAssemblyProbabilityIndex].ErrorText = e.Message; + } + } + + /// + /// Updates the column state definitions. + /// + /// Thrown when + /// is a valid value, but unsupported. + private void UpdateColumnStateDefinitions() + { + bool simpleAssessmentSufficient = FailureMechanismSectionResultRowHelper.SimpleAssessmentIsSufficient(SimpleAssessmentResult); + + FailureMechanismSectionResultRowHelper.SetColumnState(ColumnStateDefinitions[simpleAssessmentResultIndex], UseManualAssemblyProbability); + FailureMechanismSectionResultRowHelper.SetColumnState(ColumnStateDefinitions[detailedAssessmentResultIndex], simpleAssessmentSufficient + || UseManualAssemblyProbability); + if (simpleAssessmentSufficient + || !FailureMechanismSectionResultRowHelper.DetailedAssessmentResultIsProbability(DetailedAssessmentResult) + || UseManualAssemblyProbability) + { + FailureMechanismSectionResultRowHelper.DisableColumn(ColumnStateDefinitions[detailedAssessmentProbabilityIndex]); + } + else + { + FailureMechanismSectionResultRowHelper.EnableColumn(ColumnStateDefinitions[detailedAssessmentProbabilityIndex], true); + } + + FailureMechanismSectionResultRowHelper.SetColumnState(ColumnStateDefinitions[tailorMadeAssessmentResultIndex], + simpleAssessmentSufficient + || UseManualAssemblyProbability); + FailureMechanismSectionResultRowHelper.SetColumnState(ColumnStateDefinitions[tailorMadeAssessmentProbabilityIndex], + simpleAssessmentSufficient + || !FailureMechanismSectionResultRowHelper.TailorMadeAssessmentResultIsProbability(TailorMadeAssessmentResult) + || UseManualAssemblyProbability); + + if (UseManualAssemblyProbability) + { + FailureMechanismSectionResultRowHelper.DisableColumn(ColumnStateDefinitions[simpleAssemblyCategoryGroupIndex]); + FailureMechanismSectionResultRowHelper.DisableColumn(ColumnStateDefinitions[detailedAssemblyCategoryGroupIndex]); + FailureMechanismSectionResultRowHelper.DisableColumn(ColumnStateDefinitions[tailorMadeAssemblyCategoryGroupIndex]); + FailureMechanismSectionResultRowHelper.DisableColumn(ColumnStateDefinitions[combinedAssemblyCategoryGroupIndex]); + FailureMechanismSectionResultRowHelper.DisableColumn(ColumnStateDefinitions[combinedAssemblyProbabilityIndex]); + } + else + { + FailureMechanismSectionResultRowHelper.SetAssemblyCategoryGroupStyle(ColumnStateDefinitions[simpleAssemblyCategoryGroupIndex], + simpleAssemblyCategoryGroup); + FailureMechanismSectionResultRowHelper.SetAssemblyCategoryGroupStyle(ColumnStateDefinitions[detailedAssemblyCategoryGroupIndex], + detailedAssemblyCategoryGroup); + FailureMechanismSectionResultRowHelper.SetAssemblyCategoryGroupStyle(ColumnStateDefinitions[tailorMadeAssemblyCategoryGroupIndex], + tailorMadeAssemblyCategoryGroup); + FailureMechanismSectionResultRowHelper.SetAssemblyCategoryGroupStyle(ColumnStateDefinitions[combinedAssemblyCategoryGroupIndex], + combinedAssemblyCategoryGroup); + FailureMechanismSectionResultRowHelper.EnableColumn(ColumnStateDefinitions[combinedAssemblyProbabilityIndex], true); + } + + FailureMechanismSectionResultRowHelper.SetColumnState(ColumnStateDefinitions[manualAssemblyProbabilityIndex], !UseManualAssemblyProbability); + } + + /// + /// Class holding the various construction parameters for . + /// + public class ConstructionProperties + { + /// + /// Sets the simple assessment result index. + /// + public int SimpleAssessmentResultIndex { internal get; set; } + + /// + /// Sets the detailed assessment result index. + /// + public int DetailedAssessmentResultIndex { internal get; set; } + + /// + /// Sets the detailed assessment probability index. + /// + public int DetailedAssessmentProbabilityIndex { internal get; set; } + + /// + /// Sets the tailor made assessment result index. + /// + public int TailorMadeAssessmentResultIndex { internal get; set; } + + /// + /// Sets the tailor made assessment probability index. + /// + public int TailorMadeAssessmentProbabilityIndex { internal get; set; } + + /// + /// Sets the simple assembly category group index. + /// + public int SimpleAssemblyCategoryGroupIndex { internal get; set; } + + /// + /// Sets the detailed assembly category group index. + /// + public int DetailedAssemblyCategoryGroupIndex { internal get; set; } + + /// + /// Sets the tailor made assembly category group index. + /// + public int TailorMadeAssemblyCategoryGroupIndex { internal get; set; } + + /// + /// Sets the combined assembly category group index. + /// + public int CombinedAssemblyCategoryGroupIndex { internal get; set; } + + /// + /// Sets the combined assembly probability index. + /// + public int CombinedAssemblyProbabilityIndex { internal get; set; } + + /// + /// Sets the manual assembly category group index. + /// + public int ManualAssemblyProbabilityIndex { internal get; set; } + } } } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj =================================================================== diff -u -rd7696913d8f9239cb80eb2c3bac6cc0ccf23d479 -rf665294814c085178591a35d0d811a1df72feb55 --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj (.../Ringtoets.Piping.Forms.Test.csproj) (revision d7696913d8f9239cb80eb2c3bac6cc0ccf23d479) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj (.../Ringtoets.Piping.Forms.Test.csproj) (revision f665294814c085178591a35d0d811a1df72feb55) @@ -114,6 +114,18 @@ {F0FB401A-3494-4237-9E6D-02CDF77912A8} Core.Components.Gis.TestUtil + + {420ED9C3-0C33-47EA-B893-121A9C0DB4F1} + Ringtoets.AssemblyTool.Data + + + {358B6DA2-A1DF-477F-B6AC-C30204265CB0} + Ringtoets.AssemblyTool.KernelWrapper + + + {0AB432BB-E2CC-42EA-A72C-7AFEF7536B38} + Ringtoets.AssemblyTool.KernelWrapper.TestUtil + {d4200f43-3f72-4f42-af0a-8ced416a38ec} Ringtoets.Common.Data Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingFailureMechanismResultViewTest.cs =================================================================== diff -u -r1c200c32948d83b6a93a92da6a728120634e6e4f -rf665294814c085178591a35d0d811a1df72feb55 --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingFailureMechanismResultViewTest.cs (.../PipingFailureMechanismResultViewTest.cs) (revision 1c200c32948d83b6a93a92da6a728120634e6e4f) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingFailureMechanismResultViewTest.cs (.../PipingFailureMechanismResultViewTest.cs) (revision f665294814c085178591a35d0d811a1df72feb55) @@ -21,16 +21,14 @@ using System; using System.Collections.Generic; -using System.Globalization; using System.Linq; using System.Windows.Forms; using Core.Common.Base; -using Core.Common.Base.Data; using Core.Common.Base.Geometry; -using Core.Common.TestUtil; using NUnit.Extensions.Forms; using NUnit.Framework; using Rhino.Mocks; +using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.TestUtil; @@ -46,9 +44,19 @@ public class PipingFailureMechanismResultViewTest { private const int nameColumnIndex = 0; - private const int simpleAssessmentIndex = 1; - private const int detailedAssessmentIndex = 2; - private const int tailorMadeAssessmentProbabilityIndex = 3; + private const int simpleAssessmentResultIndex = 1; + private const int detailedAssessmentResultIndex = 2; + private const int detailedAssessmentProbabilityIndex = 3; + private const int tailorMadeAssessmentResultIndex = 4; + private const int tailorMadeAssessmentProbabilityIndex = 5; + private const int simpleAssemblyCategoryGroupIndex = 6; + private const int detailedAssemblyCategoryGroupIndex = 7; + private const int tailorMadeAssemblyCategoryGroupIndex = 8; + private const int combinedAssemblyCategoryGroupIndex = 9; + private const int combinedAssemblyProbabilityIndex = 10; + private const int useManualAssemblyProbabilityIndex = 11; + private const int manualAssemblyProbabilityIndex = 12; + private const int columnCount = 13; private Form testForm; [SetUp] @@ -102,27 +110,58 @@ } [Test] - public void Constructor_DataGridViewCorrectlyInitialized() + public void GivenFormWithPipingFailureMechanismResultView_ThenExpectedColumnsAreVisible() { - // Setup - var failureMechanism = new PipingFailureMechanism(); - - // Call - using (ShowFailureMechanismResultsView(failureMechanism)) + // Given + using (ShowFailureMechanismResultsView(new ObservableList())) { - // Assert + // Then var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; - Assert.AreEqual(4, dataGridView.ColumnCount); - Assert.IsTrue(dataGridView.Columns[detailedAssessmentIndex].ReadOnly); - Assert.IsInstanceOf(dataGridView.Columns[simpleAssessmentIndex]); - Assert.IsInstanceOf(dataGridView.Columns[detailedAssessmentIndex]); + Assert.AreEqual(13, dataGridView.ColumnCount); + Assert.IsTrue(dataGridView.Columns[detailedAssessmentProbabilityIndex].ReadOnly); + + Assert.IsInstanceOf(dataGridView.Columns[nameColumnIndex]); + Assert.IsInstanceOf(dataGridView.Columns[simpleAssessmentResultIndex]); + Assert.IsInstanceOf(dataGridView.Columns[detailedAssessmentResultIndex]); + Assert.IsInstanceOf(dataGridView.Columns[detailedAssessmentProbabilityIndex]); + Assert.IsInstanceOf(dataGridView.Columns[tailorMadeAssessmentResultIndex]); Assert.IsInstanceOf(dataGridView.Columns[tailorMadeAssessmentProbabilityIndex]); + Assert.IsInstanceOf(dataGridView.Columns[simpleAssemblyCategoryGroupIndex]); + Assert.IsInstanceOf(dataGridView.Columns[detailedAssemblyCategoryGroupIndex]); + Assert.IsInstanceOf(dataGridView.Columns[tailorMadeAssemblyCategoryGroupIndex]); + Assert.IsInstanceOf(dataGridView.Columns[combinedAssemblyCategoryGroupIndex]); + Assert.IsInstanceOf(dataGridView.Columns[combinedAssemblyProbabilityIndex]); + Assert.IsInstanceOf(dataGridView.Columns[useManualAssemblyProbabilityIndex]); + Assert.IsInstanceOf(dataGridView.Columns[manualAssemblyProbabilityIndex]); - Assert.AreEqual("Eenvoudige toets", dataGridView.Columns[simpleAssessmentIndex].HeaderText); - Assert.AreEqual("Gedetailleerde toets per vak", dataGridView.Columns[detailedAssessmentIndex].HeaderText); - Assert.AreEqual("Toets op maat", dataGridView.Columns[tailorMadeAssessmentProbabilityIndex].HeaderText); + Assert.AreEqual("Vak", dataGridView.Columns[nameColumnIndex].HeaderText); + Assert.AreEqual("Eenvoudige toets", dataGridView.Columns[simpleAssessmentResultIndex].HeaderText); + Assert.AreEqual("Gedetailleerde toets per vak", dataGridView.Columns[detailedAssessmentResultIndex].HeaderText); + Assert.AreEqual("Gedetailleerde toets per vak\r\nfaalkans", dataGridView.Columns[detailedAssessmentProbabilityIndex].HeaderText); + Assert.AreEqual("Toets op maat", dataGridView.Columns[tailorMadeAssessmentResultIndex].HeaderText); + Assert.AreEqual("Toets op maat\r\nfaalkans", dataGridView.Columns[tailorMadeAssessmentProbabilityIndex].HeaderText); + Assert.AreEqual("Assemblageresultaat\r\neenvoudige toets", dataGridView.Columns[simpleAssemblyCategoryGroupIndex].HeaderText); + Assert.AreEqual("Assemblageresultaat\r\ngedetailleerde toets per vak", dataGridView.Columns[detailedAssemblyCategoryGroupIndex].HeaderText); + Assert.AreEqual("Assemblageresultaat\r\ntoets op maat", dataGridView.Columns[tailorMadeAssemblyCategoryGroupIndex].HeaderText); + Assert.AreEqual("Assemblageresultaat\r\ngecombineerd", dataGridView.Columns[combinedAssemblyCategoryGroupIndex].HeaderText); + Assert.AreEqual("Assemblageresultaat\r\ngecombineerde\r\nfaalkansschatting", dataGridView.Columns[combinedAssemblyProbabilityIndex].HeaderText); + Assert.AreEqual("Overschrijf\r\nassemblageresultaat", dataGridView.Columns[useManualAssemblyProbabilityIndex].HeaderText); + Assert.AreEqual("Assemblageresultaat\r\nhandmatig", dataGridView.Columns[manualAssemblyProbabilityIndex].HeaderText); + Assert.IsTrue(dataGridView.Columns[nameColumnIndex].ReadOnly); + Assert.IsFalse(dataGridView.Columns[simpleAssessmentResultIndex].ReadOnly); + Assert.IsFalse(dataGridView.Columns[detailedAssessmentResultIndex].ReadOnly); + Assert.IsTrue(dataGridView.Columns[detailedAssessmentProbabilityIndex].ReadOnly); + Assert.IsFalse(dataGridView.Columns[tailorMadeAssessmentResultIndex].ReadOnly); + Assert.IsFalse(dataGridView.Columns[tailorMadeAssessmentProbabilityIndex].ReadOnly); + Assert.IsTrue(dataGridView.Columns[simpleAssemblyCategoryGroupIndex].ReadOnly); + Assert.IsTrue(dataGridView.Columns[detailedAssemblyCategoryGroupIndex].ReadOnly); + Assert.IsTrue(dataGridView.Columns[tailorMadeAssemblyCategoryGroupIndex].ReadOnly); + Assert.IsTrue(dataGridView.Columns[combinedAssemblyCategoryGroupIndex].ReadOnly); + Assert.IsFalse(dataGridView.Columns[useManualAssemblyProbabilityIndex].ReadOnly); + Assert.IsFalse(dataGridView.Columns[manualAssemblyProbabilityIndex].ReadOnly); + Assert.AreEqual(DataGridViewAutoSizeColumnsMode.AllCells, dataGridView.AutoSizeColumnsMode); Assert.AreEqual(DataGridViewContentAlignment.MiddleCenter, dataGridView.ColumnHeadersDefaultCellStyle.Alignment); } @@ -132,370 +171,63 @@ public void FailureMechanismResultsView_AllDataSet_DataGridViewCorrectlyInitialized() { // Setup - PipingFailureMechanism pipingFailureMechanism = GetFullyConfiguredFailureMechanism(); + var results = new ObservableList + { + new PipingFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection("Section 1")) + }; // Call - using (ShowFailureMechanismResultsView(pipingFailureMechanism)) + using (new AssemblyToolCalculatorFactoryConfig()) + using (ShowFailureMechanismResultsView(results)) { var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; // Assert DataGridViewRowCollection rows = dataGridView.Rows; - Assert.AreEqual(2, rows.Count); + Assert.AreEqual(1, rows.Count); DataGridViewCellCollection cells = rows[0].Cells; - Assert.AreEqual(4, cells.Count); + Assert.AreEqual(columnCount, cells.Count); Assert.AreEqual("Section 1", cells[nameColumnIndex].FormattedValue); - Assert.AreEqual(SimpleAssessmentResultType.None, cells[simpleAssessmentIndex].Value); - Assert.AreEqual("-", cells[detailedAssessmentIndex].FormattedValue); + Assert.AreEqual(SimpleAssessmentResultType.None, cells[simpleAssessmentResultIndex].Value); + Assert.AreEqual(DetailedAssessmentResultType.Probability, cells[detailedAssessmentResultIndex].Value); + Assert.AreEqual("-", cells[detailedAssessmentProbabilityIndex].FormattedValue); + Assert.AreEqual(TailorMadeAssessmentProbabilityCalculationResultType.None, cells[tailorMadeAssessmentResultIndex].Value); Assert.AreEqual("-", cells[tailorMadeAssessmentProbabilityIndex].FormattedValue); - - cells = rows[1].Cells; - Assert.AreEqual(4, cells.Count); - Assert.AreEqual("Section 2", cells[nameColumnIndex].FormattedValue); - Assert.AreEqual(SimpleAssessmentResultType.None, cells[simpleAssessmentIndex].Value); - Assert.AreEqual("-", cells[detailedAssessmentIndex].FormattedValue); - Assert.AreEqual("-", cells[tailorMadeAssessmentProbabilityIndex].FormattedValue); + Assert.AreEqual("Iv", cells[simpleAssemblyCategoryGroupIndex].Value); + Assert.AreEqual("VIv", cells[detailedAssemblyCategoryGroupIndex].Value); + Assert.AreEqual("VIv", cells[tailorMadeAssemblyCategoryGroupIndex].Value); + Assert.AreEqual("VIv", cells[combinedAssemblyCategoryGroupIndex].Value); + Assert.AreEqual("1/1", cells[combinedAssemblyProbabilityIndex].FormattedValue); + Assert.AreEqual(false, cells[useManualAssemblyProbabilityIndex].Value); + Assert.AreEqual("-", cells[manualAssemblyProbabilityIndex].FormattedValue); } } [Test] - [TestCase(SimpleAssessmentResultType.None)] - [TestCase(SimpleAssessmentResultType.NotApplicable)] - [TestCase(SimpleAssessmentResultType.ProbabilityNegligible)] - [TestCase(SimpleAssessmentResultType.AssessFurther)] - public void FailureMechanismResultsView_ChangeComboBox_DataGridViewCorrectlySyncedAndStylingSet( - SimpleAssessmentResultType simpleAssessmentType) + public void GivenFailureMechanismResultView_WhenFailureMechanismNotifiesObserver_ThenViewUpdated() { - // Setup - PipingFailureMechanism pipingFailureMechanism = GetFullyConfiguredFailureMechanism(); - - // Call - using (ShowFailureMechanismResultsView(pipingFailureMechanism)) + // Given + var pipingFailureMechanism = new PipingFailureMechanism(); + pipingFailureMechanism.AddSection(new FailureMechanismSection("Section 1", new List { - var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + new Point2D(0.0, 0.0), + new Point2D(5.0, 0.0) + })); - dataGridView.Rows[0].Cells[simpleAssessmentIndex].Value = simpleAssessmentType; - - // Assert - DataGridViewRowCollection rows = dataGridView.Rows; - - DataGridViewCellCollection cells = rows[0].Cells; - Assert.AreEqual(4, cells.Count); - Assert.AreEqual("Section 1", cells[nameColumnIndex].FormattedValue); - DataGridViewCell cellDetailedAssessment = cells[detailedAssessmentIndex]; - DataGridViewCell cellTailorMadeAssessmentProbability = cells[tailorMadeAssessmentProbabilityIndex]; - - Assert.AreEqual(simpleAssessmentType, cells[simpleAssessmentIndex].Value); - Assert.AreEqual("-", cellDetailedAssessment.FormattedValue); - Assert.AreEqual("-", cellTailorMadeAssessmentProbability.FormattedValue); - - if (simpleAssessmentType == SimpleAssessmentResultType.ProbabilityNegligible - || simpleAssessmentType == SimpleAssessmentResultType.NotApplicable) - { - DataGridViewTestHelper.AssertCellIsDisabled(cellDetailedAssessment); - DataGridViewTestHelper.AssertCellIsDisabled(cellTailorMadeAssessmentProbability); - - Assert.IsTrue(cellTailorMadeAssessmentProbability.ReadOnly); - } - else - { - DataGridViewTestHelper.AssertCellIsEnabled(cellDetailedAssessment, true); - DataGridViewTestHelper.AssertCellIsEnabled(cellTailorMadeAssessmentProbability); - - Assert.IsFalse(cellTailorMadeAssessmentProbability.ReadOnly); - } - } - } - - [Test] - [TestCase("test", tailorMadeAssessmentProbabilityIndex)] - [TestCase(";/[].,~!@#$%^&*()_-+={}|?", tailorMadeAssessmentProbabilityIndex)] - public void FailureMechanismResultView_EditValueInvalid_ShowsErrorTooltip(string newValue, int cellIndex) - { - // Setup - PipingFailureMechanism pipingFailureMechanism = GetFullyConfiguredFailureMechanism(); - using (ShowFailureMechanismResultsView(pipingFailureMechanism)) + pipingFailureMechanism.AddSection(new FailureMechanismSection("Section 2", new List { - var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; - - // Call - dataGridView.Rows[0].Cells[cellIndex].Value = newValue; - - // Assert - Assert.AreEqual("De waarde kon niet geïnterpreteerd worden als een kans.", dataGridView.Rows[0].ErrorText); - } - } - - [Test] - [SetCulture("nl-NL")] - [TestCase(1.01)] - [TestCase(-0.01)] - [TestCase(5)] - [TestCase(-10)] - public void FailureMechanismResultView_EditValueTailorMadeAssessmentProbabilityInvalid_ShowErrorToolTip(double newValue) - { - // Setup - PipingFailureMechanism pipingFailureMechanism = GetFullyConfiguredFailureMechanism(); - using (ShowFailureMechanismResultsView(pipingFailureMechanism)) - { - var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; - - // Call - dataGridView.Rows[0].Cells[tailorMadeAssessmentProbabilityIndex].Value = newValue.ToString(CultureInfo.CurrentCulture); - - // Assert - Assert.AreEqual("De waarde voor de faalkans moet in het bereik [0,0, 1,0] liggen.", dataGridView.Rows[0].ErrorText); - } - } - - [Test] - [SetCulture("nl-NL")] - [TestCase(1)] - [TestCase(0)] - [TestCase(0.5)] - [TestCase(1e-6)] - [TestCase(double.NaN)] - public void FailureMechanismResultView_EditValueTailorMadeAssessmentProbabilityValid_DoNotShowErrorToolTipAndEditValue(double newValue) - { - // Setup - PipingFailureMechanism pipingFailureMechanism = GetFullyConfiguredFailureMechanism(); - using (ShowFailureMechanismResultsView(pipingFailureMechanism)) - { - var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; - - // Call - dataGridView.Rows[0].Cells[tailorMadeAssessmentProbabilityIndex].Value = newValue.ToString(CultureInfo.CurrentCulture); - - // Assert - Assert.IsEmpty(dataGridView.Rows[0].ErrorText); - Assert.AreEqual(newValue, pipingFailureMechanism.SectionResults.First().TailorMadeAssessmentProbability); - } - } - - [Test] - [TestCase(SimpleAssessmentResultType.None)] - [TestCase(SimpleAssessmentResultType.AssessFurther)] - public void FailureMechanismResultView_TotalContributionNotHundred_ShowsErrorTooltip( - SimpleAssessmentResultType simpleAssessmentType) - { - // Setup - const int rowIndex = 0; - PipingFailureMechanism pipingFailureMechanism = GetFullyConfiguredFailureMechanism(); - PipingCalculationScenario calculationScenario = PipingCalculationScenarioTestFactory.CreatePipingCalculationScenario( - pipingFailureMechanism.Sections.First()); - calculationScenario.Contribution = (RoundedDouble) 0.3; - pipingFailureMechanism.CalculationsGroup.Children.Add(calculationScenario); - - using (ShowFailureMechanismResultsView(pipingFailureMechanism)) - { - var gridTester = new ControlTester("dataGridView"); - var dataGridView = (DataGridView) gridTester.TheObject; - - DataGridViewCell dataGridViewCell = dataGridView.Rows[rowIndex].Cells[detailedAssessmentIndex]; - dataGridView.Rows[rowIndex].Cells[simpleAssessmentIndex].Value = simpleAssessmentType; - - // Call - object formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. - - // Assert - Assert.AreEqual("Bijdrage van de geselecteerde scenario's voor dit vak moet opgeteld gelijk zijn aan 100%.", - dataGridViewCell.ErrorText); - Assert.AreEqual("-", formattedValue); - } - } - - [Test] - [SetCulture("nl-NL")] - [TestCase(SimpleAssessmentResultType.None)] - [TestCase(SimpleAssessmentResultType.AssessFurther)] - public void FailureMechanismResultView_DetailedAssessmentProbabilityHasValue_DoesNotShowsErrorTooltip( - SimpleAssessmentResultType simpleAssessmentType) - { - // Setup - const int rowIndex = 0; - PipingFailureMechanism pipingFailureMechanism = GetFullyConfiguredFailureMechanism(); - PipingCalculationScenario calculationScenario = PipingCalculationScenarioTestFactory.CreatePipingCalculationScenario( - pipingFailureMechanism.Sections.First()); - pipingFailureMechanism.CalculationsGroup.Children.Add(calculationScenario); - - using (ShowFailureMechanismResultsView(pipingFailureMechanism)) - { - var gridTester = new ControlTester("dataGridView"); - var dataGridView = (DataGridView) gridTester.TheObject; - - DataGridViewCell dataGridViewCell = dataGridView.Rows[rowIndex].Cells[detailedAssessmentIndex]; - dataGridView.Rows[rowIndex].Cells[simpleAssessmentIndex].Value = simpleAssessmentType; - - // Call - object formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. - - // Assert - Assert.IsEmpty(dataGridViewCell.ErrorText); - Assert.AreEqual("1/4.123", - formattedValue); - } - } - - [Test] - [TestCase(SimpleAssessmentResultType.None)] - [TestCase(SimpleAssessmentResultType.AssessFurther)] - public void FailureMechanismResultView_NoCalculatedScenario_ShowsErrorTooltip(SimpleAssessmentResultType simpleAssessmentType) - { - // Setup - const int rowIndex = 0; - PipingFailureMechanism pipingFailureMechanism = GetFullyConfiguredFailureMechanism(); - PipingCalculationScenario calculationScenario = PipingCalculationScenarioTestFactory.CreateNotCalculatedPipingCalculationScenario( - pipingFailureMechanism.Sections.First()); - pipingFailureMechanism.CalculationsGroup.Children.Add(calculationScenario); - - using (ShowFailureMechanismResultsView(pipingFailureMechanism)) - { - var gridTester = new ControlTester("dataGridView"); - var dataGridView = (DataGridView) gridTester.TheObject; - - DataGridViewCell dataGridViewCell = dataGridView.Rows[rowIndex].Cells[detailedAssessmentIndex]; - dataGridView.Rows[rowIndex].Cells[simpleAssessmentIndex].Value = simpleAssessmentType; - - // Call - object formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. - - // Assert - Assert.AreEqual("Alle berekeningen voor dit vak moeten uitgevoerd zijn.", - dataGridViewCell.ErrorText); - Assert.AreEqual("-", formattedValue); - } - } - - [Test] - [TestCase(SimpleAssessmentResultType.None)] - [TestCase(SimpleAssessmentResultType.AssessFurther)] - public void FailureMechanismResultView_DetailedAssessmentProbabilityNaN_ShowsErrorTooltip(SimpleAssessmentResultType simpleAssessmentType) - { - // Setup - const int rowIndex = 0; - PipingFailureMechanism pipingFailureMechanism = GetFullyConfiguredFailureMechanism(); - PipingCalculationScenario calculationScenario = PipingCalculationScenarioTestFactory.CreateNotCalculatedPipingCalculationScenario( - pipingFailureMechanism.Sections.First()); - calculationScenario.Output = new PipingOutput(new PipingOutput.ConstructionProperties()); - pipingFailureMechanism.CalculationsGroup.Children.Add(calculationScenario); - - using (ShowFailureMechanismResultsView(pipingFailureMechanism)) - { - var gridTester = new ControlTester("dataGridView"); - var dataGridView = (DataGridView) gridTester.TheObject; - - DataGridViewCell dataGridViewCell = dataGridView.Rows[rowIndex].Cells[detailedAssessmentIndex]; - dataGridView.Rows[rowIndex].Cells[simpleAssessmentIndex].Value = simpleAssessmentType; - - // Call - object formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. - - // Assert - Assert.AreEqual("Alle berekeningen voor dit vak moeten een geldige uitkomst hebben.", - dataGridViewCell.ErrorText); - Assert.AreEqual("-", formattedValue); - } - } - - [Test] - [TestCase(SimpleAssessmentResultType.None)] - [TestCase(SimpleAssessmentResultType.AssessFurther)] - public void FailureMechanismResultView_NoCalculationScenarios_ShowsErrorTooltip(SimpleAssessmentResultType simpleAssessmentType) - { - // Setup - const int rowIndex = 0; - PipingFailureMechanism pipingFailureMechanism = GetFullyConfiguredFailureMechanism(); - using (ShowFailureMechanismResultsView(pipingFailureMechanism)) - { - var gridTester = new ControlTester("dataGridView"); - var dataGridView = (DataGridView) gridTester.TheObject; - - DataGridViewCell dataGridViewCell = dataGridView.Rows[rowIndex].Cells[detailedAssessmentIndex]; - dataGridView.Rows[rowIndex].Cells[simpleAssessmentIndex].Value = simpleAssessmentType; - - // Call - object formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. - - // Assert - Assert.AreEqual("Er moet minimaal één maatgevende berekening voor dit vak worden geselecteerd.", - dataGridViewCell.ErrorText); - Assert.AreEqual("-", formattedValue); - } - } - - [Test] - [TestCase(SimpleAssessmentResultType.None)] - [TestCase(SimpleAssessmentResultType.AssessFurther)] - public void FailureMechanismResultView_NoCalculationScenariosRelevant_ShowsErrorTooltip( - SimpleAssessmentResultType simpleAssessmentType) - { - // Setup - const int rowIndex = 0; - PipingFailureMechanism pipingFailureMechanism = GetFullyConfiguredFailureMechanism(); - PipingCalculationScenario calculationScenario = PipingCalculationScenarioTestFactory.CreateIrrelevantPipingCalculationScenario( - pipingFailureMechanism.Sections.First()); - pipingFailureMechanism.CalculationsGroup.Children.Add(calculationScenario); - - using (ShowFailureMechanismResultsView(pipingFailureMechanism)) - { - var gridTester = new ControlTester("dataGridView"); - var dataGridView = (DataGridView) gridTester.TheObject; - - DataGridViewCell dataGridViewCell = dataGridView.Rows[rowIndex].Cells[detailedAssessmentIndex]; - dataGridView.Rows[rowIndex].Cells[simpleAssessmentIndex].Value = simpleAssessmentType; - - // Call - object formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. - - // Assert - Assert.AreEqual("Er moet minimaal één maatgevende berekening voor dit vak worden geselecteerd.", - dataGridViewCell.ErrorText); - Assert.AreEqual("-", formattedValue); - } - } - - [Test] - public void FailureMechanismResultView_SimpleAssessmentProbabilityNegligibleAndDetailedAssessmentNaN_DoesNotShowError() - { - // Setup - const int rowIndex = 0; - PipingFailureMechanism pipingFailureMechanism = GetFullyConfiguredFailureMechanism(); - PipingCalculationScenario calculationScenario = PipingCalculationScenarioTestFactory.CreateNotCalculatedPipingCalculationScenario( - pipingFailureMechanism.Sections.First()); - calculationScenario.Output = new PipingOutput(new PipingOutput.ConstructionProperties()); - pipingFailureMechanism.CalculationsGroup.Children.Add(calculationScenario); - - using (ShowFailureMechanismResultsView(pipingFailureMechanism)) - { - var gridTester = new ControlTester("dataGridView"); - var dataGridView = (DataGridView) gridTester.TheObject; - - DataGridViewCell dataGridViewCell = dataGridView.Rows[rowIndex].Cells[detailedAssessmentIndex]; - - // Call - dataGridView.Rows[rowIndex].Cells[simpleAssessmentIndex].Value = SimpleAssessmentResultType.ProbabilityNegligible; - object formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. - - // Assert - Assert.IsEmpty(dataGridViewCell.ErrorText); - Assert.AreEqual("-", formattedValue); - } - } - - [Test] - public void GivenFailureMechanismResultView_WhenFailureMechanismNotifiesObserver_ThenViewUpdated() - { - // Given - PipingFailureMechanism pipingFailureMechanism = GetFullyConfiguredFailureMechanism(); + new Point2D(5.0, 0.0), + new Point2D(10.0, 0.0) + })); PipingCalculationScenario calculationScenario1 = PipingCalculationScenarioTestFactory.CreatePipingCalculationScenario( pipingFailureMechanism.Sections.First()); PipingCalculationScenario calculationScenario2 = PipingCalculationScenarioTestFactory.CreatePipingCalculationScenario( pipingFailureMechanism.Sections.First()); pipingFailureMechanism.CalculationsGroup.Children.Add(calculationScenario1); pipingFailureMechanism.CalculationsGroup.Children.Add(calculationScenario2); - using (ShowFailureMechanismResultsView(pipingFailureMechanism)) + using (ShowFailureMechanismResultsView(pipingFailureMechanism, pipingFailureMechanism.SectionResults)) { var gridTester = new ControlTester("dataGridView"); var dataGridView = (DataGridView) gridTester.TheObject; @@ -519,27 +251,15 @@ } } - private static PipingFailureMechanism GetFullyConfiguredFailureMechanism() + private PipingFailureMechanismResultView ShowFailureMechanismResultsView(IObservableEnumerable sectionResults) { - var failureMechanism = new PipingFailureMechanism(); - failureMechanism.AddSection(new FailureMechanismSection("Section 1", new List - { - new Point2D(0.0, 0.0), - new Point2D(5.0, 0.0) - })); - - failureMechanism.AddSection(new FailureMechanismSection("Section 2", new List - { - new Point2D(5.0, 0.0), - new Point2D(10.0, 0.0) - })); - - return failureMechanism; + return ShowFailureMechanismResultsView(new PipingFailureMechanism(), sectionResults); } - private PipingFailureMechanismResultView ShowFailureMechanismResultsView(PipingFailureMechanism failureMechanism) + private PipingFailureMechanismResultView ShowFailureMechanismResultsView(PipingFailureMechanism failureMechanism, + IObservableEnumerable sectionResults) { - var failureMechanismResultView = new PipingFailureMechanismResultView(failureMechanism.SectionResults, + var failureMechanismResultView = new PipingFailureMechanismResultView(sectionResults, failureMechanism, new ObservableTestAssessmentSectionStub()); testForm.Controls.Add(failureMechanismResultView); Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingFailureMechanismSectionResultRowTest.cs =================================================================== diff -u -r22f818cf3c4b2589e8b102cfedd964ee7798c3b3 -rf665294814c085178591a35d0d811a1df72feb55 --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingFailureMechanismSectionResultRowTest.cs (.../PipingFailureMechanismSectionResultRowTest.cs) (revision 22f818cf3c4b2589e8b102cfedd964ee7798c3b3) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingFailureMechanismSectionResultRowTest.cs (.../PipingFailureMechanismSectionResultRowTest.cs) (revision f665294814c085178591a35d0d811a1df72feb55) @@ -20,15 +20,25 @@ // All rights reserved. using System; +using System.Collections.Generic; +using System.Drawing; using System.Linq; using Core.Common.Base; using Core.Common.Base.Data; +using Core.Common.Controls.DataGrid; using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; +using Ringtoets.AssemblyTool.Data; +using Ringtoets.AssemblyTool.KernelWrapper.Calculators; +using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators; +using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators.Assembly; using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Forms.Helpers; +using Ringtoets.Common.Forms.TestUtil; using Ringtoets.Common.Forms.TypeConverters; using Ringtoets.Common.Forms.Views; using Ringtoets.Common.Primitives; @@ -41,62 +51,96 @@ [TestFixture] public class PipingFailureMechanismSectionResultRowTest { + private static PipingFailureMechanismSectionResultRow.ConstructionProperties ConstructionProperties + { + get + { + return new PipingFailureMechanismSectionResultRow.ConstructionProperties + { + SimpleAssessmentResultIndex = 1, + DetailedAssessmentResultIndex = 2, + DetailedAssessmentProbabilityIndex = 3, + TailorMadeAssessmentResultIndex = 4, + TailorMadeAssessmentProbabilityIndex = 5, + SimpleAssemblyCategoryGroupIndex = 6, + DetailedAssemblyCategoryGroupIndex = 7, + TailorMadeAssemblyCategoryGroupIndex = 8, + CombinedAssemblyCategoryGroupIndex = 9, + CombinedAssemblyProbabilityIndex = 10, + ManualAssemblyProbabilityIndex = 11 + }; + } + } + [Test] - public void Constructor_WithParameters_ExpectedValues() + public void Constructor_FailureMechanismNull_ThrowsArgumentNullException() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); - var failureMechanism = new PipingFailureMechanism(); - FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new PipingFailureMechanismSectionResult(section); // Call - var row = new PipingFailureMechanismSectionResultRow(result, Enumerable.Empty(), - failureMechanism, assessmentSection); + TestDelegate call = () => new PipingFailureMechanismSectionResultRow(result, + Enumerable.Empty(), + null, + assessmentSection, + ConstructionProperties); // Assert - Assert.IsInstanceOf>(row); - Assert.AreEqual(row.SimpleAssessmentResult, result.SimpleAssessmentResult); - Assert.AreEqual(result.GetDetailedAssessmentProbability(Enumerable.Empty(), - failureMechanism, assessmentSection), - row.DetailedAssessmentProbability); - Assert.AreEqual(row.TailorMadeAssessmentProbability, result.TailorMadeAssessmentProbability); - - TestHelper.AssertTypeConverter( - nameof(PipingFailureMechanismSectionResultRow.DetailedAssessmentProbability)); - TestHelper.AssertTypeConverter( - nameof(PipingFailureMechanismSectionResultRow.TailorMadeAssessmentProbability)); + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); mocks.VerifyAll(); } [Test] - public void Constructor_CalculationsNull_ThrowsArgumentNullException() + public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException() { // Setup + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new PipingFailureMechanismSectionResult(section); + + // Call + TestDelegate call = () => new PipingFailureMechanismSectionResultRow(result, + Enumerable.Empty(), + new PipingFailureMechanism(), + null, + ConstructionProperties); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void Constructor_ConstructionPropertiesNull_ThrowsArgumentNullException() + { + // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); - var failureMechanism = new PipingFailureMechanism(); - FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new PipingFailureMechanismSectionResult(section); // Call - TestDelegate test = () => new PipingFailureMechanismSectionResultRow(result, null, failureMechanism, assessmentSection); + TestDelegate call = () => new PipingFailureMechanismSectionResultRow(result, + Enumerable.Empty(), + new PipingFailureMechanism(), + assessmentSection, + null); // Assert - string paramName = Assert.Throws(test).ParamName; - Assert.AreEqual("calculations", paramName); + var exception = Assert.Throws(call); + Assert.AreEqual("constructionProperties", exception.ParamName); mocks.VerifyAll(); } [Test] - public void Constructor_FailureMechanismNull_ThrowsArgumentNullException() + public void Constructor_CalculationsNull_ThrowsArgumentNullException() { // Setup var mocks = new MockRepository(); @@ -107,61 +151,888 @@ var result = new PipingFailureMechanismSectionResult(section); // Call - TestDelegate call = () => new PipingFailureMechanismSectionResultRow(result, Enumerable.Empty(), - null, assessmentSection); + TestDelegate call = () => new PipingFailureMechanismSectionResultRow(result, + null, + new PipingFailureMechanism(), + assessmentSection, + ConstructionProperties); // Assert var exception = Assert.Throws(call); - Assert.AreEqual("failureMechanism", exception.ParamName); + Assert.AreEqual("calculations", exception.ParamName); mocks.VerifyAll(); } [Test] - public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException() + public void Constructor_WithParameters_ExpectedValues() { // Setup + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new PipingFailureMechanismSectionResult(section); + var calculationScenarios = new[] + { + PipingCalculationScenarioTestFactory.CreatePipingCalculationScenario(section) + }; // Call - TestDelegate call = () => new PipingFailureMechanismSectionResultRow(result, Enumerable.Empty(), - new PipingFailureMechanism(), null); + using (new AssemblyToolCalculatorFactoryConfig()) + { + var row = new PipingFailureMechanismSectionResultRow(result, + calculationScenarios, + failureMechanism, + assessmentSection, + ConstructionProperties); - // Assert - var exception = Assert.Throws(call); - Assert.AreEqual("assessmentSection", exception.ParamName); + // Assert + Assert.IsInstanceOf>(row); + + IDictionary columnStateDefinitions = row.ColumnStateDefinitions; + Assert.AreEqual(11, columnStateDefinitions.Count); + + for (var i = 1; i < 12; i++) + { + Assert.IsTrue(columnStateDefinitions.ContainsKey(i)); + Assert.IsNotNull(columnStateDefinitions[i]); + } + + FailureMechanismSectionResultRowTestHelper.AssertColumnStateIsEnabled(columnStateDefinitions[ConstructionProperties.SimpleAssessmentResultIndex]); + FailureMechanismSectionResultRowTestHelper.AssertColumnStateIsEnabled(columnStateDefinitions[ConstructionProperties.DetailedAssessmentResultIndex]); + FailureMechanismSectionResultRowTestHelper.AssertColumnStateIsEnabled(columnStateDefinitions[ConstructionProperties.DetailedAssessmentProbabilityIndex], + true); + FailureMechanismSectionResultRowTestHelper.AssertColumnStateIsEnabled(columnStateDefinitions[ConstructionProperties.TailorMadeAssessmentResultIndex]); + FailureMechanismSectionResultRowTestHelper.AssertColumnStateIsDisabled(columnStateDefinitions[ConstructionProperties.TailorMadeAssessmentProbabilityIndex]); + FailureMechanismSectionResultRowTestHelper.AssertColumnStateIsDisabled(columnStateDefinitions[ConstructionProperties.ManualAssemblyProbabilityIndex]); + + Assert.AreEqual(result.SimpleAssessmentResult, row.SimpleAssessmentResult); + Assert.AreEqual(result.DetailedAssessmentResult, row.DetailedAssessmentResult); + Assert.AreEqual(result.GetDetailedAssessmentProbability(calculationScenarios, failureMechanism, assessmentSection), + row.DetailedAssessmentProbability); + Assert.AreEqual(result.TailorMadeAssessmentResult, row.TailorMadeAssessmentResult); + Assert.AreEqual(result.TailorMadeAssessmentProbability, row.TailorMadeAssessmentProbability); + Assert.AreEqual(result.UseManualAssemblyProbability, row.UseManualAssemblyProbability); + Assert.AreEqual(result.ManualAssemblyProbability, row.ManualAssemblyProbability); + FailureMechanismSectionResultRowTestHelper.AssertColumnStateIsEnabled(columnStateDefinitions[ConstructionProperties.CombinedAssemblyProbabilityIndex], + true); + + TestHelper.AssertTypeConverter( + nameof(PipingFailureMechanismSectionResultRow.DetailedAssessmentProbability)); + TestHelper.AssertTypeConverter( + nameof(PipingFailureMechanismSectionResultRow.TailorMadeAssessmentProbability)); + TestHelper.AssertTypeConverter( + nameof(PipingFailureMechanismSectionResultRow.CombinedAssemblyProbability)); + TestHelper.AssertTypeConverter( + nameof(PipingFailureMechanismSectionResultRow.ManualAssemblyProbability)); + mocks.VerifyAll(); + } } [Test] + public void Constructor_AssemblyRan_ReturnCategoryGroups() + { + // Setup + var random = new Random(39); + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new PipingFailureMechanismSectionResult(section); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + calculator.SimpleAssessmentAssemblyOutput = new FailureMechanismSectionAssembly( + random.NextDouble(), + random.NextEnumValue()); + calculator.DetailedAssessmentAssemblyOutput = new FailureMechanismSectionAssembly( + random.NextDouble(), + random.NextEnumValue()); + calculator.TailorMadeAssessmentAssemblyOutput = new FailureMechanismSectionAssembly( + random.NextDouble(), + random.NextEnumValue()); + calculator.CombinedAssemblyOutput = new FailureMechanismSectionAssembly( + random.NextDouble(), + random.NextEnumValue()); + + // Call + var row = new PipingFailureMechanismSectionResultRow(result, + Enumerable.Empty(), + failureMechanism, + assessmentSection, + ConstructionProperties); + + // Assert + Assert.AreEqual(FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(calculator.SimpleAssessmentAssemblyOutput.Group), + row.SimpleAssemblyCategoryGroup); + Assert.AreEqual(FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(calculator.DetailedAssessmentAssemblyOutput.Group), + row.DetailedAssemblyCategoryGroup); + Assert.AreEqual(FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(calculator.TailorMadeAssessmentAssemblyOutput.Group), + row.TailorMadeAssemblyCategoryGroup); + Assert.AreEqual(FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(calculator.CombinedAssemblyOutput.Group), + row.CombinedAssemblyCategoryGroup); + Assert.AreEqual(calculator.CombinedAssemblyOutput.Probability, row.CombinedAssemblyProbability); + mocks.VerifyAll(); + } + } + + [Test] + public void UseManualAssemblyProbability_SetNewValue_NotifyObserversAndPropertyChanged() + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new PipingFailureMechanismSectionResult(section); + result.Attach(observer); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var row = new PipingFailureMechanismSectionResultRow( + result, Enumerable.Empty(), failureMechanism, assessmentSection, ConstructionProperties); + bool originalValue = result.UseManualAssemblyProbability; + bool newValue = !originalValue; + + // Call + row.UseManualAssemblyProbability = newValue; + + // Assert + Assert.AreEqual(newValue, result.UseManualAssemblyProbability); + mocks.VerifyAll(); + } + } + + [Test] + [TestCase(0)] + [TestCase(1)] + [TestCase(0.5)] + [TestCase(1e-6)] + [TestCase(double.NaN)] + public void ManualAssemblyProbability_ValidValue_NotifyObserversAndPropertyChanged(double value) + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new PipingFailureMechanismSectionResult(section); + result.Attach(observer); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var row = new PipingFailureMechanismSectionResultRow( + result, Enumerable.Empty(), failureMechanism, assessmentSection, ConstructionProperties); + + // Call + row.ManualAssemblyProbability = value; + + // Assert + Assert.AreEqual(value, row.ManualAssemblyProbability); + mocks.VerifyAll(); + } + } + + [Test] + [SetCulture("nl-NL")] + [TestCase(-20)] + [TestCase(-1e-6)] + [TestCase(1 + 1e-6)] + [TestCase(12)] + public void ManualAssemblyProbability_InvalidValue_ThrowsArgumentOutOfRangeException(double value) + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new PipingFailureMechanismSectionResult(section); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var row = new PipingFailureMechanismSectionResultRow( + result, Enumerable.Empty(), failureMechanism, assessmentSection, ConstructionProperties); + + // Call + TestDelegate test = () => row.ManualAssemblyProbability = value; + + // Assert + const string expectedMessage = "De waarde voor de faalkans moet in het bereik [0,0, 1,0] liggen."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + mocks.VerifyAll(); + } + } + + [Test] + public void GivenRowWithoutAssemblyErrors_WhenUpdatingAndAssemblyThrowsException_ThenAssemblyGroupSetToNone() + { + // Given + var random = new Random(39); + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new PipingFailureMechanismSectionResult(section); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + calculator.SimpleAssessmentAssemblyOutput = new FailureMechanismSectionAssembly( + random.NextDouble(), + random.NextEnumValue()); + calculator.DetailedAssessmentAssemblyOutput = new FailureMechanismSectionAssembly( + random.NextDouble(), + random.NextEnumValue()); + calculator.TailorMadeAssessmentAssemblyOutput = new FailureMechanismSectionAssembly( + random.NextDouble(), + random.NextEnumValue()); + calculator.CombinedAssemblyOutput = new FailureMechanismSectionAssembly( + random.NextDouble(), + random.NextEnumValue()); + var row = new PipingFailureMechanismSectionResultRow(result, + Enumerable.Empty(), + failureMechanism, + assessmentSection, + ConstructionProperties); + + // Precondition + Assert.AreEqual(FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(calculator.SimpleAssessmentAssemblyOutput.Group), + row.SimpleAssemblyCategoryGroup); + Assert.AreEqual(FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(calculator.DetailedAssessmentAssemblyOutput.Group), + row.DetailedAssemblyCategoryGroup); + Assert.AreEqual(FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(calculator.TailorMadeAssessmentAssemblyOutput.Group), + row.TailorMadeAssemblyCategoryGroup); + Assert.AreEqual(FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(calculator.CombinedAssemblyOutput.Group), + row.CombinedAssemblyCategoryGroup); + Assert.AreEqual(calculator.CombinedAssemblyOutput.Probability, row.CombinedAssemblyProbability); + + // When + calculator.ThrowExceptionOnCalculate = true; + row.SimpleAssessmentResult = SimpleAssessmentResultType.AssessFurther; + + // Then + string expectedAssemblyDisplayName = FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(FailureMechanismSectionAssemblyCategoryGroup.None); + Assert.AreEqual(expectedAssemblyDisplayName, row.SimpleAssemblyCategoryGroup); + Assert.AreEqual(expectedAssemblyDisplayName, row.DetailedAssemblyCategoryGroup); + Assert.AreEqual(expectedAssemblyDisplayName, row.TailorMadeAssemblyCategoryGroup); + Assert.AreEqual(expectedAssemblyDisplayName, row.CombinedAssemblyCategoryGroup); + Assert.IsNaN(row.CombinedAssemblyProbability); + + mocks.VerifyAll(); + } + } + + [Test] + public void GivenRowWithAssemblyErrors_WhenUpdatingAndAssemblyDoesNotThrowException_ExpectedColumnStates() + { + // Given + var random = new Random(39); + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new PipingFailureMechanismSectionResult(section); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + calculator.ThrowExceptionOnCalculate = true; + calculator.SimpleAssessmentAssemblyOutput = new FailureMechanismSectionAssembly( + random.NextDouble(), + random.NextEnumValue()); + calculator.DetailedAssessmentAssemblyOutput = new FailureMechanismSectionAssembly( + random.NextDouble(), + random.NextEnumValue()); + calculator.TailorMadeAssessmentAssemblyOutput = new FailureMechanismSectionAssembly( + random.NextDouble(), + random.NextEnumValue()); + calculator.CombinedAssemblyOutput = new FailureMechanismSectionAssembly( + random.NextDouble(), + random.NextEnumValue()); + + var row = new PipingFailureMechanismSectionResultRow(result, + Enumerable.Empty(), + failureMechanism, + assessmentSection, + ConstructionProperties); + + // Precondition + IDictionary columnStateDefinitions = row.ColumnStateDefinitions; + const string expectedErrorText = "Message"; + + Assert.AreEqual(expectedErrorText, columnStateDefinitions[ConstructionProperties.SimpleAssemblyCategoryGroupIndex].ErrorText); + Assert.AreEqual(expectedErrorText, columnStateDefinitions[ConstructionProperties.DetailedAssemblyCategoryGroupIndex].ErrorText); + Assert.AreEqual(expectedErrorText, columnStateDefinitions[ConstructionProperties.TailorMadeAssemblyCategoryGroupIndex].ErrorText); + Assert.AreEqual(expectedErrorText, columnStateDefinitions[ConstructionProperties.CombinedAssemblyCategoryGroupIndex].ErrorText); + Assert.AreEqual(expectedErrorText, columnStateDefinitions[ConstructionProperties.CombinedAssemblyProbabilityIndex].ErrorText); + + // When + calculator.ThrowExceptionOnCalculate = false; + row.SimpleAssessmentResult = SimpleAssessmentResultType.AssessFurther; + + // Then + Assert.AreEqual(string.Empty, columnStateDefinitions[ConstructionProperties.SimpleAssemblyCategoryGroupIndex].ErrorText); + Assert.AreEqual(string.Empty, columnStateDefinitions[ConstructionProperties.DetailedAssemblyCategoryGroupIndex].ErrorText); + Assert.AreEqual(string.Empty, columnStateDefinitions[ConstructionProperties.TailorMadeAssemblyCategoryGroupIndex].ErrorText); + Assert.AreEqual(string.Empty, columnStateDefinitions[ConstructionProperties.CombinedAssemblyCategoryGroupIndex].ErrorText); + Assert.AreEqual(string.Empty, columnStateDefinitions[ConstructionProperties.CombinedAssemblyProbabilityIndex].ErrorText); + + mocks.VerifyAll(); + } + } + + #region Column States + + [Test] + [TestCase(SimpleAssessmentResultType.None, true)] + [TestCase(SimpleAssessmentResultType.NotApplicable, false)] + [TestCase(SimpleAssessmentResultType.ProbabilityNegligible, false)] + [TestCase(SimpleAssessmentResultType.AssessFurther, true)] + public void Constructor_WithSimpleAssessmentResultSet_ExpectedColumnStates(SimpleAssessmentResultType simpleAssessmentResult, + bool cellsEnabled) + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new PipingFailureMechanismSectionResult(section) + { + SimpleAssessmentResult = simpleAssessmentResult, + TailorMadeAssessmentResult = TailorMadeAssessmentProbabilityCalculationResultType.Probability + }; + var calculationScenarios = new[] + { + PipingCalculationScenarioTestFactory.CreatePipingCalculationScenario(section) + }; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + // Call + var row = new PipingFailureMechanismSectionResultRow( + result, calculationScenarios, failureMechanism, assessmentSection, ConstructionProperties); + + // Assert + IDictionary columnStateDefinitions = row.ColumnStateDefinitions; + + FailureMechanismSectionResultRowTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.DetailedAssessmentResultIndex], + cellsEnabled); + FailureMechanismSectionResultRowTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.DetailedAssessmentProbabilityIndex], + cellsEnabled, + true); + + FailureMechanismSectionResultRowTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.TailorMadeAssessmentResultIndex], + cellsEnabled); + FailureMechanismSectionResultRowTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.TailorMadeAssessmentProbabilityIndex], + cellsEnabled); + + mocks.VerifyAll(); + } + } + + [Test] + [TestCase(DetailedAssessmentResultType.NotAssessed, false)] + [TestCase(DetailedAssessmentResultType.Probability, true)] + public void Constructor_WithDetailedAssessmentResultSet_ExpectedColumnStates(DetailedAssessmentResultType detailedAssessmentResult, + bool cellEnabled) + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new PipingFailureMechanismSectionResult(section) + { + DetailedAssessmentResult = detailedAssessmentResult + }; + var calculationScenarios = new[] + { + PipingCalculationScenarioTestFactory.CreatePipingCalculationScenario(section) + }; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + // Call + var row = new PipingFailureMechanismSectionResultRow( + result, calculationScenarios, failureMechanism, assessmentSection, ConstructionProperties); + + // Assert + IDictionary columnStateDefinitions = row.ColumnStateDefinitions; + FailureMechanismSectionResultRowTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.DetailedAssessmentProbabilityIndex], + cellEnabled, + true); + mocks.VerifyAll(); + } + } + + [Test] + [TestCase(TailorMadeAssessmentProbabilityCalculationResultType.None, false)] + [TestCase(TailorMadeAssessmentProbabilityCalculationResultType.NotAssessed, false)] + [TestCase(TailorMadeAssessmentProbabilityCalculationResultType.ProbabilityNegligible, false)] + [TestCase(TailorMadeAssessmentProbabilityCalculationResultType.Probability, true)] + public void Constructor_WithTailorMadeAssessmentResultSet_ExpectedColumnStates( + TailorMadeAssessmentProbabilityCalculationResultType tailorMadeAssessmentResult, + bool cellEnabled) + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new PipingFailureMechanismSectionResult(section) + { + TailorMadeAssessmentResult = tailorMadeAssessmentResult + }; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + // Call + var row = new PipingFailureMechanismSectionResultRow( + result, Enumerable.Empty(), failureMechanism, assessmentSection, ConstructionProperties); + + // Assert + IDictionary columnStateDefinitions = row.ColumnStateDefinitions; + FailureMechanismSectionResultRowTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.TailorMadeAssessmentProbabilityIndex], + cellEnabled); + mocks.VerifyAll(); + } + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Constructor_WithUseManualAssemblyProbability_ExpectedColumnStates(bool useManualAssemblyProbability) + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new PipingFailureMechanismSectionResult(section) + { + TailorMadeAssessmentResult = TailorMadeAssessmentProbabilityCalculationResultType.Probability, + UseManualAssemblyProbability = useManualAssemblyProbability + }; + var calculationScenarios = new[] + { + PipingCalculationScenarioTestFactory.CreatePipingCalculationScenario(section) + }; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + // Call + var row = new PipingFailureMechanismSectionResultRow( + result, calculationScenarios, failureMechanism, assessmentSection, ConstructionProperties); + + // Assert + IDictionary columnStateDefinitions = row.ColumnStateDefinitions; + + FailureMechanismSectionResultRowTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.SimpleAssessmentResultIndex], + !useManualAssemblyProbability); + FailureMechanismSectionResultRowTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.DetailedAssessmentResultIndex], + !useManualAssemblyProbability); + FailureMechanismSectionResultRowTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.DetailedAssessmentProbabilityIndex], + !useManualAssemblyProbability, true); + FailureMechanismSectionResultRowTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.TailorMadeAssessmentResultIndex], + !useManualAssemblyProbability); + FailureMechanismSectionResultRowTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.TailorMadeAssessmentProbabilityIndex], + !useManualAssemblyProbability); + + if (useManualAssemblyProbability) + { + FailureMechanismSectionResultRowTestHelper.AssertColumnStateIsDisabled( + columnStateDefinitions[ConstructionProperties.SimpleAssemblyCategoryGroupIndex]); + FailureMechanismSectionResultRowTestHelper.AssertColumnStateIsDisabled( + columnStateDefinitions[ConstructionProperties.DetailedAssemblyCategoryGroupIndex]); + FailureMechanismSectionResultRowTestHelper.AssertColumnStateIsDisabled( + columnStateDefinitions[ConstructionProperties.TailorMadeAssemblyCategoryGroupIndex]); + FailureMechanismSectionResultRowTestHelper.AssertColumnStateIsDisabled( + columnStateDefinitions[ConstructionProperties.CombinedAssemblyCategoryGroupIndex]); + } + + FailureMechanismSectionResultRowTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.CombinedAssemblyProbabilityIndex], + !useManualAssemblyProbability, true); + FailureMechanismSectionResultRowTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.ManualAssemblyProbabilityIndex], + useManualAssemblyProbability); + + mocks.VerifyAll(); + } + } + + [Test] + [TestCaseSource(typeof(FailureMechanismSectionResultRowTestHelper), nameof(FailureMechanismSectionResultRowTestHelper.CategoryGroupColorCases))] + public void Constructor_WithAssemblyCategoryGroupsSet_ExpectedColumnStates(FailureMechanismSectionAssemblyCategoryGroup assemblyCategoryGroup, + Color expectedBackgroundColor) + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new PipingFailureMechanismSectionResult(section) + { + TailorMadeAssessmentResult = TailorMadeAssessmentProbabilityCalculationResultType.Probability + }; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + var assemblyOutput = new FailureMechanismSectionAssembly(0, assemblyCategoryGroup); + calculator.SimpleAssessmentAssemblyOutput = assemblyOutput; + calculator.DetailedAssessmentAssemblyOutput = assemblyOutput; + calculator.TailorMadeAssessmentAssemblyOutput = assemblyOutput; + calculator.CombinedAssemblyCategoryOutput = assemblyCategoryGroup; + + // Call + var row = new PipingFailureMechanismSectionResultRow(result, + Enumerable.Empty(), + failureMechanism, + assessmentSection, + ConstructionProperties); + + // Assert + IDictionary columnStateDefinitions = row.ColumnStateDefinitions; + + FailureMechanismSectionResultRowTestHelper.AssertColumnWithColorState( + columnStateDefinitions[ConstructionProperties.SimpleAssemblyCategoryGroupIndex], expectedBackgroundColor); + FailureMechanismSectionResultRowTestHelper.AssertColumnWithColorState( + columnStateDefinitions[ConstructionProperties.DetailedAssemblyCategoryGroupIndex], expectedBackgroundColor); + FailureMechanismSectionResultRowTestHelper.AssertColumnWithColorState( + columnStateDefinitions[ConstructionProperties.TailorMadeAssemblyCategoryGroupIndex], expectedBackgroundColor); + FailureMechanismSectionResultRowTestHelper.AssertColumnWithColorState( + columnStateDefinitions[ConstructionProperties.CombinedAssemblyCategoryGroupIndex], expectedBackgroundColor); + + mocks.VerifyAll(); + } + } + + [Test] + [TestCase(SimpleAssessmentResultType.None)] + [TestCase(SimpleAssessmentResultType.AssessFurther)] + public void Constructor_TotalContributionNotHundred_DetailedAssessmentProbabilityHasErrorText( + SimpleAssessmentResultType simpleAssessmentResult) + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var sectionResult = new PipingFailureMechanismSectionResult(section) + { + SimpleAssessmentResult = simpleAssessmentResult + }; + + PipingCalculationScenario calculationScenario = PipingCalculationScenarioTestFactory.CreatePipingCalculationScenario(section); + calculationScenario.Contribution = (RoundedDouble) 0.3; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + // Call + var resultRow = new PipingFailureMechanismSectionResultRow( + sectionResult, + new[] + { + calculationScenario + }, + failureMechanism, + assessmentSection, + ConstructionProperties); + + // Assert + Assert.IsNaN(resultRow.DetailedAssessmentProbability); + Assert.AreEqual("Bijdrage van de geselecteerde scenario's voor dit vak moet opgeteld gelijk zijn aan 100%.", + resultRow.ColumnStateDefinitions[ConstructionProperties.DetailedAssessmentProbabilityIndex].ErrorText); + mocks.VerifyAll(); + } + } + + [Test] + [TestCase(SimpleAssessmentResultType.None)] + [TestCase(SimpleAssessmentResultType.AssessFurther)] + public void Constructor_NoCalculatedScenario_DetailedAssessmentProbabilityHasErrorText( + SimpleAssessmentResultType simpleAssessmentResult) + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var sectionResult = new PipingFailureMechanismSectionResult(section) + { + SimpleAssessmentResult = simpleAssessmentResult + }; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + // Call + var resultRow = new PipingFailureMechanismSectionResultRow( + sectionResult, + new[] + { + PipingCalculationScenarioTestFactory.CreateNotCalculatedPipingCalculationScenario(section) + }, + failureMechanism, + assessmentSection, + ConstructionProperties); + + // Assert + Assert.IsNaN(resultRow.DetailedAssessmentProbability); + Assert.AreEqual("Alle berekeningen voor dit vak moeten uitgevoerd zijn.", + resultRow.ColumnStateDefinitions[ConstructionProperties.DetailedAssessmentProbabilityIndex].ErrorText); + mocks.VerifyAll(); + } + } + + [Test] + [TestCase(SimpleAssessmentResultType.None)] + [TestCase(SimpleAssessmentResultType.AssessFurther)] + public void Constructor_DetailedAssessmentProbabilityNaN_DetailedAssessmentProbabilityHasErrorText( + SimpleAssessmentResultType simpleAssessmentResult) + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var sectionResult = new PipingFailureMechanismSectionResult(section) + { + SimpleAssessmentResult = simpleAssessmentResult + }; + + PipingCalculationScenario calculationScenario = PipingCalculationScenarioTestFactory.CreateNotCalculatedPipingCalculationScenario( + section); + calculationScenario.Output = new PipingOutput(new PipingOutput.ConstructionProperties()); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + // Call + var resultRow = new PipingFailureMechanismSectionResultRow( + sectionResult, + new[] + { + calculationScenario + }, + failureMechanism, + assessmentSection, + ConstructionProperties); + + // Assert + Assert.IsNaN(resultRow.DetailedAssessmentProbability); + Assert.AreEqual("Alle berekeningen voor dit vak moeten een geldige uitkomst hebben.", + resultRow.ColumnStateDefinitions[ConstructionProperties.DetailedAssessmentProbabilityIndex].ErrorText); + mocks.VerifyAll(); + } + } + + [Test] + [TestCase(SimpleAssessmentResultType.None)] + [TestCase(SimpleAssessmentResultType.AssessFurther)] + public void Constructor_NoCalculationScenarios_DetailedAssessmentProbabilityHasErrorText( + SimpleAssessmentResultType simpleAssessmentResult) + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var sectionResult = new PipingFailureMechanismSectionResult(section) + { + SimpleAssessmentResult = simpleAssessmentResult + }; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + // Call + var resultRow = new PipingFailureMechanismSectionResultRow( + sectionResult, + Enumerable.Empty(), + failureMechanism, + assessmentSection, + ConstructionProperties); + + // Assert + Assert.IsNaN(resultRow.DetailedAssessmentProbability); + Assert.AreEqual("Er moet minimaal één maatgevende berekening voor dit vak worden geselecteerd.", + resultRow.ColumnStateDefinitions[ConstructionProperties.DetailedAssessmentProbabilityIndex].ErrorText); + mocks.VerifyAll(); + } + } + + [Test] + [TestCase(SimpleAssessmentResultType.None)] + [TestCase(SimpleAssessmentResultType.AssessFurther)] + public void Constructor_NoCalculationScenariosRelevant_DetailedAssessmentProbabilityHasErrorText( + SimpleAssessmentResultType simpleAssessmentResult) + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var sectionResult = new PipingFailureMechanismSectionResult(section) + { + SimpleAssessmentResult = simpleAssessmentResult + }; + + PipingCalculationScenario calculationScenario = PipingCalculationScenarioTestFactory.CreateIrrelevantPipingCalculationScenario( + section); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + // Call + var resultRow = new PipingFailureMechanismSectionResultRow( + sectionResult, + new[] + { + calculationScenario + }, + failureMechanism, + assessmentSection, + ConstructionProperties); + + // Assert + Assert.IsNaN(resultRow.DetailedAssessmentProbability); + Assert.AreEqual("Er moet minimaal één maatgevende berekening voor dit vak worden geselecteerd.", + resultRow.ColumnStateDefinitions[ConstructionProperties.DetailedAssessmentProbabilityIndex].ErrorText); + mocks.VerifyAll(); + } + } + + #endregion + + #region Registration + + [Test] public void SimpleAssessmentResult_SetNewValue_NotifyObserversAndPropertyChanged() { // Setup + var failureMechanism = new PipingFailureMechanism(); + var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); var observer = mocks.StrictMock(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new PipingFailureMechanismSectionResult(section); + result.Attach(observer); + + var newValue = new Random(21).NextEnumValue(); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var row = new PipingFailureMechanismSectionResultRow(result, + Enumerable.Empty(), + failureMechanism, + assessmentSection, + ConstructionProperties); + + // Call + row.SimpleAssessmentResult = newValue; + + // Assert + Assert.AreEqual(newValue, result.SimpleAssessmentResult); + mocks.VerifyAll(); + } + } + + [Test] + public void DetailedAssessmentResult_SetNewValue_NotifyObserversAndPropertyChanged() + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + var random = new Random(39); - var newValue = random.NextEnumValue(); + var newValue = random.NextEnumValue(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new PipingFailureMechanismSectionResult(section); result.Attach(observer); - var row = new PipingFailureMechanismSectionResultRow(result, Enumerable.Empty(), - new PipingFailureMechanism(), assessmentSection); + using (new AssemblyToolCalculatorFactoryConfig()) + { + var row = new PipingFailureMechanismSectionResultRow( + result, Enumerable.Empty(), failureMechanism, assessmentSection, ConstructionProperties); - // Call - row.SimpleAssessmentResult = newValue; + // Call + row.DetailedAssessmentResult = newValue; - // Assert - Assert.AreEqual(newValue, result.SimpleAssessmentResult); - mocks.VerifyAll(); + // Assert + Assert.AreEqual(newValue, result.DetailedAssessmentResult); + mocks.VerifyAll(); + } } [Test] - public void DetailedAssessmentProbability_RelevantScenariosDone_ResultOfSection() + public void DetailedAssessmentProbability_NoCalculationSet_ReturnNaN() { // Setup var failureMechanism = new PipingFailureMechanism(); @@ -171,51 +1042,196 @@ mocks.ReplayAll(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); - PipingCalculationScenario scenario = PipingCalculationScenarioTestFactory.CreatePipingCalculationScenario(section); - scenario.Contribution = (RoundedDouble) 1.0; + var sectionResult = new PipingFailureMechanismSectionResult(section); - var result = new PipingFailureMechanismSectionResult(section); - var row = new PipingFailureMechanismSectionResultRow(result, new[] + using (new AssemblyToolCalculatorFactoryConfig()) { - scenario - }, failureMechanism, assessmentSection); + var resultRow = new PipingFailureMechanismSectionResultRow(sectionResult, Enumerable.Empty(), failureMechanism, assessmentSection, ConstructionProperties); - // Call - double detailedAssessmentProbability = row.DetailedAssessmentProbability; + // Call + double detailedAssessmentProbability = resultRow.DetailedAssessmentProbability; - // Assert - double expected = result.GetDetailedAssessmentProbability(new[] + // Assert + Assert.IsNaN(detailedAssessmentProbability); + mocks.VerifyAll(); + } + } + + [Test] + [TestCase(CalculationScenarioStatus.Failed)] + [TestCase(CalculationScenarioStatus.NotCalculated)] + public void DetailedAssessmentProbability_CalculationNotDone_ReturnNaN(CalculationScenarioStatus status) + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var sectionResult = new PipingFailureMechanismSectionResult(section); + + using (new AssemblyToolCalculatorFactoryConfig()) { - scenario - }, failureMechanism, assessmentSection); - Assert.AreEqual(expected, detailedAssessmentProbability, 1e-6); - mocks.VerifyAll(); + var resultRow = new PipingFailureMechanismSectionResultRow( + sectionResult, + new[] + { + PipingCalculationScenarioTestFactory.CreateNotCalculatedPipingCalculationScenario(section) + }, + failureMechanism, + assessmentSection, + ConstructionProperties); + + // Call + double detailedAssessmentProbability = resultRow.DetailedAssessmentProbability; + + // Assert + Assert.IsNaN(detailedAssessmentProbability); + mocks.VerifyAll(); + } } [Test] - public void TailorMadeAssessmentProbability_ValueSet_ReturnExpectedValue() + public void DetailedAssessmentProbability_CalculationSuccessful_ReturnDetailedAssessmentProbability() { // Setup + var failureMechanism = new PipingFailureMechanism(); + var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var sectionResult = new PipingFailureMechanismSectionResult(section); + var calculationScenarios = new[] + { + PipingCalculationScenarioTestFactory.CreatePipingCalculationScenario(section) + }; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var resultRow = new PipingFailureMechanismSectionResultRow( + sectionResult, + calculationScenarios, + failureMechanism, + assessmentSection, + ConstructionProperties); + + // Call + double detailedAssessmentProbability = resultRow.DetailedAssessmentProbability; + + // Assert + Assert.AreEqual(sectionResult.GetDetailedAssessmentProbability(calculationScenarios, + failureMechanism, + assessmentSection), + detailedAssessmentProbability); + mocks.VerifyAll(); + } + } + + [Test] + public void TailorMadeAssessmentResult_SetNewValue_NotifyObserversAndPropertyChanged() + { + // Setup var failureMechanism = new PipingFailureMechanism(); - var random = new Random(21); - double assessmentLayerThree = random.NextDouble(); + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); - var sectionResult = new PipingFailureMechanismSectionResult( - FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); - var row = new PipingFailureMechanismSectionResultRow(sectionResult, Enumerable.Empty(), - failureMechanism, assessmentSection); + var random = new Random(39); + var newValue = random.NextEnumValue(); - // Call - row.TailorMadeAssessmentProbability = assessmentLayerThree; + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new PipingFailureMechanismSectionResult(section); + result.Attach(observer); - // Assert - Assert.AreEqual(assessmentLayerThree, sectionResult.TailorMadeAssessmentProbability); - mocks.VerifyAll(); + using (new AssemblyToolCalculatorFactoryConfig()) + { + var row = new PipingFailureMechanismSectionResultRow( + result, Enumerable.Empty(), failureMechanism, assessmentSection, ConstructionProperties); + + // Call + row.TailorMadeAssessmentResult = newValue; + + // Assert + Assert.AreEqual(newValue, result.TailorMadeAssessmentResult); + mocks.VerifyAll(); + } } + + [Test] + [TestCase(0)] + [TestCase(1)] + [TestCase(0.5)] + [TestCase(1e-6)] + [TestCase(double.NaN)] + public void TailorMadeAssessmentProbability_ValidValue_NotifyObserversAndPropertyChanged(double value) + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new PipingFailureMechanismSectionResult(section); + result.Attach(observer); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var row = new PipingFailureMechanismSectionResultRow( + result, Enumerable.Empty(), failureMechanism, assessmentSection, ConstructionProperties); + + // Call + row.TailorMadeAssessmentProbability = value; + + // Assert + Assert.AreEqual(value, row.TailorMadeAssessmentProbability); + mocks.VerifyAll(); + } + } + + [Test] + [SetCulture("nl-NL")] + [TestCase(-20)] + [TestCase(-1e-6)] + [TestCase(1 + 1e-6)] + [TestCase(12)] + public void TailorMadeAssessmentProbability_InvalidValue_ThrowsArgumentOutOfRangeException(double value) + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new PipingFailureMechanismSectionResult(section); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var row = new PipingFailureMechanismSectionResultRow( + result, Enumerable.Empty(), failureMechanism, assessmentSection, ConstructionProperties); + + // Call + TestDelegate test = () => row.TailorMadeAssessmentProbability = value; + + // Assert + const string expectedMessage = "De waarde voor de faalkans moet in het bereik [0,0, 1,0] liggen."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + mocks.VerifyAll(); + } + } + + #endregion } } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Integration.Test/PipingFailureMechanismResultViewIntegrationTest.cs =================================================================== diff -u -r4cced5dc46fe7dd8896ad15d1ec190dec9b2358e -rf665294814c085178591a35d0d811a1df72feb55 --- Ringtoets/Piping/test/Ringtoets.Piping.Integration.Test/PipingFailureMechanismResultViewIntegrationTest.cs (.../PipingFailureMechanismResultViewIntegrationTest.cs) (revision 4cced5dc46fe7dd8896ad15d1ec190dec9b2358e) +++ Ringtoets/Piping/test/Ringtoets.Piping.Integration.Test/PipingFailureMechanismResultViewIntegrationTest.cs (.../PipingFailureMechanismResultViewIntegrationTest.cs) (revision f665294814c085178591a35d0d811a1df72feb55) @@ -40,7 +40,7 @@ [TestFixture] public class PipingFailureMechanismResultViewIntegrationTest { - private const int detailedAssessmentIndex = 2; + private const int detailedAssessmentIndex = 3; [Test] [SetCulture("nl-NL")]