Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj =================================================================== diff -u -r5ac27878c41230483441a2f860f49732369ac606 -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 5ac27878c41230483441a2f860f49732369ac606) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -54,6 +54,8 @@ + + @@ -188,6 +190,7 @@ + @@ -243,6 +246,8 @@ + + Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/AssessmentSectionCreateExtensions.cs =================================================================== diff -u -ra2bfc1b408fe5187e5968cc2ff6ac7449211b537 -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/AssessmentSectionCreateExtensions.cs (.../AssessmentSectionCreateExtensions.cs) (revision a2bfc1b408fe5187e5968cc2ff6ac7449211b537) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/AssessmentSectionCreateExtensions.cs (.../AssessmentSectionCreateExtensions.cs) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -61,6 +61,7 @@ entity.FailureMechanismEntities.Add(section.StrengthStabilityLengthwiseConstruction.Create(registry)); entity.FailureMechanismEntities.Add(section.TechnicalInnovation.Create(registry)); entity.FailureMechanismEntities.Add(section.WaterPressureAsphaltCover.Create(registry)); + entity.FailureMechanismEntities.Add(section.ClosingStructure.Create(registry)); AddEntitiesForAddStandAloneFailureMechanisms(section, entity, registry); @@ -78,7 +79,6 @@ entity.FailureMechanismEntities.Add(section.GrassCoverErosionOutwards.Create(FailureMechanismType.GrassRevetmentErosionOutwards, registry)); entity.FailureMechanismEntities.Add(section.GrassCoverSlipOffOutwards.Create(FailureMechanismType.GrassRevetmentSlidingOutwards, registry)); entity.FailureMechanismEntities.Add(section.GrassCoverSlipOffInwards.Create(FailureMechanismType.GrassRevetmentSlidingInwards, registry)); - entity.FailureMechanismEntities.Add(section.ClosingStructure.Create(FailureMechanismType.ReliabilityClosingOfStructure, registry)); entity.FailureMechanismEntities.Add(section.PipingStructure.Create(FailureMechanismType.PipingAtStructure, registry)); entity.FailureMechanismEntities.Add(section.StrengthStabilityPointConstruction.Create(FailureMechanismType.StrengthAndStabilityPointConstruction, registry)); entity.FailureMechanismEntities.Add(section.DuneErosion.Create(FailureMechanismType.DuneErosion, registry)); Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/ClosingStructureFailureMechanismCreateExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/ClosingStructureFailureMechanismCreateExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/ClosingStructureFailureMechanismCreateExtensions.cs (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -0,0 +1,71 @@ +// 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.Integration.Data.StandAlone; + +namespace Application.Ringtoets.Storage.Create +{ + /// + /// Extension methods for related to creating a . + /// + internal static class ClosingStructureFailureMechanismCreateExtensions + { + /// + /// Creates a based on the information of the . + /// + /// The failure mechanism to create a database entity for. + /// The object keeping track of create operations. + /// A new . + /// Thrown when is null. + internal static FailureMechanismEntity Create(this ClosingStructureFailureMechanism mechanism, PersistenceRegistry registry) + { + if (registry == null) + { + throw new ArgumentNullException("registry"); + } + + var entity = new FailureMechanismEntity + { + FailureMechanismType = (short) FailureMechanismType.ReliabilityClosingOfStructure, + IsRelevant = Convert.ToByte(mechanism.IsRelevant), + Comments = mechanism.Comments + }; + + mechanism.AddEntitiesForFailureMechanismSections(registry, entity); + AddEntitiesForSectionResults(mechanism, registry); + + registry.Register(entity, mechanism); + return entity; + } + + private static void AddEntitiesForSectionResults(ClosingStructureFailureMechanism mechanism, PersistenceRegistry registry) + { + foreach (var failureMechanismSectionResult in mechanism.SectionResults) + { + var sectionResultEntity = failureMechanismSectionResult.Create(registry); + var section = registry.Get(failureMechanismSectionResult.Section); + section.ClosingStructureSectionResultEntities.Add(sectionResultEntity); + } + } + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/ClosingStructureFailureMechanismSectionResultCreateExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/ClosingStructureFailureMechanismSectionResultCreateExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/ClosingStructureFailureMechanismSectionResultCreateExtensions.cs (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -0,0 +1,58 @@ +// 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.Integration.Data.StandAlone.SectionResults; + +namespace Application.Ringtoets.Storage.Create +{ + /// + /// Extension methods for related to creating a + /// . + /// + internal static class ClosingStructureFailureMechanismSectionResultCreateExtensions + { + /// + /// Creates a based on the information of the . + /// + /// The result to create a database entity for. + /// The object keeping track of create operations. + /// A new . + /// Thrown when is null. + internal static ClosingStructureSectionResultEntity Create(this ClosingStructureFailureMechanismSectionResult result, PersistenceRegistry registry) + { + if (registry == null) + { + throw new ArgumentNullException("registry"); + } + var sectionResultEntity = new ClosingStructureSectionResultEntity + { + LayerOne = Convert.ToByte(result.AssessmentLayerOne), + LayerTwoA = result.AssessmentLayerTwoA.Value.ToNullableDecimal(), + LayerThree = result.AssessmentLayerThree.Value.ToNullableDecimal() + }; + + registry.Register(sectionResultEntity, result); + return sectionResultEntity; + } + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/PersistenceRegistry.cs =================================================================== diff -u -r2fe46c62134fde70ada240fa952971444177be90 -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/PersistenceRegistry.cs (.../PersistenceRegistry.cs) (revision 2fe46c62134fde70ada240fa952971444177be90) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/PersistenceRegistry.cs (.../PersistenceRegistry.cs) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -59,6 +59,7 @@ private readonly Dictionary strengthStabilityLengthwiseConstructionFailureMechanismSectionResults = new Dictionary(); private readonly Dictionary technicalInnovationFailureMechanismSectionResults = new Dictionary(); private readonly Dictionary waterPressureAsphaltCoverFailureMechanismSectionResults = new Dictionary(); + private readonly Dictionary closingStructureFailureMechanismSectionResults = new Dictionary(); private readonly Dictionary hydraulicLocations = new Dictionary(new ReferenceEqualityComparer()); private readonly Dictionary calculationGroups = new Dictionary(new ReferenceEqualityComparer()); private readonly Dictionary pipingCalculations = new Dictionary(new ReferenceEqualityComparer()); @@ -189,6 +190,22 @@ /// Registers a create or update operation for and the /// that was constructed with the information. /// + /// The to be registered. + /// The to be registered. + /// Thrown when either: + /// + /// is null + /// is null + /// + public void Register(ClosingStructureSectionResultEntity entity, ClosingStructureFailureMechanismSectionResult model) + { + Register(closingStructureFailureMechanismSectionResults, entity, model); + } + + /// + /// Registers a create or update operation for and the + /// that was constructed with the information. + /// /// The to be registered. /// The to be registered. /// Thrown when either: @@ -685,6 +702,11 @@ waterPressureAsphaltCoverFailureMechanismSectionResults[entity].StorageId = entity.WaterPressureAsphaltCoverSectionResultEntityId; } + foreach (var entity in closingStructureFailureMechanismSectionResults.Keys) + { + closingStructureFailureMechanismSectionResults[entity].StorageId = entity.ClosingStructureSectionResultEntityId; + } + foreach (var entity in hydraulicLocations.Keys) { hydraulicLocations[entity].StorageId = entity.HydraulicLocationEntityId; @@ -865,6 +887,17 @@ } dbContext.WaterPressureAsphaltCoverSectionResultEntities.RemoveRange(orphanedWaterPressureAsphaltCoverSectionResultEntities); + var orphanedClosingStructureSectionResultEntities = new List(); + foreach (ClosingStructureSectionResultEntity sectionResultEntity in dbContext.ClosingStructureSectionResultEntities + .Where(e => e.ClosingStructureSectionResultEntityId > 0)) + { + if (!closingStructureFailureMechanismSectionResults.ContainsKey(sectionResultEntity)) + { + orphanedClosingStructureSectionResultEntities.Add(sectionResultEntity); + } + } + dbContext.ClosingStructureSectionResultEntities.RemoveRange(orphanedClosingStructureSectionResultEntities); + var orphanedHydraulicLocationEntities = new List(); foreach (HydraulicLocationEntity hydraulicLocationEntity in dbContext.HydraulicLocationEntities .Where(e => e.HydraulicLocationEntityId > 0)) Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/ClosingStructureSectionResultEntity.cs =================================================================== diff -u -r5ac27878c41230483441a2f860f49732369ac606 -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/ClosingStructureSectionResultEntity.cs (.../ClosingStructureSectionResultEntity.cs) (revision 5ac27878c41230483441a2f860f49732369ac606) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/ClosingStructureSectionResultEntity.cs (.../ClosingStructureSectionResultEntity.cs) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -38,7 +38,7 @@ public long ClosingStructureSectionResultEntityId { get; set; } public long FailureMechanismSectionEntityId { get; set; } public byte LayerOne { get; set; } - public Nullable LayerTwo { get; set; } + public Nullable LayerTwoA { get; set; } public Nullable LayerThree { get; set; } public virtual FailureMechanismSectionEntity FailureMechanismSectionEntity { get; set; } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/DatabaseStructure.sql =================================================================== diff -u -r5ac27878c41230483441a2f860f49732369ac606 -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/DatabaseStructure.sql (.../DatabaseStructure.sql) (revision 5ac27878c41230483441a2f860f49732369ac606) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/DatabaseStructure.sql (.../DatabaseStructure.sql) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -1,6 +1,6 @@ /* ---------------------------------------------------- */ /* Generated by Enterprise Architect Version 12.0 */ -/* Created On : 16-jun-2016 11:20:35 */ +/* Created On : 16-jun-2016 12:54:09 */ /* DBMS : SQLite */ /* ---------------------------------------------------- */ @@ -436,7 +436,7 @@ 'ClosingStructureSectionResultEntityId' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 'FailureMechanismSectionEntityId' INTEGER NOT NULL, 'LayerOne' TINYINT (1) NOT NULL, -- true or false - 'LayerTwo' NUMERIC, + 'LayerTwoA' NUMERIC, 'LayerThree' NUMERIC, CONSTRAINT 'FK_ClosingStructureSectionResultEntity_FailureMechanismSectionEntity' FOREIGN KEY ('FailureMechanismSectionEntityId') REFERENCES 'FailureMechanismSectionEntity' ('FailureMechanismSectionEntityId') ON DELETE Cascade ON UPDATE Cascade ) @@ -447,7 +447,7 @@ 'GrassCoverErosionOutwardsSectionResultEntityId' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 'FailureMechanismSectionEntityId' INTEGER NOT NULL, 'LayerOne' TINYINT (1) NOT NULL, -- true or false - 'LayerTwo' NUMERIC, + 'LayerTwoA' NUMERIC, 'LayerThree' NUMERIC, CONSTRAINT 'FK_GrassCoverErosionOutwardsSectionResultEntity_FailureMechanismSectionEntity' FOREIGN KEY ('FailureMechanismSectionEntityId') REFERENCES 'FailureMechanismSectionEntity' ('FailureMechanismSectionEntityId') ON DELETE Cascade ON UPDATE Cascade ) @@ -458,7 +458,7 @@ 'GrassCoverSlipOffInwardsSectionResultEntityId' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 'FailureMechanismSectionEntityId' INTEGER NOT NULL, 'LayerOne' TINYINT (1) NOT NULL, -- true or false - 'LayerTwo' NUMERIC, + 'LayerTwoA' NUMERIC, 'LayerThree' NUMERIC, CONSTRAINT 'FK_GrassCoverSlipOffInwardsSectionResultEntity_FailureMechanismSectionEntity' FOREIGN KEY ('FailureMechanismSectionEntityId') REFERENCES 'FailureMechanismSectionEntity' ('FailureMechanismSectionEntityId') ON DELETE Cascade ON UPDATE Cascade ) @@ -469,7 +469,7 @@ 'GrassCoverSlipOffOutwardsSectionResultEntityId' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 'FailureMechanismSectionEntityId' INTEGER NOT NULL, 'LayerOne' TINYINT (1) NOT NULL, -- true or false - 'LayerTwo' NUMERIC, + 'LayerTwoA' NUMERIC, 'LayerThree' NUMERIC, CONSTRAINT 'FK_GrassCoverSlipOffOutwardsSectionResultEntity_FailureMechanismSectionEntity' FOREIGN KEY ('FailureMechanismSectionEntityId') REFERENCES 'FailureMechanismSectionEntity' ('FailureMechanismSectionEntityId') ON DELETE Cascade ON UPDATE Cascade ) @@ -480,7 +480,7 @@ 'MacrostabilityInwardsSectionResultEntityId' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 'FailureMechanismSectionEntityId' INTEGER NOT NULL, 'LayerOne' TINYINT (1) NOT NULL, -- true or false - 'LayerTwo' NUMERIC, + 'LayerTwoA' NUMERIC, 'LayerThree' NUMERIC, CONSTRAINT 'FK_MacrostabilityInwardsSectionResultEntity_FailureMechanismSectionEntity' FOREIGN KEY ('FailureMechanismSectionEntityId') REFERENCES 'FailureMechanismSectionEntity' ('FailureMechanismSectionEntityId') ON DELETE Cascade ON UPDATE Cascade ) @@ -491,7 +491,7 @@ 'MacrostabilityOutwardsSectionResultEntityId' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 'FailureMechanismSectionEntityId' INTEGER NOT NULL, 'LayerOne' TINYINT (1) NOT NULL, -- true or false - 'LayerTwo' NUMERIC, + 'LayerTwoA' NUMERIC, 'LayerThree' NUMERIC, CONSTRAINT 'FK_MacrostabilityOutwardsSectionResultEntity_FailureMechanismSectionEntity' FOREIGN KEY ('FailureMechanismSectionEntityId') REFERENCES 'FailureMechanismSectionEntity' ('FailureMechanismSectionEntityId') ON DELETE Cascade ON UPDATE Cascade ) @@ -502,7 +502,7 @@ 'WaveImpactAsphaltCoverSectionResultEntityId' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 'FailureMechanismSectionEntityId' INTEGER NOT NULL, 'LayerOne' TINYINT (1) NOT NULL, -- true or false - 'LayerTwo' NUMERIC, + 'LayerTwoA' NUMERIC, 'LayerThree' NUMERIC, CONSTRAINT 'FK_WaveImpactAsphaltCoverSectionResultEntity_FailureMechanismSectionEntity' FOREIGN KEY ('FailureMechanismSectionEntityId') REFERENCES 'FailureMechanismSectionEntity' ('FailureMechanismSectionEntityId') ON DELETE Cascade ON UPDATE Cascade ) Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/GrassCoverErosionOutwardsSectionResultEntity.cs =================================================================== diff -u -r5ac27878c41230483441a2f860f49732369ac606 -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/GrassCoverErosionOutwardsSectionResultEntity.cs (.../GrassCoverErosionOutwardsSectionResultEntity.cs) (revision 5ac27878c41230483441a2f860f49732369ac606) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/GrassCoverErosionOutwardsSectionResultEntity.cs (.../GrassCoverErosionOutwardsSectionResultEntity.cs) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -38,7 +38,7 @@ public long GrassCoverErosionOutwardsSectionResultEntityId { get; set; } public long FailureMechanismSectionEntityId { get; set; } public byte LayerOne { get; set; } - public Nullable LayerTwo { get; set; } + public Nullable LayerTwoA { get; set; } public Nullable LayerThree { get; set; } public virtual FailureMechanismSectionEntity FailureMechanismSectionEntity { get; set; } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/GrassCoverSlipOffInwardsSectionResultEntity.cs =================================================================== diff -u -r5ac27878c41230483441a2f860f49732369ac606 -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/GrassCoverSlipOffInwardsSectionResultEntity.cs (.../GrassCoverSlipOffInwardsSectionResultEntity.cs) (revision 5ac27878c41230483441a2f860f49732369ac606) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/GrassCoverSlipOffInwardsSectionResultEntity.cs (.../GrassCoverSlipOffInwardsSectionResultEntity.cs) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -38,7 +38,7 @@ public long GrassCoverSlipOffInwardsSectionResultEntityId { get; set; } public long FailureMechanismSectionEntityId { get; set; } public byte LayerOne { get; set; } - public Nullable LayerTwo { get; set; } + public Nullable LayerTwoA { get; set; } public Nullable LayerThree { get; set; } public virtual FailureMechanismSectionEntity FailureMechanismSectionEntity { get; set; } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/GrassCoverSlipOffOutwardsSectionResultEntity.cs =================================================================== diff -u -r5ac27878c41230483441a2f860f49732369ac606 -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/GrassCoverSlipOffOutwardsSectionResultEntity.cs (.../GrassCoverSlipOffOutwardsSectionResultEntity.cs) (revision 5ac27878c41230483441a2f860f49732369ac606) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/GrassCoverSlipOffOutwardsSectionResultEntity.cs (.../GrassCoverSlipOffOutwardsSectionResultEntity.cs) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -38,7 +38,7 @@ public long GrassCoverSlipOffOutwardsSectionResultEntityId { get; set; } public long FailureMechanismSectionEntityId { get; set; } public byte LayerOne { get; set; } - public Nullable LayerTwo { get; set; } + public Nullable LayerTwoA { get; set; } public Nullable LayerThree { get; set; } public virtual FailureMechanismSectionEntity FailureMechanismSectionEntity { get; set; } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/IRingtoetsEntities.cs =================================================================== diff -u -r2fe46c62134fde70ada240fa952971444177be90 -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/IRingtoetsEntities.cs (.../IRingtoetsEntities.cs) (revision 2fe46c62134fde70ada240fa952971444177be90) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/IRingtoetsEntities.cs (.../IRingtoetsEntities.cs) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -91,6 +91,12 @@ DbSet WaterPressureAsphaltCoverSectionResultEntities { get; } /// + /// Gets a of containing + /// every entity found in the database. + /// + DbSet ClosingStructureSectionResultEntities { get; } + + /// /// Gets a of containing /// every entity found in the database. /// Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/MacrostabilityInwardsSectionResultEntity.cs =================================================================== diff -u -r5ac27878c41230483441a2f860f49732369ac606 -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/MacrostabilityInwardsSectionResultEntity.cs (.../MacrostabilityInwardsSectionResultEntity.cs) (revision 5ac27878c41230483441a2f860f49732369ac606) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/MacrostabilityInwardsSectionResultEntity.cs (.../MacrostabilityInwardsSectionResultEntity.cs) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -38,7 +38,7 @@ public long MacrostabilityInwardsSectionResultEntityId { get; set; } public long FailureMechanismSectionEntityId { get; set; } public byte LayerOne { get; set; } - public Nullable LayerTwo { get; set; } + public Nullable LayerTwoA { get; set; } public Nullable LayerThree { get; set; } public virtual FailureMechanismSectionEntity FailureMechanismSectionEntity { get; set; } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/MacrostabilityOutwardsSectionResultEntity.cs =================================================================== diff -u -r5ac27878c41230483441a2f860f49732369ac606 -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/MacrostabilityOutwardsSectionResultEntity.cs (.../MacrostabilityOutwardsSectionResultEntity.cs) (revision 5ac27878c41230483441a2f860f49732369ac606) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/MacrostabilityOutwardsSectionResultEntity.cs (.../MacrostabilityOutwardsSectionResultEntity.cs) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -38,7 +38,7 @@ public long MacrostabilityOutwardsSectionResultEntityId { get; set; } public long FailureMechanismSectionEntityId { get; set; } public byte LayerOne { get; set; } - public Nullable LayerTwo { get; set; } + public Nullable LayerTwoA { get; set; } public Nullable LayerThree { get; set; } public virtual FailureMechanismSectionEntity FailureMechanismSectionEntity { get; set; } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.edmx =================================================================== diff -u -r5ac27878c41230483441a2f860f49732369ac606 -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.edmx (.../RingtoetsEntities.edmx) (revision 5ac27878c41230483441a2f860f49732369ac606) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.edmx (.../RingtoetsEntities.edmx) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -43,7 +43,7 @@ - + @@ -91,7 +91,7 @@ - + @@ -101,7 +101,7 @@ - + @@ -111,7 +111,7 @@ - + @@ -142,7 +142,7 @@ - + @@ -152,7 +152,7 @@ - + @@ -363,7 +363,7 @@ - + @@ -1209,7 +1209,7 @@ - + @@ -1281,7 +1281,7 @@ - + @@ -1292,7 +1292,7 @@ - + @@ -1303,7 +1303,7 @@ - + @@ -1338,7 +1338,7 @@ - + @@ -1349,7 +1349,7 @@ - + @@ -1591,7 +1591,7 @@ - + @@ -2071,7 +2071,7 @@ - + @@ -2124,7 +2124,7 @@ - + @@ -2135,7 +2135,7 @@ - + @@ -2146,7 +2146,7 @@ - + @@ -2180,7 +2180,7 @@ - + @@ -2191,7 +2191,7 @@ - + @@ -2421,7 +2421,7 @@ - + Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.edmx.diagram =================================================================== diff -u -r5ac27878c41230483441a2f860f49732369ac606 -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.edmx.diagram (.../RingtoetsEntities.edmx.diagram) (revision 5ac27878c41230483441a2f860f49732369ac606) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.edmx.diagram (.../RingtoetsEntities.edmx.diagram) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -6,39 +6,39 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + - - + + Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/WaveImpactAsphaltCoverSectionResultEntity.cs =================================================================== diff -u -r5ac27878c41230483441a2f860f49732369ac606 -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/WaveImpactAsphaltCoverSectionResultEntity.cs (.../WaveImpactAsphaltCoverSectionResultEntity.cs) (revision 5ac27878c41230483441a2f860f49732369ac606) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/WaveImpactAsphaltCoverSectionResultEntity.cs (.../WaveImpactAsphaltCoverSectionResultEntity.cs) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -38,7 +38,7 @@ public long WaveImpactAsphaltCoverSectionResultEntityId { get; set; } public long FailureMechanismSectionEntityId { get; set; } public byte LayerOne { get; set; } - public Nullable LayerTwo { get; set; } + public Nullable LayerTwoA { get; set; } public Nullable LayerThree { get; set; } public virtual FailureMechanismSectionEntity FailureMechanismSectionEntity { get; set; } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/AssessmentSectionEntityReadExtensions.cs =================================================================== diff -u -re0ef393f7069a18d7e160aceaf91f603dfc8c5ae -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/AssessmentSectionEntityReadExtensions.cs (.../AssessmentSectionEntityReadExtensions.cs) (revision e0ef393f7069a18d7e160aceaf91f603dfc8c5ae) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/AssessmentSectionEntityReadExtensions.cs (.../AssessmentSectionEntityReadExtensions.cs) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -69,6 +69,7 @@ entity.ReadStrengthStabilityLengthwiseConstructionFailureMechanism(assessmentSection, collector); entity.ReadTechnicalInnovationFailureMechanism(assessmentSection, collector); entity.ReadWaterPressureAsphaltCoverFailureMechanism(assessmentSection, collector); + entity.ReadClosingStructureFailureMechanism(assessmentSection, collector); entity.ReadStandAloneFailureMechanisms(assessmentSection, collector); return assessmentSection; @@ -154,6 +155,15 @@ } } + private static void ReadClosingStructureFailureMechanism(this AssessmentSectionEntity entity, AssessmentSection assessmentSection, ReadConversionCollector collector) + { + var closingStructureFailureMechanismEntity = entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (int) FailureMechanismType.ReliabilityClosingOfStructure); + if (closingStructureFailureMechanismEntity != null) + { + closingStructureFailureMechanismEntity.ReadAsClosingStructureFailureMechanism(assessmentSection.ClosingStructure, collector); + } + } + private static void ReadStandAloneFailureMechanisms(this AssessmentSectionEntity entity, AssessmentSection assessmentSection, ReadConversionCollector collector) { entity.ReadStandAloneFailureMechanism(FailureMechanismType.MacrostabilityInwards, assessmentSection.MacrostabilityInwards, collector); @@ -164,7 +174,6 @@ entity.ReadStandAloneFailureMechanism(FailureMechanismType.GrassRevetmentErosionOutwards, assessmentSection.GrassCoverErosionOutwards, collector); entity.ReadStandAloneFailureMechanism(FailureMechanismType.GrassRevetmentSlidingOutwards, assessmentSection.GrassCoverSlipOffOutwards, collector); entity.ReadStandAloneFailureMechanism(FailureMechanismType.GrassRevetmentSlidingInwards, assessmentSection.GrassCoverSlipOffInwards, collector); - entity.ReadStandAloneFailureMechanism(FailureMechanismType.ReliabilityClosingOfStructure, assessmentSection.ClosingStructure, collector); entity.ReadStandAloneFailureMechanism(FailureMechanismType.PipingAtStructure, assessmentSection.PipingStructure, collector); entity.ReadStandAloneFailureMechanism(FailureMechanismType.StrengthAndStabilityPointConstruction, assessmentSection.StrengthStabilityPointConstruction, collector); entity.ReadStandAloneFailureMechanism(FailureMechanismType.DuneErosion, assessmentSection.DuneErosion, collector); Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ClosingStructureSectionResultEntityReadExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ClosingStructureSectionResultEntityReadExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ClosingStructureSectionResultEntityReadExtensions.cs (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -0,0 +1,59 @@ +// 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 Core.Common.Base.Data; +using Ringtoets.Integration.Data.StandAlone.SectionResults; + +namespace Application.Ringtoets.Storage.Read +{ + /// + /// This class defines extension methods for read operations for a based on the + /// . + /// + internal static class ClosingStructureSectionResultEntityReadExtensions + { + /// + /// Reads the and use the information to construct a + /// . + /// + /// The to create for. + /// The object keeping track of read operations. + /// A new . + /// Thrown when is null. + internal static ClosingStructureFailureMechanismSectionResult Read(this ClosingStructureSectionResultEntity entity, ReadConversionCollector collector) + { + if (collector == null) + { + throw new ArgumentNullException("collector"); + } + var sectionResult = new ClosingStructureFailureMechanismSectionResult(collector.Get(entity.FailureMechanismSectionEntity)) + { + StorageId = entity.ClosingStructureSectionResultEntityId, + AssessmentLayerOne = Convert.ToBoolean(entity.LayerOne), + AssessmentLayerTwoA = (RoundedDouble)entity.LayerTwoA.ToNanableDouble(), + AssessmentLayerThree = (RoundedDouble) entity.LayerThree.ToNanableDouble() + }; + return sectionResult; + } + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/FailureMechanismEntityReadExtensions.cs =================================================================== diff -u -r2fe46c62134fde70ada240fa952971444177be90 -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/FailureMechanismEntityReadExtensions.cs (.../FailureMechanismEntityReadExtensions.cs) (revision 2fe46c62134fde70ada240fa952971444177be90) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/FailureMechanismEntityReadExtensions.cs (.../FailureMechanismEntityReadExtensions.cs) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -245,6 +245,36 @@ } /// + /// Read the and use the information to update a . + /// + /// The to create for. + /// + /// The object keeping track of read operations. + internal static void ReadAsClosingStructureFailureMechanism(this FailureMechanismEntity entity, ClosingStructureFailureMechanism failureMechanism, ReadConversionCollector collector) + { + failureMechanism.StorageId = entity.FailureMechanismEntityId; + failureMechanism.IsRelevant = entity.IsRelevant == 1; + failureMechanism.Comments = entity.Comments; + + entity.ReadFailureMechanismSections(failureMechanism, collector); + entity.ReadClosingStructureMechanismSectionResults(failureMechanism, collector); + } + + private static void ReadClosingStructureMechanismSectionResults(this FailureMechanismEntity entity, ClosingStructureFailureMechanism failureMechanism, ReadConversionCollector collector) + { + foreach (var sectionResultEntity in entity.FailureMechanismSectionEntities.SelectMany(fms => fms.ClosingStructureSectionResultEntities)) + { + var readSectionResult = sectionResultEntity.Read(collector); + var failureMechanismSection = collector.Get(sectionResultEntity.FailureMechanismSectionEntity); + var result = failureMechanism.SectionResults.Single(sr => ReferenceEquals(sr.Section, failureMechanismSection)); + result.StorageId = readSectionResult.StorageId; + result.AssessmentLayerOne = readSectionResult.AssessmentLayerOne; + result.AssessmentLayerTwoA = readSectionResult.AssessmentLayerTwoA; + result.AssessmentLayerThree = readSectionResult.AssessmentLayerThree; + } + } + + /// /// Read the and use the information to update a . /// /// The to read into a . Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Update/ClosingStructureFailureMechanismSectionResultUpdateExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Update/ClosingStructureFailureMechanismSectionResultUpdateExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Update/ClosingStructureFailureMechanismSectionResultUpdateExtensions.cs (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -0,0 +1,84 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Linq; +using Application.Ringtoets.Storage.Create; +using Application.Ringtoets.Storage.DbContext; +using Application.Ringtoets.Storage.Exceptions; +using Application.Ringtoets.Storage.Properties; +using Ringtoets.Integration.Data.StandAlone.SectionResults; + +namespace Application.Ringtoets.Storage.Update +{ + /// + /// Extension methods for related to updating a + /// . + /// + internal static class ClosingStructureFailureMechanismSectionResultUpdateExtensions + { + /// + /// Updates a in the database based on the information of the + /// . + /// + /// The result to update the database entity for. + /// The object keeping track of update operations. + /// The context to obtain the existing entity from. + /// Thrown when either: + /// + /// is null + /// is null + /// + /// When + /// does not have a corresponding entity in . + internal static void Update(this ClosingStructureFailureMechanismSectionResult result, PersistenceRegistry registry, IRingtoetsEntities context) + { + if (context == null) + { + throw new ArgumentNullException("context"); + } + if (registry == null) + { + throw new ArgumentNullException("registry"); + } + + ClosingStructureSectionResultEntity entity = GetCorrespondingClosingStructureSectionResult(result, context); + + entity.LayerOne = Convert.ToByte(result.AssessmentLayerOne); + entity.LayerTwoA = Convert.ToDecimal(result.AssessmentLayerTwoA); + entity.LayerThree = Convert.ToDecimal(result.AssessmentLayerThree); + + registry.Register(entity, result); + } + + private static ClosingStructureSectionResultEntity GetCorrespondingClosingStructureSectionResult(ClosingStructureFailureMechanismSectionResult result, IRingtoetsEntities context) + { + try + { + return context.ClosingStructureSectionResultEntities.Single(sle => sle.ClosingStructureSectionResultEntityId == result.StorageId); + } + catch (InvalidOperationException exception) + { + throw new EntityNotFoundException(string.Format(Resources.Error_Entity_Not_Found_0_1, typeof(ClosingStructureSectionResultEntity).Name, result.StorageId), exception); + } + } + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Update/ClosingStructureFailureMechanismUpdateExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Update/ClosingStructureFailureMechanismUpdateExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Update/ClosingStructureFailureMechanismUpdateExtensions.cs (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -0,0 +1,84 @@ +// 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.Create; +using Application.Ringtoets.Storage.DbContext; +using Application.Ringtoets.Storage.Exceptions; +using Ringtoets.Integration.Data.StandAlone; + +namespace Application.Ringtoets.Storage.Update +{ + /// + /// Extension methods for related to updating a . + /// + internal static class ClosingStructureFailureMechanismUpdateExtensions + { + /// + /// Updates a in the database based on the information of the + /// . + /// + /// The mechanism to update the database entity for. + /// The object keeping track of update operations. + /// The context to obtain the existing entity from. + /// Thrown when either: + /// + /// is null + /// is null + /// + /// When + /// does not have a corresponding entity in . + internal static void Update(this ClosingStructureFailureMechanism mechanism, PersistenceRegistry registry, IRingtoetsEntities context) + { + if (context == null) + { + throw new ArgumentNullException("context"); + } + if (registry == null) + { + throw new ArgumentNullException("registry"); + } + + FailureMechanismEntity entity = mechanism.GetCorrespondingFailureMechanismEntity(context); + entity.IsRelevant = Convert.ToByte(mechanism.IsRelevant); + + mechanism.UpdateFailureMechanismSections(registry, entity, context); + UpdateSectionResults(mechanism, registry, context); + + registry.Register(entity, mechanism); + } + + private static void UpdateSectionResults(ClosingStructureFailureMechanism mechanism, PersistenceRegistry registry, IRingtoetsEntities context) + { + foreach (var sectionResult in mechanism.SectionResults) + { + if (sectionResult.IsNew()) + { + registry.Get(sectionResult.Section).ClosingStructureSectionResultEntities.Add(sectionResult.Create(registry)); + } + else + { + sectionResult.Update(registry, context); + } + } + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj =================================================================== diff -u -r2fe46c62134fde70ada240fa952971444177be90 -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 2fe46c62134fde70ada240fa952971444177be90) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -82,6 +82,8 @@ + + @@ -115,6 +117,7 @@ + @@ -148,6 +151,8 @@ + + Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/ClosingStructureFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/ClosingStructureFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/ClosingStructureFailureMechanismCreateExtensionsTest.cs (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -0,0 +1,100 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Linq; +using Application.Ringtoets.Storage.Create; +using Application.Ringtoets.Storage.DbContext; +using Application.Ringtoets.Storage.TestUtil; +using NUnit.Framework; +using Ringtoets.Integration.Data.StandAlone; + +namespace Application.Ringtoets.Storage.Test.Create +{ + [TestFixture] + public class ClosingStructureFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_WithoutPersistenceRegistry_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new ClosingStructureFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet(bool isRelevant) + { + // Setup + var failureMechanism = new ClosingStructureFailureMechanism + { + IsRelevant = isRelevant, + Comments = "Some text" + }; + var registry = new PersistenceRegistry(); + + // Call + var entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short)FailureMechanismType.ReliabilityClosingOfStructure, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.Comments, entity.Comments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new ClosingStructureFailureMechanism(); + + // Call + var entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.IsEmpty(entity.FailureMechanismSectionEntities); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + var failureMechanism = new ClosingStructureFailureMechanism(); + failureMechanism.AddSection(new TestFailureMechanismSection()); + + // Call + var entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.ClosingStructureSectionResultEntities).Count()); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/ClosingStructureFailureMechanismSectionResultCreateExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/ClosingStructureFailureMechanismSectionResultCreateExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/ClosingStructureFailureMechanismSectionResultCreateExtensionsTest.cs (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -0,0 +1,97 @@ +// 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.Create; +using Application.Ringtoets.Storage.TestUtil; +using Core.Common.Base.Data; +using NUnit.Framework; +using Ringtoets.Integration.Data.StandAlone.SectionResults; + +namespace Application.Ringtoets.Storage.Test.Create +{ + [TestFixture] + public class ClosingStructureFailureMechanismSectionResultCreateExtensionsTest + { + [Test] + public void Create_WithoutPersistenceRegistry_ThrowsArgumentNullException() + { + // Setup + var sectionResult = new ClosingStructureFailureMechanismSectionResult(new TestFailureMechanismSection()); + + // Call + TestDelegate test = () => sectionResult.Create(null); + + // Assert + Assert.Throws(test); + } + + [Test] + public void Create_WithDifferentResults_ReturnsEntityWithExpectedResults( + [Values(true, false)] bool assessmentLayerOneResult, + [Values(0.2, 0.523)] double assessmentLayerTwoAResult, + [Values(3.2, 4.5)] double assessmentLayerThreeResult + ) + { + // Setup + var sectionResult = new ClosingStructureFailureMechanismSectionResult(new TestFailureMechanismSection()); + sectionResult.AssessmentLayerOne = assessmentLayerOneResult; + sectionResult.AssessmentLayerTwoA = (RoundedDouble) assessmentLayerTwoAResult; + sectionResult.AssessmentLayerThree = (RoundedDouble) assessmentLayerThreeResult; + + // Call + var result = sectionResult.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(Convert.ToByte(assessmentLayerOneResult), result.LayerOne); + Assert.AreEqual(Convert.ToDecimal(assessmentLayerTwoAResult), result.LayerTwoA); + Assert.AreEqual(Convert.ToDecimal(assessmentLayerThreeResult), result.LayerThree); + } + + [Test] + public void Create_WithNaNLevel2aResult_ReturnsEntityWithExpectedResults() + { + // Setup + var sectionResult = new ClosingStructureFailureMechanismSectionResult(new TestFailureMechanismSection()); + sectionResult.AssessmentLayerTwoA = (RoundedDouble)double.NaN; + + // Call + var result = sectionResult.Create(new PersistenceRegistry()); + + // Assert + Assert.IsNull(result.LayerTwoA); + } + + [Test] + public void Create_WithNaNLevel3Result_ReturnsEntityWithExpectedResults() + { + // Setup + var sectionResult = new ClosingStructureFailureMechanismSectionResult(new TestFailureMechanismSection()); + sectionResult.AssessmentLayerThree = (RoundedDouble) double.NaN; + + // Call + var result = sectionResult.Create(new PersistenceRegistry()); + + // Assert + Assert.IsNull(result.LayerThree); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs =================================================================== diff -u -re0ef393f7069a18d7e160aceaf91f603dfc8c5ae -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs (.../PersistenceRegistryTest.cs) (revision e0ef393f7069a18d7e160aceaf91f603dfc8c5ae) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs (.../PersistenceRegistryTest.cs) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -1048,6 +1048,34 @@ } [Test] + public void Register_WithNullClosingStructureFailureMechanismSectionResult_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => registry.Register(new ClosingStructureSectionResultEntity(), null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + + [Test] + public void Register_WithNullClosingStructureSectionResultEntity_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => registry.Register(null, new ClosingStructureFailureMechanismSectionResult(new TestFailureMechanismSection())); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] public void Register_WithNullHydraulicLocationEntity_ThrowsArgumentNullException() { // Setup @@ -1621,6 +1649,27 @@ } [Test] + public void TransferIds_WithClosingStructureSectionResultEntityAddedWithClosingStructureFailureMechanismSectionResult_EqualClosingStructureSectionEntityIdAndClosingStructureFailureMechanismSectionResultStorageId() + { + // Setup + var registry = new PersistenceRegistry(); + + long storageId = new Random(21).Next(1,4000); + var entity = new ClosingStructureSectionResultEntity() + { + ClosingStructureSectionResultEntityId = storageId + }; + var model = new ClosingStructureFailureMechanismSectionResult(new TestFailureMechanismSection()); + registry.Register(entity, model); + + // Call + registry.TransferIds(); + + // Assert + Assert.AreEqual(storageId, model.StorageId); + } + + [Test] public void TransferIds_WithHydraulicLocationEntityAdded_EqualHydraulicLocationEntityIdAndHydraulicBoundaryLocationStorageId() { // Setup @@ -2226,6 +2275,42 @@ } [Test] + public void RemoveUntouched_ClosingStructureSectionResultEntity_OrphanedEntityIsRemovedFromRingtoetsEntities() + { + // Setup + var mocks = new MockRepository(); + IRingtoetsEntities dbContext = RingtoetsEntitiesHelper.CreateStub(mocks); + mocks.ReplayAll(); + + var orphanedEntity = new ClosingStructureSectionResultEntity + { + ClosingStructureSectionResultEntityId = 1 + }; + var persistentEntity = new ClosingStructureSectionResultEntity + { + ClosingStructureSectionResultEntityId = 2 + }; + dbContext.ClosingStructureSectionResultEntities.Add(orphanedEntity); + dbContext.ClosingStructureSectionResultEntities.Add(persistentEntity); + + var section = new ClosingStructureFailureMechanismSectionResult(new TestFailureMechanismSection()) + { + StorageId = persistentEntity.ClosingStructureSectionResultEntityId + }; + + var registry = new PersistenceRegistry(); + registry.Register(persistentEntity, section); + + // Call + registry.RemoveUntouched(dbContext); + + // Assert + Assert.AreEqual(1, dbContext.ClosingStructureSectionResultEntities.Count()); + CollectionAssert.Contains(dbContext.ClosingStructureSectionResultEntities, persistentEntity); + mocks.VerifyAll(); + } + + [Test] public void RemoveUntouched_HydraulicLocationEntity_OrphanedEntityIsRemovedFromRingtoetsEntities() { // Setup Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/IntegrationTests/StorageSqLiteIntegrationTest.cs =================================================================== diff -u -r2fe46c62134fde70ada240fa952971444177be90 -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/IntegrationTests/StorageSqLiteIntegrationTest.cs (.../StorageSqLiteIntegrationTest.cs) (revision 2fe46c62134fde70ada240fa952971444177be90) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/IntegrationTests/StorageSqLiteIntegrationTest.cs (.../StorageSqLiteIntegrationTest.cs) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -272,6 +272,9 @@ AssertFailureMechanismSectionResults( expectedAssessmentSection.WaterPressureAsphaltCover.SectionResults, actualAssessmentSection.WaterPressureAsphaltCover.SectionResults); + AssertFailureMechanismSectionResults( + expectedAssessmentSection.ClosingStructure.SectionResults, + actualAssessmentSection.ClosingStructure.SectionResults); } } @@ -379,6 +382,24 @@ } } + private void AssertFailureMechanismSectionResults(IEnumerable expectedSectionResults, IEnumerable actualSectionResults) + { + var expectedSectionResultsArray = expectedSectionResults.ToArray(); + var actualSectionResultsArray = actualSectionResults.ToArray(); + + Assert.AreEqual(expectedSectionResultsArray.Length, actualSectionResultsArray.Length); + + for (var i = 0; i < expectedSectionResultsArray.Length; i++) + { + ClosingStructureFailureMechanismSectionResult expectedSection = expectedSectionResultsArray[i]; + ClosingStructureFailureMechanismSectionResult actualSection = actualSectionResultsArray[i]; + + Assert.AreEqual(expectedSection.AssessmentLayerOne, actualSection.AssessmentLayerOne); + Assert.AreEqual(expectedSection.AssessmentLayerTwoA, actualSection.AssessmentLayerTwoA); + Assert.AreEqual(expectedSection.AssessmentLayerThree, actualSection.AssessmentLayerThree); + } + } + private void AssertFailureMechanism(IFailureMechanism expectedFailureMechanism, IFailureMechanism actualFailureMechanism) { Assert.AreEqual(expectedFailureMechanism.Name, actualFailureMechanism.Name); Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/ClosingStructureSectionResultEntityReadExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/ClosingStructureSectionResultEntityReadExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/ClosingStructureSectionResultEntityReadExtensionsTest.cs (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -0,0 +1,129 @@ +// 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 Application.Ringtoets.Storage.Read; +using Application.Ringtoets.Storage.TestUtil; +using NUnit.Framework; + +namespace Application.Ringtoets.Storage.Test.Read +{ + [TestFixture] + public class ClosingStructureSectionResultEntityReadExtensionsTest + { + [Test] + public void Read_CollectorIsNull_ThrowArgumentNullException() + { + // Setup + var entity = new ClosingStructureSectionResultEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Read_WithDecimalParameterValues_ReturnClosingStructureSoilLayerWithDoubleParameterValues(bool layerOne) + { + // Setup + var random = new Random(21); + var entityId = random.Next(1, 502); + double layerThree = random.NextDouble(); + double layerTwoA = random.NextDouble(); + var collector = new ReadConversionCollector(); + + var failureMechanismSectionEntity = new FailureMechanismSectionEntity(); + collector.Read(failureMechanismSectionEntity, new TestFailureMechanismSection()); + var entity = new ClosingStructureSectionResultEntity + { + ClosingStructureSectionResultEntityId = entityId, + LayerThree = Convert.ToDecimal(layerThree), + LayerTwoA = Convert.ToDecimal(layerTwoA), + LayerOne = Convert.ToByte(layerOne), + FailureMechanismSectionEntity = failureMechanismSectionEntity + }; + + // Call + var result = entity.Read(collector); + + // Assert + Assert.IsNotNull(result); + Assert.AreEqual(entityId, result.StorageId); + Assert.AreEqual(layerOne, result.AssessmentLayerOne); + Assert.AreEqual(layerTwoA, result.AssessmentLayerTwoA, 1e-6); + Assert.AreEqual(layerThree, result.AssessmentLayerThree, 1e-6); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Read_WithNullLayerTwoA_ReturnClosingStructureSoilLayerWithNullParameters(bool layerOne) + { + // Setup + var collector = new ReadConversionCollector(); + var failureMechanismSectionEntity = new FailureMechanismSectionEntity(); + collector.Read(failureMechanismSectionEntity, new TestFailureMechanismSection()); + var entity = new ClosingStructureSectionResultEntity + { + LayerOne = Convert.ToByte(layerOne), + LayerTwoA = null, + LayerThree = Convert.ToDecimal(new Random(21).NextDouble()), + FailureMechanismSectionEntity = failureMechanismSectionEntity + }; + + // Call + var layer = entity.Read(collector); + + // Assert + Assert.IsNaN(layer.AssessmentLayerTwoA); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Read_WithNullLayerThree_ReturnClosingStructureSoilLayerWithNullParameters(bool layerOne) + { + // Setup + var collector = new ReadConversionCollector(); + var failureMechanismSectionEntity = new FailureMechanismSectionEntity(); + collector.Read(failureMechanismSectionEntity, new TestFailureMechanismSection()); + var entity = new ClosingStructureSectionResultEntity + { + LayerOne = Convert.ToByte(layerOne), + LayerTwoA = Convert.ToDecimal(new Random(21).NextDouble()), + LayerThree = null, + FailureMechanismSectionEntity = failureMechanismSectionEntity + }; + + // Call + var layer = entity.Read(collector); + + // Assert + Assert.IsNaN(layer.AssessmentLayerThree); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/ClosingStructureFailureMechanismSectionResultUpdateExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/ClosingStructureFailureMechanismSectionResultUpdateExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/ClosingStructureFailureMechanismSectionResultUpdateExtensionsTest.cs (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -0,0 +1,162 @@ +// 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.Create; +using Application.Ringtoets.Storage.DbContext; +using Application.Ringtoets.Storage.Exceptions; +using Application.Ringtoets.Storage.TestUtil; +using Application.Ringtoets.Storage.Update; +using Core.Common.Base.Data; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Integration.Data.StandAlone.SectionResults; + +namespace Application.Ringtoets.Storage.Test.Update +{ + [TestFixture] + public class ClosingStructureFailureMechanismSectionResultUpdateExtensionsTest + { + [Test] + public void Update_WithoutContext_ArgumentNullException() + { + // Setup + var sectionResult = new ClosingStructureFailureMechanismSectionResult(new TestFailureMechanismSection()); + + // Call + TestDelegate test = () => sectionResult.Update(new PersistenceRegistry(), null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("context", paramName); + } + + [Test] + public void Update_WithoutPersistenceRegistry_ArgumentNullException() + { + // Setup + var sectionResult = new ClosingStructureFailureMechanismSectionResult(new TestFailureMechanismSection()); + + // Call + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + sectionResult.Update(null, ringtoetsEntities); + } + }; + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + public void Update_ContextWithNoClosingStructureSoilLayer_EntityNotFoundException() + { + // Setup + var sectionResult = new ClosingStructureFailureMechanismSectionResult(new TestFailureMechanismSection()); + + // Call + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + sectionResult.Update(new PersistenceRegistry(), ringtoetsEntities); + } + }; + + // Assert + var expectedMessage = String.Format("Het object 'ClosingStructureSectionResultEntity' met id '{0}' is niet gevonden.", 0); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + } + + [Test] + public void Update_ContextWithNoClosingStructureSoilLayerWithId_EntityNotFoundException() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.CreateStub(mocks); + + mocks.ReplayAll(); + + var storageId = 1; + var sectionResult = new ClosingStructureFailureMechanismSectionResult(new TestFailureMechanismSection()) + { + StorageId = storageId + }; + + ringtoetsEntities.ClosingStructureSectionResultEntities.Add(new ClosingStructureSectionResultEntity + { + ClosingStructureSectionResultEntityId = 2 + }); + + // Call + TestDelegate test = () => sectionResult.Update(new PersistenceRegistry(), ringtoetsEntities); + + // Assert + var expectedMessage = String.Format("Het object 'ClosingStructureSectionResultEntity' met id '{0}' is niet gevonden.", storageId); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + + mocks.VerifyAll(); + } + + [Test] + public void Update_WithClosingStructureSoilLayer_PropertiesUpdated() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.CreateStub(mocks); + + mocks.ReplayAll(); + + var sectionResult = new ClosingStructureFailureMechanismSectionResult(new TestFailureMechanismSection()) + { + StorageId = 1, + AssessmentLayerOne = true, + AssessmentLayerTwoA = (RoundedDouble) 0.4, + AssessmentLayerThree = (RoundedDouble) 4.4 + }; + + var sectionResultEntity = new ClosingStructureSectionResultEntity + { + ClosingStructureSectionResultEntityId = sectionResult.StorageId, + LayerOne = Convert.ToByte(false), + LayerTwoA = 2.1m, + LayerThree = 1.1m, + }; + + ringtoetsEntities.ClosingStructureSectionResultEntities.Add(sectionResultEntity); + + // Call + sectionResult.Update(new PersistenceRegistry(), ringtoetsEntities); + + // Assert + Assert.AreEqual(Convert.ToByte(true), sectionResultEntity.LayerOne); + Assert.AreEqual(sectionResult.AssessmentLayerTwoA.Value.ToNullableDecimal(), sectionResultEntity.LayerTwoA); + Assert.AreEqual(sectionResult.AssessmentLayerThree.Value.ToNullableDecimal(), sectionResultEntity.LayerThree); + + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/ClosingStructureFailureMechanismUpdateExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/ClosingStructureFailureMechanismUpdateExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/ClosingStructureFailureMechanismUpdateExtensionsTest.cs (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -0,0 +1,243 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Linq; + +using Application.Ringtoets.Storage.Create; +using Application.Ringtoets.Storage.DbContext; +using Application.Ringtoets.Storage.Exceptions; +using Application.Ringtoets.Storage.TestUtil; +using Application.Ringtoets.Storage.Update; +using Core.Common.Base.Geometry; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Integration.Data.StandAlone; + +namespace Application.Ringtoets.Storage.Test.Update +{ + [TestFixture] + public class ClosingStructureFailureMechanismUpdateExtensionsTest + { + [Test] + public void Update_WithoutContext_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new ClosingStructureFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Update(new PersistenceRegistry(), null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("context", paramName); + } + + [Test] + public void Update_WithoutPersistenceRegistry_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new ClosingStructureFailureMechanism(); + + // Call + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + failureMechanism.Update(null, ringtoetsEntities); + } + }; + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + public void Update_ContextWithNoClosingStructureFailureMechanism_ThrowsEntityNotFoundException() + { + // Setup + var failureMechanism = new ClosingStructureFailureMechanism(); + + // Call + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + failureMechanism.Update(new PersistenceRegistry(), ringtoetsEntities); + } + }; + + // Assert + var expectedMessage = String.Format("Het object 'FailureMechanismEntity' met id '{0}' is niet gevonden.", 0); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + } + + [Test] + public void Update_ContextWithNoClosingStructureFailureMechanismWithId_ThrowsEntityNotFoundException() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.CreateStub(mocks); + + mocks.ReplayAll(); + + var storageId = 1; + var failureMechanism = new ClosingStructureFailureMechanism + { + StorageId = storageId + }; + + ringtoetsEntities.FailureMechanismEntities.Add(new FailureMechanismEntity + { + FailureMechanismEntityId = 2 + }); + + // Call + TestDelegate test = () => failureMechanism.Update(new PersistenceRegistry(), ringtoetsEntities); + + // Assert + var expectedMessage = String.Format("Het object 'FailureMechanismEntity' met id '{0}' is niet gevonden.", storageId); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + + mocks.VerifyAll(); + } + + [Test] + public void Update_ContextWithClosingStructureFailureMechanism_PropertiesUpdated() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.CreateStub(mocks); + + mocks.ReplayAll(); + + var failureMechanism = new ClosingStructureFailureMechanism + { + StorageId = 1, + IsRelevant = true + }; + + var failureMechanismEntity = new FailureMechanismEntity + { + FailureMechanismEntityId = 1, + IsRelevant = Convert.ToByte(false) + }; + + ringtoetsEntities.FailureMechanismEntities.Add(failureMechanismEntity); + + // Call + failureMechanism.Update(new PersistenceRegistry(), ringtoetsEntities); + + // Assert + Assert.AreEqual(Convert.ToByte(true), failureMechanismEntity.IsRelevant); + + mocks.VerifyAll(); + } + + [Test] + public void Update_ContextWithNewFailureMechanismSections_FailureMechanismSectionsAdded() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.CreateStub(mocks); + + mocks.ReplayAll(); + + var failureMechanism = new ClosingStructureFailureMechanism + { + StorageId = 1 + }; + failureMechanism.AddSection(new FailureMechanismSection("", new[] + { + new Point2D(0, 0) + })); + + var failureMechanismEntity = new FailureMechanismEntity + { + FailureMechanismEntityId = 1, + }; + + ringtoetsEntities.FailureMechanismEntities.Add(failureMechanismEntity); + + // Call + failureMechanism.Update(new PersistenceRegistry(), ringtoetsEntities); + + // Assert + Assert.AreEqual(1, failureMechanismEntity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, failureMechanismEntity.FailureMechanismSectionEntities.SelectMany(fms => fms.ClosingStructureSectionResultEntities).Count()); + + mocks.VerifyAll(); + } + + [Test] + public void Update_ContextWithUpdatedFailureMechanismSections_NoNewFailureMechanismSectionsAdded() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.CreateStub(mocks); + + mocks.ReplayAll(); + + var failureMechanism = new ClosingStructureFailureMechanism + { + StorageId = 1 + }; + var testName = "testName"; + failureMechanism.AddSection(new FailureMechanismSection(testName, new[] + { + new Point2D(0, 0) + }) + { + StorageId = 1 + }); + + var failureMechanismSectionEntity = new FailureMechanismSectionEntity + { + FailureMechanismSectionEntityId = 1, + }; + var failureMechanismEntity = new FailureMechanismEntity + { + FailureMechanismEntityId = 1, + FailureMechanismSectionEntities = + { + failureMechanismSectionEntity + } + }; + + ringtoetsEntities.FailureMechanismEntities.Add(failureMechanismEntity); + ringtoetsEntities.FailureMechanismSectionEntities.Add(failureMechanismSectionEntity); + + // Call + failureMechanism.Update(new PersistenceRegistry(), ringtoetsEntities); + + // Assert + Assert.AreEqual(1, failureMechanismEntity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, failureMechanismEntity.FailureMechanismSectionEntities.SelectMany(fms => fms.ClosingStructureSectionResultEntities).Count()); + Assert.AreEqual(testName, failureMechanismEntity.FailureMechanismSectionEntities.ElementAt(0).Name); + + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/RingtoetsEntitiesHelper.cs =================================================================== diff -u -r2fe46c62134fde70ada240fa952971444177be90 -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/RingtoetsEntitiesHelper.cs (.../RingtoetsEntitiesHelper.cs) (revision 2fe46c62134fde70ada240fa952971444177be90) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/RingtoetsEntitiesHelper.cs (.../RingtoetsEntitiesHelper.cs) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -47,6 +47,7 @@ DbSet strengthStabilityLengthwiseConstructionSectionResultsSet = CreateEmptyTestDbSet(); DbSet technicalInnovationSectionResultsSet = CreateEmptyTestDbSet(); DbSet waterPressureAsphaltCoverSectionResultsSet = CreateEmptyTestDbSet(); + DbSet closingStructureSectionResultsSet = CreateEmptyTestDbSet(); DbSet assessmentSectionsSet = CreateEmptyTestDbSet(); DbSet referenceLinesSet = CreateEmptyTestDbSet(); DbSet calculationGroupsSet = CreateEmptyTestDbSet(); @@ -75,6 +76,7 @@ ringtoetsEntities.Stub(r => r.StrengthStabilityLengthwiseConstructionSectionResultEntities).Return(strengthStabilityLengthwiseConstructionSectionResultsSet); ringtoetsEntities.Stub(r => r.TechnicalInnovationSectionResultEntities).Return(technicalInnovationSectionResultsSet); ringtoetsEntities.Stub(r => r.WaterPressureAsphaltCoverSectionResultEntities).Return(waterPressureAsphaltCoverSectionResultsSet); + ringtoetsEntities.Stub(r => r.ClosingStructureSectionResultEntities).Return(closingStructureSectionResultsSet); ringtoetsEntities.Stub(r => r.AssessmentSectionEntities).Return(assessmentSectionsSet); ringtoetsEntities.Stub(r => r.ReferenceLinePointEntities).Return(referenceLinesSet); ringtoetsEntities.Stub(r => r.CalculationGroupEntities).Return(calculationGroupsSet); Index: Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/RingtoetsProjectHelper.cs =================================================================== diff -u -r2fe46c62134fde70ada240fa952971444177be90 -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/RingtoetsProjectHelper.cs (.../RingtoetsProjectHelper.cs) (revision 2fe46c62134fde70ada240fa952971444177be90) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/RingtoetsProjectHelper.cs (.../RingtoetsProjectHelper.cs) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -229,6 +229,7 @@ AddSections(assessmentSection.HeightStructures); SetSectionResults(assessmentSection.HeightStructures.SectionResults); AddSections(assessmentSection.ClosingStructure); + SetSectionResults(assessmentSection.ClosingStructure.SectionResults); AddSections(assessmentSection.StrengthStabilityPointConstruction); AddSections(assessmentSection.StrengthStabilityLengthwiseConstruction); SetSectionResults(assessmentSection.StrengthStabilityLengthwiseConstruction.SectionResults); @@ -300,6 +301,17 @@ } } + private static void SetSectionResults(IEnumerable sectionResults) + { + var random = new Random(21); + foreach (var sectionResult in sectionResults) + { + sectionResult.AssessmentLayerOne = Convert.ToBoolean(random.Next(0, 2)); + sectionResult.AssessmentLayerTwoA = (RoundedDouble)random.NextDouble(); + sectionResult.AssessmentLayerThree = (RoundedDouble)random.NextDouble(); + } + } + private static void AddSections(IFailureMechanism failureMechanism) { failureMechanism.AddSection(new FailureMechanismSection("section 1", new[] Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/GrassCoverErosionInwardsFailureMechanismSectionResultTest.cs =================================================================== diff -u -rf5a2d607a5b8053b232c1f3ad572a0acba6a4e3a -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/GrassCoverErosionInwardsFailureMechanismSectionResultTest.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultTest.cs) (revision f5a2d607a5b8053b232c1f3ad572a0acba6a4e3a) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/GrassCoverErosionInwardsFailureMechanismSectionResultTest.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultTest.cs) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -21,6 +21,7 @@ using System; using Core.Common.Base.Geometry; +using Core.Common.Base.Storage; using NUnit.Framework; using Ringtoets.Common.Data.FailureMechanism; @@ -51,10 +52,12 @@ // Assert Assert.IsInstanceOf(result); + Assert.IsInstanceOf(result); Assert.AreSame(section, result.Section); Assert.IsFalse(result.AssessmentLayerOne); Assert.AreEqual(0, result.AssessmentLayerTwoA.Value); Assert.AreEqual(0, result.AssessmentLayerThree.Value); + Assert.AreEqual(0, result.StorageId); } } } \ No newline at end of file Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructuresFailureMechanismSectionResultTest.cs =================================================================== diff -u -rf5a2d607a5b8053b232c1f3ad572a0acba6a4e3a -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructuresFailureMechanismSectionResultTest.cs (.../HeightStructuresFailureMechanismSectionResultTest.cs) (revision f5a2d607a5b8053b232c1f3ad572a0acba6a4e3a) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructuresFailureMechanismSectionResultTest.cs (.../HeightStructuresFailureMechanismSectionResultTest.cs) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -22,6 +22,7 @@ using System; using Core.Common.Base.Data; using Core.Common.Base.Geometry; +using Core.Common.Base.Storage; using NUnit.Framework; using Ringtoets.Common.Data.FailureMechanism; @@ -41,10 +42,12 @@ // Assert Assert.IsInstanceOf(sectionResult); + Assert.IsInstanceOf(sectionResult); Assert.AreSame(section, sectionResult.Section); Assert.IsFalse(sectionResult.AssessmentLayerOne); Assert.AreEqual(0, sectionResult.AssessmentLayerTwoA.Value); Assert.AreEqual(0, sectionResult.AssessmentLayerThree.Value); + Assert.AreEqual(0, sectionResult.StorageId); } [Test] Index: Ringtoets/Integration/src/Ringtoets.Integration.Data/StandAlone/SectionResults/ClosingStructureFailureMechanismSectionResult.cs =================================================================== diff -u -rf72f906a6875250a4378945ce814997ff8aaf1a7 -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Ringtoets/Integration/src/Ringtoets.Integration.Data/StandAlone/SectionResults/ClosingStructureFailureMechanismSectionResult.cs (.../ClosingStructureFailureMechanismSectionResult.cs) (revision f72f906a6875250a4378945ce814997ff8aaf1a7) +++ Ringtoets/Integration/src/Ringtoets.Integration.Data/StandAlone/SectionResults/ClosingStructureFailureMechanismSectionResult.cs (.../ClosingStructureFailureMechanismSectionResult.cs) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -21,6 +21,7 @@ using System; using Core.Common.Base.Data; +using Core.Common.Base.Storage; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Properties; @@ -30,7 +31,7 @@ /// This class holds information about the result of a calculation on section level for the /// Closing Structure failure mechanism. /// - public class ClosingStructureFailureMechanismSectionResult : FailureMechanismSectionResult + public class ClosingStructureFailureMechanismSectionResult : FailureMechanismSectionResult, IStorable { private RoundedDouble assessmentLayerTwoA; @@ -75,5 +76,7 @@ /// Gets or sets the value of the tailored assessment of safety. /// public RoundedDouble AssessmentLayerThree { get; set; } + + public long StorageId { get; set; } } } \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/StandAlone/SectionResults/ClosingStructureFailureMechanismSectionResultTest.cs =================================================================== diff -u -rf72f906a6875250a4378945ce814997ff8aaf1a7 -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/StandAlone/SectionResults/ClosingStructureFailureMechanismSectionResultTest.cs (.../ClosingStructureFailureMechanismSectionResultTest.cs) (revision f72f906a6875250a4378945ce814997ff8aaf1a7) +++ Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/StandAlone/SectionResults/ClosingStructureFailureMechanismSectionResultTest.cs (.../ClosingStructureFailureMechanismSectionResultTest.cs) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -22,6 +22,7 @@ using System; using Core.Common.Base.Data; using Core.Common.Base.Geometry; +using Core.Common.Base.Storage; using NUnit.Framework; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Integration.Data.StandAlone.SectionResults; @@ -53,10 +54,12 @@ // Assert Assert.IsInstanceOf(result); + Assert.IsInstanceOf(result); Assert.AreSame(section, result.Section); Assert.IsFalse(result.AssessmentLayerOne); Assert.AreEqual(1, result.AssessmentLayerTwoA.Value); Assert.AreEqual(0, result.AssessmentLayerThree.Value); + Assert.AreEqual(0, result.StorageId); } [Test] Index: Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/StandAlone/SectionResults/StrengthStabilityLengthwiseConstructionFailureMechanismSectionResultTest.cs =================================================================== diff -u -rf72f906a6875250a4378945ce814997ff8aaf1a7 -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/StandAlone/SectionResults/StrengthStabilityLengthwiseConstructionFailureMechanismSectionResultTest.cs (.../StrengthStabilityLengthwiseConstructionFailureMechanismSectionResultTest.cs) (revision f72f906a6875250a4378945ce814997ff8aaf1a7) +++ Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/StandAlone/SectionResults/StrengthStabilityLengthwiseConstructionFailureMechanismSectionResultTest.cs (.../StrengthStabilityLengthwiseConstructionFailureMechanismSectionResultTest.cs) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -21,6 +21,7 @@ using System; using Core.Common.Base.Geometry; +using Core.Common.Base.Storage; using NUnit.Framework; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Integration.Data.StandAlone.SectionResults; @@ -52,9 +53,11 @@ // Assert Assert.IsInstanceOf(result); + Assert.IsInstanceOf(result); Assert.AreSame(section, result.Section); Assert.IsFalse(result.AssessmentLayerOne); Assert.AreEqual(0, result.AssessmentLayerThree.Value); + Assert.AreEqual(0, result.StorageId); } } } \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/StandAlone/SectionResults/TechnicalInnovationFailureMechanismSectionResultTest.cs =================================================================== diff -u -rf72f906a6875250a4378945ce814997ff8aaf1a7 -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/StandAlone/SectionResults/TechnicalInnovationFailureMechanismSectionResultTest.cs (.../TechnicalInnovationFailureMechanismSectionResultTest.cs) (revision f72f906a6875250a4378945ce814997ff8aaf1a7) +++ Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/StandAlone/SectionResults/TechnicalInnovationFailureMechanismSectionResultTest.cs (.../TechnicalInnovationFailureMechanismSectionResultTest.cs) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -21,6 +21,7 @@ using System; using Core.Common.Base.Geometry; +using Core.Common.Base.Storage; using NUnit.Framework; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Integration.Data.StandAlone.SectionResults; @@ -55,9 +56,11 @@ // Assert Assert.IsInstanceOf(result); + Assert.IsInstanceOf(result); Assert.AreSame(section, result.Section); Assert.IsFalse(result.AssessmentLayerOne); Assert.AreEqual(0, result.AssessmentLayerThree.Value); + Assert.AreEqual(0, result.StorageId); } } } \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/StandAlone/SectionResults/WaterPressureAsphaltCoverFailureMechanismSectionResultTest.cs =================================================================== diff -u -rf72f906a6875250a4378945ce814997ff8aaf1a7 -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/StandAlone/SectionResults/WaterPressureAsphaltCoverFailureMechanismSectionResultTest.cs (.../WaterPressureAsphaltCoverFailureMechanismSectionResultTest.cs) (revision f72f906a6875250a4378945ce814997ff8aaf1a7) +++ Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/StandAlone/SectionResults/WaterPressureAsphaltCoverFailureMechanismSectionResultTest.cs (.../WaterPressureAsphaltCoverFailureMechanismSectionResultTest.cs) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -21,6 +21,7 @@ using System; using Core.Common.Base.Geometry; +using Core.Common.Base.Storage; using NUnit.Framework; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Integration.Data.StandAlone.SectionResults; @@ -52,9 +53,11 @@ // Assert Assert.IsInstanceOf(result); + Assert.IsInstanceOf(result); Assert.AreSame(section, result.Section); Assert.IsFalse(result.AssessmentLayerOne); Assert.AreEqual(0, result.AssessmentLayerThree.Value); + Assert.AreEqual(0, result.StorageId); } } } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/PipingFailureMechanismSectionResultTest.cs =================================================================== diff -u -r80404901c704ca22397f36ebe46f81e73059e30a -r1cd3618f5f8916ef15992d69ec3b447b311c2f72 --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/PipingFailureMechanismSectionResultTest.cs (.../PipingFailureMechanismSectionResultTest.cs) (revision 80404901c704ca22397f36ebe46f81e73059e30a) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/PipingFailureMechanismSectionResultTest.cs (.../PipingFailureMechanismSectionResultTest.cs) (revision 1cd3618f5f8916ef15992d69ec3b447b311c2f72) @@ -22,6 +22,7 @@ using System; using Core.Common.Base.Data; using Core.Common.Base.Geometry; +using Core.Common.Base.Storage; using NUnit.Framework; using Ringtoets.Common.Data.FailureMechanism; @@ -40,10 +41,13 @@ PipingFailureMechanismSectionResult sectionResult = new PipingFailureMechanismSectionResult(section); // Assert + Assert.IsInstanceOf(sectionResult); + Assert.IsInstanceOf(sectionResult); Assert.AreSame(section, sectionResult.Section); Assert.IsFalse(sectionResult.AssessmentLayerOne); Assert.AreEqual((RoundedDouble) 0, sectionResult.GetAssessmentLayerTwoA(new PipingCalculationScenario[0])); - Assert.AreEqual((RoundedDouble) 0, sectionResult.AssessmentLayerThree); + Assert.AreEqual((RoundedDouble)0, sectionResult.AssessmentLayerThree); + Assert.AreEqual(0, sectionResult.StorageId); } [Test]