Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj =================================================================== diff -u -r4e65fa5d8abdf1c0a9238492cdbcd7d2b3fa2d0f -r4e14ed090d09a220a790b3562ceb4232dab1cce6 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 4e65fa5d8abdf1c0a9238492cdbcd7d2b3fa2d0f) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) @@ -58,6 +58,7 @@ + RingtoetsEntities.tt @@ -74,6 +75,18 @@ RingtoetsEntities.tt + + RingtoetsEntities.tt + + + RingtoetsEntities.tt + + + RingtoetsEntities.tt + + + RingtoetsEntities.tt + RingtoetsEntities.tt @@ -83,6 +96,7 @@ + Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/StochasticSoilModelConverter.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/StochasticSoilModelConverter.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/StochasticSoilModelConverter.cs (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) @@ -0,0 +1,56 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using Application.Ringtoets.Storage.DbContext; +using Ringtoets.Piping.Data; + +namespace Application.Ringtoets.Storage.Converters +{ + public class StochasticSoilModelConverter : IEntityConverter { + public StochasticSoilModel ConvertEntityToModel(StochasticSoilModelEntity entity) + { + if (entity == null) + { + throw new ArgumentNullException("entity"); + } + return new StochasticSoilModel(-1, entity.Name, entity.SegmentName) + { + StorageId = entity.StochasticSoilModelEntityId + }; + } + + public void ConvertModelToEntity(StochasticSoilModel modelObject, StochasticSoilModelEntity entity) + { + if (modelObject == null) + { + throw new ArgumentNullException("modelObject"); + } + if (entity == null) + { + throw new ArgumentNullException("entity"); + } + entity.Name = modelObject.Name; + entity.SegmentName = modelObject.SegmentName; + entity.StochasticSoilModelEntityId = modelObject.StorageId; + } + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/DatabaseStructure.sql =================================================================== diff -u -r4e65fa5d8abdf1c0a9238492cdbcd7d2b3fa2d0f -r4e14ed090d09a220a790b3562ceb4232dab1cce6 --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/DatabaseStructure.sql (.../DatabaseStructure.sql) (revision 4e65fa5d8abdf1c0a9238492cdbcd7d2b3fa2d0f) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/DatabaseStructure.sql (.../DatabaseStructure.sql) (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) @@ -1,6 +1,6 @@ /* ---------------------------------------------------- */ /* Generated by Enterprise Architect Version 12.0 */ -/* Created On : 06-apr-2016 9:02:20 */ +/* Created On : 19-apr-2016 9:03:26 */ /* DBMS : SQLite */ /* ---------------------------------------------------- */ @@ -24,6 +24,18 @@ DROP TABLE IF EXISTS 'ReferenceLinePointEntity' ; +DROP TABLE IF EXISTS 'SoilLayerEntity' +; + +DROP TABLE IF EXISTS 'SoilProfileEntity' +; + +DROP TABLE IF EXISTS 'StochasticSoilModelEntity' +; + +DROP TABLE IF EXISTS 'StochasticSoilProfileEntity' +; + /* Create Tables with Primary and Foreign Keys, Check and Unique Constraints */ CREATE TABLE 'VersionEntity' @@ -90,6 +102,44 @@ ) ; +CREATE TABLE 'SoilLayerEntity' +( + 'SoilLayerEntityId' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + 'SoilProfileEntityId' INTEGER NOT NULL, + 'Top' NUMERIC, + 'IsAquifer' INTEGER, -- 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 +) +; + +CREATE TABLE 'StochasticSoilModelEntity' +( + 'StochasticSoilModelEntityId' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + 'FailureMechanismEntityId' INTEGER NOT NULL, + 'Name' TEXT NOT NULL, + 'SegmentName' TEXT NOT NULL, + CONSTRAINT 'FK_StochasticSoilModelEntity_FailureMechanismEntity' FOREIGN KEY ('FailureMechanismEntityId') REFERENCES 'FailureMechanismEntity' ('FailureMechanismEntityId') ON DELETE No Action ON UPDATE No Action +) +; + +CREATE TABLE 'StochasticSoilProfileEntity' +( + 'StochasticSoilProfileEntityId' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + 'SoilProfileEntityId' INTEGER NOT NULL, + 'StochasticSoilModelEntityId' INTEGER NOT NULL, + 'Probability' NUMERIC, + CONSTRAINT 'FK_StochasticSoilProfileEntity_SoilProfileEntity' FOREIGN KEY ('SoilProfileEntityId') REFERENCES 'SoilProfileEntity' ('SoilProfileEntityId') ON DELETE Cascade ON UPDATE Cascade, + CONSTRAINT 'FK_StochasticSoilProfileEntity_StochasticSoilModelEntity' FOREIGN KEY ('StochasticSoilModelEntityId') REFERENCES 'StochasticSoilModelEntity' ('StochasticSoilModelEntityId') ON DELETE No Action ON UPDATE No Action +) +; + /* Create Indexes and Triggers */ CREATE INDEX 'IXFK_AssessmentSectionEntity_ProjectEntity' @@ -107,3 +157,15 @@ CREATE INDEX 'IXFK_ReferenceLinePointEntity_AssessmentSectionEntity' ON 'ReferenceLinePointEntity' ('AssessmentSectionEntityId' ASC) ; + +CREATE INDEX 'IXFK_StochasticSoilModelEntity_FailureMechanismEntity' + ON 'StochasticSoilModelEntity' ('FailureMechanismEntityId' ASC) +; + +CREATE INDEX 'IXFK_StochasticSoilProfileEntity_SoilProfileEntity' + ON 'StochasticSoilProfileEntity' ('SoilProfileEntityId' ASC) +; + +CREATE INDEX 'IXFK_StochasticSoilProfileEntity_StochasticSoilModelEntity' + ON 'StochasticSoilProfileEntity' ('StochasticSoilModelEntityId' ASC) +; Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/FailureMechanismEntity.cs =================================================================== diff -u -r8b5a6f938fe2b04cd78623649df37580e145055f -r4e14ed090d09a220a790b3562ceb4232dab1cce6 --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/FailureMechanismEntity.cs (.../FailureMechanismEntity.cs) (revision 8b5a6f938fe2b04cd78623649df37580e145055f) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/FailureMechanismEntity.cs (.../FailureMechanismEntity.cs) (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) @@ -35,10 +35,18 @@ public partial class FailureMechanismEntity { + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] + public FailureMechanismEntity() + { + this.StochasticSoilModelEntities = new HashSet(); + } + public long FailureMechanismEntityId { get; set; } public long AssessmentSectionEntityId { get; set; } public short FailureMechanismType { get; set; } public virtual AssessmentSectionEntity AssessmentSectionEntity { get; set; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection StochasticSoilModelEntities { get; set; } } } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/IRingtoetsEntities.cs =================================================================== diff -u -r8b5a6f938fe2b04cd78623649df37580e145055f -r4e14ed090d09a220a790b3562ceb4232dab1cce6 --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/IRingtoetsEntities.cs (.../IRingtoetsEntities.cs) (revision 8b5a6f938fe2b04cd78623649df37580e145055f) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/IRingtoetsEntities.cs (.../IRingtoetsEntities.cs) (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) @@ -60,6 +60,12 @@ /// DbSet ReferenceLinePointEntities { get; } + /// + /// Gets a of containing + /// every entity found in the database. + /// + DbSet StochasticSoilModelEntities { 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.Context.cs =================================================================== diff -u -r4e65fa5d8abdf1c0a9238492cdbcd7d2b3fa2d0f -r4e14ed090d09a220a790b3562ceb4232dab1cce6 --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.Context.cs (.../RingtoetsEntities.Context.cs) (revision 4e65fa5d8abdf1c0a9238492cdbcd7d2b3fa2d0f) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.Context.cs (.../RingtoetsEntities.Context.cs) (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) @@ -57,6 +57,10 @@ public virtual DbSet HydraulicLocationEntities { get; set; } public virtual DbSet ProjectEntities { get; set; } public virtual DbSet ReferenceLinePointEntities { get; set; } + public virtual DbSet SoilLayerEntities { get; set; } + public virtual DbSet SoilProfileEntities { get; set; } + public virtual DbSet StochasticSoilModelEntities { get; set; } + public virtual DbSet StochasticSoilProfileEntities { get; set; } public virtual DbSet VersionEntities { get; set; } } } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.Designer.cs =================================================================== diff -u -r8b5a6f938fe2b04cd78623649df37580e145055f -r4e14ed090d09a220a790b3562ceb4232dab1cce6 --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.Designer.cs (.../RingtoetsEntities.Designer.cs) (revision 8b5a6f938fe2b04cd78623649df37580e145055f) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.Designer.cs (.../RingtoetsEntities.Designer.cs) (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) @@ -1,4 +1,4 @@ -// T4 code generation is enabled for model 'D:\Clean_WTI2017\Application\Ringtoets\src\Application.Ringtoets.Storage\DbContext\RingtoetsEntities.edmx'. +// T4 code generation is enabled for model 'D:\repos\WettelijkToetsInstrumentarium\Application\Ringtoets\src\Application.Ringtoets.Storage\DbContext\RingtoetsEntities.edmx'. // To enable legacy code generation, change the value of the 'Code Generation Strategy' designer // property to 'Legacy ObjectContext'. This property is available in the Properties Window when the model // is open in the designer. Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.edmx =================================================================== diff -u -r4e65fa5d8abdf1c0a9238492cdbcd7d2b3fa2d0f -r4e14ed090d09a220a790b3562ceb4232dab1cce6 --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.edmx (.../RingtoetsEntities.edmx) (revision 4e65fa5d8abdf1c0a9238492cdbcd7d2b3fa2d0f) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.edmx (.../RingtoetsEntities.edmx) (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) @@ -4,7 +4,7 @@ - + @@ -55,6 +55,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -112,12 +146,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -135,6 +221,22 @@ + + + + + + + + + + + + + + + + @@ -146,6 +248,10 @@ + + + + @@ -163,6 +269,22 @@ + + + + + + + + + + + + + + + + @@ -189,6 +311,7 @@ + @@ -222,6 +345,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -279,6 +443,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -340,6 +552,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.edmx.diagram =================================================================== diff -u -r4e65fa5d8abdf1c0a9238492cdbcd7d2b3fa2d0f -r4e14ed090d09a220a790b3562ceb4232dab1cce6 --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.edmx.diagram (.../RingtoetsEntities.edmx.diagram) (revision 4e65fa5d8abdf1c0a9238492cdbcd7d2b3fa2d0f) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.edmx.diagram (.../RingtoetsEntities.edmx.diagram) (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) @@ -5,16 +5,24 @@ - - - - - + + + + + + + + + + + + + Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/SoilLayerEntity.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/SoilLayerEntity.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/SoilLayerEntity.cs (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) @@ -0,0 +1,45 @@ +// 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. + +//------------------------------------------------------------------------------ +// +// This code was generated from a template. +// +// Manual changes to this file may cause unexpected behavior in your application. +// Manual changes to this file will be overwritten if the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Application.Ringtoets.Storage.DbContext +{ + using System; + using System.Collections.Generic; + + public partial class SoilLayerEntity + { + public long SoilLayerEntityId { get; set; } + public long SoilProfileEntityId { get; set; } + public Nullable Top { get; set; } + public Nullable IsAquifer { get; set; } + + public virtual SoilProfileEntity SoilProfileEntity { get; set; } + } +} Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/SoilProfileEntity.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/SoilProfileEntity.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/SoilProfileEntity.cs (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) @@ -0,0 +1,53 @@ +// 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. + +//------------------------------------------------------------------------------ +// +// This code was generated from a template. +// +// Manual changes to this file may cause unexpected behavior in your application. +// Manual changes to this file will be overwritten if the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Application.Ringtoets.Storage.DbContext +{ + using System; + using System.Collections.Generic; + + public partial class SoilProfileEntity + { + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] + public SoilProfileEntity() + { + this.SoilLayerEntities = new HashSet(); + this.StochasticSoilProfileEntities = new HashSet(); + } + + public long SoilProfileEntityId { get; set; } + public string Bottom { get; set; } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection SoilLayerEntities { get; set; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection StochasticSoilProfileEntities { get; set; } + } +} Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/StochasticSoilModelEntity.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/StochasticSoilModelEntity.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/StochasticSoilModelEntity.cs (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) @@ -0,0 +1,53 @@ +// 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. + +//------------------------------------------------------------------------------ +// +// This code was generated from a template. +// +// Manual changes to this file may cause unexpected behavior in your application. +// Manual changes to this file will be overwritten if the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Application.Ringtoets.Storage.DbContext +{ + using System; + using System.Collections.Generic; + + public partial class StochasticSoilModelEntity + { + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] + public StochasticSoilModelEntity() + { + this.StochasticSoilProfileEntities = new HashSet(); + } + + public long StochasticSoilModelEntityId { get; set; } + public long FailureMechanismEntityId { get; set; } + public string Name { get; set; } + public string SegmentName { get; set; } + + public virtual FailureMechanismEntity FailureMechanismEntity { get; set; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection StochasticSoilProfileEntities { get; set; } + } +} Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/StochasticSoilProfileEntity.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/StochasticSoilProfileEntity.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/StochasticSoilProfileEntity.cs (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) @@ -0,0 +1,46 @@ +// 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. + +//------------------------------------------------------------------------------ +// +// This code was generated from a template. +// +// Manual changes to this file may cause unexpected behavior in your application. +// Manual changes to this file will be overwritten if the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Application.Ringtoets.Storage.DbContext +{ + using System; + using System.Collections.Generic; + + public partial class StochasticSoilProfileEntity + { + public long StochasticSoilProfileEntityId { get; set; } + public long SoilProfileEntityId { get; set; } + public long StochasticSoilModelEntityId { get; set; } + public Nullable Probability { get; set; } + + public virtual SoilProfileEntity SoilProfileEntity { get; set; } + public virtual StochasticSoilModelEntity StochasticSoilModelEntity { get; set; } + } +} Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/ReferenceLinePersistor.cs =================================================================== diff -u -ra9aafffab97152303562110b1d789bacb465ce24 -r4e14ed090d09a220a790b3562ceb4232dab1cce6 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/ReferenceLinePersistor.cs (.../ReferenceLinePersistor.cs) (revision a9aafffab97152303562110b1d789bacb465ce24) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/ReferenceLinePersistor.cs (.../ReferenceLinePersistor.cs) (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) @@ -25,7 +25,6 @@ using System.Linq; using Application.Ringtoets.Storage.Converters; using Application.Ringtoets.Storage.DbContext; -using Ringtoets.Common.Data; using Ringtoets.Common.Data.AssessmentSection; namespace Application.Ringtoets.Storage.Persistors Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/StochasticSoilModelPersistor.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/StochasticSoilModelPersistor.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/StochasticSoilModelPersistor.cs (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) @@ -0,0 +1,145 @@ +// 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.Collections.Generic; +using System.Data.Entity; +using System.Linq; +using Application.Ringtoets.Storage.Converters; +using Application.Ringtoets.Storage.DbContext; +using Application.Ringtoets.Storage.Exceptions; +using Application.Ringtoets.Storage.Properties; +using Ringtoets.Piping.Data; + +namespace Application.Ringtoets.Storage.Persistors +{ + public class StochasticSoilModelPersistor + { + private readonly StochasticSoilModelConverter converter; + private readonly ICollection modifiedList = new List(); + private readonly Dictionary insertedList = new Dictionary(); + private readonly DbSet stochasticSoilModelSet; + + public StochasticSoilModelPersistor(IRingtoetsEntities ringtoetsContext) + { + if (ringtoetsContext == null) + { + throw new ArgumentNullException("ringtoetsContext"); + } + stochasticSoilModelSet = ringtoetsContext.StochasticSoilModelEntities; + converter = new StochasticSoilModelConverter(); + } + + public IEnumerable LoadModel(IEnumerable entities) + { + if (entities == null) + { + throw new ArgumentNullException("entities"); + } + return entities.Select(e => converter.ConvertEntityToModel(e)); + } + + public void InsertModel(IList parentNavigationProperty, StochasticSoilModel stochasticSoilModel) + { + if (parentNavigationProperty == null) + { + throw new ArgumentNullException("parentNavigationProperty"); + } + if (stochasticSoilModel == null) + { + return; + } + var entity = new StochasticSoilModelEntity(); + converter.ConvertModelToEntity(stochasticSoilModel, entity); + parentNavigationProperty.Add(entity); + insertedList.Add(entity, stochasticSoilModel); + } + + public void UpdateModel(IList parentNavigationProperty, IList model) + { + if (model == null) + { + return; + } + + if (parentNavigationProperty == null) + { + throw new ArgumentNullException("parentNavigationProperty"); + } + + foreach (var stochasticSoilModel in model) + { + if (stochasticSoilModel == null) + { + throw new ArgumentException("A null StochasticSoilModel cannot be added"); + } + + if (stochasticSoilModel.StorageId < 1) + { + InsertModel(parentNavigationProperty, stochasticSoilModel); + } + else + { + StochasticSoilModelEntity entity; + try + { + entity = parentNavigationProperty.SingleOrDefault(db => db.StochasticSoilModelEntityId == stochasticSoilModel.StorageId); + } + catch (InvalidOperationException exception) + { + throw new EntityNotFoundException(String.Format(Resources.Error_Entity_Not_Found_0_1, "StochasticSoilModelEntity", stochasticSoilModel.StorageId), exception); + } + + if (entity == null) + { + throw new EntityNotFoundException(String.Format(Resources.Error_Entity_Not_Found_0_1, "StochasticSoilModelEntity", stochasticSoilModel.StorageId)); + } + + modifiedList.Add(entity); + + converter.ConvertModelToEntity(stochasticSoilModel, entity); + } + } + + RemoveUnModifiedEntries(parentNavigationProperty); + } + + private void RemoveUnModifiedEntries(IList parentNavigationProperty) + { + var untouchedModifiedList = parentNavigationProperty.Where(e => e.StochasticSoilModelEntityId > 0 && !modifiedList.Contains(e)); + stochasticSoilModelSet.RemoveRange(untouchedModifiedList); + + modifiedList.Clear(); + } + + /// + /// Perform actions that can only be executed after has been called. + /// + public void PerformPostSaveActions() + { + foreach (var entry in insertedList) + { + entry.Value.StorageId = entry.Key.StochasticSoilModelEntityId; + } + insertedList.Clear(); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj =================================================================== diff -u -r8b5a6f938fe2b04cd78623649df37580e145055f -r4e14ed090d09a220a790b3562ceb4232dab1cce6 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 8b5a6f938fe2b04cd78623649df37580e145055f) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) @@ -86,8 +86,10 @@ + + @@ -133,6 +135,10 @@ {CE994CC9-6F6A-48AC-B4BE-02C30A21F4DB} Ringtoets.Piping.Data + + {955E574D-67CE-4347-AA6B-7DF8A04ED754} + Ringtoets.Piping.Data.TestUtil + {50963f12-448c-41ba-a62c-cdb0ab8d21e0} Application.Ringtoets.Storage Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/ReferenceLineConverterTest.cs =================================================================== diff -u -ra9aafffab97152303562110b1d789bacb465ce24 -r4e14ed090d09a220a790b3562ceb4232dab1cce6 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/ReferenceLineConverterTest.cs (.../ReferenceLineConverterTest.cs) (revision a9aafffab97152303562110b1d789bacb465ce24) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/ReferenceLineConverterTest.cs (.../ReferenceLineConverterTest.cs) (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) @@ -26,7 +26,6 @@ using Application.Ringtoets.Storage.DbContext; using Core.Common.Base.Geometry; using NUnit.Framework; -using Ringtoets.Common.Data; using Ringtoets.Common.Data.AssessmentSection; namespace Application.Ringtoets.Storage.Test.Converters Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/StochasticSoilModelConverterTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/StochasticSoilModelConverterTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/StochasticSoilModelConverterTest.cs (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) @@ -0,0 +1,115 @@ +using System; +using Application.Ringtoets.Storage.Converters; +using Application.Ringtoets.Storage.DbContext; +using NUnit.Framework; +using Ringtoets.Piping.Data; + +namespace Application.Ringtoets.Storage.Test.Converters +{ + [TestFixture] + public class StochasticSoilModelConverterTest + { + + [Test] + public void Constructor_Always_NewInstance() + { + // Call + var converter = new StochasticSoilModelConverter(); + + // Assert + Assert.IsInstanceOf>(converter); + } + + [Test] + public void ConvertEntityToModel_NullEntity_ThrowsArgumentNullException() + { + // Setup + var converter = new StochasticSoilModelConverter(); + + // 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 segmentName = "SomeSegmentName"; + var name = "SomeName"; + var entity = new StochasticSoilModelEntity + { + StochasticSoilModelEntityId = storageId, + Name = name, + SegmentName = segmentName + }; + 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); + } + + [Test] + public void ConvertModelToEntity_NullModel_ThrowsArgumentNullException() + { + // Setup + var converter = new StochasticSoilModelConverter(); + + // Call + TestDelegate test = () => converter.ConvertModelToEntity(null, new StochasticSoilModelEntity()); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("modelObject", exception.ParamName); + } + + [Test] + public void ConvertModelToEntity_NullEntity_ThrowsArgumentNullException() + { + // Setup + var converter = new StochasticSoilModelConverter(); + + // Call + TestDelegate test = () => converter.ConvertModelToEntity(new StochasticSoilModel(-1, string.Empty, string.Empty), null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void ConvertModelToEntity_ValidModelValidEntity_ReturnsModelAsEntity() + { + // 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 model = new StochasticSoilModel(id, name, segmentName) + { + StorageId = storageId + }; + + // Call + converter.ConvertModelToEntity(model, entity); + + // Assert + Assert.AreEqual(storageId, entity.StochasticSoilModelEntityId); + Assert.AreEqual(name, entity.Name); + Assert.AreEqual(segmentName, entity.SegmentName); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Persistors/AssessmentSectionPersistorTest.cs =================================================================== diff -u -r04b631b486b742c5339deb1d5504bb13ab5e248d -r4e14ed090d09a220a790b3562ceb4232dab1cce6 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Persistors/AssessmentSectionPersistorTest.cs (.../AssessmentSectionPersistorTest.cs) (revision 04b631b486b742c5339deb1d5504bb13ab5e248d) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Persistors/AssessmentSectionPersistorTest.cs (.../AssessmentSectionPersistorTest.cs) (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) @@ -27,6 +27,7 @@ using Application.Ringtoets.Storage.Exceptions; using Application.Ringtoets.Storage.Persistors; using Application.Ringtoets.Storage.TestUtil; +using Core.Common.Base.Geometry; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; @@ -138,6 +139,13 @@ Name = otherHydraulicDatabaseLocationName, DesignWaterLevel = otherHydraulicDatabaseLocationDesignWaterLevel, HydraulicLocationEntityId = otherHydraulicDatabaseLocationStorageId, LocationId = otherHydraulicDatabaseLocationLocationId, LocationX = otherHydraulicDatabaseLocationX, LocationY = otherHydraulicDatabaseLocationY, } + }, + ReferenceLinePointEntities = new [] + { + new ReferenceLinePointEntity + { + X = Convert.ToDecimal(1.1), Y = Convert.ToDecimal(2.3) + } } }; mockRepository.ReplayAll(); @@ -171,6 +179,11 @@ Assert.AreEqual(otherHydraulicDatabaseLocationX, secondLocation.Location.X); Assert.AreEqual(otherHydraulicDatabaseLocationY, secondLocation.Location.Y); + var line = section.ReferenceLine; + Assert.AreEqual(1, line.Points.Count()); + Assert.AreEqual(1.1, line.Points.ElementAt(0).X); + Assert.AreEqual(2.3, line.Points.ElementAt(0).Y); + mockRepository.VerifyAll(); } @@ -193,6 +206,13 @@ { Name = "test", DesignWaterLevel = 15.6, HydraulicLocationEntityId = 1234L, LocationId = 1300001, LocationX = 253, LocationY = 123 } + }, + ReferenceLinePointEntities = new [] + { + new ReferenceLinePointEntity + { + X = Convert.ToDecimal(1.1), Y = Convert.ToDecimal(2.3) + } } }, new AssessmentSectionEntity @@ -206,6 +226,13 @@ { Name = "test2", DesignWaterLevel = 135.6, HydraulicLocationEntityId = 134L, LocationId = 1400001, LocationX = 23, LocationY = 23 } + }, + ReferenceLinePointEntities = new [] + { + new ReferenceLinePointEntity + { + X = Convert.ToDecimal(2.2), Y = Convert.ToDecimal(6.3) + } } } }; @@ -238,6 +265,11 @@ Assert.AreEqual(locations[j].LocationX, loadedModelsList[i].HydraulicBoundaryDatabase.Locations[j].Location.X); Assert.AreEqual(locations[j].LocationY, loadedModelsList[i].HydraulicBoundaryDatabase.Locations[j].Location.Y); } + + var referenceLinePoints = parentNavigationPropertyList[i].ReferenceLinePointEntities; + Assert.AreEqual(1, referenceLinePoints.Count); + Assert.AreEqual(referenceLinePoints.ElementAt(0).X, loadedModelsList[i].ReferenceLine.Points.ElementAt(0).X); + Assert.AreEqual(referenceLinePoints.ElementAt(0).Y, loadedModelsList[i].ReferenceLine.Points.ElementAt(0).Y); } mockRepository.VerifyAll(); @@ -299,7 +331,7 @@ { Norm = norm }, - HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase() + HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(), }; AssessmentSectionPersistor persistor = new AssessmentSectionPersistor(ringtoetsEntities); @@ -382,11 +414,25 @@ const double locationX = 253; const double locationY = 123; - AssessmentSection assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); - assessmentSection.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); - assessmentSection.HydraulicBoundaryDatabase.Locations.Add(new HydraulicBoundaryLocation(locationId, name, locationX, locationY) + AssessmentSection assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) { - StorageId = hydraulicLocationEntityId, DesignWaterLevel = designWaterLevel + HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase() + { + Locations = + { + new HydraulicBoundaryLocation(locationId, name, locationX, locationY) + { + StorageId = hydraulicLocationEntityId, DesignWaterLevel = designWaterLevel + } + } + }, + ReferenceLine = new ReferenceLine() + }; + var pointX = 3.2; + var pointY = 1.1; + assessmentSection.ReferenceLine.SetGeometry(new[] + { + new Point2D(pointX, pointY) }); IList parentNavigationProperty = new List(); @@ -410,6 +456,9 @@ Assert.AreEqual(locationX, locationEntity.LocationX); Assert.AreEqual(locationY, locationEntity.LocationY); + Assert.AreEqual(pointX, entity.ReferenceLinePointEntities.First().X); + Assert.AreEqual(pointY, entity.ReferenceLinePointEntities.First().Y); + mockRepository.VerifyAll(); } @@ -698,12 +747,19 @@ AssessmentSection assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) { StorageId = storageId, - HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase() + HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(), + ReferenceLine = new ReferenceLine() }; assessmentSection.HydraulicBoundaryDatabase.Locations.Add(new HydraulicBoundaryLocation(1300001, "test", 253, 123) { StorageId = hydraulicLocationEntityId, }); + var pointX = 2.4; + var pointY = 3.0; + assessmentSection.ReferenceLine.SetGeometry(new [] + { + new Point2D(pointX, pointY) + }); IList parentNavigationProperty = new List { @@ -716,7 +772,8 @@ { HydraulicLocationEntityId = hydraulicLocationEntityId } - } + }, + ReferenceLinePointEntities = new List() } }; @@ -735,6 +792,10 @@ var hydraulicLocationEntity = entity.HydraulicLocationEntities.First(); Assert.AreEqual(hydraulicLocationEntityId, hydraulicLocationEntity.HydraulicLocationEntityId); + var referenceLinePointEntity = entity.ReferenceLinePointEntities.First(); + Assert.AreEqual(pointX, referenceLinePointEntity.X); + Assert.AreEqual(pointY, referenceLinePointEntity.Y); + mockRepository.VerifyAll(); } Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Persistors/HydraulicBoundaryLocationPersistorTest.cs =================================================================== diff -u -rbbe8871cfabad25988ec8f94115da2c485267118 -r4e14ed090d09a220a790b3562ceb4232dab1cce6 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Persistors/HydraulicBoundaryLocationPersistorTest.cs (.../HydraulicBoundaryLocationPersistorTest.cs) (revision bbe8871cfabad25988ec8f94115da2c485267118) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Persistors/HydraulicBoundaryLocationPersistorTest.cs (.../HydraulicBoundaryLocationPersistorTest.cs) (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) @@ -420,16 +420,14 @@ var persistor = new HydraulicBoundaryLocationPersistor(ringtoetsEntitiesMock); IList parentNavigationProperty = new List(); + HydraulicBoundaryLocation model = new HydraulicBoundaryLocation(13001, "test", 13, 52) { StorageId = 0 }; HydraulicBoundaryDatabase hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); hydraulicBoundaryDatabase.Locations.Add(model); - // Precondition - Assert.AreEqual(0, parentNavigationProperty.Count, "Precondition failed: parentNavigationProperty should be empty"); - // Call persistor.UpdateModel(parentNavigationProperty, hydraulicBoundaryDatabase); @@ -478,7 +476,7 @@ ringtoetsEntitiesMock.HydraulicLocationEntities.Add(entityToDelete); - ObservableCollection parentNavigationProperty = new ObservableCollection + var parentNavigationProperty = new List { entityToDelete }; Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Persistors/StochasticSoilModelPersistorTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Persistors/StochasticSoilModelPersistorTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Persistors/StochasticSoilModelPersistorTest.cs (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) @@ -0,0 +1,501 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Application.Ringtoets.Storage.DbContext; +using Application.Ringtoets.Storage.Exceptions; +using Application.Ringtoets.Storage.Persistors; +using Application.Ringtoets.Storage.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Piping.Data; + +namespace Application.Ringtoets.Storage.Test.Persistors +{ + [TestFixture] + public class StochasticSoilModelPersistorTest + { + private MockRepository mockRepository; + + [SetUp] + public void Setup() + { + mockRepository = new MockRepository(); + } + + [Test] + public void Constructor_EmptyDataSet_NewInstance() + { + // Setup + var ringtoetsEntitiesMock = RingtoetsEntitiesHelper.Create(mockRepository); + mockRepository.ReplayAll(); + + // Call + StochasticSoilModelPersistor persistor = new StochasticSoilModelPersistor(ringtoetsEntitiesMock); + + // Assert + Assert.IsInstanceOf(persistor); + + mockRepository.VerifyAll(); + } + + [Test] + public void Constructor_NullDataSet_ThrowsAgrumentNullException() + { + // Call + TestDelegate test = () => new StochasticSoilModelPersistor(null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("ringtoetsContext", exception.ParamName); + } + + [Test] + public void LoadModel_NullEntity_ThrowsArgumentNullException() + { + // Setup + var ringtoetsEntitiesMock = RingtoetsEntitiesHelper.Create(mockRepository); + mockRepository.ReplayAll(); + + var persistor = new StochasticSoilModelPersistor(ringtoetsEntitiesMock); + + // Call + TestDelegate test = () => persistor.LoadModel(null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entities", exception.ParamName); + mockRepository.VerifyAll(); + } + + [Test] + public void LoadModel_ValidEntityValidModel_EntityAsModel() + { + // Setup + var ringtoetsEntitiesMock = RingtoetsEntitiesHelper.Create(mockRepository); + mockRepository.ReplayAll(); + + var persistor = new StochasticSoilModelPersistor(ringtoetsEntitiesMock); + + const string name = "someName"; + const string segmentName = "someSegmentName"; + long storageId = new Random(21).Next(); + var entity = new StochasticSoilModelEntity + { + Name = name, + SegmentName = segmentName, + StochasticSoilModelEntityId = storageId + }; + + // Call + List models = persistor.LoadModel(new List + { + entity + }).ToList(); + + // Assert + Assert.AreEqual(1, models.Count); + var model = models[0]; + Assert.AreEqual(name, model.Name); + Assert.AreEqual(segmentName, model.SegmentName); + Assert.AreEqual(storageId, model.StorageId); + + mockRepository.VerifyAll(); + } + + [Test] + public void InsertModel_NullParentNavigationProperty_ThrowsArgumentNullException() + { + // Setup + var ringtoetsEntitiesMock = RingtoetsEntitiesHelper.Create(mockRepository); + mockRepository.ReplayAll(); + + var persistor = new StochasticSoilModelPersistor(ringtoetsEntitiesMock); + + // Call + TestDelegate test = () => persistor.InsertModel(null, new StochasticSoilModel(-1, string.Empty, string.Empty)); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("parentNavigationProperty", exception.ParamName); + + mockRepository.VerifyAll(); + } + + [Test] + public void InsertModel_NullModel_DoesNotAddEntityInParentNavigationProperty() + { + // Setup + var ringtoetsEntitiesMock = RingtoetsEntitiesHelper.Create(mockRepository); + mockRepository.ReplayAll(); + + var persistor = new StochasticSoilModelPersistor(ringtoetsEntitiesMock); + var parentNavigationProperty = new List(); + + // Call + TestDelegate test = () => persistor.InsertModel(parentNavigationProperty, null); + + // Assert + Assert.DoesNotThrow(test); + Assert.IsEmpty(parentNavigationProperty); + + mockRepository.VerifyAll(); + } + + [Test] + public void InsertModel_SingleEntityInParentNavigationPropertyStochasticSoilModelWithSameStorageId_StochasticSoilModelAsEntityInParentNavigationProperty() + { + // Setup + var ringtoetsEntitiesMock = RingtoetsEntitiesHelper.Create(mockRepository); + mockRepository.ReplayAll(); + + var persistor = new StochasticSoilModelPersistor(ringtoetsEntitiesMock); + + const long storageId = 1234L; + StochasticSoilModelEntity entityToDelete = new StochasticSoilModelEntity + { + StochasticSoilModelEntityId = storageId + }; + + IList parentNavigationProperty = new List + { + entityToDelete + }; + + StochasticSoilModel model = new StochasticSoilModel(-1, string.Empty, string.Empty) + { + StorageId = storageId + }; + + // Call + persistor.InsertModel(parentNavigationProperty, model); + + // Assert + Assert.AreEqual(2, parentNavigationProperty.Count); + var parentNavigationPropertyList = parentNavigationProperty.ToList(); + var entity = parentNavigationPropertyList[1]; + Assert.AreEqual(storageId, entity.StochasticSoilModelEntityId); + + mockRepository.VerifyAll(); + } + + [Test] + public void UpdateModel_NullDatasetValidModel_ThrowsArgumentNullException() + { + // Setup + var ringtoetsEntitiesMock = RingtoetsEntitiesHelper.Create(mockRepository); + mockRepository.ReplayAll(); + + var persistor = new StochasticSoilModelPersistor(ringtoetsEntitiesMock); + + var soilModels = new[] + { + new StochasticSoilModel(-1, string.Empty, string.Empty) + }; + + // Call + TestDelegate test = () => persistor.UpdateModel(null, soilModels); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("parentNavigationProperty", exception.ParamName); + + mockRepository.VerifyAll(); + } + + [Test] + public void UpdateModel_EmptyDatasetNullModel_DoesNotThrow() + { + // Setup + var ringtoetsEntitiesMock = RingtoetsEntitiesHelper.Create(mockRepository); + mockRepository.ReplayAll(); + + var persistor = new StochasticSoilModelPersistor(ringtoetsEntitiesMock); + IList parentNavigationProperty = new List(); + + // Call + TestDelegate test = () => persistor.UpdateModel(parentNavigationProperty, null); + + // Assert + Assert.DoesNotThrow(test); + } + + [Test] + public void UpdateModel_EmptyDatasetNullEntryInModel_ArgumentException() + { + // Setup + var ringtoetsEntitiesMock = RingtoetsEntitiesHelper.Create(mockRepository); + mockRepository.ReplayAll(); + + var persistor = new StochasticSoilModelPersistor(ringtoetsEntitiesMock); + IList parentNavigationProperty = new List(); + + var soilModels = new StochasticSoilModel[] + { + null + }; + + // Call + TestDelegate test = () => persistor.UpdateModel(parentNavigationProperty, soilModels); + + // Assert + var message = Assert.Throws(test).Message; + Assert.AreEqual("A null StochasticSoilModel cannot be added", message); + } + + [Test] + public void UpdateModel_EmptyDataset_ThrowsEntityNotFoundException() + { + // Setup + const long storageId = 1234L; + + var ringtoetsEntitiesMock = RingtoetsEntitiesHelper.Create(mockRepository); + mockRepository.ReplayAll(); + + var persistor = new StochasticSoilModelPersistor(ringtoetsEntitiesMock); + IList parentNavigationProperty = new List(); + + var soilModels = new[] + { + new StochasticSoilModel(-1, string.Empty, string.Empty) + { + StorageId = storageId + } + }; + + // Call + TestDelegate test = () => persistor.UpdateModel(parentNavigationProperty, soilModels); + + // Assert + var expectedMessage = String.Format("Het object 'StochasticSoilModelEntity' met id '{0}' is niet gevonden.", storageId); + var exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + mockRepository.VerifyAll(); + } + + [Test] + public void UpdateModel_DuplicateEntityInDataset_ThrowsEntityNotFoundException() + { + // Setup + const long storageId = 1234L; + + var ringtoetsEntitiesMock = RingtoetsEntitiesHelper.Create(mockRepository); + mockRepository.ReplayAll(); + + var persistor = new StochasticSoilModelPersistor(ringtoetsEntitiesMock); + IList parentNavigationProperty = new List + { + new StochasticSoilModelEntity + { + StochasticSoilModelEntityId = storageId + }, + new StochasticSoilModelEntity + { + StochasticSoilModelEntityId = storageId + } + }; + + var soilModels = new[] + { + new StochasticSoilModel(-1, string.Empty, string.Empty) + { + StorageId = storageId + } + }; + + // Call + TestDelegate test = () => persistor.UpdateModel(parentNavigationProperty, soilModels); + + // Assert + var expectedMessage = String.Format("Het object 'StochasticSoilModelEntity' met id '{0}' is niet gevonden.", storageId); + var exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + mockRepository.VerifyAll(); + } + + [Test] + public void UpdateModel_SingleEntityInParentNavigationPropertySingleStochasticSoilModelWithStorageId_UpdatedStochasticSoilModelAsEntityInParentNavigationProperty() + { + // Setup + const long storageId = 1234L; + + var ringtoetsEntitiesMock = RingtoetsEntitiesHelper.Create(mockRepository); + mockRepository.ReplayAll(); + + var persistor = new StochasticSoilModelPersistor(ringtoetsEntitiesMock); + var parentNavigationProperty = new [] + { + new StochasticSoilModelEntity + { + StochasticSoilModelEntityId = storageId + } + }; + + var name = "someName"; + var segmentName = "someSegmentName"; + var soilModels = new[] + { + new StochasticSoilModel(-1, name, segmentName) + { + StorageId = storageId + } + }; + + // Call + persistor.UpdateModel(parentNavigationProperty, soilModels); + + // Assert + Assert.AreEqual(1, parentNavigationProperty.Length); + var parentNavigationPropertyList = parentNavigationProperty.ToList(); + var entity = parentNavigationPropertyList[0]; + Assert.AreEqual(storageId, entity.StochasticSoilModelEntityId); + Assert.AreEqual(name, entity.Name); + Assert.AreEqual(segmentName, entity.SegmentName); + mockRepository.VerifyAll(); + } + + [Test] + public void UpdateModel_NoStorageIdSet_InsertNewEntity() + { + // Setup + var ringtoetsEntitiesMock = RingtoetsEntitiesHelper.Create(mockRepository); + mockRepository.ReplayAll(); + + var persistor = new StochasticSoilModelPersistor(ringtoetsEntitiesMock); + + IList parentNavigationProperty = new List(); + + var name = "someName"; + var segmentName = "someSegmentName"; + var soilModels = new[] + { + new StochasticSoilModel(-1, name, segmentName) + { + StorageId = 0 + } + }; + + // Call + persistor.UpdateModel(parentNavigationProperty, soilModels); + + // Assert + Assert.AreEqual(1, parentNavigationProperty.Count); + + mockRepository.VerifyAll(); + } + + [Test] + public void UpdateModel_SingleEntityInParentNavigationPropertySingleStochasticSoilModelWithoutStorageId_UpdatedStochasticSoilModelAsEntityInParentNavigationPropertyAndOthersDeletedInDbSet() + { + // Setup + const long storageId = 0L; // Newly inserted entities have Id = 0 untill they are saved + + var ringtoetsEntitiesMock = RingtoetsEntitiesHelper.Create(mockRepository); + mockRepository.ReplayAll(); + + StochasticSoilModelEntity entityToDelete = new StochasticSoilModelEntity + { + StochasticSoilModelEntityId = 4567L, + Name = "Entity to delete" + }; + + ringtoetsEntitiesMock.StochasticSoilModelEntities.Add(entityToDelete); + + var parentNavigationProperty = new List + { + entityToDelete + }; + + mockRepository.ReplayAll(); + + StochasticSoilModelPersistor persistor = new StochasticSoilModelPersistor(ringtoetsEntitiesMock); + var name = "someName"; + var segmentName = "someSegmentName"; + var soilModels = new[] + { + new StochasticSoilModel(-1, name, segmentName) + }; + + // Call + persistor.UpdateModel(parentNavigationProperty, soilModels); + + // Assert + CollectionAssert.IsEmpty(ringtoetsEntitiesMock.StochasticSoilModelEntities); + Assert.AreEqual(2, parentNavigationProperty.Count); + StochasticSoilModelEntity entity = parentNavigationProperty.SingleOrDefault(x => x.StochasticSoilModelEntityId == storageId); + Assert.IsNotNull(entity); + Assert.AreEqual(storageId, entity.StochasticSoilModelEntityId); + Assert.AreEqual(name, entity.Name); + Assert.AreEqual(segmentName, entity.SegmentName); + + mockRepository.VerifyAll(); + } + + [Test] + public void PerformPostSaveActions_NoInserts_DoesNotThrowException() + { + // Setup + var ringtoetsEntitiesMock = RingtoetsEntitiesHelper.Create(mockRepository); + mockRepository.ReplayAll(); + + var persistor = new StochasticSoilModelPersistor(ringtoetsEntitiesMock); + + // Call + TestDelegate test = () => persistor.PerformPostSaveActions(); + + // Assert + Assert.DoesNotThrow(test); + + mockRepository.VerifyAll(); + } + + [Test] + [TestCase(0)] + [TestCase(1)] + [TestCase(2)] + public void PerformPostSaveActions_MultipleModelsInsertedWithoutStorageId_ModelsWithStorageId(int numberOfInserts) + { + // Setup + var ringtoetsEntitiesMock = RingtoetsEntitiesHelper.Create(mockRepository); + mockRepository.ReplayAll(); + + var parentNavigationProperty = new List(); + + IList stochasticSoilModel = new List(); + for (var i = 0; i < numberOfInserts; i++) + { + stochasticSoilModel.Add(new StochasticSoilModel(-1, string.Empty, string.Empty) + { + StorageId = 0L + }); + } + + var persistor = new StochasticSoilModelPersistor(ringtoetsEntitiesMock); + + try + { + persistor.UpdateModel(parentNavigationProperty, stochasticSoilModel); + } + catch (Exception) + { + Assert.Fail("Precondition failed: persistor.UpdateModel"); + } + + // Call + for (var i = 0; i < parentNavigationProperty.Count; i++) + { + parentNavigationProperty[i].StochasticSoilModelEntityId = 1L + i; + } + persistor.PerformPostSaveActions(); + + // Assert + Assert.AreEqual(stochasticSoilModel.Count, parentNavigationProperty.Count); + foreach (var entity in parentNavigationProperty) + { + StochasticSoilModel insertedModel = stochasticSoilModel.SingleOrDefault(x => x.StorageId == entity.StochasticSoilModelEntityId); + Assert.IsNotNull(insertedModel); + } + + mockRepository.VerifyAll(); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/Application.Ringtoets.Storage.TestUtil.csproj =================================================================== diff -u -r98df6e59fb589e5326b8f904dac98d402cb35b9c -r4e14ed090d09a220a790b3562ceb4232dab1cce6 --- Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/Application.Ringtoets.Storage.TestUtil.csproj (.../Application.Ringtoets.Storage.TestUtil.csproj) (revision 98df6e59fb589e5326b8f904dac98d402cb35b9c) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/Application.Ringtoets.Storage.TestUtil.csproj (.../Application.Ringtoets.Storage.TestUtil.csproj) (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) @@ -61,7 +61,7 @@ - + Fisheye: Tag 4e14ed090d09a220a790b3562ceb4232dab1cce6 refers to a dead (removed) revision in file `Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/DbTestSet.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/RingtoetsEntitiesHelper.cs =================================================================== diff -u -r8b5a6f938fe2b04cd78623649df37580e145055f -r4e14ed090d09a220a790b3562ceb4232dab1cce6 --- Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/RingtoetsEntitiesHelper.cs (.../RingtoetsEntitiesHelper.cs) (revision 8b5a6f938fe2b04cd78623649df37580e145055f) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/RingtoetsEntitiesHelper.cs (.../RingtoetsEntitiesHelper.cs) (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) @@ -20,6 +20,7 @@ // All rights reserved. using System.Collections.ObjectModel; +using System.Data.Entity; using Application.Ringtoets.Storage.DbContext; using Rhino.Mocks; @@ -30,16 +31,18 @@ public static IRingtoetsEntities Create(MockRepository mockRepository) { var ringtoetsEntities = mockRepository.Stub(); - var pSet = DbTestSet.GetDbTestSet(new ObservableCollection()); - var hlSet = DbTestSet.GetDbTestSet(new ObservableCollection()); - var fmSet = DbTestSet.GetDbTestSet(new ObservableCollection()); - var dasSet = DbTestSet.GetDbTestSet(new ObservableCollection()); - var rlpSet = DbTestSet.GetDbTestSet(new ObservableCollection()); + var pSet = (DbSet) new TestDbSet(new ObservableCollection()); + var hlSet = (DbSet) new TestDbSet(new ObservableCollection()); + var fmSet = (DbSet) new TestDbSet(new ObservableCollection()); + var dasSet = (DbSet) new TestDbSet(new ObservableCollection()); + var rlpSet = (DbSet) new TestDbSet(new ObservableCollection()); + var ssmSet = (DbSet) new TestDbSet(new ObservableCollection()); ringtoetsEntities.Stub(r => r.ProjectEntities).Return(pSet); ringtoetsEntities.Stub(r => r.HydraulicLocationEntities).Return(hlSet); ringtoetsEntities.Stub(r => r.FailureMechanismEntities).Return(fmSet); ringtoetsEntities.Stub(r => r.AssessmentSectionEntities).Return(dasSet); ringtoetsEntities.Stub(r => r.ReferenceLinePointEntities).Return(rlpSet); + ringtoetsEntities.Stub(r => r.StochasticSoilModelEntities).Return(ssmSet); return ringtoetsEntities; } } Index: Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/TestDbSet.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/TestDbSet.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/TestDbSet.cs (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) @@ -0,0 +1,106 @@ +// 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.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Data.Entity; +using System.Linq; +using System.Linq.Expressions; + +namespace Application.Ringtoets.Storage.TestUtil +{ + public class TestDbSet : DbSet, IDbSet where T : class + { + private readonly IQueryable queryable; + private readonly ObservableCollection collection; + + public TestDbSet(ObservableCollection queryable) + { + collection = queryable; + this.queryable = queryable.AsQueryable(); + } + + public IQueryProvider Provider + { + get + { + return queryable.Provider; + } + } + + public Expression Expression + { + get + { + return queryable.Expression; + } + } + + public Type ElementType + { + get + { + return queryable.ElementType; + } + } + + public override ObservableCollection Local + { + get + { + return collection; + } + } + + public override IEnumerable RemoveRange(IEnumerable entities) + { + foreach (var e in entities) + { + collection.Remove(e); + } + return entities; + } + + public override T Add(T entity) + { + collection.Add(entity); + return entity; + } + + public override T Remove(T entity) + { + collection.Remove(entity); + return entity; + } + + IEnumerator IEnumerable.GetEnumerator() + { + return collection.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return collection.GetEnumerator(); + } + } +} \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Data/StochasticSoilModel.cs =================================================================== diff -u -rcda9bb0707f49cfb8e685d3ec04da01240c73f26 -r4e14ed090d09a220a790b3562ceb4232dab1cce6 --- Ringtoets/Piping/src/Ringtoets.Piping.Data/StochasticSoilModel.cs (.../StochasticSoilModel.cs) (revision cda9bb0707f49cfb8e685d3ec04da01240c73f26) +++ Ringtoets/Piping/src/Ringtoets.Piping.Data/StochasticSoilModel.cs (.../StochasticSoilModel.cs) (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) @@ -46,6 +46,11 @@ } /// + /// Gets or sets the unique identifier for the storage of the . + /// + public long StorageId { get; set; } + + /// /// Gets the database identifier of the stochastic soil model. /// public long Id { get; private set; }