Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj
===================================================================
diff -u -r32d32b83fc8e0c9b4849361af987da0170549146 -rd86b1c6e4ebde1570bec162a9043bbb437de5d9c
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 32d32b83fc8e0c9b4849361af987da0170549146)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision d86b1c6e4ebde1570bec162a9043bbb437de5d9c)
@@ -173,6 +173,7 @@
+
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Update/AssessmentSectionUpdateExtensions.cs
===================================================================
diff -u -rae6f0c6b534ca650e160ae6d9c0bc90369d25c68 -rd86b1c6e4ebde1570bec162a9043bbb437de5d9c
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Update/AssessmentSectionUpdateExtensions.cs (.../AssessmentSectionUpdateExtensions.cs) (revision ae6f0c6b534ca650e160ae6d9c0bc90369d25c68)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Update/AssessmentSectionUpdateExtensions.cs (.../AssessmentSectionUpdateExtensions.cs) (revision d86b1c6e4ebde1570bec162a9043bbb437de5d9c)
@@ -49,6 +49,8 @@
/// - is null
/// - is null
///
+ /// When
+ /// does not have a corresponding entity in .
internal static void Update(this AssessmentSection section, PersistenceRegistry registry, IRingtoetsEntities context)
{
if (context == null)
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Update/CalculationGroupUpdateExtensions.cs
===================================================================
diff -u -r3fa8664290181eedfdcefbe87f32aa7539d748e3 -rd86b1c6e4ebde1570bec162a9043bbb437de5d9c
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Update/CalculationGroupUpdateExtensions.cs (.../CalculationGroupUpdateExtensions.cs) (revision 3fa8664290181eedfdcefbe87f32aa7539d748e3)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Update/CalculationGroupUpdateExtensions.cs (.../CalculationGroupUpdateExtensions.cs) (revision d86b1c6e4ebde1570bec162a9043bbb437de5d9c)
@@ -48,6 +48,8 @@
/// - is null
/// - is null
///
+ /// When
+ /// does not have a corresponding entity in .
internal static void Update(this CalculationGroup calculationGroup, PersistenceRegistry registry, IRingtoetsEntities context)
{
if (registry == null)
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Update/FailureMechanismSectionUpdateExtensions.cs
===================================================================
diff -u -rae6f0c6b534ca650e160ae6d9c0bc90369d25c68 -rd86b1c6e4ebde1570bec162a9043bbb437de5d9c
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Update/FailureMechanismSectionUpdateExtensions.cs (.../FailureMechanismSectionUpdateExtensions.cs) (revision ae6f0c6b534ca650e160ae6d9c0bc90369d25c68)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Update/FailureMechanismSectionUpdateExtensions.cs (.../FailureMechanismSectionUpdateExtensions.cs) (revision d86b1c6e4ebde1570bec162a9043bbb437de5d9c)
@@ -45,6 +45,8 @@
/// - is null
/// - is null
///
+ /// When
+ /// does not have a corresponding entity in .
internal static void Update(this FailureMechanismSection section, PersistenceRegistry registry, IRingtoetsEntities context)
{
if (context == null)
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Update/GrassCoverErosionInwardsFailureMechanismUpdateExtensions.cs
===================================================================
diff -u -rae6f0c6b534ca650e160ae6d9c0bc90369d25c68 -rd86b1c6e4ebde1570bec162a9043bbb437de5d9c
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Update/GrassCoverErosionInwardsFailureMechanismUpdateExtensions.cs (.../GrassCoverErosionInwardsFailureMechanismUpdateExtensions.cs) (revision ae6f0c6b534ca650e160ae6d9c0bc90369d25c68)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Update/GrassCoverErosionInwardsFailureMechanismUpdateExtensions.cs (.../GrassCoverErosionInwardsFailureMechanismUpdateExtensions.cs) (revision d86b1c6e4ebde1570bec162a9043bbb437de5d9c)
@@ -22,6 +22,8 @@
using System;
using Application.Ringtoets.Storage.Create;
using Application.Ringtoets.Storage.DbContext;
+using Application.Ringtoets.Storage.Exceptions;
+
using Ringtoets.GrassCoverErosionInwards.Data;
namespace Application.Ringtoets.Storage.Update
@@ -43,6 +45,8 @@
/// - is null
/// - is null
///
+ /// When
+ /// does not have a corresponding entity in .
internal static void Update(this GrassCoverErosionInwardsFailureMechanism mechanism, PersistenceRegistry registry, IRingtoetsEntities context)
{
if (context == null)
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Update/HydraulicBoundaryLocationUpdateExtensions.cs
===================================================================
diff -u -rae6f0c6b534ca650e160ae6d9c0bc90369d25c68 -rd86b1c6e4ebde1570bec162a9043bbb437de5d9c
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Update/HydraulicBoundaryLocationUpdateExtensions.cs (.../HydraulicBoundaryLocationUpdateExtensions.cs) (revision ae6f0c6b534ca650e160ae6d9c0bc90369d25c68)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Update/HydraulicBoundaryLocationUpdateExtensions.cs (.../HydraulicBoundaryLocationUpdateExtensions.cs) (revision d86b1c6e4ebde1570bec162a9043bbb437de5d9c)
@@ -47,6 +47,8 @@
/// - is null
/// - is null
///
+ /// When
+ /// does not have a corresponding entity in .
internal static void Update(this HydraulicBoundaryLocation location, PersistenceRegistry registry, IRingtoetsEntities context)
{
if (context == null)
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Update/IFailureMechanismUpdateExtensions.cs
===================================================================
diff -u -r8c78853745e5865dad910b2d9050ac52585daa87 -rd86b1c6e4ebde1570bec162a9043bbb437de5d9c
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Update/IFailureMechanismUpdateExtensions.cs (.../IFailureMechanismUpdateExtensions.cs) (revision 8c78853745e5865dad910b2d9050ac52585daa87)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Update/IFailureMechanismUpdateExtensions.cs (.../IFailureMechanismUpdateExtensions.cs) (revision d86b1c6e4ebde1570bec162a9043bbb437de5d9c)
@@ -46,6 +46,8 @@
/// - is null
/// - is null
///
+ /// When
+ /// does not have a corresponding entity in .
internal static void Update(this IFailureMechanism mechanism, PersistenceRegistry registry, IRingtoetsEntities context)
{
if (context == null)
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Update/PipingCalculationScenarioUpdateExtensions.cs
===================================================================
diff -u
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Update/PipingCalculationScenarioUpdateExtensions.cs (revision 0)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Update/PipingCalculationScenarioUpdateExtensions.cs (revision d86b1c6e4ebde1570bec162a9043bbb437de5d9c)
@@ -0,0 +1,138 @@
+// 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.Linq;
+
+using Application.Ringtoets.Storage.Create;
+using Application.Ringtoets.Storage.DbContext;
+using Application.Ringtoets.Storage.Exceptions;
+using Application.Ringtoets.Storage.Properties;
+
+using Core.Common.Base.Data;
+
+using Ringtoets.Piping.Data;
+
+namespace Application.Ringtoets.Storage.Update
+{
+ ///
+ /// Extension methods for related to updating
+ /// a .
+ ///
+ internal static class PipingCalculationScenarioUpdateExtensions
+ {
+ ///
+ /// Updates a in the database based on the
+ /// information of the .
+ ///
+ /// The piping calculation to update the database entity for.
+ /// The object keeping track of update operations.
+ /// The context to obtain the existing entity from.
+ /// Thrown when either:
+ ///
+ /// - is null
+ /// - is null
+ ///
+ /// When
+ /// does not have a corresponding entity in .
+ internal static void Update(this PipingCalculationScenario calculation, PersistenceRegistry registry, IRingtoetsEntities context)
+ {
+ if (registry == null)
+ {
+ throw new ArgumentNullException("registry");
+ }
+ if (context == null)
+ {
+ throw new ArgumentNullException("context");
+ }
+
+ PipingCalculationEntity entity = GetCorrespondingPipingCalculationEntity(calculation, context);
+ entity.RelevantForScenario = Convert.ToByte(calculation.IsRelevant);
+ entity.ScenarioContribution = Convert.ToDecimal(calculation.Contribution);
+ entity.Name = calculation.Name;
+ entity.Comments = calculation.Comments;
+ SetInputParameters(entity, calculation.InputParameters, registry);
+
+
+ registry.Register(entity, calculation);
+ }
+
+ private static void SetInputParameters(PipingCalculationEntity entity, PipingInput inputParameters, PersistenceRegistry registry)
+ {
+ entity.EntryPointL = GetNullableDecimal(inputParameters.EntryPointL);
+ entity.ExitPointL = GetNullableDecimal(inputParameters.ExitPointL);
+
+ entity.PhreaticLevelExitMean = Convert.ToDecimal(inputParameters.PhreaticLevelExit.Mean);
+ entity.PhreaticLevelExitStandardDeviation = Convert.ToDecimal(inputParameters.PhreaticLevelExit.StandardDeviation);
+ entity.DampingFactorExitMean = Convert.ToDecimal(inputParameters.DampingFactorExit.Mean);
+ entity.DampingFactorExitStandardDeviation = Convert.ToDecimal(inputParameters.DampingFactorExit.StandardDeviation);
+ entity.SaturatedVolumicWeightOfCoverageLayerMean = Convert.ToDecimal(inputParameters.SaturatedVolumicWeightOfCoverageLayer.Mean);
+ entity.SaturatedVolumicWeightOfCoverageLayerStandardDeviation = Convert.ToDecimal(inputParameters.SaturatedVolumicWeightOfCoverageLayer.StandardDeviation);
+ entity.SaturatedVolumicWeightOfCoverageLayerShift = Convert.ToDecimal(inputParameters.SaturatedVolumicWeightOfCoverageLayer.Shift);
+ entity.Diameter70Mean = Convert.ToDecimal(inputParameters.Diameter70.Mean);
+ entity.Diameter70StandardDeviation = Convert.ToDecimal(inputParameters.Diameter70.StandardDeviation);
+ entity.DarcyPermeabilityMean = Convert.ToDecimal(inputParameters.DarcyPermeability.Mean);
+ entity.DarcyPermeabilityStandardDeviation = Convert.ToDecimal(inputParameters.DarcyPermeability.StandardDeviation);
+
+ entity.SurfaceLineEntity = inputParameters.SurfaceLine == null ?
+ null :
+ registry.Get(inputParameters.SurfaceLine);
+ entity.HydraulicLocationEntity = inputParameters.HydraulicBoundaryLocation == null ?
+ null :
+ registry.Get(inputParameters.HydraulicBoundaryLocation);
+ entity.StochasticSoilProfileEntity = inputParameters.StochasticSoilProfile == null ?
+ null :
+ registry.Get(inputParameters.StochasticSoilProfile);
+ }
+
+ ///
+ /// Gets the based on the .
+ ///
+ /// The piping calculation corresponding with the failure mechanism entity.
+ /// The context to obtain the existing entity from.
+ /// The stored .
+ /// Thrown when either:
+ ///
+ /// - the couldn't be found in the
+ /// - more than one was found in the
+ ///
+ private static PipingCalculationEntity GetCorrespondingPipingCalculationEntity(this PipingCalculationScenario calculation, IRingtoetsEntities context)
+ {
+ try
+ {
+ return context.PipingCalculationEntities.Single(pc => pc.PipingCalculationEntityId == calculation.StorageId);
+ }
+ catch (InvalidOperationException exception)
+ {
+ throw new EntityNotFoundException(string.Format(Resources.Error_Entity_Not_Found_0_1, typeof(FailureMechanismEntity).Name, calculation.StorageId), exception);
+ }
+ }
+
+ private static decimal? GetNullableDecimal(RoundedDouble value)
+ {
+ if (double.IsNaN(value))
+ {
+ return null;
+ }
+ return Convert.ToDecimal(value);
+ }
+ }
+}
\ No newline at end of file
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Update/PipingFailureMechanismUpdateExtensions.cs
===================================================================
diff -u -rfe68c3f7cae5946b93d9e27eb532b176a6b26b84 -rd86b1c6e4ebde1570bec162a9043bbb437de5d9c
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Update/PipingFailureMechanismUpdateExtensions.cs (.../PipingFailureMechanismUpdateExtensions.cs) (revision fe68c3f7cae5946b93d9e27eb532b176a6b26b84)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Update/PipingFailureMechanismUpdateExtensions.cs (.../PipingFailureMechanismUpdateExtensions.cs) (revision d86b1c6e4ebde1570bec162a9043bbb437de5d9c)
@@ -22,6 +22,8 @@
using System;
using Application.Ringtoets.Storage.Create;
using Application.Ringtoets.Storage.DbContext;
+using Application.Ringtoets.Storage.Exceptions;
+
using Ringtoets.Piping.Data;
using Ringtoets.Piping.Primitives;
@@ -44,6 +46,8 @@
/// - is null
/// - is null
///
+ /// When
+ /// does not have a corresponding entity in .
internal static void Update(this PipingFailureMechanism mechanism, PersistenceRegistry registry, IRingtoetsEntities context)
{
if (context == null)
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Update/PipingSoilLayerUpdateExtensions.cs
===================================================================
diff -u -rae6f0c6b534ca650e160ae6d9c0bc90369d25c68 -rd86b1c6e4ebde1570bec162a9043bbb437de5d9c
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Update/PipingSoilLayerUpdateExtensions.cs (.../PipingSoilLayerUpdateExtensions.cs) (revision ae6f0c6b534ca650e160ae6d9c0bc90369d25c68)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Update/PipingSoilLayerUpdateExtensions.cs (.../PipingSoilLayerUpdateExtensions.cs) (revision d86b1c6e4ebde1570bec162a9043bbb437de5d9c)
@@ -47,6 +47,8 @@
/// - is null
/// - is null
///
+ /// When
+ /// does not have a corresponding entity in .
internal static void Update(this PipingSoilLayer layer, PersistenceRegistry registry, IRingtoetsEntities context)
{
if (context == null)
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Update/PipingSoilProfileUpdateExtensions.cs
===================================================================
diff -u -rae6f0c6b534ca650e160ae6d9c0bc90369d25c68 -rd86b1c6e4ebde1570bec162a9043bbb437de5d9c
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Update/PipingSoilProfileUpdateExtensions.cs (.../PipingSoilProfileUpdateExtensions.cs) (revision ae6f0c6b534ca650e160ae6d9c0bc90369d25c68)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Update/PipingSoilProfileUpdateExtensions.cs (.../PipingSoilProfileUpdateExtensions.cs) (revision d86b1c6e4ebde1570bec162a9043bbb437de5d9c)
@@ -46,6 +46,8 @@
/// - is null
/// - is null
///
+ /// When
+ /// does not have a corresponding entity in .
internal static void Update(this PipingSoilProfile profile, PersistenceRegistry registry, IRingtoetsEntities context)
{
if (context == null)
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Update/ProjectUpdateExtensions.cs
===================================================================
diff -u -rae6f0c6b534ca650e160ae6d9c0bc90369d25c68 -rd86b1c6e4ebde1570bec162a9043bbb437de5d9c
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Update/ProjectUpdateExtensions.cs (.../ProjectUpdateExtensions.cs) (revision ae6f0c6b534ca650e160ae6d9c0bc90369d25c68)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Update/ProjectUpdateExtensions.cs (.../ProjectUpdateExtensions.cs) (revision d86b1c6e4ebde1570bec162a9043bbb437de5d9c)
@@ -47,6 +47,8 @@
/// - is null
/// - is null
///
+ /// When
+ /// does not have a corresponding entity in .
internal static void Update(this Project project, PersistenceRegistry registry, IRingtoetsEntities context)
{
if (context == null)
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Update/StochasticSoilModelUpdateExtensions.cs
===================================================================
diff -u -r4478bdf539df278f9e2aac0f9fe683c34ac55335 -rd86b1c6e4ebde1570bec162a9043bbb437de5d9c
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Update/StochasticSoilModelUpdateExtensions.cs (.../StochasticSoilModelUpdateExtensions.cs) (revision 4478bdf539df278f9e2aac0f9fe683c34ac55335)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Update/StochasticSoilModelUpdateExtensions.cs (.../StochasticSoilModelUpdateExtensions.cs) (revision d86b1c6e4ebde1570bec162a9043bbb437de5d9c)
@@ -50,6 +50,8 @@
/// - is null
/// - is null
///
+ /// When
+ /// does not have a corresponding entity in .
internal static void Update(this StochasticSoilModel model, PersistenceRegistry registry, IRingtoetsEntities context)
{
if (context == null)
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Update/StochasticSoilProfileUpdateExtensions.cs
===================================================================
diff -u -rae6f0c6b534ca650e160ae6d9c0bc90369d25c68 -rd86b1c6e4ebde1570bec162a9043bbb437de5d9c
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Update/StochasticSoilProfileUpdateExtensions.cs (.../StochasticSoilProfileUpdateExtensions.cs) (revision ae6f0c6b534ca650e160ae6d9c0bc90369d25c68)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Update/StochasticSoilProfileUpdateExtensions.cs (.../StochasticSoilProfileUpdateExtensions.cs) (revision d86b1c6e4ebde1570bec162a9043bbb437de5d9c)
@@ -46,6 +46,8 @@
/// - is null
/// - is null
///
+ /// When
+ /// does not have a corresponding entity in .
internal static void Update(this StochasticSoilProfile profile, PersistenceRegistry registry, IRingtoetsEntities context)
{
if (context == null)
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj
===================================================================
diff -u -r32d32b83fc8e0c9b4849361af987da0170549146 -rd86b1c6e4ebde1570bec162a9043bbb437de5d9c
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 32d32b83fc8e0c9b4849361af987da0170549146)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision d86b1c6e4ebde1570bec162a9043bbb437de5d9c)
@@ -128,6 +128,7 @@
+
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/PipingCalculationScenarioUpdateExtensionsTest.cs
===================================================================
diff -u
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/PipingCalculationScenarioUpdateExtensionsTest.cs (revision 0)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/PipingCalculationScenarioUpdateExtensionsTest.cs (revision d86b1c6e4ebde1570bec162a9043bbb437de5d9c)
@@ -0,0 +1,586 @@
+using System;
+
+using Application.Ringtoets.Storage.Create;
+using Application.Ringtoets.Storage.DbContext;
+using Application.Ringtoets.Storage.Exceptions;
+using Application.Ringtoets.Storage.TestUtil;
+using Application.Ringtoets.Storage.Update;
+
+using Core.Common.Base.Data;
+using Core.Common.Base.Geometry;
+
+using NUnit.Framework;
+
+using Rhino.Mocks;
+
+using Ringtoets.HydraRing.Data;
+using Ringtoets.Piping.Data;
+using Ringtoets.Piping.Primitives;
+
+namespace Application.Ringtoets.Storage.Test.Update
+{
+ [TestFixture]
+ public class PipingCalculationScenarioUpdateExtensionsTest
+ {
+ [Test]
+ public void Update_PersistenceRegistryIsNull_ThrowArgumentNullException()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var context = RingtoetsEntitiesHelper.CreateStub(mocks);
+ mocks.ReplayAll();
+
+ var calculation = new PipingCalculationScenario(new GeneralPipingInput());
+
+ // Call
+ TestDelegate call = () => calculation.Update(null, context);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("registry", paramName);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Update_RingtoetsEntitiesIsNull_ThrowArgumentNullException()
+ {
+ // Setup
+ var calculation = new PipingCalculationScenario(new GeneralPipingInput());
+
+ var registry = new PersistenceRegistry();
+
+ // Call
+ TestDelegate call = () => calculation.Update(registry, null);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("context", paramName);
+ }
+
+ [Test]
+ public void Update_PipingCalculationScenarioNotSavedYet_ThrowEntityNotFoundException()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var context = RingtoetsEntitiesHelper.CreateStub(mocks);
+ mocks.ReplayAll();
+
+ var registry = new PersistenceRegistry();
+
+ var calculation = new PipingCalculationScenario(new GeneralPipingInput());
+
+ // Call
+ TestDelegate call = () => calculation.Update(registry, context);
+
+ // Assert
+ Assert.Throws(call);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Update_PipingCalculationScenarioChanged_EntityUpdated()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var context = RingtoetsEntitiesHelper.CreateStub(mocks);
+ mocks.ReplayAll();
+
+ var entity = new PipingCalculationEntity
+ {
+ PipingCalculationEntityId = 456
+ };
+ context.PipingCalculationEntities.Add(entity);
+
+ var registry = new PersistenceRegistry();
+
+ var calculation = new PipingCalculationScenario(new GeneralPipingInput())
+ {
+ StorageId = entity.PipingCalculationEntityId,
+ IsRelevant = true,
+ Contribution = (RoundedDouble)0.56,
+ Name = "New name!",
+ Comments = "Better comments!",
+ InputParameters =
+ {
+ EntryPointL = (RoundedDouble)1.1,
+ ExitPointL = (RoundedDouble)2.2,
+ PhreaticLevelExit =
+ {
+ Mean = (RoundedDouble)3.3,
+ StandardDeviation = (RoundedDouble) 4.4
+ },
+ DampingFactorExit =
+ {
+ Mean = (RoundedDouble)5.5,
+ StandardDeviation = (RoundedDouble)6.6
+ },
+ SaturatedVolumicWeightOfCoverageLayer =
+ {
+ Mean = (RoundedDouble)7.7,
+ StandardDeviation = (RoundedDouble)8.8,
+ Shift = (RoundedDouble)9.9
+ },
+ Diameter70 =
+ {
+ Mean = (RoundedDouble)10.10,
+ StandardDeviation = (RoundedDouble)11.11
+ },
+ DarcyPermeability =
+ {
+ Mean = (RoundedDouble)12.12,
+ StandardDeviation = (RoundedDouble)13.13
+ }
+ }
+ };
+
+ // Call
+ calculation.Update(registry, context);
+
+ // Assert
+ Assert.AreEqual(Convert.ToByte(calculation.IsRelevant), entity.RelevantForScenario);
+ Assert.AreEqual(Convert.ToDecimal(calculation.Contribution), entity.ScenarioContribution);
+ Assert.AreEqual(calculation.Name, entity.Name);
+ Assert.AreEqual(calculation.Comments, entity.Comments);
+
+ PipingInput inputParameters = calculation.InputParameters;
+ Assert.AreEqual(ToNullableDecimal(inputParameters.EntryPointL), entity.EntryPointL);
+ Assert.AreEqual(ToNullableDecimal(inputParameters.ExitPointL), entity.ExitPointL);
+
+ Assert.AreEqual(inputParameters.PhreaticLevelExit.Mean.Value, entity.PhreaticLevelExitMean);
+ Assert.AreEqual(inputParameters.PhreaticLevelExit.StandardDeviation.Value, entity.PhreaticLevelExitStandardDeviation);
+ Assert.AreEqual(inputParameters.DampingFactorExit.Mean.Value, entity.DampingFactorExitMean);
+ Assert.AreEqual(inputParameters.DampingFactorExit.StandardDeviation.Value, entity.DampingFactorExitStandardDeviation);
+ Assert.AreEqual(inputParameters.SaturatedVolumicWeightOfCoverageLayer.Mean.Value, entity.SaturatedVolumicWeightOfCoverageLayerMean);
+ Assert.AreEqual(inputParameters.SaturatedVolumicWeightOfCoverageLayer.StandardDeviation.Value, entity.SaturatedVolumicWeightOfCoverageLayerStandardDeviation);
+ Assert.AreEqual(inputParameters.SaturatedVolumicWeightOfCoverageLayer.Shift.Value, entity.SaturatedVolumicWeightOfCoverageLayerShift);
+ Assert.AreEqual(inputParameters.Diameter70.Mean.Value, entity.Diameter70Mean);
+ Assert.AreEqual(inputParameters.Diameter70.StandardDeviation.Value, entity.Diameter70StandardDeviation);
+ Assert.AreEqual(inputParameters.DarcyPermeability.Mean.Value, entity.DarcyPermeabilityMean);
+ Assert.AreEqual(inputParameters.DarcyPermeability.StandardDeviation.Value, entity.DarcyPermeabilityStandardDeviation);
+
+ registry.RemoveUntouched(context);
+ CollectionAssert.Contains(context.PipingCalculationEntities, entity);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Update_PipingCalculationScenarioWithReplaceSurfaceLine_PipingCalculationEntityUpdated()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var context = RingtoetsEntitiesHelper.CreateStub(mocks);
+ mocks.ReplayAll();
+
+ var originalSurfaceLineEntity = new SurfaceLineEntity
+ {
+ SurfaceLineEntityId = 345,
+ Name = "Original"
+ };
+ var replacementSurfaceLineEntity = new SurfaceLineEntity
+ {
+ SurfaceLineEntityId = 897,
+ Name = "Replacement"
+ };
+ var entity = new PipingCalculationEntity
+ {
+ PipingCalculationEntityId = 453,
+ SurfaceLineEntity = originalSurfaceLineEntity
+ };
+ context.PipingCalculationEntities.Add(entity);
+ context.SurfaceLineEntities.Add(originalSurfaceLineEntity);
+ context.SurfaceLineEntities.Add(replacementSurfaceLineEntity);
+
+ var replacementSurfaceLine = new RingtoetsPipingSurfaceLine
+ {
+ Name = replacementSurfaceLineEntity.Name,
+ StorageId = replacementSurfaceLineEntity.SurfaceLineEntityId,
+ ReferenceLineIntersectionWorldPoint = new Point2D(1, 2)
+ };
+ replacementSurfaceLine.SetGeometry(new[]
+ {
+ new Point3D(1, 2, 3),
+ new Point3D(4, 5, 6)
+ });
+
+ var registry = new PersistenceRegistry();
+ registry.Register(originalSurfaceLineEntity, new RingtoetsPipingSurfaceLine());
+ registry.Register(replacementSurfaceLineEntity, replacementSurfaceLine);
+
+ var calculation = new PipingCalculationScenario(new GeneralPipingInput())
+ {
+ StorageId = entity.PipingCalculationEntityId,
+ InputParameters =
+ {
+ EntryPointL = (RoundedDouble)1.1,
+ ExitPointL = (RoundedDouble)2.2,
+ DampingFactorExit =
+ {
+ Mean = (RoundedDouble)1
+ },
+ SaturatedVolumicWeightOfCoverageLayer =
+ {
+ Mean = (RoundedDouble)1
+ },
+ Diameter70 =
+ {
+ Mean = (RoundedDouble)1
+ },
+ DarcyPermeability =
+ {
+ Mean = (RoundedDouble)1
+ },
+ SurfaceLine = replacementSurfaceLine
+ }
+ };
+
+ // Call
+ calculation.Update(registry, context);
+
+ // Assert
+ Assert.IsNotNull(entity.SurfaceLineEntity);
+ Assert.AreSame(replacementSurfaceLineEntity, entity.SurfaceLineEntity);
+
+ registry.RemoveUntouched(context);
+ CollectionAssert.Contains(context.PipingCalculationEntities, entity);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Update_PipingCalculationScenarioWithClearedSurfaceLine_PipingCalculationEntityUpdated()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var context = RingtoetsEntitiesHelper.CreateStub(mocks);
+ mocks.ReplayAll();
+
+ var surfaceLineEntity = new SurfaceLineEntity
+ {
+ SurfaceLineEntityId = 345,
+ Name = "Original"
+ };
+ var entity = new PipingCalculationEntity
+ {
+ PipingCalculationEntityId = 453,
+ SurfaceLineEntity = surfaceLineEntity
+ };
+ context.PipingCalculationEntities.Add(entity);
+
+ var registry = new PersistenceRegistry();
+ registry.Register(surfaceLineEntity, new RingtoetsPipingSurfaceLine());
+
+ var calculation = new PipingCalculationScenario(new GeneralPipingInput())
+ {
+ StorageId = entity.PipingCalculationEntityId,
+ InputParameters =
+ {
+ EntryPointL = (RoundedDouble)1.1,
+ ExitPointL = (RoundedDouble)2.2,
+ DampingFactorExit =
+ {
+ Mean = (RoundedDouble)1
+ },
+ SaturatedVolumicWeightOfCoverageLayer =
+ {
+ Mean = (RoundedDouble)1
+ },
+ Diameter70 =
+ {
+ Mean = (RoundedDouble)1
+ },
+ DarcyPermeability =
+ {
+ Mean = (RoundedDouble)1
+ },
+ SurfaceLine = null
+ }
+ };
+
+ // Call
+ calculation.Update(registry, context);
+
+ // Assert
+ Assert.IsNull(entity.SurfaceLineEntity);
+
+ registry.RemoveUntouched(context);
+ CollectionAssert.Contains(context.PipingCalculationEntities, entity);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Update_PipingCalculationScenarioWithReplacedHydraulicBoundarLocation_PipingCalculationEntityUpdated()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var context = RingtoetsEntitiesHelper.CreateStub(mocks);
+ mocks.ReplayAll();
+
+ var originalHydraulicLocationEntity = new HydraulicLocationEntity
+ {
+ HydraulicLocationEntityId = 345,
+ Name = "Original"
+ };
+ var replacementHydraulicLocationEntity = new HydraulicLocationEntity
+ {
+ HydraulicLocationEntityId = 897,
+ Name = "Replacement"
+ };
+ var entity = new PipingCalculationEntity
+ {
+ PipingCalculationEntityId = 453,
+ HydraulicLocationEntity = originalHydraulicLocationEntity
+ };
+ context.PipingCalculationEntities.Add(entity);
+ context.HydraulicLocationEntities.Add(originalHydraulicLocationEntity);
+ context.HydraulicLocationEntities.Add(replacementHydraulicLocationEntity);
+
+ var replacementBoundaryLocation = new HydraulicBoundaryLocation(1, replacementHydraulicLocationEntity.Name, 1, 2)
+ {
+ StorageId = replacementHydraulicLocationEntity.HydraulicLocationEntityId,
+ };
+
+ var registry = new PersistenceRegistry();
+ registry.Register(originalHydraulicLocationEntity,
+ new HydraulicBoundaryLocation(2, originalHydraulicLocationEntity.Name, 3, 4));
+ registry.Register(replacementHydraulicLocationEntity, replacementBoundaryLocation);
+
+ var calculation = new PipingCalculationScenario(new GeneralPipingInput())
+ {
+ StorageId = entity.PipingCalculationEntityId,
+ InputParameters =
+ {
+ EntryPointL = (RoundedDouble)1.1,
+ ExitPointL = (RoundedDouble)2.2,
+ DampingFactorExit =
+ {
+ Mean = (RoundedDouble)1
+ },
+ SaturatedVolumicWeightOfCoverageLayer =
+ {
+ Mean = (RoundedDouble)1
+ },
+ Diameter70 =
+ {
+ Mean = (RoundedDouble)1
+ },
+ DarcyPermeability =
+ {
+ Mean = (RoundedDouble)1
+ },
+ HydraulicBoundaryLocation = replacementBoundaryLocation
+ }
+ };
+
+ // Call
+ calculation.Update(registry, context);
+
+ // Assert
+ Assert.AreSame(replacementHydraulicLocationEntity, entity.HydraulicLocationEntity);
+
+ registry.RemoveUntouched(context);
+ CollectionAssert.Contains(context.PipingCalculationEntities, entity);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Update_PipingCalculationScenarioWithClearedHydraulicBoundaryLocation_PipingCalculationEntityUpdated()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var context = RingtoetsEntitiesHelper.CreateStub(mocks);
+ mocks.ReplayAll();
+
+ var hydraulicLocationEntity = new HydraulicLocationEntity
+ {
+ HydraulicLocationEntityId = 5675,
+ Name = "Original"
+ };
+ var entity = new PipingCalculationEntity
+ {
+ PipingCalculationEntityId = 453,
+ HydraulicLocationEntity = hydraulicLocationEntity
+ };
+ context.PipingCalculationEntities.Add(entity);
+ context.HydraulicLocationEntities.Add(hydraulicLocationEntity);
+
+ var registry = new PersistenceRegistry();
+ registry.Register(hydraulicLocationEntity, new HydraulicBoundaryLocation(1, hydraulicLocationEntity.Name, 1, 3));
+
+ var calculation = new PipingCalculationScenario(new GeneralPipingInput())
+ {
+ StorageId = entity.PipingCalculationEntityId,
+ InputParameters =
+ {
+ EntryPointL = (RoundedDouble)1.1,
+ ExitPointL = (RoundedDouble)2.2,
+ DampingFactorExit =
+ {
+ Mean = (RoundedDouble)1
+ },
+ SaturatedVolumicWeightOfCoverageLayer =
+ {
+ Mean = (RoundedDouble)1
+ },
+ Diameter70 =
+ {
+ Mean = (RoundedDouble)1
+ },
+ DarcyPermeability =
+ {
+ Mean = (RoundedDouble)1
+ },
+ HydraulicBoundaryLocation = null
+ }
+ };
+
+ // Call
+ calculation.Update(registry, context);
+
+ // Assert
+ Assert.IsNull(entity.HydraulicLocationEntity);
+
+ registry.RemoveUntouched(context);
+ CollectionAssert.Contains(context.PipingCalculationEntities, entity);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Update_PipingCalculationScenarioWithReplacedStochasticSoilProfile_PipingCalculationEntityUpdated()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var context = RingtoetsEntitiesHelper.CreateStub(mocks);
+ mocks.ReplayAll();
+
+ var originalStochasticSoilProfileEntity = new StochasticSoilProfileEntity
+ {
+ StochasticSoilProfileEntityId = 490865
+ };
+ var replacementStochasticSoilProfileEntity = new StochasticSoilProfileEntity
+ {
+ StochasticSoilProfileEntityId = 57,
+ };
+ var entity = new PipingCalculationEntity
+ {
+ PipingCalculationEntityId = 453,
+ StochasticSoilProfileEntity = originalStochasticSoilProfileEntity
+ };
+ context.PipingCalculationEntities.Add(entity);
+ context.StochasticSoilProfileEntities.Add(originalStochasticSoilProfileEntity);
+ context.StochasticSoilProfileEntities.Add(replacementStochasticSoilProfileEntity);
+
+ var replacementSurfaceLine = new StochasticSoilProfile(0.6, SoilProfileType.SoilProfile1D, 34)
+ {
+ StorageId = replacementStochasticSoilProfileEntity.StochasticSoilProfileEntityId,
+ };
+
+ var registry = new PersistenceRegistry();
+ registry.Register(originalStochasticSoilProfileEntity,
+ new StochasticSoilProfile(0.6, SoilProfileType.SoilProfile2D, 131));
+ registry.Register(replacementStochasticSoilProfileEntity, replacementSurfaceLine);
+
+ var calculation = new PipingCalculationScenario(new GeneralPipingInput())
+ {
+ StorageId = entity.PipingCalculationEntityId,
+ InputParameters =
+ {
+ EntryPointL = (RoundedDouble)1.1,
+ ExitPointL = (RoundedDouble)2.2,
+ DampingFactorExit =
+ {
+ Mean = (RoundedDouble)1
+ },
+ SaturatedVolumicWeightOfCoverageLayer =
+ {
+ Mean = (RoundedDouble)1
+ },
+ Diameter70 =
+ {
+ Mean = (RoundedDouble)1
+ },
+ DarcyPermeability =
+ {
+ Mean = (RoundedDouble)1
+ },
+ StochasticSoilProfile = replacementSurfaceLine
+ }
+ };
+
+ // Call
+ calculation.Update(registry, context);
+
+ // Assert
+ Assert.AreSame(replacementStochasticSoilProfileEntity, entity.StochasticSoilProfileEntity);
+
+ registry.RemoveUntouched(context);
+ CollectionAssert.Contains(context.PipingCalculationEntities, entity);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Update_PipingCalculationScenarioWithClearedStochasticSoilProfile_PipingCalculationEntityUpdated()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var context = RingtoetsEntitiesHelper.CreateStub(mocks);
+ mocks.ReplayAll();
+
+ var stochasticSoilProfileEntity = new StochasticSoilProfileEntity
+ {
+ StochasticSoilProfileEntityId = 6,
+ };
+ var entity = new PipingCalculationEntity
+ {
+ PipingCalculationEntityId = 453,
+ StochasticSoilProfileEntity = stochasticSoilProfileEntity
+ };
+ context.PipingCalculationEntities.Add(entity);
+
+ var registry = new PersistenceRegistry();
+
+ var calculation = new PipingCalculationScenario(new GeneralPipingInput())
+ {
+ StorageId = entity.PipingCalculationEntityId,
+ InputParameters =
+ {
+ EntryPointL = (RoundedDouble)1.1,
+ ExitPointL = (RoundedDouble)2.2,
+ DampingFactorExit =
+ {
+ Mean = (RoundedDouble)1
+ },
+ SaturatedVolumicWeightOfCoverageLayer =
+ {
+ Mean = (RoundedDouble)1
+ },
+ Diameter70 =
+ {
+ Mean = (RoundedDouble)1
+ },
+ DarcyPermeability =
+ {
+ Mean = (RoundedDouble)1
+ },
+ StochasticSoilProfile = null
+ }
+ };
+
+ // Call
+ calculation.Update(registry, context);
+
+ // Assert
+ Assert.IsNull(entity.StochasticSoilProfileEntity);
+
+ registry.RemoveUntouched(context);
+ CollectionAssert.Contains(context.PipingCalculationEntities, entity);
+ mocks.VerifyAll();
+ }
+ private decimal? ToNullableDecimal(RoundedDouble roundedDoubleValue)
+ {
+ if (double.IsNaN(roundedDoubleValue))
+ {
+ return null;
+ }
+ return Convert.ToDecimal(roundedDoubleValue);
+ }
+ }
+}
\ No newline at end of file