Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj =================================================================== diff -u -r4abb9905e5c81445217060c7394966acf6a7c0d3 -re13ada41fc3e534300575c578f398ef8dddbee4e --- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 4abb9905e5c81445217060c7394966acf6a7c0d3) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision e13ada41fc3e534300575c578f398ef8dddbee4e) @@ -83,6 +83,7 @@ + Code Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/MacroStabilityInwards/MacroStabilityInwardsSoilProfile1DCreateExtensions.cs =================================================================== diff -u -r25e0f6d008a17ea054a3658d82746b3a2e94f3c5 -re13ada41fc3e534300575c578f398ef8dddbee4e --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/MacroStabilityInwards/MacroStabilityInwardsSoilProfile1DCreateExtensions.cs (.../MacroStabilityInwardsSoilProfile1DCreateExtensions.cs) (revision 25e0f6d008a17ea054a3658d82746b3a2e94f3c5) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/MacroStabilityInwards/MacroStabilityInwardsSoilProfile1DCreateExtensions.cs (.../MacroStabilityInwardsSoilProfile1DCreateExtensions.cs) (revision e13ada41fc3e534300575c578f398ef8dddbee4e) @@ -21,11 +21,9 @@ 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 { @@ -43,6 +41,7 @@ /// The object keeping track of create operations. /// A new or one from the /// if it was created for the earlier. + /// Thrown when any input parameter is null. internal static MacroStabilityInwardsSoilProfile1DEntity Create(this MacroStabilityInwardsSoilProfile1D soilProfile, PersistenceRegistry registry) { @@ -73,7 +72,7 @@ } private static void AddEntitiesForSoilLayers(IEnumerable layers, - MacroStabilityInwardsSoilProfile1DEntity entity) + MacroStabilityInwardsSoilProfile1DEntity entity) { var index = 0; foreach (MacroStabilityInwardsSoilLayer1D layer in layers) Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/MacroStabilityInwards/MacroStabilityInwardsSoilProfile2DCreateExtensions.cs =================================================================== diff -u -r4abb9905e5c81445217060c7394966acf6a7c0d3 -re13ada41fc3e534300575c578f398ef8dddbee4e --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/MacroStabilityInwards/MacroStabilityInwardsSoilProfile2DCreateExtensions.cs (.../MacroStabilityInwardsSoilProfile2DCreateExtensions.cs) (revision 4abb9905e5c81445217060c7394966acf6a7c0d3) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/MacroStabilityInwards/MacroStabilityInwardsSoilProfile2DCreateExtensions.cs (.../MacroStabilityInwardsSoilProfile2DCreateExtensions.cs) (revision e13ada41fc3e534300575c578f398ef8dddbee4e) @@ -41,6 +41,7 @@ /// The object keeping track of create operations. /// A new or one from the /// if it was created for the earlier. + /// Thrown when any input parameter is null. internal static MacroStabilityInwardsSoilProfile2DEntity Create(this MacroStabilityInwardsSoilProfile2D soilProfile, PersistenceRegistry registry) { Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/MacroStabilityInwards/MacroStabilityInwardsStochasticSoilProfileCreateExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/MacroStabilityInwards/MacroStabilityInwardsStochasticSoilProfileCreateExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/MacroStabilityInwards/MacroStabilityInwardsStochasticSoilProfileCreateExtensions.cs (revision e13ada41fc3e534300575c578f398ef8dddbee4e) @@ -0,0 +1,91 @@ +// 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 Application.Ringtoets.Storage.DbContext; +using Ringtoets.MacroStabilityInwards.Data.SoilProfile; +using Ringtoets.MacroStabilityInwards.Primitives; + +namespace Application.Ringtoets.Storage.Create.MacroStabilityInwards +{ + /// + /// Extension methods for related to + /// creating a . + /// + internal static class MacroStabilityInwardsStochasticSoilProfileCreateExtensions + { + /// + /// Creates a based on + /// the information of the . + /// + /// The stochastic soil profile to create a database entity for. + /// The object keeping track of create operations. + /// Index at which this instance resides inside its parent container. + /// A new . + /// Thrown when any input parameter is null. + internal static MacroStabilityInwardsStochasticSoilProfileEntity Create(this MacroStabilityInwardsStochasticSoilProfile stochasticSoilProfile, + PersistenceRegistry registry, + int order) + { + if (stochasticSoilProfile == null) + { + throw new ArgumentNullException(nameof(stochasticSoilProfile)); + } + if (registry == null) + { + throw new ArgumentNullException(nameof(registry)); + } + + if (registry.Contains(stochasticSoilProfile)) + { + return registry.Get(stochasticSoilProfile); + } + + var entity = new MacroStabilityInwardsStochasticSoilProfileEntity + { + Probability = stochasticSoilProfile.Probability, + Order = order + }; + + AddEntityForProfile(stochasticSoilProfile.SoilProfile, entity, registry); + + registry.Register(entity, stochasticSoilProfile); + return entity; + } + + private static void AddEntityForProfile(IMacroStabilityInwardsSoilProfile soilProfile, + MacroStabilityInwardsStochasticSoilProfileEntity entity, + PersistenceRegistry registry) + { + var soilProfile1D = soilProfile as MacroStabilityInwardsSoilProfile1D; + if (soilProfile1D != null) + { + entity.MacroStabilityInwardsSoilProfile1DEntity = soilProfile1D.Create(registry); + } + + var soilProfile2D = soilProfile as MacroStabilityInwardsSoilProfile2D; + if (soilProfile2D != null) + { + entity.MacroStabilityInwardsSoilProfile2DEntity = soilProfile2D.Create(registry); + } + } + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/PersistenceRegistry.cs =================================================================== diff -u -r25e0f6d008a17ea054a3658d82746b3a2e94f3c5 -re13ada41fc3e534300575c578f398ef8dddbee4e --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/PersistenceRegistry.cs (.../PersistenceRegistry.cs) (revision 25e0f6d008a17ea054a3658d82746b3a2e94f3c5) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/PersistenceRegistry.cs (.../PersistenceRegistry.cs) (revision e13ada41fc3e534300575c578f398ef8dddbee4e) @@ -32,6 +32,7 @@ using Ringtoets.DuneErosion.Data; using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.HeightStructures.Data; +using Ringtoets.MacroStabilityInwards.Data.SoilProfile; using Ringtoets.MacroStabilityInwards.Primitives; using Ringtoets.Piping.Data.SoilProfile; using Ringtoets.Piping.Primitives; @@ -68,6 +69,9 @@ private readonly Dictionary pipingSoilProfiles = CreateDictionary(); + private readonly Dictionary macroStabilityInwardsStochasticSoilProfiles = + CreateDictionary(); + private readonly Dictionary macroStabilityInwardsSoil1DProfiles = CreateDictionary(); @@ -268,6 +272,18 @@ /// 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(MacroStabilityInwardsStochasticSoilProfileEntity entity, MacroStabilityInwardsStochasticSoilProfile model) + { + Register(macroStabilityInwardsStochasticSoilProfiles, 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. @@ -418,6 +434,17 @@ /// /// 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(MacroStabilityInwardsStochasticSoilProfile model) + { + return ContainsValue(macroStabilityInwardsStochasticSoilProfiles, 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. @@ -653,6 +680,23 @@ } /// + /// Obtains the which was registered for + /// the given . + /// + /// The for which a create + /// operation has been registered. + /// The created . + /// Thrown when is null. + /// Thrown when no create operation + /// has been registered for . + /// Use to find out whether + /// a create/create operation has been registered for . + internal MacroStabilityInwardsStochasticSoilProfileEntity Get(MacroStabilityInwardsStochasticSoilProfile model) + { + return Get(macroStabilityInwardsStochasticSoilProfiles, model); + } + + /// /// Obtains the which was registered for the given /// . /// Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj =================================================================== diff -u -r4abb9905e5c81445217060c7394966acf6a7c0d3 -re13ada41fc3e534300575c578f398ef8dddbee4e --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 4abb9905e5c81445217060c7394966acf6a7c0d3) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision e13ada41fc3e534300575c578f398ef8dddbee4e) @@ -102,6 +102,7 @@ + Code Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/MacroStabilityInwards/MacroStabilityInwardsStochasticSoilProfileCreateExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/MacroStabilityInwards/MacroStabilityInwardsStochasticSoilProfileCreateExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/MacroStabilityInwards/MacroStabilityInwardsStochasticSoilProfileCreateExtensionsTest.cs (revision e13ada41fc3e534300575c578f398ef8dddbee4e) @@ -0,0 +1,194 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using System.Linq; +using Application.Ringtoets.Storage.Create; +using Application.Ringtoets.Storage.Create.MacroStabilityInwards; +using Application.Ringtoets.Storage.DbContext; +using Core.Common.Base.Geometry; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.MacroStabilityInwards.Data.SoilProfile; +using Ringtoets.MacroStabilityInwards.Primitives; +using Ringtoets.MacroStabilityInwards.Primitives.TestUtil; + +namespace Application.Ringtoets.Storage.Test.Create.MacroStabilityInwards +{ + [TestFixture] + public class MacroStabilityInwardsStochasticSoilProfileCreateExtensionsTest + { + [Test] + public void Create_StochasticSoilProfileNull_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => ((MacroStabilityInwardsStochasticSoilProfile) null).Create(registry, 0); + + // Assert + string parameterName = Assert.Throws(test).ParamName; + Assert.AreEqual("stochasticSoilProfile", parameterName); + } + + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var mockRepository = new MockRepository(); + var soilProfile = mockRepository.Stub(); + mockRepository.ReplayAll(); + + var stochasticSoilProfile = new MacroStabilityInwardsStochasticSoilProfile(0, soilProfile); + + // Call + TestDelegate test = () => stochasticSoilProfile.Create(null, 0); + + // Assert + string parameterName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", parameterName); + + mockRepository.VerifyAll(); + } + + [Test] + [TestCaseSource(nameof(GetMacroStabilityInwardsSoilProfiles))] + public void Create_WithValidProperties_ReturnsStochasticSoilProfileEntityWithPropertiesSet(IMacroStabilityInwardsSoilProfile soilProfile) + { + // Setup + var random = new Random(31); + var stochasticSoilProfile = new MacroStabilityInwardsStochasticSoilProfile(random.NextDouble(), soilProfile); + + int order = random.Next(); + + var registry = new PersistenceRegistry(); + + // Call + MacroStabilityInwardsStochasticSoilProfileEntity entity = stochasticSoilProfile.Create(registry, order); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(stochasticSoilProfile.Probability, entity.Probability); + + var soilProfile1D = soilProfile as MacroStabilityInwardsSoilProfile1D; + if (soilProfile1D == null) + { + Assert.IsNull(entity.MacroStabilityInwardsSoilProfile1DEntity); + } + else + { + Assert.AreEqual(soilProfile1D.Name, entity.MacroStabilityInwardsSoilProfile1DEntity.Name); + } + + var soilProfile2D = soilProfile as MacroStabilityInwardsSoilProfile2D; + if (soilProfile2D == null) + { + Assert.IsNull(entity.MacroStabilityInwardsSoilProfile2DEntity); + } + else + { + Assert.AreEqual(soilProfile2D.Name, entity.MacroStabilityInwardsSoilProfile2DEntity.Name); + } + + Assert.AreEqual(order, entity.Order); + } + + [Test] + [TestCaseSource(nameof(GetSameExpectedMacroStabilityInwardsSoilProfiles))] + public void Create_DifferentStochasticSoilProfilesWithSameSoilProfile_ReturnsEntityWithSameSoilProfileEntitySet( + IMacroStabilityInwardsSoilProfile soilProfileOne, + IMacroStabilityInwardsSoilProfile soilProfileTwo, + bool expectedToBeSame) + { + // Setup + var random = new Random(31); + var firstStochasticSoilProfile = new MacroStabilityInwardsStochasticSoilProfile(random.NextDouble(), soilProfileOne); + var secondStochasticSoilProfile = new MacroStabilityInwardsStochasticSoilProfile(random.NextDouble(), soilProfileTwo); + var registry = new PersistenceRegistry(); + + // Call + MacroStabilityInwardsStochasticSoilProfileEntity firstEntity = firstStochasticSoilProfile.Create(registry, 0); + MacroStabilityInwardsStochasticSoilProfileEntity secondEntity = secondStochasticSoilProfile.Create(registry, 0); + + // Assert + if (!expectedToBeSame) + { + if (firstEntity.MacroStabilityInwardsSoilProfile1DEntity != null) + { + Assert.AreNotSame(firstEntity.MacroStabilityInwardsSoilProfile1DEntity, secondEntity.MacroStabilityInwardsSoilProfile1DEntity); + } + if (firstEntity.MacroStabilityInwardsSoilProfile2DEntity != null) + { + Assert.AreNotSame(firstEntity.MacroStabilityInwardsSoilProfile2DEntity, secondEntity.MacroStabilityInwardsSoilProfile2DEntity); + } + } + else + { + Assert.AreSame(firstEntity.MacroStabilityInwardsSoilProfile1DEntity, secondEntity.MacroStabilityInwardsSoilProfile1DEntity); + Assert.AreSame(firstEntity.MacroStabilityInwardsSoilProfile2DEntity, secondEntity.MacroStabilityInwardsSoilProfile2DEntity); + } + } + + [Test] + [TestCaseSource(nameof(GetMacroStabilityInwardsSoilProfiles))] + public void Create_SameStochasticSoilProfileMultipleTimes_ReturnSameEntity(IMacroStabilityInwardsSoilProfile soilProfile) + { + // Setup + var stochasticSoilProfile = new MacroStabilityInwardsStochasticSoilProfile(0.4, soilProfile); + var registry = new PersistenceRegistry(); + + // Call + MacroStabilityInwardsStochasticSoilProfileEntity entity1 = stochasticSoilProfile.Create(registry, 0); + MacroStabilityInwardsStochasticSoilProfileEntity entity2 = stochasticSoilProfile.Create(registry, 0); + + // Assert + Assert.AreSame(entity1, entity2); + } + + private static IEnumerable GetSameExpectedMacroStabilityInwardsSoilProfiles() + { + IMacroStabilityInwardsSoilProfile[] soilProfiles = GetMacroStabilityInwardsSoilProfiles().ToArray(); + int count = soilProfiles.Length; + for (var i = 0; i < count; i++) + { + for (var j = 0; j < count; j++) + { + yield return new TestCaseData(soilProfiles[i], soilProfiles[j], i == j); + } + } + } + + private static IEnumerable GetMacroStabilityInwardsSoilProfiles() + { + yield return new TestMacroStabilityInwardsSoilProfile1D(nameof(MacroStabilityInwardsSoilProfile1D)); + yield return new MacroStabilityInwardsSoilProfile2D(nameof(MacroStabilityInwardsSoilProfile2D), new[] + { + new MacroStabilityInwardsSoilLayer2D(new Ring(new[] + { + new Point2D(0, 0), + new Point2D(1, 1) + }), Enumerable.Empty()) + }, new MacroStabilityInwardsPreconsolidationStress[0]); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs =================================================================== diff -u -r25e0f6d008a17ea054a3658d82746b3a2e94f3c5 -re13ada41fc3e534300575c578f398ef8dddbee4e --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs (.../PersistenceRegistryTest.cs) (revision 25e0f6d008a17ea054a3658d82746b3a2e94f3c5) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs (.../PersistenceRegistryTest.cs) (revision e13ada41fc3e534300575c578f398ef8dddbee4e) @@ -26,6 +26,7 @@ using Application.Ringtoets.Storage.TestUtil; using Core.Common.Base.Geometry; using NUnit.Framework; +using Rhino.Mocks; using Ringtoets.ClosingStructures.Data; using Ringtoets.ClosingStructures.Data.TestUtil; using Ringtoets.Common.Data.DikeProfiles; @@ -38,6 +39,7 @@ using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.HeightStructures.Data; using Ringtoets.HeightStructures.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Data.SoilProfile; using Ringtoets.MacroStabilityInwards.Primitives; using Ringtoets.MacroStabilityInwards.Primitives.TestUtil; using Ringtoets.Piping.Data.SoilProfile; @@ -98,6 +100,50 @@ } [TestFixture] + private class MacroStabilityInwardsStochasticSoilProfileTest : RegistryTest + { + private MockRepository mockRepository; + + [SetUp] + public void Setup() + { + mockRepository = new MockRepository(); + } + + [TearDown] + public void TearDown() + { + mockRepository.VerifyAll(); + } + + protected override MacroStabilityInwardsStochasticSoilProfile CreateDataModel() + { + var soilProfile = mockRepository.Stub(); + mockRepository.ReplayAll(); + + return new MacroStabilityInwardsStochasticSoilProfile(0, soilProfile); + } + + protected override MacroStabilityInwardsStochasticSoilProfileEntity Get(PersistenceRegistry registry, + MacroStabilityInwardsStochasticSoilProfile model) + { + return registry.Get(model); + } + + protected override bool Contains(PersistenceRegistry registry, MacroStabilityInwardsStochasticSoilProfile model) + { + return registry.Contains(model); + } + + protected override void Register(PersistenceRegistry registry, MacroStabilityInwardsStochasticSoilProfileEntity entity, + MacroStabilityInwardsStochasticSoilProfile model) + { + registry.Register(entity, model); + } + } + + [TestFixture] private class MacroStabilityInwardsSoilProfile1DTest : RegistryTest {