Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj =================================================================== diff -u -r183d1e7ed095ea4e8024068bc4ddfcf3ac6997d3 -rbce62ec6102f15b0dbb1328fd9d14063fd21c978 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 183d1e7ed095ea4e8024068bc4ddfcf3ac6997d3) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision bce62ec6102f15b0dbb1328fd9d14063fd21c978) @@ -60,7 +60,6 @@ Properties\GlobalAssembly.cs - @@ -165,6 +164,7 @@ RingtoetsEntities.tt + RingtoetsEntities.tt @@ -174,6 +174,8 @@ RingtoetsEntities.tt + + RingtoetsEntities.tt @@ -264,6 +266,7 @@ + Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/CalculationGroupCreateExtensions.cs =================================================================== diff -u -r811967790aed0c6617f36c2135016a5bc4aa8fcc -rbce62ec6102f15b0dbb1328fd9d14063fd21c978 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/CalculationGroupCreateExtensions.cs (.../CalculationGroupCreateExtensions.cs) (revision 811967790aed0c6617f36c2135016a5bc4aa8fcc) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/CalculationGroupCreateExtensions.cs (.../CalculationGroupCreateExtensions.cs) (revision bce62ec6102f15b0dbb1328fd9d14063fd21c978) @@ -100,12 +100,12 @@ var childHeightStructuresCalculation = calculationBase as StructuresCalculation; if (childHeightStructuresCalculation != null) { - entity.HeightStructuresCalculationEntities.Add(childHeightStructuresCalculation.Create(registry, i)); + entity.HeightStructuresCalculationEntities.Add(childHeightStructuresCalculation.CreateForHeightStructures(registry, i)); } var childClosingStructuresCalculation = calculationBase as StructuresCalculation; if (childClosingStructuresCalculation != null) { - entity.ClosingStructuresCalculationEntities.Add(childClosingStructuresCalculation.Create(registry, i)); + entity.ClosingStructuresCalculationEntities.Add(childClosingStructuresCalculation.CreateForClosingStructures(registry, i)); } var stabilityStoneCoverWaveConditionsCalculation = calculationBase as StabilityStoneCoverWaveConditionsCalculation; if (stabilityStoneCoverWaveConditionsCalculation != null) Fisheye: Tag bce62ec6102f15b0dbb1328fd9d14063fd21c978 refers to a dead (removed) revision in file `Application/Ringtoets/src/Application.Ringtoets.Storage/Create/ClosingStructures/ClosingStructureCalculationCreateExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/StructuresCalculationCreateExtensions.cs =================================================================== diff -u -r183d1e7ed095ea4e8024068bc4ddfcf3ac6997d3 -rbce62ec6102f15b0dbb1328fd9d14063fd21c978 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/StructuresCalculationCreateExtensions.cs (.../StructuresCalculationCreateExtensions.cs) (revision 183d1e7ed095ea4e8024068bc4ddfcf3ac6997d3) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/StructuresCalculationCreateExtensions.cs (.../StructuresCalculationCreateExtensions.cs) (revision bce62ec6102f15b0dbb1328fd9d14063fd21c978) @@ -22,6 +22,8 @@ using System; using Application.Ringtoets.Storage.DbContext; using Core.Common.Utils.Extensions; +using Ringtoets.ClosingStructures.Data; +using Ringtoets.Common.Data; using Ringtoets.Common.Data.Structures; using Ringtoets.HeightStructures.Data; @@ -43,7 +45,7 @@ /// in its parent container. /// A new . /// Thrown when is null. - internal static HeightStructuresCalculationEntity Create(this StructuresCalculation calculation, PersistenceRegistry registry, int order) + internal static HeightStructuresCalculationEntity CreateForHeightStructures(this StructuresCalculation calculation, PersistenceRegistry registry, int order) { if (registry == null) { @@ -68,52 +70,134 @@ return entity; } - private static void SetInputValues(HeightStructuresCalculationEntity entity, HeightStructuresInput input, PersistenceRegistry registry) + /// + /// Creates a based + /// on the information of the . + /// + /// The calculation to create a database entity for. + /// The object keeping track of create operations. + /// The index at where resides + /// in its parent container. + /// A new . + /// Thrown when is null. + internal static ClosingStructuresCalculationEntity CreateForClosingStructures(this StructuresCalculation calculation, PersistenceRegistry registry, int order) { - if (input.HydraulicBoundaryLocation != null) + if (registry == null) { - entity.HydraulicLocationEntity = registry.Get(input.HydraulicBoundaryLocation); + throw new ArgumentNullException("registry"); } + + var entity = new ClosingStructuresCalculationEntity + { + Name = calculation.Name.DeepClone(), + Comments = calculation.Comments.DeepClone(), + Order = order + }; + SetInputValues(entity, calculation.InputParameters, registry); + + return entity; + } + + private static void SetInputValues(HeightStructuresCalculationEntity entity, HeightStructuresInput input, PersistenceRegistry registry) + { + input.Create(entity, registry); + if (input.Structure != null) { entity.HeightStructureEntity = registry.Get(input.Structure); } - if (input.ForeshoreProfile != null) + + entity.LevelCrestStructureMean = input.LevelCrestStructure.Mean.Value.ToNaNAsNull(); + entity.LevelCrestStructureStandardDeviation = input.LevelCrestStructure.StandardDeviation.Value.ToNaNAsNull(); + + entity.DeviationWaveDirection = input.DeviationWaveDirection.Value.ToNaNAsNull(); + } + + private static void SetInputValues(ClosingStructuresCalculationEntity entity, ClosingStructuresInput input, PersistenceRegistry registry) + { + input.Create(entity, registry); + + if (input.Structure != null) { - entity.ForeshoreProfileEntity = registry.Get(input.ForeshoreProfile); + entity.ClosingStructureEntity = registry.Get(input.Structure); } - entity.StructureNormalOrientation = input.StructureNormalOrientation.Value.ToNaNAsNull(); - entity.ModelFactorSuperCriticalFlowMean = input.ModelFactorSuperCriticalFlow.Mean.Value.ToNaNAsNull(); + entity.InflowModelType = Convert.ToByte(input.InflowModelType); - entity.AllowedLevelIncreaseStorageMean = input.AllowedLevelIncreaseStorage.Mean.Value.ToNaNAsNull(); - entity.AllowedLevelIncreaseStorageStandardDeviation = input.AllowedLevelIncreaseStorage.StandardDeviation.Value.ToNaNAsNull(); + entity.InsideWaterLevelMean = input.InsideWaterLevel.Mean.Value.ToNaNAsNull(); + entity.InsideWaterLevelStandardDeviation = input.InsideWaterLevel.StandardDeviation.Value.ToNaNAsNull(); - entity.StorageStructureAreaMean = input.StorageStructureArea.Mean.Value.ToNaNAsNull(); - entity.StorageStructureAreaCoefficientOfVariation = input.StorageStructureArea.CoefficientOfVariation.Value.ToNaNAsNull(); + entity.DeviationWaveDirection = input.DeviationWaveDirection.Value.ToNaNAsNull(); - entity.FlowWidthAtBottomProtectionMean = input.FlowWidthAtBottomProtection.Mean.Value.ToNaNAsNull(); - entity.FlowWidthAtBottomProtectionStandardDeviation = input.FlowWidthAtBottomProtection.StandardDeviation.Value.ToNaNAsNull(); + entity.DrainCoefficientMean = input.DrainCoefficient.Mean.Value.ToNaNAsNull(); - entity.CriticalOvertoppingDischargeMean = input.CriticalOvertoppingDischarge.Mean.Value.ToNaNAsNull(); - entity.CriticalOvertoppingDischargeCoefficientOfVariation = input.CriticalOvertoppingDischarge.CoefficientOfVariation.Value.ToNaNAsNull(); + entity.FactorStormDurationOpenStructure = input.FactorStormDurationOpenStructure.Value.ToNaNAsNull(); - entity.FailureProbabilityStructureWithErosion = input.FailureProbabilityStructureWithErosion; + entity.ThresholdHeightOpenWeirMean = input.ThresholdHeightOpenWeir.Mean.Value.ToNaNAsNull(); + entity.ThresholdHeightOpenWeirStandardDeviation = input.ThresholdHeightOpenWeir.StandardDeviation.Value.ToNaNAsNull(); - entity.WidthFlowAperturesMean = input.WidthFlowApertures.Mean.Value.ToNaNAsNull(); - entity.WidthFlowAperturesCoefficientOfVariation = input.WidthFlowApertures.CoefficientOfVariation.Value.ToNaNAsNull(); + entity.AreaFlowAperturesMean = input.AreaFlowApertures.Mean.Value.ToNaNAsNull(); + entity.AreaFlowAperturesStandardDeviation = input.AreaFlowApertures.StandardDeviation.Value.ToNaNAsNull(); - entity.StormDurationMean = input.StormDuration.Mean.Value.ToNaNAsNull(); + entity.FailureProbabilityOpenStructure = input.FailureProbabilityOpenStructure; - entity.LevelCrestStructureMean = input.LevelCrestStructure.Mean.Value.ToNaNAsNull(); - entity.LevelCrestStructureStandardDeviation = input.LevelCrestStructure.StandardDeviation.Value.ToNaNAsNull(); + entity.FailureProbablityReparation = input.FailureProbabilityReparation; - entity.DeviationWaveDirection = input.DeviationWaveDirection.Value.ToNaNAsNull(); + entity.IdenticalApertures = input.IdenticalApertures; - entity.BreakWaterHeight = input.BreakWater.Height.Value.ToNaNAsNull(); - entity.BreakWaterType = Convert.ToInt16(input.BreakWater.Type); - entity.UseBreakWater = Convert.ToByte(input.UseBreakWater); - entity.UseForeshore = Convert.ToByte(input.UseForeshore); + entity.LevelCrestStructureNotClosingMean = input.LevelCrestStructureNotClosing.Mean.Value.ToNaNAsNull(); + entity.LevelCrestStructureNotClosingStandardDeviation = input.LevelCrestStructureNotClosing.StandardDeviation.Value.ToNaNAsNull(); + + entity.ProbabilityOpenStructureBeforeFlooding = input.ProbabilityOpenStructureBeforeFlooding; } + + private static void Create(this StructuresInputBase input, IStructuresCalculationEntity entityToUpdate, PersistenceRegistry registry) + where T : StructureBase + { + if (entityToUpdate == null) + { + throw new ArgumentNullException("entityToUpdate"); + } + if (registry == null) + { + throw new ArgumentNullException("registry"); + } + + entityToUpdate.StormDurationMean = input.StormDuration.Mean.Value.ToNaNAsNull(); + entityToUpdate.StructureNormalOrientation = input.StructureNormalOrientation.Value.ToNaNAsNull(); + entityToUpdate.FailureProbabilityStructureWithErosion = input.FailureProbabilityStructureWithErosion; + + if (input.HydraulicBoundaryLocation != null) + { + entityToUpdate.HydraulicLocationEntity = registry.Get(input.HydraulicBoundaryLocation); + } + + if (input.ForeshoreProfile != null) + { + entityToUpdate.ForeshoreProfileEntity = registry.Get(input.ForeshoreProfile); + } + entityToUpdate.UseForeshore = Convert.ToByte(input.UseForeshore); + + entityToUpdate.UseBreakWater = Convert.ToByte(input.UseBreakWater); + entityToUpdate.BreakWaterType = Convert.ToInt16(input.BreakWater.Type); + entityToUpdate.BreakWaterHeight = input.BreakWater.Height.Value.ToNaNAsNull(); + + entityToUpdate.AllowedLevelIncreaseStorageMean = input.AllowedLevelIncreaseStorage.Mean.Value.ToNaNAsNull(); + entityToUpdate.AllowedLevelIncreaseStorageStandardDeviation = input.AllowedLevelIncreaseStorage.StandardDeviation.Value.ToNaNAsNull(); + + entityToUpdate.StorageStructureAreaMean = input.StorageStructureArea.Mean.Value.ToNaNAsNull(); + entityToUpdate.StorageStructureAreaCoefficientOfVariation = input.StorageStructureArea.CoefficientOfVariation.Value.ToNaNAsNull(); + + entityToUpdate.FlowWidthAtBottomProtectionMean = input.FlowWidthAtBottomProtection.Mean.Value.ToNaNAsNull(); + entityToUpdate.FlowWidthAtBottomProtectionStandardDeviation = input.FlowWidthAtBottomProtection.StandardDeviation.Value.ToNaNAsNull(); + + entityToUpdate.CriticalOvertoppingDischargeMean = input.CriticalOvertoppingDischarge.Mean.Value.ToNaNAsNull(); + entityToUpdate.CriticalOvertoppingDischargeCoefficientOfVariation = input.CriticalOvertoppingDischarge.CoefficientOfVariation.Value.ToNaNAsNull(); + + entityToUpdate.ModelFactorSuperCriticalFlowMean = input.ModelFactorSuperCriticalFlow.Mean.Value.ToNaNAsNull(); + + entityToUpdate.WidthFlowAperturesMean = input.WidthFlowApertures.Mean.Value.ToNaNAsNull(); + entityToUpdate.WidthFlowAperturesCoefficientOfVariation = input.WidthFlowApertures.CoefficientOfVariation.Value.ToNaNAsNull(); + } } } \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/IStructuresCalculationEntity.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/IStructuresCalculationEntity.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/IStructuresCalculationEntity.cs (revision bce62ec6102f15b0dbb1328fd9d14063fd21c978) @@ -0,0 +1,50 @@ +// 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; + +namespace Application.Ringtoets.Storage.DbContext +{ + public interface IStructuresCalculationEntity + { + Nullable ModelFactorSuperCriticalFlowMean { get; set; } + Nullable StructureNormalOrientation { get; set; } + Nullable AllowedLevelIncreaseStorageMean { get; set; } + Nullable AllowedLevelIncreaseStorageStandardDeviation { get; set; } + Nullable StorageStructureAreaMean { get; set; } + Nullable StorageStructureAreaCoefficientOfVariation { get; set; } + Nullable FlowWidthAtBottomProtectionMean { get; set; } + Nullable FlowWidthAtBottomProtectionStandardDeviation { get; set; } + Nullable CriticalOvertoppingDischargeMean { get; set; } + Nullable CriticalOvertoppingDischargeCoefficientOfVariation { get; set; } + double FailureProbabilityStructureWithErosion { get; set; } + Nullable WidthFlowAperturesMean { get; set; } + Nullable WidthFlowAperturesCoefficientOfVariation { get; set; } + Nullable StormDurationMean { get; set; } + byte UseBreakWater { get; set; } + byte UseForeshore { get; set; } + short BreakWaterType { get; set; } + Nullable BreakWaterHeight { get; set; } + + HydraulicLocationEntity HydraulicLocationEntity { get; set; } + ForeshoreProfileEntity ForeshoreProfileEntity { get; set; } + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/PartialClosingStructuresCalculationEntity.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/PartialClosingStructuresCalculationEntity.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/PartialClosingStructuresCalculationEntity.cs (revision bce62ec6102f15b0dbb1328fd9d14063fd21c978) @@ -0,0 +1,28 @@ +// 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. + +namespace Application.Ringtoets.Storage.DbContext +{ + public partial class ClosingStructuresCalculationEntity : IStructuresCalculationEntity + { + + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/PartialHeightStructuresCalculationEntity.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/PartialHeightStructuresCalculationEntity.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/PartialHeightStructuresCalculationEntity.cs (revision bce62ec6102f15b0dbb1328fd9d14063fd21c978) @@ -0,0 +1,28 @@ +// 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. + +namespace Application.Ringtoets.Storage.DbContext +{ + public partial class HeightStructuresCalculationEntity : IStructuresCalculationEntity + { + + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ClosingStructures/ClosingStructuresCalculationEntityReadExtensions.cs =================================================================== diff -u -r4b095752c115dd672400da5a4acc1560e4c9ce2c -rbce62ec6102f15b0dbb1328fd9d14063fd21c978 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ClosingStructures/ClosingStructuresCalculationEntityReadExtensions.cs (.../ClosingStructuresCalculationEntityReadExtensions.cs) (revision 4b095752c115dd672400da5a4acc1560e4c9ce2c) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ClosingStructures/ClosingStructuresCalculationEntityReadExtensions.cs (.../ClosingStructuresCalculationEntityReadExtensions.cs) (revision bce62ec6102f15b0dbb1328fd9d14063fd21c978) @@ -23,6 +23,7 @@ using Application.Ringtoets.Storage.DbContext; using Core.Common.Base.Data; using Ringtoets.ClosingStructures.Data; +using Ringtoets.Common.Data; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.Structures; @@ -62,50 +63,13 @@ private static void ReadInputParameters(ClosingStructuresInput inputParameters, ClosingStructuresCalculationEntity entity, ReadConversionCollector collector) { - ReadBaseStructuresInputParameters(inputParameters, entity, collector); - ReadClosingStructuresSpecificInputParameters(inputParameters, entity); - } - - private static void ReadBaseStructuresInputParameters(StructuresInputBase structuresInputBase, - ClosingStructuresCalculationEntity entity, - ReadConversionCollector collector) - { - if (entity.ForeshoreProfileEntity != null) - { - structuresInputBase.ForeshoreProfile = entity.ForeshoreProfileEntity.Read(collector); - } if (entity.ClosingStructureEntity != null) { - structuresInputBase.Structure = entity.ClosingStructureEntity.Read(collector); + inputParameters.Structure = entity.ClosingStructureEntity.Read(collector); } - if (entity.HydraulicLocationEntity != null) - { - structuresInputBase.HydraulicBoundaryLocation = entity.HydraulicLocationEntity.Read(collector); - } - structuresInputBase.StructureNormalOrientation = (RoundedDouble) entity.StructureNormalOrientation.ToNullAsNaN(); - structuresInputBase.ModelFactorSuperCriticalFlow.Mean = (RoundedDouble) entity.ModelFactorSuperCriticalFlowMean.ToNullAsNaN(); - structuresInputBase.AllowedLevelIncreaseStorage.Mean = (RoundedDouble) entity.AllowedLevelIncreaseStorageMean.ToNullAsNaN(); - structuresInputBase.AllowedLevelIncreaseStorage.StandardDeviation = (RoundedDouble) entity.AllowedLevelIncreaseStorageStandardDeviation.ToNullAsNaN(); - structuresInputBase.StorageStructureArea.Mean = (RoundedDouble) entity.StorageStructureAreaMean.ToNullAsNaN(); - structuresInputBase.StorageStructureArea.CoefficientOfVariation = (RoundedDouble) entity.StorageStructureAreaCoefficientOfVariation.ToNullAsNaN(); - structuresInputBase.FlowWidthAtBottomProtection.Mean = (RoundedDouble) entity.FlowWidthAtBottomProtectionMean.ToNullAsNaN(); - structuresInputBase.FlowWidthAtBottomProtection.StandardDeviation = (RoundedDouble) entity.FlowWidthAtBottomProtectionStandardDeviation.ToNullAsNaN(); - structuresInputBase.CriticalOvertoppingDischarge.Mean = (RoundedDouble) entity.CriticalOvertoppingDischargeMean.ToNullAsNaN(); - structuresInputBase.CriticalOvertoppingDischarge.CoefficientOfVariation = (RoundedDouble) entity.CriticalOvertoppingDischargeCoefficientOfVariation.ToNullAsNaN(); - structuresInputBase.FailureProbabilityStructureWithErosion = entity.FailureProbabilityStructureWithErosion; - structuresInputBase.WidthFlowApertures.Mean = (RoundedDouble) entity.WidthFlowAperturesMean.ToNullAsNaN(); - structuresInputBase.WidthFlowApertures.CoefficientOfVariation = (RoundedDouble) entity.WidthFlowAperturesCoefficientOfVariation.ToNullAsNaN(); - structuresInputBase.StormDuration.Mean = (RoundedDouble) entity.StormDurationMean.ToNullAsNaN(); + entity.Read(inputParameters, collector); - structuresInputBase.UseBreakWater = Convert.ToBoolean(entity.UseBreakWater); - structuresInputBase.BreakWater.Type = (BreakWaterType)entity.BreakWaterType; - structuresInputBase.BreakWater.Height = (RoundedDouble)entity.BreakWaterHeight.ToNullAsNaN(); - structuresInputBase.UseForeshore = Convert.ToBoolean(entity.UseForeshore); - } - - private static void ReadClosingStructuresSpecificInputParameters(ClosingStructuresInput inputParameters, ClosingStructuresCalculationEntity entity) - { inputParameters.InflowModelType = (ClosingStructureInflowModelType) entity.InflowModelType; inputParameters.InsideWaterLevel.Mean = (RoundedDouble) entity.InsideWaterLevelMean.ToNullAsNaN(); inputParameters.InsideWaterLevel.StandardDeviation = (RoundedDouble) entity.InsideWaterLevelStandardDeviation.ToNullAsNaN(); Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/HeightStructures/HeightStructuresCalculationEntityReadExtensions.cs =================================================================== diff -u -r04cb34562587c9b06345f2e639c57394e6a7d0a7 -rbce62ec6102f15b0dbb1328fd9d14063fd21c978 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/HeightStructures/HeightStructuresCalculationEntityReadExtensions.cs (.../HeightStructuresCalculationEntityReadExtensions.cs) (revision 04cb34562587c9b06345f2e639c57394e6a7d0a7) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/HeightStructures/HeightStructuresCalculationEntityReadExtensions.cs (.../HeightStructuresCalculationEntityReadExtensions.cs) (revision bce62ec6102f15b0dbb1328fd9d14063fd21c978) @@ -74,39 +74,16 @@ private static void ReadInputParameters(HeightStructuresInput inputParameters, HeightStructuresCalculationEntity entity, ReadConversionCollector collector) { - if (entity.ForeshoreProfileEntity != null) - { - inputParameters.ForeshoreProfile = entity.ForeshoreProfileEntity.Read(collector); - } if (entity.HeightStructureEntity != null) { inputParameters.Structure = entity.HeightStructureEntity.Read(collector); } - if (entity.HydraulicLocationEntity != null) - { - inputParameters.HydraulicBoundaryLocation = entity.HydraulicLocationEntity.Read(collector); - } - inputParameters.StructureNormalOrientation = (RoundedDouble) entity.StructureNormalOrientation.ToNullAsNaN(); - inputParameters.ModelFactorSuperCriticalFlow.Mean = (RoundedDouble) entity.ModelFactorSuperCriticalFlowMean.ToNullAsNaN(); - inputParameters.AllowedLevelIncreaseStorage.Mean = (RoundedDouble) entity.AllowedLevelIncreaseStorageMean.ToNullAsNaN(); - inputParameters.AllowedLevelIncreaseStorage.StandardDeviation = (RoundedDouble) entity.AllowedLevelIncreaseStorageStandardDeviation.ToNullAsNaN(); - inputParameters.StorageStructureArea.Mean = (RoundedDouble) entity.StorageStructureAreaMean.ToNullAsNaN(); - inputParameters.StorageStructureArea.CoefficientOfVariation = (RoundedDouble) entity.StorageStructureAreaCoefficientOfVariation.ToNullAsNaN(); - inputParameters.FlowWidthAtBottomProtection.Mean = (RoundedDouble) entity.FlowWidthAtBottomProtectionMean.ToNullAsNaN(); - inputParameters.FlowWidthAtBottomProtection.StandardDeviation = (RoundedDouble) entity.FlowWidthAtBottomProtectionStandardDeviation.ToNullAsNaN(); - inputParameters.CriticalOvertoppingDischarge.Mean = (RoundedDouble) entity.CriticalOvertoppingDischargeMean.ToNullAsNaN(); - inputParameters.CriticalOvertoppingDischarge.CoefficientOfVariation = (RoundedDouble) entity.CriticalOvertoppingDischargeCoefficientOfVariation.ToNullAsNaN(); - inputParameters.FailureProbabilityStructureWithErosion = entity.FailureProbabilityStructureWithErosion; - inputParameters.WidthFlowApertures.Mean = (RoundedDouble) entity.WidthFlowAperturesMean.ToNullAsNaN(); - inputParameters.WidthFlowApertures.CoefficientOfVariation = (RoundedDouble) entity.WidthFlowAperturesCoefficientOfVariation.ToNullAsNaN(); - inputParameters.StormDuration.Mean = (RoundedDouble)entity.StormDurationMean.ToNullAsNaN(); + entity.Read(inputParameters, collector); + inputParameters.LevelCrestStructure.Mean = (RoundedDouble) entity.LevelCrestStructureMean.ToNullAsNaN(); inputParameters.LevelCrestStructure.StandardDeviation = (RoundedDouble)entity.LevelCrestStructureStandardDeviation.ToNullAsNaN(); inputParameters.DeviationWaveDirection = (RoundedDouble) entity.DeviationWaveDirection.ToNullAsNaN(); - - inputParameters.UseBreakWater = Convert.ToBoolean(entity.UseBreakWater); - inputParameters.UseForeshore = Convert.ToBoolean(entity.UseForeshore); } } } \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/IStructureCalculationEntityReadExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/IStructureCalculationEntityReadExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/IStructureCalculationEntityReadExtensions.cs (revision bce62ec6102f15b0dbb1328fd9d14063fd21c978) @@ -0,0 +1,90 @@ +// 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.Common.Data; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Structures; + +namespace Application.Ringtoets.Storage.Read +{ + /// + /// This class defines extension methods for read operations for the common code + /// among all instances based on the . + /// + internal static class IStructureCalculationEntityReadExtensions + { + /// + /// Reads all the information from the entity and updated the given input object, + /// with the exception of the property. + /// + /// The type of structure residing in . + /// The entity. + /// The input object to update. + /// The object keeping track of read operations. + /// Thrown when + /// or is null. + public static void Read(this IStructuresCalculationEntity entity, + StructuresInputBase inputToUpdate, + ReadConversionCollector collector) where T : StructureBase + { + if (inputToUpdate == null) + { + throw new ArgumentNullException("inputToUpdate"); + } + if (collector == null) + { + throw new ArgumentNullException("collector"); + } + + if (entity.ForeshoreProfileEntity != null) + { + inputToUpdate.ForeshoreProfile = entity.ForeshoreProfileEntity.Read(collector); + } + if (entity.HydraulicLocationEntity != null) + { + inputToUpdate.HydraulicBoundaryLocation = entity.HydraulicLocationEntity.Read(collector); + } + + inputToUpdate.StructureNormalOrientation = (RoundedDouble) entity.StructureNormalOrientation.ToNullAsNaN(); + inputToUpdate.ModelFactorSuperCriticalFlow.Mean = (RoundedDouble) entity.ModelFactorSuperCriticalFlowMean.ToNullAsNaN(); + inputToUpdate.AllowedLevelIncreaseStorage.Mean = (RoundedDouble) entity.AllowedLevelIncreaseStorageMean.ToNullAsNaN(); + inputToUpdate.AllowedLevelIncreaseStorage.StandardDeviation = (RoundedDouble) entity.AllowedLevelIncreaseStorageStandardDeviation.ToNullAsNaN(); + inputToUpdate.StorageStructureArea.Mean = (RoundedDouble) entity.StorageStructureAreaMean.ToNullAsNaN(); + inputToUpdate.StorageStructureArea.CoefficientOfVariation = (RoundedDouble) entity.StorageStructureAreaCoefficientOfVariation.ToNullAsNaN(); + inputToUpdate.FlowWidthAtBottomProtection.Mean = (RoundedDouble) entity.FlowWidthAtBottomProtectionMean.ToNullAsNaN(); + inputToUpdate.FlowWidthAtBottomProtection.StandardDeviation = (RoundedDouble) entity.FlowWidthAtBottomProtectionStandardDeviation.ToNullAsNaN(); + inputToUpdate.CriticalOvertoppingDischarge.Mean = (RoundedDouble) entity.CriticalOvertoppingDischargeMean.ToNullAsNaN(); + inputToUpdate.CriticalOvertoppingDischarge.CoefficientOfVariation = (RoundedDouble) entity.CriticalOvertoppingDischargeCoefficientOfVariation.ToNullAsNaN(); + inputToUpdate.FailureProbabilityStructureWithErosion = entity.FailureProbabilityStructureWithErosion; + inputToUpdate.WidthFlowApertures.Mean = (RoundedDouble) entity.WidthFlowAperturesMean.ToNullAsNaN(); + inputToUpdate.WidthFlowApertures.CoefficientOfVariation = (RoundedDouble) entity.WidthFlowAperturesCoefficientOfVariation.ToNullAsNaN(); + inputToUpdate.StormDuration.Mean = (RoundedDouble) entity.StormDurationMean.ToNullAsNaN(); + + inputToUpdate.UseBreakWater = Convert.ToBoolean(entity.UseBreakWater); + inputToUpdate.BreakWater.Type = (BreakWaterType) entity.BreakWaterType; + inputToUpdate.BreakWater.Height = (RoundedDouble) entity.BreakWaterHeight.ToNullAsNaN(); + inputToUpdate.UseForeshore = Convert.ToBoolean(entity.UseForeshore); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj =================================================================== diff -u -r183d1e7ed095ea4e8024068bc4ddfcf3ac6997d3 -rbce62ec6102f15b0dbb1328fd9d14063fd21c978 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 183d1e7ed095ea4e8024068bc4ddfcf3ac6997d3) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision bce62ec6102f15b0dbb1328fd9d14063fd21c978) @@ -77,7 +77,6 @@ Properties\GlobalAssembly.cs - @@ -105,6 +104,7 @@ + Fisheye: Tag bce62ec6102f15b0dbb1328fd9d14063fd21c978 refers to a dead (removed) revision in file `Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/ClosingStructures/ClosingStructureCalculationCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/StructuresCalculationCreateExtensionsTest.cs =================================================================== diff -u -r183d1e7ed095ea4e8024068bc4ddfcf3ac6997d3 -rbce62ec6102f15b0dbb1328fd9d14063fd21c978 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/StructuresCalculationCreateExtensionsTest.cs (.../StructuresCalculationCreateExtensionsTest.cs) (revision 183d1e7ed095ea4e8024068bc4ddfcf3ac6997d3) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/StructuresCalculationCreateExtensionsTest.cs (.../StructuresCalculationCreateExtensionsTest.cs) (revision bce62ec6102f15b0dbb1328fd9d14063fd21c978) @@ -24,8 +24,11 @@ using Application.Ringtoets.Storage.DbContext; using Application.Ringtoets.Storage.TestUtil; using Core.Common.Base.Data; +using Core.Common.Base.Geometry; using Core.Common.TestUtil; using NUnit.Framework; +using Ringtoets.ClosingStructures.Data; +using Ringtoets.ClosingStructures.Data.TestUtil; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.Probability; using Ringtoets.Common.Data.Structures; @@ -38,14 +41,16 @@ [TestFixture] public class StructuresCalculationCreateExtensionsTest { + #region CreateForHeightStructures + [Test] - public void Create_PersistenceRegistryNull_ThrowArgumentNullException() + public void CreateForHeightStructures_PersistenceRegistryNull_ThrowArgumentNullException() { // Setup var calculation = new StructuresCalculation(); // Call - TestDelegate call = () => calculation.Create(null, 0); + TestDelegate call = () => calculation.CreateForHeightStructures(null, 0); // Assert string paramName = Assert.Throws(call).ParamName; @@ -55,7 +60,7 @@ [Test] [TestCase("I have no comments", null, 0, 827364)] [TestCase("I have a comment", "I am comment", 98, 231)] - public void Create_ValidCalculation_ReturnEntity(string name, string comments, int order, int randomSeed) + public void CreateForHeightStructures_ValidCalculation_ReturnEntity(string name, string comments, int order, int randomSeed) { // Setup var random = new Random(randomSeed); @@ -121,7 +126,7 @@ var registry = new PersistenceRegistry(); // Call - HeightStructuresCalculationEntity entity = calculation.Create(registry, order); + HeightStructuresCalculationEntity entity = calculation.CreateForHeightStructures(registry, order); // Assert Assert.AreEqual(0, entity.HeightStructuresCalculationEntityId); @@ -161,7 +166,7 @@ } [Test] - public void Create_NaNParameters_EntityWithNullFields() + public void CreateForHeightStructures_NaNParameters_EntityWithNullFields() { // Setup var calculation = new StructuresCalculation @@ -218,7 +223,7 @@ var registry = new PersistenceRegistry(); // Call - HeightStructuresCalculationEntity entity = calculation.Create(registry, 0); + HeightStructuresCalculationEntity entity = calculation.CreateForHeightStructures(registry, 0); // Assert Assert.IsNull(entity.StructureNormalOrientation); @@ -242,7 +247,7 @@ } [Test] - public void Create_StringPropertiesDoNotShareReference() + public void CreateForHeightStructures_StringPropertiesDoNotShareReference() { // Setup const string name = "A"; @@ -256,7 +261,7 @@ var registry = new PersistenceRegistry(); // Call - HeightStructuresCalculationEntity entity = calculation.Create(registry, 0); + HeightStructuresCalculationEntity entity = calculation.CreateForHeightStructures(registry, 0); // Assert Assert.AreNotSame(name, entity.Name, @@ -269,7 +274,7 @@ } [Test] - public void Create_CalculationWithAlreadySavedHydraulicBoundaryLocation_ReturnEntityWithHydraulicLocationEntity() + public void CreateForHeightStructures_CalculationWithAlreadySavedHydraulicBoundaryLocation_ReturnEntityWithHydraulicLocationEntity() { // Setup var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "A", 1, 1); @@ -286,14 +291,14 @@ registry.Register(hydraulicLocationEntity, hydraulicBoundaryLocation); // Call - HeightStructuresCalculationEntity entity = calculation.Create(registry, 0); + HeightStructuresCalculationEntity entity = calculation.CreateForHeightStructures(registry, 0); // Assert Assert.AreSame(hydraulicLocationEntity, entity.HydraulicLocationEntity); } [Test] - public void Create_CalculationWithAlreadySavedHeightStructure_ReturnEntityWithHeightStructureEntity() + public void CreateForHeightStructures_CalculationWithAlreadySavedHeightStructure_ReturnEntityWithHeightStructureEntity() { // Setup var heightStructure = new TestHeightStructure(); @@ -310,14 +315,14 @@ registry.Register(heightStructureEntity, heightStructure); // Call - HeightStructuresCalculationEntity entity = calculation.Create(registry, 0); + HeightStructuresCalculationEntity entity = calculation.CreateForHeightStructures(registry, 0); // Assert Assert.AreSame(heightStructureEntity, entity.HeightStructureEntity); } [Test] - public void Create_CalculationWithAlreadySavedForeshoreProfile_ReturnEntityWithForeshoreProfileEntity() + public void CreateForHeightStructures_CalculationWithAlreadySavedForeshoreProfile_ReturnEntityWithForeshoreProfileEntity() { // Setup var foreshoreProfile = new TestForeshoreProfile(); @@ -334,14 +339,14 @@ registry.Register(foreshoreProfileEntity, foreshoreProfile); // Call - HeightStructuresCalculationEntity entity = calculation.Create(registry, 0); + HeightStructuresCalculationEntity entity = calculation.CreateForHeightStructures(registry, 0); // Assert Assert.AreSame(foreshoreProfileEntity, entity.ForeshoreProfileEntity); } [Test] - public void Create_CalculationWithOutput_ReturnEntity() + public void CreateForHeightStructures_CalculationWithOutput_ReturnEntity() { // Setup var random = new Random(159); @@ -355,10 +360,351 @@ var registry = new PersistenceRegistry(); // Call - HeightStructuresCalculationEntity entity = calculation.Create(registry, 0); + HeightStructuresCalculationEntity entity = calculation.CreateForHeightStructures(registry, 0); // Assert Assert.AreEqual(1, entity.HeightStructuresOutputEntities.Count); } + + #endregion + + #region CreateForClosingStructures + + [Test] + public void CreateForClosingStructures_RegistryIsNull_ThrowArgumentNullException() + { + // Setup + var calculation = new StructuresCalculation(); + + // Call + TestDelegate call = () => calculation.CreateForClosingStructures(null, 0); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + public void CreateForClosingStructures_ValidCalculation_ReturnClosingStructuresCalculationEntity() + { + // Setup + var random = new Random(45); + var calculation = new StructuresCalculation + { + Name = "A", + Comments = "B", + InputParameters = + { + StormDuration = + { + Mean = (RoundedDouble) random.NextDouble(), + }, + StructureNormalOrientation = (RoundedDouble) random.NextDouble(), + FailureProbabilityStructureWithErosion = (RoundedDouble) random.NextDouble(), + UseForeshore = random.NextBoolean(), + UseBreakWater = random.NextBoolean(), + BreakWater = + { + Type = BreakWaterType.Dam, + Height = (RoundedDouble) random.NextDouble() + }, + AllowedLevelIncreaseStorage = + { + Mean = (RoundedDouble) random.NextDouble(), + StandardDeviation = (RoundedDouble) random.NextDouble() + }, + StorageStructureArea = + { + Mean = (RoundedDouble) random.NextDouble(), + CoefficientOfVariation = (RoundedDouble) random.NextDouble() + }, + FlowWidthAtBottomProtection = + { + Mean = (RoundedDouble) random.NextDouble(), + StandardDeviation = (RoundedDouble) random.NextDouble() + }, + CriticalOvertoppingDischarge = + { + Mean = (RoundedDouble) random.NextDouble(), + CoefficientOfVariation = (RoundedDouble) random.NextDouble() + }, + ModelFactorSuperCriticalFlow = + { + Mean = (RoundedDouble) random.NextDouble() + }, + WidthFlowApertures = + { + Mean = (RoundedDouble) random.NextDouble(), + CoefficientOfVariation = (RoundedDouble) random.NextDouble() + }, + InflowModelType = ClosingStructureInflowModelType.VerticalWall, + InsideWaterLevel = + { + Mean = (RoundedDouble) random.NextDouble(), + StandardDeviation = (RoundedDouble) random.NextDouble() + }, + DeviationWaveDirection = (RoundedDouble) random.NextDouble(), + DrainCoefficient = + { + Mean = (RoundedDouble) random.NextDouble() + }, + FactorStormDurationOpenStructure = (RoundedDouble) random.NextDouble(), + ThresholdHeightOpenWeir = + { + Mean = (RoundedDouble) random.NextDouble(), + StandardDeviation = (RoundedDouble) random.NextDouble() + }, + AreaFlowApertures = + { + Mean = (RoundedDouble) random.NextDouble(), + StandardDeviation = (RoundedDouble) random.NextDouble() + }, + FailureProbabilityOpenStructure = (RoundedDouble) random.NextDouble(), + FailureProbabilityReparation = (RoundedDouble) random.NextDouble(), + IdenticalApertures = random.Next(), + LevelCrestStructureNotClosing = + { + Mean = (RoundedDouble) random.NextDouble(), + StandardDeviation = (RoundedDouble) random.NextDouble() + }, + ProbabilityOpenStructureBeforeFlooding = (RoundedDouble) random.NextDouble() + } + }; + + var registry = new PersistenceRegistry(); + + const int order = 67; + + // Call + ClosingStructuresCalculationEntity entity = calculation.CreateForClosingStructures(registry, order); + + // Assert + Assert.AreEqual(calculation.Name, entity.Name); + Assert.AreEqual(calculation.Comments, entity.Comments); + + ClosingStructuresInput inputParameters = calculation.InputParameters; + Assert.AreEqual(inputParameters.StormDuration.Mean.Value, entity.StormDurationMean); + Assert.AreEqual(inputParameters.StructureNormalOrientation.Value, entity.StructureNormalOrientation); + Assert.AreEqual(inputParameters.FailureProbabilityStructureWithErosion, entity.FailureProbabilityStructureWithErosion); + Assert.IsNull(entity.ClosingStructureEntity); + Assert.IsNull(entity.HydraulicLocationEntity); + Assert.IsNull(entity.ForeshoreProfileEntity); + Assert.AreEqual(Convert.ToByte(inputParameters.UseForeshore), entity.UseForeshore); + Assert.AreEqual(Convert.ToByte(inputParameters.UseBreakWater), entity.UseBreakWater); + Assert.AreEqual(Convert.ToInt16(inputParameters.BreakWater.Type), entity.BreakWaterType); + Assert.AreEqual(inputParameters.BreakWater.Height.Value, entity.BreakWaterHeight); + Assert.AreEqual(inputParameters.AllowedLevelIncreaseStorage.Mean.Value, entity.AllowedLevelIncreaseStorageMean); + Assert.AreEqual(inputParameters.AllowedLevelIncreaseStorage.StandardDeviation.Value, entity.AllowedLevelIncreaseStorageStandardDeviation); + Assert.AreEqual(inputParameters.StorageStructureArea.Mean.Value, entity.StorageStructureAreaMean); + Assert.AreEqual(inputParameters.StorageStructureArea.CoefficientOfVariation.Value, entity.StorageStructureAreaCoefficientOfVariation); + Assert.AreEqual(inputParameters.FlowWidthAtBottomProtection.Mean.Value, entity.FlowWidthAtBottomProtectionMean); + Assert.AreEqual(inputParameters.FlowWidthAtBottomProtection.StandardDeviation.Value, entity.FlowWidthAtBottomProtectionStandardDeviation); + Assert.AreEqual(inputParameters.CriticalOvertoppingDischarge.Mean.Value, entity.CriticalOvertoppingDischargeMean); + Assert.AreEqual(inputParameters.CriticalOvertoppingDischarge.CoefficientOfVariation.Value, entity.CriticalOvertoppingDischargeCoefficientOfVariation); + Assert.AreEqual(inputParameters.ModelFactorSuperCriticalFlow.Mean.Value, entity.ModelFactorSuperCriticalFlowMean); + Assert.AreEqual(inputParameters.WidthFlowApertures.Mean.Value, entity.WidthFlowAperturesMean); + Assert.AreEqual(inputParameters.WidthFlowApertures.CoefficientOfVariation.Value, entity.WidthFlowAperturesCoefficientOfVariation); + Assert.AreEqual(Convert.ToByte(inputParameters.InflowModelType), entity.InflowModelType); + Assert.AreEqual(inputParameters.InsideWaterLevel.Mean.Value, entity.InsideWaterLevelMean); + Assert.AreEqual(inputParameters.InsideWaterLevel.StandardDeviation.Value, entity.InsideWaterLevelStandardDeviation); + Assert.AreEqual(inputParameters.DeviationWaveDirection.Value, entity.DeviationWaveDirection); + Assert.AreEqual(inputParameters.DrainCoefficient.Mean.Value, entity.DrainCoefficientMean); + Assert.AreEqual(inputParameters.FactorStormDurationOpenStructure.Value, entity.FactorStormDurationOpenStructure); + Assert.AreEqual(inputParameters.ThresholdHeightOpenWeir.Mean.Value, entity.ThresholdHeightOpenWeirMean); + Assert.AreEqual(inputParameters.ThresholdHeightOpenWeir.StandardDeviation.Value, entity.ThresholdHeightOpenWeirStandardDeviation); + Assert.AreEqual(inputParameters.AreaFlowApertures.Mean.Value, entity.AreaFlowAperturesMean); + Assert.AreEqual(inputParameters.AreaFlowApertures.StandardDeviation.Value, entity.AreaFlowAperturesStandardDeviation); + Assert.AreEqual(inputParameters.FailureProbabilityOpenStructure, entity.FailureProbabilityOpenStructure); + Assert.AreEqual(inputParameters.FailureProbabilityReparation, entity.FailureProbablityReparation); + Assert.AreEqual(inputParameters.IdenticalApertures, entity.IdenticalApertures); + Assert.AreEqual(inputParameters.LevelCrestStructureNotClosing.Mean.Value, entity.LevelCrestStructureNotClosingMean); + Assert.AreEqual(inputParameters.LevelCrestStructureNotClosing.StandardDeviation.Value, entity.LevelCrestStructureNotClosingStandardDeviation); + Assert.AreEqual(inputParameters.ProbabilityOpenStructureBeforeFlooding, entity.ProbabilityOpenStructureBeforeFlooding); + Assert.AreEqual(order, entity.Order); + } + + [Test] + public void CreateForClosingStructures_CalculationWithParametersNaN_ReturnEntityWithNullParameters() + { + // Setup + var calculation = new StructuresCalculation + { + InputParameters = + { + StormDuration = + { + Mean = RoundedDouble.NaN, + }, + StructureNormalOrientation = RoundedDouble.NaN, + BreakWater = + { + Height = RoundedDouble.NaN + }, + AllowedLevelIncreaseStorage = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + StorageStructureArea = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + FlowWidthAtBottomProtection = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + CriticalOvertoppingDischarge = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + ModelFactorSuperCriticalFlow = + { + Mean = RoundedDouble.NaN + }, + WidthFlowApertures = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + InsideWaterLevel = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + DeviationWaveDirection = RoundedDouble.NaN, + DrainCoefficient = + { + Mean = RoundedDouble.NaN + }, + FactorStormDurationOpenStructure = RoundedDouble.NaN, + ThresholdHeightOpenWeir = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + AreaFlowApertures = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + LevelCrestStructureNotClosing = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + } + } + }; + + var registry = new PersistenceRegistry(); + + const int order = 67; + + // Call + ClosingStructuresCalculationEntity entity = calculation.CreateForClosingStructures(registry, order); + + // Assert + Assert.IsNull(entity.StormDurationMean); + Assert.IsNull(entity.StructureNormalOrientation); + Assert.IsNull(entity.BreakWaterHeight); + Assert.IsNull(entity.AllowedLevelIncreaseStorageMean); + Assert.IsNull(entity.AllowedLevelIncreaseStorageStandardDeviation); + Assert.IsNull(entity.StorageStructureAreaMean); + Assert.IsNull(entity.StorageStructureAreaCoefficientOfVariation); + Assert.IsNull(entity.FlowWidthAtBottomProtectionMean); + Assert.IsNull(entity.FlowWidthAtBottomProtectionStandardDeviation); + Assert.IsNull(entity.CriticalOvertoppingDischargeMean); + Assert.IsNull(entity.CriticalOvertoppingDischargeCoefficientOfVariation); + Assert.IsNull(entity.ModelFactorSuperCriticalFlowMean); + Assert.IsNull(entity.WidthFlowAperturesMean); + Assert.IsNull(entity.WidthFlowAperturesCoefficientOfVariation); + Assert.IsNull(entity.InsideWaterLevelMean); + Assert.IsNull(entity.InsideWaterLevelStandardDeviation); + Assert.IsNull(entity.DeviationWaveDirection); + Assert.IsNull(entity.DrainCoefficientMean); + Assert.IsNull(entity.FactorStormDurationOpenStructure); + Assert.IsNull(entity.ThresholdHeightOpenWeirMean); + Assert.IsNull(entity.ThresholdHeightOpenWeirStandardDeviation); + Assert.IsNull(entity.AreaFlowAperturesMean); + Assert.IsNull(entity.AreaFlowAperturesStandardDeviation); + Assert.IsNull(entity.LevelCrestStructureNotClosingMean); + Assert.IsNull(entity.LevelCrestStructureNotClosingStandardDeviation); + } + + [Test] + public void CreateForClosingStructures_CalculationWithStructure_ReturnEntityWithStructureEntity() + { + // Setup + ClosingStructure alreadyRegisteredStructure = new TestClosingStructure(); + var calculation = new StructuresCalculation + { + InputParameters = + { + Structure = alreadyRegisteredStructure + } + }; + + var registry = new PersistenceRegistry(); + registry.Register(new ClosingStructureEntity(), alreadyRegisteredStructure); + + // Call + ClosingStructuresCalculationEntity entity = calculation.CreateForClosingStructures(registry, 0); + + // Assert + Assert.IsNotNull(entity.ClosingStructureEntity); + } + + [Test] + public void CreateForClosingStructures_CalculationWithHydraulicBoundaryLocation_ReturnEntityWithHydraulicLocationEntity() + { + // Setup + var alreadyRegisteredHydroLocation = new HydraulicBoundaryLocation(1, "A", 2, 3); + var calculation = new StructuresCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = alreadyRegisteredHydroLocation + } + }; + + var registry = new PersistenceRegistry(); + registry.Register(new HydraulicLocationEntity(), alreadyRegisteredHydroLocation); + + // Call + ClosingStructuresCalculationEntity entity = calculation.CreateForClosingStructures(registry, 0); + + // Assert + Assert.IsNotNull(entity.HydraulicLocationEntity); + } + + [Test] + public void CreateForClosingStructures_CalculationWithForeshoreProfile_ReturnEntityWithForeshoreProfileEntity() + { + // Setup + var alreadyRegisteredForeshoreProfile = new ForeshoreProfile(new Point2D(0, 0), + new Point2D[0], + null, + new ForeshoreProfile.ConstructionProperties()); + var calculation = new StructuresCalculation + { + InputParameters = + { + ForeshoreProfile = alreadyRegisteredForeshoreProfile + } + }; + + var registry = new PersistenceRegistry(); + registry.Register(new ForeshoreProfileEntity(), alreadyRegisteredForeshoreProfile); + + // Call + ClosingStructuresCalculationEntity entity = calculation.CreateForClosingStructures(registry, 0); + + // Assert + Assert.IsNotNull(entity.ForeshoreProfileEntity); + } + + #endregion } } \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/IStructureCalculationEntityReadExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/IStructureCalculationEntityReadExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/IStructureCalculationEntityReadExtensionsTest.cs (revision bce62ec6102f15b0dbb1328fd9d14063fd21c978) @@ -0,0 +1,240 @@ +// 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 Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.HydraRing.Data; + +namespace Application.Ringtoets.Storage.Test.Read +{ + [TestFixture] + public class IStructureCalculationEntityReadExtensionsTest + { + [Test] + public void Read_InputToUpdateNull_ThrowArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var entity = mocks.Stub(); + mocks.ReplayAll(); + + var collector = new ReadConversionCollector(); + + // Call + TestDelegate call = () => entity.Read(null, collector); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("inputToUpdate", paramName); + mocks.VerifyAll(); + } + + [Test] + public void Read_ReadConversionCollectorIsNull_ThrowArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var entity = mocks.Stub(); + mocks.ReplayAll(); + + var inputToUpdate = new SimpleStructuresInput(); + + // Call + TestDelegate call = () => entity.Read(inputToUpdate, null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + mocks.VerifyAll(); + } + + [Test] + public void Read_ValidEntity_InputObjectUpdated() + { + // Setup + var random = new Random(78); + + var mocks = new MockRepository(); + var entity = mocks.Stub(); + entity.StructureNormalOrientation = random.GetFromRange(0, 360); + entity.ModelFactorSuperCriticalFlowMean = random.GetFromRange(-9999.9999, 9999.9999); + entity.AllowedLevelIncreaseStorageMean = random.GetFromRange(1e-6, 9999.9999); + entity.AllowedLevelIncreaseStorageStandardDeviation = random.GetFromRange(1e-6, 9999.9999); + entity.FlowWidthAtBottomProtectionMean = random.GetFromRange(1e-6, 9999.9999); + entity.FlowWidthAtBottomProtectionStandardDeviation = random.GetFromRange(1e-6, 9999.9999); + entity.CriticalOvertoppingDischargeMean = random.GetFromRange(1e-6, 9999.9999); + entity.CriticalOvertoppingDischargeCoefficientOfVariation = random.GetFromRange(1e-6, 9999.9999); + entity.FailureProbabilityStructureWithErosion = random.NextDouble(); + entity.WidthFlowAperturesMean = random.GetFromRange(1e-6, 9999.9999); + entity.WidthFlowAperturesCoefficientOfVariation = random.GetFromRange(1e-6, 9999.9999); + entity.StormDurationMean = random.GetFromRange(1e-6, 9999.9999); + entity.UseForeshore = 1; + entity.UseBreakWater = 1; + mocks.ReplayAll(); + + var inputToUpdate = new SimpleStructuresInput(); + var collector = new ReadConversionCollector(); + + // Call + entity.Read(inputToUpdate, collector); + + // Assert + Assert.IsTrue(inputToUpdate.UseForeshore); + Assert.IsTrue(inputToUpdate.UseBreakWater); + + AssertRoundedDouble(entity.StructureNormalOrientation, inputToUpdate.StructureNormalOrientation); + AssertRoundedDouble(entity.ModelFactorSuperCriticalFlowMean, inputToUpdate.ModelFactorSuperCriticalFlow.Mean); + AssertRoundedDouble(entity.AllowedLevelIncreaseStorageMean, inputToUpdate.AllowedLevelIncreaseStorage.Mean); + AssertRoundedDouble(entity.AllowedLevelIncreaseStorageStandardDeviation, inputToUpdate.AllowedLevelIncreaseStorage.StandardDeviation); + AssertRoundedDouble(entity.FlowWidthAtBottomProtectionMean, inputToUpdate.FlowWidthAtBottomProtection.Mean); + AssertRoundedDouble(entity.FlowWidthAtBottomProtectionStandardDeviation, inputToUpdate.FlowWidthAtBottomProtection.StandardDeviation); + AssertRoundedDouble(entity.CriticalOvertoppingDischargeMean, inputToUpdate.CriticalOvertoppingDischarge.Mean); + AssertRoundedDouble(entity.CriticalOvertoppingDischargeCoefficientOfVariation, inputToUpdate.CriticalOvertoppingDischarge.CoefficientOfVariation); + Assert.AreEqual(entity.FailureProbabilityStructureWithErosion, inputToUpdate.FailureProbabilityStructureWithErosion); + AssertRoundedDouble(entity.WidthFlowAperturesMean, inputToUpdate.WidthFlowApertures.Mean); + AssertRoundedDouble(entity.WidthFlowAperturesCoefficientOfVariation, inputToUpdate.WidthFlowApertures.CoefficientOfVariation); + AssertRoundedDouble(entity.StormDurationMean, inputToUpdate.StormDuration.Mean); + + Assert.IsEmpty(inputToUpdate.ForeshoreGeometry); + Assert.IsNull(inputToUpdate.ForeshoreProfile); + Assert.IsNull(inputToUpdate.HydraulicBoundaryLocation); + Assert.IsNull(inputToUpdate.Structure); + mocks.VerifyAll(); + } + + [Test] + public void Read_EntityWithParametersNull_InputObjectUpdatedWithNaN() + { + // Setup + var mocks = new MockRepository(); + var entity = mocks.Stub(); + entity.StructureNormalOrientation = null; + entity.ModelFactorSuperCriticalFlowMean = null; + entity.AllowedLevelIncreaseStorageMean = null; + entity.AllowedLevelIncreaseStorageStandardDeviation = null; + entity.FlowWidthAtBottomProtectionMean = null; + entity.FlowWidthAtBottomProtectionStandardDeviation = null; + entity.CriticalOvertoppingDischargeMean = null; + entity.CriticalOvertoppingDischargeCoefficientOfVariation = null; + entity.WidthFlowAperturesMean = null; + entity.WidthFlowAperturesCoefficientOfVariation = null; + entity.StormDurationMean = null; + mocks.ReplayAll(); + + var inputToUpdate = new SimpleStructuresInput(); + var collector = new ReadConversionCollector(); + + // Call + entity.Read(inputToUpdate, collector); + + // Assert + Assert.IsNaN(inputToUpdate.StructureNormalOrientation); + Assert.IsNaN(inputToUpdate.ModelFactorSuperCriticalFlow.Mean); + Assert.IsNaN(inputToUpdate.AllowedLevelIncreaseStorage.Mean); + Assert.IsNaN(inputToUpdate.AllowedLevelIncreaseStorage.StandardDeviation); + Assert.IsNaN(inputToUpdate.FlowWidthAtBottomProtection.Mean); + Assert.IsNaN(inputToUpdate.FlowWidthAtBottomProtection.StandardDeviation); + Assert.IsNaN(inputToUpdate.CriticalOvertoppingDischarge.Mean); + Assert.IsNaN(inputToUpdate.CriticalOvertoppingDischarge.CoefficientOfVariation); + Assert.IsNaN(inputToUpdate.WidthFlowApertures.Mean); + Assert.IsNaN(inputToUpdate.WidthFlowApertures.CoefficientOfVariation); + Assert.IsNaN(inputToUpdate.StormDuration.Mean); + mocks.VerifyAll(); + } + + [Test] + public void Read_EntityWithForeshoreProfileEntity_InputObjectUpdatedWithForeshoreProfile() + { + // Setup + var foreshoreProfile = new ForeshoreProfile(new Point2D(0,0), new Point2D[0], + null, new ForeshoreProfile.ConstructionProperties()); + var foreshoreEntity = new ForeshoreProfileEntity(); + + var mocks = new MockRepository(); + var entity = mocks.Stub(); + entity.ForeshoreProfileEntity = foreshoreEntity; + mocks.ReplayAll(); + + var inputToUpdate = new SimpleStructuresInput(); + var collector = new ReadConversionCollector(); + collector.Read(foreshoreEntity, foreshoreProfile); + + // Call + entity.Read(inputToUpdate, collector); + + // Assert + Assert.AreSame(foreshoreProfile, inputToUpdate.ForeshoreProfile); + mocks.VerifyAll(); + } + + [Test] + public void Read_EntityWithHydraulicLocationEntity_InputObjectUpdatedWithHydraulicBoundaryLocation() + { + // Setup + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(0, "A", 0,0); + var hydraulicLocationEntity = new HydraulicLocationEntity(); + + var mocks = new MockRepository(); + var entity = mocks.Stub(); + entity.HydraulicLocationEntity = hydraulicLocationEntity; + mocks.ReplayAll(); + + var inputToUpdate = new SimpleStructuresInput(); + var collector = new ReadConversionCollector(); + collector.Read(hydraulicLocationEntity, hydraulicBoundaryLocation); + + // Call + entity.Read(inputToUpdate, collector); + + // Assert + Assert.AreSame(hydraulicBoundaryLocation, inputToUpdate.HydraulicBoundaryLocation); + mocks.VerifyAll(); + } + + private static void AssertRoundedDouble(double? entityValue, RoundedDouble roundedDouble) + { + Assert.AreEqual((RoundedDouble)entityValue.ToNullAsNaN(), roundedDouble, roundedDouble.GetAccuracy()); + } + + private class SimpleStructure : StructureBase + { + public SimpleStructure(ConstructionProperties constructionProperties) : base(constructionProperties) {} + } + + private class SimpleStructuresInput : StructuresInputBase + { + protected override void UpdateStructureParameters() + { + throw new NotImplementedException(); + } + } + } +} \ No newline at end of file