Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj =================================================================== diff -u -r6a9a423fddb189769e43cc9d69d4dd828a6f68e2 -r32d32b83fc8e0c9b4849361af987da0170549146 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 6a9a423fddb189769e43cc9d69d4dd828a6f68e2) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 32d32b83fc8e0c9b4849361af987da0170549146) @@ -129,6 +129,7 @@ + Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/AssessmentSectionEntityReadExtensions.cs =================================================================== diff -u -rfe68c3f7cae5946b93d9e27eb532b176a6b26b84 -r32d32b83fc8e0c9b4849361af987da0170549146 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/AssessmentSectionEntityReadExtensions.cs (.../AssessmentSectionEntityReadExtensions.cs) (revision fe68c3f7cae5946b93d9e27eb532b176a6b26b84) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/AssessmentSectionEntityReadExtensions.cs (.../AssessmentSectionEntityReadExtensions.cs) (revision 32d32b83fc8e0c9b4849361af987da0170549146) @@ -59,7 +59,7 @@ entity.ReadPipingFailureMechanism(assessmentSection, collector); entity.ReadGrassCoverErosionInwardsFailureMechanism(assessmentSection); - entity.ReadHydraulicDatabase(assessmentSection); + entity.ReadHydraulicDatabase(assessmentSection, collector); entity.ReadReferenceLine(assessmentSection); entity.ReadStandAloneFailureMechanisms(assessmentSection); @@ -75,7 +75,7 @@ } } - private static void ReadHydraulicDatabase(this AssessmentSectionEntity entity, IAssessmentSection assessmentSection) + private static void ReadHydraulicDatabase(this AssessmentSectionEntity entity, IAssessmentSection assessmentSection, ReadConversionCollector collector) { if (entity.HydraulicDatabaseLocation != null) { @@ -87,7 +87,7 @@ foreach (var hydraulicLocationEntity in entity.HydraulicLocationEntities) { - assessmentSection.HydraulicBoundaryDatabase.Locations.Add(hydraulicLocationEntity.Read()); + assessmentSection.HydraulicBoundaryDatabase.Locations.Add(hydraulicLocationEntity.Read(collector)); } } } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/HydraulicLocationEntityReadExtensions.cs =================================================================== diff -u -r67d310178885cdd996f37441492d2331429219a1 -r32d32b83fc8e0c9b4849361af987da0170549146 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/HydraulicLocationEntityReadExtensions.cs (.../HydraulicLocationEntityReadExtensions.cs) (revision 67d310178885cdd996f37441492d2331429219a1) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/HydraulicLocationEntityReadExtensions.cs (.../HydraulicLocationEntityReadExtensions.cs) (revision 32d32b83fc8e0c9b4849361af987da0170549146) @@ -35,9 +35,19 @@ /// Read the and use the information to construct a . /// /// The to create for. + /// The object keeping track of read operations. /// A new . - internal static HydraulicBoundaryLocation Read(this HydraulicLocationEntity entity) + internal static HydraulicBoundaryLocation Read(this HydraulicLocationEntity entity, ReadConversionCollector collector) { + if (collector == null) + { + throw new ArgumentNullException("collector"); + } + if (collector.Contains(entity)) + { + return collector.Get(entity); + } + HydraulicBoundaryLocation hydraulicBoundaryLocation = new HydraulicBoundaryLocation( entity.LocationId, entity.Name, @@ -52,6 +62,8 @@ hydraulicBoundaryLocation.DesignWaterLevel = Convert.ToDouble(entity.DesignWaterLevel); } + collector.Read(entity, hydraulicBoundaryLocation); + return hydraulicBoundaryLocation; } } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/PipingCalculationEntityReadExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/PipingCalculationEntityReadExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/PipingCalculationEntityReadExtensions.cs (revision 32d32b83fc8e0c9b4849361af987da0170549146) @@ -0,0 +1,107 @@ +// 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; +using Ringtoets.Piping.Data; + +namespace Application.Ringtoets.Storage.Read +{ + internal static class PipingCalculationEntityReadExtensions + { + /// + /// Read the and use the information to + /// construct a . + /// + /// The to create + /// for. + /// The object keeping track of read operations. + /// The general input parameters that apply + /// to all instances. + /// A new . + /// Thrown when is null. + internal static PipingCalculationScenario Read(this PipingCalculationEntity entity, ReadConversionCollector collector, + GeneralPipingInput generalInputParameters) + { + if (collector == null) + { + throw new ArgumentNullException("collector"); + } + + var calculation = new PipingCalculationScenario(generalInputParameters) + { + StorageId = entity.PipingCalculationEntityId, + IsRelevant = Convert.ToBoolean(entity.RelevantForScenario), + Contribution = (RoundedDouble)Convert.ToDouble(entity.ScenarioContribution), + Name = entity.Name, + Comments = entity.Comments + }; + ReadInputParameters(calculation.InputParameters, entity, collector); + + return calculation; + } + + private static void ReadInputParameters(PipingInput inputParameters, PipingCalculationEntity entity, ReadConversionCollector collector) + { + inputParameters.EntryPointL = GetRoundedDoubleFromNullableDecimal(entity.EntryPointL); + inputParameters.ExitPointL = GetRoundedDoubleFromNullableDecimal(entity.ExitPointL); + inputParameters.PhreaticLevelExit.Mean = (RoundedDouble)Convert.ToDouble(entity.PhreaticLevelExitMean); + inputParameters.PhreaticLevelExit.StandardDeviation = (RoundedDouble)Convert.ToDouble(entity.PhreaticLevelExitStandardDeviation); + inputParameters.DampingFactorExit.Mean = (RoundedDouble)Convert.ToDouble(entity.DampingFactorExitMean); + inputParameters.DampingFactorExit.StandardDeviation = (RoundedDouble)Convert.ToDouble(entity.DampingFactorExitStandardDeviation); + inputParameters.SaturatedVolumicWeightOfCoverageLayer.Mean = (RoundedDouble)Convert.ToDouble(entity.SaturatedVolumicWeightOfCoverageLayerMean); + inputParameters.SaturatedVolumicWeightOfCoverageLayer.StandardDeviation = (RoundedDouble)Convert.ToDouble(entity.SaturatedVolumicWeightOfCoverageLayerStandardDeviation); + inputParameters.SaturatedVolumicWeightOfCoverageLayer.Shift = (RoundedDouble)Convert.ToDouble(entity.SaturatedVolumicWeightOfCoverageLayerShift); + inputParameters.Diameter70.Mean = (RoundedDouble)Convert.ToDouble(entity.Diameter70Mean); + inputParameters.Diameter70.StandardDeviation = (RoundedDouble)Convert.ToDouble(entity.Diameter70StandardDeviation); + inputParameters.DarcyPermeability.Mean = (RoundedDouble)Convert.ToDouble(entity.DarcyPermeabilityMean); + inputParameters.DarcyPermeability.StandardDeviation = (RoundedDouble)Convert.ToDouble(entity.DarcyPermeabilityStandardDeviation); + + if (entity.SurfaceLineEntity != null) + { + inputParameters.SurfaceLine = entity.SurfaceLineEntity.Read(collector); + } + if (entity.HydraulicLocationEntity != null) + { + inputParameters.HydraulicBoundaryLocation = entity.HydraulicLocationEntity.Read(collector); + } + if (entity.StochasticSoilProfileEntity != null) + { + inputParameters.StochasticSoilModel = entity.StochasticSoilProfileEntity.StochasticSoilModelEntity.Read(collector); + inputParameters.StochasticSoilProfile = entity.StochasticSoilProfileEntity.Read(collector); + } + } + + private static RoundedDouble GetRoundedDoubleFromNullableDecimal(decimal? parameter) + { + if (parameter.HasValue) + { + return (RoundedDouble)Convert.ToDouble(parameter); + } + return (RoundedDouble)double.NaN; + } + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ReadConversionCollector.cs =================================================================== diff -u -r54e6baff4fab535777949f737314f052853e818a -r32d32b83fc8e0c9b4849361af987da0170549146 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ReadConversionCollector.cs (.../ReadConversionCollector.cs) (revision 54e6baff4fab535777949f737314f052853e818a) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ReadConversionCollector.cs (.../ReadConversionCollector.cs) (revision 32d32b83fc8e0c9b4849361af987da0170549146) @@ -25,6 +25,9 @@ using Core.Common.Base.Geometry; using Core.Common.Utils; + +using Ringtoets.HydraRing.Data; +using Ringtoets.Piping.Data; using Ringtoets.Piping.Primitives; namespace Application.Ringtoets.Storage.Read @@ -35,12 +38,159 @@ /// internal class ReadConversionCollector { + private readonly Dictionary stochasticSoilModels = new Dictionary(new ReferenceEqualityComparer()); + private readonly Dictionary stochasticSoilProfiles = new Dictionary(new ReferenceEqualityComparer()); private readonly Dictionary soilProfiles = new Dictionary(new ReferenceEqualityComparer()); + private readonly Dictionary surfaceLines = new Dictionary(new ReferenceEqualityComparer()); private readonly Dictionary surfaceLineGeometryPoints = new Dictionary(new ReferenceEqualityComparer()); + private readonly Dictionary hydraulicBoundaryLocations = new Dictionary(new ReferenceEqualityComparer()); #region SoilProfileEntity: Read, Contains, Get /// + /// Registers a read operation for and the + /// that was constructed with the information. + /// + /// The that was read. + /// The that was constructed. + /// Thrown when either: + /// + /// is null + /// is null + /// + internal void Read(StochasticSoilModelEntity entity, StochasticSoilModel model) + { + if (entity == null) + { + throw new ArgumentNullException("entity"); + } + if (model == null) + { + throw new ArgumentNullException("model"); + } + + stochasticSoilModels[entity] = model; + } + + /// + /// Checks whether a read operations has been registered for the given . + /// + /// The to check for. + /// true if the was read before, false otherwise. + /// Thrown when is null. + internal bool Contains(StochasticSoilModelEntity entity) + { + if (entity == null) + { + throw new ArgumentNullException("entity"); + } + return stochasticSoilModels.ContainsKey(entity); + } + + /// + /// Obtains the which was read for the given . + /// + /// The for which a + /// read operation has been registered. + /// The constructed . + /// Thrown when is null. + /// Thrown when no read operation has been registered for + /// . + /// Use to find out + /// whether a read operation has been registered for . + internal StochasticSoilModel Get(StochasticSoilModelEntity entity) + { + if (entity == null) + { + throw new ArgumentNullException("entity"); + } + try + { + return stochasticSoilModels[entity]; + } + catch (KeyNotFoundException e) + { + throw new InvalidOperationException(e.Message, e); + } + } + + #endregion + + #region StochasticSoilProfileEntity: Read, Contains, Get + + /// + /// Registers a read operation for and + /// the that was constructed with the information. + /// + /// The that was read. + /// The that was constructed. + /// Thrown when either: + /// + /// is null + /// is null + /// + internal void Read(StochasticSoilProfileEntity entity, StochasticSoilProfile model) + { + if (entity == null) + { + throw new ArgumentNullException("entity"); + } + if (model == null) + { + throw new ArgumentNullException("model"); + } + + stochasticSoilProfiles[entity] = model; + } + + /// + /// Checks whether a read operations has been registered for the given . + /// + /// The to check for. + /// true if the was read before, false otherwise. + /// Thrown when is null. + internal bool Contains(StochasticSoilProfileEntity entity) + { + if (entity == null) + { + throw new ArgumentNullException("entity"); + } + return stochasticSoilProfiles.ContainsKey(entity); + } + + /// + /// Obtains the which was read for the given + /// . + /// + /// The for which + /// a read operation has been registered. + /// The constructed . + /// Thrown when is null. + /// Thrown when no read operation has been registered for + /// . + /// Use to find out whether a read operation has been registered for + /// . + internal StochasticSoilProfile Get(StochasticSoilProfileEntity entity) + { + if (entity == null) + { + throw new ArgumentNullException("entity"); + } + try + { + return stochasticSoilProfiles[entity]; + } + catch (KeyNotFoundException e) + { + throw new InvalidOperationException(e.Message, e); + } + } + + #endregion + + #region SoilProfileEntity: Read, Contains, Get + + /// /// Registers a read operation for and the that /// was constructed with the information. /// @@ -111,6 +261,78 @@ #region SurfaceLinePointEntity: Read, Contains, Get /// + /// Registers a read operation for and the + /// that was constructed with the information. + /// + /// The that was read. + /// The that was constructed. + /// Thrown when either: + /// + /// is null + /// is null + /// + internal void Read(SurfaceLineEntity entity, RingtoetsPipingSurfaceLine model) + { + if (entity == null) + { + throw new ArgumentNullException("entity"); + } + if (model == null) + { + throw new ArgumentNullException("model"); + } + + surfaceLines[entity] = model; + } + + /// + /// Checks whether a read operation has been registered for a given . + /// + /// The to check for. + /// true if the was read before, false otherwise. + /// Thrown when is null. + internal bool Contains(SurfaceLineEntity entity) + { + if (entity == null) + { + throw new ArgumentNullException("entity"); + } + return surfaceLines.ContainsKey(entity); + } + + /// + /// Obtains the which was read for the + /// given . + /// + /// The for which a read operation + /// has been registered. + /// The constructed . + /// Thrown when is null. + /// Thrown when no read operation has + /// been registered for . + /// Use to find out whether a + /// read operation has been registered for . + internal RingtoetsPipingSurfaceLine Get(SurfaceLineEntity entity) + { + if (entity == null) + { + throw new ArgumentNullException("entity"); + } + try + { + return surfaceLines[entity]; + } + catch (KeyNotFoundException e) + { + throw new InvalidOperationException(e.Message, e); + } + } + + #endregion + + #region SurfaceLinePointEntity: Read, Contains, Get + + /// /// Registers a read operation for and the /// (that is part of ) /// that was constructed with the information. @@ -180,5 +402,77 @@ } #endregion + + #region SurfaceLinePointEntity: Read, Contains, Get + + /// + /// Registers a read operation for and the + /// that was constructed with the information. + /// + /// The that was read. + /// The that was constructed. + /// Thrown when either: + /// + /// is null + /// is null + /// + internal void Read(HydraulicLocationEntity entity, HydraulicBoundaryLocation model) + { + if (entity == null) + { + throw new ArgumentNullException("entity"); + } + if (model == null) + { + throw new ArgumentNullException("model"); + } + + hydraulicBoundaryLocations[entity] = model; + } + + /// + /// Checks whether a read operation has been registered for a given . + /// + /// The to check for. + /// true if the was read before, false otherwise. + /// Thrown when is null. + internal bool Contains(HydraulicLocationEntity entity) + { + if (entity == null) + { + throw new ArgumentNullException("entity"); + } + return hydraulicBoundaryLocations.ContainsKey(entity); + } + + /// + /// Obtains the which was read for the + /// given . + /// + /// The for which a read + /// operation has been registered. + /// The constructed . + /// Thrown when is null. + /// Thrown when no read operation has + /// been registered for . + /// Use to find out whether a + /// read operation has been registered for . + internal HydraulicBoundaryLocation Get(HydraulicLocationEntity entity) + { + if (entity == null) + { + throw new ArgumentNullException("entity"); + } + try + { + return hydraulicBoundaryLocations[entity]; + } + catch (KeyNotFoundException e) + { + throw new InvalidOperationException(e.Message, e); + } + } + + #endregion } } \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/StochasticSoilModelEntityReadExtensions.cs =================================================================== diff -u -r4478bdf539df278f9e2aac0f9fe683c34ac55335 -r32d32b83fc8e0c9b4849361af987da0170549146 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/StochasticSoilModelEntityReadExtensions.cs (.../StochasticSoilModelEntityReadExtensions.cs) (revision 4478bdf539df278f9e2aac0f9fe683c34ac55335) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/StochasticSoilModelEntityReadExtensions.cs (.../StochasticSoilModelEntityReadExtensions.cs) (revision 32d32b83fc8e0c9b4849361af987da0170549146) @@ -46,6 +46,10 @@ { throw new ArgumentNullException("collector"); } + if (collector.Contains(entity)) + { + return collector.Get(entity); + } var model = new StochasticSoilModel(-1, entity.Name, entity.SegmentName) { @@ -54,6 +58,8 @@ entity.ReadStochasticSoilProfiles(model, collector); entity.ReadSegmentPoints(model); + collector.Read(entity, model); + return model; } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/StochasticSoilProfileEntityReadExtensions.cs =================================================================== diff -u -r67d310178885cdd996f37441492d2331429219a1 -r32d32b83fc8e0c9b4849361af987da0170549146 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/StochasticSoilProfileEntityReadExtensions.cs (.../StochasticSoilProfileEntityReadExtensions.cs) (revision 67d310178885cdd996f37441492d2331429219a1) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/StochasticSoilProfileEntityReadExtensions.cs (.../StochasticSoilProfileEntityReadExtensions.cs) (revision 32d32b83fc8e0c9b4849361af987da0170549146) @@ -45,13 +45,19 @@ { throw new ArgumentNullException("collector"); } + if (collector.Contains(entity)) + { + return collector.Get(entity); + } var profile = new StochasticSoilProfile(Convert.ToDouble(entity.Probability), SoilProfileType.SoilProfile1D, -1) { StorageId = entity.StochasticSoilProfileEntityId }; entity.ReadSoilProfile(profile, collector); + collector.Read(entity, profile); + return profile; } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/SurfaceLineEntityReadExtensions.cs =================================================================== diff -u -r3fa8664290181eedfdcefbe87f32aa7539d748e3 -r32d32b83fc8e0c9b4849361af987da0170549146 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/SurfaceLineEntityReadExtensions.cs (.../SurfaceLineEntityReadExtensions.cs) (revision 3fa8664290181eedfdcefbe87f32aa7539d748e3) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/SurfaceLineEntityReadExtensions.cs (.../SurfaceLineEntityReadExtensions.cs) (revision 32d32b83fc8e0c9b4849361af987da0170549146) @@ -26,7 +26,6 @@ using Core.Common.Base.Geometry; -using Ringtoets.Integration.Data; using Ringtoets.Piping.Primitives; namespace Application.Ringtoets.Storage.Read @@ -52,6 +51,11 @@ { throw new ArgumentNullException("collector"); } + if (collector.Contains(entity)) + { + return collector.Get(entity); + } + var surfaceLine = new RingtoetsPipingSurfaceLine { StorageId = entity.SurfaceLineEntityId, @@ -60,9 +64,10 @@ Convert.ToDouble(entity.ReferenceLineIntersectionX), Convert.ToDouble(entity.ReferenceLineIntersectionY)) }; - entity.ReadSurfaceLineGeometryAndCharacteristicPoints(surfaceLine, collector); + collector.Read(entity, surfaceLine); + return surfaceLine; } Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj =================================================================== diff -u -r6a9a423fddb189769e43cc9d69d4dd828a6f68e2 -r32d32b83fc8e0c9b4849361af987da0170549146 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 6a9a423fddb189769e43cc9d69d4dd828a6f68e2) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 32d32b83fc8e0c9b4849361af987da0170549146) @@ -104,6 +104,7 @@ + Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/HydraulicLocationEntityReadExtensionsTest.cs =================================================================== diff -u -rfe68c3f7cae5946b93d9e27eb532b176a6b26b84 -r32d32b83fc8e0c9b4849361af987da0170549146 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/HydraulicLocationEntityReadExtensionsTest.cs (.../HydraulicLocationEntityReadExtensionsTest.cs) (revision fe68c3f7cae5946b93d9e27eb532b176a6b26b84) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/HydraulicLocationEntityReadExtensionsTest.cs (.../HydraulicLocationEntityReadExtensionsTest.cs) (revision 32d32b83fc8e0c9b4849361af987da0170549146) @@ -24,12 +24,28 @@ using Application.Ringtoets.Storage.Read; using NUnit.Framework; +using Ringtoets.HydraRing.Data; + namespace Application.Ringtoets.Storage.Test.Read { [TestFixture] public class HydraulicLocationEntityReadExtensionsTest { [Test] + public void Read_CollectorIsNull_ThrowArgumentNullException() + { + // Setup + var entity = new HydraulicLocationEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] public void Read_Always_ReturnsHydraulicBoundaryLocationWithPropertiesSet() { // Setup @@ -48,8 +64,10 @@ LocationY = Convert.ToDecimal(y) }; + var collector = new ReadConversionCollector(); + // Call - var location = entity.Read(); + var location = entity.Read(collector); // Assert Assert.IsNotNull(location); @@ -75,12 +93,33 @@ DesignWaterLevel = waterLevel }; + var collector = new ReadConversionCollector(); + // Call - var location = entity.Read(); + var location = entity.Read(collector); // Assert Assert.IsNotNull(location); Assert.AreEqual(expectedWaterLevel, location.DesignWaterLevel); - } + } + + [Test] + public void Read_SameHydraulicLocationEntityTwice_ReturnSameHydraulicBoundaryLocation() + { + // Setup + var entity = new HydraulicLocationEntity + { + Name = "A" + }; + + var collector = new ReadConversionCollector(); + + // Call + HydraulicBoundaryLocation location1 = entity.Read(collector); + HydraulicBoundaryLocation location2 = entity.Read(collector); + + // Assert + Assert.AreSame(location1, location2); + } } } \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/PipingCalculationEntityReadExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/PipingCalculationEntityReadExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/PipingCalculationEntityReadExtensionsTest.cs (revision 32d32b83fc8e0c9b4849361af987da0170549146) @@ -0,0 +1,387 @@ +// 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 NUnit.Framework; + +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.HydraRing.Data; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Primitives; + +namespace Application.Ringtoets.Storage.Test.Read +{ + [TestFixture] + public class PipingCalculationEntityReadExtensionsTest + { + [Test] + public void Read_CollectorIsNull_ThrowArgumentNullException() + { + // Setup + var entity = new PipingCalculationEntity(); + + // Call + TestDelegate call = () => entity.Read(null, new GeneralPipingInput()); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + [TestCase(3456789, true, 0.98, "haha", "hihi", 0.0, 3.4, 123)] + [TestCase(234, false, 0.0, null, null, double.NaN, double.NaN, 321)] + public void Read_ValidEntity_ReturnPipingCalculationScenario(long id, bool isRelevant, double contribution, + string name, string comments, double entryPoint, double exitPoint, int seed) + { + // Setup + var random = new Random(seed); + + var entity = new PipingCalculationEntity + { + PipingCalculationEntityId = id, + RelevantForScenario = Convert.ToByte(isRelevant), + ScenarioContribution = Convert.ToDecimal(contribution), + Name = name, + Comments = comments, + EntryPointL = ToNullableDecimal(entryPoint), + ExitPointL = ToNullableDecimal(exitPoint), + PhreaticLevelExitMean = GetRandomDecimalInRange(random, -9999.99, 9999.99), + PhreaticLevelExitStandardDeviation = GetRandomDecimalInRange(random, 0, 9999.99), + DampingFactorExitMean = GetRandomDecimalInRange(random, 1e-6, 9999.99), + DampingFactorExitStandardDeviation = GetRandomDecimalInRange(random, 0, 9999.99), + SaturatedVolumicWeightOfCoverageLayerMean = GetRandomDecimalInRange(random, 1e-6, 9999.99), + SaturatedVolumicWeightOfCoverageLayerStandardDeviation = GetRandomDecimalInRange(random, 0, 9999.99), + SaturatedVolumicWeightOfCoverageLayerShift = GetRandomDecimalInRange(random, -9999.99, 9999.99), + Diameter70Mean = GetRandomDecimalInRange(random, 1e-6, 9999.99), + Diameter70StandardDeviation = GetRandomDecimalInRange(random, 0.0, 9999.99), + DarcyPermeabilityMean = GetRandomDecimalInRange(random, 1e-6, 9999.99), + DarcyPermeabilityStandardDeviation = GetRandomDecimalInRange(random, 0.0, 9999.99) + }; + + var collector = new ReadConversionCollector(); + var generalInputParameters = new GeneralPipingInput(); + + // Call + PipingCalculationScenario calculation = entity.Read(collector, generalInputParameters); + + // Assert + Assert.AreEqual(id, calculation.StorageId); + Assert.AreEqual(isRelevant, calculation.IsRelevant); + Assert.AreEqual(contribution, calculation.Contribution, 1e-6); + Assert.AreEqual(name, calculation.Name); + Assert.AreEqual(comments, calculation.Comments); + + Assert.AreEqual(generalInputParameters.BeddingAngle, calculation.InputParameters.BeddingAngle); + Assert.AreEqual(generalInputParameters.CriticalHeaveGradient, calculation.InputParameters.CriticalHeaveGradient); + Assert.AreEqual(generalInputParameters.Gravity, calculation.InputParameters.Gravity); + Assert.AreEqual(generalInputParameters.MeanDiameter70, calculation.InputParameters.MeanDiameter70); + Assert.AreEqual(generalInputParameters.SandParticlesVolumicWeight, calculation.InputParameters.SandParticlesVolumicWeight); + Assert.AreEqual(generalInputParameters.SellmeijerModelFactor, calculation.InputParameters.SellmeijerModelFactor); + Assert.AreEqual(generalInputParameters.SellmeijerReductionFactor, calculation.InputParameters.SellmeijerReductionFactor); + Assert.AreEqual(generalInputParameters.UpliftModelFactor, calculation.InputParameters.UpliftModelFactor); + Assert.AreEqual(generalInputParameters.WaterKinematicViscosity, calculation.InputParameters.WaterKinematicViscosity); + Assert.AreEqual(generalInputParameters.WaterVolumetricWeight, calculation.InputParameters.WaterVolumetricWeight); + Assert.AreEqual(generalInputParameters.WhitesDragCoefficient, calculation.InputParameters.WhitesDragCoefficient); + + AssertRoundedDouble(entryPoint, calculation.InputParameters.EntryPointL); + AssertRoundedDouble(exitPoint, calculation.InputParameters.ExitPointL); + AssertRoundedDouble(entity.PhreaticLevelExitMean, calculation.InputParameters.PhreaticLevelExit.Mean); + AssertRoundedDouble(entity.PhreaticLevelExitStandardDeviation, calculation.InputParameters.PhreaticLevelExit.StandardDeviation); + AssertRoundedDouble(entity.DampingFactorExitMean, calculation.InputParameters.DampingFactorExit.Mean); + AssertRoundedDouble(entity.DampingFactorExitStandardDeviation, calculation.InputParameters.DampingFactorExit.StandardDeviation); + AssertRoundedDouble(entity.SaturatedVolumicWeightOfCoverageLayerMean, calculation.InputParameters.SaturatedVolumicWeightOfCoverageLayer.Mean); + AssertRoundedDouble(entity.SaturatedVolumicWeightOfCoverageLayerStandardDeviation, calculation.InputParameters.SaturatedVolumicWeightOfCoverageLayer.StandardDeviation); + AssertRoundedDouble(entity.SaturatedVolumicWeightOfCoverageLayerShift, calculation.InputParameters.SaturatedVolumicWeightOfCoverageLayer.Shift); + AssertRoundedDouble(entity.Diameter70Mean, calculation.InputParameters.Diameter70.Mean); + AssertRoundedDouble(entity.Diameter70StandardDeviation, calculation.InputParameters.Diameter70.StandardDeviation); + AssertRoundedDouble(entity.DarcyPermeabilityMean, calculation.InputParameters.DarcyPermeability.Mean); + AssertRoundedDouble(entity.DarcyPermeabilityStandardDeviation, calculation.InputParameters.DarcyPermeability.StandardDeviation); + + Assert.IsNull(calculation.InputParameters.SurfaceLine); + Assert.IsNull(calculation.InputParameters.HydraulicBoundaryLocation); + Assert.IsNull(calculation.InputParameters.StochasticSoilModel); + Assert.IsNull(calculation.InputParameters.StochasticSoilProfile); + } + + [Test] + public void Read_EntityWithSurfaceLineInCollector_CalculationHasAlreadyReadSurfaceLine() + { + // Setup + var surfaceLine = new RingtoetsPipingSurfaceLine(); + surfaceLine.SetGeometry(new[] + { + new Point3D(1, 2, 3), + new Point3D(4, 5, 6) + }); + var surfaceLineEntity = new SurfaceLineEntity(); + var entity = new PipingCalculationEntity + { + SurfaceLineEntity = surfaceLineEntity, + EntryPointL = 1m, + ExitPointL = 2m, + DampingFactorExitMean = 1, + SaturatedVolumicWeightOfCoverageLayerMean = 1, + Diameter70Mean = 1, + DarcyPermeabilityMean = 1 + }; + + var collector = new ReadConversionCollector(); + collector.Read(surfaceLineEntity, surfaceLine); + + // Call + PipingCalculationScenario calculation = entity.Read(collector, new GeneralPipingInput()); + + // Assert + Assert.AreSame(surfaceLine, calculation.InputParameters.SurfaceLine); + } + + [Test] + public void Read_EntityWithSurfaceLineNotYetInCollector_CalculationWithCreatedSurfaceLineAndRegisteredNewEntities() + { + // Setup + var pointEntity1 = new SurfaceLinePointEntity + { + Order = 0, + SurfaceLinePointEntityId = 1, + X = 1m, + Y = 3m, + Z = 4m + }; + var pointEntity2 = new SurfaceLinePointEntity + { + Order = 1, + SurfaceLinePointEntityId = 2, + X = 7m, + Y = 10m, + Z = 11m + }; + + var surfaceLineEntity = new SurfaceLineEntity + { + SurfaceLineEntityId = 123, + SurfaceLinePointEntities = + { + pointEntity1, + pointEntity2 + } + }; + + var entity = new PipingCalculationEntity + { + SurfaceLineEntity = surfaceLineEntity, + EntryPointL = 1m, + ExitPointL = 2m, + DampingFactorExitMean = 1, + SaturatedVolumicWeightOfCoverageLayerMean = 1, + Diameter70Mean = 1, + DarcyPermeabilityMean = 1 + }; + + var collector = new ReadConversionCollector(); + + // Call + PipingCalculationScenario calculation = entity.Read(collector, new GeneralPipingInput()); + + // Assert + Assert.AreEqual(surfaceLineEntity.SurfaceLineEntityId, calculation.InputParameters.SurfaceLine.StorageId); + Assert.IsTrue(collector.Contains(surfaceLineEntity)); + Assert.IsTrue(collector.Contains(pointEntity1)); + Assert.IsTrue(collector.Contains(pointEntity2)); + } + + [Test] + public void Read_EntityWithHydraulicBoundaryLocationInCollector_CalculationHasAlreadyReadHydraulicBoundaryLocation() + { + // Setup + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "A", 1.1, 2.2); + var hydraulicLocationEntity = new HydraulicLocationEntity(); + var entity = new PipingCalculationEntity + { + HydraulicLocationEntity = hydraulicLocationEntity, + EntryPointL = 1m, + ExitPointL = 2m, + DampingFactorExitMean = 1, + SaturatedVolumicWeightOfCoverageLayerMean = 1, + Diameter70Mean = 1, + DarcyPermeabilityMean = 1 + }; + + var collector = new ReadConversionCollector(); + collector.Read(hydraulicLocationEntity, hydraulicBoundaryLocation); + + // Call + PipingCalculationScenario calculation = entity.Read(collector, new GeneralPipingInput()); + + // Assert + Assert.AreSame(hydraulicBoundaryLocation, calculation.InputParameters.HydraulicBoundaryLocation); + } + + [Test] + public void Read_EntityWithHydraulicBoundaryLocationNotYetInCollector_CalculationWithCreatedHydraulicBoundaryLocationAndRegisteredNewEntities() + { + // Setup + var hydraulicLocationEntity = new HydraulicLocationEntity + { + HydraulicLocationEntityId = 123, + Name = "A" + }; + + var entity = new PipingCalculationEntity + { + HydraulicLocationEntity = hydraulicLocationEntity, + EntryPointL = 1m, + ExitPointL = 2m, + DampingFactorExitMean = 1, + SaturatedVolumicWeightOfCoverageLayerMean = 1, + Diameter70Mean = 1, + DarcyPermeabilityMean = 1 + }; + + var collector = new ReadConversionCollector(); + + // Call + PipingCalculationScenario calculation = entity.Read(collector, new GeneralPipingInput()); + + // Assert + Assert.AreEqual(hydraulicLocationEntity.HydraulicLocationEntityId, calculation.InputParameters.HydraulicBoundaryLocation.StorageId); + Assert.IsTrue(collector.Contains(hydraulicLocationEntity)); + } + + [Test] + public void Read_EntityWithStochasticSoilModelEntityInCollector_CalculationHasAlreadyReadStochasticSoilModel() + { + // Setup + var stochasticSoilModel = new StochasticSoilModel(1, "A", "B"); + var stochasticSoilModelEntity = new StochasticSoilModelEntity(); + + var stochasticSoilProfile = new StochasticSoilProfile(1, SoilProfileType.SoilProfile1D, 1); + var stochasticSoilProfileEntity = new StochasticSoilProfileEntity + { + StochasticSoilModelEntity = stochasticSoilModelEntity + }; + + var entity = new PipingCalculationEntity + { + StochasticSoilProfileEntity = stochasticSoilProfileEntity, + EntryPointL = 1m, + ExitPointL = 2m, + DampingFactorExitMean = 1, + SaturatedVolumicWeightOfCoverageLayerMean = 1, + Diameter70Mean = 1, + DarcyPermeabilityMean = 1 + }; + + var collector = new ReadConversionCollector(); + collector.Read(stochasticSoilProfileEntity, stochasticSoilProfile); + collector.Read(stochasticSoilModelEntity, stochasticSoilModel); + + // Call + PipingCalculationScenario calculation = entity.Read(collector, new GeneralPipingInput()); + + // Assert + Assert.AreSame(stochasticSoilProfile, calculation.InputParameters.StochasticSoilProfile); + Assert.AreSame(stochasticSoilModel, calculation.InputParameters.StochasticSoilModel); + } + + [Test] + public void Read_EntityWithStochasticSoilProfileEntityNotYetInCollector_CalculationWithCreatedStochasticSoilProfileAndRegisteredNewEntities() + { + // Setup + var stochasticSoilProfileEntity = new StochasticSoilProfileEntity + { + StochasticSoilProfileEntityId = 546, + SoilProfileEntity = new SoilProfileEntity + { + SoilLayerEntities = + { + new SoilLayerEntity() + } + } + }; + + var stochasticSoilModelEntity = new StochasticSoilModelEntity + { + StochasticSoilModelEntityId = 75, + StochasticSoilProfileEntities = + { + stochasticSoilProfileEntity + } + }; + stochasticSoilProfileEntity.StochasticSoilModelEntity = stochasticSoilModelEntity; + + + var entity = new PipingCalculationEntity + { + StochasticSoilProfileEntity = stochasticSoilProfileEntity, + EntryPointL = 1m, + ExitPointL = 2m, + DampingFactorExitMean = 1, + SaturatedVolumicWeightOfCoverageLayerMean = 1, + Diameter70Mean = 1, + DarcyPermeabilityMean = 1 + }; + + var collector = new ReadConversionCollector(); + + // Call + PipingCalculationScenario calculation = entity.Read(collector, new GeneralPipingInput()); + + // Assert + Assert.AreEqual(stochasticSoilProfileEntity.StochasticSoilProfileEntityId, calculation.InputParameters.StochasticSoilProfile.StorageId); + Assert.AreEqual(stochasticSoilModelEntity.StochasticSoilModelEntityId, calculation.InputParameters.StochasticSoilModel.StorageId); + Assert.IsTrue(collector.Contains(stochasticSoilProfileEntity)); + Assert.IsTrue(collector.Contains(stochasticSoilModelEntity)); + } + + private void AssertRoundedDouble(decimal expectedValue, RoundedDouble actualValue) + { + Assert.AreEqual(Convert.ToDouble(expectedValue), actualValue, actualValue.GetAccuracy()); + } + + private static void AssertRoundedDouble(double expectedValue, RoundedDouble actualValue) + { + Assert.AreEqual(expectedValue, actualValue, actualValue.GetAccuracy()); + } + + private static decimal? ToNullableDecimal(double entryPoint) + { + if (double.IsNaN(entryPoint)) + { + return null; + } + return Convert.ToDecimal(entryPoint); + } + + private static decimal GetRandomDecimalInRange(Random random, double lowerLimit, double upperLimit) + { + var difference = upperLimit - lowerLimit; + return Convert.ToDecimal(lowerLimit + random.NextDouble() * difference); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/ReadConversionCollectorTest.cs =================================================================== diff -u -r54e6baff4fab535777949f737314f052853e818a -r32d32b83fc8e0c9b4849361af987da0170549146 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/ReadConversionCollectorTest.cs (.../ReadConversionCollectorTest.cs) (revision 54e6baff4fab535777949f737314f052853e818a) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/ReadConversionCollectorTest.cs (.../ReadConversionCollectorTest.cs) (revision 32d32b83fc8e0c9b4849361af987da0170549146) @@ -27,13 +27,166 @@ using Core.Common.Base.Geometry; using NUnit.Framework; + +using Ringtoets.HydraRing.Data; +using Ringtoets.Piping.Data; using Ringtoets.Piping.KernelWrapper.TestUtil; +using Ringtoets.Piping.Primitives; namespace Application.Ringtoets.Storage.Test.Read { [TestFixture] public class ReadConversionCollectorTest { + #region StochasticSoilProfileEntity: Read, Contains, Get + + [Test] + public void Contains_WithoutStochasticSoilProfileEntity_ArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => collector.Contains((StochasticSoilProfileEntity)null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Contains_StochasticSoilProfileEntityAdded_True() + { + // Setup + var collector = new ReadConversionCollector(); + var entity = new StochasticSoilProfileEntity(); + collector.Read(entity, new StochasticSoilProfile(1, SoilProfileType.SoilProfile1D, 1)); + + // Call + var result = collector.Contains(entity); + + // Assert + Assert.IsTrue(result); + } + + [Test] + public void Contains_NoStochasticSoilProfileEntityAdded_False() + { + // Setup + var collector = new ReadConversionCollector(); + var entity = new StochasticSoilProfileEntity(); + + // Call + var result = collector.Contains(entity); + + // Assert + Assert.IsFalse(result); + } + + [Test] + public void Contains_OtherStochasticSoilProfileEntityAdded_False() + { + // Setup + var collector = new ReadConversionCollector(); + var entity = new StochasticSoilProfileEntity(); + collector.Read(new StochasticSoilProfileEntity(), new StochasticSoilProfile(0.4, SoilProfileType.SoilProfile2D, 2)); + + // Call + var result = collector.Contains(entity); + + // Assert + Assert.IsFalse(result); + } + + [Test] + public void Get_WithoutStochasticSoilProfileEntity_ThrowArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => collector.Get((StochasticSoilProfileEntity)null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Get_StochasticSoilProfileEntityAdded_ReturnsReadStochasticSoilProfile() + { + // Setup + var collector = new ReadConversionCollector(); + var profile = new StochasticSoilProfile(0.5, SoilProfileType.SoilProfile2D, 2); + var entity = new StochasticSoilProfileEntity(); + collector.Read(entity, profile); + + // Call + StochasticSoilProfile result = collector.Get(entity); + + // Assert + Assert.AreSame(profile, result); + } + + [Test] + public void Get_NoStochasticSoilProfileEntityAdded_ThrowsInvalidOperationException() + { + // Setup + var collector = new ReadConversionCollector(); + var entity = new StochasticSoilProfileEntity(); + + // Call + TestDelegate test = () => collector.Get(entity); + + // Assert + Assert.Throws(test); + } + + [Test] + public void Get_OtherStochasticSoilProfileEntityAdded_ThrowsInvalidOperationException() + { + // Setup + var collector = new ReadConversionCollector(); + var entity = new StochasticSoilProfileEntity(); + collector.Read(new StochasticSoilProfileEntity(), new StochasticSoilProfile(0.7, SoilProfileType.SoilProfile1D, 6)); + + // Call + TestDelegate test = () => collector.Get(entity); + + // Assert + Assert.Throws(test); + } + + [Test] + public void Read_WithNullStochasticSoilProfileEntity_ThrowsArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => collector.Read(null, new StochasticSoilProfile(0.7, SoilProfileType.SoilProfile1D, 6)); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Read_WithNullStochasticSoilProfile_ThrowsArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => collector.Read(new StochasticSoilProfileEntity(), null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + + #endregion + #region SoilProfileEntity: Read, Contains, Get [Test] @@ -183,6 +336,168 @@ #endregion + #region SurfaceLineEntity: Read, Contains, Get + + [Test] + public void Contains_SurfaceLineEntityIsNull_ThrowArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate call = () => collector.Contains((SurfaceLineEntity)null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Contains_SurfaceLineEntityAdded_True() + { + // Setup + var entity = new SurfaceLineEntity(); + var model = new RingtoetsPipingSurfaceLine(); + + var collector = new ReadConversionCollector(); + collector.Read(entity, model); + + // Call + var hasEntity = collector.Contains(entity); + + // Assert + Assert.IsTrue(hasEntity); + } + + [Test] + public void Contains_SurfaceLineEntityNotAdded_False() + { + // Setup + var entity = new SurfaceLineEntity(); + + var collector = new ReadConversionCollector(); + + // Call + var hasEntity = collector.Contains(entity); + + // Assert + Assert.IsFalse(hasEntity); + } + + [Test] + public void Contains_OtherSurfaceLineEntityAdded_False() + { + // Setup + var registeredEntity = new SurfaceLineEntity(); + var model = new RingtoetsPipingSurfaceLine(); + + var collector = new ReadConversionCollector(); + collector.Read(registeredEntity, model); + + var unregisteredEntity = new SurfaceLineEntity(); + + // Call + var hasEntity = collector.Contains(unregisteredEntity); + + // Assert + Assert.IsFalse(hasEntity); + } + + [Test] + public void Get_SurfaceLineEntityIsNull_ThrowArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate call = () => collector.Get((SurfaceLineEntity)null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Get_SurfaceLineEntityAdded_ReturnsRingtoetsPipingSurfaceLine() + { + // Setup + var entity = new SurfaceLineEntity(); + var model = new RingtoetsPipingSurfaceLine(); + + var collector = new ReadConversionCollector(); + collector.Read(entity, model); + + // Call + RingtoetsPipingSurfaceLine retrievedGeometryPoint = collector.Get(entity); + + // Assert + Assert.AreSame(model, retrievedGeometryPoint); + } + + [Test] + public void Get_SurfaceLineEntityNotAdded_ThrowInvalidOperationException() + { + // Setup + var entity = new SurfaceLineEntity(); + + var collector = new ReadConversionCollector(); + + // Call + TestDelegate call = () => collector.Get(entity); + + // Assert + Assert.Throws(call); + } + + [Test] + public void Get_DifferentSurfaceLineEntityAdded_ThrowsInvalidOperationException() + { + // Setup + var registeredEntity = new SurfaceLineEntity(); + var model = new RingtoetsPipingSurfaceLine(); + + var collector = new ReadConversionCollector(); + collector.Read(registeredEntity, model); + + var unregisteredEntity = new SurfaceLineEntity(); + + // Call + TestDelegate call = () => collector.Get(unregisteredEntity); + + // Assert + Assert.Throws(call); + } + + [Test] + public void Read_SurfaceLineEntityIsNull_ThrowsArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => collector.Read(null, new RingtoetsPipingSurfaceLine()); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Read_RingtoetsPipingSurfaceLineIsNull_ThrowsArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => collector.Read(new SurfaceLineEntity(), null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + + #endregion + #region SurfaceLinePointEntity: Read, Contains, Get [Test] @@ -344,5 +659,154 @@ } #endregion + + #region HydraulicLocationEntity: Read, Contains, Get + + [Test] + public void Contains_WithoutHydraulicLocationEntity_ArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => collector.Contains((HydraulicLocationEntity)null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Contains_HydraulicLocationEntityAdded_True() + { + // Setup + var collector = new ReadConversionCollector(); + var entity = new HydraulicLocationEntity(); + collector.Read(entity, new HydraulicBoundaryLocation(1, "A", 1, 2)); + + // Call + var result = collector.Contains(entity); + + // Assert + Assert.IsTrue(result); + } + + [Test] + public void Contains_NoHydraulicLocationEntityAdded_False() + { + // Setup + var collector = new ReadConversionCollector(); + var entity = new HydraulicLocationEntity(); + + // Call + var result = collector.Contains(entity); + + // Assert + Assert.IsFalse(result); + } + + [Test] + public void Contains_OtherHydraulicLocationEntityAdded_False() + { + // Setup + var collector = new ReadConversionCollector(); + var entity = new HydraulicLocationEntity(); + collector.Read(new HydraulicLocationEntity(), new HydraulicBoundaryLocation(1, "A", 2, 3)); + + // Call + var result = collector.Contains(entity); + + // Assert + Assert.IsFalse(result); + } + + [Test] + public void Get_WithoutHydraulicLocationEntity_ThrowArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => collector.Get((HydraulicLocationEntity)null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Get_HydraulicLocationEntityAdded_ReturnsHydraulicBoundaryLocation() + { + // Setup + var collector = new ReadConversionCollector(); + var profile = new HydraulicBoundaryLocation(1, "A", 1, 1); + var entity = new HydraulicLocationEntity(); + collector.Read(entity, profile); + + // Call + var result = collector.Get(entity); + + // Assert + Assert.AreSame(profile, result); + } + + [Test] + public void Get_NoHydraulicLocationEntityAdded_ThrowsInvalidOperationException() + { + // Setup + var collector = new ReadConversionCollector(); + var entity = new HydraulicLocationEntity(); + + // Call + TestDelegate test = () => collector.Get(entity); + + // Assert + Assert.Throws(test); + } + + [Test] + public void Get_OtherHydraulicLocationEntityAdded_ThrowsInvalidOperationException() + { + // Setup + var collector = new ReadConversionCollector(); + var entity = new HydraulicLocationEntity(); + collector.Read(new HydraulicLocationEntity(), new HydraulicBoundaryLocation(1,"A", 1, 1)); + + // Call + TestDelegate test = () => collector.Get(entity); + + // Assert + Assert.Throws(test); + } + + [Test] + public void Read_WithNullHydraulicLocationEntity_ThrowsArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => collector.Read(null, new HydraulicBoundaryLocation(1, "A", 1, 1)); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Read_WithNullHydraulicBoundaryLocation_ThrowsArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => collector.Read(new HydraulicLocationEntity(), null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + + #endregion } } \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/StochasticSoilModelEntityReadExtensionsTest.cs =================================================================== diff -u -r4478bdf539df278f9e2aac0f9fe683c34ac55335 -r32d32b83fc8e0c9b4849361af987da0170549146 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/StochasticSoilModelEntityReadExtensionsTest.cs (.../StochasticSoilModelEntityReadExtensionsTest.cs) (revision 4478bdf539df278f9e2aac0f9fe683c34ac55335) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/StochasticSoilModelEntityReadExtensionsTest.cs (.../StochasticSoilModelEntityReadExtensionsTest.cs) (revision 32d32b83fc8e0c9b4849361af987da0170549146) @@ -24,6 +24,8 @@ using Application.Ringtoets.Storage.Read; using NUnit.Framework; +using Ringtoets.Piping.Data; + namespace Application.Ringtoets.Storage.Test.Read { [TestFixture] @@ -127,5 +129,21 @@ // Assert Assert.AreEqual(2, model.Geometry.Count); } + + [Test] + public void Read_SameStochasticSoilModelEntityMultipleTimes_ReturnSameStochasticSoilModel() + { + // Setup + var entity = new StochasticSoilModelEntity(); + + var collector = new ReadConversionCollector(); + + // Call + StochasticSoilModel soilModel1 = entity.Read(collector); + StochasticSoilModel soilModel2 = entity.Read(collector); + + // Assert + Assert.AreSame(soilModel1, soilModel2); + } } } \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/StochasticSoilProfileEntityReadExtensionsTest.cs =================================================================== diff -u -rfe68c3f7cae5946b93d9e27eb532b176a6b26b84 -r32d32b83fc8e0c9b4849361af987da0170549146 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/StochasticSoilProfileEntityReadExtensionsTest.cs (.../StochasticSoilProfileEntityReadExtensionsTest.cs) (revision fe68c3f7cae5946b93d9e27eb532b176a6b26b84) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/StochasticSoilProfileEntityReadExtensionsTest.cs (.../StochasticSoilProfileEntityReadExtensionsTest.cs) (revision 32d32b83fc8e0c9b4849361af987da0170549146) @@ -24,6 +24,8 @@ using Application.Ringtoets.Storage.Read; using NUnit.Framework; +using Ringtoets.Piping.Data; + namespace Application.Ringtoets.Storage.Test.Read { [TestFixture] @@ -106,5 +108,30 @@ Assert.AreNotSame(firstProfile, secondProfile); Assert.AreSame(firstProfile.SoilProfile, secondProfile.SoilProfile); } + + [Test] + public void Read_SameStochasticSoilProfileEntityMultipleTimes_ReturnSameStochasticSoilProfile() + { + // Setup + var entity = new StochasticSoilProfileEntity + { + SoilProfileEntity = new SoilProfileEntity + { + SoilLayerEntities = + { + new SoilLayerEntity() + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + StochasticSoilProfile profile1 = entity.Read(collector); + StochasticSoilProfile profile2 = entity.Read(collector); + + // Assert + Assert.AreSame(profile1, profile2); + } } } \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/SurfaceLineEntityReadExtensionsTest.cs =================================================================== diff -u -rae6f0c6b534ca650e160ae6d9c0bc90369d25c68 -r32d32b83fc8e0c9b4849361af987da0170549146 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/SurfaceLineEntityReadExtensionsTest.cs (.../SurfaceLineEntityReadExtensionsTest.cs) (revision ae6f0c6b534ca650e160ae6d9c0bc90369d25c68) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/SurfaceLineEntityReadExtensionsTest.cs (.../SurfaceLineEntityReadExtensionsTest.cs) (revision 32d32b83fc8e0c9b4849361af987da0170549146) @@ -423,5 +423,26 @@ Assert.AreSame(geometryPoint, surfaceLine.DitchDikeSide); Assert.AreSame(geometryPoint, surfaceLine.DitchPolderSide); } + + [Test] + public void Read_SurfaceLineEntityReadMultipleTimes_ReturnSameSurfaceLine() + { + // Setup + var collector = new ReadConversionCollector(); + + const long id = 9348765; + + var entity = new SurfaceLineEntity + { + SurfaceLineEntityId = id + }; + + // Call + RingtoetsPipingSurfaceLine surfaceLine1 = entity.Read(collector); + RingtoetsPipingSurfaceLine surfaceLine2 = entity.Read(collector); + + // Assert + Assert.AreSame(surfaceLine1, surfaceLine2); + } } } \ No newline at end of file