Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj =================================================================== diff -u -rebad637e9483d348a5efe2fe902d56aa91bf6a31 -r2fe46c62134fde70ada240fa952971444177be90 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision ebad637e9483d348a5efe2fe902d56aa91bf6a31) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -54,6 +54,10 @@ + + + + @@ -163,6 +167,8 @@ + + @@ -216,6 +222,10 @@ + + + + Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/AssessmentSectionCreateExtensions.cs =================================================================== diff -u -rebad637e9483d348a5efe2fe902d56aa91bf6a31 -r2fe46c62134fde70ada240fa952971444177be90 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/AssessmentSectionCreateExtensions.cs (.../AssessmentSectionCreateExtensions.cs) (revision ebad637e9483d348a5efe2fe902d56aa91bf6a31) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/AssessmentSectionCreateExtensions.cs (.../AssessmentSectionCreateExtensions.cs) (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -61,6 +61,8 @@ entity.FailureMechanismEntities.Add(section.GrassCoverErosionInwards.Create(registry)); entity.FailureMechanismEntities.Add(section.HeightStructures.Create(registry)); entity.FailureMechanismEntities.Add(section.StrengthStabilityLengthwiseConstruction.Create(registry)); + entity.FailureMechanismEntities.Add(section.TechnicalInnovation.Create(registry)); + entity.FailureMechanismEntities.Add(section.WaterPressureAsphaltCover.Create(registry)); AddEntitiesForAddStandAloneFailureMechanisms(section, entity, registry); @@ -75,15 +77,13 @@ entity.FailureMechanismEntities.Add(section.Microstability.Create(FailureMechanismType.Microstability, registry)); entity.FailureMechanismEntities.Add(section.StabilityStoneCover.Create(FailureMechanismType.StabilityStoneRevetment, registry)); entity.FailureMechanismEntities.Add(section.WaveImpactAsphaltCover.Create(FailureMechanismType.WaveImpactOnAsphaltRevetment, registry)); - entity.FailureMechanismEntities.Add(section.WaterPressureAsphaltCover.Create(FailureMechanismType.WaterOverpressureAsphaltRevetment, registry)); 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)); - entity.FailureMechanismEntities.Add(section.TechnicalInnovation.Create(FailureMechanismType.TechnicalInnovations, registry)); } private static void AddEntityForReferenceLine(AssessmentSection section, AssessmentSectionEntity entity) Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/PersistenceRegistry.cs =================================================================== diff -u -rebad637e9483d348a5efe2fe902d56aa91bf6a31 -r2fe46c62134fde70ada240fa952971444177be90 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/PersistenceRegistry.cs (.../PersistenceRegistry.cs) (revision ebad637e9483d348a5efe2fe902d56aa91bf6a31) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/PersistenceRegistry.cs (.../PersistenceRegistry.cs) (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -57,6 +57,8 @@ private readonly Dictionary grassCoverErosionInwardsFailureMechanismSectionResults = new Dictionary(); private readonly Dictionary heightStructuresFailureMechanismSectionResults = new Dictionary(); private readonly Dictionary strengthStabilityLengthwiseConstructionFailureMechanismSectionResults = new Dictionary(); + private readonly Dictionary technicalInnovationFailureMechanismSectionResults = new Dictionary(); + private readonly Dictionary waterPressureAsphaltCoverFailureMechanismSectionResults = 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()); @@ -155,6 +157,38 @@ /// 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(TechnicalInnovationSectionResultEntity entity, TechnicalInnovationFailureMechanismSectionResult model) + { + Register(technicalInnovationFailureMechanismSectionResults, 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: + /// + /// is null + /// is null + /// + public void Register(WaterPressureAsphaltCoverSectionResultEntity entity, WaterPressureAsphaltCoverFailureMechanismSectionResult model) + { + Register(waterPressureAsphaltCoverFailureMechanismSectionResults, 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: @@ -641,6 +675,16 @@ strengthStabilityLengthwiseConstructionFailureMechanismSectionResults[entity].StorageId = entity.StrengthStabilityLengthwiseConstructionSectionResultEntityId; } + foreach (var entity in technicalInnovationFailureMechanismSectionResults.Keys) + { + technicalInnovationFailureMechanismSectionResults[entity].StorageId = entity.TechnicalInnovationSectionResultEntityId; + } + + foreach (var entity in waterPressureAsphaltCoverFailureMechanismSectionResults.Keys) + { + waterPressureAsphaltCoverFailureMechanismSectionResults[entity].StorageId = entity.WaterPressureAsphaltCoverSectionResultEntityId; + } + foreach (var entity in hydraulicLocations.Keys) { hydraulicLocations[entity].StorageId = entity.HydraulicLocationEntityId; @@ -799,6 +843,28 @@ } dbContext.StrengthStabilityLengthwiseConstructionSectionResultEntities.RemoveRange(orphanedStrengthStabilityLengthwiseConstructionSectionResultEntities); + var orphanedTechnicalInnovationSectionResultEntities = new List(); + foreach (TechnicalInnovationSectionResultEntity sectionResultEntity in dbContext.TechnicalInnovationSectionResultEntities + .Where(e => e.TechnicalInnovationSectionResultEntityId > 0)) + { + if (!technicalInnovationFailureMechanismSectionResults.ContainsKey(sectionResultEntity)) + { + orphanedTechnicalInnovationSectionResultEntities.Add(sectionResultEntity); + } + } + dbContext.TechnicalInnovationSectionResultEntities.RemoveRange(orphanedTechnicalInnovationSectionResultEntities); + + var orphanedWaterPressureAsphaltCoverSectionResultEntities = new List(); + foreach (WaterPressureAsphaltCoverSectionResultEntity sectionResultEntity in dbContext.WaterPressureAsphaltCoverSectionResultEntities + .Where(e => e.WaterPressureAsphaltCoverSectionResultEntityId > 0)) + { + if (!waterPressureAsphaltCoverFailureMechanismSectionResults.ContainsKey(sectionResultEntity)) + { + orphanedWaterPressureAsphaltCoverSectionResultEntities.Add(sectionResultEntity); + } + } + dbContext.WaterPressureAsphaltCoverSectionResultEntities.RemoveRange(orphanedWaterPressureAsphaltCoverSectionResultEntities); + var orphanedHydraulicLocationEntities = new List(); foreach (HydraulicLocationEntity hydraulicLocationEntity in dbContext.HydraulicLocationEntities .Where(e => e.HydraulicLocationEntityId > 0)) Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/TechnicalInnovationFailureMechanismCreateExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/TechnicalInnovationFailureMechanismCreateExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/TechnicalInnovationFailureMechanismCreateExtensions.cs (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -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 TechnicalInnovationFailureMechanismCreateExtensions + { + /// + /// 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 TechnicalInnovationFailureMechanism mechanism, PersistenceRegistry registry) + { + if (registry == null) + { + throw new ArgumentNullException("registry"); + } + + var entity = new FailureMechanismEntity + { + FailureMechanismType = (short) FailureMechanismType.TechnicalInnovations, + 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(TechnicalInnovationFailureMechanism mechanism, PersistenceRegistry registry) + { + foreach (var failureMechanismSectionResult in mechanism.SectionResults) + { + var sectionResultEntity = failureMechanismSectionResult.Create(registry); + var section = registry.Get(failureMechanismSectionResult.Section); + section.TechnicalInnovationSectionResultEntities.Add(sectionResultEntity); + } + } + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/TechnicalInnovationFailureMechanismSectionResultCreateExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/TechnicalInnovationFailureMechanismSectionResultCreateExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/TechnicalInnovationFailureMechanismSectionResultCreateExtensions.cs (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -0,0 +1,57 @@ +// 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 TechnicalInnovationFailureMechanismSectionResultCreateExtensions + { + /// + /// 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 TechnicalInnovationSectionResultEntity Create(this TechnicalInnovationFailureMechanismSectionResult result, PersistenceRegistry registry) + { + if (registry == null) + { + throw new ArgumentNullException("registry"); + } + var sectionResultEntity = new TechnicalInnovationSectionResultEntity + { + LayerOne = Convert.ToByte(result.AssessmentLayerOne), + 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/WaterPressureAsphaltCoverFailureMechanismCreateExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/WaterPressureAsphaltCoverFailureMechanismCreateExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/WaterPressureAsphaltCoverFailureMechanismCreateExtensions.cs (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -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 WaterPressureAsphaltCoverFailureMechanismCreateExtensions + { + /// + /// 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 WaterPressureAsphaltCoverFailureMechanism mechanism, PersistenceRegistry registry) + { + if (registry == null) + { + throw new ArgumentNullException("registry"); + } + + var entity = new FailureMechanismEntity + { + FailureMechanismType = (short) FailureMechanismType.WaterOverpressureAsphaltRevetment, + 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(WaterPressureAsphaltCoverFailureMechanism mechanism, PersistenceRegistry registry) + { + foreach (var failureMechanismSectionResult in mechanism.SectionResults) + { + var sectionResultEntity = failureMechanismSectionResult.Create(registry); + var section = registry.Get(failureMechanismSectionResult.Section); + section.WaterPressureAsphaltCoverSectionResultEntities.Add(sectionResultEntity); + } + } + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/WaterPressureAsphaltCoverFailureMechanismSectionResultCreateExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/WaterPressureAsphaltCoverFailureMechanismSectionResultCreateExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/WaterPressureAsphaltCoverFailureMechanismSectionResultCreateExtensions.cs (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -0,0 +1,57 @@ +// 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 WaterPressureAsphaltCoverFailureMechanismSectionResultCreateExtensions + { + /// + /// 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 WaterPressureAsphaltCoverSectionResultEntity Create(this WaterPressureAsphaltCoverFailureMechanismSectionResult result, PersistenceRegistry registry) + { + if (registry == null) + { + throw new ArgumentNullException("registry"); + } + var sectionResultEntity = new WaterPressureAsphaltCoverSectionResultEntity + { + LayerOne = Convert.ToByte(result.AssessmentLayerOne), + LayerThree = result.AssessmentLayerThree.Value.ToNullableDecimal() + }; + + registry.Register(sectionResultEntity, result); + return sectionResultEntity; + } + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/IRingtoetsEntities.cs =================================================================== diff -u -rebad637e9483d348a5efe2fe902d56aa91bf6a31 -r2fe46c62134fde70ada240fa952971444177be90 --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/IRingtoetsEntities.cs (.../IRingtoetsEntities.cs) (revision ebad637e9483d348a5efe2fe902d56aa91bf6a31) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/IRingtoetsEntities.cs (.../IRingtoetsEntities.cs) (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -79,6 +79,18 @@ DbSet StrengthStabilityLengthwiseConstructionSectionResultEntities { get; } /// + /// Gets a of containing + /// every entity found in the database. + /// + DbSet TechnicalInnovationSectionResultEntities { get; } + + /// + /// Gets a of containing + /// every entity found in the database. + /// + DbSet WaterPressureAsphaltCoverSectionResultEntities { get; } + + /// /// Gets a of containing /// every entity found in the database. /// Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/AssessmentSectionEntityReadExtensions.cs =================================================================== diff -u -rebad637e9483d348a5efe2fe902d56aa91bf6a31 -r2fe46c62134fde70ada240fa952971444177be90 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/AssessmentSectionEntityReadExtensions.cs (.../AssessmentSectionEntityReadExtensions.cs) (revision ebad637e9483d348a5efe2fe902d56aa91bf6a31) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/AssessmentSectionEntityReadExtensions.cs (.../AssessmentSectionEntityReadExtensions.cs) (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -69,6 +69,8 @@ entity.ReadGrassCoverErosionInwardsFailureMechanism(assessmentSection, collector); entity.ReadHeightStructuresFailureMechanism(assessmentSection, collector); entity.ReadStrengthStabilityLengthwiseConstructionFailureMechanism(assessmentSection, collector); + entity.ReadTechnicalInnovationFailureMechanism(assessmentSection, collector); + entity.ReadWaterPressureAsphaltCoverFailureMechanism(assessmentSection, collector); entity.ReadStandAloneFailureMechanisms(assessmentSection, collector); return assessmentSection; @@ -136,22 +138,38 @@ } } + private static void ReadTechnicalInnovationFailureMechanism(this AssessmentSectionEntity entity, AssessmentSection assessmentSection, ReadConversionCollector collector) + { + var technicalInnovationFailureMechanismEntity = entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (int) FailureMechanismType.TechnicalInnovations); + if (technicalInnovationFailureMechanismEntity != null) + { + technicalInnovationFailureMechanismEntity.ReadAsTechnicalInnovationFailureMechanism(assessmentSection.TechnicalInnovation, collector); + } + } + + private static void ReadWaterPressureAsphaltCoverFailureMechanism(this AssessmentSectionEntity entity, AssessmentSection assessmentSection, ReadConversionCollector collector) + { + var waterPressureAsphaltCoverFailureMechanismEntity = entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (int) FailureMechanismType.WaterOverpressureAsphaltRevetment); + if (waterPressureAsphaltCoverFailureMechanismEntity != null) + { + waterPressureAsphaltCoverFailureMechanismEntity.ReadAsWaterPressureAsphaltCoverFailureMechanism(assessmentSection.WaterPressureAsphaltCover, collector); + } + } + private static void ReadStandAloneFailureMechanisms(this AssessmentSectionEntity entity, AssessmentSection assessmentSection, ReadConversionCollector collector) { entity.ReadStandAloneFailureMechanism(FailureMechanismType.MacrostabilityInwards, assessmentSection.MacrostabilityInwards, collector); entity.ReadStandAloneFailureMechanism(FailureMechanismType.MacrostabilityOutwards, assessmentSection.MacrostabilityOutwards, collector); entity.ReadStandAloneFailureMechanism(FailureMechanismType.Microstability, assessmentSection.Microstability, collector); entity.ReadStandAloneFailureMechanism(FailureMechanismType.StabilityStoneRevetment, assessmentSection.StabilityStoneCover, collector); entity.ReadStandAloneFailureMechanism(FailureMechanismType.WaveImpactOnAsphaltRevetment, assessmentSection.WaveImpactAsphaltCover, collector); - entity.ReadStandAloneFailureMechanism(FailureMechanismType.WaterOverpressureAsphaltRevetment, assessmentSection.WaterPressureAsphaltCover, collector); 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); - entity.ReadStandAloneFailureMechanism(FailureMechanismType.TechnicalInnovations, assessmentSection.TechnicalInnovation, collector); } private static void ReadStandAloneFailureMechanism(this AssessmentSectionEntity entity, FailureMechanismType failureMechanismType, IFailureMechanism standAloneFailureMechanism, ReadConversionCollector collector) Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/FailureMechanismEntityReadExtensions.cs =================================================================== diff -u -rebad637e9483d348a5efe2fe902d56aa91bf6a31 -r2fe46c62134fde70ada240fa952971444177be90 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/FailureMechanismEntityReadExtensions.cs (.../FailureMechanismEntityReadExtensions.cs) (revision ebad637e9483d348a5efe2fe902d56aa91bf6a31) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/FailureMechanismEntityReadExtensions.cs (.../FailureMechanismEntityReadExtensions.cs) (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -187,6 +187,64 @@ } /// + /// Read the and use the information to update a . + /// + /// The to create for. + /// + /// The object keeping track of read operations. + internal static void ReadAsTechnicalInnovationFailureMechanism(this FailureMechanismEntity entity, TechnicalInnovationFailureMechanism failureMechanism, ReadConversionCollector collector) + { + failureMechanism.StorageId = entity.FailureMechanismEntityId; + failureMechanism.IsRelevant = entity.IsRelevant == 1; + failureMechanism.Comments = entity.Comments; + + entity.ReadFailureMechanismSections(failureMechanism, collector); + entity.ReadTechnicalInnovationMechanismSectionResults(failureMechanism, collector); + } + + private static void ReadTechnicalInnovationMechanismSectionResults(this FailureMechanismEntity entity, TechnicalInnovationFailureMechanism failureMechanism, ReadConversionCollector collector) + { + foreach (var sectionResultEntity in entity.FailureMechanismSectionEntities.SelectMany(fms => fms.TechnicalInnovationSectionResultEntities)) + { + 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.AssessmentLayerThree = readSectionResult.AssessmentLayerThree; + } + } + + /// + /// Read the and use the information to update a . + /// + /// The to create for. + /// + /// The object keeping track of read operations. + internal static void ReadAsWaterPressureAsphaltCoverFailureMechanism(this FailureMechanismEntity entity, WaterPressureAsphaltCoverFailureMechanism failureMechanism, ReadConversionCollector collector) + { + failureMechanism.StorageId = entity.FailureMechanismEntityId; + failureMechanism.IsRelevant = entity.IsRelevant == 1; + failureMechanism.Comments = entity.Comments; + + entity.ReadFailureMechanismSections(failureMechanism, collector); + entity.ReadWaterPressureAsphaltCoverMechanismSectionResults(failureMechanism, collector); + } + + private static void ReadWaterPressureAsphaltCoverMechanismSectionResults(this FailureMechanismEntity entity, WaterPressureAsphaltCoverFailureMechanism failureMechanism, ReadConversionCollector collector) + { + foreach (var sectionResultEntity in entity.FailureMechanismSectionEntities.SelectMany(fms => fms.WaterPressureAsphaltCoverSectionResultEntities)) + { + 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.AssessmentLayerThree = readSectionResult.AssessmentLayerThree; + } + } + + /// /// Read the and use the information to update a . /// /// The to read into a . Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/TechnicalInnovationSectionResultEntityReadExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/TechnicalInnovationSectionResultEntityReadExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/TechnicalInnovationSectionResultEntityReadExtensions.cs (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -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 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 TechnicalInnovationSectionResultEntityReadExtensions + { + /// + /// 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 TechnicalInnovationFailureMechanismSectionResult Read(this TechnicalInnovationSectionResultEntity entity, ReadConversionCollector collector) + { + if (collector == null) + { + throw new ArgumentNullException("collector"); + } + var sectionResult = new TechnicalInnovationFailureMechanismSectionResult(collector.Get(entity.FailureMechanismSectionEntity)) + { + StorageId = entity.TechnicalInnovationSectionResultEntityId, + AssessmentLayerOne = Convert.ToBoolean(entity.LayerOne), + AssessmentLayerThree = (RoundedDouble) entity.LayerThree.ToNanableDouble() + }; + return sectionResult; + } + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/WaterPressureAsphaltCoverSectionResultEntityReadExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/WaterPressureAsphaltCoverSectionResultEntityReadExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/WaterPressureAsphaltCoverSectionResultEntityReadExtensions.cs (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -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 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 WaterPressureAsphaltCoverSectionResultEntityReadExtensions + { + /// + /// 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 WaterPressureAsphaltCoverFailureMechanismSectionResult Read(this WaterPressureAsphaltCoverSectionResultEntity entity, ReadConversionCollector collector) + { + if (collector == null) + { + throw new ArgumentNullException("collector"); + } + var sectionResult = new WaterPressureAsphaltCoverFailureMechanismSectionResult(collector.Get(entity.FailureMechanismSectionEntity)) + { + StorageId = entity.WaterPressureAsphaltCoverSectionResultEntityId, + AssessmentLayerOne = Convert.ToBoolean(entity.LayerOne), + AssessmentLayerThree = (RoundedDouble) entity.LayerThree.ToNanableDouble() + }; + return sectionResult; + } + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Update/TechnicalInnovationFailureMechanismSectionResultUpdateExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Update/TechnicalInnovationFailureMechanismSectionResultUpdateExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Update/TechnicalInnovationFailureMechanismSectionResultUpdateExtensions.cs (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -0,0 +1,83 @@ +// 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 TechnicalInnovationFailureMechanismSectionResultUpdateExtensions + { + /// + /// 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 TechnicalInnovationFailureMechanismSectionResult result, PersistenceRegistry registry, IRingtoetsEntities context) + { + if (context == null) + { + throw new ArgumentNullException("context"); + } + if (registry == null) + { + throw new ArgumentNullException("registry"); + } + + TechnicalInnovationSectionResultEntity entity = GetCorrespondingTechnicalInnovationSectionResult(result, context); + + entity.LayerOne = Convert.ToByte(result.AssessmentLayerOne); + entity.LayerThree = Convert.ToDecimal(result.AssessmentLayerThree); + + registry.Register(entity, result); + } + + private static TechnicalInnovationSectionResultEntity GetCorrespondingTechnicalInnovationSectionResult(TechnicalInnovationFailureMechanismSectionResult result, IRingtoetsEntities context) + { + try + { + return context.TechnicalInnovationSectionResultEntities.Single(sle => sle.TechnicalInnovationSectionResultEntityId == result.StorageId); + } + catch (InvalidOperationException exception) + { + throw new EntityNotFoundException(string.Format(Resources.Error_Entity_Not_Found_0_1, typeof(TechnicalInnovationSectionResultEntity).Name, result.StorageId), exception); + } + } + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Update/TechnicalInnovationFailureMechanismUpdateExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Update/TechnicalInnovationFailureMechanismUpdateExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Update/TechnicalInnovationFailureMechanismUpdateExtensions.cs (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -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 TechnicalInnovationFailureMechanismUpdateExtensions + { + /// + /// 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 TechnicalInnovationFailureMechanism 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(TechnicalInnovationFailureMechanism mechanism, PersistenceRegistry registry, IRingtoetsEntities context) + { + foreach (var sectionResult in mechanism.SectionResults) + { + if (sectionResult.IsNew()) + { + registry.Get(sectionResult.Section).TechnicalInnovationSectionResultEntities.Add(sectionResult.Create(registry)); + } + else + { + sectionResult.Update(registry, context); + } + } + } + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Update/WaterPressureAsphaltCoverFailureMechanismSectionResultUpdateExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Update/WaterPressureAsphaltCoverFailureMechanismSectionResultUpdateExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Update/WaterPressureAsphaltCoverFailureMechanismSectionResultUpdateExtensions.cs (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -0,0 +1,83 @@ +// 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 WaterPressureAsphaltCoverFailureMechanismSectionResultUpdateExtensions + { + /// + /// 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 WaterPressureAsphaltCoverFailureMechanismSectionResult result, PersistenceRegistry registry, IRingtoetsEntities context) + { + if (context == null) + { + throw new ArgumentNullException("context"); + } + if (registry == null) + { + throw new ArgumentNullException("registry"); + } + + WaterPressureAsphaltCoverSectionResultEntity entity = GetCorrespondingWaterPressureAsphaltCoverSectionResult(result, context); + + entity.LayerOne = Convert.ToByte(result.AssessmentLayerOne); + entity.LayerThree = Convert.ToDecimal(result.AssessmentLayerThree); + + registry.Register(entity, result); + } + + private static WaterPressureAsphaltCoverSectionResultEntity GetCorrespondingWaterPressureAsphaltCoverSectionResult(WaterPressureAsphaltCoverFailureMechanismSectionResult result, IRingtoetsEntities context) + { + try + { + return context.WaterPressureAsphaltCoverSectionResultEntities.Single(sle => sle.WaterPressureAsphaltCoverSectionResultEntityId == result.StorageId); + } + catch (InvalidOperationException exception) + { + throw new EntityNotFoundException(string.Format(Resources.Error_Entity_Not_Found_0_1, typeof(WaterPressureAsphaltCoverSectionResultEntity).Name, result.StorageId), exception); + } + } + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Update/WaterPressureAsphaltCoverFailureMechanismUpdateExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Update/WaterPressureAsphaltCoverFailureMechanismUpdateExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Update/WaterPressureAsphaltCoverFailureMechanismUpdateExtensions.cs (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -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 WaterPressureAsphaltCoverFailureMechanismUpdateExtensions + { + /// + /// 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 WaterPressureAsphaltCoverFailureMechanism 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(WaterPressureAsphaltCoverFailureMechanism mechanism, PersistenceRegistry registry, IRingtoetsEntities context) + { + foreach (var sectionResult in mechanism.SectionResults) + { + if (sectionResult.IsNew()) + { + registry.Get(sectionResult.Section).WaterPressureAsphaltCoverSectionResultEntities.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 -rebad637e9483d348a5efe2fe902d56aa91bf6a31 -r2fe46c62134fde70ada240fa952971444177be90 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision ebad637e9483d348a5efe2fe902d56aa91bf6a31) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -82,6 +82,10 @@ + + + + @@ -111,6 +115,8 @@ + + @@ -142,6 +148,10 @@ + + + + Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs =================================================================== diff -u -rebad637e9483d348a5efe2fe902d56aa91bf6a31 -r2fe46c62134fde70ada240fa952971444177be90 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs (.../PersistenceRegistryTest.cs) (revision ebad637e9483d348a5efe2fe902d56aa91bf6a31) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs (.../PersistenceRegistryTest.cs) (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -993,6 +993,62 @@ } [Test] + public void Register_WithNullTechnicalInnovationFailureMechanismSectionResult_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => registry.Register(new TechnicalInnovationSectionResultEntity(), null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + + [Test] + public void Register_WithNullTechnicalInnovationSectionResultEntity_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => registry.Register(null, new TechnicalInnovationFailureMechanismSectionResult(new TestFailureMechanismSection())); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Register_WithNullWaterPressureAsphaltCoverFailureMechanismSectionResult_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => registry.Register(new WaterPressureAsphaltCoverSectionResultEntity(), null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + + [Test] + public void Register_WithNullWaterPressureAsphaltCoverSectionResultEntity_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => registry.Register(null, new WaterPressureAsphaltCoverFailureMechanismSectionResult(new TestFailureMechanismSection())); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] public void Register_WithNullHydraulicLocationEntity_ThrowsArgumentNullException() { // Setup @@ -1524,6 +1580,48 @@ } [Test] + public void TransferIds_WithTechnicalInnovationSectionResultEntityAddedWithTechnicalInnovationFailureMechanismSectionResult_EqualTechnicalInnovationSectionEntityIdAndTechnicalInnovationFailureMechanismSectionResultStorageId() + { + // Setup + var registry = new PersistenceRegistry(); + + long storageId = new Random(21).Next(1,4000); + var entity = new TechnicalInnovationSectionResultEntity() + { + TechnicalInnovationSectionResultEntityId = storageId + }; + var model = new TechnicalInnovationFailureMechanismSectionResult(new TestFailureMechanismSection()); + registry.Register(entity, model); + + // Call + registry.TransferIds(); + + // Assert + Assert.AreEqual(storageId, model.StorageId); + } + + [Test] + public void TransferIds_WithWaterPressureAsphaltCoverSectionResultEntityAddedWithWaterPressureAsphaltCoverFailureMechanismSectionResult_EqualWaterPressureAsphaltCoverSectionEntityIdAndWaterPressureAsphaltCoverFailureMechanismSectionResultStorageId() + { + // Setup + var registry = new PersistenceRegistry(); + + long storageId = new Random(21).Next(1,4000); + var entity = new WaterPressureAsphaltCoverSectionResultEntity() + { + WaterPressureAsphaltCoverSectionResultEntityId = storageId + }; + var model = new WaterPressureAsphaltCoverFailureMechanismSectionResult(new TestFailureMechanismSection()); + registry.Register(entity, model); + + // Call + registry.TransferIds(); + + // Assert + Assert.AreEqual(storageId, model.StorageId); + } + + [Test] public void TransferIds_WithHydraulicLocationEntityAdded_EqualHydraulicLocationEntityIdAndHydraulicBoundaryLocationStorageId() { // Setup @@ -2057,6 +2155,78 @@ } [Test] + public void RemoveUntouched_TechnicalInnovationSectionResultEntity_OrphanedEntityIsRemovedFromRingtoetsEntities() + { + // Setup + var mocks = new MockRepository(); + IRingtoetsEntities dbContext = RingtoetsEntitiesHelper.CreateStub(mocks); + mocks.ReplayAll(); + + var orphanedEntity = new TechnicalInnovationSectionResultEntity + { + TechnicalInnovationSectionResultEntityId = 1 + }; + var persistentEntity = new TechnicalInnovationSectionResultEntity + { + TechnicalInnovationSectionResultEntityId = 2 + }; + dbContext.TechnicalInnovationSectionResultEntities.Add(orphanedEntity); + dbContext.TechnicalInnovationSectionResultEntities.Add(persistentEntity); + + var section = new TechnicalInnovationFailureMechanismSectionResult(new TestFailureMechanismSection()) + { + StorageId = persistentEntity.TechnicalInnovationSectionResultEntityId + }; + + var registry = new PersistenceRegistry(); + registry.Register(persistentEntity, section); + + // Call + registry.RemoveUntouched(dbContext); + + // Assert + Assert.AreEqual(1, dbContext.TechnicalInnovationSectionResultEntities.Count()); + CollectionAssert.Contains(dbContext.TechnicalInnovationSectionResultEntities, persistentEntity); + mocks.VerifyAll(); + } + + [Test] + public void RemoveUntouched_WaterPressureAsphaltCoverSectionResultEntity_OrphanedEntityIsRemovedFromRingtoetsEntities() + { + // Setup + var mocks = new MockRepository(); + IRingtoetsEntities dbContext = RingtoetsEntitiesHelper.CreateStub(mocks); + mocks.ReplayAll(); + + var orphanedEntity = new WaterPressureAsphaltCoverSectionResultEntity + { + WaterPressureAsphaltCoverSectionResultEntityId = 1 + }; + var persistentEntity = new WaterPressureAsphaltCoverSectionResultEntity + { + WaterPressureAsphaltCoverSectionResultEntityId = 2 + }; + dbContext.WaterPressureAsphaltCoverSectionResultEntities.Add(orphanedEntity); + dbContext.WaterPressureAsphaltCoverSectionResultEntities.Add(persistentEntity); + + var section = new WaterPressureAsphaltCoverFailureMechanismSectionResult(new TestFailureMechanismSection()) + { + StorageId = persistentEntity.WaterPressureAsphaltCoverSectionResultEntityId + }; + + var registry = new PersistenceRegistry(); + registry.Register(persistentEntity, section); + + // Call + registry.RemoveUntouched(dbContext); + + // Assert + Assert.AreEqual(1, dbContext.WaterPressureAsphaltCoverSectionResultEntities.Count()); + CollectionAssert.Contains(dbContext.WaterPressureAsphaltCoverSectionResultEntities, persistentEntity); + mocks.VerifyAll(); + } + + [Test] public void RemoveUntouched_HydraulicLocationEntity_OrphanedEntityIsRemovedFromRingtoetsEntities() { // Setup Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/TechnicalInnovationFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/TechnicalInnovationFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/TechnicalInnovationFailureMechanismCreateExtensionsTest.cs (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -0,0 +1,104 @@ +// 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 Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Integration.Data.StandAlone; + +namespace Application.Ringtoets.Storage.Test.Create +{ + [TestFixture] + public class TechnicalInnovationFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_WithoutPersistenceRegistry_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new TechnicalInnovationFailureMechanism(); + + // 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 TechnicalInnovationFailureMechanism + { + IsRelevant = isRelevant, + Comments = "Some text" + }; + var registry = new PersistenceRegistry(); + + // Call + var entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short)FailureMechanismType.TechnicalInnovations, 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 TechnicalInnovationFailureMechanism(); + + // Call + var entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.IsEmpty(entity.FailureMechanismSectionEntities); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + var failureMechanism = new TechnicalInnovationFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("", new[] + { + new Point2D(0, 0) + })); + + // Call + var entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.TechnicalInnovationSectionResultEntities).Count()); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/TechnicalInnovationFailureMechanismSectionResultCreateExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/TechnicalInnovationFailureMechanismSectionResultCreateExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/TechnicalInnovationFailureMechanismSectionResultCreateExtensionsTest.cs (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -0,0 +1,81 @@ +// 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 Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Integration.Data.StandAlone.SectionResults; + +namespace Application.Ringtoets.Storage.Test.Create +{ + [TestFixture] + public class TechnicalInnovationFailureMechanismSectionResultCreateExtensionsTest + { + [Test] + public void Create_WithoutPersistenceRegistry_ThrowsArgumentNullException() + { + // Setup + var sectionResult = new TechnicalInnovationFailureMechanismSectionResult(new FailureMechanismSection("", new[] { new Point2D(0, 0) })); + + // Call + TestDelegate test = () => sectionResult.Create(null); + + // Assert + Assert.Throws(test); + } + + [Test] + public void Create_WithDifferentResults_ReturnsEntityWithExpectedResults( + [Values(true, false)] bool assessmentLayerOneResult, + [Values(3.2, 4.5)] double assessmentLayerThreeResult + ) + { + // Setup + var sectionResult = new TechnicalInnovationFailureMechanismSectionResult(new FailureMechanismSection("", new[] { new Point2D(0, 0) })); + sectionResult.AssessmentLayerOne = assessmentLayerOneResult; + sectionResult.AssessmentLayerThree = (RoundedDouble) assessmentLayerThreeResult; + + // Call + var result = sectionResult.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(Convert.ToByte(assessmentLayerOneResult), result.LayerOne); + Assert.AreEqual(Convert.ToDecimal(assessmentLayerThreeResult), result.LayerThree); + } + + [Test] + public void Create_WithNaNLevel3Result_ReturnsEntityWithExpectedResults() + { + // Setup + var sectionResult = new TechnicalInnovationFailureMechanismSectionResult(new FailureMechanismSection("", new[] { new Point2D(0, 0) })); + 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/WaterPressureAsphaltCoverFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/WaterPressureAsphaltCoverFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/WaterPressureAsphaltCoverFailureMechanismCreateExtensionsTest.cs (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -0,0 +1,104 @@ +// 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 Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Integration.Data.StandAlone; + +namespace Application.Ringtoets.Storage.Test.Create +{ + [TestFixture] + public class WaterPressureAsphaltCoverFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_WithoutPersistenceRegistry_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new WaterPressureAsphaltCoverFailureMechanism(); + + // 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 WaterPressureAsphaltCoverFailureMechanism + { + IsRelevant = isRelevant, + Comments = "Some text" + }; + var registry = new PersistenceRegistry(); + + // Call + var entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short)FailureMechanismType.WaterOverpressureAsphaltRevetment, 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 WaterPressureAsphaltCoverFailureMechanism(); + + // Call + var entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.IsEmpty(entity.FailureMechanismSectionEntities); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + var failureMechanism = new WaterPressureAsphaltCoverFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("", new[] + { + new Point2D(0, 0) + })); + + // Call + var entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.WaterPressureAsphaltCoverSectionResultEntities).Count()); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/WaterPressureAsphaltCoverFailureMechanismSectionResultCreateExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/WaterPressureAsphaltCoverFailureMechanismSectionResultCreateExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/WaterPressureAsphaltCoverFailureMechanismSectionResultCreateExtensionsTest.cs (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -0,0 +1,81 @@ +// 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 Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Integration.Data.StandAlone.SectionResults; + +namespace Application.Ringtoets.Storage.Test.Create +{ + [TestFixture] + public class WaterPressureAsphaltCoverFailureMechanismSectionResultCreateExtensionsTest + { + [Test] + public void Create_WithoutPersistenceRegistry_ThrowsArgumentNullException() + { + // Setup + var sectionResult = new WaterPressureAsphaltCoverFailureMechanismSectionResult(new FailureMechanismSection("", new[] { new Point2D(0, 0) })); + + // Call + TestDelegate test = () => sectionResult.Create(null); + + // Assert + Assert.Throws(test); + } + + [Test] + public void Create_WithDifferentResults_ReturnsEntityWithExpectedResults( + [Values(true, false)] bool assessmentLayerOneResult, + [Values(3.2, 4.5)] double assessmentLayerThreeResult + ) + { + // Setup + var sectionResult = new WaterPressureAsphaltCoverFailureMechanismSectionResult(new FailureMechanismSection("", new[] { new Point2D(0, 0) })); + sectionResult.AssessmentLayerOne = assessmentLayerOneResult; + sectionResult.AssessmentLayerThree = (RoundedDouble) assessmentLayerThreeResult; + + // Call + var result = sectionResult.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(Convert.ToByte(assessmentLayerOneResult), result.LayerOne); + Assert.AreEqual(Convert.ToDecimal(assessmentLayerThreeResult), result.LayerThree); + } + + [Test] + public void Create_WithNaNLevel3Result_ReturnsEntityWithExpectedResults() + { + // Setup + var sectionResult = new WaterPressureAsphaltCoverFailureMechanismSectionResult(new FailureMechanismSection("", new[] { new Point2D(0, 0) })); + 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/IntegrationTests/StorageSqLiteIntegrationTest.cs =================================================================== diff -u -rebad637e9483d348a5efe2fe902d56aa91bf6a31 -r2fe46c62134fde70ada240fa952971444177be90 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/IntegrationTests/StorageSqLiteIntegrationTest.cs (.../StorageSqLiteIntegrationTest.cs) (revision ebad637e9483d348a5efe2fe902d56aa91bf6a31) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/IntegrationTests/StorageSqLiteIntegrationTest.cs (.../StorageSqLiteIntegrationTest.cs) (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -266,6 +266,12 @@ AssertFailureMechanismSectionResults( expectedAssessmentSection.StrengthStabilityLengthwiseConstruction.SectionResults, actualAssessmentSection.StrengthStabilityLengthwiseConstruction.SectionResults); + AssertFailureMechanismSectionResults( + expectedAssessmentSection.TechnicalInnovation.SectionResults, + actualAssessmentSection.TechnicalInnovation.SectionResults); + AssertFailureMechanismSectionResults( + expectedAssessmentSection.WaterPressureAsphaltCover.SectionResults, + actualAssessmentSection.WaterPressureAsphaltCover.SectionResults); } } @@ -339,6 +345,40 @@ } } + 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++) + { + TechnicalInnovationFailureMechanismSectionResult expectedSection = expectedSectionResultsArray[i]; + TechnicalInnovationFailureMechanismSectionResult actualSection = actualSectionResultsArray[i]; + + Assert.AreEqual(expectedSection.AssessmentLayerOne, actualSection.AssessmentLayerOne); + Assert.AreEqual(expectedSection.AssessmentLayerThree, actualSection.AssessmentLayerThree); + } + } + + 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++) + { + WaterPressureAsphaltCoverFailureMechanismSectionResult expectedSection = expectedSectionResultsArray[i]; + WaterPressureAsphaltCoverFailureMechanismSectionResult actualSection = actualSectionResultsArray[i]; + + Assert.AreEqual(expectedSection.AssessmentLayerOne, actualSection.AssessmentLayerOne); + 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/TechnicalInnovationSectionResultEntityReadExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/TechnicalInnovationSectionResultEntityReadExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/TechnicalInnovationSectionResultEntityReadExtensionsTest.cs (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -0,0 +1,101 @@ +// 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.Test.Update; +using NUnit.Framework; + +namespace Application.Ringtoets.Storage.Test.Read +{ + [TestFixture] + public class TechnicalInnovationSectionResultEntityReadExtensionsTest + { + [Test] + public void Read_CollectorIsNull_ThrowArgumentNullException() + { + // Setup + var entity = new TechnicalInnovationSectionResultEntity(); + + // 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_ReturnTechnicalInnovationSoilLayerWithDoubleParameterValues(bool layerOne) + { + // Setup + var random = new Random(21); + var entityId = random.Next(1, 502); + double layerThree = random.NextDouble(); + var collector = new ReadConversionCollector(); + + var failureMechanismSectionEntity = new FailureMechanismSectionEntity(); + collector.Read(failureMechanismSectionEntity, new TestFailureMechanismSection()); + var entity = new TechnicalInnovationSectionResultEntity + { + TechnicalInnovationSectionResultEntityId = entityId, + LayerThree = Convert.ToDecimal(layerThree), + 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(layerThree, result.AssessmentLayerThree, 1e-6); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Read_WithNullParameterValues_ReturnTechnicalInnovationSoilLayerWithNullParameters(bool layerOne) + { + // Setup + var collector = new ReadConversionCollector(); + var failureMechanismSectionEntity = new FailureMechanismSectionEntity(); + collector.Read(failureMechanismSectionEntity, new TestFailureMechanismSection()); + var entity = new TechnicalInnovationSectionResultEntity + { + LayerOne = Convert.ToByte(layerOne), + 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/Read/WaterPressureAsphaltCoverSectionResultEntityReadExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/WaterPressureAsphaltCoverSectionResultEntityReadExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/WaterPressureAsphaltCoverSectionResultEntityReadExtensionsTest.cs (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -0,0 +1,101 @@ +// 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.Test.Update; +using NUnit.Framework; + +namespace Application.Ringtoets.Storage.Test.Read +{ + [TestFixture] + public class WaterPressureAsphaltCoverSectionResultEntityReadExtensionsTest + { + [Test] + public void Read_CollectorIsNull_ThrowArgumentNullException() + { + // Setup + var entity = new WaterPressureAsphaltCoverSectionResultEntity(); + + // 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_ReturnWaterPressureAsphaltCoverSoilLayerWithDoubleParameterValues(bool layerOne) + { + // Setup + var random = new Random(21); + var entityId = random.Next(1, 502); + double layerThree = random.NextDouble(); + var collector = new ReadConversionCollector(); + + var failureMechanismSectionEntity = new FailureMechanismSectionEntity(); + collector.Read(failureMechanismSectionEntity, new TestFailureMechanismSection()); + var entity = new WaterPressureAsphaltCoverSectionResultEntity + { + WaterPressureAsphaltCoverSectionResultEntityId = entityId, + LayerThree = Convert.ToDecimal(layerThree), + 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(layerThree, result.AssessmentLayerThree, 1e-6); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Read_WithNullParameterValues_ReturnWaterPressureAsphaltCoverSoilLayerWithNullParameters(bool layerOne) + { + // Setup + var collector = new ReadConversionCollector(); + var failureMechanismSectionEntity = new FailureMechanismSectionEntity(); + collector.Read(failureMechanismSectionEntity, new TestFailureMechanismSection()); + var entity = new WaterPressureAsphaltCoverSectionResultEntity + { + LayerOne = Convert.ToByte(layerOne), + 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/TechnicalInnovationFailureMechanismSectionResultUpdateExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/TechnicalInnovationFailureMechanismSectionResultUpdateExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/TechnicalInnovationFailureMechanismSectionResultUpdateExtensionsTest.cs (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -0,0 +1,159 @@ +// 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 TechnicalInnovationFailureMechanismSectionResultUpdateExtensionsTest + { + [Test] + public void Update_WithoutContext_ArgumentNullException() + { + // Setup + var sectionResult = new TechnicalInnovationFailureMechanismSectionResult(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 TechnicalInnovationFailureMechanismSectionResult(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_ContextWithNoTechnicalInnovationSoilLayer_EntityNotFoundException() + { + // Setup + var sectionResult = new TechnicalInnovationFailureMechanismSectionResult(new TestFailureMechanismSection()); + + // Call + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + sectionResult.Update(new PersistenceRegistry(), ringtoetsEntities); + } + }; + + // Assert + var expectedMessage = String.Format("Het object 'TechnicalInnovationSectionResultEntity' met id '{0}' is niet gevonden.", 0); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + } + + [Test] + public void Update_ContextWithNoTechnicalInnovationSoilLayerWithId_EntityNotFoundException() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.CreateStub(mocks); + + mocks.ReplayAll(); + + var storageId = 1; + var sectionResult = new TechnicalInnovationFailureMechanismSectionResult(new TestFailureMechanismSection()) + { + StorageId = storageId + }; + + ringtoetsEntities.TechnicalInnovationSectionResultEntities.Add(new TechnicalInnovationSectionResultEntity + { + TechnicalInnovationSectionResultEntityId = 2 + }); + + // Call + TestDelegate test = () => sectionResult.Update(new PersistenceRegistry(), ringtoetsEntities); + + // Assert + var expectedMessage = String.Format("Het object 'TechnicalInnovationSectionResultEntity' met id '{0}' is niet gevonden.", storageId); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + + mocks.VerifyAll(); + } + + [Test] + public void Update_WithTechnicalInnovationSoilLayer_PropertiesUpdated() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.CreateStub(mocks); + + mocks.ReplayAll(); + + var sectionResult = new TechnicalInnovationFailureMechanismSectionResult(new TestFailureMechanismSection()) + { + StorageId = 1, + AssessmentLayerOne = true, + AssessmentLayerThree = (RoundedDouble) 4.4 + }; + + var sectionResultEntity = new TechnicalInnovationSectionResultEntity + { + TechnicalInnovationSectionResultEntityId = sectionResult.StorageId, + LayerOne = Convert.ToByte(false), + LayerThree = 1.1m, + }; + + ringtoetsEntities.TechnicalInnovationSectionResultEntities.Add(sectionResultEntity); + + // Call + sectionResult.Update(new PersistenceRegistry(), ringtoetsEntities); + + // Assert + Assert.AreEqual(Convert.ToByte(true), sectionResultEntity.LayerOne); + 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/TechnicalInnovationFailureMechanismUpdateExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/TechnicalInnovationFailureMechanismUpdateExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/TechnicalInnovationFailureMechanismUpdateExtensionsTest.cs (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -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 TechnicalInnovationFailureMechanismUpdateExtensionsTest + { + [Test] + public void Update_WithoutContext_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new TechnicalInnovationFailureMechanism(); + + // 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 TechnicalInnovationFailureMechanism(); + + // 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_ContextWithNoTechnicalInnovationFailureMechanism_ThrowsEntityNotFoundException() + { + // Setup + var failureMechanism = new TechnicalInnovationFailureMechanism(); + + // 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_ContextWithNoTechnicalInnovationFailureMechanismWithId_ThrowsEntityNotFoundException() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.CreateStub(mocks); + + mocks.ReplayAll(); + + var storageId = 1; + var failureMechanism = new TechnicalInnovationFailureMechanism + { + 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_ContextWithTechnicalInnovationFailureMechanism_PropertiesUpdated() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.CreateStub(mocks); + + mocks.ReplayAll(); + + var failureMechanism = new TechnicalInnovationFailureMechanism + { + 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 TechnicalInnovationFailureMechanism + { + 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.TechnicalInnovationSectionResultEntities).Count()); + + mocks.VerifyAll(); + } + + [Test] + public void Update_ContextWithUpdatedFailureMechanismSections_NoNewFailureMechanismSectionsAdded() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.CreateStub(mocks); + + mocks.ReplayAll(); + + var failureMechanism = new TechnicalInnovationFailureMechanism + { + 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.TechnicalInnovationSectionResultEntities).Count()); + Assert.AreEqual(testName, failureMechanismEntity.FailureMechanismSectionEntities.ElementAt(0).Name); + + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/WaterPressureAsphaltCoverFailureMechanismSectionResultUpdateExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/WaterPressureAsphaltCoverFailureMechanismSectionResultUpdateExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/WaterPressureAsphaltCoverFailureMechanismSectionResultUpdateExtensionsTest.cs (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -0,0 +1,159 @@ +// 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 WaterPressureAsphaltCoverFailureMechanismSectionResultUpdateExtensionsTest + { + [Test] + public void Update_WithoutContext_ArgumentNullException() + { + // Setup + var sectionResult = new WaterPressureAsphaltCoverFailureMechanismSectionResult(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 WaterPressureAsphaltCoverFailureMechanismSectionResult(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_ContextWithNoWaterPressureAsphaltCoverSoilLayer_EntityNotFoundException() + { + // Setup + var sectionResult = new WaterPressureAsphaltCoverFailureMechanismSectionResult(new TestFailureMechanismSection()); + + // Call + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + sectionResult.Update(new PersistenceRegistry(), ringtoetsEntities); + } + }; + + // Assert + var expectedMessage = String.Format("Het object 'WaterPressureAsphaltCoverSectionResultEntity' met id '{0}' is niet gevonden.", 0); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + } + + [Test] + public void Update_ContextWithNoWaterPressureAsphaltCoverSoilLayerWithId_EntityNotFoundException() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.CreateStub(mocks); + + mocks.ReplayAll(); + + var storageId = 1; + var sectionResult = new WaterPressureAsphaltCoverFailureMechanismSectionResult(new TestFailureMechanismSection()) + { + StorageId = storageId + }; + + ringtoetsEntities.WaterPressureAsphaltCoverSectionResultEntities.Add(new WaterPressureAsphaltCoverSectionResultEntity + { + WaterPressureAsphaltCoverSectionResultEntityId = 2 + }); + + // Call + TestDelegate test = () => sectionResult.Update(new PersistenceRegistry(), ringtoetsEntities); + + // Assert + var expectedMessage = String.Format("Het object 'WaterPressureAsphaltCoverSectionResultEntity' met id '{0}' is niet gevonden.", storageId); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + + mocks.VerifyAll(); + } + + [Test] + public void Update_WithWaterPressureAsphaltCoverSoilLayer_PropertiesUpdated() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.CreateStub(mocks); + + mocks.ReplayAll(); + + var sectionResult = new WaterPressureAsphaltCoverFailureMechanismSectionResult(new TestFailureMechanismSection()) + { + StorageId = 1, + AssessmentLayerOne = true, + AssessmentLayerThree = (RoundedDouble) 4.4 + }; + + var sectionResultEntity = new WaterPressureAsphaltCoverSectionResultEntity + { + WaterPressureAsphaltCoverSectionResultEntityId = sectionResult.StorageId, + LayerOne = Convert.ToByte(false), + LayerThree = 1.1m, + }; + + ringtoetsEntities.WaterPressureAsphaltCoverSectionResultEntities.Add(sectionResultEntity); + + // Call + sectionResult.Update(new PersistenceRegistry(), ringtoetsEntities); + + // Assert + Assert.AreEqual(Convert.ToByte(true), sectionResultEntity.LayerOne); + 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/WaterPressureAsphaltCoverFailureMechanismUpdateExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/WaterPressureAsphaltCoverFailureMechanismUpdateExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/WaterPressureAsphaltCoverFailureMechanismUpdateExtensionsTest.cs (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -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 WaterPressureAsphaltCoverFailureMechanismUpdateExtensionsTest + { + [Test] + public void Update_WithoutContext_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new WaterPressureAsphaltCoverFailureMechanism(); + + // 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 WaterPressureAsphaltCoverFailureMechanism(); + + // 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_ContextWithNoWaterPressureAsphaltCoverFailureMechanism_ThrowsEntityNotFoundException() + { + // Setup + var failureMechanism = new WaterPressureAsphaltCoverFailureMechanism(); + + // 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_ContextWithNoWaterPressureAsphaltCoverFailureMechanismWithId_ThrowsEntityNotFoundException() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.CreateStub(mocks); + + mocks.ReplayAll(); + + var storageId = 1; + var failureMechanism = new WaterPressureAsphaltCoverFailureMechanism + { + 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_ContextWithWaterPressureAsphaltCoverFailureMechanism_PropertiesUpdated() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.CreateStub(mocks); + + mocks.ReplayAll(); + + var failureMechanism = new WaterPressureAsphaltCoverFailureMechanism + { + 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 WaterPressureAsphaltCoverFailureMechanism + { + 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.WaterPressureAsphaltCoverSectionResultEntities).Count()); + + mocks.VerifyAll(); + } + + [Test] + public void Update_ContextWithUpdatedFailureMechanismSections_NoNewFailureMechanismSectionsAdded() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.CreateStub(mocks); + + mocks.ReplayAll(); + + var failureMechanism = new WaterPressureAsphaltCoverFailureMechanism + { + 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.WaterPressureAsphaltCoverSectionResultEntities).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 -rebad637e9483d348a5efe2fe902d56aa91bf6a31 -r2fe46c62134fde70ada240fa952971444177be90 --- Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/RingtoetsEntitiesHelper.cs (.../RingtoetsEntitiesHelper.cs) (revision ebad637e9483d348a5efe2fe902d56aa91bf6a31) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/RingtoetsEntitiesHelper.cs (.../RingtoetsEntitiesHelper.cs) (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -45,6 +45,8 @@ DbSet grassCoverErosionInwardsSectionResultsSet = CreateEmptyTestDbSet(); DbSet heightStructuresSectionResultsSet = CreateEmptyTestDbSet(); DbSet strengthStabilityLengthwiseConstructionSectionResultsSet = CreateEmptyTestDbSet(); + DbSet technicalInnovationSectionResultsSet = CreateEmptyTestDbSet(); + DbSet waterPressureAsphaltCoverSectionResultsSet = CreateEmptyTestDbSet(); DbSet assessmentSectionsSet = CreateEmptyTestDbSet(); DbSet referenceLinesSet = CreateEmptyTestDbSet(); DbSet calculationGroupsSet = CreateEmptyTestDbSet(); @@ -71,6 +73,8 @@ ringtoetsEntities.Stub(r => r.GrassCoverErosionInwardsSectionResultEntities).Return(grassCoverErosionInwardsSectionResultsSet); ringtoetsEntities.Stub(r => r.HeightStructuresSectionResultEntities).Return(heightStructuresSectionResultsSet); 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.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 -rebad637e9483d348a5efe2fe902d56aa91bf6a31 -r2fe46c62134fde70ada240fa952971444177be90 --- Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/RingtoetsProjectHelper.cs (.../RingtoetsProjectHelper.cs) (revision ebad637e9483d348a5efe2fe902d56aa91bf6a31) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/RingtoetsProjectHelper.cs (.../RingtoetsProjectHelper.cs) (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -222,6 +222,7 @@ AddSections(assessmentSection.StabilityStoneCover); AddSections(assessmentSection.WaveImpactAsphaltCover); AddSections(assessmentSection.WaterPressureAsphaltCover); + SetSectionResults(assessmentSection.WaterPressureAsphaltCover.SectionResults); AddSections(assessmentSection.GrassCoverErosionOutwards); AddSections(assessmentSection.GrassCoverSlipOffOutwards); AddSections(assessmentSection.GrassCoverSlipOffInwards); @@ -234,6 +235,7 @@ AddSections(assessmentSection.PipingStructure); AddSections(assessmentSection.DuneErosion); AddSections(assessmentSection.TechnicalInnovation); + SetSectionResults(assessmentSection.TechnicalInnovation.SectionResults); return fullTestProject; } @@ -278,6 +280,26 @@ } } + 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.AssessmentLayerThree = (RoundedDouble)random.NextDouble(); + } + } + + 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.AssessmentLayerThree = (RoundedDouble)random.NextDouble(); + } + } + private static void AddSections(IFailureMechanism failureMechanism) { failureMechanism.AddSection(new FailureMechanismSection("section 1", new[] Index: Ringtoets/Integration/src/Ringtoets.Integration.Data/StandAlone/SectionResults/TechnicalInnovationFailureMechanismSectionResult.cs =================================================================== diff -u -rf72f906a6875250a4378945ce814997ff8aaf1a7 -r2fe46c62134fde70ada240fa952971444177be90 --- Ringtoets/Integration/src/Ringtoets.Integration.Data/StandAlone/SectionResults/TechnicalInnovationFailureMechanismSectionResult.cs (.../TechnicalInnovationFailureMechanismSectionResult.cs) (revision f72f906a6875250a4378945ce814997ff8aaf1a7) +++ Ringtoets/Integration/src/Ringtoets.Integration.Data/StandAlone/SectionResults/TechnicalInnovationFailureMechanismSectionResult.cs (.../TechnicalInnovationFailureMechanismSectionResult.cs) (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -21,6 +21,7 @@ using System; using Core.Common.Base.Data; +using Core.Common.Base.Storage; using Ringtoets.Common.Data.FailureMechanism; namespace Ringtoets.Integration.Data.StandAlone.SectionResults @@ -29,7 +30,7 @@ /// This class holds information about the result of a calculation on section level for the /// Technical Innovations failure mechanism. /// - public class TechnicalInnovationFailureMechanismSectionResult : FailureMechanismSectionResult + public class TechnicalInnovationFailureMechanismSectionResult : FailureMechanismSectionResult, IStorable { /// /// Creates a new instance of . @@ -48,5 +49,7 @@ /// Gets or sets the value of the tailored assessment of safety. /// public RoundedDouble AssessmentLayerThree { get; set; } + + public long StorageId { get; set; } } } Index: Ringtoets/Integration/src/Ringtoets.Integration.Data/StandAlone/SectionResults/WaterPressureAsphaltCoverFailureMechanismSectionResult.cs =================================================================== diff -u -rf72f906a6875250a4378945ce814997ff8aaf1a7 -r2fe46c62134fde70ada240fa952971444177be90 --- Ringtoets/Integration/src/Ringtoets.Integration.Data/StandAlone/SectionResults/WaterPressureAsphaltCoverFailureMechanismSectionResult.cs (.../WaterPressureAsphaltCoverFailureMechanismSectionResult.cs) (revision f72f906a6875250a4378945ce814997ff8aaf1a7) +++ Ringtoets/Integration/src/Ringtoets.Integration.Data/StandAlone/SectionResults/WaterPressureAsphaltCoverFailureMechanismSectionResult.cs (.../WaterPressureAsphaltCoverFailureMechanismSectionResult.cs) (revision 2fe46c62134fde70ada240fa952971444177be90) @@ -21,6 +21,7 @@ using System; using Core.Common.Base.Data; +using Core.Common.Base.Storage; using Ringtoets.Common.Data.FailureMechanism; namespace Ringtoets.Integration.Data.StandAlone.SectionResults @@ -29,7 +30,7 @@ /// This class holds information about the result of a calculation on section level for the /// Water Pressure on Asphalt failure mechanism. /// - public class WaterPressureAsphaltCoverFailureMechanismSectionResult : FailureMechanismSectionResult + public class WaterPressureAsphaltCoverFailureMechanismSectionResult : FailureMechanismSectionResult, IStorable { /// /// Creates a new instance of . @@ -48,5 +49,7 @@ /// Gets or sets the value of the tailored assessment of safety. /// public RoundedDouble AssessmentLayerThree { get; set; } + + public long StorageId { get; set; } } }