Index: Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsCalculationsProperties.cs =================================================================== diff -u -r3a79a9260f7434ff776602cc53a2b8c6a9f8633e -r0e9d074a8dd58198dbb156c497eb96979868b879 --- Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsCalculationsProperties.cs (.../GrassCoverErosionInwardsCalculationsProperties.cs) (revision 3a79a9260f7434ff776602cc53a2b8c6a9f8633e) +++ Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsCalculationsProperties.cs (.../GrassCoverErosionInwardsCalculationsProperties.cs) (revision 0e9d074a8dd58198dbb156c497eb96979868b879) @@ -47,7 +47,6 @@ private const int fbFactorPropertyIndex = 7; private const int fnFactorPropertyIndex = 8; private const int fshallowModelFactorPropertyIndex = 9; - private readonly IFailureMechanismPropertyChangeHandler propertyChangeHandler; /// /// Creates a new instance of . @@ -64,30 +63,8 @@ GroupPropertyIndex = groupPropertyIndex, ContributionPropertyIndex = contributionPropertyIndex, NPropertyIndex = nPropertyIndex - }, handler ) - { - if (data == null) - { - throw new ArgumentNullException(nameof(data)); - } + }, handler) {} - if (handler == null) - { - throw new ArgumentNullException(nameof(handler)); - } - - Data = data; - propertyChangeHandler = handler; - } - - private static void NotifyAffectedObjects(IEnumerable affectedObjects) - { - foreach (IObservable affectedObject in affectedObjects) - { - affectedObject.NotifyObservers(); - } - } - #region General [PropertyOrder(contributionPropertyIndex)] @@ -104,6 +81,39 @@ #endregion + #region Length effect parameters + + [PropertyOrder(nPropertyIndex)] + [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_LengthEffect))] + [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_N_DisplayName))] + [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_N_Description))] + public override RoundedDouble N + { + get + { + return data.GeneralInput.N; + } + set + { + IEnumerable affectedObjects = PropertyChangeHandler.SetPropertyValueAfterConfirmation( + data, + value, + (f, v) => f.GeneralInput.N = v); + + NotifyAffectedObjects(affectedObjects); + } + } + + #endregion + + private static void NotifyAffectedObjects(IEnumerable affectedObjects) + { + foreach (IObservable affectedObject in affectedObjects) + { + affectedObject.NotifyObservers(); + } + } + #region Model settings [PropertyOrder(frunupModelFactorPropertyIndex)] @@ -159,30 +169,5 @@ } #endregion - - #region Length effect parameters - - [PropertyOrder(nPropertyIndex)] - [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_LengthEffect))] - [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_N_DisplayName))] - [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_N_Description))] - public override RoundedDouble N - { - get - { - return data.GeneralInput.N; - } - set - { - IEnumerable affectedObjects = propertyChangeHandler.SetPropertyValueAfterConfirmation( - data, - value, - (f, v) => f.GeneralInput.N = v); - - NotifyAffectedObjects(affectedObjects); - } - } - - #endregion } } \ No newline at end of file Index: Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsFailureMechanismProperties.cs =================================================================== diff -u -r3a79a9260f7434ff776602cc53a2b8c6a9f8633e -r0e9d074a8dd58198dbb156c497eb96979868b879 --- Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsFailureMechanismProperties.cs (.../GrassCoverErosionInwardsFailureMechanismProperties.cs) (revision 3a79a9260f7434ff776602cc53a2b8c6a9f8633e) +++ Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsFailureMechanismProperties.cs (.../GrassCoverErosionInwardsFailureMechanismProperties.cs) (revision 0e9d074a8dd58198dbb156c497eb96979868b879) @@ -39,8 +39,6 @@ { private readonly Dictionary propertyIndexLookup; - private readonly IFailureMechanismPropertyChangeHandler propertyChangeHandler; - /// /// Creates a new instance of . /// @@ -69,7 +67,7 @@ } Data = data; - propertyChangeHandler = handler; + PropertyChangeHandler = handler; propertyIndexLookup = new Dictionary { @@ -91,8 +89,31 @@ }; } + #region Length effect parameters + [DynamicPropertyOrder] + [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_LengthEffect))] + [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_N_Rounded_DisplayName))] + [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_N_Rounded_Description))] + public virtual RoundedDouble N + { + get + { + return data.GeneralInput.N; + } + set + { + IEnumerable affectedObjects = PropertyChangeHandler.SetPropertyValueAfterConfirmation( + data, + value, + (f, v) => f.GeneralInput.N = v); + NotifyAffectedObjects(affectedObjects); + } + } + + #endregion + [DynamicPropertyOrderEvaluationMethod] public int DynamicPropertyOrderEvaluationMethod(string propertyName) { @@ -101,6 +122,8 @@ return propertyIndex; } + protected IFailureMechanismPropertyChangeHandler PropertyChangeHandler { get; } + private static void NotifyAffectedObjects(IEnumerable affectedObjects) { foreach (IObservable affectedObject in affectedObjects) @@ -199,30 +222,5 @@ } #endregion - - #region Length effect parameters - - [DynamicPropertyOrder] - [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_LengthEffect))] - [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_N_DisplayName))] - [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_N_Description))] - public virtual RoundedDouble N - { - get - { - return data.GeneralInput.N; - } - set - { - IEnumerable affectedObjects = propertyChangeHandler.SetPropertyValueAfterConfirmation( - data, - value, - (f, v) => f.GeneralInput.N = v); - - NotifyAffectedObjects(affectedObjects); - } - } - - #endregion } } \ No newline at end of file Index: Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsFailurePathProperties.cs =================================================================== diff -u -r3a79a9260f7434ff776602cc53a2b8c6a9f8633e -r0e9d074a8dd58198dbb156c497eb96979868b879 --- Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsFailurePathProperties.cs (.../GrassCoverErosionInwardsFailurePathProperties.cs) (revision 3a79a9260f7434ff776602cc53a2b8c6a9f8633e) +++ Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsFailurePathProperties.cs (.../GrassCoverErosionInwardsFailurePathProperties.cs) (revision 0e9d074a8dd58198dbb156c497eb96979868b879) @@ -43,8 +43,6 @@ private const int isRelevantPropertyIndex = 5; private const int nPropertyIndex = 6; - private readonly IFailureMechanismPropertyChangeHandler propertyChangeHandler; - /// /// Creates a new instance of . /// @@ -53,37 +51,23 @@ /// Thrown when any input parameter is null. public GrassCoverErosionInwardsFailurePathProperties( GrassCoverErosionInwardsFailureMechanism data, - IFailureMechanismPropertyChangeHandler handler) : + IFailureMechanismPropertyChangeHandler handler) : base(data, new ConstructionProperties - { - NamePropertyIndex = namePropertyIndex, - CodePropertyIndex = codePropertyIndex, - GroupPropertyIndex = groupPropertyIndex, - ContributionPropertyIndex = contributionPropertyIndex, - NPropertyIndex = nPropertyIndex - }, handler) - { - if (data == null) { - throw new ArgumentNullException(nameof(data)); - } + NamePropertyIndex = namePropertyIndex, + CodePropertyIndex = codePropertyIndex, + GroupPropertyIndex = groupPropertyIndex, + ContributionPropertyIndex = contributionPropertyIndex, + NPropertyIndex = nPropertyIndex + }, handler) {} - if (handler == null) - { - throw new ArgumentNullException(nameof(handler)); - } - - Data = data; - propertyChangeHandler = handler; - } - #region Length effect parameters [DynamicVisible] [PropertyOrder(nPropertyIndex)] [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_LengthEffect))] - [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_N_DisplayName))] - [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_N_Description))] + [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_N_Rounded_DisplayName))] + [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_N_Rounded_Description))] public override RoundedDouble N { get @@ -92,7 +76,7 @@ } set { - IEnumerable affectedObjects = propertyChangeHandler.SetPropertyValueAfterConfirmation( + IEnumerable affectedObjects = PropertyChangeHandler.SetPropertyValueAfterConfirmation( data, value, (f, v) => f.GeneralInput.N = v); @@ -156,6 +140,5 @@ } #endregion - } } \ No newline at end of file Fisheye: Tag 12974d5032777e3a29fe5566ebe16e7b80012290 refers to a dead (removed) revision in file `Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Forms.Test/PropertyClasses/GrassCoverErosionInwardsFailureMechanismPropertiesTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Forms.Test/PropertyClasses/GrassCoverErosionInwardsFailurePathPropertiesTest.cs =================================================================== diff -u --- Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Forms.Test/PropertyClasses/GrassCoverErosionInwardsFailurePathPropertiesTest.cs (revision 0) +++ Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Forms.Test/PropertyClasses/GrassCoverErosionInwardsFailurePathPropertiesTest.cs (revision 0e9d074a8dd58198dbb156c497eb96979868b879) @@ -0,0 +1,298 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.ComponentModel; +using Core.Common.Base; +using Core.Common.Base.Data; +using Core.Common.TestUtil; +using Core.Gui.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Riskeer.Common.Data.TestUtil; +using Riskeer.Common.Forms.PropertyClasses; +using Riskeer.Common.Forms.TestUtil; +using Riskeer.GrassCoverErosionInwards.Data; +using Riskeer.GrassCoverErosionInwards.Forms.PropertyClasses; + +namespace Riskeer.GrassCoverErosionInwards.Forms.Test.PropertyClasses +{ + [TestFixture] + public class GrassCoverErosionInwardsFailurePathPropertiesTest + { + private const int namePropertyIndex = 0; + private const int codePropertyIndex = 1; + private const int groupPropertyIndex = 2; + private const int contributionPropertyIndex = 3; + private const int isRelevantPropertyIndex = 4; + private const int nPropertyIndex = 5; + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Constructor_ExpectedValues(bool isRelevant) + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism + { + IsRelevant = isRelevant + }; + + var mocks = new MockRepository(); + var handler = mocks.Stub>(); + mocks.ReplayAll(); + + // Call + var properties = new GrassCoverErosionInwardsFailurePathProperties(failureMechanism, handler); + + // Assert + Assert.IsInstanceOf(properties); + Assert.AreEqual(failureMechanism.Name, properties.Name); + Assert.AreEqual(failureMechanism.Code, properties.Code); + Assert.AreEqual(failureMechanism.Group, properties.Group); + Assert.AreEqual(failureMechanism.Contribution, properties.Contribution); + Assert.AreEqual(isRelevant, properties.IsRelevant); + + GeneralGrassCoverErosionInwardsInput generalInput = failureMechanism.GeneralInput; + Assert.AreEqual(2, properties.N.NumberOfDecimalPlaces); + Assert.AreEqual(generalInput.N, + properties.N, + properties.N.GetAccuracy()); + + mocks.VerifyAll(); + } + + [Test] + public void Constructor_IsRelevantTrue_PropertiesHaveExpectedAttributesValues() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism + { + IsRelevant = true + }; + + var mocks = new MockRepository(); + var handler = mocks.Stub>(); + mocks.ReplayAll(); + + // Call + var properties = new GrassCoverErosionInwardsFailurePathProperties(failureMechanism, handler); + + // Assert + PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); + Assert.AreEqual(6, dynamicProperties.Count); + + const string generalCategory = "Algemeen"; + const string lengthEffectCategory = "Lengte-effect parameters"; + + 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 contributionProperty = dynamicProperties[contributionPropertyIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(contributionProperty, + generalCategory, + "Faalkansbijdrage [%]", + "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, + "N* [-]", + "De parameter 'N' die gebruikt wordt om het lengte-effect mee te nemen in de beoordeling (afgerond)."); + + mocks.VerifyAll(); + } + + [Test] + public void Constructor_IsRelevantFalse_PropertiesHaveExpectedAttributesValues() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism + { + IsRelevant = false + }; + + var mocks = new MockRepository(); + var handler = mocks.Stub>(); + mocks.ReplayAll(); + + // Call + var properties = new GrassCoverErosionInwardsFailurePathProperties(failureMechanism, handler); + + // 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); + + mocks.VerifyAll(); + } + + [Test] + [SetCulture("nl-NL")] + [TestCase(0.0)] + [TestCase(-1.0)] + [TestCase(-20.0)] + public void N_SetInvalidValue_ThrowsArgumentOutOfRangeExceptionNoNotifications(double newN) + { + // Setup + var mockRepository = new MockRepository(); + var observable = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var handler = new FailureMechanismSetPropertyValueAfterConfirmationParameterTester( + failureMechanism, + (RoundedDouble) newN, + new[] + { + observable + }); + + var properties = new GrassCoverErosionInwardsFailurePathProperties(failureMechanism, handler); + + // Call + void Call() => properties.N = (RoundedDouble) newN; + + // Assert + const string expectedMessage = "De waarde voor 'N' moet in het bereik [1,00, 20,00] liggen."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(Call, expectedMessage); + Assert.IsTrue(handler.Called); + mockRepository.VerifyAll(); + } + + [Test] + [TestCase(1)] + [TestCase(10)] + [TestCase(20)] + public void N_SetValidValue_UpdateDataAndNotifyObservers(double newN) + { + // Setup + var mockRepository = new MockRepository(); + var observable = mockRepository.StrictMock(); + observable.Expect(o => o.NotifyObservers()); + mockRepository.ReplayAll(); + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var handler = new FailureMechanismSetPropertyValueAfterConfirmationParameterTester( + failureMechanism, + (RoundedDouble) newN, + new[] + { + observable + }); + + var properties = new GrassCoverErosionInwardsFailurePathProperties(failureMechanism, handler); + + // Call + properties.N = (RoundedDouble) newN; + + // Assert + Assert.AreEqual(newN, failureMechanism.GeneralInput.N, failureMechanism.GeneralInput.N.GetAccuracy()); + Assert.IsTrue(handler.Called); + mockRepository.VerifyAll(); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void DynamicVisibleValidationMethod_DependingOnRelevancy_ReturnExpectedVisibility(bool isRelevant) + { + // Setup + var mocks = new MockRepository(); + var handler = mocks.Stub>(); + mocks.ReplayAll(); + + var grassCoverErosionInwardsFailureMechanism = new GrassCoverErosionInwardsFailureMechanism + { + IsRelevant = isRelevant + }; + var properties = new GrassCoverErosionInwardsFailurePathProperties(grassCoverErosionInwardsFailureMechanism, handler); + + // 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)); + + mocks.VerifyAll(); + } + } +} \ No newline at end of file