Index: Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Forms/PropertyClasses/StabilityPointStructuresFailureMechanismProperties.cs =================================================================== diff -u -rf861839e975251253e2ffd7bc3f0a1839b85534e -r29b6e326e4a729daa7f88c6a54b2fcd7c5e2af83 --- Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Forms/PropertyClasses/StabilityPointStructuresFailureMechanismProperties.cs (.../StabilityPointStructuresFailureMechanismProperties.cs) (revision f861839e975251253e2ffd7bc3f0a1839b85534e) +++ Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Forms/PropertyClasses/StabilityPointStructuresFailureMechanismProperties.cs (.../StabilityPointStructuresFailureMechanismProperties.cs) (revision 29b6e326e4a729daa7f88c6a54b2fcd7c5e2af83) @@ -41,12 +41,13 @@ { private const int namePropertyIndex = 1; private const int codePropertyIndex = 2; - private const int gravitationalAccelerationPropertyIndex = 3; - private const int lengthEffectPropertyIndex = 4; - private const int modelFactorStorageVolumePropertyIndex = 5; - private const int modelFactorSubCriticalFlowPropertyIndex = 6; - private const int modelFactorCollisionLoadPropertyIndex = 7; - private const int modelFactorLoadEffectPropertyIndex = 8; + private const int isRelevantPropertyIndex = 3; + private const int gravitationalAccelerationPropertyIndex = 4; + private const int lengthEffectPropertyIndex = 5; + private const int modelFactorStorageVolumePropertyIndex = 6; + private const int modelFactorSubCriticalFlowPropertyIndex = 7; + private const int modelFactorCollisionLoadPropertyIndex = 8; + private const int modelFactorLoadEffectPropertyIndex = 9; private readonly IFailureMechanismPropertyChangeHandler propertyChangeHandler; @@ -74,6 +75,7 @@ #region Length effect parameters + [DynamicVisible] [PropertyOrder(lengthEffectPropertyIndex)] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_LengthEffect))] [ResourcesDisplayName(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.FailureMechanism_N_DisplayName))] @@ -97,6 +99,16 @@ #endregion + [DynamicVisibleValidationMethod] + public bool DynamicVisibleValidationMethod(string propertyName) + { + if (!data.IsRelevant && ShouldHidePropertyWhenFailureMechanismIrrelevant(propertyName)) + { + return false; + } + return true; + } + private static void NotifyAffectedObjects(IEnumerable affectedObjects) { foreach (var affectedObject in affectedObjects) @@ -105,6 +117,16 @@ } } + private bool ShouldHidePropertyWhenFailureMechanismIrrelevant(string propertyName) + { + return nameof(LengthEffect).Equals(propertyName) + || nameof(GravitationalAcceleration).Equals(propertyName) + || nameof(ModelFactorStorageVolume).Equals(propertyName) + || nameof(ModelFactorSubCriticalFlow).Equals(propertyName) + || nameof(ModelFactorCollisionLoad).Equals(propertyName) + || nameof(ModelFactorLoadEffect).Equals(propertyName); + } + #region General [PropertyOrder(namePropertyIndex)] @@ -131,6 +153,19 @@ } } + [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.IsRelevant; + } + } + + [DynamicVisible] [PropertyOrder(gravitationalAccelerationPropertyIndex)] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_General))] [ResourcesDisplayName(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.GravitationalAcceleration_DisplayName))] @@ -147,6 +182,7 @@ #region Model settings + [DynamicVisible] [PropertyOrder(modelFactorStorageVolumePropertyIndex)] [TypeConverter(typeof(ExpandableObjectConverter))] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_ModelSettings))] @@ -160,6 +196,7 @@ } } + [DynamicVisible] [PropertyOrder(modelFactorSubCriticalFlowPropertyIndex)] [TypeConverter(typeof(ExpandableObjectConverter))] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_ModelSettings))] @@ -173,6 +210,7 @@ } } + [DynamicVisible] [PropertyOrder(modelFactorCollisionLoadPropertyIndex)] [TypeConverter(typeof(ExpandableObjectConverter))] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_ModelSettings))] @@ -186,6 +224,7 @@ } } + [DynamicVisible] [PropertyOrder(modelFactorLoadEffectPropertyIndex)] [TypeConverter(typeof(ExpandableObjectConverter))] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_ModelSettings))] Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/PropertyClasses/StabilityPointStructuresFailureMechanismPropertiesTest.cs =================================================================== diff -u -r54feee4bbc803da593586d0c19de638dccf5c621 -r29b6e326e4a729daa7f88c6a54b2fcd7c5e2af83 --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/PropertyClasses/StabilityPointStructuresFailureMechanismPropertiesTest.cs (.../StabilityPointStructuresFailureMechanismPropertiesTest.cs) (revision 54feee4bbc803da593586d0c19de638dccf5c621) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/PropertyClasses/StabilityPointStructuresFailureMechanismPropertiesTest.cs (.../StabilityPointStructuresFailureMechanismPropertiesTest.cs) (revision 29b6e326e4a729daa7f88c6a54b2fcd7c5e2af83) @@ -38,12 +38,13 @@ { private const int namePropertyIndex = 0; private const int codePropertyIndex = 1; - private const int gravitationalAccelerationPropertyIndex = 2; - private const int lengthEffectPropertyIndex = 3; - private const int modelFactorStorageVolumePropertyIndex = 4; - private const int modelFactorSubCriticalFlowPropertyIndex = 5; - private const int modelFactorCollisionLoadPropertyIndex = 6; - private const int modelFactorLoadEffectPropertyIndex = 7; + private const int isRelevantPropertyIndex = 2; + private const int gravitationalAccelerationPropertyIndex = 3; + private const int lengthEffectPropertyIndex = 4; + private const int modelFactorStorageVolumePropertyIndex = 5; + private const int modelFactorSubCriticalFlowPropertyIndex = 6; + private const int modelFactorCollisionLoadPropertyIndex = 7; + private const int modelFactorLoadEffectPropertyIndex = 8; [Test] public void Constructor_DataIsNull_ThrowArgumentNullException() @@ -77,15 +78,19 @@ } [Test] - public void Constructor_ValidValues_ExpectedValues() + [TestCase(true)] + [TestCase(false)] + public void Constructor_ValidValues_ExpectedValues(bool isRelevant) { // Setup var mocks = new MockRepository(); - IFailureMechanismPropertyChangeHandler changeHandler = - mocks.Stub>(); + var changeHandler = mocks.Stub>(); mocks.ReplayAll(); - var failureMechanism = new StabilityPointStructuresFailureMechanism(); + var failureMechanism = new StabilityPointStructuresFailureMechanism + { + IsRelevant = isRelevant + }; // Call var properties = new StabilityPointStructuresFailureMechanismProperties(failureMechanism, changeHandler); @@ -96,6 +101,7 @@ Assert.AreEqual("Kunstwerken - Sterkte en stabiliteit puntconstructies", properties.Name); Assert.AreEqual("STKWp", properties.Code); + Assert.AreEqual(isRelevant, properties.IsRelevant); GeneralStabilityPointStructuresInput generalInput = failureMechanism.GeneralInput; Assert.AreEqual(generalInput.N, properties.LengthEffect); @@ -111,15 +117,17 @@ } [Test] - public void Constructor_Always_PropertiesHaveExpectedAttributesValues() + public void Constructor_IsRelevantTrue_PropertiesHaveExpectedAttributesValues() { // Setup var mocks = new MockRepository(); - IFailureMechanismPropertyChangeHandler changeHandler = - mocks.Stub>(); + var changeHandler = mocks.Stub>(); mocks.ReplayAll(); - var failureMechanism = new StabilityPointStructuresFailureMechanism(); + var failureMechanism = new StabilityPointStructuresFailureMechanism + { + IsRelevant = true + }; // Call var properties = new StabilityPointStructuresFailureMechanismProperties(failureMechanism, changeHandler); @@ -130,7 +138,7 @@ var modelSettingsCategory = "Modelinstellingen"; PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); - Assert.AreEqual(8, dynamicProperties.Count); + Assert.AreEqual(9, dynamicProperties.Count); PropertyDescriptor nameProperty = dynamicProperties[namePropertyIndex]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(nameProperty, @@ -146,6 +154,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 gravitationalAccelerationProperty = dynamicProperties[gravitationalAccelerationPropertyIndex]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(gravitationalAccelerationProperty, generalCategory, @@ -190,9 +205,55 @@ "Modelfactor belastingeffect [-]", "Modelfactor belastingeffect.", true); + mocks.VerifyAll(); } [Test] + public void Constructor_IsRelevantFalse_PropertiesHaveExpectedAttributesValues() + { + // Setup + var mocks = new MockRepository(); + var changeHandler = mocks.Stub>(); + mocks.ReplayAll(); + + var failureMechanism = new StabilityPointStructuresFailureMechanism + { + IsRelevant = false + }; + + // Call + var properties = new StabilityPointStructuresFailureMechanismProperties(failureMechanism, changeHandler); + + // 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); + mocks.VerifyAll(); + } + + [Test] [TestCase(0)] [TestCase(-1)] [TestCase(-20)] @@ -256,5 +317,63 @@ Assert.IsTrue(changeHandler.Called); mockRepository.VerifyAll(); } + + [Test] + public void DynamicVisibleValidationMethod_ForRelevantFailureMechanism_ReturnExpectedVisibility() + { + // Setup + var mocks = new MockRepository(); + var changeHandler = mocks.Stub>(); + mocks.ReplayAll(); + + var properties = new StabilityPointStructuresFailureMechanismProperties( + new StabilityPointStructuresFailureMechanism + { + IsRelevant = true + }, + 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.GravitationalAcceleration))); + Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.ModelFactorStorageVolume))); + Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.ModelFactorSubCriticalFlow))); + Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.ModelFactorCollisionLoad))); + Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.ModelFactorLoadEffect))); + + Assert.IsTrue(properties.DynamicVisibleValidationMethod(null)); + } + + [Test] + public void DynamicVisibleValidationMethod_ForIrrelevantFailureMechanism_ReturnExpectedVisibility() + { + // Setup + var mocks = new MockRepository(); + var changeHandler = mocks.Stub>(); + mocks.ReplayAll(); + + var properties = new StabilityPointStructuresFailureMechanismProperties( + new StabilityPointStructuresFailureMechanism + { + IsRelevant = false + }, + 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.GravitationalAcceleration))); + Assert.IsFalse(properties.DynamicVisibleValidationMethod(nameof(properties.ModelFactorStorageVolume))); + Assert.IsFalse(properties.DynamicVisibleValidationMethod(nameof(properties.ModelFactorSubCriticalFlow))); + Assert.IsFalse(properties.DynamicVisibleValidationMethod(nameof(properties.ModelFactorCollisionLoad))); + Assert.IsFalse(properties.DynamicVisibleValidationMethod(nameof(properties.ModelFactorLoadEffect))); + + Assert.IsTrue(properties.DynamicVisibleValidationMethod(null)); + } } } \ No newline at end of file