Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/PropertyClasses/ClosingStructuresInputContextProperties.cs =================================================================== diff -u -r242268fc2adc055cc3ac4f28b14b4db26251b30e -rd4e6fdd1b3c4e1f7f39ce1707cb9ae4241ac6e04 --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/PropertyClasses/ClosingStructuresInputContextProperties.cs (.../ClosingStructuresInputContextProperties.cs) (revision 242268fc2adc055cc3ac4f28b14b4db26251b30e) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/PropertyClasses/ClosingStructuresInputContextProperties.cs (.../ClosingStructuresInputContextProperties.cs) (revision d4e6fdd1b3c4e1f7f39ce1707cb9ae4241ac6e04) @@ -33,7 +33,6 @@ using Ringtoets.ClosingStructures.Forms.Properties; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.Structures; -using Ringtoets.Common.Forms.ChangeHandlers; using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.PropertyClasses; using Ringtoets.Common.Utils; @@ -249,7 +248,7 @@ } [DynamicVisible] - public override NormalDistributionProperties WidthFlowApertures + public override ConfirmingNormalDistributionProperties WidthFlowApertures { get { Index: Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/ConfirmingVariationCoefficientDistributionPropertiesBase.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/ConfirmingVariationCoefficientDistributionPropertiesBase.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/ConfirmingVariationCoefficientDistributionPropertiesBase.cs (revision d4e6fdd1b3c4e1f7f39ce1707cb9ae4241ac6e04) @@ -0,0 +1,178 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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.Collections.Generic; +using Core.Common.Base; +using Core.Common.Base.Data; +using Core.Common.Gui.Attributes; +using Core.Common.Gui.PropertyBag; +using Core.Common.Utils.Attributes; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Probabilistics; +using Ringtoets.Common.Forms.Properties; + +namespace Ringtoets.Common.Forms.PropertyClasses +{ + /// + /// Properties class for implementations of . + /// + public abstract class ConfirmingVariationCoefficientDistributionPropertiesBase : ObjectProperties + where TDistribution : IVariationCoefficientDistribution + where TCalculationInput : ICalculationInput + { + private const string meanPropertyName = nameof(Mean); + private readonly string variationCoefficientPropertyName = nameof(CoefficientOfVariation); + private readonly bool isMeanReadOnly; + private readonly bool isVariationCoefficientReadOnly; + private readonly TCalculationInput calculationInput; + private readonly ICalculation calculation; + private readonly ICalculationInputPropertyChangeHandler changeHandler; + + /// + /// Creates a new instance of . + /// + /// Indicates which properties, if any, should be marked as read-only. + /// The data of the to create the properties for. + /// The calculation the belongs to. + /// The calculation input the belongs to. + /// The handler responsible for handling effects of a property change. + /// Thrown when is null + /// or when any number of properties in this class is editable and any other parameter is null. + protected ConfirmingVariationCoefficientDistributionPropertiesBase(VariationCoefficientDistributionPropertiesReadOnly propertiesReadOnly, + TDistribution data, + ICalculation calculation, + TCalculationInput calculationInput, + ICalculationInputPropertyChangeHandler handler) + { + if (data == null) + { + throw new ArgumentNullException(nameof(data)); + } + if (!propertiesReadOnly.HasFlag(VariationCoefficientDistributionPropertiesReadOnly.All)) + { + if (calculation == null) + { + throw new ArgumentException(@"Calculation required if changes are possible.", nameof(calculation)); + } + if (calculationInput == null) + { + throw new ArgumentException(@"CalculationInput required if changes are possible.", nameof(calculationInput)); + } + if (handler == null) + { + throw new ArgumentException(@"Change handler required if changes are possible.", nameof(handler)); + } + } + Data = data; + + isMeanReadOnly = propertiesReadOnly.HasFlag(VariationCoefficientDistributionPropertiesReadOnly.Mean); + isVariationCoefficientReadOnly = propertiesReadOnly.HasFlag(VariationCoefficientDistributionPropertiesReadOnly.CoefficientOfVariation); + + this.calculationInput = calculationInput; + this.calculation = calculation; + changeHandler = handler; + } + + [PropertyOrder(1)] + [ResourcesDisplayName(typeof(Resources), nameof(Resources.Distribution_DistributionType_DisplayName))] + [ResourcesDescription(typeof(Resources), nameof(Resources.Distribution_DistributionType_Description))] + public abstract string DistributionType { get; } + + [PropertyOrder(2)] + [DynamicReadOnly] + [ResourcesDisplayName(typeof(Resources), nameof(Resources.NormalDistribution_Mean_DisplayName))] + public virtual RoundedDouble Mean + { + get + { + return data.Mean; + } + set + { + if (isMeanReadOnly) + { + throw new InvalidOperationException("Mean is set to be read-only."); + } + + ChangePropertyAndNotify((input, newValue) => data.Mean = newValue, value); + } + } + + [PropertyOrder(3)] + [DynamicReadOnly] + [ResourcesDisplayName(typeof(Resources), nameof(Resources.Distribution_VariationCoefficient_DisplayName))] + public virtual RoundedDouble CoefficientOfVariation + { + get + { + return data.CoefficientOfVariation; + } + set + { + if (isVariationCoefficientReadOnly) + { + throw new InvalidOperationException($"{nameof(CoefficientOfVariation)} is set to be read-only."); + } + + ChangePropertyAndNotify((input, newValue) => data.CoefficientOfVariation = newValue, value); + } + } + + [DynamicReadOnlyValidationMethod] + public bool DynamicReadOnlyValidationMethod(string propertyName) + { + if (propertyName == meanPropertyName) + { + return isMeanReadOnly; + } + if (propertyName == variationCoefficientPropertyName) + { + return isVariationCoefficientReadOnly; + } + return false; + } + + public override string ToString() + { + return data == null ? string.Empty : + $"{Mean} ({Resources.Distribution_VariationCoefficient_DisplayName} = {CoefficientOfVariation})"; + } + + private void ChangePropertyAndNotify(SetCalculationInputPropertyValueDelegate setPropertyValue, + RoundedDouble value) + { + IEnumerable affectedObjects = changeHandler.SetPropertyValueAfterConfirmation(calculationInput, + calculation, + value, + setPropertyValue); + NotifyAffectedObjects(affectedObjects); + } + + private static void NotifyAffectedObjects(IEnumerable affectedObjects) + { + foreach (IObservable affectedObject in affectedObjects) + { + affectedObject.NotifyObservers(); + } + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/ConfirmingVariationCoefficientLogNormalDistributionProperties.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/ConfirmingVariationCoefficientLogNormalDistributionProperties.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/ConfirmingVariationCoefficientLogNormalDistributionProperties.cs (revision d4e6fdd1b3c4e1f7f39ce1707cb9ae4241ac6e04) @@ -0,0 +1,92 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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 Core.Common.Base.Data; +using Core.Common.Gui.PropertyBag; +using Core.Common.Utils.Attributes; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Probabilistics; +using Ringtoets.Common.Forms.Properties; + +namespace Ringtoets.Common.Forms.PropertyClasses +{ + /// + /// An implementation for . + /// + public class ConfirmingVariationCoefficientLogNormalDistributionProperties + : ConfirmingVariationCoefficientDistributionPropertiesBase + where TCalculationInput : ICalculationInput + { + /// + /// Creates a new instance of . + /// + /// Indicates which properties, if any, should be + /// marked as read-only. + /// The to create the properties for. + /// The calculation the belongs to. + /// The calculation input the belongs to. + /// Optional handler that is used to handle property changes. + /// Thrown when is null + /// or when any number of properties in this class is editable and any other parameter is null. + public ConfirmingVariationCoefficientLogNormalDistributionProperties( + VariationCoefficientDistributionPropertiesReadOnly propertiesReadOnly, + VariationCoefficientLogNormalDistribution distribution, + ICalculation calculation, + TCalculationInput calculationInput, + ICalculationInputPropertyChangeHandler handler) + : base(propertiesReadOnly, distribution, calculation, calculationInput, handler) {} + + public override string DistributionType + { + get + { + return Resources.DistributionType_LogNormal; + } + } + + [ResourcesDescription(typeof(Resources), nameof(Resources.LogNormalDistribution_Mean_Description))] + public override RoundedDouble Mean + { + get + { + return base.Mean; + } + set + { + base.Mean = value; + } + } + + [ResourcesDescription(typeof(Resources), nameof(Resources.LogNormalDistribution_VariationCoefficient_Description))] + public override RoundedDouble CoefficientOfVariation + { + get + { + return base.CoefficientOfVariation; + } + set + { + base.CoefficientOfVariation = value; + } + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/StructuresInputBaseProperties.cs =================================================================== diff -u -r242268fc2adc055cc3ac4f28b14b4db26251b30e -rd4e6fdd1b3c4e1f7f39ce1707cb9ae4241ac6e04 --- Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/StructuresInputBaseProperties.cs (.../StructuresInputBaseProperties.cs) (revision 242268fc2adc055cc3ac4f28b14b4db26251b30e) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/StructuresInputBaseProperties.cs (.../StructuresInputBaseProperties.cs) (revision d4e6fdd1b3c4e1f7f39ce1707cb9ae4241ac6e04) @@ -403,14 +403,16 @@ [ResourcesCategory(typeof(Resources), nameof(Resources.Categories_Schematization))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.Structure_FlowWidthAtBottomProtection_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.Structure_FlowWidthAtBottomProtection_Description))] - public LogNormalDistributionProperties FlowWidthAtBottomProtection + public ConfirmingLogNormalDistributionProperties FlowWidthAtBottomProtection { get { - return new LogNormalDistributionProperties(DistributionPropertiesReadOnly.None, data.WrappedData, this) - { - Data = data.WrappedData.FlowWidthAtBottomProtection - }; + return new ConfirmingLogNormalDistributionProperties( + DistributionPropertiesReadOnly.None, + data.WrappedData.FlowWidthAtBottomProtection, + data.Calculation, + data.WrappedData, + propertyChangeHandler); } } @@ -419,17 +421,16 @@ [ResourcesCategory(typeof(Resources), nameof(Resources.Categories_Schematization))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.Structure_WidthFlowApertures_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.Structure_WidthFlowApertures_Description))] - public virtual NormalDistributionProperties WidthFlowApertures + public virtual ConfirmingNormalDistributionProperties WidthFlowApertures { get { - return new NormalDistributionProperties( + return new ConfirmingNormalDistributionProperties( DistributionPropertiesReadOnly.None, + data.WrappedData.WidthFlowApertures, + data.Calculation, data.WrappedData, - this) - { - Data = data.WrappedData.WidthFlowApertures - }; + propertyChangeHandler); } } @@ -438,17 +439,16 @@ [ResourcesCategory(typeof(Resources), nameof(Resources.Categories_Schematization))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.Structure_StorageStructureArea_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.Structure_StorageStructureArea_Description))] - public VariationCoefficientLogNormalDistributionProperties StorageStructureArea + public ConfirmingVariationCoefficientLogNormalDistributionProperties StorageStructureArea { get { - return new VariationCoefficientLogNormalDistributionProperties( + return new ConfirmingVariationCoefficientLogNormalDistributionProperties( VariationCoefficientDistributionPropertiesReadOnly.None, + data.WrappedData.StorageStructureArea, + data.Calculation, data.WrappedData, - this) - { - Data = data.WrappedData.StorageStructureArea - }; + propertyChangeHandler); } } @@ -457,14 +457,16 @@ [ResourcesCategory(typeof(Resources), nameof(Resources.Categories_Schematization))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.Structure_AllowedLevelIncreaseStorage_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.Structure_AllowedLevelIncreaseStorage_Description))] - public LogNormalDistributionProperties AllowedLevelIncreaseStorage + public ConfirmingLogNormalDistributionProperties AllowedLevelIncreaseStorage { get { - return new LogNormalDistributionProperties(DistributionPropertiesReadOnly.None, data.WrappedData, this) - { - Data = data.WrappedData.AllowedLevelIncreaseStorage - }; + return new ConfirmingLogNormalDistributionProperties( + DistributionPropertiesReadOnly.None, + data.WrappedData.AllowedLevelIncreaseStorage, + data.Calculation, + data.WrappedData, + propertyChangeHandler); } } @@ -473,17 +475,16 @@ [ResourcesCategory(typeof(Resources), nameof(Resources.Categories_Schematization))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.Structure_CriticalOvertoppingDischarge_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.Structure_CriticalOvertoppingDischarge_Description))] - public VariationCoefficientLogNormalDistributionProperties CriticalOvertoppingDischarge + public ConfirmingVariationCoefficientLogNormalDistributionProperties CriticalOvertoppingDischarge { get { - return new VariationCoefficientLogNormalDistributionProperties( + return new ConfirmingVariationCoefficientLogNormalDistributionProperties( VariationCoefficientDistributionPropertiesReadOnly.None, + data.WrappedData.CriticalOvertoppingDischarge, + data.Calculation, data.WrappedData, - this) - { - Data = data.WrappedData.CriticalOvertoppingDischarge - }; + propertyChangeHandler); } } @@ -585,17 +586,16 @@ [ResourcesCategory(typeof(Resources), nameof(Resources.Categories_HydraulicData))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.Structure_StormDuration_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.Structure_StormDuration_Description))] - public VariationCoefficientLogNormalDistributionProperties StormDuration + public ConfirmingVariationCoefficientLogNormalDistributionProperties StormDuration { get { - return new VariationCoefficientLogNormalDistributionProperties( + return new ConfirmingVariationCoefficientLogNormalDistributionProperties( VariationCoefficientDistributionPropertiesReadOnly.CoefficientOfVariation, + data.WrappedData.StormDuration, + data.Calculation, data.WrappedData, - this) - { - Data = data.WrappedData.StormDuration - }; + propertyChangeHandler); } } Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj =================================================================== diff -u -r242268fc2adc055cc3ac4f28b14b4db26251b30e -rd4e6fdd1b3c4e1f7f39ce1707cb9ae4241ac6e04 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision 242268fc2adc055cc3ac4f28b14b4db26251b30e) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision d4e6fdd1b3c4e1f7f39ce1707cb9ae4241ac6e04) @@ -75,6 +75,7 @@ True Resources.resx + @@ -94,6 +95,7 @@ + Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/ConfirmingDistributionPropertiesBaseTest.cs =================================================================== diff -u -r242268fc2adc055cc3ac4f28b14b4db26251b30e -rd4e6fdd1b3c4e1f7f39ce1707cb9ae4241ac6e04 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/ConfirmingDistributionPropertiesBaseTest.cs (.../ConfirmingDistributionPropertiesBaseTest.cs) (revision 242268fc2adc055cc3ac4f28b14b4db26251b30e) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/ConfirmingDistributionPropertiesBaseTest.cs (.../ConfirmingDistributionPropertiesBaseTest.cs) (revision d4e6fdd1b3c4e1f7f39ce1707cb9ae4241ac6e04) @@ -226,16 +226,16 @@ var handler = mocks.Stub(); mocks.ReplayAll(); + // Call var properties = new SimpleDistributionProperties(DistributionPropertiesReadOnly.None, distribution, calculation, input, handler); - // Call - properties.Data = distribution; - // Assert Assert.AreEqual(distribution.Mean, properties.Mean); Assert.AreEqual(distribution.StandardDeviation, properties.StandardDeviation); string expectedToString = string.Format("{0} ({1} = {2})", - distribution.Mean, Resources.NormalDistribution_StandardDeviation_DisplayName, distribution.StandardDeviation); + distribution.Mean, + Resources.NormalDistribution_StandardDeviation_DisplayName, + distribution.StandardDeviation); Assert.AreEqual(expectedToString, properties.ToString()); mocks.VerifyAll(); } @@ -251,10 +251,12 @@ var handler = mocks.Stub(); mocks.ReplayAll(); - var properties = new SimpleDistributionProperties(DistributionPropertiesReadOnly.All, distribution, calculation, input, handler) - { - Data = distribution - }; + var properties = new SimpleDistributionProperties( + DistributionPropertiesReadOnly.All, + distribution, + calculation, + input, + handler); // Call TestDelegate test = () => properties.Mean = new RoundedDouble(2, 20); @@ -285,10 +287,12 @@ observerableMock }); - var properties = new SimpleDistributionProperties(DistributionPropertiesReadOnly.None, distribution, calculation, input, handler) - { - Data = distribution - }; + var properties = new SimpleDistributionProperties( + DistributionPropertiesReadOnly.None, + distribution, + calculation, + input, + handler); // Call properties.Mean = newMeanValue; @@ -311,10 +315,12 @@ var handler = mocks.Stub(); mocks.ReplayAll(); - var properties = new SimpleDistributionProperties(propertiesReadOnly, distribution, calculation, input, handler) - { - Data = distribution - }; + var properties = new SimpleDistributionProperties( + propertiesReadOnly, + distribution, + calculation, + input, + handler); // Call TestDelegate test = () => properties.StandardDeviation = new RoundedDouble(2, 20); @@ -345,10 +351,12 @@ observerableMock }); - var properties = new SimpleDistributionProperties(DistributionPropertiesReadOnly.None, distribution, calculation, input, handler) - { - Data = distribution - }; + var properties = new SimpleDistributionProperties( + DistributionPropertiesReadOnly.None, + distribution, + calculation, + input, + handler); // Call properties.StandardDeviation = newStandardDeviationValue; Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/ConfirmingVariationCoefficientDistributionPropertiesBaseTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/ConfirmingVariationCoefficientDistributionPropertiesBaseTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/ConfirmingVariationCoefficientDistributionPropertiesBaseTest.cs (revision d4e6fdd1b3c4e1f7f39ce1707cb9ae4241ac6e04) @@ -0,0 +1,380 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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 NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Probabilistics; +using Ringtoets.Common.Forms.Properties; +using Ringtoets.Common.Forms.PropertyClasses; +using Ringtoets.Common.Forms.TestUtil; + +namespace Ringtoets.Common.Forms.Test.PropertyClasses +{ + [TestFixture] + public class ConfirmingVariationCoefficientDistributionPropertiesBaseTest + { + [Test] + public void Constructor_ReadOnlyWithData_ExpectedValues() + { + // Setup + var mocks = new MockRepository(); + var distribution = mocks.Stub(); + mocks.ReplayAll(); + + // Call + var properties = new SimpleDistributionProperties(VariationCoefficientDistributionPropertiesReadOnly.All, distribution, null, null, null); + + // Assert + Assert.IsInstanceOf>(properties); + Assert.AreSame(distribution, properties.Data); + mocks.VerifyAll(); + } + + [Test] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.Mean)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.CoefficientOfVariation)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.None)] + public void Constructor_NoDistributionSetWhileChangesPossible_ThrowArgumentException( + VariationCoefficientDistributionPropertiesReadOnly flags) + { + // Call + TestDelegate call = () => new SimpleDistributionProperties(flags, null, null, null, null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("data", paramName); + } + + [Test] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.Mean)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.CoefficientOfVariation)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.None)] + public void Constructor_NoCalculationSetWhileChangesPossible_ThrowArgumentException( + VariationCoefficientDistributionPropertiesReadOnly flags) + { + // Setup + var mocks = new MockRepository(); + var distribution = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => new SimpleDistributionProperties(flags, distribution, null, null, null); + + // Assert + var message = "Calculation required if changes are possible."; + var exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, message); + Assert.AreEqual("calculation", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.Mean)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.CoefficientOfVariation)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.None)] + public void Constructor_NoInputSetWhileChangesPossible_ThrowArgumentException( + VariationCoefficientDistributionPropertiesReadOnly flags) + { + // Setup + var mocks = new MockRepository(); + var distribution = mocks.Stub(); + var calculation = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => new SimpleDistributionProperties(flags, distribution, calculation, null, null); + + // Assert + var message = "CalculationInput required if changes are possible."; + var exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, message); + Assert.AreEqual("calculationInput", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.Mean)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.CoefficientOfVariation)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.None)] + public void Constructor_NoHandlerSetWhileChangesPossible_ThrowArgumentException( + VariationCoefficientDistributionPropertiesReadOnly flags) + { + // Setup + var mocks = new MockRepository(); + var distribution = mocks.Stub(); + var calculation = mocks.Stub(); + var input = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => new SimpleDistributionProperties(flags, distribution, calculation, input, null); + + // Assert + var message = "Change handler required if changes are possible."; + var exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, message); + Assert.AreEqual("handler", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.All, true, true)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.Mean, true, false)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.None, false, false)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.CoefficientOfVariation, false, true)] + public void Constructor_Always_PropertiesHaveExpectedAttributesValues(VariationCoefficientDistributionPropertiesReadOnly propertiesReadOnly, bool expectMeanReadOnly, bool expectCoefficientOfVariationReadOnly) + { + // Setup + var mocks = new MockRepository(); + var distribution = mocks.Stub(); + var calculation = mocks.Stub(); + var input = mocks.Stub(); + var handler = mocks.Stub(); + mocks.ReplayAll(); + + // Call + var properties = new SimpleDistributionProperties(propertiesReadOnly, distribution, calculation, input, handler); + + // Assert + PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); + Assert.AreEqual(3, dynamicProperties.Count); + + PropertyDescriptor distributionTypeProperty = dynamicProperties[0]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(distributionTypeProperty, + "Misc", + "Type verdeling", + "Het soort kansverdeling waarin deze parameter gedefinieerd wordt.", + true); + + PropertyDescriptor meanProperty = dynamicProperties[1]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(meanProperty, + "Misc", + "Verwachtingswaarde", + "", + expectMeanReadOnly); + + PropertyDescriptor coefficientOfVariationProperty = dynamicProperties[2]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(coefficientOfVariationProperty, + "Misc", + "Variatiecoëfficiënt", + "", + expectCoefficientOfVariationReadOnly); + mocks.VerifyAll(); + } + + [Test] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.All, true, true)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.Mean, true, false)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.None, false, false)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.CoefficientOfVariation, false, true)] + public void DynamicReadOnlyValidationMethod_VariousReadOnlySet_ExpectedValues(VariationCoefficientDistributionPropertiesReadOnly propertiesReadOnly, bool expectMeanReadOnly, bool expectCoefficientOfVariationReadOnly) + { + // Setup + var mocks = new MockRepository(); + var distribution = mocks.Stub(); + var calculation = mocks.Stub(); + var input = mocks.Stub(); + var handler = mocks.Stub(); + mocks.ReplayAll(); + + var properties = new SimpleDistributionProperties(propertiesReadOnly, distribution, calculation, input, handler); + + // Call + bool meanIsReadOnly = properties.DynamicReadOnlyValidationMethod("Mean"); + bool coefficientOfVariationIsReadOnly = properties.DynamicReadOnlyValidationMethod("CoefficientOfVariation"); + bool doesNotExist = properties.DynamicReadOnlyValidationMethod("DoesNotExist"); + + // Assert + Assert.AreEqual(expectCoefficientOfVariationReadOnly, coefficientOfVariationIsReadOnly); + Assert.AreEqual(expectMeanReadOnly, meanIsReadOnly); + Assert.IsFalse(doesNotExist); + mocks.VerifyAll(); + } + + [Test] + public void Data_SetNewDistributionContextInstance_ReturnCorrectPropertyValues() + { + // Setup + var mocks = new MockRepository(); + var distribution = mocks.Stub(); + distribution.Mean = new RoundedDouble(1, 1.1); + distribution.CoefficientOfVariation = new RoundedDouble(2, 2.2); + + var calculation = mocks.Stub(); + var input = mocks.Stub(); + var handler = mocks.Stub(); + mocks.ReplayAll(); + + var properties = new SimpleDistributionProperties(VariationCoefficientDistributionPropertiesReadOnly.None, distribution, calculation, input, handler); + + // Call + properties.Data = distribution; + + // Assert + Assert.AreEqual(distribution.Mean, properties.Mean); + Assert.AreEqual(distribution.CoefficientOfVariation, properties.CoefficientOfVariation); + string expectedToString = string.Format("{0} ({1} = {2})", + distribution.Mean, + Resources.Distribution_VariationCoefficient_DisplayName, + distribution.CoefficientOfVariation); + Assert.AreEqual(expectedToString, properties.ToString()); + mocks.VerifyAll(); + } + + [Test] + public void Mean_ReadOnlyWithObserverable_ThrowsArgumentException() + { + // Setup + var mocks = new MockRepository(); + var distribution = mocks.Stub(); + var calculation = mocks.Stub(); + var input = mocks.Stub(); + var handler = mocks.Stub(); + mocks.ReplayAll(); + + var properties = new SimpleDistributionProperties( + VariationCoefficientDistributionPropertiesReadOnly.All, + distribution, + calculation, + input, + handler); + + // Call + TestDelegate test = () => properties.Mean = new RoundedDouble(2, 20); + + // Assert + const string expectedMessage = "Mean is set to be read-only."; + string actualMessage = Assert.Throws(test).Message; + Assert.AreEqual(expectedMessage, actualMessage); + mocks.VerifyAll(); + } + + [Test] + public void Mean_WithObserverable_ValueSetNotifyObservers() + { + // Setup + var mocks = new MockRepository(); + var distribution = mocks.Stub(); + var calculation = mocks.Stub(); + var input = mocks.Stub(); + var observerableMock = mocks.StrictMock(); + observerableMock.Expect(o => o.NotifyObservers()); + mocks.ReplayAll(); + + var newMeanValue = new RoundedDouble(3, 20); + var handler = new CalculationInputSetPropertyValueAfterConfirmationParameterTester( + input, calculation, newMeanValue, new[] + { + observerableMock + }); + + var properties = new SimpleDistributionProperties( + VariationCoefficientDistributionPropertiesReadOnly.None, + distribution, + calculation, + input, + handler); + + // Call + properties.Mean = newMeanValue; + + // Assert + Assert.AreEqual(newMeanValue, properties.Mean); + mocks.VerifyAll(); + } + + [Test] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.All)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.CoefficientOfVariation)] + public void CoefficientOfVariation_ReadOnlyWithoutObserverable_ThrowsArgumentException(VariationCoefficientDistributionPropertiesReadOnly propertiesReadOnly) + { + // Setup + var mocks = new MockRepository(); + var distribution = mocks.Stub(); + var calculation = mocks.Stub(); + var input = mocks.Stub(); + var handler = mocks.Stub(); + mocks.ReplayAll(); + + var properties = new SimpleDistributionProperties(propertiesReadOnly, distribution, calculation, input, handler); + + // Call + TestDelegate test = () => properties.CoefficientOfVariation = new RoundedDouble(2, 20); + + // Assert + const string expectedMessage = "CoefficientOfVariation is set to be read-only."; + string actualMessage = Assert.Throws(test).Message; + Assert.AreEqual(expectedMessage, actualMessage); + mocks.VerifyAll(); + } + + [Test] + public void CoefficientOfVariation_WithObserverable_ValueSetNotifyObservers() + { + // Setup + var mocks = new MockRepository(); + var distribution = mocks.Stub(); + var calculation = mocks.Stub(); + var input = mocks.Stub(); + var observerableMock = mocks.StrictMock(); + observerableMock.Expect(o => o.NotifyObservers()); + mocks.ReplayAll(); + + var newCoefficientOfVariation = new RoundedDouble(3, 20); + var handler = new CalculationInputSetPropertyValueAfterConfirmationParameterTester( + input, calculation, newCoefficientOfVariation, new[] + { + observerableMock + }); + + var properties = new SimpleDistributionProperties(VariationCoefficientDistributionPropertiesReadOnly.None, distribution, calculation, input, handler) + { + Data = distribution + }; + + // Call + properties.CoefficientOfVariation = newCoefficientOfVariation; + + // Assert + Assert.AreEqual(newCoefficientOfVariation, properties.CoefficientOfVariation); + mocks.VerifyAll(); + } + + private class SimpleDistributionProperties : ConfirmingVariationCoefficientDistributionPropertiesBase + { + public SimpleDistributionProperties(VariationCoefficientDistributionPropertiesReadOnly propertiesReadOnly, + IVariationCoefficientDistribution distribution, ICalculation calculation, + ICalculationInput input, ICalculationInputPropertyChangeHandler handler) + : base(propertiesReadOnly, distribution, calculation, input, handler) {} + + public override string DistributionType + { + get + { + return "SimpleDestributionType"; + } + } + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/ConfirmingVariationCoefficientLogNormalDistributionPropertiesTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/ConfirmingVariationCoefficientLogNormalDistributionPropertiesTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/ConfirmingVariationCoefficientLogNormalDistributionPropertiesTest.cs (revision d4e6fdd1b3c4e1f7f39ce1707cb9ae4241ac6e04) @@ -0,0 +1,89 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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.ComponentModel; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Probabilistics; +using Ringtoets.Common.Forms.PropertyClasses; + +namespace Ringtoets.Common.Forms.Test.PropertyClasses +{ + [TestFixture] + public class ConfirmingVariationCoefficientLogNormalDistributionPropertiesTest + { + private MockRepository mockRepository; + + [SetUp] + public void SetUp() + { + mockRepository = new MockRepository(); + } + + [Test] + public void Constructor_WithParameters_ExpectedValues() + { + // Setup + var mocks = new MockRepository(); + var calculation = mocks.Stub(); + var input = mocks.Stub(); + var handler = mocks.Stub(); + mockRepository.ReplayAll(); + + var distribution = new VariationCoefficientLogNormalDistribution(); + + // Call + var properties = new ConfirmingVariationCoefficientLogNormalDistributionProperties( + VariationCoefficientDistributionPropertiesReadOnly.None, distribution, calculation, input, handler); + + // Assert + Assert.IsInstanceOf>(properties); + Assert.AreSame(distribution, properties.Data); + Assert.AreEqual("Lognormaal", properties.DistributionType); + + PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); + Assert.AreEqual(3, dynamicProperties.Count); + + PropertyDescriptor distributionTypeProperty = dynamicProperties[0]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(distributionTypeProperty, + "Misc", + "Type verdeling", + "Het soort kansverdeling waarin deze parameter gedefinieerd wordt.", + true); + + PropertyDescriptor meanProperty = dynamicProperties[1]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(meanProperty, + "Misc", + "Verwachtingswaarde", + "De gemiddelde waarde van de lognormale verdeling."); + + PropertyDescriptor standardDeviationProperty = dynamicProperties[2]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(standardDeviationProperty, + "Misc", + "Variatiecoëfficiënt", + "De variatiecoëfficiënt van de lognormale verdeling."); + + mockRepository.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/StructuresInputBasePropertiesTest.cs =================================================================== diff -u -r242268fc2adc055cc3ac4f28b14b4db26251b30e -rd4e6fdd1b3c4e1f7f39ce1707cb9ae4241ac6e04 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/StructuresInputBasePropertiesTest.cs (.../StructuresInputBasePropertiesTest.cs) (revision 242268fc2adc055cc3ac4f28b14b4db26251b30e) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/StructuresInputBasePropertiesTest.cs (.../StructuresInputBasePropertiesTest.cs) (revision d4e6fdd1b3c4e1f7f39ce1707cb9ae4241ac6e04) @@ -710,13 +710,67 @@ [Test] public void ModelFactorSuperCriticalFlow_MeanChanged_InputChangedAndObsevablesNotified() { - RoundedDouble modelFactorSuperCriticalFlowMean = new Random(21).NextRoundedDouble(); + RoundedDouble newMean = new Random(21).NextRoundedDouble(); SetPropertyAndVerifyNotifcationsAndOutput( - properties => properties.ModelFactorSuperCriticalFlow.Mean = modelFactorSuperCriticalFlowMean, - modelFactorSuperCriticalFlowMean); + properties => properties.ModelFactorSuperCriticalFlow.Mean = newMean, + newMean); } [Test] + public void FlowWidthAtBottomProtection_MeanChanged_InputChangedAndObsevablesNotified() + { + RoundedDouble newMean = new Random(21).NextRoundedDouble(); + SetPropertyAndVerifyNotifcationsAndOutput( + properties => properties.FlowWidthAtBottomProtection.Mean = newMean, + newMean); + } + + [Test] + public void WidthFlowApertures_MeanChanged_InputChangedAndObsevablesNotified() + { + RoundedDouble newMean = new Random(21).NextRoundedDouble(); + SetPropertyAndVerifyNotifcationsAndOutput( + properties => properties.WidthFlowApertures.Mean = newMean, + newMean); + } + + [Test] + public void StorageStructureArea_MeanChanged_InputChangedAndObsevablesNotified() + { + RoundedDouble newMean = new Random(21).NextRoundedDouble(); + SetPropertyAndVerifyNotifcationsAndOutput( + properties => properties.StorageStructureArea.Mean = newMean, + newMean); + } + + [Test] + public void AllowedLevelIncreaseStorage_MeanChanged_InputChangedAndObsevablesNotified() + { + RoundedDouble newMean = new Random(21).NextRoundedDouble(); + SetPropertyAndVerifyNotifcationsAndOutput( + properties => properties.AllowedLevelIncreaseStorage.Mean = newMean, + newMean); + } + + [Test] + public void CriticalOvertoppingDischarge_MeanChanged_InputChangedAndObsevablesNotified() + { + RoundedDouble newMean = new Random(21).NextRoundedDouble(); + SetPropertyAndVerifyNotifcationsAndOutput( + properties => properties.CriticalOvertoppingDischarge.Mean = newMean, + newMean); + } + + [Test] + public void StormDuration_MeanChanged_InputChangedAndObsevablesNotified() + { + RoundedDouble newMean = new Random(21).NextRoundedDouble(); + SetPropertyAndVerifyNotifcationsAndOutput( + properties => properties.StormDuration.Mean = newMean, + newMean); + } + + [Test] public void Structure_NullValue_AfterSettingStructureCalled() { // Setup Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj =================================================================== diff -u -r242268fc2adc055cc3ac4f28b14b4db26251b30e -rd4e6fdd1b3c4e1f7f39ce1707cb9ae4241ac6e04 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision 242268fc2adc055cc3ac4f28b14b4db26251b30e) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision d4e6fdd1b3c4e1f7f39ce1707cb9ae4241ac6e04) @@ -81,7 +81,9 @@ + + Index: Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Forms/PropertyClasses/StabilityPointStructuresInputContextProperties.cs =================================================================== diff -u -r242268fc2adc055cc3ac4f28b14b4db26251b30e -rd4e6fdd1b3c4e1f7f39ce1707cb9ae4241ac6e04 --- Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Forms/PropertyClasses/StabilityPointStructuresInputContextProperties.cs (.../StabilityPointStructuresInputContextProperties.cs) (revision 242268fc2adc055cc3ac4f28b14b4db26251b30e) +++ Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Forms/PropertyClasses/StabilityPointStructuresInputContextProperties.cs (.../StabilityPointStructuresInputContextProperties.cs) (revision d4e6fdd1b3c4e1f7f39ce1707cb9ae4241ac6e04) @@ -285,7 +285,7 @@ #region Schematization [DynamicVisible] - public override NormalDistributionProperties WidthFlowApertures + public override ConfirmingNormalDistributionProperties WidthFlowApertures { get {