Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsFailureMechanismContextProperties.cs =================================================================== diff -u -r0eef796eb9da995e56fd1e4a61296ec3c25dcfad -ra0500683a36518c9b3cd5bb74fee36b858dda96d --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsFailureMechanismContextProperties.cs (.../GrassCoverErosionInwardsFailureMechanismContextProperties.cs) (revision 0eef796eb9da995e56fd1e4a61296ec3c25dcfad) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsFailureMechanismContextProperties.cs (.../GrassCoverErosionInwardsFailureMechanismContextProperties.cs) (revision a0500683a36518c9b3cd5bb74fee36b858dda96d) @@ -39,14 +39,15 @@ /// public class GrassCoverErosionInwardsFailureMechanismContextProperties : ObjectProperties { - private readonly IFailureMechanismPropertyChangeHandler propertyChangeHandler; private const int namePropertyIndex = 1; private const int codePropertyIndex = 2; - private const int lengthEffectPropertyIndex = 3; - private const int frunupModelFactorPropertyIndex = 4; - private const int fbFactorPropertyIndex = 5; - private const int fnFactorPropertyIndex = 6; - private const int fshallowModelFactorPropertyIndex = 7; + private const int isRelevantPropertyIndex = 3; + private const int lengthEffectPropertyIndex = 4; + private const int frunupModelFactorPropertyIndex = 5; + private const int fbFactorPropertyIndex = 6; + private const int fnFactorPropertyIndex = 7; + private const int fshallowModelFactorPropertyIndex = 8; + private readonly IFailureMechanismPropertyChangeHandler propertyChangeHandler; /// /// Creates a new instance of . @@ -55,7 +56,7 @@ /// Handler responsible for handling effects of a property change. /// Thrown when any input parameter is null. public GrassCoverErosionInwardsFailureMechanismContextProperties( - GrassCoverErosionInwardsFailureMechanismContext data, + GrassCoverErosionInwardsFailureMechanismContext data, IFailureMechanismPropertyChangeHandler handler) { if (data == null) @@ -72,6 +73,7 @@ #region Length effect parameters + [DynamicVisible] [PropertyOrder(lengthEffectPropertyIndex)] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_LengthEffect))] [ResourcesDisplayName(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.FailureMechanism_N_DisplayName))] @@ -95,6 +97,33 @@ #endregion + [DynamicVisibleValidationMethod] + public bool DynamicVisibleValidationMethod(string propertyName) + { + if (!data.WrappedData.IsRelevant && ShouldHidePropertyWhenFailureMechanismIrrelevant(propertyName)) + { + return false; + } + return true; + } + + private static void NotifyAffectedObjects(IEnumerable affectedObjects) + { + foreach (var affectedObject in affectedObjects) + { + affectedObject.NotifyObservers(); + } + } + + private bool ShouldHidePropertyWhenFailureMechanismIrrelevant(string propertyName) + { + return nameof(LengthEffect).Equals(propertyName) + || nameof(FrunupModelFactor).Equals(propertyName) + || nameof(FbFactor).Equals(propertyName) + || nameof(FnFactor).Equals(propertyName) + || nameof(FshallowModelFactor).Equals(propertyName); + } + #region General [PropertyOrder(namePropertyIndex)] @@ -121,10 +150,23 @@ } } + [PropertyOrder(isRelevantPropertyIndex)] + [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_General))] + [ResourcesDisplayName(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.FailureMechanism_IsRelevant_DisplayName))] + [ResourcesDescription(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.FailureMechanism_IsRelevant_Description))] + public bool IsRelevant + { + get + { + return data.WrappedData.IsRelevant; + } + } + #endregion #region Model settings + [DynamicVisible] [PropertyOrder(frunupModelFactorPropertyIndex)] [TypeConverter(typeof(ExpandableObjectConverter))] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_ModelSettings))] @@ -138,6 +180,7 @@ } } + [DynamicVisible] [PropertyOrder(fbFactorPropertyIndex)] [TypeConverter(typeof(ExpandableObjectConverter))] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_ModelSettings))] @@ -151,6 +194,7 @@ } } + [DynamicVisible] [PropertyOrder(fnFactorPropertyIndex)] [TypeConverter(typeof(ExpandableObjectConverter))] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_ModelSettings))] @@ -164,6 +208,7 @@ } } + [DynamicVisible] [PropertyOrder(fshallowModelFactorPropertyIndex)] [TypeConverter(typeof(ExpandableObjectConverter))] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_ModelSettings))] @@ -178,13 +223,5 @@ } #endregion - - private static void NotifyAffectedObjects(IEnumerable affectedObjects) - { - foreach (var affectedObject in affectedObjects) - { - affectedObject.NotifyObservers(); - } - } } } \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/PropertyClasses/GrassCoverErosionInwardsFailureMechanismContextPropertiesTest.cs =================================================================== diff -u -rfb9bf56793b90226745888c194ba6ae760f83f4c -ra0500683a36518c9b3cd5bb74fee36b858dda96d --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/PropertyClasses/GrassCoverErosionInwardsFailureMechanismContextPropertiesTest.cs (.../GrassCoverErosionInwardsFailureMechanismContextPropertiesTest.cs) (revision fb9bf56793b90226745888c194ba6ae760f83f4c) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/PropertyClasses/GrassCoverErosionInwardsFailureMechanismContextPropertiesTest.cs (.../GrassCoverErosionInwardsFailureMechanismContextPropertiesTest.cs) (revision a0500683a36518c9b3cd5bb74fee36b858dda96d) @@ -29,7 +29,6 @@ using Ringtoets.Common.Forms.PropertyClasses; using Ringtoets.Common.Forms.TestUtil; using Ringtoets.GrassCoverErosionInwards.Data; -using Ringtoets.GrassCoverErosionInwards.Data.Properties; using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects; using Ringtoets.GrassCoverErosionInwards.Forms.PropertyClasses; @@ -40,11 +39,12 @@ { private const int namePropertyIndex = 0; private const int codePropertyIndex = 1; - private const int lengthEffectPropertyIndex = 2; - private const int frunupModelFactorPropertyIndex = 3; - private const int fbFactorPropertyIndex = 4; - private const int fnFactorPropertyIndex = 5; - private const int fshallowModelFactorPropertyIndex = 6; + private const int isRelevantPropertyIndex = 2; + private const int lengthEffectPropertyIndex = 3; + private const int frunupModelFactorPropertyIndex = 4; + private const int fbFactorPropertyIndex = 5; + private const int fnFactorPropertyIndex = 6; + private const int fshallowModelFactorPropertyIndex = 7; private MockRepository mockRepository; [SetUp] @@ -88,22 +88,28 @@ } [Test] - public void Constructor_ExpectedValues() + [TestCase(true)] + [TestCase(false)] + public void Constructor_ExpectedValues(bool isRelevant) { // Setup var assessmentSection = mockRepository.Stub(); var handler = mockRepository.Stub>(); mockRepository.ReplayAll(); - var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism + { + IsRelevant = isRelevant + }; var properties = new GrassCoverErosionInwardsFailureMechanismContextProperties( new GrassCoverErosionInwardsFailureMechanismContext(failureMechanism, assessmentSection), handler); // Assert - Assert.AreEqual(Resources.GrassCoverErosionInwardsFailureMechanism_DisplayName, properties.Name); - Assert.AreEqual(Resources.GrassCoverErosionInwardsFailureMechanism_DisplayCode, properties.Code); + Assert.AreEqual("Dijken en dammen - Grasbekleding erosie kruin en binnentalud", properties.Name); + Assert.AreEqual("GEKB", properties.Code); + Assert.AreEqual(isRelevant, properties.IsRelevant); Assert.AreEqual(2, properties.LengthEffect); var generalInput = new GeneralGrassCoverErosionInwardsInput(); @@ -122,14 +128,17 @@ } [Test] - public void Constructor_Always_PropertiesHaveExpectedAttributesValues() + public void Constructor_IsRelevantTrue_PropertiesHaveExpectedAttributesValues() { // Setup var assessmentSection = mockRepository.Stub(); var handler = mockRepository.Stub>(); mockRepository.ReplayAll(); - var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism + { + IsRelevant = true + }; // Call var properties = new GrassCoverErosionInwardsFailureMechanismContextProperties( @@ -142,7 +151,7 @@ var modelSettingsCategory = "Modelinstellingen"; PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); - Assert.AreEqual(7, dynamicProperties.Count); + Assert.AreEqual(8, dynamicProperties.Count); PropertyDescriptor nameProperty = dynamicProperties[namePropertyIndex]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(nameProperty, @@ -158,6 +167,13 @@ "Het label van het toetsspoor.", true); + PropertyDescriptor isRelevantProperty = dynamicProperties[isRelevantPropertyIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(isRelevantProperty, + generalCategory, + "Is relevant", + "Geeft aan of dit toetsspoor relevant is of niet.", + true); + PropertyDescriptor lengthEffectProperty = dynamicProperties[lengthEffectPropertyIndex]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(lengthEffectProperty, lengthEffectParameterCategory, @@ -200,6 +216,54 @@ } [Test] + public void Constructor_IsRelevantFalse_PropertiesHaveExpectedAttributesValues() + { + // Setup + var assessmentSection = mockRepository.Stub(); + var handler = mockRepository.Stub>(); + mockRepository.ReplayAll(); + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism + { + IsRelevant = false + }; + + // Call + var properties = new GrassCoverErosionInwardsFailureMechanismContextProperties( + new GrassCoverErosionInwardsFailureMechanismContext(failureMechanism, assessmentSection), + handler); + + // Assert + var generalCategory = "Algemeen"; + + PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); + Assert.AreEqual(3, dynamicProperties.Count); + + PropertyDescriptor nameProperty = dynamicProperties[namePropertyIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(nameProperty, + generalCategory, + "Naam", + "De naam van het toetsspoor.", + true); + + PropertyDescriptor codeProperty = dynamicProperties[codePropertyIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(codeProperty, + generalCategory, + "Label", + "Het label van het toetsspoor.", + true); + + PropertyDescriptor isRelevantProperty = dynamicProperties[isRelevantPropertyIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(isRelevantProperty, + generalCategory, + "Is relevant", + "Geeft aan of dit toetsspoor relevant is of niet.", + true); + + mockRepository.VerifyAll(); + } + + [Test] [TestCase(0, TestName = "LenghtEffect_InvalidValue_ThrowsArgumentOutOfRangeExceptionNoNotifcations(0)")] [TestCase(-1, TestName = "LenghtEffect_InvalidValue_ThrowsArgumentOutOfRangeExceptionNoNotifcations(-1)")] [TestCase(-20, TestName = "LenghtEffect_InvalidValue_ThrowsArgumentOutOfRangeExceptionNoNotifcations(-20)")] @@ -267,5 +331,65 @@ Assert.IsTrue(changeHandler.Called); mockRepository.VerifyAll(); } + + [Test] + public void DynamicVisibleValidationMethod_ForRelevantFailureMechanism_ReturnExpectedVisibility() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + var changeHandler = mocks.Stub>(); + mocks.ReplayAll(); + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism + { + IsRelevant = true + }; + var context = new GrassCoverErosionInwardsFailureMechanismContext(failureMechanism, assessmentSection); + + var properties = new GrassCoverErosionInwardsFailureMechanismContextProperties(context, changeHandler); + + // Call & Assert + Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.LengthEffect))); + Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.Name))); + Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.Code))); + Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.IsRelevant))); + Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.FrunupModelFactor))); + Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.FbFactor))); + Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.FnFactor))); + Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.FshallowModelFactor))); + + Assert.IsTrue(properties.DynamicVisibleValidationMethod(null)); + } + + [Test] + public void DynamicVisibleValidationMethod_ForIrrelevantFailureMechanism_ReturnExpectedVisibility() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + var changeHandler = mocks.Stub>(); + mocks.ReplayAll(); + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism + { + IsRelevant = false + }; + var context = new GrassCoverErosionInwardsFailureMechanismContext(failureMechanism, assessmentSection); + + var properties = new GrassCoverErosionInwardsFailureMechanismContextProperties(context, changeHandler); + + // Call & Assert + Assert.IsFalse(properties.DynamicVisibleValidationMethod(nameof(properties.LengthEffect))); + Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.Name))); + Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.Code))); + Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.IsRelevant))); + Assert.IsFalse(properties.DynamicVisibleValidationMethod(nameof(properties.FrunupModelFactor))); + Assert.IsFalse(properties.DynamicVisibleValidationMethod(nameof(properties.FbFactor))); + Assert.IsFalse(properties.DynamicVisibleValidationMethod(nameof(properties.FnFactor))); + Assert.IsFalse(properties.DynamicVisibleValidationMethod(nameof(properties.FshallowModelFactor))); + + Assert.IsTrue(properties.DynamicVisibleValidationMethod(null)); + } } } \ No newline at end of file