Index: Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Forms/PropertyClasses/GrassCoverErosionOutwardsFailurePathProperties.cs =================================================================== diff -u -r4075241549b94454a6ad23fc355c69be49aecc17 -rc32114e2ca7e943d46c4db7053f737a91d1beb4d --- Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Forms/PropertyClasses/GrassCoverErosionOutwardsFailurePathProperties.cs (.../GrassCoverErosionOutwardsFailurePathProperties.cs) (revision 4075241549b94454a6ad23fc355c69be49aecc17) +++ Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Forms/PropertyClasses/GrassCoverErosionOutwardsFailurePathProperties.cs (.../GrassCoverErosionOutwardsFailurePathProperties.cs) (revision c32114e2ca7e943d46c4db7053f737a91d1beb4d) @@ -39,6 +39,7 @@ private const int contributionPropertyIndex = 4; private const int inAssemblyPropertyIndex = 5; private const int nPropertyIndex = 6; + private const int applyLengthEffectInSectionPropertyIndex = 7; /// /// Creates a new instance of . @@ -52,6 +53,24 @@ CodePropertyIndex = codePropertyIndex }) {} + [DynamicVisibleValidationMethod] + public bool DynamicVisibleValidationMethod(string propertyName) + { + if (!data.InAssembly && ShouldHidePropertyWhenFailureMechanismNotPartOfAssembly(propertyName)) + { + return false; + } + + return true; + } + + private static bool ShouldHidePropertyWhenFailureMechanismNotPartOfAssembly(string propertyName) + { + return nameof(Contribution).Equals(propertyName) + || nameof(N).Equals(propertyName) + || nameof(ApplyLengthEffectInSection).Equals(propertyName); + } + #region Length effect parameters [DynamicVisible] @@ -72,24 +91,25 @@ } } - #endregion - - [DynamicVisibleValidationMethod] - public bool DynamicVisibleValidationMethod(string propertyName) + [DynamicVisible] + [PropertyOrder(applyLengthEffectInSectionPropertyIndex)] + [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_LengthEffect))] + [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailurePath_Apply_LengthEffect_In_Section_DisplayName))] + [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailurePath_Apply_LengthEffect_In_Section_Description))] + public bool ApplyLengthEffectInSection { - if (!data.InAssembly && ShouldHidePropertyWhenFailureMechanismNotPartOfAssembly(propertyName)) + get { - return false; + return data.GeneralInput.ApplyLengthEffectInSection; } - - return true; + set + { + data.GeneralInput.ApplyLengthEffectInSection = value; + data.NotifyObservers(); + } } - private bool ShouldHidePropertyWhenFailureMechanismNotPartOfAssembly(string propertyName) - { - return nameof(Contribution).Equals(propertyName) - || nameof(N).Equals(propertyName); - } + #endregion #region General Index: Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Forms.Test/PropertyClasses/GrassCoverErosionOutwardsFailurePathPropertiesTest.cs =================================================================== diff -u -rfdfcebfac58179f6b1d1e19d376342f82eaaffcd -rc32114e2ca7e943d46c4db7053f737a91d1beb4d --- Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Forms.Test/PropertyClasses/GrassCoverErosionOutwardsFailurePathPropertiesTest.cs (.../GrassCoverErosionOutwardsFailurePathPropertiesTest.cs) (revision fdfcebfac58179f6b1d1e19d376342f82eaaffcd) +++ Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Forms.Test/PropertyClasses/GrassCoverErosionOutwardsFailurePathPropertiesTest.cs (.../GrassCoverErosionOutwardsFailurePathPropertiesTest.cs) (revision c32114e2ca7e943d46c4db7053f737a91d1beb4d) @@ -42,6 +42,7 @@ private const int contributionPropertyIndex = 3; private const int inAssemblyPropertyIndex = 4; private const int nPropertyIndex = 5; + private const int applyLengthEffectInSectionPropertyIndex = 6; [Test] public void Constructor_ExpectedValues() @@ -50,7 +51,11 @@ var random = new Random(21); var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism { - InAssembly = random.NextBoolean() + InAssembly = random.NextBoolean(), + GeneralInput = + { + ApplyLengthEffectInSection = random.NextBoolean() + } }; // Call @@ -69,6 +74,7 @@ Assert.AreEqual(generalInput.N, properties.N, properties.N.GetAccuracy()); + Assert.AreEqual(generalInput.ApplyLengthEffectInSection, properties.ApplyLengthEffectInSection); } [Test] @@ -82,7 +88,7 @@ // Assert PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); - Assert.AreEqual(6, dynamicProperties.Count); + Assert.AreEqual(7, dynamicProperties.Count); const string generalCategory = "Algemeen"; const string lengthEffectCategory = "Lengte-effect"; @@ -127,6 +133,12 @@ lengthEffectCategory, "N [-]", "De parameter 'N' die gebruikt wordt om het lengte-effect mee te nemen in de beoordeling."); + + PropertyDescriptor applySectionLengthInSectionProperty = dynamicProperties[applyLengthEffectInSectionPropertyIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(applySectionLengthInSectionProperty, + lengthEffectCategory, + "Toepassen lengte-effect binnen vak", + "Geeft aan of het lengte-effect binnen een vak toegepast wordt."); } [Test] @@ -232,6 +244,37 @@ [Test] [TestCase(true)] [TestCase(false)] + public void ApplyLengthEffectInSection_SetNewValue_NotifyObservers(bool applyLengthEffectInSection) + { + // Setup + var mocks = new MockRepository(); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism + { + GeneralInput = + { + ApplyLengthEffectInSection = !applyLengthEffectInSection + } + }; + + failureMechanism.Attach(observer); + + var properties = new GrassCoverErosionOutwardsFailurePathProperties(failureMechanism); + + // Call + properties.ApplyLengthEffectInSection = applyLengthEffectInSection; + + // Assert + Assert.AreEqual(applyLengthEffectInSection, failureMechanism.GeneralInput.ApplyLengthEffectInSection); + mocks.VerifyAll(); + } + + [Test] + [TestCase(true)] + [TestCase(false)] public void DynamicVisibleValidationMethod_DependingOnInAssembly_ReturnExpectedVisibility(bool inAssembly) { // Setup @@ -249,6 +292,7 @@ Assert.AreEqual(inAssembly, properties.DynamicVisibleValidationMethod(nameof(properties.Contribution))); Assert.AreEqual(inAssembly, properties.DynamicVisibleValidationMethod(nameof(properties.N))); + Assert.AreEqual(inAssembly, properties.DynamicVisibleValidationMethod(nameof(properties.ApplyLengthEffectInSection))); Assert.IsTrue(properties.DynamicVisibleValidationMethod(null)); }