Index: Riskeer/Common/src/Riskeer.Common.Forms/TypeConverters/NoValueDoubleConverter.cs
===================================================================
diff -u
--- Riskeer/Common/src/Riskeer.Common.Forms/TypeConverters/NoValueDoubleConverter.cs (revision 0)
+++ Riskeer/Common/src/Riskeer.Common.Forms/TypeConverters/NoValueDoubleConverter.cs (revision 00f1aeb03b58ee1e86805ce9280cb3baef8b9e40)
@@ -0,0 +1,59 @@
+// Copyright (C) Stichting Deltares 2021. All rights reserved.
+//
+// This file is part of Riskeer.
+//
+// Riskeer is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.ComponentModel;
+using System.Globalization;
+using Riskeer.Common.Forms.Properties;
+
+namespace Riskeer.Common.Forms.TypeConverters
+{
+ ///
+ /// Converter to display as .
+ ///
+ public class NoValueDoubleConverter : TypeConverter
+ {
+ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
+ {
+ if (value is string text)
+ {
+ return string.IsNullOrWhiteSpace(text) || text.Trim() == Resources.RoundedDouble_No_result_dash
+ ? double.NaN
+ : Convert.ToDouble(text);
+ }
+
+ return base.ConvertFrom(context, culture, value);
+ }
+
+ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
+ {
+ var doubleValue = (double) value;
+ if (destinationType == typeof(string))
+ {
+ return double.IsNaN(doubleValue)
+ ? Resources.RoundedDouble_No_result_dash
+ : Convert.ToString(doubleValue, CultureInfo.CurrentCulture);
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+}
\ No newline at end of file
Index: Riskeer/Common/test/Riskeer.Common.Forms.Test/TypeConverters/NoValueDoubleConverterTest.cs
===================================================================
diff -u
--- Riskeer/Common/test/Riskeer.Common.Forms.Test/TypeConverters/NoValueDoubleConverterTest.cs (revision 0)
+++ Riskeer/Common/test/Riskeer.Common.Forms.Test/TypeConverters/NoValueDoubleConverterTest.cs (revision 00f1aeb03b58ee1e86805ce9280cb3baef8b9e40)
@@ -0,0 +1,242 @@
+// Copyright (C) Stichting Deltares 2021. All rights reserved.
+//
+// This file is part of Riskeer.
+//
+// Riskeer is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.ComponentModel;
+using System.Globalization;
+using NUnit.Framework;
+using Rhino.Mocks;
+using Riskeer.Common.Forms.TypeConverters;
+
+namespace Riskeer.Common.Forms.Test.TypeConverters
+{
+ [TestFixture]
+ public class NoValueDoubleConverterTest
+ {
+ [Test]
+ public void Constructor_ExpectedValues()
+ {
+ // Call
+ var converter = new NoValueDoubleConverter();
+
+ // Assert
+ Assert.IsInstanceOf(converter);
+ }
+
+ [Test]
+ [TestCase("")]
+ [TestCase(" ")]
+ [TestCase("-")]
+ [TestCase("NaN")]
+ public void ConvertFrom_NoValueText_ReturnNaN(string text)
+ {
+ // Setup
+ var converter = new NoValueDoubleConverter();
+
+ // Call
+ var result = (double) converter.ConvertFrom(text);
+
+ // Assert
+ Assert.IsNaN(result);
+ }
+
+ [Test]
+ [SetCulture("nl-NL")]
+ [TestCase(123.4567)]
+ [TestCase(-9.87654321)]
+ public void ConvertFrom_SomeNumericalTextInDutchCulture_ReturnConvertedDouble(double input)
+ {
+ DoConvertFrom_SomeNumericalTextInCurrentCulture_ReturnConvertedDouble(input);
+ }
+
+ [Test]
+ [SetCulture("en-US")]
+ [TestCase(12.34)]
+ [TestCase(-0.96834715)]
+ public void ConvertFrom_SomeNumericalTextInEnglishCulture_ReturnConvertedDouble(double input)
+ {
+ DoConvertFrom_SomeNumericalTextInCurrentCulture_ReturnConvertedDouble(input);
+ }
+
+ [Test]
+ [SetCulture("nl-NL")]
+ [TestCase("0,04", 0.04)]
+ [TestCase("0,4", 0.4)]
+ [TestCase("0,0004", 0.0004)]
+ [TestCase("0,001", 0.001)]
+ [TestCase("-0,001", -0.001)]
+ [TestCase("-0,1", -0.1)]
+ [TestCase("-0,4", -0.4)]
+ [TestCase("-0,5", -0.5)]
+ [TestCase("-1", -1.0)]
+ [TestCase("-1e-2", -0.01)]
+ public void ConvertFrom_StringInDutchCulture_ReturnExpectedConvertedDouble(string input, double expectedOutput)
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var context = mocks.Stub();
+ mocks.ReplayAll();
+
+ var converter = new NoValueDoubleConverter();
+
+ // Call
+ var conversionResult = (double) converter.ConvertFrom(context, CultureInfo.CurrentCulture, input);
+
+ // Assert
+ Assert.AreEqual(expectedOutput, conversionResult);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ [SetCulture("en-US")]
+ [TestCase("0.04", 0.04)]
+ [TestCase("0.4", 0.4)]
+ [TestCase("0.0004", 0.0004)]
+ [TestCase("0.001", 0.001)]
+ [TestCase("-0.001", -0.001)]
+ [TestCase("-0.1", -0.1)]
+ [TestCase("-0.4", -0.4)]
+ [TestCase("-0.5", -0.5)]
+ [TestCase("-1", -1.0)]
+ [TestCase("-1e-2", -0.01)]
+ public void ConvertFrom_StringInEnglishCulture_ReturnExpectedConvertedDouble(string input, double expectedOutput)
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var context = mocks.Stub();
+ mocks.ReplayAll();
+
+ var converter = new NoValueDoubleConverter();
+
+ // Call
+ var conversionResult = (double) converter.ConvertFrom(context, CultureInfo.CurrentCulture, input);
+
+ // Assert
+ Assert.AreEqual(expectedOutput, conversionResult);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void CanConvertTo_ToString_ReturnTrue()
+ {
+ // Setup
+ var converter = new NoProbabilityValueDoubleConverter();
+
+ // Call
+ bool canConvertToString = converter.CanConvertTo(typeof(string));
+
+ // Assert
+ Assert.IsTrue(canConvertToString);
+ }
+
+ [Test]
+ public void CanConvertTo_ToObject_ReturnFalse()
+ {
+ // Setup
+ var converter = new NoProbabilityValueDoubleConverter();
+
+ // Call
+ bool canConvertToObject = converter.CanConvertTo(typeof(object));
+
+ // Assert
+ Assert.IsFalse(canConvertToObject);
+ }
+
+ [Test]
+ public void ConvertTo_Object_ThrowNotSupportedException()
+ {
+ // Setup
+ var converter = new NoValueDoubleConverter();
+
+ // Call
+ void Call() => converter.ConvertTo(1.1, typeof(object));
+
+ // Assert
+ Assert.Throws(Call);
+ }
+
+ [Test]
+ public void ConvertTo_NaNToString_ReturnHyphen()
+ {
+ // Setup
+ var converter = new NoValueDoubleConverter();
+
+ // Call
+ var text = (string) converter.ConvertTo(double.NaN, typeof(string));
+
+ // Assert
+ Assert.AreEqual("-", text);
+ }
+
+ [Test]
+ [SetCulture("nl-NL")]
+ [TestCase(-0.000235, "-0,000235")]
+ [TestCase(0.0069, "0,0069")]
+ [TestCase(0.000000000000000069, "6,9E-17")]
+ public void ConvertTo_NumberToString_ReturnStringInLocalDutchCulture(double value, string expectedText)
+ {
+ // Setup
+ var converter = new NoValueDoubleConverter();
+
+ // Call
+ var text = (string) converter.ConvertTo(value, typeof(string));
+
+ // Assert
+ Assert.AreEqual(expectedText, text);
+ }
+
+ [Test]
+ [SetCulture("en-US")]
+ [TestCase(-0.0658, "-0.0658")]
+ [TestCase(0.000006788, "6.788E-06")]
+ [TestCase(-0.000000000000000069, "-6.9E-17")]
+ public void ConvertTo_NumberToString_ReturnStringInLocalEnglishCulture(double value, string expectedText)
+ {
+ // Setup
+ var converter = new NoValueDoubleConverter();
+
+ // Call
+ var text = (string) converter.ConvertTo(value, typeof(string));
+
+ // Assert
+ Assert.AreEqual(expectedText, text);
+ }
+
+ private static void DoConvertFrom_SomeNumericalTextInCurrentCulture_ReturnConvertedDouble(double input)
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var context = mocks.Stub();
+ mocks.ReplayAll();
+
+ var text = input.ToString(CultureInfo.CurrentCulture);
+
+ var converter = new NoValueDoubleConverter();
+
+ // Call
+ var conversionResult = (double) converter.ConvertFrom(context, CultureInfo.CurrentCulture, text);
+
+ // Assert
+ Assert.AreEqual(input, conversionResult);
+ mocks.VerifyAll();
+ }
+ }
+}
\ No newline at end of file
Index: Riskeer/Piping/src/Riskeer.Piping.Forms/Views/PipingFailureMechanismSectionResultRow.cs
===================================================================
diff -u -rd0d68360e744e3e0724e17edc3e024e85562d9fc -r00f1aeb03b58ee1e86805ce9280cb3baef8b9e40
--- Riskeer/Piping/src/Riskeer.Piping.Forms/Views/PipingFailureMechanismSectionResultRow.cs (.../PipingFailureMechanismSectionResultRow.cs) (revision d0d68360e744e3e0724e17edc3e024e85562d9fc)
+++ Riskeer/Piping/src/Riskeer.Piping.Forms/Views/PipingFailureMechanismSectionResultRow.cs (.../PipingFailureMechanismSectionResultRow.cs) (revision 00f1aeb03b58ee1e86805ce9280cb3baef8b9e40)
@@ -262,6 +262,7 @@
///
/// Gets the section N.
///
+ [TypeConverter(typeof(NoValueDoubleConverter))]
public double SectionN => AssemblyResult.N;
///
Index: Riskeer/Piping/test/Riskeer.Piping.Forms.Test/Views/PipingFailureMechanismSectionResultRowTest.cs
===================================================================
diff -u -rd0d68360e744e3e0724e17edc3e024e85562d9fc -r00f1aeb03b58ee1e86805ce9280cb3baef8b9e40
--- Riskeer/Piping/test/Riskeer.Piping.Forms.Test/Views/PipingFailureMechanismSectionResultRowTest.cs (.../PipingFailureMechanismSectionResultRowTest.cs) (revision d0d68360e744e3e0724e17edc3e024e85562d9fc)
+++ Riskeer/Piping/test/Riskeer.Piping.Forms.Test/Views/PipingFailureMechanismSectionResultRowTest.cs (.../PipingFailureMechanismSectionResultRowTest.cs) (revision 00f1aeb03b58ee1e86805ce9280cb3baef8b9e40)
@@ -215,6 +215,12 @@
nameof(PipingFailureMechanismSectionResultRow.RefinedProfileProbability));
TestHelper.AssertTypeConverter(
nameof(PipingFailureMechanismSectionResultRow.RefinedSectionProbability));
+ TestHelper.AssertTypeConverter(
+ nameof(PipingFailureMechanismSectionResultRow.ProfileProbability));
+ TestHelper.AssertTypeConverter(
+ nameof(PipingFailureMechanismSectionResultRow.SectionProbability));
+ TestHelper.AssertTypeConverter(
+ nameof(PipingFailureMechanismSectionResultRow.SectionN));
IDictionary columnStateDefinitions = row.ColumnStateDefinitions;
Assert.AreEqual(11, columnStateDefinitions.Count);