Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj
===================================================================
diff -u -r650bc408cf4cc755aed422ea1b07d31e4cca11ec -r790cfed116a6bd0d34eae8b66dae8dfc66774c86
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 650bc408cf4cc755aed422ea1b07d31e4cca11ec)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 790cfed116a6bd0d34eae8b66dae8dfc66774c86)
@@ -388,6 +388,7 @@
+
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/HydraulicLocationCalculationEntityReadExtensions.cs
===================================================================
diff -u
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/HydraulicLocationCalculationEntityReadExtensions.cs (revision 0)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/HydraulicLocationCalculationEntityReadExtensions.cs (revision 790cfed116a6bd0d34eae8b66dae8dfc66774c86)
@@ -0,0 +1,64 @@
+// 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 Application.Ringtoets.Storage.DbContext;
+using Ringtoets.Common.Data.Hydraulics;
+
+namespace Application.Ringtoets.Storage.Read
+{
+ ///
+ /// This class defines extension methods for read operations for a based on the
+ /// .
+ ///
+ internal static class HydraulicLocationCalculationEntityReadExtensions
+ {
+ ///
+ /// Reads the and use the information to construct a
+ /// .
+ ///
+ /// The to update the
+ /// .
+ /// The target of the read operation.
+ /// Thrown when any parameter is null.
+ internal static void Read(this HydraulicLocationCalculationEntity entity,
+ HydraulicBoundaryLocationCalculation calculation)
+ {
+ if (entity == null)
+ {
+ throw new ArgumentNullException(nameof(entity));
+ }
+
+ if (calculation == null)
+ {
+ throw new ArgumentNullException(nameof(calculation));
+ }
+
+ calculation.InputParameters.ShouldIllustrationPointsBeCalculated = Convert.ToBoolean(entity.ShouldIllustrationPointsBeCalculated);
+ HydraulicLocationOutputEntity outputEntity = entity.HydraulicLocationOutputEntities.SingleOrDefault();
+ if (outputEntity != null)
+ {
+ calculation.Output = outputEntity.Read();
+ }
+ }
+ }
+}
\ No newline at end of file
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj
===================================================================
diff -u -r54a4372151869517f914727339477256a52090f6 -r790cfed116a6bd0d34eae8b66dae8dfc66774c86
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 54a4372151869517f914727339477256a52090f6)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 790cfed116a6bd0d34eae8b66dae8dfc66774c86)
@@ -106,6 +106,7 @@
+
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/HydraulicLocationCalculationEntityReadExtensionsTest.cs
===================================================================
diff -u
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/HydraulicLocationCalculationEntityReadExtensionsTest.cs (revision 0)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/HydraulicLocationCalculationEntityReadExtensionsTest.cs (revision 790cfed116a6bd0d34eae8b66dae8dfc66774c86)
@@ -0,0 +1,215 @@
+// 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 Application.Ringtoets.Storage.DbContext;
+using Core.Common.Base.Data;
+using Core.Common.TestUtil;
+using NUnit.Framework;
+using Ringtoets.Common.Data.Hydraulics;
+using Ringtoets.Common.Data.IllustrationPoints;
+using Ringtoets.Common.Data.TestUtil;
+using Application.Ringtoets.Storage.Read;
+
+namespace Application.Ringtoets.Storage.Test.Read
+{
+ [TestFixture]
+ public class HydraulicLocationCalculationEntityReadExtensionsTest
+ {
+ [Test]
+ public void Read_EntityNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var calculation = new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation());
+
+ // Call
+ TestDelegate call = () => ((HydraulicLocationCalculationEntity)null).Read(calculation);
+
+ // Assert
+ var exception = Assert.Throws(call);
+ Assert.AreEqual("entity", exception.ParamName);
+ }
+
+ [Test]
+ public void Read_HydraulicBoundaryLocationCalculationNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var entity = new HydraulicLocationCalculationEntity();
+
+ // Call
+ TestDelegate call = () => entity.Read(null);
+
+ // Assert
+ var exception = Assert.Throws(call);
+ Assert.AreEqual("calculation", exception.ParamName);
+ }
+
+ [Test]
+ public void Read_CalculationWithoutOutput_HydraulicBoundaryLocationCalculationWithExpectedValues()
+ {
+ // Setup
+ HydraulicLocationCalculationEntity entity = CreateCalculationEntity(21);
+
+ var calculation = new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation());
+
+ // Call
+ entity.Read(calculation);
+
+ // Assert
+ AssertHydraulicBoundaryLocationCalculation(entity, calculation);
+ }
+
+ [Test]
+ public void Read_CalculationWithOutputWithoutIllustrationPoints_HydraulicBoundaryLocationCalculationWithExpectedValues()
+ {
+ // Setup
+ HydraulicLocationCalculationEntity entity = CreateCalculationEntityWithOutputEntity(21);
+
+ var calculation = new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation());
+
+ // Call
+ entity.Read(calculation);
+
+ // Assert
+ AssertHydraulicBoundaryLocationCalculation(entity, calculation);
+ }
+
+ [Test]
+ public void Read_CalculationWithOutputAndIllustrationPoints_HydraulicBoundaryLocationCalculationWithExpectedValues()
+ {
+ // Setup
+ HydraulicLocationCalculationEntity entity = CreateCalculationEntityWithOutputAndGeneralResultEntity(21);
+
+ var calculation = new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation());
+
+ // Call
+ entity.Read(calculation);
+
+ // Assert
+ AssertHydraulicBoundaryLocationCalculation(entity, calculation);
+ }
+
+
+ private static HydraulicLocationCalculationEntity CreateCalculationEntity(int seed)
+ {
+ var random = new Random(seed);
+
+ return new HydraulicLocationCalculationEntity
+ {
+ ShouldIllustrationPointsBeCalculated = Convert.ToByte(random.NextBoolean())
+ };
+ }
+
+ private static HydraulicLocationOutputEntity CreateHydraulicOutputEntity(int seed)
+ {
+ var random = new Random(seed);
+ var hydraulicLocationOutputEntity = new HydraulicLocationOutputEntity
+ {
+ Result = random.NextDouble(),
+ TargetProbability = random.NextDouble(),
+ TargetReliability = random.NextDouble(),
+ CalculatedProbability = random.NextDouble(),
+ CalculatedReliability = random.NextDouble(),
+ CalculationConvergence = (byte)CalculationConvergence.NotCalculated
+ };
+ return hydraulicLocationOutputEntity;
+ }
+
+ private static HydraulicLocationCalculationEntity CreateCalculationEntityWithOutputEntity(int seed)
+ {
+ HydraulicLocationCalculationEntity calculationEntity = CreateCalculationEntity(seed);
+ calculationEntity.HydraulicLocationOutputEntities.Add(CreateHydraulicOutputEntity(seed));
+
+ return calculationEntity;
+ }
+
+ private static HydraulicLocationCalculationEntity CreateCalculationEntityWithOutputAndGeneralResultEntity(int seed)
+ {
+ var random = new Random(seed);
+ var generalResultEntity = new GeneralResultSubMechanismIllustrationPointEntity
+ {
+ GoverningWindDirectionName = "A wind direction",
+ GoverningWindDirectionAngle = random.NextDouble()
+ };
+
+ HydraulicLocationOutputEntity hydraulicLocationOutputEntity = CreateHydraulicOutputEntity(seed);
+ hydraulicLocationOutputEntity.GeneralResultSubMechanismIllustrationPointEntity = generalResultEntity;
+
+ HydraulicLocationCalculationEntity calculationEntity = CreateCalculationEntity(seed);
+ calculationEntity.HydraulicLocationOutputEntities.Add(hydraulicLocationOutputEntity);
+
+ return calculationEntity;
+ }
+
+ private static void AssertHydraulicBoundaryLocationCalculation(HydraulicLocationCalculationEntity expected,
+ HydraulicBoundaryLocationCalculation actual)
+ {
+ Assert.AreEqual(Convert.ToBoolean(expected.ShouldIllustrationPointsBeCalculated),
+ actual.InputParameters.ShouldIllustrationPointsBeCalculated);
+
+ AssertHydraulicBoundaryLocationOutput(expected.HydraulicLocationOutputEntities.SingleOrDefault(),
+ actual.Output);
+ }
+
+ private static void AssertHydraulicBoundaryLocationOutput(HydraulicLocationOutputEntity expected, HydraulicBoundaryLocationOutput actual)
+ {
+ if (expected == null)
+ {
+ Assert.IsNull(actual);
+ return;
+ }
+
+ Assert.IsNotNull(expected.Result);
+ Assert.AreEqual((RoundedDouble)expected.Result, actual.Result, actual.Result.GetAccuracy());
+ Assert.IsNotNull(expected.TargetReliability);
+ Assert.AreEqual((RoundedDouble)expected.TargetReliability, actual.TargetReliability, actual.TargetReliability.GetAccuracy());
+ Assert.IsNotNull(expected.TargetProbability);
+ Assert.AreEqual(expected.TargetProbability, actual.TargetProbability);
+ Assert.IsNotNull(expected.CalculatedReliability);
+ Assert.AreEqual((RoundedDouble)expected.CalculatedReliability, actual.CalculatedReliability, actual.CalculatedReliability.GetAccuracy());
+ Assert.IsNotNull(expected.CalculatedProbability);
+ Assert.AreEqual(expected.CalculatedProbability, actual.CalculatedProbability);
+ Assert.AreEqual((CalculationConvergence)expected.CalculationConvergence, actual.CalculationConvergence);
+
+ AssertGeneralResult(expected.GeneralResultSubMechanismIllustrationPointEntity, actual.GeneralResult);
+ }
+
+ private static void AssertGeneralResult(GeneralResultSubMechanismIllustrationPointEntity expected,
+ GeneralResult illustrationPoint)
+ {
+ if (expected == null)
+ {
+ Assert.IsNull(illustrationPoint);
+ return;
+ }
+
+ WindDirection actualGoverningWindDirection = illustrationPoint.GoverningWindDirection;
+ Assert.AreEqual(expected.GoverningWindDirectionName, actualGoverningWindDirection.Name);
+ Assert.AreEqual(expected.GoverningWindDirectionAngle, actualGoverningWindDirection.Angle,
+ actualGoverningWindDirection.Angle.GetAccuracy());
+
+ Assert.AreEqual(expected.TopLevelSubMechanismIllustrationPointEntities.Count,
+ illustrationPoint.TopLevelIllustrationPoints.Count());
+ Assert.AreEqual(expected.StochastEntities.Count, illustrationPoint.Stochasts.Count());
+ }
+ }
+}
\ No newline at end of file