Index: Ringtoets/Common/src/Ringtoets.Common.IO/Configurations/Helpers/CalculationScenarioConversionExtensions.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.IO/Configurations/Helpers/CalculationScenarioConversionExtensions.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Configurations/Helpers/CalculationScenarioConversionExtensions.cs (revision fafb2af7750af9da6d84479074522c8035fccd49) @@ -0,0 +1,57 @@ +// 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 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 Ringtoets.Common.Data.Calculation; + +namespace Ringtoets.Common.IO.Configurations.Helpers +{ + /// + /// Extension methods for converting to . + /// + public static class CalculationScenarioConversionExtensions + { + /// + /// Configure a new with + /// and + /// taken from + /// . + /// + /// The calculation scenario to take the values from. + /// A new with + /// and + /// set. + /// Thrown when is null. + public static ScenarioConfiguration ToScenarioConfiguration(this ICalculationScenario calculationScenario) + { + if (calculationScenario == null) + { + throw new ArgumentNullException(nameof(calculationScenario)); + } + + return new ScenarioConfiguration + { + Contribution = calculationScenario.Contribution * 100, + IsRelevant = calculationScenario.IsRelevant + }; + } + } +} \ No newline at end of file Fisheye: Tag fafb2af7750af9da6d84479074522c8035fccd49 refers to a dead (removed) revision in file `Ringtoets/Common/src/Ringtoets.Common.IO/Configurations/Helpers/ICalculationScenarioConversionExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag fafb2af7750af9da6d84479074522c8035fccd49 refers to a dead (removed) revision in file `Ringtoets/Common/src/Ringtoets.Common.IO/Configurations/Helpers/ILogExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Common/src/Ringtoets.Common.IO/Configurations/Helpers/LogExtensions.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.IO/Configurations/Helpers/LogExtensions.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Configurations/Helpers/LogExtensions.cs (revision fafb2af7750af9da6d84479074522c8035fccd49) @@ -0,0 +1,58 @@ +// 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 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 log4net; +using Ringtoets.Common.IO.Properties; + +namespace Ringtoets.Common.IO.Configurations.Helpers +{ + /// + /// Extension methods for for logging problems occurring during import + /// or export of configurations. + /// + public static class LogExtensions + { + /// + /// Logs an out of range exception that was thrown when converting configuration to actual data model instances. + /// + /// The to use for logging. + /// Part of the message that precedes the out of range error message. + /// The name of the calculation for which the exception was thrown. + /// The exception that was thrown. + public static void LogOutOfRangeException(this ILog log, string errorMessage, string calculationName, ArgumentOutOfRangeException exception) + { + log.LogCalculationConversionError($"{errorMessage} {exception.Message}", calculationName); + } + + /// + /// Logs a message for an error which occurred when converting configuration to actual data model instances. + /// + /// The to use for logging. + /// The error message to log. + /// The name of the calculation for which the error occurred. + public static void LogCalculationConversionError(this ILog log, string errorMessage, string calculationName) + { + log.ErrorFormat(Resources.ILogExtensions_LogCalculationConversionError_ErrorMessage_0_Calculation_1_skipped, + errorMessage, calculationName); + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj =================================================================== diff -u -r8e717411be3a9f6947737321832ec2ffe06f43dd -rfafb2af7750af9da6d84479074522c8035fccd49 --- Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision 8e717411be3a9f6947737321832ec2ffe06f43dd) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision fafb2af7750af9da6d84479074522c8035fccd49) @@ -57,8 +57,8 @@ - - + + Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Configurations/Helpers/CalculationScenarioConversionExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Configurations/Helpers/CalculationScenarioConversionExtensionsTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Configurations/Helpers/CalculationScenarioConversionExtensionsTest.cs (revision fafb2af7750af9da6d84479074522c8035fccd49) @@ -0,0 +1,70 @@ +// 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 General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using Core.Common.Base.Data; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.IO.Configurations; +using Ringtoets.Common.IO.Configurations.Helpers; + +namespace Ringtoets.Common.IO.Test.Configurations.Helpers +{ + [TestFixture] + public class CalculationScenarioConversionExtensionsTest + { + [Test] + public void ToScenarioConfiguration_CalculationScenarioNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => ((ICalculationScenario) null).ToScenarioConfiguration(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("calculationScenario", exception.ParamName); + } + + [Test] + public void ToScenarioConfiguration_ValidCalculationScenario_InstanceWithExpectedParametersSet() + { + // Setup + var mocks = new MockRepository(); + var scenario = mocks.Stub(); + mocks.ReplayAll(); + + var random = new Random(21); + RoundedDouble contribution = random.NextRoundedDouble(); + bool relevant = random.NextBoolean(); + + scenario.Contribution = contribution; + scenario.IsRelevant = relevant; + + // Call + ScenarioConfiguration configuration = scenario.ToScenarioConfiguration(); + + // Assert + Assert.AreEqual(contribution * 100, configuration.Contribution); + Assert.AreEqual(relevant, configuration.IsRelevant); + } + } +} \ No newline at end of file Fisheye: Tag fafb2af7750af9da6d84479074522c8035fccd49 refers to a dead (removed) revision in file `Ringtoets/Common/test/Ringtoets.Common.IO.Test/Configurations/Helpers/ICalculationScenarioConversionExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag fafb2af7750af9da6d84479074522c8035fccd49 refers to a dead (removed) revision in file `Ringtoets/Common/test/Ringtoets.Common.IO.Test/Configurations/Helpers/ILogExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Configurations/Helpers/LogExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Configurations/Helpers/LogExtensionsTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Configurations/Helpers/LogExtensionsTest.cs (revision fafb2af7750af9da6d84479074522c8035fccd49) @@ -0,0 +1,74 @@ +// 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 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 log4net; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.IO.Configurations.Helpers; + +namespace Ringtoets.Common.IO.Test.Configurations.Helpers +{ + [TestFixture] + public class LogExtensionsTest + { + [Test] + public void LogOutOfRangeException_Always_LogMessage() + { + // Setup + const string message = "an error"; + const string calculationName = "calculationA"; + const string innerMessage = "Inner message"; + + var mocks = new MockRepository(); + var log = mocks.StrictMock(); + log.Expect(l => l.ErrorFormat("{0} Berekening '{1}' is overgeslagen.", $"{message} {innerMessage}", calculationName)); + mocks.ReplayAll(); + + var exception = new ArgumentOutOfRangeException(null, innerMessage); + + // Call + log.LogOutOfRangeException(message, calculationName, exception); + + // Assert + mocks.VerifyAll(); + } + + [Test] + public void LogCalculationConversionError_Always_LogMessage() + { + // Setup + const string message = "an error"; + const string calculationName = "calculationA"; + + var mocks = new MockRepository(); + var log = mocks.StrictMock(); + log.Expect(l => l.ErrorFormat("{0} Berekening '{1}' is overgeslagen.", message, calculationName)); + mocks.ReplayAll(); + + // Call + log.LogCalculationConversionError(message, calculationName); + + // Assert + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj =================================================================== diff -u -r8e717411be3a9f6947737321832ec2ffe06f43dd -rfafb2af7750af9da6d84479074522c8035fccd49 --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision 8e717411be3a9f6947737321832ec2ffe06f43dd) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision fafb2af7750af9da6d84479074522c8035fccd49) @@ -61,7 +61,7 @@ - +