Index: Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Forms/PropertyClasses/GrassCoverErosionOutwardsFailurePathProperties.cs =================================================================== diff -u -r53721462b03e2de9b909eda6b07cc24a063ad525 -r48e2c1dc393b22970f96ab42d605f6d74ef638f8 --- Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Forms/PropertyClasses/GrassCoverErosionOutwardsFailurePathProperties.cs (.../GrassCoverErosionOutwardsFailurePathProperties.cs) (revision 53721462b03e2de9b909eda6b07cc24a063ad525) +++ Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Forms/PropertyClasses/GrassCoverErosionOutwardsFailurePathProperties.cs (.../GrassCoverErosionOutwardsFailurePathProperties.cs) (revision 48e2c1dc393b22970f96ab42d605f6d74ef638f8) @@ -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,9 +52,27 @@ CodePropertyIndex = codePropertyIndex, 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 + [DynamicVisible] [PropertyOrder(contributionPropertyIndex)] [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_General))] [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_Contribution_DisplayName))] @@ -65,11 +84,24 @@ 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(nPropertyIndex)] [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_LengthEffect))] [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_N_DisplayName))] Index: Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Forms.Test/PropertyClasses/GrassCoverErosionOutwardsFailurePathPropertiesTest.cs =================================================================== diff -u -re727a4e22432d443b1bd2d24667e1e8c9746d73c -r48e2c1dc393b22970f96ab42d605f6d74ef638f8 --- Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Forms.Test/PropertyClasses/GrassCoverErosionOutwardsFailurePathPropertiesTest.cs (.../GrassCoverErosionOutwardsFailurePathPropertiesTest.cs) (revision e727a4e22432d443b1bd2d24667e1e8c9746d73c) +++ Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Forms.Test/PropertyClasses/GrassCoverErosionOutwardsFailurePathPropertiesTest.cs (.../GrassCoverErosionOutwardsFailurePathPropertiesTest.cs) (revision 48e2c1dc393b22970f96ab42d605f6d74ef638f8) @@ -40,13 +40,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 GrassCoverErosionOutwardsFailureMechanism(); + var random = new Random(21); + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism + { + IsRelevant = random.NextBoolean() + }; // Call var properties = new GrassCoverErosionOutwardsFailurePathProperties(failureMechanism); @@ -57,6 +62,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); GeneralGrassCoverErosionOutwardsInput generalInput = failureMechanism.GeneralInput; Assert.AreEqual(2, properties.N.NumberOfDecimalPlaces); @@ -66,7 +72,7 @@ } [Test] - public void Constructor_Always_PropertiesHaveExpectedAttributesValues() + public void Constructor_IsRelevantTrue_PropertiesHaveExpectedAttributesValues() { // Setup var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); @@ -76,7 +82,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"; @@ -109,6 +115,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, @@ -117,6 +130,53 @@ } [Test] + public void Constructor_IsRelevantFalse_PropertiesHaveExpectedAttributesValues() + { + // Setup + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism() + { + IsRelevant = false + }; + + // Call + var properties = new GrassCoverErosionOutwardsFailurePathProperties(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)]