Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj
===================================================================
diff -u -r9ee8f17742a5407fd9453aeb12f20cfedb20c73e -r6913ef75b5ec527ab771006f3430cfafef8b680c
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 9ee8f17742a5407fd9453aeb12f20cfedb20c73e)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 6913ef75b5ec527ab771006f3430cfafef8b680c)
@@ -67,6 +67,9 @@
+
+ Code
+
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/HeightStructures/HeightStructuresCalculationCreateExtensions.cs
===================================================================
diff -u
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/HeightStructures/HeightStructuresCalculationCreateExtensions.cs (revision 0)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/HeightStructures/HeightStructuresCalculationCreateExtensions.cs (revision 6913ef75b5ec527ab771006f3430cfafef8b680c)
@@ -0,0 +1,108 @@
+// 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 Application.Ringtoets.Storage.DbContext;
+using Core.Common.Utils.Extensions;
+using Ringtoets.HeightStructures.Data;
+
+namespace Application.Ringtoets.Storage.Create.HeightStructures
+{
+ ///
+ /// Extension methods for related
+ /// to creating a .
+ ///
+ internal static class HeightStructuresCalculationCreateExtensions
+ {
+ ///
+ /// Creates a based
+ /// on the information of the .
+ ///
+ /// The calculation to create a database entity for.
+ /// The object keeping track of create operations.
+ /// The index at where resides
+ /// in its parent container.
+ /// A new .
+ /// Thrown when is null.
+ internal static HeightStructuresCalculationEntity Create(this HeightStructuresCalculation calculation, PersistenceRegistry registry, int order)
+ {
+ if (registry == null)
+ {
+ throw new ArgumentNullException("registry");
+ }
+
+ var entity = new HeightStructuresCalculationEntity
+ {
+ Name = calculation.Name.DeepClone(),
+ Comments = calculation.Comments.DeepClone(),
+ Order = order
+ };
+ SetInputValues(entity, calculation.InputParameters, registry);
+
+ return entity;
+ }
+
+ private static void SetInputValues(HeightStructuresCalculationEntity entity, HeightStructuresInput input, PersistenceRegistry registry)
+ {
+ if (input.HydraulicBoundaryLocation != null)
+ {
+ entity.HydraulicLocationEntity = registry.Get(input.HydraulicBoundaryLocation);
+ }
+ if (input.Structure != null)
+ {
+ entity.HeightStructureEntity = registry.Get(input.Structure);
+ }
+ if (input.ForeshoreProfile != null)
+ {
+ entity.ForeshoreProfileEntity = registry.Get(input.ForeshoreProfile);
+ }
+ entity.StructureNormalOrientation = input.StructureNormalOrientation.Value.ToNaNAsNull();
+
+ entity.ModelFactorSuperCriticalFlowMean = input.ModelFactorSuperCriticalFlow.Mean.Value.ToNaNAsNull();
+ entity.AllowedLevelIncreaseStorageMean = input.AllowedLevelIncreaseStorage.Mean.Value.ToNaNAsNull();
+ entity.AllowedLevelIncreaseStorageStandardDeviation = input.AllowedLevelIncreaseStorage.StandardDeviation.Value.ToNaNAsNull();
+
+ entity.StorageStructureAreaMean = input.StorageStructureArea.Mean.Value.ToNaNAsNull();
+ entity.StorageStructureAreaCoefficientOfVariation = input.StorageStructureArea.CoefficientOfVariation.Value.ToNaNAsNull();
+
+ entity.FlowWidthAtBottomProtectionMean = input.FlowWidthAtBottomProtection.Mean.Value.ToNaNAsNull();
+ entity.FlowWidthAtBottomProtectionStandardDeviation = input.FlowWidthAtBottomProtection.StandardDeviation.Value.ToNaNAsNull();
+
+ entity.CriticalOvertoppingDischargeMean = input.CriticalOvertoppingDischarge.Mean.Value.ToNaNAsNull();
+ entity.CriticalOvertoppingDischargeCoefficientOfVariation = input.CriticalOvertoppingDischarge.CoefficientOfVariation.Value.ToNaNAsNull();
+
+ entity.FailureProbabilityStructureWithErosion = input.FailureProbabilityStructureWithErosion.ToNaNAsNull();
+
+ entity.WidthFlowAperturesMean = input.WidthFlowApertures.Mean.Value.ToNaNAsNull();
+ entity.WidthFlowAperturesCoefficientOfVariation = input.WidthFlowApertures.CoefficientOfVariation.Value.ToNaNAsNull();
+
+ entity.StormDurationMean = input.StormDuration.Mean.Value.ToNaNAsNull();
+ entity.LevelCrestStructureMean = input.LevelCrestStructure.Mean.Value.ToNaNAsNull();
+ entity.LevelCrestStructureStandardDeviation = input.LevelCrestStructure.StandardDeviation.Value.ToNaNAsNull();
+ entity.DeviationWaveDirection = input.DeviationWaveDirection.Value.ToNaNAsNull();
+
+ entity.BreakWaterHeight = input.BreakWater.Height.Value.ToNaNAsNull();
+ entity.BreakWaterType = Convert.ToInt16(input.BreakWater.Type);
+ entity.UseBreakWater = Convert.ToByte(input.UseBreakWater);
+ entity.UseForeshore = Convert.ToByte(input.UseForeshore);
+ }
+ }
+}
\ No newline at end of file
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj
===================================================================
diff -u -r9ee8f17742a5407fd9453aeb12f20cfedb20c73e -r6913ef75b5ec527ab771006f3430cfafef8b680c
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 9ee8f17742a5407fd9453aeb12f20cfedb20c73e)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 6913ef75b5ec527ab771006f3430cfafef8b680c)
@@ -83,6 +83,9 @@
+
+ Code
+
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/HeightStructures/HeightStructuresCalculationCreateExtensionsTest.cs
===================================================================
diff -u
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/HeightStructures/HeightStructuresCalculationCreateExtensionsTest.cs (revision 0)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/HeightStructures/HeightStructuresCalculationCreateExtensionsTest.cs (revision 6913ef75b5ec527ab771006f3430cfafef8b680c)
@@ -0,0 +1,347 @@
+// 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 Application.Ringtoets.Storage.Create;
+using Application.Ringtoets.Storage.Create.HeightStructures;
+using Application.Ringtoets.Storage.DbContext;
+using Application.Ringtoets.Storage.TestUtil;
+using Core.Common.Base.Data;
+using NUnit.Framework;
+using Ringtoets.Common.Data.DikeProfiles;
+using Ringtoets.HeightStructures.Data;
+using Ringtoets.HeightStructures.Data.TestUtil;
+using Ringtoets.HydraRing.Data;
+
+namespace Application.Ringtoets.Storage.Test.Create.HeightStructures
+{
+ [TestFixture]
+ public class HeightStructuresCalculationCreateExtensionsTest
+ {
+ [Test]
+ public void Create_PersistenceRegistryNull_ThrowArgumentNullException()
+ {
+ // Setup
+ var calculation = new HeightStructuresCalculation();
+
+ // Call
+ TestDelegate call = () => calculation.Create(null, 0);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("registry", paramName);
+ }
+
+ [Test]
+ [TestCase("I have no comments", null, 0, 827364)]
+ [TestCase("I have a comment", "I am comment", 98, 231)]
+ public void Create_ValidCalculation_ReturnEntity(string name, string comments, int order, int randomSeed)
+ {
+ // Setup
+ var random = new Random(randomSeed);
+
+ var calculation = new HeightStructuresCalculation
+ {
+ Name = name,
+ Comments = comments,
+ InputParameters =
+ {
+ StructureNormalOrientation = (RoundedDouble) GetRandomDoubleFromRange(random, 0, 360),
+ ModelFactorSuperCriticalFlow =
+ {
+ Mean = (RoundedDouble) GetRandomDoubleFromRange(random, -9999.9999, 9999.9999)
+ },
+ AllowedLevelIncreaseStorage =
+ {
+ Mean = (RoundedDouble) GetRandomDoubleFromRange(random, 1e-6, 9999.9999),
+ StandardDeviation = (RoundedDouble) GetRandomDoubleFromRange(random, 1e-6, 9999.9999)
+ },
+ StorageStructureArea =
+ {
+ Mean = (RoundedDouble) GetRandomDoubleFromRange(random, 1e-6, 9999.9999),
+ CoefficientOfVariation = (RoundedDouble) GetRandomDoubleFromRange(random, 1e-6, 9999.9999)
+ },
+ FlowWidthAtBottomProtection =
+ {
+ Mean = (RoundedDouble) GetRandomDoubleFromRange(random, 1e-6, 9999.9999),
+ StandardDeviation = (RoundedDouble) GetRandomDoubleFromRange(random, 1e-6, 9999.9999)
+ },
+ CriticalOvertoppingDischarge =
+ {
+ Mean = (RoundedDouble) GetRandomDoubleFromRange(random, 1e-6, 9999.9999),
+ CoefficientOfVariation = (RoundedDouble) GetRandomDoubleFromRange(random, 1e-6, 9999.9999)
+ },
+ FailureProbabilityStructureWithErosion = random.NextDouble(),
+ WidthFlowApertures =
+ {
+ Mean = (RoundedDouble) GetRandomDoubleFromRange(random, -9999.9999, 9999.9999),
+ CoefficientOfVariation = (RoundedDouble) GetRandomDoubleFromRange(random, 1e-6, 9999.9999)
+ },
+ StormDuration =
+ {
+ Mean = (RoundedDouble) GetRandomDoubleFromRange(random, 1e-6, 9999.9999),
+ CoefficientOfVariation = (RoundedDouble) GetRandomDoubleFromRange(random, 1e-6, 9999.9999)
+ },
+ DeviationWaveDirection = (RoundedDouble) random.NextDouble(),
+ LevelCrestStructure =
+ {
+ Mean = (RoundedDouble) GetRandomDoubleFromRange(random, -9999.9999, 9999.9999),
+ StandardDeviation = (RoundedDouble) GetRandomDoubleFromRange(random, 1e-6, 9999.9999)
+ },
+ UseBreakWater = true,
+ UseForeshore = false,
+ BreakWater =
+ {
+ Height = (RoundedDouble) random.NextDouble(),
+ Type = BreakWaterType.Dam
+ }
+ }
+ };
+
+ var registry = new PersistenceRegistry();
+
+ // Call
+ HeightStructuresCalculationEntity entity = calculation.Create(registry, order);
+
+ // Assert
+ Assert.AreEqual(0, entity.HeightStructuresCalculationEntityId);
+ Assert.AreEqual(name, entity.Name);
+ Assert.AreEqual(comments, entity.Comments);
+ Assert.AreEqual(order, entity.Order);
+
+ HeightStructuresInput input = calculation.InputParameters;
+ Assert.AreEqual(input.StructureNormalOrientation.Value, entity.StructureNormalOrientation);
+ Assert.AreEqual(input.ModelFactorSuperCriticalFlow.Mean.Value, entity.ModelFactorSuperCriticalFlowMean);
+ Assert.AreEqual(input.AllowedLevelIncreaseStorage.Mean.Value, entity.AllowedLevelIncreaseStorageMean);
+ Assert.AreEqual(input.AllowedLevelIncreaseStorage.StandardDeviation.Value, entity.AllowedLevelIncreaseStorageStandardDeviation);
+ Assert.AreEqual(input.StorageStructureArea.Mean.Value, entity.StorageStructureAreaMean);
+ Assert.AreEqual(input.StorageStructureArea.CoefficientOfVariation.Value, entity.StorageStructureAreaCoefficientOfVariation);
+ Assert.AreEqual(input.FlowWidthAtBottomProtection.Mean.Value, entity.FlowWidthAtBottomProtectionMean);
+ Assert.AreEqual(input.FlowWidthAtBottomProtection.StandardDeviation.Value, entity.FlowWidthAtBottomProtectionStandardDeviation);
+ Assert.AreEqual(input.CriticalOvertoppingDischarge.Mean.Value, entity.CriticalOvertoppingDischargeMean);
+ Assert.AreEqual(input.CriticalOvertoppingDischarge.CoefficientOfVariation.Value, entity.CriticalOvertoppingDischargeCoefficientOfVariation);
+ Assert.AreEqual(input.FailureProbabilityStructureWithErosion, entity.FailureProbabilityStructureWithErosion);
+ Assert.AreEqual(input.WidthFlowApertures.Mean.Value, entity.WidthFlowAperturesMean);
+ Assert.AreEqual(input.WidthFlowApertures.CoefficientOfVariation.Value, entity.WidthFlowAperturesCoefficientOfVariation);
+ Assert.AreEqual(input.StormDuration.Mean.Value, entity.StormDurationMean);
+
+ Assert.AreEqual(input.LevelCrestStructure.Mean.Value, entity.LevelCrestStructureMean);
+ Assert.AreEqual(input.LevelCrestStructure.StandardDeviation.Value, entity.LevelCrestStructureStandardDeviation);
+ Assert.AreEqual(input.DeviationWaveDirection.Value, entity.DeviationWaveDirection);
+
+ Assert.IsNull(entity.CalculationGroupEntity);
+ Assert.IsNull(entity.ForeshoreProfileEntityId);
+ Assert.IsNull(entity.HeightStructureEntityId);
+ Assert.IsNull(entity.HydraulicLocationEntityId);
+
+ Assert.AreEqual(input.BreakWater.Height.Value, entity.BreakWaterHeight);
+ Assert.AreEqual((short) input.BreakWater.Type, entity.BreakWaterType);
+ Assert.AreEqual(Convert.ToByte(input.UseBreakWater), entity.UseBreakWater);
+ Assert.AreEqual(Convert.ToByte(input.UseForeshore), entity.UseForeshore);
+ }
+
+ [Test]
+ public void Create_NaNParameters_EntityWithNullFields()
+ {
+ // Setup
+ var calculation = new HeightStructuresCalculation
+ {
+ InputParameters =
+ {
+ StructureNormalOrientation = (RoundedDouble) double.NaN,
+ ModelFactorSuperCriticalFlow =
+ {
+ Mean = (RoundedDouble) double.NaN
+ },
+ AllowedLevelIncreaseStorage =
+ {
+ Mean = (RoundedDouble) double.NaN,
+ StandardDeviation = (RoundedDouble) double.NaN
+ },
+ StorageStructureArea =
+ {
+ Mean = (RoundedDouble) double.NaN,
+ CoefficientOfVariation = (RoundedDouble) double.NaN
+ },
+ FlowWidthAtBottomProtection =
+ {
+ Mean = (RoundedDouble) double.NaN,
+ StandardDeviation = (RoundedDouble) double.NaN
+ },
+ CriticalOvertoppingDischarge =
+ {
+ Mean = (RoundedDouble) double.NaN,
+ CoefficientOfVariation = (RoundedDouble) double.NaN
+ },
+ WidthFlowApertures =
+ {
+ Mean = (RoundedDouble) double.NaN,
+ CoefficientOfVariation = (RoundedDouble) double.NaN
+ },
+ StormDuration =
+ {
+ Mean = (RoundedDouble) double.NaN,
+ CoefficientOfVariation = (RoundedDouble) double.NaN
+ },
+ LevelCrestStructure =
+ {
+ Mean = (RoundedDouble) double.NaN,
+ StandardDeviation = (RoundedDouble) double.NaN
+ },
+ DeviationWaveDirection = (RoundedDouble) double.NaN,
+ BreakWater =
+ {
+ Height = (RoundedDouble) double.NaN
+ }
+ }
+ };
+ var registry = new PersistenceRegistry();
+
+ // Call
+ HeightStructuresCalculationEntity entity = calculation.Create(registry, 0);
+
+ // Assert
+ Assert.IsNull(entity.StructureNormalOrientation);
+ Assert.IsNull(entity.ModelFactorSuperCriticalFlowMean);
+ Assert.IsNull(entity.AllowedLevelIncreaseStorageMean);
+ Assert.IsNull(entity.AllowedLevelIncreaseStorageStandardDeviation);
+ Assert.IsNull(entity.StorageStructureAreaMean);
+ Assert.IsNull(entity.StorageStructureAreaCoefficientOfVariation);
+ Assert.IsNull(entity.FlowWidthAtBottomProtectionMean);
+ Assert.IsNull(entity.FlowWidthAtBottomProtectionStandardDeviation);
+ Assert.IsNull(entity.CriticalOvertoppingDischargeMean);
+ Assert.IsNull(entity.CriticalOvertoppingDischargeCoefficientOfVariation);
+ Assert.IsNull(entity.WidthFlowAperturesMean);
+ Assert.IsNull(entity.WidthFlowAperturesCoefficientOfVariation);
+ Assert.IsNull(entity.StormDurationMean);
+ Assert.IsNull(entity.DeviationWaveDirection);
+ Assert.IsNull(entity.LevelCrestStructureMean);
+ Assert.IsNull(entity.LevelCrestStructureStandardDeviation);
+
+ Assert.IsNull(entity.BreakWaterHeight);
+ }
+
+ [Test]
+ public void Create_StringPropertiesDoNotShareReference()
+ {
+ // Setup
+ const string name = "A";
+ const string comment = "B";
+ var calculation = new HeightStructuresCalculation
+ {
+ Name = name,
+ Comments = comment
+ };
+
+ var registry = new PersistenceRegistry();
+
+ // Call
+ HeightStructuresCalculationEntity entity = calculation.Create(registry, 0);
+
+ // Assert
+ Assert.AreNotSame(name, entity.Name,
+ "To create stable binary representations/fingerprints, it's really important that strings are not shared.");
+ Assert.AreEqual(name, entity.Name);
+
+ Assert.AreNotSame(comment, entity.Comments,
+ "To create stable binary representations/fingerprints, it's really important that strings are not shared.");
+ Assert.AreEqual(comment, entity.Comments);
+ }
+
+ [Test]
+ public void Create_CalculationWithAlreadySavedHydraulicBoundaryLocation_ReturnEntityWithHydraulicLocationEntity()
+ {
+ // Setup
+ var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "A", 1, 1);
+ var calculation = new HeightStructuresCalculation
+ {
+ InputParameters =
+ {
+ HydraulicBoundaryLocation = hydraulicBoundaryLocation
+ }
+ };
+
+ var hydraulicLocationEntity = new HydraulicLocationEntity();
+ var registry = new PersistenceRegistry();
+ registry.Register(hydraulicLocationEntity, hydraulicBoundaryLocation);
+
+ // Call
+ HeightStructuresCalculationEntity entity = calculation.Create(registry, 0);
+
+ // Assert
+ Assert.AreSame(hydraulicLocationEntity, entity.HydraulicLocationEntity);
+ }
+
+ [Test]
+ public void Create_CalculationWithAlreadySavedHeightStructure_ReturnEntityWithHeightStructureEntity()
+ {
+ // Setup
+ var heightStructure = new TestHeightStructure();
+ var calculation = new HeightStructuresCalculation
+ {
+ InputParameters =
+ {
+ Structure = heightStructure
+ }
+ };
+
+ var heightStructureEntity = new HeightStructureEntity();
+ var registry = new PersistenceRegistry();
+ registry.Register(heightStructureEntity, heightStructure);
+
+ // Call
+ HeightStructuresCalculationEntity entity = calculation.Create(registry, 0);
+
+ // Assert
+ Assert.AreSame(heightStructureEntity, entity.HeightStructureEntity);
+ }
+
+ [Test]
+ public void Create_CalculationWithAlreadySavedForeshoreProfile_ReturnEntityWithForeshoreProfileEntity()
+ {
+ // Setup
+ var foreshoreProfile = new TestForeshoreProfile();
+ var calculation = new HeightStructuresCalculation
+ {
+ InputParameters =
+ {
+ ForeshoreProfile = foreshoreProfile
+ }
+ };
+
+ var foreshoreProfileEntity = new ForeshoreProfileEntity();
+ var registry = new PersistenceRegistry();
+ registry.Register(foreshoreProfileEntity, foreshoreProfile);
+
+ // Call
+ HeightStructuresCalculationEntity entity = calculation.Create(registry, 0);
+
+ // Assert
+ Assert.AreSame(foreshoreProfileEntity, entity.ForeshoreProfileEntity);
+ }
+
+ private static double GetRandomDoubleFromRange(Random random, double lowerLimit, double upperLimit)
+ {
+ double difference = upperLimit - lowerLimit;
+ return lowerLimit + random.NextDouble()*difference;
+ }
+ }
+}
\ No newline at end of file