Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Data/DerivedMacroStabilityInwardsOutputFactory.cs =================================================================== diff -u -r31eb717b3eae473dc7846e6dbe48d06e92b4b964 -r74df3b2f37b578eb5f0d5c8d33379d965805bb8e --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Data/DerivedMacroStabilityInwardsOutputFactory.cs (.../DerivedMacroStabilityInwardsOutputFactory.cs) (revision 31eb717b3eae473dc7846e6dbe48d06e92b4b964) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Data/DerivedMacroStabilityInwardsOutputFactory.cs (.../DerivedMacroStabilityInwardsOutputFactory.cs) (revision 74df3b2f37b578eb5f0d5c8d33379d965805bb8e) @@ -82,13 +82,13 @@ } /// - /// Calculates the required probability of the piping failure mechanism for the complete assessment section. + /// Calculates the required probability of the macro stability inwards failure mechanism for the complete assessment section. /// /// The constant a. /// The constant b. /// The length of the assessment section. /// The norm. - /// The contribution of piping to the total failure. + /// The contribution of macro stability inwards to the total failure. /// A value representing the required probability. private static double CalculateRequiredProbability(double constantA, double constantB, double sectionLength, double norm, double contribution) { Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Ringtoets.MacroStabilityInwards.Forms.csproj =================================================================== diff -u -rd7696913d8f9239cb80eb2c3bac6cc0ccf23d479 -r74df3b2f37b578eb5f0d5c8d33379d965805bb8e --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Ringtoets.MacroStabilityInwards.Forms.csproj (.../Ringtoets.MacroStabilityInwards.Forms.csproj) (revision d7696913d8f9239cb80eb2c3bac6cc0ccf23d479) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Ringtoets.MacroStabilityInwards.Forms.csproj (.../Ringtoets.MacroStabilityInwards.Forms.csproj) (revision 74df3b2f37b578eb5f0d5c8d33379d965805bb8e) @@ -168,6 +168,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/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsFailureMechanismResultView.cs =================================================================== diff -u -rd6f110ecb32392f3ff1983a5e3e2b1f4603ae917 -r74df3b2f37b578eb5f0d5c8d33379d965805bb8e --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsFailureMechanismResultView.cs (.../MacroStabilityInwardsFailureMechanismResultView.cs) (revision d6f110ecb32392f3ff1983a5e3e2b1f4603ae917) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsFailureMechanismResultView.cs (.../MacroStabilityInwardsFailureMechanismResultView.cs) (revision 74df3b2f37b578eb5f0d5c8d33379d965805bb8e) @@ -21,27 +21,33 @@ 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.MacroStabilityInwards.Data; -using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.MacroStabilityInwards.Forms.Views { /// /// The view for the . /// public class MacroStabilityInwardsFailureMechanismResultView : FailureMechanismResultView + MacroStabilityInwardsFailureMechanismSectionResultRow, MacroStabilityInwardsFailureMechanism> { - 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; @@ -52,10 +58,9 @@ /// Creates a new instance of . /// /// The assessment section that the failure mechanism belongs to. - public MacroStabilityInwardsFailureMechanismResultView( - IObservableEnumerable failureMechanismSectionResults, - MacroStabilityInwardsFailureMechanism failureMechanism, - IAssessmentSection assessmentSection) + public MacroStabilityInwardsFailureMechanismResultView(IObservableEnumerable failureMechanismSectionResults, + MacroStabilityInwardsFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) : base(failureMechanismSectionResults, failureMechanism) { if (assessmentSection == null) @@ -81,136 +86,97 @@ c => c.Children); CalculationGroup observableGroup = failureMechanism.CalculationsGroup; - calculationInputObserver.Observable = observableGroup; calculationOutputObserver.Observable = observableGroup; calculationGroupObserver.Observable = observableGroup; } protected override void Dispose(bool disposing) { - DataGridViewControl.CellFormatting -= ShowDetailedAssessmentErrors; - DataGridViewControl.CellFormatting -= DisableIrrelevantFieldsFormatting; - calculationInputObserver.Dispose(); calculationOutputObserver.Dispose(); calculationGroupObserver.Dispose(); base.Dispose(disposing); } - protected override MacroStabilityInwardsFailureMechanismSectionResultRow CreateFailureMechanismSectionResultRow(MacroStabilityInwardsFailureMechanismSectionResult sectionResult) + protected override MacroStabilityInwardsFailureMechanismSectionResultRow CreateFailureMechanismSectionResultRow( + MacroStabilityInwardsFailureMechanismSectionResult sectionResult) { - return new MacroStabilityInwardsFailureMechanismSectionResultRow(sectionResult, - FailureMechanism.Calculations.OfType(), - FailureMechanism, - assessmentSection); + return new MacroStabilityInwardsFailureMechanismSectionResultRow( + sectionResult, + FailureMechanism.Calculations.Cast(), + FailureMechanism, + assessmentSection, + new MacroStabilityInwardsFailureMechanismSectionResultRow.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(MacroStabilityInwardsFailureMechanismSectionResultRow.Name), - RingtoetsCommonFormsResources.Section_DisplayName, - true); + FailureMechanismSectionResultViewColumnBuilder.AddSectionNameColumn( + DataGridViewControl, + nameof(MacroStabilityInwardsFailureMechanismSectionResultRow.Name)); - EnumDisplayWrapper[] simpleAssessmentDataSource = - Enum.GetValues(typeof(SimpleAssessmentResultType)) - .OfType() - .Select(sa => new EnumDisplayWrapper(sa)) - .ToArray(); + FailureMechanismSectionResultViewColumnBuilder.AddSimpleAssessmentResultColumn( + DataGridViewControl, + nameof(MacroStabilityInwardsFailureMechanismSectionResultRow.SimpleAssessmentResult)); - DataGridViewControl.AddComboBoxColumn( - nameof(MacroStabilityInwardsFailureMechanismSectionResultRow.SimpleAssessmentResult), - RingtoetsCommonFormsResources.FailureMechanismResultView_SimpleAssessmentResult_DisplayName, - simpleAssessmentDataSource, - nameof(EnumDisplayWrapper.Value), - nameof(EnumDisplayWrapper.DisplayName)); + FailureMechanismSectionResultViewColumnBuilder.AddDetailedAssessmentProbabilityOnlyResultColumn( + DataGridViewControl, + nameof(MacroStabilityInwardsFailureMechanismSectionResultRow.DetailedAssessmentResult)); - DataGridViewControl.AddTextBoxColumn( - nameof(MacroStabilityInwardsFailureMechanismSectionResultRow.DetailedAssessmentProbability), - RingtoetsCommonFormsResources.FailureMechanismResultView_DetailedAssessmentResult_DisplayName, - true); - DataGridViewControl.AddTextBoxColumn( - nameof(MacroStabilityInwardsFailureMechanismSectionResultRow.AssessmentLayerThree), - RingtoetsCommonFormsResources.FailureMechanismResultView_TailorMadeAssessmentResult_DisplayName); - } + FailureMechanismSectionResultViewColumnBuilder.AddDetailedAssessmentProbabilityColumn( + DataGridViewControl, + nameof(MacroStabilityInwardsFailureMechanismSectionResultRow.DetailedAssessmentProbability)); - protected override void BindEvents() - { - base.BindEvents(); + FailureMechanismSectionResultViewColumnBuilder.AddTailorMadeAssessmentProbabilityCalculationResultColumn( + DataGridViewControl, + nameof(MacroStabilityInwardsFailureMechanismSectionResultRow.TailorMadeAssessmentResult)); - DataGridViewControl.CellFormatting += ShowDetailedAssessmentErrors; - DataGridViewControl.CellFormatting += DisableIrrelevantFieldsFormatting; - } + FailureMechanismSectionResultViewColumnBuilder.AddTailorMadeAssessmentProbabilityColumn( + DataGridViewControl, + nameof(MacroStabilityInwardsFailureMechanismSectionResultRow.TailorMadeAssessmentProbability)); - #region Event handling + FailureMechanismSectionResultViewColumnBuilder.AddSimpleAssemblyCategoryGroupColumn( + DataGridViewControl, + nameof(MacroStabilityInwardsFailureMechanismSectionResultRow.SimpleAssemblyCategoryGroup)); - private void DisableIrrelevantFieldsFormatting(object sender, DataGridViewCellFormattingEventArgs eventArgs) - { - 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.AddDetailedAssemblyCategoryGroupColumn( + DataGridViewControl, + nameof(MacroStabilityInwardsFailureMechanismSectionResultRow.DetailedAssemblyCategoryGroup)); - private void ShowDetailedAssessmentErrors(object sender, DataGridViewCellFormattingEventArgs e) - { - if (e.ColumnIndex != detailedAssessmentIndex) - { - return; - } + FailureMechanismSectionResultViewColumnBuilder.AddTailorMadeAssemblyCategoryGroupColumn( + DataGridViewControl, + nameof(MacroStabilityInwardsFailureMechanismSectionResultRow.TailorMadeAssemblyCategoryGroup)); - DataGridViewCell currentDataGridViewCell = DataGridViewControl.GetCell(e.RowIndex, e.ColumnIndex); + FailureMechanismSectionResultViewColumnBuilder.AddCombinedAssemblyCategoryGroupColumn( + DataGridViewControl, + nameof(MacroStabilityInwardsFailureMechanismSectionResultRow.CombinedAssemblyCategoryGroup)); - MacroStabilityInwardsFailureMechanismSectionResultRow resultRow = GetDataAtRow(e.RowIndex); - MacroStabilityInwardsFailureMechanismSectionResult rowObject = resultRow.GetSectionResult; - if (rowObject.SimpleAssessmentResult == SimpleAssessmentResultType.ProbabilityNegligible || - rowObject.SimpleAssessmentResult == SimpleAssessmentResultType.NotApplicable) - { - currentDataGridViewCell.ErrorText = string.Empty; - return; - } + FailureMechanismSectionResultViewColumnBuilder.AddCombinedAssemblyProbabilityColumn( + DataGridViewControl, + nameof(MacroStabilityInwardsFailureMechanismSectionResultRow.CombinedAssemblyProbability)); - MacroStabilityInwardsCalculationScenario[] relevantScenarios = rowObject.GetCalculationScenarios(FailureMechanism.Calculations.OfType()).ToArray(); - bool relevantScenarioAvailable = relevantScenarios.Length != 0; + FailureMechanismSectionResultViewColumnBuilder.AddUseManualAssemblyCategoryGroupColumn( + DataGridViewControl, + nameof(MacroStabilityInwardsFailureMechanismSectionResultRow.UseManualAssemblyProbability)); - 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(MacroStabilityInwardsFailureMechanismSectionResultRow.ManualAssemblyProbability)); } - - #endregion } } \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsFailureMechanismSectionResultRow.cs =================================================================== diff -u -rcb5473dc9372632b858565eef6a48a1efb6f14a2 -r74df3b2f37b578eb5f0d5c8d33379d965805bb8e --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsFailureMechanismSectionResultRow.cs (.../MacroStabilityInwardsFailureMechanismSectionResultRow.cs) (revision cb5473dc9372632b858565eef6a48a1efb6f14a2) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsFailureMechanismSectionResultRow.cs (.../MacroStabilityInwardsFailureMechanismSectionResultRow.cs) (revision 74df3b2f37b578eb5f0d5c8d33379d965805bb8e) @@ -22,11 +22,18 @@ 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.MacroStabilityInwards.Data; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.MacroStabilityInwards.Forms.Views { @@ -36,10 +43,25 @@ /// public class MacroStabilityInwardsFailureMechanismSectionResultRow : FailureMechanismSectionResultRow { - private const double tolerance = 1e-6; + 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 MacroStabilityInwardsFailureMechanism failureMechanism; private readonly IAssessmentSection assessmentSection; + private FailureMechanismSectionAssemblyCategoryGroup simpleAssemblyCategoryGroup; + private FailureMechanismSectionAssemblyCategoryGroup detailedAssemblyCategoryGroup; + private FailureMechanismSectionAssemblyCategoryGroup tailorMadeAssemblyCategoryGroup; + private FailureMechanismSectionAssemblyCategoryGroup combinedAssemblyCategoryGroup; /// /// Creates a new instance of . @@ -49,11 +71,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 MacroStabilityInwardsFailureMechanismSectionResultRow(MacroStabilityInwardsFailureMechanismSectionResult sectionResult, IEnumerable calculations, MacroStabilityInwardsFailureMechanism failureMechanism, - IAssessmentSection assessmentSection) + IAssessmentSection assessmentSection, + ConstructionProperties constructionProperties) : base(sectionResult) { if (calculations == null) @@ -71,14 +98,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 @@ -88,17 +138,67 @@ set { SectionResult.SimpleAssessmentResult = value; - SectionResult.NotifyObservers(); + UpdateInternalData(); } } /// + /// Gets or sets the value representing the detailed assessment result. + /// + /// Thrown when + /// is a valid value, but unsupported. + public DetailedAssessmentProbabilityOnlyResultType 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 outside of the valid ranges. + /// Thrown when is + /// not in the range [0,1]. + /// Thrown when + /// is a valid value, but unsupported. [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] - public double AssessmentLayerThree + public double TailorMadeAssessmentProbability { get { @@ -107,32 +207,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 MacroStabilityInwardsFailureMechanismSectionResult 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() + { + MacroStabilityInwardsCalculationScenario[] 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 = MacroStabilityInwardsFailureMechanismSectionResultAssemblyFactory.AssembleSimpleAssessment(SectionResult).Group; + } + catch (AssemblyException e) + { + simpleAssemblyCategoryGroup = FailureMechanismSectionAssemblyCategoryGroup.None; + ColumnStateDefinitions[simpleAssemblyCategoryGroupIndex].ErrorText = e.Message; + } + } + + private void TryGetDetailedAssemblyCategoryGroup() + { + try + { + detailedAssemblyCategoryGroup = MacroStabilityInwardsFailureMechanismSectionResultAssemblyFactory.AssembleDetailedAssessment( + SectionResult, + calculations, + failureMechanism, + assessmentSection).Group; + } + catch (AssemblyException e) + { + detailedAssemblyCategoryGroup = FailureMechanismSectionAssemblyCategoryGroup.None; + ColumnStateDefinitions[detailedAssemblyCategoryGroupIndex].ErrorText = e.Message; + } + } + + private void TryGetTailorMadeAssemblyCategoryGroup() + { + try + { + tailorMadeAssemblyCategoryGroup = MacroStabilityInwardsFailureMechanismSectionResultAssemblyFactory.AssembleTailorMadeAssessment( + SectionResult, + failureMechanism, + assessmentSection).Group; + } + catch (AssemblyException e) + { + tailorMadeAssemblyCategoryGroup = FailureMechanismSectionAssemblyCategoryGroup.None; + ColumnStateDefinitions[tailorMadeAssemblyCategoryGroupIndex].ErrorText = e.Message; + } + } + + private void TryGetCombinedAssemblyCategoryGroup() + { + try + { + FailureMechanismSectionAssembly combinedAssembly = + MacroStabilityInwardsFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssessment( + 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/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.TestUtil.Test/MacroStabilityInwardsCalculationScenarioTestFactoryTest.cs =================================================================== diff -u -r9871a2374e0f08658f7bec58412958b35f8a849b -r74df3b2f37b578eb5f0d5c8d33379d965805bb8e --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.TestUtil.Test/MacroStabilityInwardsCalculationScenarioTestFactoryTest.cs (.../MacroStabilityInwardsCalculationScenarioTestFactoryTest.cs) (revision 9871a2374e0f08658f7bec58412958b35f8a849b) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.TestUtil.Test/MacroStabilityInwardsCalculationScenarioTestFactoryTest.cs (.../MacroStabilityInwardsCalculationScenarioTestFactoryTest.cs) (revision 74df3b2f37b578eb5f0d5c8d33379d965805bb8e) @@ -36,9 +36,42 @@ public class MacroStabilityInwardsCalculationScenarioTestFactoryTest { [Test] - public void CreateMacroStabilityInwardsCalculationScenario_WithNoSection_ThrowsArgumentNullException() + public void CreateMacroStabilityInwardsCalculationScenariot_SectionNull_ThrowsArgumentNullException() { // Call + TestDelegate test = () => MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("section", paramName); + } + + [Test] + public void CreateMacroStabilityInwardsCalculationScenario_WithSection_CreatesCalculationWithOutputSet() + { + // Setup + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + + // Call + MacroStabilityInwardsCalculationScenario scenario = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(section); + + // Assert + Assert.IsTrue(scenario.IsRelevant); + + MacroStabilityInwardsOutput output = scenario.Output; + Assert.IsNotNull(output); + Assert.IsTrue(IsValidDouble(output.FactorOfStability)); + Assert.IsTrue(IsValidDouble(output.ZValue)); + Assert.IsTrue(IsValidDouble(output.ForbiddenZonesXEntryMax)); + Assert.IsTrue(IsValidDouble(output.ForbiddenZonesXEntryMin)); + Assert.IsNotNull(output.SlidingCurve); + Assert.IsNotNull(output.SlipPlane); + } + + [Test] + public void CreateMacroStabilityInwardsCalculationScenario_SectionNull_ThrowsArgumentNullException() + { + // Call TestDelegate test = () => MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(double.NaN, null); // Assert @@ -66,7 +99,7 @@ } [Test] - public void CreateMacroStabilityInwardsCalculationScenarioWithNaNOutput_WithNoSection_ThrowsArgumentNullException() + public void CreateMacroStabilityInwardsCalculationScenarioWithNaNOutput_SectionNull_ThrowsArgumentNullException() { // Call TestDelegate test = () => MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithNaNOutput(null); @@ -92,7 +125,7 @@ } [Test] - public void CreateIrrelevantMacroStabilityInwardsCalculationScenario_WithNoSection_ThrowsArgumentNullException() + public void CreateIrrelevantMacroStabilityInwardsCalculationScenario_SectionNull_ThrowsArgumentNullException() { // Call TestDelegate test = () => MacroStabilityInwardsCalculationScenarioTestFactory.CreateIrrelevantMacroStabilityInwardsCalculationScenario(null); @@ -118,7 +151,7 @@ } [Test] - public void CreateNotCalculatedMacroStabilityInwardsCalculationScenario_WithNoSection_ThrowsArgumentNullException() + public void CreateNotCalculatedMacroStabilityInwardsCalculationScenario_SectionNull_ThrowsArgumentNullException() { // Call TestDelegate test = () => MacroStabilityInwardsCalculationScenarioTestFactory.CreateNotCalculatedMacroStabilityInwardsCalculationScenario(null); Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.TestUtil/MacroStabilityInwardsCalculationScenarioTestFactory.cs =================================================================== diff -u -r9871a2374e0f08658f7bec58412958b35f8a849b -r74df3b2f37b578eb5f0d5c8d33379d965805bb8e --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.TestUtil/MacroStabilityInwardsCalculationScenarioTestFactory.cs (.../MacroStabilityInwardsCalculationScenarioTestFactory.cs) (revision 9871a2374e0f08658f7bec58412958b35f8a849b) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.TestUtil/MacroStabilityInwardsCalculationScenarioTestFactory.cs (.../MacroStabilityInwardsCalculationScenarioTestFactory.cs) (revision 74df3b2f37b578eb5f0d5c8d33379d965805bb8e) @@ -41,6 +41,20 @@ /// /// Creates a calculated scenario for which the surface line on the input intersects with . /// + /// The section for which an intersection will be created. + /// A new . + /// Thrown when is null. + public static MacroStabilityInwardsCalculationScenario CreateMacroStabilityInwardsCalculationScenario(FailureMechanismSection section) + { + MacroStabilityInwardsCalculationScenario scenario = CreateNotCalculatedMacroStabilityInwardsCalculationScenario(section); + scenario.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput(); + + return scenario; + } + + /// + /// Creates a calculated scenario for which the surface line on the input intersects with . + /// /// The value for . /// The section for which an intersection will be created. /// A new . Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Ringtoets.MacroStabilityInwards.Forms.Test.csproj =================================================================== diff -u -rf5b9652936357f6b97e4fc332b25f1c666248c3d -r74df3b2f37b578eb5f0d5c8d33379d965805bb8e --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Ringtoets.MacroStabilityInwards.Forms.Test.csproj (.../Ringtoets.MacroStabilityInwards.Forms.Test.csproj) (revision f5b9652936357f6b97e4fc332b25f1c666248c3d) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Ringtoets.MacroStabilityInwards.Forms.Test.csproj (.../Ringtoets.MacroStabilityInwards.Forms.Test.csproj) (revision 74df3b2f37b578eb5f0d5c8d33379d965805bb8e) @@ -138,6 +138,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/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsFailureMechanismResultViewTest.cs =================================================================== diff -u -rcb5473dc9372632b858565eef6a48a1efb6f14a2 -r74df3b2f37b578eb5f0d5c8d33379d965805bb8e --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsFailureMechanismResultViewTest.cs (.../MacroStabilityInwardsFailureMechanismResultViewTest.cs) (revision cb5473dc9372632b858565eef6a48a1efb6f14a2) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsFailureMechanismResultViewTest.cs (.../MacroStabilityInwardsFailureMechanismResultViewTest.cs) (revision 74df3b2f37b578eb5f0d5c8d33379d965805bb8e) @@ -20,24 +20,17 @@ // All rights reserved. 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; using Ringtoets.Common.Forms.Views; using Ringtoets.Common.Primitives; using Ringtoets.MacroStabilityInwards.Data; -using Ringtoets.MacroStabilityInwards.Data.TestUtil; using Ringtoets.MacroStabilityInwards.Forms.Views; namespace Ringtoets.MacroStabilityInwards.Forms.Test.Views @@ -46,9 +39,19 @@ public class MacroStabilityInwardsFailureMechanismResultViewTest { private const int nameColumnIndex = 0; - private const int simpleAssessmentIndex = 1; - private const int detailedAssessmentIndex = 2; - private const int assessmentLayerThreeIndex = 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] @@ -64,9 +67,25 @@ } [Test] - public void DefaultConstructor_DefaultValues() + public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException() { // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + // Call + TestDelegate call = () => new MacroStabilityInwardsFailureMechanismResultView(new ObservableList(), + failureMechanism, + null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void Constructor_ExpectedValues() + { + // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); @@ -77,8 +96,7 @@ using (var view = new MacroStabilityInwardsFailureMechanismResultView(failureMechanism.SectionResults, failureMechanism, assessmentSection)) { // Assert - Assert.IsInstanceOf>(view); + Assert.IsInstanceOf>(view); Assert.IsNull(view.Data); Assert.AreSame(failureMechanism, view.FailureMechanism); } @@ -87,40 +105,58 @@ } [Test] - public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException() + public void GivenFormWithMacroStabilityInwardsFailureMechanismResultView_ThenExpectedColumnsAreVisible() { - // Setup - var failureMechanism = new MacroStabilityInwardsFailureMechanism(); - - // Call - TestDelegate call = () => new MacroStabilityInwardsFailureMechanismResultView(failureMechanism.SectionResults, failureMechanism, null); - - // Assert - var exception = Assert.Throws(call); - Assert.AreEqual("assessmentSection", exception.ParamName); - } - - [Test] - public void Constructor_DataGridViewCorrectlyInitialized() - { - // Call - using (ShowFailureMechanismResultsView( - new MacroStabilityInwardsFailureMechanism(), - new ObservableList())) + // 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.IsInstanceOf(dataGridView.Columns[assessmentLayerThreeIndex]); + Assert.AreEqual(13, dataGridView.ColumnCount); + Assert.IsTrue(dataGridView.Columns[detailedAssessmentProbabilityIndex].ReadOnly); - 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[assessmentLayerThreeIndex].HeaderText); + 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("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); } @@ -130,379 +166,50 @@ public void FailureMechanismResultsView_AllDataSet_DataGridViewCorrectlyInitialized() { // Setup - MacroStabilityInwardsFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); - - // Call - using (ShowFailureMechanismResultsView(failureMechanism, failureMechanism.SectionResults)) + var results = new ObservableList { - var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + new MacroStabilityInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection("Section 1")) + }; - // Assert - DataGridViewRowCollection rows = dataGridView.Rows; - Assert.AreEqual(2, rows.Count); - - DataGridViewCellCollection cells = rows[0].Cells; - Assert.AreEqual(4, cells.Count); - Assert.AreEqual("Section 1", cells[nameColumnIndex].FormattedValue); - Assert.AreEqual(SimpleAssessmentResultType.None, cells[simpleAssessmentIndex].Value); - Assert.AreEqual("-", cells[detailedAssessmentIndex].FormattedValue); - Assert.AreEqual("-", cells[assessmentLayerThreeIndex].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[assessmentLayerThreeIndex].FormattedValue); - } - } - - [Test] - [TestCase(SimpleAssessmentResultType.None)] - [TestCase(SimpleAssessmentResultType.NotApplicable)] - [TestCase(SimpleAssessmentResultType.ProbabilityNegligible)] - [TestCase(SimpleAssessmentResultType.AssessFurther)] - public void FailureMechanismResultsView_ChangeComboBox_DataGridViewCorrectlySyncedAndStylingSet(SimpleAssessmentResultType simpleAssessmentResult) - { - // Setup - MacroStabilityInwardsFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); - // Call - using (ShowFailureMechanismResultsView(failureMechanism, failureMechanism.SectionResults)) + using (new AssemblyToolCalculatorFactoryConfig()) + using (ShowFailureMechanismResultsView(results)) { var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; - dataGridView.Rows[0].Cells[simpleAssessmentIndex].Value = simpleAssessmentResult; - // Assert DataGridViewRowCollection rows = dataGridView.Rows; + 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); - DataGridViewCell cellDetailedAssessment = cells[detailedAssessmentIndex]; - DataGridViewCell cellAssessmentLayerThree = cells[assessmentLayerThreeIndex]; - - Assert.AreEqual(simpleAssessmentResult, cells[simpleAssessmentIndex].Value); - Assert.AreEqual("-", cellDetailedAssessment.FormattedValue); - Assert.AreEqual("-", cellAssessmentLayerThree.FormattedValue); - - if (simpleAssessmentResult == SimpleAssessmentResultType.ProbabilityNegligible - || simpleAssessmentResult == SimpleAssessmentResultType.NotApplicable) - { - DataGridViewTestHelper.AssertCellIsDisabled(cellDetailedAssessment); - DataGridViewTestHelper.AssertCellIsDisabled(cellAssessmentLayerThree); - - Assert.IsTrue(cellAssessmentLayerThree.ReadOnly); - } - else - { - DataGridViewTestHelper.AssertCellIsEnabled(cellDetailedAssessment, true); - DataGridViewTestHelper.AssertCellIsEnabled(cellAssessmentLayerThree); - - Assert.IsFalse(cellAssessmentLayerThree.ReadOnly); - } + Assert.AreEqual(SimpleAssessmentResultType.None, cells[simpleAssessmentResultIndex].Value); + Assert.AreEqual(DetailedAssessmentProbabilityOnlyResultType.Probability, cells[detailedAssessmentResultIndex].Value); + Assert.AreEqual("-", cells[detailedAssessmentProbabilityIndex].FormattedValue); + Assert.AreEqual(TailorMadeAssessmentProbabilityCalculationResultType.None, cells[tailorMadeAssessmentResultIndex].Value); + 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("test", assessmentLayerThreeIndex)] - [TestCase(";/[].,~!@#$%^&*()_-+={}|?", assessmentLayerThreeIndex)] - public void FailureMechanismResultView_EditValueInvalid_ShowsErrorTooltip(string newValue, int cellIndex) + private MacroStabilityInwardsFailureMechanismResultView ShowFailureMechanismResultsView(IObservableEnumerable sectionResults) { - // Setup - MacroStabilityInwardsFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); - using (ShowFailureMechanismResultsView(failureMechanism, failureMechanism.SectionResults)) - { - 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); - } + return ShowFailureMechanismResultsView(new MacroStabilityInwardsFailureMechanism(), sectionResults); } - [Test] - [SetCulture("nl-NL")] - [TestCase(1.01)] - [TestCase(-0.01)] - [TestCase(5)] - [TestCase(-10)] - public void FailureMechanismResultView_EditValueAssessmentLayerThreeInvalid_ShowErrorToolTip(double newValue) + private MacroStabilityInwardsFailureMechanismResultView ShowFailureMechanismResultsView(MacroStabilityInwardsFailureMechanism failureMechanism, + IObservableEnumerable sectionResults) { - // Setup - MacroStabilityInwardsFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); - - using (ShowFailureMechanismResultsView(failureMechanism, failureMechanism.SectionResults)) - { - var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; - - // Call - dataGridView.Rows[0].Cells[assessmentLayerThreeIndex].Value = newValue.ToString(CultureInfo.CurrentCulture); - - // Assert - Assert.AreEqual("Kans moet in het bereik [0,0, 1,0] liggen.", dataGridView.Rows[0].ErrorText); - } - } - - [Test] - [SetCulture("nl-NL")] - [TestCase(1)] - [TestCase(0.5)] - [TestCase(1e-6)] - [TestCase(double.NaN)] - public void FailureMechanismResultView_EditValueAssessmentLayerThreeValid_DoNotShowErrorToolTipAndEditValue(double newValue) - { - // Setup - MacroStabilityInwardsFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); - - using (ShowFailureMechanismResultsView(failureMechanism, failureMechanism.SectionResults)) - { - var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; - - // Call - dataGridView.Rows[0].Cells[assessmentLayerThreeIndex].Value = newValue.ToString(CultureInfo.CurrentCulture); - - // Assert - Assert.IsEmpty(dataGridView.Rows[0].ErrorText); - Assert.AreEqual(newValue, failureMechanism.SectionResults.First().TailorMadeAssessmentProbability); - } - } - - [Test] - [TestCase(SimpleAssessmentResultType.None)] - [TestCase(SimpleAssessmentResultType.AssessFurther)] - public void FailureMechanismResultView_TotalContributionNotHundred_ShowsErrorTooltip(SimpleAssessmentResultType simpleAssessmentResult) - { - // Setup - const int rowIndex = 0; - MacroStabilityInwardsFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); - MacroStabilityInwardsCalculationScenario calculationScenario = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario( - 1.0 / 1000.0, - failureMechanism.Sections.First()); - calculationScenario.Contribution = (RoundedDouble) 0.3; - failureMechanism.CalculationsGroup.Children.Add(calculationScenario); - - using (ShowFailureMechanismResultsView(failureMechanism, failureMechanism.SectionResults)) - { - var gridTester = new ControlTester("dataGridView"); - var dataGridView = (DataGridView) gridTester.TheObject; - - DataGridViewCell dataGridViewCell = dataGridView.Rows[rowIndex].Cells[detailedAssessmentIndex]; - dataGridView.Rows[rowIndex].Cells[simpleAssessmentIndex].Value = simpleAssessmentResult; - - // 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] - [TestCase(SimpleAssessmentResultType.None)] - [TestCase(SimpleAssessmentResultType.NotApplicable)] - [TestCase(SimpleAssessmentResultType.AssessFurther)] - public void FailureMechanismResultView_DetailedAssessmentProbabilityHasValue_DoesNotShowsErrorTooltip(SimpleAssessmentResultType simpleAssessmentResult) - { - // Setup - const int rowIndex = 0; - MacroStabilityInwardsFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); - MacroStabilityInwardsCalculationScenario calculationScenario = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario( - (RoundedDouble) 1e-3, - failureMechanism.Sections.First()); - failureMechanism.CalculationsGroup.Children.Add(calculationScenario); - - using (ShowFailureMechanismResultsView(failureMechanism, failureMechanism.SectionResults)) - { - var gridTester = new ControlTester("dataGridView"); - var dataGridView = (DataGridView) gridTester.TheObject; - - DataGridViewCell dataGridViewCell = dataGridView.Rows[rowIndex].Cells[detailedAssessmentIndex]; - dataGridView.Rows[rowIndex].Cells[simpleAssessmentIndex].Value = simpleAssessmentResult; - - // Call - object formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. - - // Assert - Assert.IsEmpty(dataGridViewCell.ErrorText); - Assert.AreEqual("1/1", - formattedValue); - } - } - - [Test] - [TestCase(SimpleAssessmentResultType.None)] - [TestCase(SimpleAssessmentResultType.AssessFurther)] - public void FailureMechanismResultView_NoCalculatedScenario_ShowsErrorTooltip(SimpleAssessmentResultType simpleAssessmentResult) - { - // Setup - const int rowIndex = 0; - - MacroStabilityInwardsFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); - MacroStabilityInwardsCalculationScenario calculationScenario = MacroStabilityInwardsCalculationScenarioTestFactory.CreateNotCalculatedMacroStabilityInwardsCalculationScenario( - failureMechanism.Sections.First()); - failureMechanism.CalculationsGroup.Children.Add(calculationScenario); - - using (ShowFailureMechanismResultsView(failureMechanism, failureMechanism.SectionResults)) - { - var gridTester = new ControlTester("dataGridView"); - var dataGridView = (DataGridView) gridTester.TheObject; - - DataGridViewCell dataGridViewCell = dataGridView.Rows[rowIndex].Cells[detailedAssessmentIndex]; - dataGridView.Rows[rowIndex].Cells[simpleAssessmentIndex].Value = simpleAssessmentResult; - - // 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 simpleAssessmentResult) - { - // Setup - const int rowIndex = 0; - - MacroStabilityInwardsFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); - MacroStabilityInwardsCalculationScenario calculationScenario = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithNaNOutput( - failureMechanism.Sections.First()); - failureMechanism.CalculationsGroup.Children.Add(calculationScenario); - using (ShowFailureMechanismResultsView(failureMechanism, failureMechanism.SectionResults)) - { - var gridTester = new ControlTester("dataGridView"); - var dataGridView = (DataGridView) gridTester.TheObject; - - DataGridViewCell dataGridViewCell = dataGridView.Rows[rowIndex].Cells[detailedAssessmentIndex]; - dataGridView.Rows[rowIndex].Cells[simpleAssessmentIndex].Value = simpleAssessmentResult; - - // 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 simpleAssessmentResult) - { - // Setup - const int rowIndex = 0; - MacroStabilityInwardsFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); - - using (ShowFailureMechanismResultsView(failureMechanism, failureMechanism.SectionResults)) - { - var gridTester = new ControlTester("dataGridView"); - var dataGridView = (DataGridView) gridTester.TheObject; - - DataGridViewCell dataGridViewCell = dataGridView.Rows[rowIndex].Cells[detailedAssessmentIndex]; - dataGridView.Rows[rowIndex].Cells[simpleAssessmentIndex].Value = simpleAssessmentResult; - - // 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 simpleAssessmentResult) - { - // Setup - const int rowIndex = 0; - MacroStabilityInwardsFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); - MacroStabilityInwardsCalculationScenario calculationScenario = MacroStabilityInwardsCalculationScenarioTestFactory.CreateIrrelevantMacroStabilityInwardsCalculationScenario( - failureMechanism.Sections.First()); - failureMechanism.CalculationsGroup.Children.Add(calculationScenario); - - using (ShowFailureMechanismResultsView(failureMechanism, failureMechanism.SectionResults)) - { - var gridTester = new ControlTester("dataGridView"); - var dataGridView = (DataGridView) gridTester.TheObject; - - DataGridViewCell dataGridViewCell = dataGridView.Rows[rowIndex].Cells[detailedAssessmentIndex]; - dataGridView.Rows[rowIndex].Cells[simpleAssessmentIndex].Value = simpleAssessmentResult; - - // 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_SimpleAssessmentProbabilityNegligibleAndDetailedAssessmentProbabilityHasNaNOutput_DoesNotShowError() - { - // Setup - const int rowIndex = 0; - MacroStabilityInwardsFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); - MacroStabilityInwardsCalculationScenario calculationScenario = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithNaNOutput( - failureMechanism.Sections.First()); - failureMechanism.CalculationsGroup.Children.Add(calculationScenario); - - using (ShowFailureMechanismResultsView(failureMechanism, failureMechanism.SectionResults)) - { - 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); - } - } - - private static MacroStabilityInwardsFailureMechanism CreateFullyConfiguredFailureMechanism() - { - var failureMechanism = new MacroStabilityInwardsFailureMechanism(); - 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; - } - - private MacroStabilityInwardsFailureMechanismResultView ShowFailureMechanismResultsView( - MacroStabilityInwardsFailureMechanism failureMechanism, - IObservableEnumerable sectionResults) - { - var failureMechanismResultView = new MacroStabilityInwardsFailureMechanismResultView(sectionResults, failureMechanism, new ObservableTestAssessmentSectionStub()); + var failureMechanismResultView = new MacroStabilityInwardsFailureMechanismResultView(sectionResults, + failureMechanism, + new ObservableTestAssessmentSectionStub()); testForm.Controls.Add(failureMechanismResultView); testForm.Show(); Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsFailureMechanismSectionResultRowTest.cs =================================================================== diff -u -rcb5473dc9372632b858565eef6a48a1efb6f14a2 -r74df3b2f37b578eb5f0d5c8d33379d965805bb8e --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsFailureMechanismSectionResultRowTest.cs (.../MacroStabilityInwardsFailureMechanismSectionResultRowTest.cs) (revision cb5473dc9372632b858565eef6a48a1efb6f14a2) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsFailureMechanismSectionResultRowTest.cs (.../MacroStabilityInwardsFailureMechanismSectionResultRowTest.cs) (revision 74df3b2f37b578eb5f0d5c8d33379d965805bb8e) @@ -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,63 +51,96 @@ [TestFixture] public class MacroStabilityInwardsFailureMechanismSectionResultRowTest { + private static MacroStabilityInwardsFailureMechanismSectionResultRow.ConstructionProperties ConstructionProperties + { + get + { + return new MacroStabilityInwardsFailureMechanismSectionResultRow.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 MacroStabilityInwardsFailureMechanism(); - FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new MacroStabilityInwardsFailureMechanismSectionResult(section); // Call - var row = new MacroStabilityInwardsFailureMechanismSectionResultRow(result, Enumerable.Empty(), - failureMechanism, assessmentSection); + TestDelegate call = () => new MacroStabilityInwardsFailureMechanismSectionResultRow(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.AssessmentLayerThree, result.TailorMadeAssessmentProbability); - - TestHelper.AssertTypeConverter( - nameof(MacroStabilityInwardsFailureMechanismSectionResultRow.DetailedAssessmentProbability)); - TestHelper.AssertTypeConverter( - nameof(MacroStabilityInwardsFailureMechanismSectionResultRow.AssessmentLayerThree)); + 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 MacroStabilityInwardsFailureMechanismSectionResult(section); + + // Call + TestDelegate call = () => new MacroStabilityInwardsFailureMechanismSectionResultRow(result, + Enumerable.Empty(), + new MacroStabilityInwardsFailureMechanism(), + 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 MacroStabilityInwardsFailureMechanism(); - FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new MacroStabilityInwardsFailureMechanismSectionResult(section); // Call - TestDelegate test = () => new MacroStabilityInwardsFailureMechanismSectionResultRow(result, null, - failureMechanism, assessmentSection); + TestDelegate call = () => new MacroStabilityInwardsFailureMechanismSectionResultRow(result, + Enumerable.Empty(), + new MacroStabilityInwardsFailureMechanism(), + 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(); @@ -108,61 +151,872 @@ var result = new MacroStabilityInwardsFailureMechanismSectionResult(section); // Call - TestDelegate call = () => new MacroStabilityInwardsFailureMechanismSectionResultRow(result, Enumerable.Empty(), - null, assessmentSection); + TestDelegate call = () => new MacroStabilityInwardsFailureMechanismSectionResultRow(result, + null, + new MacroStabilityInwardsFailureMechanism(), + 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 MacroStabilityInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new MacroStabilityInwardsFailureMechanismSectionResult(section); + var calculationScenarios = new[] + { + MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(section) + }; // Call - TestDelegate call = () => new MacroStabilityInwardsFailureMechanismSectionResultRow(result, Enumerable.Empty(), - new MacroStabilityInwardsFailureMechanism(), null); + using (new AssemblyToolCalculatorFactoryConfig()) + { + var row = new MacroStabilityInwardsFailureMechanismSectionResultRow(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(MacroStabilityInwardsFailureMechanismSectionResultRow.DetailedAssessmentProbability)); + TestHelper.AssertTypeConverter( + nameof(MacroStabilityInwardsFailureMechanismSectionResultRow.TailorMadeAssessmentProbability)); + TestHelper.AssertTypeConverter( + nameof(MacroStabilityInwardsFailureMechanismSectionResultRow.CombinedAssemblyProbability)); + TestHelper.AssertTypeConverter( + nameof(MacroStabilityInwardsFailureMechanismSectionResultRow.ManualAssemblyProbability)); + mocks.VerifyAll(); + } } [Test] + public void Constructor_AssemblyRan_ReturnCategoryGroups() + { + // Setup + var random = new Random(39); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new MacroStabilityInwardsFailureMechanismSectionResult(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 MacroStabilityInwardsFailureMechanismSectionResultRow(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 MacroStabilityInwardsFailureMechanism(); + + 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 MacroStabilityInwardsFailureMechanismSectionResult(section); + result.Attach(observer); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var row = new MacroStabilityInwardsFailureMechanismSectionResultRow( + 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 MacroStabilityInwardsFailureMechanism(); + + 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 MacroStabilityInwardsFailureMechanismSectionResult(section); + result.Attach(observer); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var row = new MacroStabilityInwardsFailureMechanismSectionResultRow( + 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 MacroStabilityInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new MacroStabilityInwardsFailureMechanismSectionResult(section); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var row = new MacroStabilityInwardsFailureMechanismSectionResultRow( + 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 MacroStabilityInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new MacroStabilityInwardsFailureMechanismSectionResult(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 MacroStabilityInwardsFailureMechanismSectionResultRow(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 failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new MacroStabilityInwardsFailureMechanismSectionResult(section); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + calculator.ThrowExceptionOnCalculate = true; + + var row = new MacroStabilityInwardsFailureMechanismSectionResultRow(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 MacroStabilityInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new MacroStabilityInwardsFailureMechanismSectionResult(section) + { + SimpleAssessmentResult = simpleAssessmentResult, + TailorMadeAssessmentResult = TailorMadeAssessmentProbabilityCalculationResultType.Probability + }; + var calculationScenarios = new[] + { + MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(section) + }; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + // Call + var row = new MacroStabilityInwardsFailureMechanismSectionResultRow( + 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(DetailedAssessmentProbabilityOnlyResultType.NotAssessed, false)] + [TestCase(DetailedAssessmentProbabilityOnlyResultType.Probability, true)] + public void Constructor_WithDetailedAssessmentResultSet_ExpectedColumnStates(DetailedAssessmentProbabilityOnlyResultType detailedAssessmentResult, + bool cellEnabled) + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new MacroStabilityInwardsFailureMechanismSectionResult(section) + { + DetailedAssessmentResult = detailedAssessmentResult + }; + var calculationScenarios = new[] + { + MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(section) + }; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + // Call + var row = new MacroStabilityInwardsFailureMechanismSectionResultRow( + 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 MacroStabilityInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new MacroStabilityInwardsFailureMechanismSectionResult(section) + { + TailorMadeAssessmentResult = tailorMadeAssessmentResult + }; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + // Call + var row = new MacroStabilityInwardsFailureMechanismSectionResultRow( + 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 MacroStabilityInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new MacroStabilityInwardsFailureMechanismSectionResult(section) + { + TailorMadeAssessmentResult = TailorMadeAssessmentProbabilityCalculationResultType.Probability, + UseManualAssemblyProbability = useManualAssemblyProbability + }; + var calculationScenarios = new[] + { + MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(section) + }; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + // Call + var row = new MacroStabilityInwardsFailureMechanismSectionResultRow( + 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 MacroStabilityInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new MacroStabilityInwardsFailureMechanismSectionResult(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 MacroStabilityInwardsFailureMechanismSectionResultRow(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 MacroStabilityInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var sectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(section) + { + SimpleAssessmentResult = simpleAssessmentResult + }; + + MacroStabilityInwardsCalculationScenario calculationScenario = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(section); + calculationScenario.Contribution = (RoundedDouble) 0.3; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + // Call + var resultRow = new MacroStabilityInwardsFailureMechanismSectionResultRow( + 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 MacroStabilityInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var sectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(section) + { + SimpleAssessmentResult = simpleAssessmentResult + }; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + // Call + var resultRow = new MacroStabilityInwardsFailureMechanismSectionResultRow( + sectionResult, + new[] + { + MacroStabilityInwardsCalculationScenarioTestFactory.CreateNotCalculatedMacroStabilityInwardsCalculationScenario(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 MacroStabilityInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var sectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(section) + { + SimpleAssessmentResult = simpleAssessmentResult + }; + + MacroStabilityInwardsCalculationScenario calculationScenario = MacroStabilityInwardsCalculationScenarioTestFactory.CreateNotCalculatedMacroStabilityInwardsCalculationScenario( + section); + calculationScenario.Output = MacroStabilityInwardsOutputTestFactory.CreateOutput(); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + // Call + var resultRow = new MacroStabilityInwardsFailureMechanismSectionResultRow( + 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 MacroStabilityInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var sectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(section) + { + SimpleAssessmentResult = simpleAssessmentResult + }; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + // Call + var resultRow = new MacroStabilityInwardsFailureMechanismSectionResultRow( + 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 MacroStabilityInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var sectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(section) + { + SimpleAssessmentResult = simpleAssessmentResult + }; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + // Call + var resultRow = new MacroStabilityInwardsFailureMechanismSectionResultRow( + sectionResult, + new[] + { + MacroStabilityInwardsCalculationScenarioTestFactory.CreateIrrelevantMacroStabilityInwardsCalculationScenario(section) + }, + 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 MacroStabilityInwardsFailureMechanism(); + 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 MacroStabilityInwardsFailureMechanismSectionResult(section); + result.Attach(observer); + + var newValue = new Random(21).NextEnumValue(); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var row = new MacroStabilityInwardsFailureMechanismSectionResultRow(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 MacroStabilityInwardsFailureMechanism(); + + 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 MacroStabilityInwardsFailureMechanismSectionResult(section); result.Attach(observer); - var row = new MacroStabilityInwardsFailureMechanismSectionResultRow(result, Enumerable.Empty(), - new MacroStabilityInwardsFailureMechanism(), assessmentSection); + using (new AssemblyToolCalculatorFactoryConfig()) + { + var row = new MacroStabilityInwardsFailureMechanismSectionResultRow( + 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 MacroStabilityInwardsFailureMechanism(); @@ -172,53 +1026,202 @@ mocks.ReplayAll(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); - MacroStabilityInwardsCalculationScenario scenario = - MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(0.2, section); - scenario.Contribution = (RoundedDouble) 1.0; + var sectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(section); - var result = new MacroStabilityInwardsFailureMechanismSectionResult(section); - var row = new MacroStabilityInwardsFailureMechanismSectionResultRow(result, new[] + using (new AssemblyToolCalculatorFactoryConfig()) { - scenario - }, failureMechanism, assessmentSection); + var resultRow = new MacroStabilityInwardsFailureMechanismSectionResultRow(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 MacroStabilityInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var sectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(section); + + MacroStabilityInwardsCalculationScenario scenario = MacroStabilityInwardsCalculationScenarioTestFactory.CreateNotCalculatedMacroStabilityInwardsCalculationScenario(section); + if (status == CalculationScenarioStatus.Failed) { - scenario - }, failureMechanism, assessmentSection); - Assert.AreEqual(expected, detailedAssessmentProbability, 1e-6); - mocks.VerifyAll(); + scenario.Output = MacroStabilityInwardsOutputTestFactory.CreateOutput(); + } + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var resultRow = new MacroStabilityInwardsFailureMechanismSectionResultRow( + sectionResult, + new[] + { + scenario + }, + failureMechanism, + assessmentSection, + ConstructionProperties); + + // Call + double detailedAssessmentProbability = resultRow.DetailedAssessmentProbability; + + // Assert + Assert.IsNaN(detailedAssessmentProbability); + mocks.VerifyAll(); + } } [Test] - public void AssessmentLayerThree_ValueSet_ReturnExpectedValue() + public void DetailedAssessmentProbability_CalculationSuccessful_ReturnDetailedAssessmentProbability() { // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var sectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(section); + var calculationScenarios = new[] + { + MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(section) + }; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var resultRow = new MacroStabilityInwardsFailureMechanismSectionResultRow( + 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 MacroStabilityInwardsFailureMechanism(); - 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 MacroStabilityInwardsFailureMechanismSectionResult( - FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); - var row = new MacroStabilityInwardsFailureMechanismSectionResultRow(sectionResult, - Enumerable.Empty(), - failureMechanism, assessmentSection); + var random = new Random(39); + var newValue = random.NextEnumValue(); - // Call - row.AssessmentLayerThree = assessmentLayerThree; + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new MacroStabilityInwardsFailureMechanismSectionResult(section); + result.Attach(observer); - // Assert - Assert.AreEqual(assessmentLayerThree, sectionResult.TailorMadeAssessmentProbability); - mocks.VerifyAll(); + using (new AssemblyToolCalculatorFactoryConfig()) + { + var row = new MacroStabilityInwardsFailureMechanismSectionResultRow( + 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 MacroStabilityInwardsFailureMechanism(); + + 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 MacroStabilityInwardsFailureMechanismSectionResult(section); + result.Attach(observer); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var row = new MacroStabilityInwardsFailureMechanismSectionResultRow( + 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 MacroStabilityInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new MacroStabilityInwardsFailureMechanismSectionResult(section); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var row = new MacroStabilityInwardsFailureMechanismSectionResultRow( + 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