Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/PropertyClasses/ClosingStructuresInputContextProperties.cs =================================================================== diff -u -rf88343c0590cb04c7135ce141872940e59325927 -r5cb5707e72014afb2b2bc5a015bf3bd507242318 --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/PropertyClasses/ClosingStructuresInputContextProperties.cs (.../ClosingStructuresInputContextProperties.cs) (revision f88343c0590cb04c7135ce141872940e59325927) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/PropertyClasses/ClosingStructuresInputContextProperties.cs (.../ClosingStructuresInputContextProperties.cs) (revision 5cb5707e72014afb2b2bc5a015bf3bd507242318) @@ -33,8 +33,8 @@ 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.Forms.TypeConverters; using Ringtoets.Common.Utils; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; @@ -325,41 +325,37 @@ [DynamicReadOnly] [PropertyOrder(failureProbabilityOpenStructurePropertyIndex)] + [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_Schematization))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.FailureProbabilityOpenStructure_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.FailureProbabilityOpenStructure_Description))] - public string FailureProbabilityOpenStructure + public double FailureProbabilityOpenStructure { get { - return ProbabilityFormattingHelper.Format(data.WrappedData.FailureProbabilityOpenStructure); + return data.WrappedData.FailureProbabilityOpenStructure; } set { - PropertyChangeHelper.ChangePropertyAndNotify(() => SetProbabilityValue( - value, - data.WrappedData, - (wrappedData, parsedValue) => wrappedData.FailureProbabilityOpenStructure = parsedValue), PropertyChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => data.WrappedData.FailureProbabilityOpenStructure = value, PropertyChangeHandler); } } [DynamicReadOnly] [PropertyOrder(failureProbabilityReparationPropertyIndex)] + [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_Schematization))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.FailureProbabilityReparation_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.FailureProbabilityReparation_Description))] - public string FailureProbabilityReparation + public double FailureProbabilityReparation { get { - return ProbabilityFormattingHelper.Format(data.WrappedData.FailureProbabilityReparation); + return data.WrappedData.FailureProbabilityReparation; } set { - PropertyChangeHelper.ChangePropertyAndNotify(() => SetProbabilityValue( - value, - data.WrappedData, - (wrappedData, parsedValue) => wrappedData.FailureProbabilityReparation = parsedValue), PropertyChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => data.WrappedData.FailureProbabilityReparation = value, PropertyChangeHandler); } } @@ -401,21 +397,19 @@ [DynamicReadOnly] [PropertyOrder(probabilityOrFrequencyOpenStructureBeforeFloodingPropertyIndex)] + [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_Schematization))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.ProbabilityOrFrequencyOpenStructureBeforeFlooding_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.ProbabilityOrFrequencyOpenStructureBeforeFlooding_Description))] - public string ProbabilityOrFrequencyOpenStructureBeforeFlooding + public double ProbabilityOrFrequencyOpenStructureBeforeFlooding { get { - return ProbabilityFormattingHelper.Format(data.WrappedData.ProbabilityOrFrequencyOpenStructureBeforeFlooding); + return data.WrappedData.ProbabilityOrFrequencyOpenStructureBeforeFlooding; } set { - PropertyChangeHelper.ChangePropertyAndNotify(() => SetProbabilityValue( - value, - data.WrappedData, - (wrappedData, parsedValue) => wrappedData.ProbabilityOrFrequencyOpenStructureBeforeFlooding = parsedValue), PropertyChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => data.WrappedData.ProbabilityOrFrequencyOpenStructureBeforeFlooding = value, PropertyChangeHandler); } } Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/PropertyClasses/ClosingStructuresInputContextPropertiesTest.cs =================================================================== diff -u -rd491788b870f9a9d2e08c93b52777f613809a133 -r5cb5707e72014afb2b2bc5a015bf3bd507242318 --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/PropertyClasses/ClosingStructuresInputContextPropertiesTest.cs (.../ClosingStructuresInputContextPropertiesTest.cs) (revision d491788b870f9a9d2e08c93b52777f613809a133) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/PropertyClasses/ClosingStructuresInputContextPropertiesTest.cs (.../ClosingStructuresInputContextPropertiesTest.cs) (revision 5cb5707e72014afb2b2bc5a015bf3bd507242318) @@ -22,7 +22,6 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.Globalization; using System.Linq; using Core.Common.Base; using Core.Common.Base.Data; @@ -39,7 +38,6 @@ using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Data.TestUtil; -using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.PropertyClasses; using Ringtoets.Common.Forms.TestUtil; @@ -131,9 +129,6 @@ Assert.AreSame(inputContext, properties.Data); ClosingStructuresInput input = calculation.InputParameters; - string expectedProbabilityOrFrequencyOpenStructureBeforeFlooding = ProbabilityFormattingHelper.Format(input.ProbabilityOrFrequencyOpenStructureBeforeFlooding); - string expectedFailureProbabilityOpenStructure = ProbabilityFormattingHelper.Format(input.FailureProbabilityOpenStructure); - string expectedFailureProbabilityReparation = ProbabilityFormattingHelper.Format(input.FailureProbabilityReparation); Assert.AreSame(input.ModelFactorSuperCriticalFlow, properties.ModelFactorSuperCriticalFlow.Data); Assert.AreEqual(input.StructureNormalOrientation, properties.StructureNormalOrientation); @@ -143,9 +138,9 @@ Assert.AreEqual(input.IdenticalApertures, properties.IdenticalApertures); Assert.AreSame(input.LevelCrestStructureNotClosing, properties.LevelCrestStructureNotClosing.Data); Assert.AreSame(input.ThresholdHeightOpenWeir, properties.ThresholdHeightOpenWeir.Data); - Assert.AreEqual(expectedProbabilityOrFrequencyOpenStructureBeforeFlooding, properties.ProbabilityOrFrequencyOpenStructureBeforeFlooding); - Assert.AreEqual(expectedFailureProbabilityOpenStructure, properties.FailureProbabilityOpenStructure); - Assert.AreEqual(expectedFailureProbabilityReparation, properties.FailureProbabilityReparation); + Assert.AreEqual(input.ProbabilityOrFrequencyOpenStructureBeforeFlooding, properties.ProbabilityOrFrequencyOpenStructureBeforeFlooding); + Assert.AreEqual(input.FailureProbabilityOpenStructure, properties.FailureProbabilityOpenStructure); + Assert.AreEqual(input.FailureProbabilityReparation, properties.FailureProbabilityReparation); Assert.AreSame(input.DrainCoefficient, properties.DrainCoefficient.Data); Assert.AreEqual(input.FactorStormDurationOpenStructure, properties.FactorStormDurationOpenStructure); @@ -582,36 +577,27 @@ } [Test] - [SetCulture("nl-NL")] - [TestCase("0,1")] - [TestCase("1/100")] - [TestCase("1e-2")] - public void ProbabilityOrFrequencyOpenStructureBeforeFlooding_Always_InputChangedAndObservablesNotified(string probability) + public void ProbabilityOrFrequencyOpenStructureBeforeFlooding_Always_InputChangedAndObservablesNotified() { + var random = new Random(21); SetPropertyAndVerifyNotifcationsAndOutput( - properties => properties.ProbabilityOrFrequencyOpenStructureBeforeFlooding = probability); + properties => properties.ProbabilityOrFrequencyOpenStructureBeforeFlooding = random.NextDouble()); } [Test] - [SetCulture("nl-NL")] - [TestCase("0,1")] - [TestCase("1/100")] - [TestCase("1e-2")] - public void FailureProbabilityOpenStructure_Always_InputChangedAndObservablesNotified(string probability) + public void FailureProbabilityOpenStructure_Always_InputChangedAndObservablesNotified() { + var random = new Random(21); SetPropertyAndVerifyNotifcationsAndOutput( - properties => properties.FailureProbabilityOpenStructure = probability); + properties => properties.FailureProbabilityOpenStructure = random.NextDouble()); } [Test] - [SetCulture("nl-NL")] - [TestCase("0,1")] - [TestCase("1/100")] - [TestCase("1e-2")] - public void FailureProbabilityReparation_Always_InputChangedAndObservablesNotified(string probability) + public void FailureProbabilityReparation_Always_InputChangedAndObservablesNotified() { + var random = new Random(21); SetPropertyAndVerifyNotifcationsAndOutput( - properties => properties.FailureProbabilityReparation = probability); + properties => properties.FailureProbabilityReparation = random.NextDouble()); } [Test] @@ -679,304 +665,6 @@ } [Test] - [TestCase(double.MinValue)] - [TestCase(double.MaxValue)] - public void ProbabilityOrFrequencyOpenStructureBeforeFlooding_InvalidDoubleValues_ThrowsArgumentException(double newValue) - { - // Setup - mockRepository.ReplayAll(); - - var failureMechanism = new ClosingStructuresFailureMechanism(); - var calculation = new StructuresCalculation(); - ClosingStructuresInput input = calculation.InputParameters; - var inputContext = new ClosingStructuresInputContext(input, - calculation, - failureMechanism, - assessmentSection); - - const int overflow = 1; - string newProbabilityString = string.Concat(newValue.ToString("r", CultureInfo.CurrentCulture), overflow); - - var handler = new SetPropertyValueAfterConfirmationParameterTester(Enumerable.Empty()); - var properties = new ClosingStructuresInputContextProperties(inputContext, handler); - - // Call - TestDelegate call = () => properties.ProbabilityOrFrequencyOpenStructureBeforeFlooding = newProbabilityString; - - // Assert - const string expectedMessage = "De waarde is te groot of te klein."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); - - mockRepository.VerifyAll(); - } - - [Test] - [SetCulture("nl-NL")] - [TestCase(double.MinValue)] - [TestCase(double.MaxValue)] - public void ProbabilityOrFrequencyOpenStructureBeforeFlooding_InvalidValues_ThrowsArgumentOutOfRangeException(double newValue) - { - // Setup - mockRepository.ReplayAll(); - - var failureMechanism = new ClosingStructuresFailureMechanism(); - var calculation = new StructuresCalculation(); - ClosingStructuresInput input = calculation.InputParameters; - var inputContext = new ClosingStructuresInputContext(input, - calculation, - failureMechanism, - assessmentSection); - - string newProbabilityString = newValue.ToString("r", CultureInfo.CurrentCulture); - var handler = new SetPropertyValueAfterConfirmationParameterTester(Enumerable.Empty()); - var properties = new ClosingStructuresInputContextProperties(inputContext, handler); - - // Call - TestDelegate call = () => properties.ProbabilityOrFrequencyOpenStructureBeforeFlooding = newProbabilityString; - - // Assert - const string expectedMessage = "De waarde voor de faalkans moet in het bereik [0,0, 1,0] liggen."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); - - mockRepository.VerifyAll(); - } - - [Test] - [TestCase("no double value")] - [TestCase("")] - [TestCase("1/aaa")] - public void ProbabilityOrFrequencyOpenStructureBeforeFlooding_ValuesUnableToParse_ThrowsArgumentException(string newValue) - { - // Setup - mockRepository.ReplayAll(); - - var failureMechanism = new ClosingStructuresFailureMechanism(); - var calculation = new StructuresCalculation(); - ClosingStructuresInput input = calculation.InputParameters; - var inputContext = new ClosingStructuresInputContext(input, - calculation, - failureMechanism, - assessmentSection); - - var handler = new SetPropertyValueAfterConfirmationParameterTester(Enumerable.Empty()); - var properties = new ClosingStructuresInputContextProperties(inputContext, handler); - - // Call - TestDelegate call = () => properties.ProbabilityOrFrequencyOpenStructureBeforeFlooding = newValue; - - // Assert - const string expectedMessage = "De waarde kon niet geïnterpreteerd worden als een kans."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); - - mockRepository.VerifyAll(); - } - - [Test] - public void ProbabilityOrFrequencyOpenStructureBeforeFlooding_NullValue_ThrowsArgumentNullException() - { - // Setup - mockRepository.ReplayAll(); - - var failureMechanism = new ClosingStructuresFailureMechanism(); - var calculation = new StructuresCalculation(); - ClosingStructuresInput input = calculation.InputParameters; - var inputContext = new ClosingStructuresInputContext(input, - calculation, - failureMechanism, - assessmentSection); - - var handler = new SetPropertyValueAfterConfirmationParameterTester(Enumerable.Empty()); - var properties = new ClosingStructuresInputContextProperties(inputContext, handler); - - // Call - TestDelegate call = () => properties.ProbabilityOrFrequencyOpenStructureBeforeFlooding = null; - - // Assert - const string expectedMessage = "De waarde voor de faalkans moet ingevuld zijn."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); - - mockRepository.VerifyAll(); - } - - [Test] - [TestCase(double.MinValue)] - [TestCase(double.MaxValue)] - public void FailureProbabilityOpenStructure_InvalidValues_ThrowsArgumentException(double newValue) - { - // Setup - mockRepository.ReplayAll(); - - var failureMechanism = new ClosingStructuresFailureMechanism(); - var calculation = new StructuresCalculation(); - ClosingStructuresInput input = calculation.InputParameters; - var inputContext = new ClosingStructuresInputContext(input, - calculation, - failureMechanism, - assessmentSection); - - const int overflow = 1; - string newProbabilityString = string.Concat(newValue.ToString("r", CultureInfo.CurrentCulture), overflow); - - var handler = new SetPropertyValueAfterConfirmationParameterTester(Enumerable.Empty()); - var properties = new ClosingStructuresInputContextProperties(inputContext, handler); - - // Call - TestDelegate call = () => properties.FailureProbabilityOpenStructure = newProbabilityString; - - // Assert - const string expectedMessage = "De waarde is te groot of te klein."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); - - mockRepository.VerifyAll(); - } - - [Test] - [TestCase("no double value")] - [TestCase("")] - [TestCase("1/aaa")] - public void FailureProbabilityOpenStructure_ValuesUnableToParse_ThrowsArgumentException(string newValue) - { - // Setup - mockRepository.ReplayAll(); - - var failureMechanism = new ClosingStructuresFailureMechanism(); - var calculation = new StructuresCalculation(); - ClosingStructuresInput input = calculation.InputParameters; - var inputContext = new ClosingStructuresInputContext(input, - calculation, - failureMechanism, - assessmentSection); - - var handler = new SetPropertyValueAfterConfirmationParameterTester(Enumerable.Empty()); - var properties = new ClosingStructuresInputContextProperties(inputContext, handler); - - // Call - TestDelegate call = () => properties.FailureProbabilityOpenStructure = newValue; - - // Assert - const string expectedMessage = "De waarde kon niet geïnterpreteerd worden als een kans."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); - - mockRepository.VerifyAll(); - } - - [Test] - public void FailureProbabilityOpenStructure_NullValue_ThrowsArgumentNullException() - { - // Setup - mockRepository.ReplayAll(); - - var failureMechanism = new ClosingStructuresFailureMechanism(); - var calculation = new StructuresCalculation(); - ClosingStructuresInput input = calculation.InputParameters; - var inputContext = new ClosingStructuresInputContext(input, - calculation, - failureMechanism, - assessmentSection); - - var handler = new SetPropertyValueAfterConfirmationParameterTester(Enumerable.Empty()); - var properties = new ClosingStructuresInputContextProperties(inputContext, handler); - - // Call - TestDelegate call = () => properties.FailureProbabilityOpenStructure = null; - - // Assert - const string expectedMessage = "De waarde voor de faalkans moet ingevuld zijn."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); - - mockRepository.VerifyAll(); - } - - [Test] - [TestCase(double.MinValue)] - [TestCase(double.MaxValue)] - public void FailureProbabilityReparation_InvalidValues_ThrowsArgumentException(double newValue) - { - // Setup - mockRepository.ReplayAll(); - - var failureMechanism = new ClosingStructuresFailureMechanism(); - var calculation = new StructuresCalculation(); - ClosingStructuresInput input = calculation.InputParameters; - var inputContext = new ClosingStructuresInputContext(input, - calculation, - failureMechanism, - assessmentSection); - - const int overflow = 1; - string newProbabilityString = string.Concat(newValue.ToString("r", CultureInfo.CurrentCulture), overflow); - - var handler = new SetPropertyValueAfterConfirmationParameterTester(Enumerable.Empty()); - var properties = new ClosingStructuresInputContextProperties(inputContext, handler); - - // Call - TestDelegate call = () => properties.FailureProbabilityReparation = newProbabilityString; - - // Assert - const string expectedMessage = "De waarde is te groot of te klein."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); - - mockRepository.VerifyAll(); - } - - [Test] - [TestCase("no double value")] - [TestCase("")] - [TestCase("1/aaa")] - public void FailureProbabilityReparation_ValuesUnableToParse_ThrowsArgumentException(string newValue) - { - // Setup - mockRepository.ReplayAll(); - - var failureMechanism = new ClosingStructuresFailureMechanism(); - var calculation = new StructuresCalculation(); - ClosingStructuresInput input = calculation.InputParameters; - var inputContext = new ClosingStructuresInputContext(input, - calculation, - failureMechanism, - assessmentSection); - - var handler = new SetPropertyValueAfterConfirmationParameterTester(Enumerable.Empty()); - var properties = new ClosingStructuresInputContextProperties(inputContext, handler); - - // Call - TestDelegate call = () => properties.FailureProbabilityReparation = newValue; - - // Assert - const string expectedMessage = "De waarde kon niet geïnterpreteerd worden als een kans."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); - - mockRepository.VerifyAll(); - } - - [Test] - public void FailureProbabilityReparation_NullValue_ThrowsArgumentNullException() - { - // Setup - mockRepository.ReplayAll(); - - var failureMechanism = new ClosingStructuresFailureMechanism(); - var calculation = new StructuresCalculation(); - ClosingStructuresInput input = calculation.InputParameters; - var inputContext = new ClosingStructuresInputContext(input, - calculation, - failureMechanism, - assessmentSection); - - var handler = new SetPropertyValueAfterConfirmationParameterTester(Enumerable.Empty()); - var properties = new ClosingStructuresInputContextProperties(inputContext, handler); - - // Call - TestDelegate call = () => properties.FailureProbabilityReparation = null; - - // Assert - const string expectedMessage = "De waarde voor de faalkans moet ingevuld zijn."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); - - mockRepository.VerifyAll(); - } - - [Test] public void Structure_StructureInSection_UpdateSectionResults() { // Setup Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Helpers/ProbabilityFormattingHelper.cs =================================================================== diff -u -r9ec7530d68e3e12f58d5d9498be3e4879a0cbc15 -r5cb5707e72014afb2b2bc5a015bf3bd507242318 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Helpers/ProbabilityFormattingHelper.cs (.../ProbabilityFormattingHelper.cs) (revision 9ec7530d68e3e12f58d5d9498be3e4879a0cbc15) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Helpers/ProbabilityFormattingHelper.cs (.../ProbabilityFormattingHelper.cs) (revision 5cb5707e72014afb2b2bc5a015bf3bd507242318) @@ -19,7 +19,6 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System; using Ringtoets.Common.Forms.Properties; using CommonBaseResources = Core.Common.Base.Properties.Resources; @@ -61,20 +60,5 @@ return string.Format(Resources.ProbabilityPerYearFormat, returnPeriod); } - - /// - /// Parses the input string to a probability. - /// - /// The return period input string. - /// The parsed double probability value. - public static double Parse(string returnPeriod) - { - if (returnPeriod.StartsWith("1/")) - { - return 1 / Convert.ToDouble(returnPeriod.Substring(2)); - } - - return Convert.ToDouble(returnPeriod); - } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/StructuresInputBaseProperties.cs =================================================================== diff -u -rd491788b870f9a9d2e08c93b52777f613809a133 -r5cb5707e72014afb2b2bc5a015bf3bd507242318 --- Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/StructuresInputBaseProperties.cs (.../StructuresInputBaseProperties.cs) (revision d491788b870f9a9d2e08c93b52777f613809a133) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/StructuresInputBaseProperties.cs (.../StructuresInputBaseProperties.cs) (revision 5cb5707e72014afb2b2bc5a015bf3bd507242318) @@ -37,6 +37,7 @@ using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.Common.Forms.Properties; +using Ringtoets.Common.Forms.TypeConverters; using Ringtoets.Common.Forms.UITypeEditors; namespace Ringtoets.Common.Forms.PropertyClasses @@ -215,36 +216,6 @@ protected IObservablePropertyChangeHandler PropertyChangeHandler { get; } /// - /// Sets a probability value to one of the properties of a wrapped data object. - /// - /// The probability value to set. - /// The wrapped data to set a probability value for. - /// The action that sets the probability value to a specific property of the wrapped data. - /// Thrown when equals null. - /// Thrown when cannot be parsed into a double. - protected static void SetProbabilityValue(string value, - TStructureInput structureInput, - Action setValueAction) - { - if (value == null) - { - throw new ArgumentNullException(nameof(value), Resources.Probability_Value_cannot_be_null); - } - try - { - setValueAction(structureInput, (RoundedDouble) ProbabilityFormattingHelper.Parse(value)); - } - catch (OverflowException) - { - throw new ArgumentException(Resources.Probability_Value_too_large); - } - catch (FormatException) - { - throw new ArgumentException(Resources.Probability_Could_not_parse_string_to_probability); - } - } - - /// /// The action to perform after setting the property. /// protected abstract void AfterSettingStructure(); @@ -505,21 +476,19 @@ [DynamicReadOnly] [DynamicPropertyOrder] + [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] [ResourcesCategory(typeof(Resources), nameof(Resources.Categories_Schematization))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.Structure_FailureProbabilityStructureWithErosion_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.Structure_FailureProbabilityStructureWithErosion_Description))] - public string FailureProbabilityStructureWithErosion + public double FailureProbabilityStructureWithErosion { get { - return ProbabilityFormattingHelper.Format(data.WrappedData.FailureProbabilityStructureWithErosion); + return data.WrappedData.FailureProbabilityStructureWithErosion; } set { - PropertyChangeHelper.ChangePropertyAndNotify(() => SetProbabilityValue( - value, - data.WrappedData, - (wrappedData, parsedValue) => wrappedData.FailureProbabilityStructureWithErosion = parsedValue), PropertyChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => data.WrappedData.FailureProbabilityStructureWithErosion = value, PropertyChangeHandler); } } Index: Ringtoets/Common/src/Ringtoets.Common.Forms/TypeConverters/NoProbabilityValueDoubleConverter.cs =================================================================== diff -u -rd491788b870f9a9d2e08c93b52777f613809a133 -r5cb5707e72014afb2b2bc5a015bf3bd507242318 --- Ringtoets/Common/src/Ringtoets.Common.Forms/TypeConverters/NoProbabilityValueDoubleConverter.cs (.../NoProbabilityValueDoubleConverter.cs) (revision d491788b870f9a9d2e08c93b52777f613809a133) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/TypeConverters/NoProbabilityValueDoubleConverter.cs (.../NoProbabilityValueDoubleConverter.cs) (revision 5cb5707e72014afb2b2bc5a015bf3bd507242318) @@ -71,7 +71,12 @@ try { - return ProbabilityFormattingHelper.Parse(text); + if (text.StartsWith("1/")) + { + return 1 / Convert.ToDouble(text.Substring(2)); + } + + return Convert.ToDouble(text); } catch (FormatException exception) { Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Helpers/ProbabilityFormattingHelperTest.cs =================================================================== diff -u -r9ec7530d68e3e12f58d5d9498be3e4879a0cbc15 -r5cb5707e72014afb2b2bc5a015bf3bd507242318 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Helpers/ProbabilityFormattingHelperTest.cs (.../ProbabilityFormattingHelperTest.cs) (revision 9ec7530d68e3e12f58d5d9498be3e4879a0cbc15) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Helpers/ProbabilityFormattingHelperTest.cs (.../ProbabilityFormattingHelperTest.cs) (revision 5cb5707e72014afb2b2bc5a015bf3bd507242318) @@ -19,8 +19,6 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System; -using System.Globalization; using NUnit.Framework; using Ringtoets.Common.Forms.Helpers; @@ -79,48 +77,5 @@ // Assert Assert.AreEqual(expectedText, text); } - - [Test] - [SetCulture("nl-NL")] - [TestCase("1/10", 0.1)] - [TestCase("1/2,5", 0.4)] - [TestCase("0,5", 0.5)] - [TestCase("1", 1.0)] - [TestCase("1e-2", 0.01)] - public void Parse_WithValidInput_ReturnsCorrectProbability(string input, double expectedProbability) - { - // Call - double probability = ProbabilityFormattingHelper.Parse(input); - - // Assert - Assert.AreEqual(expectedProbability, probability); - } - - [Test] - [TestCase("not a double")] - [TestCase("")] - [TestCase("1/aaa")] - [TestCase("1/")] - [TestCase(".")] - public void Parse_WithInvalidInput_ThrowsFormatException(string input) - { - // Call - TestDelegate call = () => ProbabilityFormattingHelper.Parse(input); - - // Assert - Assert.Throws(call); - } - - [Test] - [TestCase(double.MinValue)] - [TestCase(double.MaxValue)] - public void Parse_WithOutOfRangeInput_ThrowsOverflowException(double input) - { - // Call - TestDelegate call = () => ProbabilityFormattingHelper.Parse(input.ToString(CultureInfo.CurrentCulture) + "1"); - - // Assert - Assert.Throws(call); - } } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/StructuresInputBasePropertiesTest.cs =================================================================== diff -u -rd491788b870f9a9d2e08c93b52777f613809a133 -r5cb5707e72014afb2b2bc5a015bf3bd507242318 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/StructuresInputBasePropertiesTest.cs (.../StructuresInputBasePropertiesTest.cs) (revision d491788b870f9a9d2e08c93b52777f613809a133) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/StructuresInputBasePropertiesTest.cs (.../StructuresInputBasePropertiesTest.cs) (revision 5cb5707e72014afb2b2bc5a015bf3bd507242318) @@ -22,7 +22,6 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.Globalization; using System.Linq; using Core.Common.Base; using Core.Common.Base.Data; @@ -38,7 +37,6 @@ using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Forms.ChangeHandlers; -using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.Common.Forms.PropertyClasses; using Ringtoets.Common.Forms.TestUtil; @@ -146,7 +144,6 @@ Assert.AreSame(inputContext, properties.Data); SimpleStructureInput input = calculation.InputParameters; - string expectedFailureProbabilityStructureWithErosion = ProbabilityFormattingHelper.Format(input.FailureProbabilityStructureWithErosion); Assert.IsNull(properties.Structure); Assert.IsNull(properties.StructureLocation); @@ -160,7 +157,7 @@ Assert.IsNull(properties.ForeshoreProfile); Assert.IsInstanceOf(properties.UseBreakWater); Assert.IsInstanceOf(properties.UseForeshore); - Assert.AreEqual(expectedFailureProbabilityStructureWithErosion, properties.FailureProbabilityStructureWithErosion); + Assert.AreEqual(input.FailureProbabilityStructureWithErosion, properties.FailureProbabilityStructureWithErosion); Assert.IsNull(properties.SelectedHydraulicBoundaryLocation); Assert.AreSame(input.StormDuration, properties.StormDuration.Data); @@ -676,16 +673,15 @@ // Call properties.Structure = newStructure; properties.StructureNormalOrientation = (RoundedDouble) newStructureNormalOrientation; - properties.FailureProbabilityStructureWithErosion = "1e-2"; + properties.FailureProbabilityStructureWithErosion = 1e-2; properties.SelectedHydraulicBoundaryLocation = newSelectableHydraulicBoundaryLocation; properties.ForeshoreProfile = newForeshoreProfile; properties.ShouldIllustrationPointsBeCalculated = newShouldIllustrationPointsBeCalculated; // Assert Assert.AreSame(newStructure, properties.Structure); Assert.AreEqual(newStructureNormalOrientation, properties.StructureNormalOrientation, properties.StructureNormalOrientation.GetAccuracy()); - Assert.AreEqual(0.01, inputContext.WrappedData.FailureProbabilityStructureWithErosion); - Assert.AreEqual("1/100", properties.FailureProbabilityStructureWithErosion); + Assert.AreEqual(0.01, properties.FailureProbabilityStructureWithErosion); Assert.AreSame(newHydraulicBoundaryLocation, properties.SelectedHydraulicBoundaryLocation.HydraulicBoundaryLocation); Assert.AreSame(newForeshoreProfile, properties.ForeshoreProfile); Assert.AreEqual(newShouldIllustrationPointsBeCalculated, properties.ShouldIllustrationPointsBeCalculated); @@ -709,14 +705,11 @@ } [Test] - [SetCulture("nl-NL")] - [TestCase("0,1")] - [TestCase("1/100")] - [TestCase("1e-2")] - public void FailureProbabilityStructureWithErosion_Always_InputChangedAndObservablesNotified(string failureProbability) + public void FailureProbabilityStructureWithErosion_Always_InputChangedAndObservablesNotified() { + var random = new Random(21); SetPropertyAndVerifyNotifcationsAndOutput( - properties => properties.FailureProbabilityStructureWithErosion = failureProbability); + properties => properties.FailureProbabilityStructureWithErosion = random.NextDouble()); } [Test] @@ -868,102 +861,6 @@ Assert.IsTrue(properties.AfterSettingStructureCalled); } - [Test] - [TestCase(double.MinValue)] - [TestCase(double.MaxValue)] - public void FailureProbabilityStructureWithErosion_InvalidValues_ThrowsArgumentException(double newValue) - { - // Setup - mockRepository.ReplayAll(); - - var calculation = new StructuresCalculation(); - var inputContext = new SimpleInputContext(calculation.InputParameters, - calculation, - failureMechanism, - assessmentSection); - - string newStringValue = newValue.ToString(CultureInfo.InvariantCulture); - SetPropertyValueAfterConfirmationParameterTester customHandler = - CreateCustomHandlerForCalculationReturningNoObservables(); - - var properties = new SimpleStructuresInputProperties( - inputContext, - new StructuresInputBaseProperties, IFailureMechanism>.ConstructionProperties(), - customHandler); - - // Call - TestDelegate call = () => properties.FailureProbabilityStructureWithErosion = newStringValue; - - // Assert - const string expectedMessage = "De waarde is te groot of te klein."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); - - mockRepository.VerifyAll(); - } - - [Test] - [TestCase("no double value")] - [TestCase("")] - [TestCase("1/aa")] - public void FailureProbabilityStructureWithErosion_ValuesUnableToParse_ThrowsArgumentException(string newValue) - { - // Setup - mockRepository.ReplayAll(); - - var calculation = new StructuresCalculation(); - var inputContext = new SimpleInputContext(calculation.InputParameters, - calculation, - failureMechanism, - assessmentSection); - - SetPropertyValueAfterConfirmationParameterTester customHandler = - CreateCustomHandlerForCalculationReturningNoObservables(); - - var properties = new SimpleStructuresInputProperties( - inputContext, - new StructuresInputBaseProperties, IFailureMechanism>.ConstructionProperties(), - customHandler); - - // Call - TestDelegate call = () => properties.FailureProbabilityStructureWithErosion = newValue; - - // Assert - const string expectedMessage = "De waarde kon niet geïnterpreteerd worden als een kans."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); - - mockRepository.VerifyAll(); - } - - [Test] - public void FailureProbabilityStructureWithErosion_NullValue_ThrowsArgumentNullException() - { - // Setup - mockRepository.ReplayAll(); - - var calculation = new StructuresCalculation(); - var inputContext = new SimpleInputContext(calculation.InputParameters, - calculation, - failureMechanism, - assessmentSection); - - SetPropertyValueAfterConfirmationParameterTester customHandler = - CreateCustomHandlerForCalculationReturningNoObservables(); - - var properties = new SimpleStructuresInputProperties( - inputContext, - new StructuresInputBaseProperties, IFailureMechanism>.ConstructionProperties(), - customHandler); - - // Call - TestDelegate call = () => properties.FailureProbabilityStructureWithErosion = null; - - // Assert - const string expectedMessage = "De waarde voor de faalkans moet ingevuld zijn."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); - - mockRepository.VerifyAll(); - } - private static SetPropertyValueAfterConfirmationParameterTester CreateCustomHandlerForCalculationReturningNoObservables() { return new SetPropertyValueAfterConfirmationParameterTester(Enumerable.Empty()); Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TypeConverters/NoProbabilityValueDoubleConverterTest.cs =================================================================== diff -u -rd491788b870f9a9d2e08c93b52777f613809a133 -r5cb5707e72014afb2b2bc5a015bf3bd507242318 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TypeConverters/NoProbabilityValueDoubleConverterTest.cs (.../NoProbabilityValueDoubleConverterTest.cs) (revision d491788b870f9a9d2e08c93b52777f613809a133) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TypeConverters/NoProbabilityValueDoubleConverterTest.cs (.../NoProbabilityValueDoubleConverterTest.cs) (revision 5cb5707e72014afb2b2bc5a015bf3bd507242318) @@ -102,7 +102,7 @@ [SetCulture("nl-NL")] [TestCase(123.4567)] [TestCase(-9.87654321)] - public void ConvertFrom_SomeNumericalTextInDutchCulture_ReturnConvertedRoundedDouble(double input) + public void ConvertFrom_SomeNumericalTextInDutchCulture_ReturnConvertedDouble(double input) { DoConvertFrom_SomeNumericalTextInCurrentCulture_ReturnConvertedDouble(input); } @@ -111,17 +111,18 @@ [SetCulture("en-US")] [TestCase(12.34)] [TestCase(-0.96834715)] - public void ConvertFrom_SomeNumericalTextInEnglishCulture_ReturnConvertedRoundedDouble(double input) + public void ConvertFrom_SomeNumericalTextInEnglishCulture_ReturnConvertedDouble(double input) { DoConvertFrom_SomeNumericalTextInCurrentCulture_ReturnConvertedDouble(input); } [Test] [SetCulture("nl-NL")] [TestCase("1/25", 0.04)] - [TestCase("1/2,5", 0.4)] + [TestCase("1/2,500", 0.4)] + [TestCase("1/2.500", 0.0004)] [TestCase("1e-3", 0.001)] - public void ConvertFrom_StringInDutchCulture_ReturnExpectedConvertedRoundedDouble(string input, double expectedOutput) + public void ConvertFrom_StringInDutchCulture_ReturnExpectedConvertedDouble(string input, double expectedOutput) { // Setup var mocks = new MockRepository(); @@ -145,7 +146,7 @@ [TestCase("1/25", 0.04)] [TestCase("1/2.5", 0.4)] [TestCase("1e-3", 0.001)] - public void ConvertFrom_StringInEnglishCulture_ReturnExpectedConvertedRoundedDouble(string input, double expectedOutput) + public void ConvertFrom_StringInEnglishCulture_ReturnExpectedConvertedDouble(string input, double expectedOutput) { // Setup var mocks = new MockRepository(); Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/FailureMechanismContributionProperties.cs =================================================================== diff -u -rd491788b870f9a9d2e08c93b52777f613809a133 -r5cb5707e72014afb2b2bc5a015bf3bd507242318 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/FailureMechanismContributionProperties.cs (.../FailureMechanismContributionProperties.cs) (revision d491788b870f9a9d2e08c93b52777f613809a133) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/FailureMechanismContributionProperties.cs (.../FailureMechanismContributionProperties.cs) (revision 5cb5707e72014afb2b2bc5a015bf3bd507242318) @@ -30,8 +30,8 @@ using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Contribution; using Ringtoets.Common.Forms.ChangeHandlers; -using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.PropertyClasses; +using Ringtoets.Common.Forms.TypeConverters; using Ringtoets.Integration.Forms.Properties; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; @@ -110,34 +110,36 @@ } [PropertyOrder(2)] + [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_General))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.SignalingNorm_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.SignalingNorm_Description))] - public string SignalingNorm + public double SignalingNorm { get { - return ProbabilityFormattingHelper.Format(data.SignalingNorm); + return data.SignalingNorm; } set { - PropertyChangeHelper.ChangePropertyAndNotify(() => data.SignalingNorm = GetProbabilityValue(value), normChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => data.SignalingNorm = value, normChangeHandler); } } [PropertyOrder(3)] + [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_General))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.LowerLimitNorm_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.LowerLimitNorm_Description))] - public string LowerLimitNorm + public double LowerLimitNorm { get { - return ProbabilityFormattingHelper.Format(data.LowerLimitNorm); + return data.LowerLimitNorm; } set { - PropertyChangeHelper.ChangePropertyAndNotify(() => data.LowerLimitNorm = GetProbabilityValue(value), normChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => data.LowerLimitNorm = value, normChangeHandler); } } @@ -157,31 +159,5 @@ PropertyChangeHelper.ChangePropertyAndNotify(() => data.NormativeNorm = value, normChangeHandler); } } - - /// - /// Gets a probability value based on the input string value. - /// - /// The probability value to convert. - /// Thrown when equals null. - /// Thrown when cannot be parsed into a double. - private static double GetProbabilityValue(string value) - { - if (value == null) - { - throw new ArgumentNullException(nameof(value), RingtoetsCommonFormsResources.Probability_Value_cannot_be_null); - } - try - { - return ProbabilityFormattingHelper.Parse(value); - } - catch (OverflowException) - { - throw new ArgumentException(RingtoetsCommonFormsResources.Probability_Value_too_large); - } - catch (FormatException) - { - throw new ArgumentException(RingtoetsCommonFormsResources.Probability_Could_not_parse_string_to_probability); - } - } } } \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/PropertyClasses/FailureMechanismContributionPropertiesIntegrationTest.cs =================================================================== diff -u -r1f0cd3fafaa7340a446612870810629587474302 -r5cb5707e72014afb2b2bc5a015bf3bd507242318 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/PropertyClasses/FailureMechanismContributionPropertiesIntegrationTest.cs (.../FailureMechanismContributionPropertiesIntegrationTest.cs) (revision 1f0cd3fafaa7340a446612870810629587474302) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/PropertyClasses/FailureMechanismContributionPropertiesIntegrationTest.cs (.../FailureMechanismContributionPropertiesIntegrationTest.cs) (revision 5cb5707e72014afb2b2bc5a015bf3bd507242318) @@ -20,7 +20,6 @@ // All rights reserved. using System; -using System.Globalization; using System.Linq; using Core.Common.Base; using Core.Common.Gui.Commands; @@ -34,7 +33,6 @@ using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Data.TestUtil; -using Ringtoets.Common.Forms.Helpers; using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.GrassCoverErosionInwards.Data.TestUtil; using Ringtoets.HeightStructures.Data; @@ -43,7 +41,6 @@ using Ringtoets.Integration.Plugin.Handlers; using Ringtoets.Piping.Data; using Ringtoets.Piping.Data.TestUtil; -using Ringtoets.Piping.KernelWrapper.TestUtil; namespace Ringtoets.Integration.Forms.Test.PropertyClasses { @@ -55,8 +52,8 @@ private const string messageCalculationsremoved = "De resultaten van {0} berekeningen zijn verwijderd."; private const NormType newNormativeNorm = NormType.Signaling; - private readonly string newLowerLimitNorm = 0.01.ToString(CultureInfo.CurrentCulture); - private readonly string newSignalingNorm = 0.000001.ToString(CultureInfo.CurrentCulture); + private readonly double newLowerLimitNorm = 0.01; + private readonly double newSignalingNorm = 0.000001; private void SetPropertyAndVerifyNotifcationsAndOutputForAllDataSet(Action setPropertyAction) { @@ -811,8 +808,8 @@ private static void AssertNormValues(FailureMechanismContributionProperties properties, FailureMechanismContribution failureMechanismContribution) { - Assert.AreEqual(properties.LowerLimitNorm, ProbabilityFormattingHelper.Format(failureMechanismContribution.LowerLimitNorm)); - Assert.AreEqual(properties.SignalingNorm, ProbabilityFormattingHelper.Format(failureMechanismContribution.SignalingNorm)); + Assert.AreEqual(properties.LowerLimitNorm, failureMechanismContribution.LowerLimitNorm); + Assert.AreEqual(properties.SignalingNorm, failureMechanismContribution.SignalingNorm); Assert.AreEqual(properties.NormativeNorm, failureMechanismContribution.NormativeNorm); double expectedNorm = failureMechanismContribution.NormativeNorm == NormType.LowerLimit Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/PropertyClasses/FailureMechanismContributionPropertiesTest.cs =================================================================== diff -u -rdcc94dbcc481ef9f6f83308b82096f85f9cb6f01 -r5cb5707e72014afb2b2bc5a015bf3bd507242318 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/PropertyClasses/FailureMechanismContributionPropertiesTest.cs (.../FailureMechanismContributionPropertiesTest.cs) (revision dcc94dbcc481ef9f6f83308b82096f85f9cb6f01) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/PropertyClasses/FailureMechanismContributionPropertiesTest.cs (.../FailureMechanismContributionPropertiesTest.cs) (revision 5cb5707e72014afb2b2bc5a015bf3bd507242318) @@ -21,7 +21,6 @@ using System; using System.ComponentModel; -using System.Globalization; using Core.Common.Base; using Core.Common.Gui.Commands; using Core.Common.Gui.PropertyBag; @@ -33,7 +32,6 @@ using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Contribution; using Ringtoets.Common.Data.TestUtil; -using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.PropertyClasses; using Ringtoets.Common.Forms.TestUtil; using Ringtoets.Integration.Data; @@ -217,121 +215,26 @@ assessmentSectionChangeHandler); // Assert - string expectedLowerLimitNorm = ProbabilityFormattingHelper.Format(contribution.LowerLimitNorm); - string expectedSignalingNorm = ProbabilityFormattingHelper.Format(contribution.SignalingNorm); - Assert.AreEqual(assessmentSectionComposition, properties.AssessmentSectionComposition); - Assert.AreEqual(expectedLowerLimitNorm, properties.LowerLimitNorm); - Assert.AreEqual(expectedSignalingNorm, properties.SignalingNorm); + Assert.AreEqual(contribution.LowerLimitNorm, properties.LowerLimitNorm); + Assert.AreEqual(contribution.SignalingNorm, properties.SignalingNorm); Assert.AreEqual(contribution.NormativeNorm, properties.NormativeNorm); mocks.VerifyAll(); } [Test] - [SetCulture("nl-NL")] - [TestCase("0,1")] - [TestCase("1/100")] - [TestCase("1e-2")] - public void LowerLimitNorm_Always_ContributionNotifiedAndPropertyChangedCalled(string norm) + public void LowerLimitNorm_Always_ContributionNotifiedAndPropertyChangedCalled() { - SetPropertyAndVerifyNotifcationsAndOutputForCalculation(properties => properties.LowerLimitNorm = norm); + SetPropertyAndVerifyNotifcationsAndOutputForCalculation(properties => properties.LowerLimitNorm = 0.001); } [Test] - [TestCase(double.MinValue)] - [TestCase(double.MaxValue)] - public void LowerLimitNorm_InvalidValues_ThrowsArgumentException(double newValue) + public void SignalingNorm_Always_ContributionNotifiedAndPropertyChangedCalled() { - // Setup - const int overflow = 1; - string newProbabilityString = string.Concat(newValue.ToString("r", CultureInfo.CurrentCulture), overflow); - - // Call - TestDelegate call = () => SetPropertyAndVerifyNotifcationsAndOutputForCalculation(properties => properties.LowerLimitNorm = newProbabilityString); - - // Assert - const string expectedMessage = "De waarde is te groot of te klein."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); + SetPropertyAndVerifyNotifcationsAndOutputForCalculation(properties => properties.SignalingNorm = 0.00001); } [Test] - [TestCase("no double value")] - [TestCase("")] - [TestCase("1/aaa")] - public void LowerLimitNorm_ValuesUnableToParse_ThrowsArgumentException(string newValue) - { - // Call - TestDelegate call = () => SetPropertyAndVerifyNotifcationsAndOutputForCalculation(properties => properties.LowerLimitNorm = newValue); - - // Assert - const string expectedMessage = "De waarde kon niet geïnterpreteerd worden als een kans."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); - } - - [Test] - public void LowerLimitNorm_NullValue_ThrowsArgumentNullException() - { - // Call - TestDelegate call = () => SetPropertyAndVerifyNotifcationsAndOutputForCalculation(properties => properties.LowerLimitNorm = null); - - // Assert - const string expectedMessage = "De waarde voor de faalkans moet ingevuld zijn."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); - } - - [Test] - [TestCase(double.MinValue)] - [TestCase(double.MaxValue)] - public void SignalingNorm_InvalidValues_ThrowsArgumentException(double newValue) - { - // Setup - const int overflow = 1; - string newProbabilityString = string.Concat(newValue.ToString("r", CultureInfo.CurrentCulture), overflow); - - // Call - TestDelegate call = () => SetPropertyAndVerifyNotifcationsAndOutputForCalculation(properties => properties.SignalingNorm = newProbabilityString); - - // Assert - const string expectedMessage = "De waarde is te groot of te klein."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); - } - - [Test] - [TestCase("no double value")] - [TestCase("")] - [TestCase("1/aaa")] - public void SignalingNorm_ValuesUnableToParse_ThrowsArgumentException(string newValue) - { - // Call - TestDelegate call = () => SetPropertyAndVerifyNotifcationsAndOutputForCalculation(properties => properties.SignalingNorm = newValue); - - // Assert - const string expectedMessage = "De waarde kon niet geïnterpreteerd worden als een kans."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); - } - - [Test] - public void SignalingNorm_NullValue_ThrowsArgumentNullException() - { - // Call - TestDelegate call = () => SetPropertyAndVerifyNotifcationsAndOutputForCalculation(properties => properties.SignalingNorm = null); - - // Assert - const string expectedMessage = "De waarde voor de faalkans moet ingevuld zijn."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); - } - - [Test] - [SetCulture("nl-NL")] - [TestCase("0,00001")] - [TestCase("1/30000")] - [TestCase("1e-5")] - public void SignalingNorm_Always_ContributionNotifiedAndPropertyChangedCalled(string norm) - { - SetPropertyAndVerifyNotifcationsAndOutputForCalculation(properties => properties.SignalingNorm = norm); - } - - [Test] public void NormativeNorm_Always_ContributionNotifiedAndPropertyChangedCalled() { SetPropertyAndVerifyNotifcationsAndOutputForCalculation(properties => properties.NormativeNorm = NormType.Signaling); Index: Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Forms/PropertyClasses/StabilityPointStructuresInputContextProperties.cs =================================================================== diff -u -rff948d4633181ead2677ab35467a93b4118c6751 -r5cb5707e72014afb2b2bc5a015bf3bd507242318 --- Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Forms/PropertyClasses/StabilityPointStructuresInputContextProperties.cs (.../StabilityPointStructuresInputContextProperties.cs) (revision ff948d4633181ead2677ab35467a93b4118c6751) +++ Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Forms/PropertyClasses/StabilityPointStructuresInputContextProperties.cs (.../StabilityPointStructuresInputContextProperties.cs) (revision 5cb5707e72014afb2b2bc5a015bf3bd507242318) @@ -30,8 +30,8 @@ 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.Forms.TypeConverters; using Ringtoets.Common.Utils; using Ringtoets.StabilityPointStructures.Data; using Ringtoets.StabilityPointStructures.Forms.PresentationObjects; @@ -494,21 +494,19 @@ [DynamicReadOnly] [PropertyOrder(failureProbabilityRepairClosurePropertyIndex)] + [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_Schematization))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.Structure_FailureProbabilityRepairClosure_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.Structure_FailureProbabilityRepairClosure_Description))] - public string FailureProbabilityRepairClosure + public double FailureProbabilityRepairClosure { get { - return ProbabilityFormattingHelper.Format(data.WrappedData.FailureProbabilityRepairClosure); + return data.WrappedData.FailureProbabilityRepairClosure; } set { - PropertyChangeHelper.ChangePropertyAndNotify(() => SetProbabilityValue( - value, - data.WrappedData, - (wrappedData, parsedValue) => wrappedData.FailureProbabilityRepairClosure = parsedValue), PropertyChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => data.WrappedData.FailureProbabilityRepairClosure = value, PropertyChangeHandler); } } @@ -585,21 +583,19 @@ [DynamicReadOnly] [PropertyOrder(probabilityCollisionSecondaryStructurePropertyIndex)] + [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_Schematization))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.Structure_ProbabilityCollisionSecondaryStructure_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.Structure_ProbabilityCollisionSecondaryStructure_Description))] - public string ProbabilityCollisionSecondaryStructure + public double ProbabilityCollisionSecondaryStructure { get { - return ProbabilityFormattingHelper.Format(data.WrappedData.ProbabilityCollisionSecondaryStructure); + return data.WrappedData.ProbabilityCollisionSecondaryStructure; } set { - PropertyChangeHelper.ChangePropertyAndNotify(() => SetProbabilityValue( - value, - data.WrappedData, - (wrappedData, parsedValue) => wrappedData.ProbabilityCollisionSecondaryStructure = parsedValue), PropertyChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => data.WrappedData.ProbabilityCollisionSecondaryStructure = value, PropertyChangeHandler); } } Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/PropertyClasses/StabilityPointStructuresInputContextPropertiesTest.cs =================================================================== diff -u -rd491788b870f9a9d2e08c93b52777f613809a133 -r5cb5707e72014afb2b2bc5a015bf3bd507242318 --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/PropertyClasses/StabilityPointStructuresInputContextPropertiesTest.cs (.../StabilityPointStructuresInputContextPropertiesTest.cs) (revision d491788b870f9a9d2e08c93b52777f613809a133) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/PropertyClasses/StabilityPointStructuresInputContextPropertiesTest.cs (.../StabilityPointStructuresInputContextPropertiesTest.cs) (revision 5cb5707e72014afb2b2bc5a015bf3bd507242318) @@ -22,7 +22,6 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.Globalization; using System.Linq; using Core.Common.Base; using Core.Common.Base.Data; @@ -35,7 +34,6 @@ using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Data.TestUtil; -using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.PropertyClasses; using Ringtoets.Common.Forms.TestUtil; using Ringtoets.StabilityPointStructures.Data; @@ -125,8 +123,6 @@ Assert.AreSame(inputContext, properties.Data); StabilityPointStructuresInput input = calculation.InputParameters; - string expectedFailureProbabilityRepairClosure = ProbabilityFormattingHelper.Format(input.FailureProbabilityRepairClosure); - string expectedProbabilityCollisionSecondaryStructure = ProbabilityFormattingHelper.Format(input.ProbabilityCollisionSecondaryStructure); Assert.AreSame(input.ModelFactorSuperCriticalFlow, properties.ModelFactorSuperCriticalFlow.Data); Assert.AreEqual(input.StructureNormalOrientation, properties.StructureNormalOrientation); @@ -145,12 +141,12 @@ Assert.AreSame(input.ConstructiveStrengthQuadraticLoadModel, properties.ConstructiveStrengthQuadraticLoadModel.Data); Assert.AreSame(input.StabilityLinearLoadModel, properties.StabilityLinearLoadModel.Data); Assert.AreSame(input.StabilityQuadraticLoadModel, properties.StabilityQuadraticLoadModel.Data); - Assert.AreEqual(expectedFailureProbabilityRepairClosure, properties.FailureProbabilityRepairClosure); + Assert.AreEqual(input.FailureProbabilityRepairClosure, properties.FailureProbabilityRepairClosure); Assert.AreSame(input.FailureCollisionEnergy, properties.FailureCollisionEnergy.Data); Assert.AreSame(input.ShipMass, properties.ShipMass.Data); Assert.AreSame(input.ShipVelocity, properties.ShipVelocity.Data); Assert.AreEqual(input.LevellingCount, properties.LevellingCount); - Assert.AreEqual(expectedProbabilityCollisionSecondaryStructure, properties.ProbabilityCollisionSecondaryStructure); + Assert.AreEqual(input.ProbabilityCollisionSecondaryStructure, properties.ProbabilityCollisionSecondaryStructure); Assert.AreSame(input.BankWidth, properties.BankWidth.Data); Assert.AreEqual(input.EvaluationLevel, properties.EvaluationLevel); Assert.AreEqual(input.VerticalDistance, properties.VerticalDistance); @@ -1259,14 +1255,11 @@ } [Test] - [SetCulture("nl-NL")] - [TestCase("0,1")] - [TestCase("1/100")] - [TestCase("1e-2")] - public void FailureProbabilityRepairClosure_WithOrWithoutOutput_HasOutputFalseInputNotifiedAndCalculationNotifiedWhenHadOutput(string probability) + public void FailureProbabilityRepairClosure_WithOrWithoutOutput_HasOutputFalseInputNotifiedAndCalculationNotifiedWhenHadOutput() { + var random = new Random(21); SetPropertyAndVerifyNotifcationsAndOutput( - properties => properties.FailureProbabilityRepairClosure = probability); + properties => properties.FailureProbabilityRepairClosure = random.NextDouble()); } [Test] @@ -1278,14 +1271,11 @@ } [Test] - [SetCulture("nl-NL")] - [TestCase("0,1")] - [TestCase("1/100")] - [TestCase("1e-2")] - public void ProbabilityCollisionSecondaryStructure_WithOrWithoutOutput_HasOutputFalseInputNotifiedAndCalculationNotifiedWhenHadOutput(string probability) + public void ProbabilityCollisionSecondaryStructure_WithOrWithoutOutput_HasOutputFalseInputNotifiedAndCalculationNotifiedWhenHadOutput() { + var random = new Random(21); SetPropertyAndVerifyNotifcationsAndOutput( - properties => properties.ProbabilityCollisionSecondaryStructure = probability); + properties => properties.ProbabilityCollisionSecondaryStructure = random.NextDouble()); } [Test] @@ -1441,184 +1431,6 @@ } [Test] - [TestCase(double.MinValue)] - [TestCase(double.MaxValue)] - public void SetFailureProbabilityRepairClosure_InvalidValues_ThrowsArgumentException(double newValue) - { - // Setup - mockRepository.ReplayAll(); - - var failureMechanism = new StabilityPointStructuresFailureMechanism(); - var calculation = new StructuresCalculation(); - StabilityPointStructuresInput input = calculation.InputParameters; - var inputContext = new StabilityPointStructuresInputContext(input, - calculation, - failureMechanism, - assessmentSection); - - const int overflow = 1; - string newProbabilityString = string.Concat(newValue.ToString("r", CultureInfo.CurrentCulture), overflow); - - var handler = new SetPropertyValueAfterConfirmationParameterTester(Enumerable.Empty()); - var properties = new StabilityPointStructuresInputContextProperties(inputContext, handler); - - // Call - TestDelegate call = () => properties.FailureProbabilityRepairClosure = newProbabilityString; - - // Assert - const string expectedMessage = "De waarde is te groot of te klein."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); - - mockRepository.VerifyAll(); - } - - [Test] - [TestCase("no double value")] - [TestCase("")] - [TestCase("1/aaa")] - public void SetFailureProbabilityRepairClosure_ValuesUnableToParse_ThrowsArgumentException(string newValue) - { - // Setup - mockRepository.ReplayAll(); - - var failureMechanism = new StabilityPointStructuresFailureMechanism(); - var calculation = new StructuresCalculation(); - StabilityPointStructuresInput input = calculation.InputParameters; - var inputContext = new StabilityPointStructuresInputContext(input, - calculation, - failureMechanism, - assessmentSection); - - var handler = new SetPropertyValueAfterConfirmationParameterTester(Enumerable.Empty()); - var properties = new StabilityPointStructuresInputContextProperties(inputContext, handler); - - // Call - TestDelegate call = () => properties.FailureProbabilityRepairClosure = newValue; - - // Assert - const string expectedMessage = "De waarde kon niet geïnterpreteerd worden als een kans."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); - - mockRepository.VerifyAll(); - } - - [Test] - public void SetFailureProbabilityRepairClosure_NullValue_ThrowsArgumentNullException() - { - // Setup - mockRepository.ReplayAll(); - - var failureMechanism = new StabilityPointStructuresFailureMechanism(); - var calculation = new StructuresCalculation(); - StabilityPointStructuresInput input = calculation.InputParameters; - var inputContext = new StabilityPointStructuresInputContext(input, - calculation, - failureMechanism, - assessmentSection); - - var handler = new SetPropertyValueAfterConfirmationParameterTester(Enumerable.Empty()); - var properties = new StabilityPointStructuresInputContextProperties(inputContext, handler); - - // Call - TestDelegate call = () => properties.FailureProbabilityRepairClosure = null; - - // Assert - const string expectedMessage = "De waarde voor de faalkans moet ingevuld zijn."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); - - mockRepository.VerifyAll(); - } - - [Test] - [TestCase(double.MinValue)] - [TestCase(double.MaxValue)] - public void SetProbabilityCollisionSecondaryStructure_InvalidValues_ThrowsArgumentException(double newValue) - { - // Setup - mockRepository.ReplayAll(); - - var failureMechanism = new StabilityPointStructuresFailureMechanism(); - var calculation = new StructuresCalculation(); - StabilityPointStructuresInput input = calculation.InputParameters; - var inputContext = new StabilityPointStructuresInputContext(input, - calculation, - failureMechanism, - assessmentSection); - - const int overflow = 1; - string newProbabilityString = string.Concat(newValue.ToString("r", CultureInfo.CurrentCulture), overflow); - - var handler = new SetPropertyValueAfterConfirmationParameterTester(Enumerable.Empty()); - var properties = new StabilityPointStructuresInputContextProperties(inputContext, handler); - - // Call - TestDelegate call = () => properties.ProbabilityCollisionSecondaryStructure = newProbabilityString; - - // Assert - const string expectedMessage = "De waarde is te groot of te klein."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); - - mockRepository.VerifyAll(); - } - - [Test] - [TestCase("no double value")] - [TestCase("")] - [TestCase("1/aaa")] - public void SetProbabilityCollisionSecondaryStructure_ValuesUnableToParse_ThrowsArgumentException(string newValue) - { - // Setup - mockRepository.ReplayAll(); - - var failureMechanism = new StabilityPointStructuresFailureMechanism(); - var calculation = new StructuresCalculation(); - StabilityPointStructuresInput input = calculation.InputParameters; - var inputContext = new StabilityPointStructuresInputContext(input, - calculation, - failureMechanism, - assessmentSection); - - var handler = new SetPropertyValueAfterConfirmationParameterTester(Enumerable.Empty()); - var properties = new StabilityPointStructuresInputContextProperties(inputContext, handler); - - // Call - TestDelegate call = () => properties.ProbabilityCollisionSecondaryStructure = newValue; - - // Assert - const string expectedMessage = "De waarde kon niet geïnterpreteerd worden als een kans."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); - - mockRepository.VerifyAll(); - } - - [Test] - public void SetProbabilityCollisionSecondaryStructure_NullValue_ThrowsArgumentNullException() - { - // Setup - mockRepository.ReplayAll(); - - var failureMechanism = new StabilityPointStructuresFailureMechanism(); - var calculation = new StructuresCalculation(); - StabilityPointStructuresInput input = calculation.InputParameters; - var inputContext = new StabilityPointStructuresInputContext(input, - calculation, - failureMechanism, - assessmentSection); - - var handler = new SetPropertyValueAfterConfirmationParameterTester(Enumerable.Empty()); - var properties = new StabilityPointStructuresInputContextProperties(inputContext, handler); - - // Call - TestDelegate call = () => properties.ProbabilityCollisionSecondaryStructure = null; - - // Assert - const string expectedMessage = "De waarde voor de faalkans moet ingevuld zijn."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); - - mockRepository.VerifyAll(); - } - - [Test] public void SetStructure_StructureInSection_UpdateSectionResults() { // Setup