Index: Ringtoets/Common/src/Ringtoets.Common.IO/BreakWaterTypeTypeConverter.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.IO/BreakWaterTypeTypeConverter.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.IO/BreakWaterTypeTypeConverter.cs (revision fde0ecf7d1d897337907d512aab471ead4a4c5e4) @@ -0,0 +1,82 @@ +// 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 System.Globalization; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.IO.Schema; + +namespace Ringtoets.Common.IO +{ + /// + /// Converts to and back. + /// + public class BreakWaterTypeTypeConverter : TypeConverter + { + public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) + { + if (destinationType == typeof(string)) + { + var type = (BreakWaterType) value; + switch (type) + { + case BreakWaterType.Caisson: + return ConfigurationSchemaIdentifiers.BreakWaterCaisson; + case BreakWaterType.Dam: + return ConfigurationSchemaIdentifiers.BreakWaterDam; + case BreakWaterType.Wall: + return ConfigurationSchemaIdentifiers.BreakWaterWall; + default: + throw new NotSupportedException(); + } + } + return base.ConvertTo(context, culture, value, destinationType); + } + + public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) + { + if (sourceType == typeof(string)) + { + return true; + } + return base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) + { + var text = value as string; + if (text != null) + { + switch (text) + { + case ConfigurationSchemaIdentifiers.BreakWaterCaisson: + return BreakWaterType.Caisson; + case ConfigurationSchemaIdentifiers.BreakWaterDam: + return BreakWaterType.Dam; + case ConfigurationSchemaIdentifiers.BreakWaterWall: + return BreakWaterType.Wall; + } + } + return base.ConvertFrom(context, culture, value); + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj =================================================================== diff -u -r63f628ad3e252277b290dd3f08ad8a5a6c8b70e8 -rfde0ecf7d1d897337907d512aab471ead4a4c5e4 --- Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision 63f628ad3e252277b290dd3f08ad8a5a6c8b70e8) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision fde0ecf7d1d897337907d512aab471ead4a4c5e4) @@ -54,6 +54,7 @@ + Index: Ringtoets/Common/src/Ringtoets.Common.IO/Writers/CalculationConfigurationWriter.cs =================================================================== diff -u -rccad0677b59f5f6e5303e9ebfdb5ee3670f35610 -rfde0ecf7d1d897337907d512aab471ead4a4c5e4 --- Ringtoets/Common/src/Ringtoets.Common.IO/Writers/CalculationConfigurationWriter.cs (.../CalculationConfigurationWriter.cs) (revision ccad0677b59f5f6e5303e9ebfdb5ee3670f35610) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Writers/CalculationConfigurationWriter.cs (.../CalculationConfigurationWriter.cs) (revision fde0ecf7d1d897337907d512aab471ead4a4c5e4) @@ -21,7 +21,6 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Xml; using Core.Common.IO.Exceptions; @@ -163,17 +162,7 @@ private static string BreakWaterTypeAsXmlString(BreakWaterType type) { - switch (type) - { - case BreakWaterType.Caisson: - return ConfigurationSchemaIdentifiers.BreakWaterCaisson; - case BreakWaterType.Dam: - return ConfigurationSchemaIdentifiers.BreakWaterDam; - case BreakWaterType.Wall: - return ConfigurationSchemaIdentifiers.BreakWaterWall; - default: - throw new InvalidEnumArgumentException(nameof(type), (int) type, typeof(BreakWaterType)); - } + return new BreakWaterTypeTypeConverter().ConvertToInvariantString(type); } private static void WriteDistribution(IDistribution distribution, string elementName, XmlWriter writer) Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/BreakWaterTypeTypeConverterTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/BreakWaterTypeTypeConverterTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/BreakWaterTypeTypeConverterTest.cs (revision fde0ecf7d1d897337907d512aab471ead4a4c5e4) @@ -0,0 +1,142 @@ +// 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 NUnit.Framework; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.IO.Schema; + +namespace Ringtoets.Common.IO.Test +{ + [TestFixture] + public class BreakWaterTypeTypeConverterTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Call + var converter = new BreakWaterTypeTypeConverter(); + + // Assert + Assert.IsInstanceOf(converter); + } + + [Test] + public void CanConvertTo_String_ReturnTrue() + { + // Setup + var converter = new BreakWaterTypeTypeConverter(); + + // Call + bool canConvertToString = converter.CanConvertTo(typeof(string)); + + // Assert + Assert.IsTrue(canConvertToString); + } + + [Test] + public void CanConvertTo_OtherThanString_ReturnFalse() + { + // Setup + var converter = new BreakWaterTypeTypeConverter(); + + // Call + bool canConvertToString = converter.CanConvertTo(typeof(object)); + + // Assert + Assert.IsFalse(canConvertToString); + } + + [Test] + [TestCase(BreakWaterType.Caisson, ConfigurationSchemaIdentifiers.BreakWaterCaisson)] + [TestCase(BreakWaterType.Dam, ConfigurationSchemaIdentifiers.BreakWaterDam)] + [TestCase(BreakWaterType.Wall, ConfigurationSchemaIdentifiers.BreakWaterWall)] + public void ConverTo_VariousCases_ReturnExpectedText(BreakWaterType value, + string expectedResult) + { + // Setup + var converter = new BreakWaterTypeTypeConverter(); + + // Call + object result = converter.ConvertTo(value, typeof(string)); + + // Assert + Assert.AreEqual(expectedResult, result); + } + + [Test] + public void CanConvertFrom_String_ReturnTrue() + { + // Setup + var converter = new BreakWaterTypeTypeConverter(); + + // Call + bool canConvertFromString = converter.CanConvertFrom(typeof(string)); + + // Assert + Assert.IsTrue(canConvertFromString); + } + + [Test] + public void CanConvertFrom_OtherThanString_ReturnFalse() + { + // Setup + var converter = new BreakWaterTypeTypeConverter(); + + // Call + bool canConvertFromString = converter.CanConvertFrom(typeof(object)); + + // Assert + Assert.IsFalse(canConvertFromString); + } + + [Test] + [TestCase(ConfigurationSchemaIdentifiers.BreakWaterCaisson, BreakWaterType.Caisson)] + [TestCase(ConfigurationSchemaIdentifiers.BreakWaterDam, BreakWaterType.Dam)] + [TestCase(ConfigurationSchemaIdentifiers.BreakWaterWall, BreakWaterType.Wall)] + public void ConvertFrom_Text_ReturnExpectedBreakWaterType(string value, + BreakWaterType expectedResult) + { + // Setup + var converter = new BreakWaterTypeTypeConverter(); + + // Call + object result = converter.ConvertFrom(value); + + // Assert + Assert.AreEqual(expectedResult, result); + } + + [Test] + public void ConvertFrom_InvalidText_ThrowNotSupportedException() + { + // Setup + var converter = new BreakWaterTypeTypeConverter(); + + // Call + TestDelegate call = () => converter.ConvertFrom("A"); + + // Assert + Assert.Throws(call); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj =================================================================== diff -u -r63f628ad3e252277b290dd3f08ad8a5a6c8b70e8 -rfde0ecf7d1d897337907d512aab471ead4a4c5e4 --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision 63f628ad3e252277b290dd3f08ad8a5a6c8b70e8) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision fde0ecf7d1d897337907d512aab471ead4a4c5e4) @@ -59,6 +59,7 @@ + Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/CalculationConfigurationWriterTest.cs =================================================================== diff -u -rae137e9d1b26f1b37e47f2b4a6bf9ae03c6c9b2e -rfde0ecf7d1d897337907d512aab471ead4a4c5e4 --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/CalculationConfigurationWriterTest.cs (.../CalculationConfigurationWriterTest.cs) (revision ae137e9d1b26f1b37e47f2b4a6bf9ae03c6c9b2e) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/CalculationConfigurationWriterTest.cs (.../CalculationConfigurationWriterTest.cs) (revision fde0ecf7d1d897337907d512aab471ead4a4c5e4) @@ -386,11 +386,6 @@ { public const string CalculationElementTag = "calculation"; - protected override void WriteCalculation(TestCalculation calculation, XmlWriter writer) - { - writer.WriteElementString(CalculationElementTag, calculation.Name); - } - public void PublicWriteDistributions(IEnumerable> distributions, XmlWriter writer) { WriteDistributions(distributions, writer); @@ -400,6 +395,11 @@ { WriteBreakWaterProperties(breakWater, writer); } + + protected override void WriteCalculation(TestCalculation calculation, XmlWriter writer) + { + writer.WriteElementString(CalculationElementTag, calculation.Name); + } } private static IEnumerable GetCalculationConfigurations() @@ -418,7 +418,7 @@ }; yield return new TestCaseData( - new [] + new[] { calculationGroup1 }, Index: Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Ringtoets.Revetment.IO.csproj =================================================================== diff -u -rae137e9d1b26f1b37e47f2b4a6bf9ae03c6c9b2e -rfde0ecf7d1d897337907d512aab471ead4a4c5e4 --- Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Ringtoets.Revetment.IO.csproj (.../Ringtoets.Revetment.IO.csproj) (revision ae137e9d1b26f1b37e47f2b4a6bf9ae03c6c9b2e) +++ Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Ringtoets.Revetment.IO.csproj (.../Ringtoets.Revetment.IO.csproj) (revision fde0ecf7d1d897337907d512aab471ead4a4c5e4) @@ -56,6 +56,7 @@ + Index: Ringtoets/Revetment/src/Ringtoets.Revetment.IO/WaveConditionsInputConfigurationWriter.cs =================================================================== diff -u -r2923096aeb41e1fb5d4ba0ad43ccb9f95ca7407a -rfde0ecf7d1d897337907d512aab471ead4a4c5e4 --- Ringtoets/Revetment/src/Ringtoets.Revetment.IO/WaveConditionsInputConfigurationWriter.cs (.../WaveConditionsInputConfigurationWriter.cs) (revision 2923096aeb41e1fb5d4ba0ad43ccb9f95ca7407a) +++ Ringtoets/Revetment/src/Ringtoets.Revetment.IO/WaveConditionsInputConfigurationWriter.cs (.../WaveConditionsInputConfigurationWriter.cs) (revision fde0ecf7d1d897337907d512aab471ead4a4c5e4) @@ -19,8 +19,6 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System.ComponentModel; -using System.Globalization; using System.Xml; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.DikeProfiles; @@ -38,6 +36,13 @@ /// The type of calculations that are written to file. public abstract class WaveConditionsInputConfigurationWriter : CalculationConfigurationWriter where T : class, ICalculation { + private readonly WaveConditionsInputStepSizeTypeConverter waveConditionsInputStepSizeConverter; + + public WaveConditionsInputConfigurationWriter() + { + waveConditionsInputStepSizeConverter = new WaveConditionsInputStepSizeTypeConverter(); + } + /// /// Writes a single calculation with its in XML format to file. /// @@ -65,7 +70,7 @@ XmlConvert.ToString(input.LowerBoundaryWaterLevels)); writer.WriteElementString( WaveConditionsInputConfigurationSchemaIdentifiers.StepSize, - string.Format(CultureInfo.InvariantCulture, "{0:0.0}", input.StepSize.AsValue())); + waveConditionsInputStepSizeConverter.ConvertToInvariantString(input.StepSize)); WriteForeshoreProfile(input.ForeshoreProfile, writer); Index: Ringtoets/Revetment/src/Ringtoets.Revetment.IO/WaveConditionsInputStepSizeTypeConverter.cs =================================================================== diff -u --- Ringtoets/Revetment/src/Ringtoets.Revetment.IO/WaveConditionsInputStepSizeTypeConverter.cs (revision 0) +++ Ringtoets/Revetment/src/Ringtoets.Revetment.IO/WaveConditionsInputStepSizeTypeConverter.cs (revision fde0ecf7d1d897337907d512aab471ead4a4c5e4) @@ -0,0 +1,75 @@ +// 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 System.Globalization; +using Ringtoets.Revetment.Data; + +namespace Ringtoets.Revetment.IO +{ + /// + /// Converts to and back. + /// + public class WaveConditionsInputStepSizeTypeConverter : TypeConverter + { + public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) + { + if (destinationType == typeof(string)) + { + var stepSize = (WaveConditionsInputStepSize) value; + return string.Format(culture, "{0:0.0}", stepSize.AsValue()); + } + return base.ConvertTo(context, culture, value, destinationType); + } + + public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) + { + if (sourceType == typeof(string)) + { + return true; + } + return base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) + { + var text = value as string; + if (text != null) + { + string decimalSeperator = culture.NumberFormat.NumberDecimalSeparator; + if ($"0{decimalSeperator}5".Equals(text)) + { + return WaveConditionsInputStepSize.Half; + } + if ($"1{decimalSeperator}0".Equals(text)) + { + return WaveConditionsInputStepSize.One; + } + if ($"2{decimalSeperator}0".Equals(text)) + { + return WaveConditionsInputStepSize.Two; + } + } + return base.ConvertFrom(context, culture, value); + } + } +} \ No newline at end of file Index: Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Ringtoets.Revetment.IO.Test.csproj =================================================================== diff -u -r0e700dc5121b8f56c96d1d552056bbe6ebe29300 -rfde0ecf7d1d897337907d512aab471ead4a4c5e4 --- Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Ringtoets.Revetment.IO.Test.csproj (.../Ringtoets.Revetment.IO.Test.csproj) (revision 0e700dc5121b8f56c96d1d552056bbe6ebe29300) +++ Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Ringtoets.Revetment.IO.Test.csproj (.../Ringtoets.Revetment.IO.Test.csproj) (revision fde0ecf7d1d897337907d512aab471ead4a4c5e4) @@ -56,6 +56,7 @@ + Index: Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/WaveConditionsInputStepSizeTypeConverterTest.cs =================================================================== diff -u --- Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/WaveConditionsInputStepSizeTypeConverterTest.cs (revision 0) +++ Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/WaveConditionsInputStepSizeTypeConverterTest.cs (revision fde0ecf7d1d897337907d512aab471ead4a4c5e4) @@ -0,0 +1,163 @@ +// 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 System.Globalization; +using NUnit.Framework; +using Ringtoets.Revetment.Data; + +namespace Ringtoets.Revetment.IO.Test +{ + [TestFixture] + public class WaveConditionsInputStepSizeTypeConverterTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Call + var converter = new WaveConditionsInputStepSizeTypeConverter(); + + // Assert + Assert.IsInstanceOf(converter); + } + + [Test] + public void CanConvertTo_String_ReturnTrue() + { + // Setup + var converter = new WaveConditionsInputStepSizeTypeConverter(); + + // Call + bool canConvertToString = converter.CanConvertTo(typeof(string)); + + // Assert + Assert.IsTrue(canConvertToString); + } + + [Test] + public void CanConvertTo_OtherTypeThenString_ReturnFalse() + { + // Setup + var converter = new WaveConditionsInputStepSizeTypeConverter(); + + // Call + bool canConvertToNonString = converter.CanConvertTo(typeof(object)); + + // Assert + Assert.IsFalse(canConvertToNonString); + } + + [Test] + [SetCulture("nl-NL")] + [TestCase(WaveConditionsInputStepSize.Half, "0,5")] + [TestCase(WaveConditionsInputStepSize.One, "1,0")] + [TestCase(WaveConditionsInputStepSize.Two, "2,0")] + public void ConvertTo_ForAllEnumValues_ReturnExpectedText(WaveConditionsInputStepSize value, + string expectedText) + { + // Setup + var converter = new WaveConditionsInputStepSizeTypeConverter(); + + // Call + object result = converter.ConvertTo(null, CultureInfo.CurrentCulture, value, typeof(string)); + + // Assert + Assert.AreEqual(expectedText, result); + } + + [Test] + public void CanConvertFrom_String_ReturnTrue() + { + // Setup + var converter = new WaveConditionsInputStepSizeTypeConverter(); + + // Call + bool canConvertFromString = converter.CanConvertFrom(typeof(string)); + + // Assert + Assert.IsTrue(canConvertFromString); + } + + [Test] + public void CanConvertFrom_NonString_ReturnFalse() + { + // Setup + var converter = new WaveConditionsInputStepSizeTypeConverter(); + + // Call + bool canConvertFromString = converter.CanConvertFrom(typeof(object)); + + // Assert + Assert.IsFalse(canConvertFromString); + } + + [Test] + [SetCulture("nl-NL")] + [TestCase("0,5", WaveConditionsInputStepSize.Half)] + [TestCase("1,0", WaveConditionsInputStepSize.One)] + [TestCase("2,0", WaveConditionsInputStepSize.Two)] + public void ConvertFrom_VariousCasesInCultureNL_ReturnWaveConditionsInputStepSize(string text, + WaveConditionsInputStepSize expectedResult) + { + // Setup + var converter = new WaveConditionsInputStepSizeTypeConverter(); + + // Call + object result = converter.ConvertFrom(null, CultureInfo.CurrentCulture, text); + + // Assert + Assert.AreEqual(expectedResult, result); + } + + [Test] + [SetCulture("en-US")] + [TestCase("0.5", WaveConditionsInputStepSize.Half)] + [TestCase("1.0", WaveConditionsInputStepSize.One)] + [TestCase("2.0", WaveConditionsInputStepSize.Two)] + public void ConvertFrom_VariousCasesInCultureEN_ReturnWaveConditionsInputStepSize(string text, + WaveConditionsInputStepSize expectedResult) + { + // Setup + var converter = new WaveConditionsInputStepSizeTypeConverter(); + + // Call + object result = converter.ConvertFrom(null, CultureInfo.CurrentCulture, text); + + // Assert + Assert.AreEqual(expectedResult, result); + } + + [Test] + [SetCulture("nl-NL")] + public void ConvertFrom_InvalidText_ThrowNotSupportedException() + { + // Setup + var converter = new WaveConditionsInputStepSizeTypeConverter(); + + // Call + TestDelegate call = () => converter.ConvertFrom("1"); + + // Assert + Assert.Throws(call); + } + } +} \ No newline at end of file