Index: Ringtoets/Common/src/Ringtoets.Common.Service/IllustrationPoints/CombinationTypeConverter.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Service/IllustrationPoints/CombinationTypeConverter.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Service/IllustrationPoints/CombinationTypeConverter.cs (revision c883bd5e03754a2a020f36683abb0e4c9d324d2d) @@ -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 System.ComponentModel; +using Ringtoets.Common.Data.IllustrationPoints; +using HydraRingCombinationType = Ringtoets.HydraRing.Calculation.Data.Output.IllustrationPoints.CombinationType; + +namespace Ringtoets.Common.Service.IllustrationPoints +{ + /// + /// The converter that converts data into data. + /// + public static class CombinationTypeConverter + { + /// + /// Creates a based on . + /// + /// The + /// to convert. + /// The . + /// Thrown when + /// has an invalid value. + public static CombinationType Create(HydraRingCombinationType hydraRingCombinationType) + { + switch (hydraRingCombinationType) + { + case HydraRingCombinationType.Or: + return CombinationType.Or; + case HydraRingCombinationType.And: + return CombinationType.And; + default: + throw new InvalidEnumArgumentException(nameof(hydraRingCombinationType), + (int) hydraRingCombinationType, + typeof(HydraRingCombinationType)); + } + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Service/IllustrationPoints/FaultTreeIllustrationPointConverter.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Service/IllustrationPoints/FaultTreeIllustrationPointConverter.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Service/IllustrationPoints/FaultTreeIllustrationPointConverter.cs (revision c883bd5e03754a2a020f36683abb0e4c9d324d2d) @@ -0,0 +1,63 @@ +// 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 System.Collections.Generic; +using System.Linq; +using Ringtoets.Common.Data.IllustrationPoints; +using HydraRingFaultTreeIllustrationPoint = Ringtoets.HydraRing.Calculation.Data.Output.IllustrationPoints.FaultTreeIllustrationPoint; + +namespace Ringtoets.Common.Service.IllustrationPoints +{ + /// + /// The converter that converts data into + /// data. + /// + public static class FaultTreeIllustrationPointConverter + { + /// + /// Creates a new instance of based on the + /// information of . + /// + /// The + /// to base the to create on. + /// The newly created . + /// Thrown when + /// is null. + public static FaultTreeIllustrationPoint Create(HydraRingFaultTreeIllustrationPoint hydraRingFaultTreeIllustrationPoint) + { + if (hydraRingFaultTreeIllustrationPoint == null) + { + throw new ArgumentNullException(nameof(hydraRingFaultTreeIllustrationPoint)); + } + + IEnumerable stochasts = hydraRingFaultTreeIllustrationPoint + .Stochasts.Select(StochastConverter.CreateStochast); + + CombinationType combinationType = CombinationTypeConverter.Create(hydraRingFaultTreeIllustrationPoint.CombinationType); + + return new FaultTreeIllustrationPoint(hydraRingFaultTreeIllustrationPoint.Name, + hydraRingFaultTreeIllustrationPoint.Beta, + stochasts, + combinationType); + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Service/Ringtoets.Common.Service.csproj =================================================================== diff -u -r461842cc9a0a60d00900065b9a7db474db7d7548 -rc883bd5e03754a2a020f36683abb0e4c9d324d2d --- Ringtoets/Common/src/Ringtoets.Common.Service/Ringtoets.Common.Service.csproj (.../Ringtoets.Common.Service.csproj) (revision 461842cc9a0a60d00900065b9a7db474db7d7548) +++ Ringtoets/Common/src/Ringtoets.Common.Service/Ringtoets.Common.Service.csproj (.../Ringtoets.Common.Service.csproj) (revision c883bd5e03754a2a020f36683abb0e4c9d324d2d) @@ -48,6 +48,8 @@ + + Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/IllustrationPoints/CombinationTypeConverterTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/IllustrationPoints/CombinationTypeConverterTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/IllustrationPoints/CombinationTypeConverterTest.cs (revision c883bd5e03754a2a020f36683abb0e4c9d324d2d) @@ -0,0 +1,60 @@ +// 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 System.ComponentModel; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Service.IllustrationPoints; +using HydraRingCombinationType = Ringtoets.HydraRing.Calculation.Data.Output.IllustrationPoints.CombinationType; + +namespace Ringtoets.Common.Service.Test.IllustrationPoints +{ + [TestFixture] + public class CombinationTypeConverterTest + { + [Test] + public void Create_InvalidEnumValue_ThrowsInvalidEnumArgumentException() + { + // Call + TestDelegate test = () => CombinationTypeConverter.Create((HydraRingCombinationType) 99); + + // Assert + const string message = "The value of argument 'hydraRingCombinationType' (99) is invalid for Enum type 'CombinationType'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, message); + } + + [Test] + public void Create_ValidHydraRingCombinationType_ReturnCombinationType() + { + // Setup + var random = new Random(); + var hydraRingCombinationType = random.NextEnumValue(); + + // Call + CombinationType combinationType = CombinationTypeConverter.Create(hydraRingCombinationType); + + // Assert + Assert.AreEqual((int) hydraRingCombinationType, (int) combinationType); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/IllustrationPoints/FaultTreeIllustrationPointConverterTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/IllustrationPoints/FaultTreeIllustrationPointConverterTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/IllustrationPoints/FaultTreeIllustrationPointConverterTest.cs (revision c883bd5e03754a2a020f36683abb0e4c9d324d2d) @@ -0,0 +1,78 @@ +// 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 System.Linq; +using NUnit.Framework; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Service.IllustrationPoints; +using HydraRingCombinationType = Ringtoets.HydraRing.Calculation.Data.Output.IllustrationPoints.CombinationType; +using HydraRingFaultTreeIllustrationPoint = Ringtoets.HydraRing.Calculation.Data.Output.IllustrationPoints.FaultTreeIllustrationPoint; +using HydraRingStochast = Ringtoets.HydraRing.Calculation.Data.Output.IllustrationPoints.Stochast; + +namespace Ringtoets.Common.Service.Test.IllustrationPoints +{ + [TestFixture] + public class FaultTreeIllustrationPointConverterTest + { + [Test] + public void CreateIllustrationPoint_HydraRingFaultTreeIllustrationPointNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => FaultTreeIllustrationPointConverter.Create(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("hydraRingFaultTreeIllustrationPoint", paramName); + } + + [Test] + public void Create_ValidArguments_ExpectedProperties() + { + // Setup + var random = new Random(21); + + const string name = "hydraRingStochast"; + double alpha = random.NextDouble(); + double duration = random.NextDouble(); + var hydraRingStochast = new HydraRingStochast(name, duration, alpha); + + double beta = random.NextDouble(); + var hydraRingFaultTreeIllustrationPoint = new HydraRingFaultTreeIllustrationPoint("name", beta, HydraRingCombinationType.And); + hydraRingFaultTreeIllustrationPoint.Stochasts.Add(hydraRingStochast); + + // Call + FaultTreeIllustrationPoint faultTreeIllustrationPoint = + FaultTreeIllustrationPointConverter.Create(hydraRingFaultTreeIllustrationPoint); + + // Assert + Assert.AreEqual(hydraRingFaultTreeIllustrationPoint.Beta, faultTreeIllustrationPoint.Beta, faultTreeIllustrationPoint.Beta.GetAccuracy()); + Assert.AreEqual(hydraRingFaultTreeIllustrationPoint.Name, faultTreeIllustrationPoint.Name); + Assert.AreEqual((int)hydraRingFaultTreeIllustrationPoint.CombinationType, (int)faultTreeIllustrationPoint.CombinationType); + + Stochast stochast = faultTreeIllustrationPoint.Stochasts.Single(); + Assert.AreEqual(hydraRingStochast.Alpha, stochast.Alpha, stochast.Alpha.GetAccuracy()); + Assert.AreEqual(hydraRingStochast.Duration, stochast.Duration, stochast.Duration.GetAccuracy()); + Assert.AreEqual(hydraRingStochast.Name, stochast.Name); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/IllustrationPoints/SubMechanismIllustrationPointConverterTest.cs =================================================================== diff -u -r6eabea7a72771b62ff8b173b9b37f5b89ed403f3 -rc883bd5e03754a2a020f36683abb0e4c9d324d2d --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/IllustrationPoints/SubMechanismIllustrationPointConverterTest.cs (.../SubMechanismIllustrationPointConverterTest.cs) (revision 6eabea7a72771b62ff8b173b9b37f5b89ed403f3) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/IllustrationPoints/SubMechanismIllustrationPointConverterTest.cs (.../SubMechanismIllustrationPointConverterTest.cs) (revision c883bd5e03754a2a020f36683abb0e4c9d324d2d) @@ -83,7 +83,7 @@ SubMechanismIllustrationPointStochast stochast = subMechanismIllustrationPoint.Stochasts.Single(); Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Alpha, stochast.Alpha, stochast.Alpha.GetAccuracy()); - Assert.AreEqual(duration, stochast.Duration, stochast.Duration.GetAccuracy()); + Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Duration, stochast.Duration, stochast.Duration.GetAccuracy()); Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Name, stochast.Name); Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Realization, stochast.Realization, stochast.Realization.GetAccuracy()); } Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj =================================================================== diff -u -rc6997df2bf70eaf7ac4d3e8268e53c42f8a8896c -rc883bd5e03754a2a020f36683abb0e4c9d324d2d --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj (.../Ringtoets.Common.Service.Test.csproj) (revision c6997df2bf70eaf7ac4d3e8268e53c42f8a8896c) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj (.../Ringtoets.Common.Service.Test.csproj) (revision c883bd5e03754a2a020f36683abb0e4c9d324d2d) @@ -65,7 +65,9 @@ + +