Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj
===================================================================
diff -u -r6b3a6850b43d0098dcaf52c23b9a74d2e678bf8e -r25e0f6d008a17ea054a3658d82746b3a2e94f3c5
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 6b3a6850b43d0098dcaf52c23b9a74d2e678bf8e)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 25e0f6d008a17ea054a3658d82746b3a2e94f3c5)
@@ -81,6 +81,7 @@
+
Code
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer1DCreateExtensions.cs
===================================================================
diff -u -r6b3a6850b43d0098dcaf52c23b9a74d2e678bf8e -r25e0f6d008a17ea054a3658d82746b3a2e94f3c5
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer1DCreateExtensions.cs (.../MacroStabilityInwardsSoilLayer1DCreateExtensions.cs) (revision 6b3a6850b43d0098dcaf52c23b9a74d2e678bf8e)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer1DCreateExtensions.cs (.../MacroStabilityInwardsSoilLayer1DCreateExtensions.cs) (revision 25e0f6d008a17ea054a3658d82746b3a2e94f3c5)
@@ -36,16 +36,22 @@
/// Creates a based on the information
/// of the .
///
- /// The layer to create a database entity for.
+ /// The soil layer to create a database entity for.
/// Index at which this instance resides inside its parent container.
/// A new .
- internal static MacroStabilityInwardsSoilLayer1DEntity Create(this MacroStabilityInwardsSoilLayer1D layer,
+ /// Thrown when is null.
+ internal static MacroStabilityInwardsSoilLayer1DEntity Create(this MacroStabilityInwardsSoilLayer1D soilLayer,
int order)
{
- MacroStabilityInwardsSoilLayerProperties properties = layer.Properties;
+ if (soilLayer == null)
+ {
+ throw new ArgumentNullException(nameof(soilLayer));
+ }
+
+ MacroStabilityInwardsSoilLayerProperties properties = soilLayer.Properties;
return new MacroStabilityInwardsSoilLayer1DEntity
{
- Top = layer.Top.ToNaNAsNull(),
+ Top = soilLayer.Top.ToNaNAsNull(),
IsAquifer = Convert.ToByte(properties.IsAquifer),
MaterialName = properties.MaterialName.DeepClone(),
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer2DCreateExtensions.cs
===================================================================
diff -u -r6b3a6850b43d0098dcaf52c23b9a74d2e678bf8e -r25e0f6d008a17ea054a3658d82746b3a2e94f3c5
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer2DCreateExtensions.cs (.../MacroStabilityInwardsSoilLayer2DCreateExtensions.cs) (revision 6b3a6850b43d0098dcaf52c23b9a74d2e678bf8e)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer2DCreateExtensions.cs (.../MacroStabilityInwardsSoilLayer2DCreateExtensions.cs) (revision 25e0f6d008a17ea054a3658d82746b3a2e94f3c5)
@@ -36,13 +36,19 @@
/// Creates a based on the information
/// of the .
///
- /// The layer to create a database entity for.
+ /// The soil layer to create a database entity for.
/// Index at which this instance resides inside its parent container.
/// A new .
- internal static MacroStabilityInwardsSoilLayer2DEntity Create(this MacroStabilityInwardsSoilLayer2D layer,
+ /// Thrown when is null.
+ internal static MacroStabilityInwardsSoilLayer2DEntity Create(this MacroStabilityInwardsSoilLayer2D soilLayer,
int order)
{
- MacroStabilityInwardsSoilLayerProperties properties = layer.Properties;
+ if (soilLayer == null)
+ {
+ throw new ArgumentNullException(nameof(soilLayer));
+ }
+
+ MacroStabilityInwardsSoilLayerProperties properties = soilLayer.Properties;
return new MacroStabilityInwardsSoilLayer2DEntity
{
IsAquifer = Convert.ToByte(properties.IsAquifer),
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/MacroStabilityInwards/MacroStabilityInwardsSoilProfile1DCreateExtensions.cs
===================================================================
diff -u
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/MacroStabilityInwards/MacroStabilityInwardsSoilProfile1DCreateExtensions.cs (revision 0)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/MacroStabilityInwards/MacroStabilityInwardsSoilProfile1DCreateExtensions.cs (revision 25e0f6d008a17ea054a3658d82746b3a2e94f3c5)
@@ -0,0 +1,85 @@
+// 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 Application.Ringtoets.Storage.Create.Piping;
+using Application.Ringtoets.Storage.DbContext;
+using Core.Common.Utils.Extensions;
+using Ringtoets.MacroStabilityInwards.Primitives;
+using Ringtoets.Piping.Primitives;
+
+namespace Application.Ringtoets.Storage.Create.MacroStabilityInwards
+{
+ ///
+ /// Extension methods for related to creating
+ /// a .
+ ///
+ internal static class MacroStabilityInwardsSoilProfile1DCreateExtensions
+ {
+ ///
+ /// Creates a based on the information
+ /// of the .
+ ///
+ /// The soil profile to create a database entity for.
+ /// The object keeping track of create operations.
+ /// A new or one from the
+ /// if it was created for the earlier.
+ internal static MacroStabilityInwardsSoilProfile1DEntity Create(this MacroStabilityInwardsSoilProfile1D soilProfile,
+ PersistenceRegistry registry)
+ {
+ if (soilProfile == null)
+ {
+ throw new ArgumentNullException(nameof(soilProfile));
+ }
+ if (registry == null)
+ {
+ throw new ArgumentNullException(nameof(registry));
+ }
+
+ if (registry.Contains(soilProfile))
+ {
+ return registry.Get(soilProfile);
+ }
+
+ var entity = new MacroStabilityInwardsSoilProfile1DEntity
+ {
+ Name = soilProfile.Name.DeepClone(),
+ Bottom = soilProfile.Bottom.ToNaNAsNull()
+ };
+
+ AddEntitiesForSoilLayers(soilProfile.Layers, entity);
+
+ registry.Register(entity, soilProfile);
+ return entity;
+ }
+
+ private static void AddEntitiesForSoilLayers(IEnumerable layers,
+ MacroStabilityInwardsSoilProfile1DEntity entity)
+ {
+ var index = 0;
+ foreach (MacroStabilityInwardsSoilLayer1D layer in layers)
+ {
+ entity.MacroStabilityInwardsSoilLayer1DEntity.Add(layer.Create(index++));
+ }
+ }
+ }
+}
\ No newline at end of file
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/PersistenceRegistry.cs
===================================================================
diff -u -ra096cb901099c85dbaafa2dba6c69288464c248e -r25e0f6d008a17ea054a3658d82746b3a2e94f3c5
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/PersistenceRegistry.cs (.../PersistenceRegistry.cs) (revision a096cb901099c85dbaafa2dba6c69288464c248e)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/PersistenceRegistry.cs (.../PersistenceRegistry.cs) (revision 25e0f6d008a17ea054a3658d82746b3a2e94f3c5)
@@ -32,6 +32,7 @@
using Ringtoets.DuneErosion.Data;
using Ringtoets.GrassCoverErosionInwards.Data;
using Ringtoets.HeightStructures.Data;
+using Ringtoets.MacroStabilityInwards.Primitives;
using Ringtoets.Piping.Data.SoilProfile;
using Ringtoets.Piping.Primitives;
using Ringtoets.StabilityPointStructures.Data;
@@ -67,6 +68,12 @@
private readonly Dictionary pipingSoilProfiles =
CreateDictionary();
+ private readonly Dictionary macroStabilityInwardsSoil1DProfiles =
+ CreateDictionary();
+
+ private readonly Dictionary macroStabilityInwardsSoil2DProfiles =
+ CreateDictionary();
+
private readonly Dictionary surfaceLines =
CreateDictionary();
@@ -261,6 +268,30 @@
/// Registers a create operation for and the
/// that was constructed with the information.
///
+ /// The to be registered.
+ /// The to be registered.
+ /// Thrown any of the input parameters is null.
+ internal void Register(MacroStabilityInwardsSoilProfile1DEntity entity, MacroStabilityInwardsSoilProfile1D model)
+ {
+ Register(macroStabilityInwardsSoil1DProfiles, entity, model);
+ }
+
+ ///
+ /// Registers a create operation for and the
+ /// that was constructed with the information.
+ ///
+ /// The to be registered.
+ /// The to be registered.
+ /// Thrown any of the input parameters is null.
+ internal void Register(MacroStabilityInwardsSoilProfile2DEntity entity, MacroStabilityInwardsSoilProfile2D model)
+ {
+ Register(macroStabilityInwardsSoil2DProfiles, entity, model);
+ }
+
+ ///
+ /// Registers a create operation for and the
+ /// that was constructed with the information.
+ ///
/// The to be registered.
/// The to be registered.
/// Thrown any of the input parameters is null.
@@ -387,6 +418,28 @@
///
/// Checks whether a create operations has been registered for the given .
///
+ /// The to check for.
+ /// true if the was registered before, false otherwise.
+ /// Thrown when is null.
+ internal bool Contains(MacroStabilityInwardsSoilProfile1D model)
+ {
+ return ContainsValue(macroStabilityInwardsSoil1DProfiles, model);
+ }
+
+ ///
+ /// Checks whether a create operations has been registered for the given .
+ ///
+ /// The to check for.
+ /// true if the was registered before, false otherwise.
+ /// Thrown when is null.
+ internal bool Contains(MacroStabilityInwardsSoilProfile2D model)
+ {
+ return ContainsValue(macroStabilityInwardsSoil2DProfiles, model);
+ }
+
+ ///
+ /// Checks whether a create operations has been registered for the given .
+ ///
/// The to check for.
/// true if the was registered before, false otherwise.
/// Thrown when is null.
@@ -600,6 +653,40 @@
}
///
+ /// Obtains the which was registered for the given
+ /// .
+ ///
+ /// The for which a create
+ /// operation has been registered.
+ /// The constructed .
+ /// Thrown when is null.
+ /// Thrown when no create operation
+ /// has been registered for .
+ /// Use to find out whether a
+ /// create operation has been registered for .
+ internal MacroStabilityInwardsSoilProfile1DEntity Get(MacroStabilityInwardsSoilProfile1D model)
+ {
+ return Get(macroStabilityInwardsSoil1DProfiles, model);
+ }
+
+ ///
+ /// Obtains the which was registered for the given
+ /// .
+ ///
+ /// The for which a create
+ /// operation has been registered.
+ /// The constructed .
+ /// Thrown when is null.
+ /// Thrown when no create operation
+ /// has been registered for .
+ /// Use to find out whether a
+ /// create operation has been registered for .
+ internal MacroStabilityInwardsSoilProfile2DEntity Get(MacroStabilityInwardsSoilProfile2D model)
+ {
+ return Get(macroStabilityInwardsSoil2DProfiles, model);
+ }
+
+ ///
/// Obtains the which was registered for the given
/// .
///
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj
===================================================================
diff -u -r6b3a6850b43d0098dcaf52c23b9a74d2e678bf8e -r25e0f6d008a17ea054a3658d82746b3a2e94f3c5
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 6b3a6850b43d0098dcaf52c23b9a74d2e678bf8e)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 25e0f6d008a17ea054a3658d82746b3a2e94f3c5)
@@ -100,6 +100,7 @@
+
Code
@@ -324,6 +325,10 @@
{e9b39743-2dc9-4922-9e0f-6ba3e0e54189}
Ringtoets.MacroStabilityInwards.Primitives
+
+ {1DF4EE8D-0EF5-4FCC-A40E-CB8B82080FDF}
+ Ringtoets.MacroStabilityInwards.Primitives.TestUtil
+
{6F568E38-592A-4F99-A901-86B74C4F24D2}
Ringtoets.Piping.Primitives.TestUtil
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer1DCreateExtensionsTest.cs
===================================================================
diff -u -r31a621e36dfd14666d4ec7bb492b5eb5ea8a9265 -r25e0f6d008a17ea054a3658d82746b3a2e94f3c5
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer1DCreateExtensionsTest.cs (.../MacroStabilityInwardsSoilLayer1DCreateExtensionsTest.cs) (revision 31a621e36dfd14666d4ec7bb492b5eb5ea8a9265)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer1DCreateExtensionsTest.cs (.../MacroStabilityInwardsSoilLayer1DCreateExtensionsTest.cs) (revision 25e0f6d008a17ea054a3658d82746b3a2e94f3c5)
@@ -33,6 +33,17 @@
public class MacroStabilityInwardsSoilLayer1DCreateExtensionsTest
{
[Test]
+ public void Create_SoilLayerNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate test = () => ((MacroStabilityInwardsSoilLayer1D) null).Create(0);
+
+ // Assert
+ string parameterName = Assert.Throws(test).ParamName;
+ Assert.AreEqual("soilLayer", parameterName);
+ }
+
+ [Test]
public void Create_WithValidProperties_ReturnsEntityWithPropertiesSet()
{
// Setup
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer2DCreateExtensionsTest.cs
===================================================================
diff -u -r6b3a6850b43d0098dcaf52c23b9a74d2e678bf8e -r25e0f6d008a17ea054a3658d82746b3a2e94f3c5
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer2DCreateExtensionsTest.cs (.../MacroStabilityInwardsSoilLayer2DCreateExtensionsTest.cs) (revision 6b3a6850b43d0098dcaf52c23b9a74d2e678bf8e)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer2DCreateExtensionsTest.cs (.../MacroStabilityInwardsSoilLayer2DCreateExtensionsTest.cs) (revision 25e0f6d008a17ea054a3658d82746b3a2e94f3c5)
@@ -34,6 +34,17 @@
public class MacroStabilityInwardsSoilLayer2DCreateExtensionsTest
{
[Test]
+ public void Create_SoilLayerNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate test = () => ((MacroStabilityInwardsSoilLayer2D) null).Create(0);
+
+ // Assert
+ string parameterName = Assert.Throws(test).ParamName;
+ Assert.AreEqual("soilLayer", parameterName);
+ }
+
+ [Test]
public void Create_WithValidProperties_ReturnsEntityWithPropertiesSet()
{
// Setup
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSoilProfile1DCreateExtensionsTest.cs
===================================================================
diff -u
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSoilProfile1DCreateExtensionsTest.cs (revision 0)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSoilProfile1DCreateExtensionsTest.cs (revision 25e0f6d008a17ea054a3658d82746b3a2e94f3c5)
@@ -0,0 +1,143 @@
+// 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.Create;
+using Application.Ringtoets.Storage.Create.MacroStabilityInwards;
+using Application.Ringtoets.Storage.DbContext;
+using Core.Common.TestUtil;
+using NUnit.Framework;
+using Ringtoets.MacroStabilityInwards.Primitives;
+using Ringtoets.MacroStabilityInwards.Primitives.TestUtil;
+
+namespace Application.Ringtoets.Storage.Test.Create.MacroStabilityInwards
+{
+ [TestFixture]
+ public class MacroStabilityInwardsSoilProfile1DCreateExtensionsTest
+ {
+ [Test]
+ public void Create_PersistenceRegistryNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var soilProfile = new TestMacroStabilityInwardsSoilProfile1D();
+
+ // Call
+ TestDelegate test = () => soilProfile.Create(null);
+
+ // Assert
+ string parameterName = Assert.Throws(test).ParamName;
+ Assert.AreEqual("registry", parameterName);
+ }
+
+ [Test]
+ public void Create_SoilProfileNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var registry = new PersistenceRegistry();
+
+ // Call
+ TestDelegate test = () => ((MacroStabilityInwardsSoilProfile1D) null).Create(registry);
+
+ // Assert
+ string parameterName = Assert.Throws(test).ParamName;
+ Assert.AreEqual("soilProfile", parameterName);
+ }
+
+ [Test]
+ public void Create_WithValidProperties_ReturnsEntityWithPropertiesSet()
+ {
+ // Setup
+ var random = new Random(31);
+ const string name = "some name";
+ var soilProfile = new MacroStabilityInwardsSoilProfile1D(name, -random.NextDouble(), new[]
+ {
+ new MacroStabilityInwardsSoilLayer1D(random.NextDouble()),
+ new MacroStabilityInwardsSoilLayer1D(random.NextDouble())
+ });
+ var registry = new PersistenceRegistry();
+
+ // Call
+ MacroStabilityInwardsSoilProfile1DEntity entity = soilProfile.Create(registry);
+
+ // Assert
+ Assert.IsNotNull(entity);
+ Assert.AreEqual(soilProfile.Bottom, entity.Bottom);
+ Assert.AreEqual(2, entity.MacroStabilityInwardsSoilLayer1DEntity.Count);
+
+ MacroStabilityInwardsSoilLayer1DEntity firstLayerEntity = entity.MacroStabilityInwardsSoilLayer1DEntity.ElementAt(0);
+ Assert.AreEqual(soilProfile.Layers.ElementAt(0).Top, firstLayerEntity.Top);
+
+ MacroStabilityInwardsSoilLayer1DEntity secondLayerEntity = entity.MacroStabilityInwardsSoilLayer1DEntity.ElementAt(1);
+ Assert.AreEqual(soilProfile.Layers.ElementAt(1).Top, secondLayerEntity.Top);
+ }
+
+ [Test]
+ public void Create_WithNaNProperties_ReturnsEntityWithPropertiesSetToNull()
+ {
+ // Setup
+ var random = new Random(31);
+ var soilProfile = new MacroStabilityInwardsSoilProfile1D("some name", double.NaN, new[]
+ {
+ new MacroStabilityInwardsSoilLayer1D(random.NextDouble())
+ });
+ var registry = new PersistenceRegistry();
+
+ // Call
+ MacroStabilityInwardsSoilProfile1DEntity entity = soilProfile.Create(registry);
+
+ // Assert
+ Assert.IsNotNull(entity);
+ Assert.IsNull(entity.Bottom);
+ }
+
+ [Test]
+ public void Create_StringPropertiesDoNotShareReference()
+ {
+ // Setup
+ const string name = "some name";
+ var soilProfile = new TestMacroStabilityInwardsSoilProfile1D(name);
+ var registry = new PersistenceRegistry();
+
+ // Call
+ MacroStabilityInwardsSoilProfile1DEntity entity = soilProfile.Create(registry);
+
+ // Assert
+ TestHelper.AssertAreEqualButNotSame(name, entity.Name);
+ }
+
+ [Test]
+ public void Create_ForTheSameObjectTwice_ReturnsSameEntityInstance()
+ {
+ // Setup
+ var soilProfile = new TestMacroStabilityInwardsSoilProfile1D();
+ var registry = new PersistenceRegistry();
+
+ MacroStabilityInwardsSoilProfile1DEntity firstEntity = soilProfile.Create(registry);
+
+ // Call
+ MacroStabilityInwardsSoilProfile1DEntity secondEntity = soilProfile.Create(registry);
+
+ // Assert
+ Assert.AreSame(firstEntity, secondEntity);
+ }
+ }
+}
\ No newline at end of file
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs
===================================================================
diff -u -rb0b8bffcbb871a42e6c8b282fe20858d6a738dbc -r25e0f6d008a17ea054a3658d82746b3a2e94f3c5
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs (.../PersistenceRegistryTest.cs) (revision b0b8bffcbb871a42e6c8b282fe20858d6a738dbc)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs (.../PersistenceRegistryTest.cs) (revision 25e0f6d008a17ea054a3658d82746b3a2e94f3c5)
@@ -20,6 +20,7 @@
// All rights reserved.
using System;
+using System.Linq;
using Application.Ringtoets.Storage.Create;
using Application.Ringtoets.Storage.DbContext;
using Application.Ringtoets.Storage.TestUtil;
@@ -37,6 +38,8 @@
using Ringtoets.GrassCoverErosionInwards.Data;
using Ringtoets.HeightStructures.Data;
using Ringtoets.HeightStructures.Data.TestUtil;
+using Ringtoets.MacroStabilityInwards.Primitives;
+using Ringtoets.MacroStabilityInwards.Primitives.TestUtil;
using Ringtoets.Piping.Data.SoilProfile;
using Ringtoets.Piping.Primitives;
using Ringtoets.Piping.Primitives.TestUtil;
@@ -67,66 +70,274 @@
});
}
- #region Contains methods
-
- [Test]
- public void Contains_WithoutPipingSoilProfile_ThrowsArgumentNullException()
+ [TestFixture]
+ private class PipingSoilProfileTest : RegistryTest
{
- // Setup
- var registry = new PersistenceRegistry();
+ protected override PipingSoilProfile CreateDataModel()
+ {
+ return PipingSoilProfileTestFactory.CreatePipingSoilProfile();
+ }
- // Call
- TestDelegate test = () => registry.Contains((PipingSoilProfile) null);
+ protected override PipingSoilProfileEntity Get(PersistenceRegistry registry,
+ PipingSoilProfile model)
+ {
+ return registry.Get(model);
+ }
- // Assert
- string paramName = Assert.Throws(test).ParamName;
- Assert.AreEqual("model", paramName);
+ protected override bool Contains(PersistenceRegistry registry, PipingSoilProfile model)
+ {
+ return registry.Contains(model);
+ }
+
+ protected override void Register(PersistenceRegistry registry, PipingSoilProfileEntity entity,
+ PipingSoilProfile model)
+ {
+ registry.Register(entity, model);
+ }
}
- [Test]
- public void Contains_PipingSoilProfileAdded_ReturnsTrue()
+ [TestFixture]
+ private class MacroStabilityInwardsSoilProfile1DTest : RegistryTest
{
- // Setup
- var registry = new PersistenceRegistry();
- PipingSoilProfile profile = PipingSoilProfileTestFactory.CreatePipingSoilProfile();
- registry.Register(new PipingSoilProfileEntity(), profile);
+ protected override MacroStabilityInwardsSoilProfile1D CreateDataModel()
+ {
+ return new TestMacroStabilityInwardsSoilProfile1D();
+ }
- // Call
- bool result = registry.Contains(profile);
+ protected override MacroStabilityInwardsSoilProfile1DEntity Get(PersistenceRegistry registry,
+ MacroStabilityInwardsSoilProfile1D model)
+ {
+ return registry.Get(model);
+ }
- // Assert
- Assert.IsTrue(result);
+ protected override bool Contains(PersistenceRegistry registry, MacroStabilityInwardsSoilProfile1D model)
+ {
+ return registry.Contains(model);
+ }
+
+ protected override void Register(PersistenceRegistry registry, MacroStabilityInwardsSoilProfile1DEntity entity,
+ MacroStabilityInwardsSoilProfile1D model)
+ {
+ registry.Register(entity, model);
+ }
}
- [Test]
- public void Contains_NoPipingSoilProfileAdded_ReturnsFalse()
+ [TestFixture]
+ private class MacroStabilityInwardsSoilProfile2DTest : RegistryTest
{
- // Setup
- var registry = new PersistenceRegistry();
- PipingSoilProfile profile = PipingSoilProfileTestFactory.CreatePipingSoilProfile();
+ protected override MacroStabilityInwardsSoilProfile2D CreateDataModel()
+ {
+ return new MacroStabilityInwardsSoilProfile2D("", new[]
+ {
+ new MacroStabilityInwardsSoilLayer2D(new Ring(new[]
+ {
+ new Point2D(0, 0),
+ new Point2D(1, 1)
+ }), new Ring[0])
+ }, Enumerable.Empty());
+ }
- // Call
- bool result = registry.Contains(profile);
+ protected override MacroStabilityInwardsSoilProfile2DEntity Get(PersistenceRegistry registry,
+ MacroStabilityInwardsSoilProfile2D model)
+ {
+ return registry.Get(model);
+ }
- // Assert
- Assert.IsFalse(result);
+ protected override bool Contains(PersistenceRegistry registry, MacroStabilityInwardsSoilProfile2D model)
+ {
+ return registry.Contains(model);
+ }
+
+ protected override void Register(PersistenceRegistry registry, MacroStabilityInwardsSoilProfile2DEntity entity,
+ MacroStabilityInwardsSoilProfile2D model)
+ {
+ registry.Register(entity, model);
+ }
}
- [Test]
- public void Contains_OtherPipingSoilProfileAdded_ReturnsFalse()
+ [TestFixture]
+ private abstract class RegistryTest where TDataModel : class
+ where TEntity : class, new()
{
- // Setup
- var registry = new PersistenceRegistry();
- PipingSoilProfile profile = PipingSoilProfileTestFactory.CreatePipingSoilProfile();
- registry.Register(new PipingSoilProfileEntity(), PipingSoilProfileTestFactory.CreatePipingSoilProfile());
+ [Test]
+ public void Register_WithNullEntity_ThrowsArgumentNullException()
+ {
+ // Setup
+ var registry = new PersistenceRegistry();
- // Call
- bool result = registry.Contains(profile);
+ // Call
+ TestDelegate test = () => Register(registry, null, CreateDataModel());
- // Assert
- Assert.IsFalse(result);
+ // Assert
+ string paramName = Assert.Throws(test).ParamName;
+ Assert.AreEqual("entity", paramName);
+ }
+
+ [Test]
+ public void Register_WithNullDataModel_ThrowsArgumentNullException()
+ {
+ // Setup
+ var registry = new PersistenceRegistry();
+
+ // Call
+ TestDelegate test = () => Register(registry, new TEntity(), null);
+
+ // Assert
+ string paramName = Assert.Throws(test).ParamName;
+ Assert.AreEqual("model", paramName);
+ }
+
+ [Test]
+ public void Contains_DataModelNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var registry = new PersistenceRegistry();
+
+ // Call
+ TestDelegate test = () => Contains(registry, null);
+
+ // Assert
+ string paramName = Assert.Throws(test).ParamName;
+ Assert.AreEqual("model", paramName);
+ }
+
+ [Test]
+ public void Contains_DataModelAdded_ReturnsTrue()
+ {
+ // Setup
+ var registry = new PersistenceRegistry();
+ TDataModel dataModel = CreateDataModel();
+ Register(registry, new TEntity(), dataModel);
+
+ // Call
+ bool result = Contains(registry, dataModel);
+
+ // Assert
+ Assert.IsTrue(result);
+ }
+
+ [Test]
+ public void Contains_NoDataModelAdded_ReturnsFalse()
+ {
+ // Setup
+ var registry = new PersistenceRegistry();
+ TDataModel dataModel = CreateDataModel();
+
+ // Call
+ bool result = Contains(registry, dataModel);
+
+ // Assert
+ Assert.IsFalse(result);
+ }
+
+ [Test]
+ public void Get_DataModelNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var registry = new PersistenceRegistry();
+
+ // Call
+ TestDelegate test = () => Get(registry, null);
+
+ // Assert
+ string paramName = Assert.Throws(test).ParamName;
+ Assert.AreEqual("model", paramName);
+ }
+
+ [Test]
+ public void Get_DataModelAdded_ReturnsEntity()
+ {
+ // Setup
+ var registry = new PersistenceRegistry();
+ TDataModel dataModel = CreateDataModel();
+ var entity = new TEntity();
+
+ Register(registry, entity, dataModel);
+
+ // Call
+ TEntity result = Get(registry, dataModel);
+
+ // Assert
+ Assert.AreSame(entity, result);
+ }
+
+ [Test]
+ public void Get_NoDataModelAdded_ThrowsInvalidOperationException()
+ {
+ // Setup
+ var registry = new PersistenceRegistry();
+ TDataModel dataModel = CreateDataModel();
+
+ // Call
+ TestDelegate test = () => Get(registry, dataModel);
+
+ // Assert
+ Assert.Throws(test);
+ }
+
+ [Test]
+ public void Get_OtherDataModelAdded_ThrowsInvalidOperationException()
+ {
+ // Setup
+ var registry = new PersistenceRegistry();
+ Register(registry, new TEntity(), CreateDataModel());
+
+ // Call
+ TestDelegate test = () => Get(registry, CreateDataModel());
+
+ // Assert
+ Assert.Throws(test);
+ }
+
+ ///
+ /// Creates a new instance of .
+ ///
+ ///
+ protected abstract TDataModel CreateDataModel();
+
+ ///
+ /// Obtains the which was registered for the given .
+ ///
+ /// The registry to use.
+ /// The for which a create operation has
+ /// been registered.
+ /// The constructed .
+ /// Thrown when is
+ /// null.
+ /// Thrown when no create operation has
+ /// been registered for .
+ protected abstract TEntity Get(PersistenceRegistry registry, TDataModel model);
+
+ ///
+ /// Checks whether a create operations has been registered for the given .
+ ///
+ /// The registry to use.
+ /// The to check for.
+ /// true if the was registered before, false
+ /// otherwise.
+ /// Thrown when is
+ /// null.
+ protected abstract bool Contains(PersistenceRegistry registry, TDataModel model);
+
+ ///
+ /// Registers a create operation for and the
+ /// that was constructed with the information.
+ ///
+ /// The registry to use.
+ /// The
+ /// to be registered.
+ /// The to be
+ /// registered.
+ /// Thrown any of the input parameters is
+ /// null.
+ protected abstract void Register(PersistenceRegistry registry, TEntity entity, TDataModel model);
}
+ #region Contains methods
+
[Test]
public void Contains_WithoutPipingSurfaceLine_ThrowsArgumentNullException()
{
@@ -1013,65 +1224,6 @@
#region Get methods
[Test]
- public void Get_WithoutPipingSoilProfile_ThrowsArgumentNullException()
- {
- // Setup
- var registry = new PersistenceRegistry();
-
- // Call
- TestDelegate test = () => registry.Get((PipingSoilProfile) null);
-
- // Assert
- string paramName = Assert.Throws(test).ParamName;
- Assert.AreEqual("model", paramName);
- }
-
- [Test]
- public void Get_PipingSoilProfileAdded_ReturnsEntity()
- {
- // Setup
- var registry = new PersistenceRegistry();
- PipingSoilProfile profile = PipingSoilProfileTestFactory.CreatePipingSoilProfile();
- var entity = new PipingSoilProfileEntity();
- registry.Register(entity, profile);
-
- // Call
- PipingSoilProfileEntity result = registry.Get(profile);
-
- // Assert
- Assert.AreSame(entity, result);
- }
-
- [Test]
- public void Get_NoPipingSoilProfileAdded_ThrowsInvalidOperationException()
- {
- // Setup
- var registry = new PersistenceRegistry();
- PipingSoilProfile profile = PipingSoilProfileTestFactory.CreatePipingSoilProfile();
-
- // Call
- TestDelegate test = () => registry.Get(profile);
-
- // Assert
- Assert.Throws(test);
- }
-
- [Test]
- public void Get_OtherPipingSoilProfileAdded_ThrowsInvalidOperationException()
- {
- // Setup
- var registry = new PersistenceRegistry();
- PipingSoilProfile profile = PipingSoilProfileTestFactory.CreatePipingSoilProfile();
- registry.Register(new PipingSoilProfileEntity(), PipingSoilProfileTestFactory.CreatePipingSoilProfile());
-
- // Call
- TestDelegate test = () => registry.Get(profile);
-
- // Assert
- Assert.Throws(test);
- }
-
- [Test]
public void Get_WithoutPipingSurfaceLine_ThrowsArgumentNullException()
{
// Setup
@@ -2158,37 +2310,6 @@
}
[Test]
- public void Register_WithNullPipingSoilProfileEntity_ThrowsArgumentNullException()
- {
- // Setup
- var registry = new PersistenceRegistry();
-
- // Call
- TestDelegate test = () => registry.Register(null, new PipingSoilProfile("name", 0, new[]
- {
- new PipingSoilLayer(1)
- }, SoilProfileType.SoilProfile1D));
-
- // Assert
- string paramName = Assert.Throws(test).ParamName;
- Assert.AreEqual("entity", paramName);
- }
-
- [Test]
- public void Register_WithNullPipingSoilProfile_ThrowsArgumentNullException()
- {
- // Setup
- var registry = new PersistenceRegistry();
-
- // Call
- TestDelegate test = () => registry.Register(new PipingSoilProfileEntity(), null);
-
- // Assert
- string paramName = Assert.Throws(test).ParamName;
- Assert.AreEqual("model", paramName);
- }
-
- [Test]
public void Register_WithNullHeightStructureEntity_ThrowsArgumentNullException()
{
// Setup