Index: Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/ConfirmingDistributionPropertiesBase.cs =================================================================== diff -u -rf8998df0ea8c1228216bbb00ed9178058af4af67 -r2abaaf908070732e84673348cca9df2a600b8450 --- Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/ConfirmingDistributionPropertiesBase.cs (.../ConfirmingDistributionPropertiesBase.cs) (revision f8998df0ea8c1228216bbb00ed9178058af4af67) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/ConfirmingDistributionPropertiesBase.cs (.../ConfirmingDistributionPropertiesBase.cs) (revision 2abaaf908070732e84673348cca9df2a600b8450) @@ -26,7 +26,6 @@ using Core.Common.Gui.Attributes; using Core.Common.Gui.PropertyBag; using Core.Common.Utils.Attributes; -using Core.Common.Utils.Reflection; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.Probabilistics; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; @@ -41,8 +40,8 @@ where TCalculationInput : ICalculationInput where TCalculation : ICalculation { - private readonly string meanPropertyName; - private readonly string standardDeviationPropertyName; + private const string meanPropertyName = nameof(Mean); + private const string standardDeviationPropertyName = nameof(StandardDeviation); private readonly bool isMeanReadOnly; private readonly bool isStandardDeviationReadOnly; private readonly TCalculationInput calculationInput; @@ -60,10 +59,10 @@ /// Thrown when is null /// or when any number of properties in this class is editable and any other parameter is null. protected ConfirmingDistributionPropertiesBase(DistributionPropertiesReadOnly propertiesReadOnly, - TDistribution data, - TCalculation calculation, - TCalculationInput calculationInput, - ICalculationInputPropertyChangeHandler handler) + TDistribution data, + TCalculation calculation, + TCalculationInput calculationInput, + ICalculationInputPropertyChangeHandler handler) { if (data == null) { @@ -86,9 +85,6 @@ } Data = data; - meanPropertyName = TypeUtils.GetMemberName>(dpb => dpb.Mean); - standardDeviationPropertyName = TypeUtils.GetMemberName>(dpb => dpb.StandardDeviation); - isMeanReadOnly = propertiesReadOnly.HasFlag(DistributionPropertiesReadOnly.Mean); isStandardDeviationReadOnly = propertiesReadOnly.HasFlag(DistributionPropertiesReadOnly.StandardDeviation); @@ -115,11 +111,10 @@ { if (isMeanReadOnly) { - throw new ArgumentException("Mean is set to be read-only."); + throw new InvalidOperationException("Mean is set to be read-only."); } - IEnumerable affectedObjects = changeHandler.SetPropertyValueAfterConfirmation(calculationInput, calculation, value, (input, d) => data.Mean = d); - NotifyAffectedObjects(affectedObjects); + ChangePropertyAndNotify((input, newValue) => data.Mean = newValue, value); } } @@ -136,11 +131,10 @@ { if (isStandardDeviationReadOnly) { - throw new ArgumentException("StandardDeviation is set to be read-only."); + throw new InvalidOperationException("StandardDeviation is set to be read-only."); } - IEnumerable affectedObjects = changeHandler.SetPropertyValueAfterConfirmation(calculationInput, calculation, value, (input, d) => data.StandardDeviation = d); - NotifyAffectedObjects(affectedObjects); + ChangePropertyAndNotify((input, newValue) => data.StandardDeviation = newValue, value); } } @@ -158,9 +152,19 @@ return $"{Mean} ({RingtoetsCommonFormsResources.NormalDistribution_StandardDeviation_DisplayName} = {StandardDeviation})"; } + private void ChangePropertyAndNotify(SetCalculationInputPropertyValueDelegate setPropertyValue, + RoundedDouble value) + { + IEnumerable affectedObjects = changeHandler.SetPropertyValueAfterConfirmation(calculationInput, + calculation, + value, + setPropertyValue); + NotifyAffectedObjects(affectedObjects); + } + private static void NotifyAffectedObjects(IEnumerable affectedObjects) { - foreach (var affectedObject in affectedObjects) + foreach (IObservable affectedObject in affectedObjects) { affectedObject.NotifyObservers(); } Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/ConfirmingDistributionPropertiesBaseTest.cs =================================================================== diff -u -rf8998df0ea8c1228216bbb00ed9178058af4af67 -r2abaaf908070732e84673348cca9df2a600b8450 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/ConfirmingDistributionPropertiesBaseTest.cs (.../ConfirmingDistributionPropertiesBaseTest.cs) (revision f8998df0ea8c1228216bbb00ed9178058af4af67) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/ConfirmingDistributionPropertiesBaseTest.cs (.../ConfirmingDistributionPropertiesBaseTest.cs) (revision 2abaaf908070732e84673348cca9df2a600b8450) @@ -261,7 +261,8 @@ // Assert const string expectedMessage = "Mean is set to be read-only."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + string actualMessage = Assert.Throws(test).Message; + Assert.AreEqual(expectedMessage, actualMessage); mocks.VerifyAll(); } @@ -279,7 +280,10 @@ var newMeanValue = new RoundedDouble(3, 20); var handler = new CalculationInputSetPropertyValueAfterConfirmationParameterTester( - input, calculation, newMeanValue, new [] { observerableMock }); + input, calculation, newMeanValue, new[] + { + observerableMock + }); var properties = new SimpleDistributionProperties(DistributionPropertiesReadOnly.None, distribution, calculation, input, handler) { @@ -317,7 +321,8 @@ // Assert const string expectedMessage = "StandardDeviation is set to be read-only."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + string actualMessage = Assert.Throws(test).Message; + Assert.AreEqual(expectedMessage, actualMessage); mocks.VerifyAll(); } @@ -335,7 +340,10 @@ var newStandardDeviationValue = new RoundedDouble(3, 20); var handler = new CalculationInputSetPropertyValueAfterConfirmationParameterTester( - input, calculation, newStandardDeviationValue, new[] { observerableMock }); + input, calculation, newStandardDeviationValue, new[] + { + observerableMock + }); var properties = new SimpleDistributionProperties(DistributionPropertiesReadOnly.None, distribution, calculation, input, handler) { @@ -355,7 +363,9 @@ ICalculationInput, ICalculation> { - public SimpleDistributionProperties(DistributionPropertiesReadOnly propertiesReadOnly, IDistribution distribution, ICalculation calculation, ICalculationInput input, ICalculationInputPropertyChangeHandler handler) + public SimpleDistributionProperties(DistributionPropertiesReadOnly propertiesReadOnly, + IDistribution distribution, ICalculation calculation, + ICalculationInput input, ICalculationInputPropertyChangeHandler handler) : base(propertiesReadOnly, distribution, calculation, input, handler) {} public override string DistributionType Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsInputContextProperties.cs =================================================================== diff -u -r662e55f5b46d01f77a977ab0ea92acbbaddf2365 -r2abaaf908070732e84673348cca9df2a600b8450 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsInputContextProperties.cs (.../GrassCoverErosionInwardsInputContextProperties.cs) (revision 662e55f5b46d01f77a977ab0ea92acbbaddf2365) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsInputContextProperties.cs (.../GrassCoverErosionInwardsInputContextProperties.cs) (revision 2abaaf908070732e84673348cca9df2a600b8450) @@ -70,7 +70,8 @@ /// The instance to show the properties for. /// The handler responsible for handling effects of a property change. /// Thrown when any parameter is null. - public GrassCoverErosionInwardsInputContextProperties(GrassCoverErosionInwardsInputContext data, ICalculationInputPropertyChangeHandler handler) + public GrassCoverErosionInwardsInputContextProperties(GrassCoverErosionInwardsInputContext data, + ICalculationInputPropertyChangeHandler handler) { if (data == null) { @@ -97,7 +98,7 @@ } set { - ChangePropertyValueAndNotifyAffectedObjectsAndNotifyPropertyChanged((input, v) => + ChangePropertyAndNotify((input, v) => { input.DikeProfile = v; GrassCoverErosionInwardsHelper.UpdateCalculationToSectionResultAssignments( @@ -135,8 +136,8 @@ } set { - ChangePropertyValueAndNotifyAffectedObjectsAndNotifyPropertyChanged( - (input, v) => input.Orientation = v, value); + ChangePropertyAndNotify( + (input, newValue) => input.Orientation = newValue, value); } } @@ -201,8 +202,8 @@ } set { - ChangePropertyValueAndNotifyAffectedObjectsAndNotifyPropertyChanged((input, v) => - input.DikeHeight = v, value); + ChangePropertyAndNotify( + (input, newValue) => input.DikeHeight = newValue, value); } } @@ -219,8 +220,8 @@ } set { - ChangePropertyValueAndNotifyAffectedObjectsAndNotifyPropertyChanged((input, v) => - input.DikeHeightCalculationType = v, value); + ChangePropertyAndNotify( + (input, newValue) => input.DikeHeightCalculationType = newValue, value); } } @@ -258,8 +259,9 @@ } set { - ChangePropertyValueAndNotifyAffectedObjectsAndNotifyPropertyChanged((input, v) => - input.HydraulicBoundaryLocation = v, value.HydraulicBoundaryLocation); + ChangePropertyAndNotify( + (input, newValue) => input.HydraulicBoundaryLocation = newValue, + value.HydraulicBoundaryLocation); } } @@ -286,7 +288,7 @@ data.AvailableHydraulicBoundaryLocations, calculationLocation); } - private void ChangePropertyValueAndNotifyAffectedObjectsAndNotifyPropertyChanged( + private void ChangePropertyAndNotify( SetCalculationInputPropertyValueDelegate setPropertyValue, TValue value) {