Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/PropertyClasses/MacroStabilityInwardsCalculationsProperties.cs =================================================================== diff -u -rfbd1360d7ee58f83c97bd7ef829e16a493f3748c -r1f16a57392fb30cd9e33fdc63f701a483b40316b --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/PropertyClasses/MacroStabilityInwardsCalculationsProperties.cs (.../MacroStabilityInwardsCalculationsProperties.cs) (revision fbd1360d7ee58f83c97bd7ef829e16a493f3748c) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/PropertyClasses/MacroStabilityInwardsCalculationsProperties.cs (.../MacroStabilityInwardsCalculationsProperties.cs) (revision 1f16a57392fb30cd9e33fdc63f701a483b40316b) @@ -20,12 +20,9 @@ // All rights reserved. using System; -using Core.Common.Base.Data; using Core.Common.Util.Attributes; using Core.Gui.Attributes; -using Core.Gui.PropertyBag; using Riskeer.Common.Data.AssessmentSection; -using Riskeer.Common.Data.Probability; using Riskeer.MacroStabilityInwards.Data; using Riskeer.MacroStabilityInwards.Forms.Properties; using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; @@ -35,7 +32,7 @@ /// /// Calculation related ViewModel of for properties panel. /// - public class MacroStabilityInwardsCalculationsProperties : ObjectProperties + public class MacroStabilityInwardsCalculationsProperties : MacroStabilityInwardsFailureMechanismProperties { private const int namePropertyIndex = 1; private const int codePropertyIndex = 2; @@ -47,30 +44,27 @@ private const int bPropertyIndex = 8; private const int sectionLengthPropertyIndex = 9; private const int nPropertyIndex = 10; - private readonly IAssessmentSection assessmentSection; /// /// Creates a new instance of . /// /// The instance to show the properties of. /// The assessment section the data belongs to. /// Thrown when any parameter is null. - public MacroStabilityInwardsCalculationsProperties(MacroStabilityInwardsFailureMechanism data, IAssessmentSection assessmentSection) - { - if (data == null) + public MacroStabilityInwardsCalculationsProperties(MacroStabilityInwardsFailureMechanism data, + IAssessmentSection assessmentSection) : + base(data, new ConstructionProperties { - throw new ArgumentNullException(nameof(data)); - } + NamePropertyIndex = namePropertyIndex, + CodePropertyIndex = codePropertyIndex, + GroupPropertyIndex = groupPropertyIndex, + ContributionPropertyIndex = contributionPropertyIndex, + APropertyIndex = aPropertyIndex, + BPropertyIndex = bPropertyIndex, + SectionLengthPropertyIndex = sectionLengthPropertyIndex, + NPropertyIndex = nPropertyIndex + }, assessmentSection) {} - if (assessmentSection == null) - { - throw new ArgumentNullException(nameof(assessmentSection)); - } - - Data = data; - this.assessmentSection = assessmentSection; - } - #region Model settings [PropertyOrder(modelFactorPropertyIndex)] @@ -89,54 +83,6 @@ #region General - [PropertyOrder(namePropertyIndex)] - [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_General))] - [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_Name_DisplayName))] - [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_Name_Description))] - public string Name - { - get - { - return data.Name; - } - } - - [PropertyOrder(codePropertyIndex)] - [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_General))] - [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_Code_DisplayName))] - [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_Code_Description))] - public string Code - { - get - { - return data.Code; - } - } - - [PropertyOrder(groupPropertyIndex)] - [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_General))] - [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_Group_DisplayName))] - [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_Group_Description))] - public int Group - { - get - { - return data.Group; - } - } - - [PropertyOrder(contributionPropertyIndex)] - [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_General))] - [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_Contribution_DisplayName))] - [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_Contribution_Description))] - public double Contribution - { - get - { - return data.Contribution; - } - } - [PropertyOrder(waterVolumetricWeightPropertyIndex)] [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_General))] [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.WaterVolumetricWeight_DisplayName))] @@ -150,63 +96,5 @@ } #endregion - - #region Length effect parameters - - [PropertyOrder(aPropertyIndex)] - [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_LengthEffect))] - [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_ProbabilityAssessmentInput_A_DisplayName))] - [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_ProbabilityAssessmentInput_A_Description))] - public double A - { - get - { - return data.MacroStabilityInwardsProbabilityAssessmentInput.A; - } - set - { - data.MacroStabilityInwardsProbabilityAssessmentInput.A = value; - data.NotifyObservers(); - } - } - - [PropertyOrder(bPropertyIndex)] - [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_LengthEffect))] - [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_ProbabilityAssessmentInput_B_DisplayName))] - [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_ProbabilityAssessmentInput_B_Description))] - public double B - { - get - { - return data.MacroStabilityInwardsProbabilityAssessmentInput.B; - } - } - - [PropertyOrder(sectionLengthPropertyIndex)] - [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_LengthEffect))] - [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.ReferenceLine_Length_Rounded_DisplayName))] - [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.ReferenceLine_Length_Rounded_Description))] - public RoundedDouble SectionLength - { - get - { - return new RoundedDouble(2, assessmentSection.ReferenceLine.Length); - } - } - - [PropertyOrder(nPropertyIndex)] - [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_LengthEffect))] - [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_N_Rounded_DisplayName))] - [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_N_Rounded_Description))] - public RoundedDouble N - { - get - { - MacroStabilityInwardsProbabilityAssessmentInput probabilityAssessmentInput = data.MacroStabilityInwardsProbabilityAssessmentInput; - return new RoundedDouble(2, probabilityAssessmentInput.GetN(assessmentSection.ReferenceLine.Length)); - } - } - - #endregion } } \ No newline at end of file Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/PropertyClasses/MacroStabilityInwardsFailureMechanismProperties.cs =================================================================== diff -u -r0c7abe3958167c723c5013de52c45f6a10294227 -r1f16a57392fb30cd9e33fdc63f701a483b40316b --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/PropertyClasses/MacroStabilityInwardsFailureMechanismProperties.cs (.../MacroStabilityInwardsFailureMechanismProperties.cs) (revision 0c7abe3958167c723c5013de52c45f6a10294227) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/PropertyClasses/MacroStabilityInwardsFailureMechanismProperties.cs (.../MacroStabilityInwardsFailureMechanismProperties.cs) (revision 1f16a57392fb30cd9e33fdc63f701a483b40316b) @@ -20,14 +20,14 @@ // All rights reserved. using System; +using System.Collections.Generic; using Core.Common.Base.Data; using Core.Common.Util.Attributes; using Core.Gui.Attributes; using Core.Gui.PropertyBag; using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Data.Probability; using Riskeer.MacroStabilityInwards.Data; -using Riskeer.MacroStabilityInwards.Forms.Properties; using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; namespace Riskeer.MacroStabilityInwards.Forms.PropertyClasses @@ -37,78 +37,136 @@ /// public class MacroStabilityInwardsFailureMechanismProperties : ObjectProperties { - private const int namePropertyIndex = 1; - private const int codePropertyIndex = 2; - private const int groupPropertyIndex = 3; - private const int contributionPropertyIndex = 4; - private const int isRelevantPropertyIndex = 5; - private const int waterVolumetricWeightPropertyIndex = 6; - private const int modelFactorPropertyIndex = 7; - private const int aPropertyIndex = 8; - private const int bPropertyIndex = 9; - private const int sectionLengthPropertyIndex = 10; - private const int nPropertyIndex = 11; - private readonly IAssessmentSection assessmentSection; + private readonly Dictionary propertyIndexLookup; /// /// Creates a new instance of . /// /// The instance to show the properties of. + /// The property values required to create an instance of . /// The assessment section the data belongs to. /// Thrown when any parameter is null. - public MacroStabilityInwardsFailureMechanismProperties(MacroStabilityInwardsFailureMechanism data, IAssessmentSection assessmentSection) + public MacroStabilityInwardsFailureMechanismProperties(MacroStabilityInwardsFailureMechanism data, + ConstructionProperties constructionProperties, + IAssessmentSection assessmentSection) { if (data == null) { throw new ArgumentNullException(nameof(data)); } + if (constructionProperties == null) + { + throw new ArgumentNullException(nameof(constructionProperties)); + } + if (assessmentSection == null) { throw new ArgumentNullException(nameof(assessmentSection)); } Data = data; - this.assessmentSection = assessmentSection; - } + AssessmentSection = assessmentSection; - #region Model settings - - [DynamicVisible] - [PropertyOrder(modelFactorPropertyIndex)] - [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_ModelSettings))] - [ResourcesDisplayName(typeof(Resources), nameof(Resources.MacroStabilityInwardsFailureMechanismProperties_ModelFactor_DisplayName))] - [ResourcesDescription(typeof(Resources), nameof(Resources.MacroStabilityInwardsFailureMechanismProperties_ModelFactor_Description))] - public double ModelFactor - { - get + propertyIndexLookup = new Dictionary { - return data.GeneralInput.ModelFactor; - } + { + nameof(Name), constructionProperties.NamePropertyIndex + }, + { + nameof(Code), constructionProperties.CodePropertyIndex + }, + { + nameof(Group), constructionProperties.GroupPropertyIndex + }, + { + nameof(Contribution), constructionProperties.ContributionPropertyIndex + }, + { + nameof(A), constructionProperties.APropertyIndex + }, + { + nameof(B), constructionProperties.BPropertyIndex + }, + { + nameof(SectionLength), constructionProperties.SectionLengthPropertyIndex + }, + { + nameof(N), constructionProperties.NPropertyIndex + } + }; } - #endregion - - [DynamicVisibleValidationMethod] - public bool DynamicVisibleValidationMethod(string propertyName) + [DynamicPropertyOrderEvaluationMethod] + public int DynamicPropertyOrderEvaluationMethod(string propertyName) { - return data.IsRelevant || !ShouldHidePropertyWhenFailureMechanismIrrelevant(propertyName); + propertyIndexLookup.TryGetValue(propertyName, out int propertyIndex); + + return propertyIndex; } - private bool ShouldHidePropertyWhenFailureMechanismIrrelevant(string propertyName) + /// + /// Gets the . + /// + protected IAssessmentSection AssessmentSection { get; } + + /// + /// Class holding the various construction parameters for . + /// + public class ConstructionProperties { - return nameof(Contribution).Equals(propertyName) - || nameof(A).Equals(propertyName) - || nameof(B).Equals(propertyName) - || nameof(SectionLength).Equals(propertyName) - || nameof(N).Equals(propertyName) - || nameof(ModelFactor).Equals(propertyName) - || nameof(WaterVolumetricWeight).Equals(propertyName); + #region General + + /// + /// Gets or sets the property index for . + /// + public int NamePropertyIndex { get; set; } + + /// + /// Gets or sets the property index for . + /// + public int CodePropertyIndex { get; set; } + + /// + /// Gets or sets the property index for . + /// + public int GroupPropertyIndex { get; set; } + + /// + /// Gets or sets the property index for . + /// + public int ContributionPropertyIndex { get; set; } + + #endregion + + #region Length effect parameters + + /// + /// Gets or sets the property index for . + /// + public int APropertyIndex { get; set; } + + /// + /// Gets or sets the property index for . + /// + public int BPropertyIndex { get; set; } + + /// + /// Gets or sets the property index for . + /// + public int SectionLengthPropertyIndex { get; set; } + + /// + /// Gets or sets the property index for . + /// + public int NPropertyIndex { get; set; } + + #endregion } #region General - [PropertyOrder(namePropertyIndex)] + [DynamicPropertyOrder] [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_General))] [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_Name_DisplayName))] [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_Name_Description))] @@ -120,7 +178,7 @@ } } - [PropertyOrder(codePropertyIndex)] + [DynamicPropertyOrder] [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_General))] [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_Code_DisplayName))] [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_Code_Description))] @@ -132,7 +190,7 @@ } } - [PropertyOrder(groupPropertyIndex)] + [DynamicPropertyOrder] [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_General))] [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_Group_DisplayName))] [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_Group_Description))] @@ -144,54 +202,27 @@ } } - [DynamicVisible] - [PropertyOrder(contributionPropertyIndex)] + [DynamicPropertyOrder] [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_General))] [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_Contribution_DisplayName))] [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_Contribution_Description))] - public double Contribution + public virtual double Contribution { get { return data.Contribution; } } - [PropertyOrder(isRelevantPropertyIndex)] - [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_General))] - [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_IsRelevant_DisplayName))] - [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_IsRelevant_Description))] - public bool IsRelevant - { - get - { - return data.IsRelevant; - } - } - - [DynamicVisible] - [PropertyOrder(waterVolumetricWeightPropertyIndex)] - [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_General))] - [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.WaterVolumetricWeight_DisplayName))] - [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.WaterVolumetricWeight_Description))] - public double WaterVolumetricWeight - { - get - { - return data.GeneralInput.WaterVolumetricWeight; - } - } - #endregion #region Length effect parameters - [DynamicVisible] - [PropertyOrder(aPropertyIndex)] + [DynamicPropertyOrder] [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_LengthEffect))] [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_ProbabilityAssessmentInput_A_DisplayName))] [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_ProbabilityAssessmentInput_A_Description))] - public double A + public virtual double A { get { @@ -204,43 +235,40 @@ } } - [DynamicVisible] - [PropertyOrder(bPropertyIndex)] + [DynamicPropertyOrder] [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_LengthEffect))] [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_ProbabilityAssessmentInput_B_DisplayName))] [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_ProbabilityAssessmentInput_B_Description))] - public double B + public virtual double B { get { return data.MacroStabilityInwardsProbabilityAssessmentInput.B; } } - [DynamicVisible] - [PropertyOrder(sectionLengthPropertyIndex)] + [DynamicPropertyOrder] [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_LengthEffect))] [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.ReferenceLine_Length_Rounded_DisplayName))] [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.ReferenceLine_Length_Rounded_Description))] - public RoundedDouble SectionLength + public virtual RoundedDouble SectionLength { get { - return new RoundedDouble(2, assessmentSection.ReferenceLine.Length); + return new RoundedDouble(2, AssessmentSection.ReferenceLine.Length); } } - [DynamicVisible] - [PropertyOrder(nPropertyIndex)] + [DynamicPropertyOrder] [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_LengthEffect))] [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_N_Rounded_DisplayName))] [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_N_Rounded_Description))] - public RoundedDouble N + public virtual RoundedDouble N { get { MacroStabilityInwardsProbabilityAssessmentInput probabilityAssessmentInput = data.MacroStabilityInwardsProbabilityAssessmentInput; - return new RoundedDouble(2, probabilityAssessmentInput.GetN(assessmentSection.ReferenceLine.Length)); + return new RoundedDouble(2, probabilityAssessmentInput.GetN(AssessmentSection.ReferenceLine.Length)); } } Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/PropertyClasses/MacroStabilityInwardsFailurePathProperties.cs =================================================================== diff -u -r0c7abe3958167c723c5013de52c45f6a10294227 -r1f16a57392fb30cd9e33fdc63f701a483b40316b --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/PropertyClasses/MacroStabilityInwardsFailurePathProperties.cs (.../MacroStabilityInwardsFailurePathProperties.cs) (revision 0c7abe3958167c723c5013de52c45f6a10294227) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/PropertyClasses/MacroStabilityInwardsFailurePathProperties.cs (.../MacroStabilityInwardsFailurePathProperties.cs) (revision 1f16a57392fb30cd9e33fdc63f701a483b40316b) @@ -1,7 +1,174 @@ -namespace Riskeer.MacroStabilityInwards.Forms.PropertyClasses +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using Core.Common.Base.Data; +using Core.Common.Util.Attributes; +using Core.Gui.Attributes; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.Probability; +using Riskeer.MacroStabilityInwards.Data; +using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; + +namespace Riskeer.MacroStabilityInwards.Forms.PropertyClasses { - public class MacroStabilityInwardsFailurePathProperties + /// + /// Failure path related ViewModel of properties panel. + /// + public class MacroStabilityInwardsFailurePathProperties : MacroStabilityInwardsFailureMechanismProperties { - + private const int namePropertyIndex = 1; + private const int codePropertyIndex = 2; + private const int groupPropertyIndex = 3; + private const int contributionPropertyIndex = 4; + private const int isRelevantPropertyIndex = 5; + private const int aPropertyIndex = 6; + private const int bPropertyIndex = 7; + private const int sectionLengthPropertyIndex = 8; + private const int nPropertyIndex = 9; + + /// + /// Creates a new instance of . + /// + /// The instance to show the properties of. + /// The assessment section the data belongs to. + /// Thrown when any parameter is null. + public MacroStabilityInwardsFailurePathProperties(MacroStabilityInwardsFailureMechanism data, + IAssessmentSection assessmentSection) : + base(data, new ConstructionProperties + { + NamePropertyIndex = namePropertyIndex, + CodePropertyIndex = codePropertyIndex, + GroupPropertyIndex = groupPropertyIndex, + ContributionPropertyIndex = contributionPropertyIndex, + APropertyIndex = aPropertyIndex, + BPropertyIndex = bPropertyIndex, + SectionLengthPropertyIndex = sectionLengthPropertyIndex, + NPropertyIndex = nPropertyIndex + }, assessmentSection) {} + + [DynamicVisibleValidationMethod] + public bool DynamicVisibleValidationMethod(string propertyName) + { + return data.IsRelevant || !ShouldHidePropertyWhenFailureMechanismIrrelevant(propertyName); + } + + private bool ShouldHidePropertyWhenFailureMechanismIrrelevant(string propertyName) + { + return nameof(Contribution).Equals(propertyName) + || nameof(A).Equals(propertyName) + || nameof(B).Equals(propertyName) + || nameof(SectionLength).Equals(propertyName) + || nameof(N).Equals(propertyName); + } + + #region General + + [DynamicVisible] + [PropertyOrder(contributionPropertyIndex)] + [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_General))] + [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_Contribution_DisplayName))] + [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_Contribution_Description))] + public override double Contribution + { + get + { + return data.Contribution; + } + } + + [PropertyOrder(isRelevantPropertyIndex)] + [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_General))] + [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_IsRelevant_DisplayName))] + [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_IsRelevant_Description))] + public bool IsRelevant + { + get + { + return data.IsRelevant; + } + } + + #endregion + + #region Length effect parameters + + [DynamicVisible] + [PropertyOrder(aPropertyIndex)] + [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_LengthEffect))] + [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_ProbabilityAssessmentInput_A_DisplayName))] + [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_ProbabilityAssessmentInput_A_Description))] + public override double A + { + get + { + return data.MacroStabilityInwardsProbabilityAssessmentInput.A; + } + set + { + data.MacroStabilityInwardsProbabilityAssessmentInput.A = value; + data.NotifyObservers(); + } + } + + [DynamicVisible] + [PropertyOrder(bPropertyIndex)] + [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_LengthEffect))] + [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_ProbabilityAssessmentInput_B_DisplayName))] + [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_ProbabilityAssessmentInput_B_Description))] + public override double B + { + get + { + return data.MacroStabilityInwardsProbabilityAssessmentInput.B; + } + } + + [DynamicVisible] + [PropertyOrder(sectionLengthPropertyIndex)] + [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_LengthEffect))] + [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.ReferenceLine_Length_Rounded_DisplayName))] + [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.ReferenceLine_Length_Rounded_Description))] + public override RoundedDouble SectionLength + { + get + { + return new RoundedDouble(2, AssessmentSection.ReferenceLine.Length); + } + } + + [DynamicVisible] + [PropertyOrder(nPropertyIndex)] + [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_LengthEffect))] + [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_N_Rounded_DisplayName))] + [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_N_Rounded_Description))] + public override RoundedDouble N + { + get + { + MacroStabilityInwardsProbabilityAssessmentInput probabilityAssessmentInput = data.MacroStabilityInwardsProbabilityAssessmentInput; + return new RoundedDouble(2, probabilityAssessmentInput.GetN(AssessmentSection.ReferenceLine.Length)); + } + } + + #endregion } } \ No newline at end of file Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Forms.Test/PropertyClasses/MacroStabilityInwardsCalculationsPropertiesTest.cs =================================================================== diff -u -rfbd1360d7ee58f83c97bd7ef829e16a493f3748c -r1f16a57392fb30cd9e33fdc63f701a483b40316b --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Forms.Test/PropertyClasses/MacroStabilityInwardsCalculationsPropertiesTest.cs (.../MacroStabilityInwardsCalculationsPropertiesTest.cs) (revision fbd1360d7ee58f83c97bd7ef829e16a493f3748c) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Forms.Test/PropertyClasses/MacroStabilityInwardsCalculationsPropertiesTest.cs (.../MacroStabilityInwardsCalculationsPropertiesTest.cs) (revision 1f16a57392fb30cd9e33fdc63f701a483b40316b) @@ -23,7 +23,6 @@ using System.ComponentModel; using Core.Common.Base; using Core.Common.TestUtil; -using Core.Gui.PropertyBag; using Core.Gui.TestUtil; using NUnit.Framework; using Rhino.Mocks; @@ -50,34 +49,6 @@ private const int nPropertyIndex = 9; [Test] - public void Constructor_DataNull_ThrowArgumentNullException() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - // Call - void Call() => new MacroStabilityInwardsCalculationsProperties(null, assessmentSection); - - // Assert - string paramName = Assert.Throws(Call).ParamName; - Assert.AreEqual("data", paramName); - mocks.VerifyAll(); - } - - [Test] - public void Constructor_AssessmentSectionNull_ThrowArgumentNullException() - { - // Call - void Call() => new MacroStabilityInwardsCalculationsProperties(new MacroStabilityInwardsFailureMechanism(), null); - - // Assert - var exception = Assert.Throws(Call); - Assert.AreEqual("assessmentSection", exception.ParamName); - } - - [Test] public void Constructor_ExpectedValues() { // Setup @@ -92,12 +63,16 @@ var properties = new MacroStabilityInwardsCalculationsProperties(failureMechanism, assessmentSection); // Assert - Assert.IsInstanceOf>(properties); + Assert.IsInstanceOf(properties); Assert.AreEqual(failureMechanism.Name, properties.Name); Assert.AreEqual(failureMechanism.Code, properties.Code); Assert.AreEqual(failureMechanism.Group, properties.Group); Assert.AreEqual(failureMechanism.Contribution, properties.Contribution); + GeneralMacroStabilityInwardsInput generalInput = failureMechanism.GeneralInput; + + Assert.AreEqual(generalInput.WaterVolumetricWeight, properties.WaterVolumetricWeight); + MacroStabilityInwardsProbabilityAssessmentInput probabilityAssessmentInput = failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput; Assert.AreEqual(probabilityAssessmentInput.A, properties.A); Assert.AreEqual(probabilityAssessmentInput.B, properties.B); @@ -109,8 +84,7 @@ Assert.AreEqual(assessmentSection.ReferenceLine.Length, properties.SectionLength, properties.SectionLength.GetAccuracy()); - Assert.AreEqual(failureMechanism.GeneralInput.ModelFactor, properties.ModelFactor); - Assert.AreEqual(failureMechanism.GeneralInput.WaterVolumetricWeight, properties.WaterVolumetricWeight); + mocks.VerifyAll(); } @@ -132,8 +106,8 @@ Assert.AreEqual(10, dynamicProperties.Count); const string generalCategory = "Algemeen"; + const string modelFactorCategory = "Modelinstellingen"; const string lengthEffectCategory = "Lengte-effect parameters"; - const string modelSettingsCategory = "Modelinstellingen"; PropertyDescriptor nameProperty = dynamicProperties[namePropertyIndex]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(nameProperty, @@ -163,16 +137,16 @@ "Procentuele bijdrage van dit toetsspoor aan de totale overstromingskans van het traject.", true); - PropertyDescriptor waterVolumetricWeightProperty = dynamicProperties[waterVolumetricWeightPropertyIndex]; - PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(waterVolumetricWeightProperty, + PropertyDescriptor volumicWeightOfWaterProperty = dynamicProperties[waterVolumetricWeightPropertyIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(volumicWeightOfWaterProperty, generalCategory, "Volumiek gewicht van water [kN/m³]", "Volumiek gewicht van water.", true); PropertyDescriptor modelFactorProperty = dynamicProperties[modelFactorPropertyIndex]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(modelFactorProperty, - modelSettingsCategory, + modelFactorCategory, "Modelfactor [-]", "Modelfactor die wordt gebruikt bij de berekening van de benaderde faalkans op basis van de berekende stabiliteitsfactor.", true); @@ -203,6 +177,7 @@ "N* [-]", "De parameter 'N' die gebruikt wordt om het lengte-effect mee te nemen in de beoordeling (afgerond).", true); + mocks.VerifyAll(); } @@ -231,6 +206,7 @@ // Assert const string expectedMessage = "De waarde voor 'a' moet in het bereik [0,0, 1,0] liggen."; TestHelper.AssertThrowsArgumentExceptionAndTestMessage(Call, expectedMessage); + mocks.VerifyAll(); } @@ -259,6 +235,7 @@ // Assert Assert.AreEqual(value, failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput.A); + mocks.VerifyAll(); } } Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Forms.Test/PropertyClasses/MacroStabilityInwardsFailureMechanismPropertiesTest.cs =================================================================== diff -u -r0c7abe3958167c723c5013de52c45f6a10294227 -r1f16a57392fb30cd9e33fdc63f701a483b40316b --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Forms.Test/PropertyClasses/MacroStabilityInwardsFailureMechanismPropertiesTest.cs (.../MacroStabilityInwardsFailureMechanismPropertiesTest.cs) (revision 0c7abe3958167c723c5013de52c45f6a10294227) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Forms.Test/PropertyClasses/MacroStabilityInwardsFailureMechanismPropertiesTest.cs (.../MacroStabilityInwardsFailureMechanismPropertiesTest.cs) (revision 1f16a57392fb30cd9e33fdc63f701a483b40316b) @@ -38,17 +38,14 @@ [TestFixture] public class MacroStabilityInwardsFailureMechanismPropertiesTest { - private const int namePropertyIndex = 0; - private const int codePropertyIndex = 1; - private const int groupPropertyIndex = 2; - private const int contributionPropertyIndex = 3; - private const int isRelevantPropertyIndex = 4; - private const int waterVolumetricWeightPropertyIndex = 5; - private const int modelFactorPropertyIndex = 6; - private const int aPropertyIndex = 7; - private const int bPropertyIndex = 8; - private const int sectionLengthPropertyIndex = 9; - private const int nPropertyIndex = 10; + private const int namePropertyIndex = 7; + private const int codePropertyIndex = 6; + private const int groupPropertyIndex = 5; + private const int contributionPropertyIndex = 4; + private const int aPropertyIndex = 3; + private const int bPropertyIndex = 2; + private const int sectionLengthPropertyIndex = 1; + private const int nPropertyIndex = 0; [Test] public void Constructor_DataNull_ThrowArgumentNullException() @@ -59,51 +56,64 @@ mocks.ReplayAll(); // Call - void Call() => new MacroStabilityInwardsFailureMechanismProperties(null, assessmentSection); + void Call() => new MacroStabilityInwardsFailureMechanismProperties(null, new MacroStabilityInwardsFailureMechanismProperties.ConstructionProperties(), assessmentSection); // Assert - string paramName = Assert.Throws(Call).ParamName; - Assert.AreEqual("data", paramName); + var exception = Assert.Throws(Call); + Assert.AreEqual("data", exception.ParamName); + mocks.VerifyAll(); } [Test] - public void Constructor_AssessmentSectionNull_ThrowArgumentNullException() + public void Constructor_ConstructionPropertiesNull_ThrowsArgumentNullException() { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + // Call - void Call() => new MacroStabilityInwardsFailureMechanismProperties(new MacroStabilityInwardsFailureMechanism(), null); + void Call() => new MacroStabilityInwardsFailureMechanismProperties(new MacroStabilityInwardsFailureMechanism(), null, assessmentSection); // Assert var exception = Assert.Throws(Call); + Assert.AreEqual("constructionProperties", exception.ParamName); + + mocks.VerifyAll(); + } + + [Test] + public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + void Call() => new MacroStabilityInwardsFailureMechanismProperties(new MacroStabilityInwardsFailureMechanism(), new MacroStabilityInwardsFailureMechanismProperties.ConstructionProperties(), null); + + // Assert + var exception = Assert.Throws(Call); Assert.AreEqual("assessmentSection", exception.ParamName); } [Test] - [TestCase(true)] - [TestCase(false)] - public void Constructor_ExpectedValues(bool isRelevant) + public void Constructor_ExpectedValues() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); assessmentSection.Stub(a => a.ReferenceLine).Return(new ReferenceLine()); mocks.ReplayAll(); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); - var failureMechanism = new MacroStabilityInwardsFailureMechanism - { - IsRelevant = isRelevant - }; - // Call - var properties = new MacroStabilityInwardsFailureMechanismProperties(failureMechanism, assessmentSection); + var properties = new MacroStabilityInwardsFailureMechanismProperties(failureMechanism, new MacroStabilityInwardsFailureMechanismProperties.ConstructionProperties(), assessmentSection); // Assert Assert.IsInstanceOf>(properties); Assert.AreEqual(failureMechanism.Name, properties.Name); Assert.AreEqual(failureMechanism.Code, properties.Code); Assert.AreEqual(failureMechanism.Group, properties.Group); Assert.AreEqual(failureMechanism.Contribution, properties.Contribution); - Assert.AreEqual(isRelevant, properties.IsRelevant); MacroStabilityInwardsProbabilityAssessmentInput probabilityAssessmentInput = failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput; Assert.AreEqual(probabilityAssessmentInput.A, properties.A); @@ -116,34 +126,40 @@ Assert.AreEqual(assessmentSection.ReferenceLine.Length, properties.SectionLength, properties.SectionLength.GetAccuracy()); - Assert.AreEqual(failureMechanism.GeneralInput.ModelFactor, properties.ModelFactor); - Assert.AreEqual(failureMechanism.GeneralInput.WaterVolumetricWeight, properties.WaterVolumetricWeight); + mocks.VerifyAll(); } [Test] - public void Constructor_IsRelevantTrue_PropertiesHaveExpectedAttributesValues() + public void Constructor_Always_PropertiesHaveExpectedAttributeValues() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.ReferenceLine).Return(new ReferenceLine()); mocks.ReplayAll(); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); - var failureMechanism = new MacroStabilityInwardsFailureMechanism + // Call + var properties = new MacroStabilityInwardsFailureMechanismProperties(failureMechanism, new MacroStabilityInwardsFailureMechanismProperties.ConstructionProperties { - IsRelevant = true - }; + NamePropertyIndex = namePropertyIndex, + CodePropertyIndex = codePropertyIndex, + GroupPropertyIndex = groupPropertyIndex, + ContributionPropertyIndex = contributionPropertyIndex, + APropertyIndex = aPropertyIndex, + BPropertyIndex = bPropertyIndex, + SectionLengthPropertyIndex = sectionLengthPropertyIndex, + NPropertyIndex = nPropertyIndex + }, assessmentSection); - // Call - var properties = new MacroStabilityInwardsFailureMechanismProperties(failureMechanism, assessmentSection); - // Assert PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); - Assert.AreEqual(11, dynamicProperties.Count); + Assert.AreEqual(8, dynamicProperties.Count); const string generalCategory = "Algemeen"; const string lengthEffectCategory = "Lengte-effect parameters"; - const string modelSettingsCategory = "Modelinstellingen"; PropertyDescriptor nameProperty = dynamicProperties[namePropertyIndex]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(nameProperty, @@ -173,27 +189,6 @@ "Procentuele bijdrage van dit toetsspoor aan de totale overstromingskans van het traject.", true); - PropertyDescriptor isRelevantProperty = dynamicProperties[isRelevantPropertyIndex]; - PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(isRelevantProperty, - generalCategory, - "Is relevant", - "Geeft aan of dit toetsspoor relevant is of niet.", - true); - - PropertyDescriptor waterVolumetricWeightProperty = dynamicProperties[waterVolumetricWeightPropertyIndex]; - PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(waterVolumetricWeightProperty, - generalCategory, - "Volumiek gewicht van water [kN/m³]", - "Volumiek gewicht van water.", - true); - - PropertyDescriptor modelFactorProperty = dynamicProperties[modelFactorPropertyIndex]; - PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(modelFactorProperty, - modelSettingsCategory, - "Modelfactor [-]", - "Modelfactor die wordt gebruikt bij de berekening van de benaderde faalkans op basis van de berekende stabiliteitsfactor.", - true); - PropertyDescriptor aProperty = dynamicProperties[aPropertyIndex]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(aProperty, lengthEffectCategory, @@ -220,58 +215,7 @@ "N* [-]", "De parameter 'N' die gebruikt wordt om het lengte-effect mee te nemen in de beoordeling (afgerond).", true); - mocks.VerifyAll(); - } - [Test] - public void Constructor_IsRelevantFalse_PropertiesHaveExpectedAttributesValues() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var failureMechanism = new MacroStabilityInwardsFailureMechanism - { - IsRelevant = false - }; - - // Call - var properties = new MacroStabilityInwardsFailureMechanismProperties(failureMechanism, assessmentSection); - - // Assert - PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); - Assert.AreEqual(4, dynamicProperties.Count); - - const string generalCategory = "Algemeen"; - - PropertyDescriptor nameProperty = dynamicProperties[namePropertyIndex]; - PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(nameProperty, - generalCategory, - "Naam", - "De naam van het toetsspoor.", - true); - - PropertyDescriptor labelProperty = dynamicProperties[codePropertyIndex]; - PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(labelProperty, - generalCategory, - "Label", - "Het label van het toetsspoor.", - true); - - PropertyDescriptor groupProperty = dynamicProperties[groupPropertyIndex]; - PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(groupProperty, - generalCategory, - "Groep", - "De groep waar het toetsspoor toe behoort.", - true); - - PropertyDescriptor isRelevantProperty = dynamicProperties[isRelevantPropertyIndex - 1]; - PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(isRelevantProperty, - generalCategory, - "Is relevant", - "Geeft aan of dit toetsspoor relevant is of niet.", - true); mocks.VerifyAll(); } @@ -292,14 +236,15 @@ var failureMechanism = new MacroStabilityInwardsFailureMechanism(); failureMechanism.Attach(observer); - var properties = new MacroStabilityInwardsFailureMechanismProperties(failureMechanism, assessmentSection); + var properties = new MacroStabilityInwardsFailureMechanismProperties(failureMechanism, new MacroStabilityInwardsFailureMechanismProperties.ConstructionProperties(), assessmentSection); // Call - TestDelegate call = () => properties.A = value; + void Call() => properties.A = value; // Assert const string expectedMessage = "De waarde voor 'a' moet in het bereik [0,0, 1,0] liggen."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(Call, expectedMessage); + mocks.VerifyAll(); } @@ -321,47 +266,14 @@ var failureMechanism = new MacroStabilityInwardsFailureMechanism(); failureMechanism.Attach(observer); - var properties = new MacroStabilityInwardsFailureMechanismProperties(failureMechanism, assessmentSection); + var properties = new MacroStabilityInwardsFailureMechanismProperties(failureMechanism, new MacroStabilityInwardsFailureMechanismProperties.ConstructionProperties(), assessmentSection); // Call properties.A = value; // Assert Assert.AreEqual(value, failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput.A); - mocks.VerifyAll(); - } - [Test] - [TestCase(true)] - [TestCase(false)] - public void DynamicVisibleValidationMethod_DependingOnRelevancy_ReturnExpectedVisibility(bool isRelevant) - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var failureMechanism = new MacroStabilityInwardsFailureMechanism - { - IsRelevant = isRelevant - }; - var properties = new MacroStabilityInwardsFailureMechanismProperties(failureMechanism, assessmentSection); - - // Call & Assert - Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.Name))); - Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.Code))); - Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.Group))); - Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.IsRelevant))); - - Assert.AreEqual(isRelevant, properties.DynamicVisibleValidationMethod(nameof(properties.Contribution))); - Assert.AreEqual(isRelevant, properties.DynamicVisibleValidationMethod(nameof(properties.A))); - Assert.AreEqual(isRelevant, properties.DynamicVisibleValidationMethod(nameof(properties.B))); - Assert.AreEqual(isRelevant, properties.DynamicVisibleValidationMethod(nameof(properties.SectionLength))); - Assert.AreEqual(isRelevant, properties.DynamicVisibleValidationMethod(nameof(properties.N))); - Assert.AreEqual(isRelevant, properties.DynamicVisibleValidationMethod(nameof(properties.ModelFactor))); - Assert.AreEqual(isRelevant, properties.DynamicVisibleValidationMethod(nameof(properties.WaterVolumetricWeight))); - - Assert.IsTrue(properties.DynamicVisibleValidationMethod(null)); mocks.VerifyAll(); } } Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Forms.Test/PropertyClasses/MacroStabilityInwardsFailurePathPropertiesTest.cs =================================================================== diff -u -r0c7abe3958167c723c5013de52c45f6a10294227 -r1f16a57392fb30cd9e33fdc63f701a483b40316b --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Forms.Test/PropertyClasses/MacroStabilityInwardsFailurePathPropertiesTest.cs (.../MacroStabilityInwardsFailurePathPropertiesTest.cs) (revision 0c7abe3958167c723c5013de52c45f6a10294227) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Forms.Test/PropertyClasses/MacroStabilityInwardsFailurePathPropertiesTest.cs (.../MacroStabilityInwardsFailurePathPropertiesTest.cs) (revision 1f16a57392fb30cd9e33fdc63f701a483b40316b) @@ -1,7 +1,320 @@ -namespace Riskeer.MacroStabilityInwards.Forms.Test.PropertyClasses +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.ComponentModel; +using Core.Common.Base; +using Core.Common.TestUtil; +using Core.Gui.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.Probability; +using Riskeer.Common.Data.TestUtil; +using Riskeer.MacroStabilityInwards.Data; +using Riskeer.MacroStabilityInwards.Forms.PropertyClasses; + +namespace Riskeer.MacroStabilityInwards.Forms.Test.PropertyClasses { public class MacroStabilityInwardsFailurePathPropertiesTest { - + private const int namePropertyIndex = 0; + private const int codePropertyIndex = 1; + private const int groupPropertyIndex = 2; + private const int contributionPropertyIndex = 3; + private const int isRelevantPropertyIndex = 4; + private const int aPropertyIndex = 5; + private const int bPropertyIndex = 6; + private const int sectionLengthPropertyIndex = 7; + private const int nPropertyIndex = 8; + private MockRepository mocks; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + } + + [TearDown] + public void TearDown() + { + mocks.VerifyAll(); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Constructor_ExpectedValues(bool isRelevant) + { + // Setup + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.ReferenceLine).Return(new ReferenceLine()); + mocks.ReplayAll(); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism + { + IsRelevant = isRelevant + }; + + // Call + var properties = new MacroStabilityInwardsFailurePathProperties(failureMechanism, assessmentSection); + + // Assert + Assert.IsInstanceOf(properties); + Assert.AreEqual(failureMechanism.Name, properties.Name); + Assert.AreEqual(failureMechanism.Code, properties.Code); + Assert.AreEqual(failureMechanism.Group, properties.Group); + Assert.AreEqual(failureMechanism.Contribution, properties.Contribution); + Assert.AreEqual(isRelevant, properties.IsRelevant); + + MacroStabilityInwardsProbabilityAssessmentInput probabilityAssessmentInput = failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput; + Assert.AreEqual(probabilityAssessmentInput.A, properties.A); + Assert.AreEqual(probabilityAssessmentInput.B, properties.B); + Assert.AreEqual(2, properties.N.NumberOfDecimalPlaces); + Assert.AreEqual(probabilityAssessmentInput.GetN(assessmentSection.ReferenceLine.Length), + properties.N, + properties.N.GetAccuracy()); + Assert.AreEqual(2, properties.SectionLength.NumberOfDecimalPlaces); + Assert.AreEqual(assessmentSection.ReferenceLine.Length, + properties.SectionLength, + properties.SectionLength.GetAccuracy()); + } + + [Test] + public void Constructor_IsRelevantTrue_PropertiesHaveExpectedAttributesValues() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism + { + IsRelevant = true + }; + + // Call + var properties = new MacroStabilityInwardsFailurePathProperties(failureMechanism, assessmentSection); + + // Assert + PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); + Assert.AreEqual(9, dynamicProperties.Count); + + const string generalCategory = "Algemeen"; + const string lengthEffectCategory = "Lengte-effect parameters"; + + PropertyDescriptor nameProperty = dynamicProperties[namePropertyIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(nameProperty, + generalCategory, + "Naam", + "De naam van het toetsspoor.", + true); + + PropertyDescriptor labelProperty = dynamicProperties[codePropertyIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(labelProperty, + generalCategory, + "Label", + "Het label van het toetsspoor.", + true); + + PropertyDescriptor groupProperty = dynamicProperties[groupPropertyIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(groupProperty, + generalCategory, + "Groep", + "De groep waar het toetsspoor toe behoort.", + true); + + PropertyDescriptor contributionProperty = dynamicProperties[contributionPropertyIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(contributionProperty, + generalCategory, + "Faalkansbijdrage [%]", + "Procentuele bijdrage van dit toetsspoor aan de totale overstromingskans van het traject.", + true); + + PropertyDescriptor isRelevantProperty = dynamicProperties[isRelevantPropertyIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(isRelevantProperty, + generalCategory, + "Is relevant", + "Geeft aan of dit toetsspoor relevant is of niet.", + true); + + PropertyDescriptor aProperty = dynamicProperties[aPropertyIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(aProperty, + lengthEffectCategory, + "a [-]", + "De parameter 'a' die gebruikt wordt voor het lengte-effect in berekening van de maximaal toelaatbare faalkans."); + + PropertyDescriptor bProperty = dynamicProperties[bPropertyIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(bProperty, + lengthEffectCategory, + "b [m]", + "De parameter 'b' die gebruikt wordt voor het lengte-effect in berekening van de maximaal toelaatbare faalkans.", + true); + + PropertyDescriptor sectionLengthProperty = dynamicProperties[sectionLengthPropertyIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(sectionLengthProperty, + lengthEffectCategory, + "Lengte* [m]", + "Totale lengte van het traject in meters (afgerond).", + true); + + PropertyDescriptor nProperty = dynamicProperties[nPropertyIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(nProperty, + lengthEffectCategory, + "N* [-]", + "De parameter 'N' die gebruikt wordt om het lengte-effect mee te nemen in de beoordeling (afgerond).", + true); + } + + [Test] + public void Constructor_IsRelevantFalse_PropertiesHaveExpectedAttributesValues() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism + { + IsRelevant = false + }; + + // Call + var properties = new MacroStabilityInwardsFailurePathProperties(failureMechanism, assessmentSection); + + // Assert + PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); + Assert.AreEqual(4, dynamicProperties.Count); + + const string generalCategory = "Algemeen"; + + PropertyDescriptor nameProperty = dynamicProperties[namePropertyIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(nameProperty, + generalCategory, + "Naam", + "De naam van het toetsspoor.", + true); + + PropertyDescriptor labelProperty = dynamicProperties[codePropertyIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(labelProperty, + generalCategory, + "Label", + "Het label van het toetsspoor.", + true); + + PropertyDescriptor groupProperty = dynamicProperties[groupPropertyIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(groupProperty, + generalCategory, + "Groep", + "De groep waar het toetsspoor toe behoort.", + true); + + PropertyDescriptor isRelevantProperty = dynamicProperties[isRelevantPropertyIndex - 1]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(isRelevantProperty, + generalCategory, + "Is relevant", + "Geeft aan of dit toetsspoor relevant is of niet.", + true); + } + + [Test] + [SetCulture("nl-NL")] + [TestCase(-1)] + [TestCase(-0.1)] + [TestCase(1.1)] + [TestCase(8)] + public void A_SetInvalidValue_ThrowsArgumentOutOfRangeExceptionNoNotifications(double value) + { + // Setup + var assessmentSection = mocks.Stub(); + var observer = mocks.StrictMock(); + mocks.ReplayAll(); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + failureMechanism.Attach(observer); + + var properties = new MacroStabilityInwardsFailurePathProperties(failureMechanism, assessmentSection); + + // Call + void Call() => properties.A = value; + + // Assert + const string expectedMessage = "De waarde voor 'a' moet in het bereik [0,0, 1,0] liggen."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(Call, expectedMessage); + } + + [Test] + [TestCase(0)] + [TestCase(0.1)] + [TestCase(1)] + [TestCase(0.0000001)] + [TestCase(0.9999999)] + public void A_SetValidValue_SetsValueAndUpdatesObservers(double value) + { + // Setup + var assessmentSection = mocks.Stub(); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + failureMechanism.Attach(observer); + + var properties = new MacroStabilityInwardsFailurePathProperties(failureMechanism, assessmentSection); + + // Call + properties.A = value; + + // Assert + Assert.AreEqual(value, failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput.A); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void DynamicVisibleValidationMethod_DependingOnRelevancy_ReturnExpectedVisibility(bool isRelevant) + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var pipingFailureMechanism = new MacroStabilityInwardsFailureMechanism + { + IsRelevant = isRelevant + }; + + var properties = new MacroStabilityInwardsFailurePathProperties(pipingFailureMechanism, assessmentSection); + + // Assert + Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.Name))); + Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.Code))); + Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.Group))); + Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.IsRelevant))); + + Assert.AreEqual(isRelevant, properties.DynamicVisibleValidationMethod(nameof(properties.Contribution))); + Assert.AreEqual(isRelevant, properties.DynamicVisibleValidationMethod(nameof(properties.A))); + Assert.AreEqual(isRelevant, properties.DynamicVisibleValidationMethod(nameof(properties.B))); + Assert.AreEqual(isRelevant, properties.DynamicVisibleValidationMethod(nameof(properties.SectionLength))); + Assert.AreEqual(isRelevant, properties.DynamicVisibleValidationMethod(nameof(properties.N))); + + Assert.IsTrue(properties.DynamicVisibleValidationMethod(null)); + } } -} \ No newline at end of file +} +