Fisheye: Tag cc883c70ff6e0cf28b0afadae0eccc45163784d1 refers to a dead (removed) revision in file `Core/Common/src/Core.Common.Gui/Converters/KeyValueAsRealizationRoundedDoubleElementAttribute.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Core/Common/src/Core.Common.Gui/Converters/KeyValueAsRoundedDoubleWithoutTrailingZeroesElementAttribute.cs =================================================================== diff -u --- Core/Common/src/Core.Common.Gui/Converters/KeyValueAsRoundedDoubleWithoutTrailingZeroesElementAttribute.cs (revision 0) +++ Core/Common/src/Core.Common.Gui/Converters/KeyValueAsRoundedDoubleWithoutTrailingZeroesElementAttribute.cs (revision cc883c70ff6e0cf28b0afadae0eccc45163784d1) @@ -0,0 +1,72 @@ +// Copyright (C) Stichting Deltares 2017. 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 Lesser 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser 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.Globalization; +using System.Reflection; +using Core.Common.Base.Data; + +namespace Core.Common.Gui.Converters +{ + /// + /// Attribute when using the to define what is + /// shown as name and value for each element. + /// + [AttributeUsage(AttributeTargets.Property)] + public class KeyValueAsRoundedDoubleWithoutTrailingZeroesElementAttribute : KeyValueElementAttribute + { + /// + /// Creates a new instance of . + /// + /// The name of the property to show as name. + /// The name of the property to show as value. + /// Thrown when any parameter is null. + public KeyValueAsRoundedDoubleWithoutTrailingZeroesElementAttribute(string namePropertyName, string valuePropertyName) : base(namePropertyName, valuePropertyName) {} + + /// + /// Gets the property value from the that is used + /// as value. + /// + /// The source to obtain the property value of. + /// The value used as value of the property. + /// Thrown when the property used for the value of + /// the is not found on the + /// or if the value is not of type RoundedDouble + /// + public override string GetValue(object source) + { + PropertyInfo valuePropertyInfo = source.GetType().GetProperty(ValuePropertyName); + if (valuePropertyInfo == null) + { + throw new ArgumentException($"Value property '{ValuePropertyName}' was not found on type {source.GetType().Name}."); + } + + object valueProperty = valuePropertyInfo.GetValue(source, new object[0]); + if (!(valueProperty is RoundedDouble)) + { + throw new ArgumentException($"Value property '{ValuePropertyName}' was not of type RoundedDouble."); + } + + var doubleValue = (RoundedDouble) valueProperty; + return doubleValue.ToString("0.#####", CultureInfo.GetCultureInfo("nl-NL")); + } + } +} \ No newline at end of file Index: Core/Common/src/Core.Common.Gui/Core.Common.Gui.csproj =================================================================== diff -u -r3a33e7253e29eb7649dcfc0f675169559b0eefb9 -rcc883c70ff6e0cf28b0afadae0eccc45163784d1 --- Core/Common/src/Core.Common.Gui/Core.Common.Gui.csproj (.../Core.Common.Gui.csproj) (revision 3a33e7253e29eb7649dcfc0f675169559b0eefb9) +++ Core/Common/src/Core.Common.Gui/Core.Common.Gui.csproj (.../Core.Common.Gui.csproj) (revision cc883c70ff6e0cf28b0afadae0eccc45163784d1) @@ -121,7 +121,7 @@ - + Fisheye: Tag cc883c70ff6e0cf28b0afadae0eccc45163784d1 refers to a dead (removed) revision in file `Core/Common/test/Core.Common.Gui.Test/Converters/KeyValueAsRealizationRoundedDoubleElementAttributeTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Core/Common/test/Core.Common.Gui.Test/Converters/KeyValueAsRoundedDoubleWithoutTrailingZeroesElementAttributeTest.cs =================================================================== diff -u --- Core/Common/test/Core.Common.Gui.Test/Converters/KeyValueAsRoundedDoubleWithoutTrailingZeroesElementAttributeTest.cs (revision 0) +++ Core/Common/test/Core.Common.Gui.Test/Converters/KeyValueAsRoundedDoubleWithoutTrailingZeroesElementAttributeTest.cs (revision cc883c70ff6e0cf28b0afadae0eccc45163784d1) @@ -0,0 +1,198 @@ +// Copyright (C) Stichting Deltares 2017. 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 Lesser 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser 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.Converters; +using Core.Common.TestUtil; +using NUnit.Framework; + +namespace Core.Common.Gui.Test.Converters +{ + [TestFixture] + public class KeyValueAsRoundedDoubleWithoutTrailingZeroesElementAttributeTest + { + [Test] + public void Constructor_WithoutValuePropertyName_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => new KeyValueAsRoundedDoubleWithoutTrailingZeroesElementAttribute("name", null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("valuePropertyName", exception.ParamName); + } + + [Test] + public void Constructor_WithoutNamePropertyName_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => new KeyValueAsRoundedDoubleWithoutTrailingZeroesElementAttribute(null, "value"); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("namePropertyName", exception.ParamName); + } + + [Test] + public void Constructor_WithParameters_CreatesNewInstance() + { + // Call + var attribute = new KeyValueAsRoundedDoubleWithoutTrailingZeroesElementAttribute("name", "value"); + + // Assert + Assert.IsInstanceOf(attribute); + } + + [Test] + public void GetName_WithObjectWithProperty_ReturnsValueOfProperty() + { + // Setup + const string expectedName = "expectedName"; + + var attribute = new KeyValueAsRoundedDoubleWithoutTrailingZeroesElementAttribute(nameof(TestObject.Name), nameof(TestObject.Value)); + + // Call + string name = attribute.GetName(new TestObject + { + Name = expectedName + }); + + // Assert + Assert.AreEqual(expectedName, name); + } + + [Test] + public void GetName_WithObjectWithNonStringProperty_ReturnsValueOfProperty() + { + // Setup + int expectedName = new Random(21).Next(3, 50); + + var attribute = new KeyValueAsRoundedDoubleWithoutTrailingZeroesElementAttribute(nameof(TestObject.NonStringName), nameof(TestObject.NonRoundedDoubleValue)); + + // Call + string name = attribute.GetName(new TestObject + { + NonStringName = expectedName + }); + + // Assert + Assert.AreEqual(Convert.ToString(expectedName), name); + } + + [Test] + public void GetName_WithObjectWithoutPropertyWithName_ThrowsArgumentException() + { + // Setup + var attribute = new KeyValueAsRoundedDoubleWithoutTrailingZeroesElementAttribute("IDoNotExist", nameof(TestObject.Value)); + + // Call + TestDelegate test = () => attribute.GetName(new TestObject()); + + // Assert + const string expectedMessage = "Name property 'IDoNotExist' was not found on type TestObject."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + [SetCulture("nl-NL")] + public void GetValue_WithObjectWithRoundedDoubleProperty_ReturnsValueOfProperty() + { + // Setup + var roundedDoubleValue = new RoundedDouble(5, 5.12345); + var attribute = new KeyValueAsRoundedDoubleWithoutTrailingZeroesElementAttribute(nameof(TestObject.Name), nameof(TestObject.Value)); + + // Call + string value = attribute.GetValue(new TestObject + { + Value = roundedDoubleValue + }); + + // Assert + const string expectedResult = "5,12345"; + Assert.AreEqual(expectedResult, value); + } + + [Test] + [SetCulture("nl-NL")] + [TestCase(5.0000, "5")] + [TestCase(-2.12000, "-2,12")] + [TestCase(1.24560, "1,2456")] + [TestCase(120, "120")] + public void GetValue_WithObjectWithRoundedDoubleProperty_ReturnsValueOfPropertyWithoutTrailingZeroes(double doubleValue, string expectedResult) + { + // Setup + var roundedDoubleValue = new RoundedDouble(5, doubleValue); + var attribute = new KeyValueAsRoundedDoubleWithoutTrailingZeroesElementAttribute(nameof(TestObject.Name), nameof(TestObject.Value)); + + // Call + string value = attribute.GetValue(new TestObject + { + Value = roundedDoubleValue + }); + + // Assert + Assert.AreEqual(expectedResult, value); + } + + [Test] + public void GetValue_WithObjectWithNonStringProperty_ThrowsArgumentException() + { + // Setup + int expectedValue = new Random(21).Next(3, 50); + + var attribute = new KeyValueAsRoundedDoubleWithoutTrailingZeroesElementAttribute(nameof(TestObject.NonStringName), nameof(TestObject.NonRoundedDoubleValue)); + + // Call + TestDelegate test = () => attribute.GetValue(new TestObject + { + NonRoundedDoubleValue = expectedValue + }); + + // Assert + const string expectedMessage = "Value property 'NonRoundedDoubleValue' was not of type RoundedDouble."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + public void GetValue_WithObjectWithoutPropertyWithName_ThrowsArgumentException() + { + // Setup + var attribute = new KeyValueAsRoundedDoubleWithoutTrailingZeroesElementAttribute(nameof(TestObject.Name), "IDoNotExist"); + + // Call + TestDelegate test = () => attribute.GetValue(new TestObject()); + + // Assert + const string expectedMessage = "Value property 'IDoNotExist' was not found on type TestObject."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + private class TestObject + { + public string Name { get; set; } + public RoundedDouble Value { get; set; } + + public int NonStringName { get; set; } + public int NonRoundedDoubleValue { get; set; } + } + } +} \ No newline at end of file Index: Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj =================================================================== diff -u -r3a33e7253e29eb7649dcfc0f675169559b0eefb9 -rcc883c70ff6e0cf28b0afadae0eccc45163784d1 --- Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj (.../Core.Common.Gui.Test.csproj) (revision 3a33e7253e29eb7649dcfc0f675169559b0eefb9) +++ Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj (.../Core.Common.Gui.Test.csproj) (revision cc883c70ff6e0cf28b0afadae0eccc45163784d1) @@ -93,7 +93,7 @@ - + Index: Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/SubMechanismIllustrationPointProperties.cs =================================================================== diff -u -r3a33e7253e29eb7649dcfc0f675169559b0eefb9 -rcc883c70ff6e0cf28b0afadae0eccc45163784d1 --- Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/SubMechanismIllustrationPointProperties.cs (.../SubMechanismIllustrationPointProperties.cs) (revision 3a33e7253e29eb7649dcfc0f675169559b0eefb9) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/SubMechanismIllustrationPointProperties.cs (.../SubMechanismIllustrationPointProperties.cs) (revision cc883c70ff6e0cf28b0afadae0eccc45163784d1) @@ -85,7 +85,7 @@ [ResourcesDisplayName(typeof(Resources), nameof(Resources.IllustrationPoint_Realization_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.IllustrationPoint_Realization_Description))] [TypeConverter(typeof(KeyValueExpandableArrayConverter))] - [KeyValueAsRealizationRoundedDoubleElement(nameof(Stochast.Name), nameof(SubMechanismIllustrationPointStochast.Realization))] + [KeyValueAsRoundedDoubleWithoutTrailingZeroesElement(nameof(Stochast.Name), nameof(SubMechanismIllustrationPointStochast.Realization))] public SubMechanismIllustrationPointStochast[] SubMechanismStochasts { get