Index: Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Forms/PropertyClasses/StabilityPointStructuresFailurePathProperties.cs =================================================================== diff -u -r9b96fbd9683bc9fe1f4b96f149e090972bfa578c -r1e8c00e611b2a452fcc58dba28cd8f6c7f162471 --- Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Forms/PropertyClasses/StabilityPointStructuresFailurePathProperties.cs (.../StabilityPointStructuresFailurePathProperties.cs) (revision 9b96fbd9683bc9fe1f4b96f149e090972bfa578c) +++ Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Forms/PropertyClasses/StabilityPointStructuresFailurePathProperties.cs (.../StabilityPointStructuresFailurePathProperties.cs) (revision 1e8c00e611b2a452fcc58dba28cd8f6c7f162471) @@ -37,7 +37,8 @@ private const int codePropertyIndex = 2; private const int groupPropertyIndex = 3; private const int contributionPropertyIndex = 4; - private const int nPropertyIndex = 5; + private const int isRelevantPropertyIndex = 5; + private const int nPropertyIndex = 6; /// /// Creates a new instance of . @@ -51,8 +52,38 @@ GroupPropertyIndex = groupPropertyIndex }) {} + [DynamicVisibleValidationMethod] + public bool DynamicVisibleValidationMethod(string propertyName) + { + if (!data.IsRelevant && ShouldHidePropertyWhenFailureMechanismIrrelevant(propertyName)) + { + return false; + } + + return true; + } + + private bool ShouldHidePropertyWhenFailureMechanismIrrelevant(string propertyName) + { + return nameof(Contribution).Equals(propertyName) + || nameof(N).Equals(propertyName); + } + #region General + [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(contributionPropertyIndex)] [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_General))] [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_Contribution_DisplayName))] @@ -69,6 +100,7 @@ #region Length effect parameters + [DynamicVisible] [PropertyOrder(nPropertyIndex)] [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_LengthEffect))] [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_N_DisplayName))] Index: Riskeer/StabilityPointStructures/test/Riskeer.StabilityPointStructures.Forms.Test/PropertyClasses/StabilityPointStructuresFailurePathPropertiesTest.cs =================================================================== diff -u -r9b96fbd9683bc9fe1f4b96f149e090972bfa578c -r1e8c00e611b2a452fcc58dba28cd8f6c7f162471 --- Riskeer/StabilityPointStructures/test/Riskeer.StabilityPointStructures.Forms.Test/PropertyClasses/StabilityPointStructuresFailurePathPropertiesTest.cs (.../StabilityPointStructuresFailurePathPropertiesTest.cs) (revision 9b96fbd9683bc9fe1f4b96f149e090972bfa578c) +++ Riskeer/StabilityPointStructures/test/Riskeer.StabilityPointStructures.Forms.Test/PropertyClasses/StabilityPointStructuresFailurePathPropertiesTest.cs (.../StabilityPointStructuresFailurePathPropertiesTest.cs) (revision 1e8c00e611b2a452fcc58dba28cd8f6c7f162471) @@ -39,13 +39,18 @@ private const int codePropertyIndex = 1; private const int groupPropertyIndex = 2; private const int contributionPropertyIndex = 3; - private const int nPropertyIndex = 4; + private const int isRelevantPropertyIndex = 4; + private const int nPropertyIndex = 5; [Test] public void Constructor_ExpectedValues() { // Setup - var failureMechanism = new StabilityPointStructuresFailureMechanism(); + var random = new Random(21); + var failureMechanism = new StabilityPointStructuresFailureMechanism + { + IsRelevant = random.NextBoolean() + }; // Call var properties = new StabilityPointStructuresFailurePathProperties(failureMechanism); @@ -56,6 +61,7 @@ Assert.AreEqual(failureMechanism.Code, properties.Code); Assert.AreEqual(failureMechanism.Group, properties.Group); Assert.AreEqual(failureMechanism.Contribution, properties.Contribution); + Assert.AreEqual(failureMechanism.IsRelevant, properties.IsRelevant); GeneralStabilityPointStructuresInput generalInput = failureMechanism.GeneralInput; Assert.AreEqual(2, properties.N.NumberOfDecimalPlaces); @@ -65,7 +71,7 @@ } [Test] - public void Constructor_Always_PropertiesHaveExpectedAttributesValues() + public void Constructor_IsRelevantTrue_PropertiesHaveExpectedAttributesValues() { // Setup var failureMechanism = new StabilityPointStructuresFailureMechanism(); @@ -75,7 +81,7 @@ // Assert PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); - Assert.AreEqual(5, dynamicProperties.Count); + Assert.AreEqual(6, dynamicProperties.Count); const string generalCategory = "Algemeen"; const string lengthEffectCategory = "Lengte-effect parameters"; @@ -108,6 +114,13 @@ "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 nProperty = dynamicProperties[nPropertyIndex]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(nProperty, lengthEffectCategory, @@ -116,6 +129,53 @@ } [Test] + public void Constructor_IsRelevantFalse_PropertiesHaveExpectedAttributesValues() + { + // Setup + var failureMechanism = new StabilityPointStructuresFailureMechanism + { + IsRelevant = false + }; + + // Call + var properties = new StabilityPointStructuresFailurePathProperties(failureMechanism); + + // 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(0.0)] [TestCase(-1.0)] @@ -167,5 +227,29 @@ mocks.VerifyAll(); } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void DynamicVisibleValidationMethod_DependingOnRelevancy_ReturnExpectedVisibility(bool isRelevant) + { + // Setup + var failureMechanism = new StabilityPointStructuresFailureMechanism + { + IsRelevant = isRelevant + }; + var properties = new StabilityPointStructuresFailurePathProperties(failureMechanism); + + // 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.N))); + + Assert.IsTrue(properties.DynamicVisibleValidationMethod(null)); + } } } \ No newline at end of file