Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj =================================================================== diff -u -r4e14ed090d09a220a790b3562ceb4232dab1cce6 -r5061321f2f8b942937713732163d9e55f2acb176 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 5061321f2f8b942937713732163d9e55f2acb176) @@ -55,6 +55,7 @@ + @@ -155,6 +156,10 @@ {CE994CC9-6F6A-48AC-B4BE-02C30A21F4DB} Ringtoets.Piping.Data + + {14c6f716-64e2-4bc4-a1ef-05865fcefa4c} + Ringtoets.Piping.Primitives + Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/PipingSoilProfileConverter.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/PipingSoilProfileConverter.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/PipingSoilProfileConverter.cs (revision 5061321f2f8b942937713732163d9e55f2acb176) @@ -0,0 +1,54 @@ +using System; +using System.Linq; +using Application.Ringtoets.Storage.DbContext; +using Ringtoets.Piping.Primitives; + +namespace Application.Ringtoets.Storage.Converters +{ + public class PipingSoilProfileConverter : IEntityConverter + { + public PipingSoilProfile ConvertEntityToModel(SoilProfileEntity entity) + { + if (entity == null) + { + throw new ArgumentNullException("entity"); + } + + var layers = entity.SoilLayerEntities.Select(sl => new PipingSoilLayer((double) sl.Top) + { + IsAquifer = sl.IsAquifer == 1 + }); + + return new PipingSoilProfile(entity.Name, (double) entity.Bottom, layers, SoilProfileType.SoilProfile1D, -1) + { + StorageId = entity.SoilProfileEntityId + }; + } + + public void ConvertModelToEntity(PipingSoilProfile modelObject, SoilProfileEntity entity) + { + if (modelObject == null) + { + throw new ArgumentNullException("modelObject"); + } + if (entity == null) + { + throw new ArgumentNullException("entity"); + } + entity.SoilProfileEntityId = modelObject.StorageId; + entity.Bottom = Convert.ToDecimal(modelObject.Bottom); + entity.Name = modelObject.Name; + + foreach (var sl in modelObject.Layers) + { + var layerEntity = new SoilLayerEntity + { + IsAquifer = sl.IsAquifer ? (byte) 1 : (byte) 0, + Top = Convert.ToDecimal(sl.Top) + }; + + entity.SoilLayerEntities.Add(layerEntity); + } + } + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/StochasticSoilModelConverter.cs =================================================================== diff -u -r4e14ed090d09a220a790b3562ceb4232dab1cce6 -r5061321f2f8b942937713732163d9e55f2acb176 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/StochasticSoilModelConverter.cs (.../StochasticSoilModelConverter.cs) (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/StochasticSoilModelConverter.cs (.../StochasticSoilModelConverter.cs) (revision 5061321f2f8b942937713732163d9e55f2acb176) @@ -22,6 +22,7 @@ using System; using Application.Ringtoets.Storage.DbContext; using Ringtoets.Piping.Data; +using Ringtoets.Piping.Primitives; namespace Application.Ringtoets.Storage.Converters { @@ -32,10 +33,16 @@ { throw new ArgumentNullException("entity"); } - return new StochasticSoilModel(-1, entity.Name, entity.SegmentName) + var convertedModel = new StochasticSoilModel(-1, entity.Name, entity.SegmentName) { StorageId = entity.StochasticSoilModelEntityId }; + foreach (var profileEntity in entity.StochasticSoilProfileEntities) + { + var profile = new StochasticSoilProfile((double)profileEntity.Probability.Value, SoilProfileType.SoilProfile1D, -1); + convertedModel.StochasticSoilProfiles.Add(profile); + } + return convertedModel; } public void ConvertModelToEntity(StochasticSoilModel modelObject, StochasticSoilModelEntity entity) @@ -51,6 +58,15 @@ entity.Name = modelObject.Name; entity.SegmentName = modelObject.SegmentName; entity.StochasticSoilModelEntityId = modelObject.StorageId; + + foreach (var stochasticProfile in modelObject.StochasticSoilProfiles) + { + var profile = new StochasticSoilProfileEntity + { + Probability = Convert.ToDecimal(stochasticProfile.Probability) + }; + entity.StochasticSoilProfileEntities.Add(profile); + } } } } \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/DatabaseStructure.sql =================================================================== diff -u -r4e14ed090d09a220a790b3562ceb4232dab1cce6 -r5061321f2f8b942937713732163d9e55f2acb176 --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/DatabaseStructure.sql (.../DatabaseStructure.sql) (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/DatabaseStructure.sql (.../DatabaseStructure.sql) (revision 5061321f2f8b942937713732163d9e55f2acb176) @@ -1,6 +1,6 @@ /* ---------------------------------------------------- */ /* Generated by Enterprise Architect Version 12.0 */ -/* Created On : 19-apr-2016 9:03:26 */ +/* Created On : 19-apr-2016 15:19:18 */ /* DBMS : SQLite */ /* ---------------------------------------------------- */ @@ -106,16 +106,17 @@ ( 'SoilLayerEntityId' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 'SoilProfileEntityId' INTEGER NOT NULL, - 'Top' NUMERIC, - 'IsAquifer' INTEGER, -- true or false + 'Top' NUMERIC NOT NULL, + 'IsAquifer' TINYINT (1) NOT NULL, -- true or false CONSTRAINT 'FK_SoilLayerEntity_SoilProfileEntity' FOREIGN KEY ('SoilProfileEntityId') REFERENCES 'SoilProfileEntity' ('SoilProfileEntityId') ON DELETE No Action ON UPDATE No Action ) ; CREATE TABLE 'SoilProfileEntity' ( 'SoilProfileEntityId' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - 'Bottom' TEXT + 'Bottom' NUMERIC NOT NULL, + 'Name' TEXT NOT NULL ) ; Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/IRingtoetsEntities.cs =================================================================== diff -u -r4e14ed090d09a220a790b3562ceb4232dab1cce6 -r5061321f2f8b942937713732163d9e55f2acb176 --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/IRingtoetsEntities.cs (.../IRingtoetsEntities.cs) (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/IRingtoetsEntities.cs (.../IRingtoetsEntities.cs) (revision 5061321f2f8b942937713732163d9e55f2acb176) @@ -66,6 +66,13 @@ /// DbSet StochasticSoilModelEntities { get; } + + /// + /// Gets a of containing + /// every entity found in the database. + /// + DbSet StochasticSoilProfileEntities { get; } + /// /// Persists all updates to the database and resets change tracking in the object context, see . /// Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.edmx =================================================================== diff -u -r4e14ed090d09a220a790b3562ceb4232dab1cce6 -r5061321f2f8b942937713732163d9e55f2acb176 --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.edmx (.../RingtoetsEntities.edmx) (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.edmx (.../RingtoetsEntities.edmx) (revision 5061321f2f8b942937713732163d9e55f2acb176) @@ -61,15 +61,16 @@ - - + + - + + @@ -351,16 +352,17 @@ - - + + - + + @@ -565,6 +567,7 @@ + Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.edmx.diagram =================================================================== diff -u -r4e14ed090d09a220a790b3562ceb4232dab1cce6 -r5061321f2f8b942937713732163d9e55f2acb176 --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.edmx.diagram (.../RingtoetsEntities.edmx.diagram) (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.edmx.diagram (.../RingtoetsEntities.edmx.diagram) (revision 5061321f2f8b942937713732163d9e55f2acb176) @@ -6,14 +6,14 @@ - + - - - - - + + + + + Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/SoilLayerEntity.cs =================================================================== diff -u -r4e14ed090d09a220a790b3562ceb4232dab1cce6 -r5061321f2f8b942937713732163d9e55f2acb176 --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/SoilLayerEntity.cs (.../SoilLayerEntity.cs) (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/SoilLayerEntity.cs (.../SoilLayerEntity.cs) (revision 5061321f2f8b942937713732163d9e55f2acb176) @@ -37,8 +37,8 @@ { public long SoilLayerEntityId { get; set; } public long SoilProfileEntityId { get; set; } - public Nullable Top { get; set; } - public Nullable IsAquifer { get; set; } + public decimal Top { get; set; } + public byte IsAquifer { get; set; } public virtual SoilProfileEntity SoilProfileEntity { get; set; } } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/SoilProfileEntity.cs =================================================================== diff -u -r4e14ed090d09a220a790b3562ceb4232dab1cce6 -r5061321f2f8b942937713732163d9e55f2acb176 --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/SoilProfileEntity.cs (.../SoilProfileEntity.cs) (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/SoilProfileEntity.cs (.../SoilProfileEntity.cs) (revision 5061321f2f8b942937713732163d9e55f2acb176) @@ -43,7 +43,8 @@ } public long SoilProfileEntityId { get; set; } - public string Bottom { get; set; } + public decimal Bottom { get; set; } + public string Name { get; set; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] public virtual ICollection SoilLayerEntities { get; set; } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/FailureMechanismPersistorBase.cs =================================================================== diff -u -r1257b99937b663621a4afb03a50a305aadff6a55 -r5061321f2f8b942937713732163d9e55f2acb176 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/FailureMechanismPersistorBase.cs (.../FailureMechanismPersistorBase.cs) (revision 1257b99937b663621a4afb03a50a305aadff6a55) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/FailureMechanismPersistorBase.cs (.../FailureMechanismPersistorBase.cs) (revision 5061321f2f8b942937713732163d9e55f2acb176) @@ -85,6 +85,11 @@ LoadChildren(failureMechanism, entity); } + /// + /// Implement to provide a way to load the children of the as children of . + /// + /// The to load into. + /// The to load from. protected abstract void LoadChildren(T model, FailureMechanismEntity entity); /// @@ -138,6 +143,11 @@ UpdateChildren(model, entity); } + /// + /// Implement to provide a way to update the children of the with data from . + /// + /// The for which to use the data to update the . + /// The to update. protected abstract void UpdateChildren(T model, FailureMechanismEntity entity); /// @@ -147,7 +157,6 @@ /// to be saved in the storage. /// Thrown when: /// is null. - /// is null. /// public void InsertModel(ICollection parentNavigationProperty, T model) { @@ -170,6 +179,12 @@ InsertChildren(model, entity); } + + /// + /// Implement to provide a way to insert the children of the into the . + /// + /// The for which to use the data to update the . + /// The to update. protected abstract void InsertChildren(T model, FailureMechanismEntity entity); /// Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/StochasticSoilModelPersistor.cs =================================================================== diff -u -r1257b99937b663621a4afb03a50a305aadff6a55 -r5061321f2f8b942937713732163d9e55f2acb176 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/StochasticSoilModelPersistor.cs (.../StochasticSoilModelPersistor.cs) (revision 1257b99937b663621a4afb03a50a305aadff6a55) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/StochasticSoilModelPersistor.cs (.../StochasticSoilModelPersistor.cs) (revision 5061321f2f8b942937713732163d9e55f2acb176) @@ -27,13 +27,17 @@ using Application.Ringtoets.Storage.DbContext; using Application.Ringtoets.Storage.Exceptions; using Application.Ringtoets.Storage.Properties; +using Core.Common.Utils; using Ringtoets.Piping.Data; +using Ringtoets.Piping.Primitives; namespace Application.Ringtoets.Storage.Persistors { public class StochasticSoilModelPersistor { - private readonly StochasticSoilModelConverter converter; + private readonly StochasticSoilModelConverter soilModelConverter = new StochasticSoilModelConverter(); + private readonly PipingSoilProfileConverter soilProfileConverter = new PipingSoilProfileConverter(); + private readonly ICollection modifiedList = new List(); private readonly Dictionary insertedList = new Dictionary(); private readonly DbSet stochasticSoilModelSet; @@ -45,7 +49,6 @@ throw new ArgumentNullException("ringtoetsContext"); } stochasticSoilModelSet = ringtoetsContext.StochasticSoilModelEntities; - converter = new StochasticSoilModelConverter(); } public IEnumerable LoadModel(IEnumerable entities) @@ -54,9 +57,17 @@ { throw new ArgumentNullException("entities"); } - return entities.Select(e => converter.ConvertEntityToModel(e)); + return entities.Select(e => soilModelConverter.ConvertEntityToModel(e)); } + /// + /// Ensures that the model is added as in the . + /// + /// Collection where objects can be added. Usually, this collection is a navigation property of a . + /// to be saved in the storage. + /// Thrown when: + /// is null. + /// public void InsertModel(ICollection parentNavigationProperty, ICollection stochasticSoilModels) { if (parentNavigationProperty == null) @@ -72,8 +83,23 @@ { InsertStochasticSoilModel(parentNavigationProperty, stochasticSoilModel); } + + InsertStochasticSoilProfiles(parentNavigationProperty, stochasticSoilModels); } + private void InsertStochasticSoilProfiles(ICollection parentNavigationProperty, ICollection stochasticSoilModels) + { + var profiles = stochasticSoilModels.SelectMany(ssm => ssm.StochasticSoilProfiles.Select(ssp => ssp.SoilProfile)); + + var convertedProfiles = new Dictionary(new ReferenceEqualityComparer()); + foreach (var soilProfile in profiles) + { + var entity = new SoilProfileEntity(); + soilProfileConverter.ConvertModelToEntity(soilProfile, entity); + convertedProfiles.Add(soilProfile, entity); + } + } + public void UpdateModel(ICollection parentNavigationProperty, IList model) { if (model == null) @@ -116,7 +142,7 @@ modifiedList.Add(entity); - converter.ConvertModelToEntity(stochasticSoilModel, entity); + soilModelConverter.ConvertModelToEntity(stochasticSoilModel, entity); } } @@ -138,7 +164,7 @@ private void InsertStochasticSoilModel(ICollection parentNavigationProperty, StochasticSoilModel stochasticSoilModel) { var entity = new StochasticSoilModelEntity(); - converter.ConvertModelToEntity(stochasticSoilModel, entity); + soilModelConverter.ConvertModelToEntity(stochasticSoilModel, entity); parentNavigationProperty.Add(entity); insertedList.Add(entity, stochasticSoilModel); } Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj =================================================================== diff -u -r4e14ed090d09a220a790b3562ceb4232dab1cce6 -r5061321f2f8b942937713732163d9e55f2acb176 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 5061321f2f8b942937713732163d9e55f2acb176) @@ -86,6 +86,7 @@ + @@ -135,10 +136,18 @@ {CE994CC9-6F6A-48AC-B4BE-02C30A21F4DB} Ringtoets.Piping.Data + + {14C6F716-64E2-4BC4-A1EF-05865FCEFA4C} + Ringtoets.Piping.Primitives + {955E574D-67CE-4347-AA6B-7DF8A04ED754} Ringtoets.Piping.Data.TestUtil + + {27E0A5C9-3ABF-426A-A3DA-7D0B83A218C8} + Ringtoets.Piping.KernelWrapper.TestUtil + {50963f12-448c-41ba-a62c-cdb0ab8d21e0} Application.Ringtoets.Storage Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/PipingSoilProfileConverterTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/PipingSoilProfileConverterTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/PipingSoilProfileConverterTest.cs (revision 5061321f2f8b942937713732163d9e55f2acb176) @@ -0,0 +1,115 @@ +using System; +using System.Linq; +using Application.Ringtoets.Storage.Converters; +using Application.Ringtoets.Storage.DbContext; +using NUnit.Framework; +using Ringtoets.Piping.KernelWrapper.TestUtil; +using Ringtoets.Piping.Primitives; + +namespace Application.Ringtoets.Storage.Test.Converters +{ + public class PipingSoilProfileConverterTest + { + [Test] + public void Constructor_Always_NewInstance() + { + // Call + var converter = new PipingSoilProfileConverter(); + + // Assert + Assert.IsInstanceOf>(converter); + } + + [Test] + public void ConvertEntityToModel_NullEntity_ThrowsArgumentNullException() + { + // Setup + var converter = new PipingSoilProfileConverter(); + + // Call + TestDelegate test = () => converter.ConvertEntityToModel(null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void ConvertEntityToModel_Always_ReturnsTheEntityAsModelWithId() + { + // Setup + var storageId = new Random(21).Next(); + var name = "SomeName"; + var entity = new SoilProfileEntity() + { + SoilProfileEntityId = storageId, + Name = name + }; + entity.SoilLayerEntities.Add(new SoilLayerEntity()); + var converter = new PipingSoilProfileConverter(); + + // Call + var location = converter.ConvertEntityToModel(entity); + + // Assert + Assert.AreEqual(storageId, location.StorageId); + Assert.AreEqual(name, location.Name); + } + + [Test] + public void ConvertModelToEntity_NullModel_ThrowsArgumentNullException() + { + // Setup + var converter = new PipingSoilProfileConverter(); + + // Call + TestDelegate test = () => converter.ConvertModelToEntity(null, new SoilProfileEntity()); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("modelObject", exception.ParamName); + } + + [Test] + public void ConvertModelToEntity_NullEntity_ThrowsArgumentNullException() + { + // Setup + var converter = new PipingSoilProfileConverter(); + + // Call + TestDelegate test = () => converter.ConvertModelToEntity(new TestPipingSoilProfile(), null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void ConvertModelToEntity_ValidModelValidEntity_ReturnsModelAsEntity() + { + // Setup + var converter = new PipingSoilProfileConverter(); + var random = new Random(21); + var entity = new SoilProfileEntity(); + + long storageId = random.Next(); + var model = new TestPipingSoilProfile + { + StorageId = storageId + }; + + // Call + converter.ConvertModelToEntity(model, entity); + + // Assert + Assert.AreEqual(storageId, entity.SoilProfileEntityId); + Assert.AreEqual(model.Name, entity.Name); + Assert.AreEqual(model.Bottom, entity.Bottom); + Assert.AreEqual(1, entity.SoilLayerEntities.Count); + + var layer = entity.SoilLayerEntities.ElementAt(0); + Assert.AreEqual(0, layer.Top); + Assert.AreEqual(1, layer.IsAquifer); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/StochasticSoilModelConverterTest.cs =================================================================== diff -u -r4e14ed090d09a220a790b3562ceb4232dab1cce6 -r5061321f2f8b942937713732163d9e55f2acb176 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/StochasticSoilModelConverterTest.cs (.../StochasticSoilModelConverterTest.cs) (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/StochasticSoilModelConverterTest.cs (.../StochasticSoilModelConverterTest.cs) (revision 5061321f2f8b942937713732163d9e55f2acb176) @@ -1,15 +1,16 @@ using System; +using System.Linq; using Application.Ringtoets.Storage.Converters; using Application.Ringtoets.Storage.DbContext; using NUnit.Framework; using Ringtoets.Piping.Data; +using Ringtoets.Piping.Primitives; namespace Application.Ringtoets.Storage.Test.Converters { [TestFixture] public class StochasticSoilModelConverterTest { - [Test] public void Constructor_Always_NewInstance() { @@ -59,6 +60,51 @@ } [Test] + public void ConvertEntityToModel_WithStochasticSoilProfiles_ReturnsTheEntityAsModelWithStochasticSoilProfiles() + { + // Setup + var storageId = new Random(21).Next(); + var segmentName = "SomeSegmentName"; + var name = "SomeName"; + var firstProfileProbability = 3.0; + var secondProfileProbability = 8.0; + var entity = new StochasticSoilModelEntity + { + StochasticSoilModelEntityId = storageId, + Name = name, + SegmentName = segmentName, + StochasticSoilProfileEntities = + { + new StochasticSoilProfileEntity + { + Probability = Convert.ToDecimal(firstProfileProbability) + }, + new StochasticSoilProfileEntity + { + Probability = Convert.ToDecimal(secondProfileProbability) + } + } + }; + var converter = new StochasticSoilModelConverter(); + + // Call + StochasticSoilModel location = converter.ConvertEntityToModel(entity); + + // Assert + Assert.AreEqual(storageId, location.StorageId); + Assert.AreEqual(name, location.Name); + Assert.AreEqual(segmentName, location.SegmentName); + + Assert.AreEqual(2, location.StochasticSoilProfiles.Count); + + var firstStochasticProfile = location.StochasticSoilProfiles.ElementAt(0); + var secondStochasticProfile = location.StochasticSoilProfiles.ElementAt(1); + + Assert.AreEqual(firstProfileProbability, firstStochasticProfile.Probability); + Assert.AreEqual(secondProfileProbability, secondStochasticProfile.Probability); + } + + [Test] public void ConvertModelToEntity_NullModel_ThrowsArgumentNullException() { // Setup @@ -111,5 +157,47 @@ Assert.AreEqual(name, entity.Name); Assert.AreEqual(segmentName, entity.SegmentName); } + + [Test] + + public void ConvertModelToEntity_ValidModelValidEntityWithStochasticSoilProfiles_ReturnsModelAsEntityWithStochasticSoilProfiles() + { + // Setup + var converter = new StochasticSoilModelConverter(); + var random = new Random(21); + var entity = new StochasticSoilModelEntity(); + + string segmentName = "someSegmentName"; + string name = "someName"; + long id = random.Next(); + long storageId = random.Next(); + var firstProfileProbability = 3.0; + var secondProfileProbability = 8.0; + var model = new StochasticSoilModel(id, name, segmentName) + { + StorageId = storageId, + StochasticSoilProfiles = + { + new StochasticSoilProfile(firstProfileProbability, SoilProfileType.SoilProfile1D, -1), + new StochasticSoilProfile(secondProfileProbability, SoilProfileType.SoilProfile1D, -1) + } + }; + + // Call + converter.ConvertModelToEntity(model, entity); + + // Assert + Assert.AreEqual(storageId, entity.StochasticSoilModelEntityId); + Assert.AreEqual(name, entity.Name); + Assert.AreEqual(segmentName, entity.SegmentName); + + Assert.AreEqual(2, entity.StochasticSoilProfileEntities.Count); + + var firstProfileEntity = entity.StochasticSoilProfileEntities.ElementAt(0); + var secondProfileEntity = entity.StochasticSoilProfileEntities.ElementAt(1); + + Assert.AreEqual(firstProfileProbability, firstProfileEntity.Probability); + Assert.AreEqual(secondProfileProbability, secondProfileEntity.Probability); + } } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Primitives/PipingSoilProfile.cs =================================================================== diff -u -r2ed0db8299205024c1c6b1eb10da05f588f5d649 -r5061321f2f8b942937713732163d9e55f2acb176 --- Ringtoets/Piping/src/Ringtoets.Piping.Primitives/PipingSoilProfile.cs (.../PipingSoilProfile.cs) (revision 2ed0db8299205024c1c6b1eb10da05f588f5d649) +++ Ringtoets/Piping/src/Ringtoets.Piping.Primitives/PipingSoilProfile.cs (.../PipingSoilProfile.cs) (revision 5061321f2f8b942937713732163d9e55f2acb176) @@ -94,6 +94,11 @@ public SoilProfileType SoilProfileType { get; private set; } /// + /// Gets or sets the unique identifier for the storage of the . + /// + public long StorageId { get; set; } + + /// /// Gets the thickness of the given layer in the . /// Thickness of a layer is determined by its top and the top of the layer below it. ///