Index: Riskeer/Storage/src/Riskeer.Storage.Core/Create/CalculationGroupCreateExtensions.cs =================================================================== diff -u -r5c6a5f8b9901e77fd2d9fadc1fd482468e2137c8 -r1eb9ed53b927cff7ee19afe65f9d6cd2431e08ce --- Riskeer/Storage/src/Riskeer.Storage.Core/Create/CalculationGroupCreateExtensions.cs (.../CalculationGroupCreateExtensions.cs) (revision 5c6a5f8b9901e77fd2d9fadc1fd482468e2137c8) +++ Riskeer/Storage/src/Riskeer.Storage.Core/Create/CalculationGroupCreateExtensions.cs (.../CalculationGroupCreateExtensions.cs) (revision 1eb9ed53b927cff7ee19afe65f9d6cd2431e08ce) @@ -34,7 +34,7 @@ using Riskeer.Storage.Core.Create.GrassCoverErosionInwards; using Riskeer.Storage.Core.Create.GrassCoverErosionOutwards; using Riskeer.Storage.Core.Create.MacroStabilityInwards; -using Riskeer.Storage.Core.Create.Piping; +using Riskeer.Storage.Core.Create.Piping.SemiProbabilistic; using Riskeer.Storage.Core.Create.StabilityStoneCover; using Riskeer.Storage.Core.Create.WaveImpactAsphaltCover; using Riskeer.Storage.Core.DbContext; Index: Riskeer/Storage/src/Riskeer.Storage.Core/Create/Piping/SemiProbabilistic/SemiProbabilisticPipingCalculationScenarioCreateExtensions.cs =================================================================== diff -u --- Riskeer/Storage/src/Riskeer.Storage.Core/Create/Piping/SemiProbabilistic/SemiProbabilisticPipingCalculationScenarioCreateExtensions.cs (revision 0) +++ Riskeer/Storage/src/Riskeer.Storage.Core/Create/Piping/SemiProbabilistic/SemiProbabilisticPipingCalculationScenarioCreateExtensions.cs (revision 1eb9ed53b927cff7ee19afe65f9d6cd2431e08ce) @@ -0,0 +1,107 @@ +// Copyright (C) Stichting Deltares 2019. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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 Core.Common.Util.Extensions; +using Riskeer.Piping.Data.SemiProbabilistic; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Create.Piping.SemiProbabilistic +{ + /// + /// Extension methods for related to creating + /// a . + /// + internal static class SemiProbabilisticPipingCalculationScenarioCreateExtensions + { + /// + /// Creates a based on the information of the . + /// + /// The piping calculation to create a database entity for. + /// The object keeping track of create operations. + /// The index at which resides within its parent. + /// A new . + /// Thrown when is null. + public static PipingCalculationEntity Create(this SemiProbabilisticPipingCalculationScenario calculation, PersistenceRegistry registry, int order) + { + if (registry == null) + { + throw new ArgumentNullException(nameof(registry)); + } + + var entity = new PipingCalculationEntity + { + RelevantForScenario = Convert.ToByte(calculation.IsRelevant), + ScenarioContribution = calculation.Contribution.ToNaNAsNull(), + Name = calculation.Name.DeepClone(), + Comments = calculation.Comments.Body.DeepClone(), + Order = order + }; + SetInputParametersToEntity(entity, calculation.InputParameters, registry); + AddEntityForPipingOutput(entity, calculation.Output); + + return entity; + } + + private static void SetInputParametersToEntity(PipingCalculationEntity entity, SemiProbabilisticPipingInput inputParameters, PersistenceRegistry registry) + { + if (inputParameters.SurfaceLine != null) + { + entity.SurfaceLineEntity = registry.Get(inputParameters.SurfaceLine); + } + + SetHydraulicBoundaryLocationInputToEntity(entity, inputParameters, registry); + + if (inputParameters.StochasticSoilProfile != null) + { + entity.PipingStochasticSoilProfileEntity = registry.Get(inputParameters.StochasticSoilProfile); + } + + entity.ExitPointL = inputParameters.ExitPointL.Value.ToNaNAsNull(); + entity.EntryPointL = inputParameters.EntryPointL.Value.ToNaNAsNull(); + + entity.PhreaticLevelExitMean = inputParameters.PhreaticLevelExit.Mean.ToNaNAsNull(); + entity.PhreaticLevelExitStandardDeviation = inputParameters.PhreaticLevelExit.StandardDeviation.ToNaNAsNull(); + + entity.DampingFactorExitMean = inputParameters.DampingFactorExit.Mean.ToNaNAsNull(); + entity.DampingFactorExitStandardDeviation = inputParameters.DampingFactorExit.StandardDeviation.ToNaNAsNull(); + } + + private static void SetHydraulicBoundaryLocationInputToEntity(PipingCalculationEntity entity, SemiProbabilisticPipingInput inputParameters, PersistenceRegistry registry) + { + entity.UseAssessmentLevelManualInput = Convert.ToByte(inputParameters.UseAssessmentLevelManualInput); + entity.AssessmentLevel = inputParameters.AssessmentLevel.ToNaNAsNull(); + + if (inputParameters.HydraulicBoundaryLocation != null) + { + entity.HydraulicLocationEntity = registry.Get(inputParameters.HydraulicBoundaryLocation); + } + } + + private static void AddEntityForPipingOutput(PipingCalculationEntity entity, SemiProbabilisticPipingOutput output) + { + if (output != null) + { + entity.PipingCalculationOutputEntities.Add(output.Create()); + } + } + } +} \ No newline at end of file Index: Riskeer/Storage/src/Riskeer.Storage.Core/Create/Piping/SemiProbabilistic/SemiProbabilisticPipingOutputCreateExtensions.cs =================================================================== diff -u --- Riskeer/Storage/src/Riskeer.Storage.Core/Create/Piping/SemiProbabilistic/SemiProbabilisticPipingOutputCreateExtensions.cs (revision 0) +++ Riskeer/Storage/src/Riskeer.Storage.Core/Create/Piping/SemiProbabilistic/SemiProbabilisticPipingOutputCreateExtensions.cs (revision 1eb9ed53b927cff7ee19afe65f9d6cd2431e08ce) @@ -0,0 +1,63 @@ +// Copyright (C) Stichting Deltares 2019. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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 Riskeer.Piping.Data.SemiProbabilistic; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Create.Piping.SemiProbabilistic +{ + /// + /// Extension methods for related to creating a . + /// + internal static class SemiProbabilisticPipingOutputCreateExtensions + { + /// + /// Creates a based on the information + /// of the . + /// + /// The calculation output for piping failure mechanism to + /// create a database entity for. + /// A new . + /// Thrown when + /// is null. + public static PipingCalculationOutputEntity Create(this SemiProbabilisticPipingOutput output) + { + if (output == null) + { + throw new ArgumentNullException(nameof(output)); + } + + var entity = new PipingCalculationOutputEntity + { + HeaveFactorOfSafety = output.HeaveFactorOfSafety.ToNaNAsNull(), + SellmeijerFactorOfSafety = output.SellmeijerFactorOfSafety.ToNaNAsNull(), + UpliftFactorOfSafety = output.UpliftFactorOfSafety.ToNaNAsNull(), + UpliftEffectiveStress = output.UpliftEffectiveStress.ToNaNAsNull(), + HeaveGradient = output.HeaveGradient.ToNaNAsNull(), + SellmeijerCreepCoefficient = output.SellmeijerCreepCoefficient.ToNaNAsNull(), + SellmeijerCriticalFall = output.SellmeijerCriticalFall.ToNaNAsNull(), + SellmeijerReducedFall = output.SellmeijerReducedFall.ToNaNAsNull() + }; + return entity; + } + } +} \ No newline at end of file Fisheye: Tag 1eb9ed53b927cff7ee19afe65f9d6cd2431e08ce refers to a dead (removed) revision in file `Riskeer/Storage/src/Riskeer.Storage.Core/Create/Piping/SemiProbabilisticPipingCalculationScenarioCreateExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1eb9ed53b927cff7ee19afe65f9d6cd2431e08ce refers to a dead (removed) revision in file `Riskeer/Storage/src/Riskeer.Storage.Core/Create/Piping/SemiProbabilisticPipingOutputCreateExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/Storage/src/Riskeer.Storage.Core/Read/CalculationGroupEntityReadExtensions.cs =================================================================== diff -u -r86594ccd7329d320872573a1d066fe18959d3cea -r1eb9ed53b927cff7ee19afe65f9d6cd2431e08ce --- Riskeer/Storage/src/Riskeer.Storage.Core/Read/CalculationGroupEntityReadExtensions.cs (.../CalculationGroupEntityReadExtensions.cs) (revision 86594ccd7329d320872573a1d066fe18959d3cea) +++ Riskeer/Storage/src/Riskeer.Storage.Core/Read/CalculationGroupEntityReadExtensions.cs (.../CalculationGroupEntityReadExtensions.cs) (revision 1eb9ed53b927cff7ee19afe65f9d6cd2431e08ce) @@ -30,6 +30,7 @@ using Riskeer.Storage.Core.Read.HeightStructures; using Riskeer.Storage.Core.Read.MacroStabilityInwards; using Riskeer.Storage.Core.Read.Piping; +using Riskeer.Storage.Core.Read.Piping.SemiProbabilistic; using Riskeer.Storage.Core.Read.StabilityPointStructures; using Riskeer.Storage.Core.Read.StabilityStoneCover; using Riskeer.Storage.Core.Read.WaveImpactAsphaltCover; Index: Riskeer/Storage/src/Riskeer.Storage.Core/Read/Piping/SemiProbabilistic/SemiProbabilisticPipingCalculationEntityReadExtensions.cs =================================================================== diff -u --- Riskeer/Storage/src/Riskeer.Storage.Core/Read/Piping/SemiProbabilistic/SemiProbabilisticPipingCalculationEntityReadExtensions.cs (revision 0) +++ Riskeer/Storage/src/Riskeer.Storage.Core/Read/Piping/SemiProbabilistic/SemiProbabilisticPipingCalculationEntityReadExtensions.cs (revision 1eb9ed53b927cff7ee19afe65f9d6cd2431e08ce) @@ -0,0 +1,110 @@ +// Copyright (C) Stichting Deltares 2019. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Linq; +using Core.Common.Base.Data; +using Riskeer.Piping.Data; +using Riskeer.Piping.Data.SemiProbabilistic; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Read.Piping.SemiProbabilistic +{ + /// + /// This class defines extension methods for read operations for a + /// based on the . + /// + internal static class SemiProbabilisticPipingCalculationEntityReadExtensions + { + /// + /// 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. + public static SemiProbabilisticPipingCalculationScenario Read(this PipingCalculationEntity entity, ReadConversionCollector collector, + GeneralPipingInput generalInputParameters) + { + if (collector == null) + { + throw new ArgumentNullException(nameof(collector)); + } + + var calculation = new SemiProbabilisticPipingCalculationScenario(generalInputParameters) + { + IsRelevant = Convert.ToBoolean(entity.RelevantForScenario), + Contribution = (RoundedDouble) entity.ScenarioContribution.ToNullAsNaN(), + Name = entity.Name, + Comments = + { + Body = entity.Comments + } + }; + ReadInputParameters(calculation.InputParameters, entity, collector); + ReadCalculationOutputs(calculation, entity); + + return calculation; + } + + private static void ReadCalculationOutputs(SemiProbabilisticPipingCalculationScenario calculation, PipingCalculationEntity entity) + { + PipingCalculationOutputEntity calculationOutputEntity = entity.PipingCalculationOutputEntities.FirstOrDefault(); + if (calculationOutputEntity != null) + { + calculation.Output = calculationOutputEntity.Read(); + } + } + + private static void ReadInputParameters(SemiProbabilisticPipingInput inputParameters, PipingCalculationEntity entity, ReadConversionCollector collector) + { + if (entity.SurfaceLineEntity != null) + { + inputParameters.SurfaceLine = entity.SurfaceLineEntity.ReadAsPipingSurfaceLine(collector); + } + + inputParameters.UseAssessmentLevelManualInput = Convert.ToBoolean(entity.UseAssessmentLevelManualInput); + inputParameters.AssessmentLevel = (RoundedDouble) entity.AssessmentLevel.ToNullAsNaN(); + + if (entity.HydraulicLocationEntity != null) + { + inputParameters.HydraulicBoundaryLocation = entity.HydraulicLocationEntity.Read(collector); + } + + if (entity.PipingStochasticSoilProfileEntity != null) + { + inputParameters.StochasticSoilModel = entity.PipingStochasticSoilProfileEntity.StochasticSoilModelEntity.ReadAsPipingStochasticSoilModel(collector); + inputParameters.StochasticSoilProfile = entity.PipingStochasticSoilProfileEntity.Read(collector); + } + + inputParameters.EntryPointL = (RoundedDouble) entity.EntryPointL.ToNullAsNaN(); + inputParameters.ExitPointL = (RoundedDouble) entity.ExitPointL.ToNullAsNaN(); + inputParameters.PhreaticLevelExit.Mean = (RoundedDouble) entity.PhreaticLevelExitMean.ToNullAsNaN(); + inputParameters.PhreaticLevelExit.StandardDeviation = (RoundedDouble) entity.PhreaticLevelExitStandardDeviation.ToNullAsNaN(); + inputParameters.DampingFactorExit.Mean = (RoundedDouble) entity.DampingFactorExitMean.ToNullAsNaN(); + inputParameters.DampingFactorExit.StandardDeviation = (RoundedDouble) entity.DampingFactorExitStandardDeviation.ToNullAsNaN(); + } + } +} \ No newline at end of file Index: Riskeer/Storage/src/Riskeer.Storage.Core/Read/Piping/SemiProbabilistic/SemiProbabilisticPipingCalculationOutputEntityReadExtensions.cs =================================================================== diff -u --- Riskeer/Storage/src/Riskeer.Storage.Core/Read/Piping/SemiProbabilistic/SemiProbabilisticPipingCalculationOutputEntityReadExtensions.cs (revision 0) +++ Riskeer/Storage/src/Riskeer.Storage.Core/Read/Piping/SemiProbabilistic/SemiProbabilisticPipingCalculationOutputEntityReadExtensions.cs (revision 1eb9ed53b927cff7ee19afe65f9d6cd2431e08ce) @@ -0,0 +1,63 @@ +// Copyright (C) Stichting Deltares 2019. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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 Riskeer.Piping.Data.SemiProbabilistic; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Read.Piping.SemiProbabilistic +{ + /// + /// This class defines extension methods for read operations for an + /// based on the . + /// + internal static class SemiProbabilisticPipingCalculationOutputEntityReadExtensions + { + /// + /// Read the and use the information to + /// construct a . + /// + /// The to create + /// for. + /// A new . + /// Thrown when + /// is null. + public static SemiProbabilisticPipingOutput Read(this PipingCalculationOutputEntity entity) + { + if (entity == null) + { + throw new ArgumentNullException(nameof(entity)); + } + + return new SemiProbabilisticPipingOutput(new SemiProbabilisticPipingOutput.ConstructionProperties + { + UpliftFactorOfSafety = entity.UpliftFactorOfSafety.ToNullAsNaN(), + HeaveFactorOfSafety = entity.HeaveFactorOfSafety.ToNullAsNaN(), + SellmeijerFactorOfSafety = entity.SellmeijerFactorOfSafety.ToNullAsNaN(), + UpliftEffectiveStress = entity.UpliftEffectiveStress.ToNullAsNaN(), + HeaveGradient = entity.HeaveGradient.ToNullAsNaN(), + SellmeijerCreepCoefficient = entity.SellmeijerCreepCoefficient.ToNullAsNaN(), + SellmeijerCriticalFall = entity.SellmeijerCriticalFall.ToNullAsNaN(), + SellmeijerReducedFall = entity.SellmeijerReducedFall.ToNullAsNaN() + }); + } + } +} \ No newline at end of file Fisheye: Tag 1eb9ed53b927cff7ee19afe65f9d6cd2431e08ce refers to a dead (removed) revision in file `Riskeer/Storage/src/Riskeer.Storage.Core/Read/Piping/SemiProbabilisticPipingCalculationEntityReadExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1eb9ed53b927cff7ee19afe65f9d6cd2431e08ce refers to a dead (removed) revision in file `Riskeer/Storage/src/Riskeer.Storage.Core/Read/Piping/SemiProbabilisticPipingCalculationOutputEntityReadExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/SemiProbabilistic/SemiProbabilisticPipingCalculationScenarioCreateExtensionsTest.cs =================================================================== diff -u --- Riskeer/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/SemiProbabilistic/SemiProbabilisticPipingCalculationScenarioCreateExtensionsTest.cs (revision 0) +++ Riskeer/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/SemiProbabilistic/SemiProbabilisticPipingCalculationScenarioCreateExtensionsTest.cs (revision 1eb9ed53b927cff7ee19afe65f9d6cd2431e08ce) @@ -0,0 +1,273 @@ +// Copyright (C) Stichting Deltares 2019. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Linq; +using Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Riskeer.Common.Data.Hydraulics; +using Riskeer.Common.Data.TestUtil; +using Riskeer.Piping.Data; +using Riskeer.Piping.Data.SemiProbabilistic; +using Riskeer.Piping.Data.SoilProfile; +using Riskeer.Piping.Data.TestUtil; +using Riskeer.Piping.Primitives; +using Riskeer.Piping.Primitives.TestUtil; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.Piping; +using Riskeer.Storage.Core.Create.Piping.SemiProbabilistic; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.Piping.SemiProbabilistic +{ + [TestFixture] + public class SemiProbabilisticPipingCalculationScenarioCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryIsNull_ThrowArgumentNullException() + { + // Setup + var calculation = new SemiProbabilisticPipingCalculationScenario(new GeneralPipingInput()); + + // Call + void Call() => calculation.Create(null, 0); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("registry", exception.ParamName); + } + + [Test] + [TestCase(true, false, 0.0, "A", "", 2.2, 0.0, 5.8, 123, 827364)] + [TestCase(false, true, 1.0, null, null, double.NaN, double.NaN, double.NaN, 980754, 231)] + public void Create_PipingCalculationScenarioWithPropertiesSet_ReturnPipingCalculationEntity( + bool isRelevant, bool useAssessmentLevelManualInput, double contribution, string name, string comments, + double exitPoint, double entryPoint, double assessmentLevel, int order, int randomSeed) + { + // Setup + var random = new Random(randomSeed); + + var calculation = new SemiProbabilisticPipingCalculationScenario(new GeneralPipingInput()) + { + IsRelevant = isRelevant, + Contribution = (RoundedDouble) contribution, + Name = name, + Comments = + { + Body = comments + }, + InputParameters = + { + ExitPointL = (RoundedDouble) exitPoint, + EntryPointL = (RoundedDouble) entryPoint, + PhreaticLevelExit = + { + Mean = random.NextRoundedDouble(-9999.9999, 9999.9999), + StandardDeviation = random.NextRoundedDouble(1e-6, 9999.9999) + }, + DampingFactorExit = + { + Mean = random.NextRoundedDouble(1e-6, 9999.9999), + StandardDeviation = random.NextRoundedDouble(1e-6, 9999.9999) + }, + UseAssessmentLevelManualInput = useAssessmentLevelManualInput, + AssessmentLevel = (RoundedDouble) assessmentLevel + } + }; + + var registry = new PersistenceRegistry(); + + // Call + PipingCalculationEntity entity = calculation.Create(registry, order); + + // Assert + Assert.AreEqual(Convert.ToByte(isRelevant), entity.RelevantForScenario); + Assert.AreEqual(contribution, entity.ScenarioContribution); + Assert.AreEqual(name, entity.Name); + Assert.AreEqual(comments, entity.Comments); + + Assert.AreEqual(exitPoint.ToNaNAsNull(), entity.ExitPointL); + Assert.AreEqual(entryPoint.ToNaNAsNull(), entity.EntryPointL); + + SemiProbabilisticPipingInput input = calculation.InputParameters; + Assert.AreEqual(input.PhreaticLevelExit.Mean.Value, entity.PhreaticLevelExitMean); + Assert.AreEqual(input.PhreaticLevelExit.StandardDeviation.Value, entity.PhreaticLevelExitStandardDeviation); + Assert.AreEqual(input.DampingFactorExit.Mean.Value, entity.DampingFactorExitMean); + Assert.AreEqual(input.DampingFactorExit.StandardDeviation.Value, entity.DampingFactorExitStandardDeviation); + + Assert.AreEqual(Convert.ToByte(input.UseAssessmentLevelManualInput), entity.UseAssessmentLevelManualInput); + Assert.AreEqual(input.AssessmentLevel.ToNaNAsNull(), entity.AssessmentLevel); + + Assert.AreEqual(order, entity.Order); + Assert.AreEqual(0, entity.PipingCalculationEntityId); + Assert.IsNull(entity.CalculationGroupEntity); + + Assert.IsNull(entity.SurfaceLineEntity); + Assert.IsNull(entity.PipingStochasticSoilProfileEntity); + Assert.IsNull(entity.HydraulicLocationEntityId); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string name = "A"; + const string comments = "B"; + var calculation = new SemiProbabilisticPipingCalculationScenario(new GeneralPipingInput()) + { + Name = name, + Comments = + { + Body = comments + } + }; + + var registry = new PersistenceRegistry(); + + // Call + PipingCalculationEntity entity = calculation.Create(registry, 0); + + // Assert + TestHelper.AssertAreEqualButNotSame(name, entity.Name); + TestHelper.AssertAreEqualButNotSame(comments, entity.Comments); + } + + [Test] + public void Create_HasSurfaceLineSet_EntityHasSurfaceLineEntity() + { + // Setup + var surfaceLine = new PipingSurfaceLine(string.Empty) + { + ReferenceLineIntersectionWorldPoint = new Point2D(1.1, 2.2) + }; + surfaceLine.SetGeometry(new[] + { + new Point3D(0.0, 0.0, 1.0), + new Point3D(3.3, 6.6, 1.0) + }); + + var registry = new PersistenceRegistry(); + SurfaceLineEntity surfaceLineEntity = surfaceLine.Create(registry, 0); + + var calculation = new SemiProbabilisticPipingCalculationScenario(new GeneralPipingInput()) + { + InputParameters = + { + SurfaceLine = surfaceLine + } + }; + + // Call + PipingCalculationEntity entity = calculation.Create(registry, 0); + + // Assert + Assert.AreSame(surfaceLineEntity, entity.SurfaceLineEntity); + } + + [Test] + public void Create_HydraulicBoundaryLocation_EntityHasHydraulicLocationEntity() + { + // Setup + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "A", 2.3, 4.5); + + var registry = new PersistenceRegistry(); + HydraulicLocationEntity hydraulicLocationEntity = hydraulicBoundaryLocation.Create(registry, 0); + + var calculation = new SemiProbabilisticPipingCalculationScenario(new GeneralPipingInput()) + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation + } + }; + + // Call + PipingCalculationEntity entity = calculation.Create(registry, 0); + + // Assert + Assert.AreSame(hydraulicLocationEntity, entity.HydraulicLocationEntity); + } + + [Test] + public void Create_StochasticSoilProfileSet_EntityHasStochasticSoilProfileEntity() + { + // Setup + PipingSoilProfile soilProfile = PipingSoilProfileTestFactory.CreatePipingSoilProfile(); + var stochasticSoilProfile = new PipingStochasticSoilProfile(0.6, soilProfile); + + PipingStochasticSoilModel soilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel("A", new[] + { + stochasticSoilProfile + }); + + var registry = new PersistenceRegistry(); + StochasticSoilModelEntity soilModelEntity = soilModel.Create(registry, 0); + + var calculation = new SemiProbabilisticPipingCalculationScenario(new GeneralPipingInput()) + { + InputParameters = + { + StochasticSoilModel = soilModel, + StochasticSoilProfile = stochasticSoilProfile + } + }; + + // Call + PipingCalculationEntity entity = calculation.Create(registry, 0); + + // Assert + PipingStochasticSoilProfileEntity expectedStochasticSoilProfileEntity = soilModelEntity.PipingStochasticSoilProfileEntities.First(); + Assert.AreSame(expectedStochasticSoilProfileEntity, entity.PipingStochasticSoilProfileEntity); + Assert.IsTrue(registry.Contains(soilModel)); + } + + [Test] + public void Create_HasCalculationOutput_EntityHasPipingCalculationOutputEntity() + { + // Setup + var registry = new PersistenceRegistry(); + + SemiProbabilisticPipingOutput newOutput = PipingTestDataGenerator.GetRandomSemiProbabilisticPipingOutput(); + var calculation = new SemiProbabilisticPipingCalculationScenario(new GeneralPipingInput()) + { + Output = newOutput + }; + + // Call + PipingCalculationEntity entity = calculation.Create(registry, 0); + + // Assert + PipingCalculationOutputEntity outputEntity = entity.PipingCalculationOutputEntities.FirstOrDefault(); + + Assert.IsNotNull(outputEntity); + Assert.AreEqual(newOutput.HeaveFactorOfSafety, outputEntity.HeaveFactorOfSafety); + Assert.AreEqual(newOutput.SellmeijerFactorOfSafety, outputEntity.SellmeijerFactorOfSafety); + Assert.AreEqual(newOutput.UpliftFactorOfSafety, outputEntity.UpliftFactorOfSafety); + Assert.AreEqual(newOutput.UpliftEffectiveStress, outputEntity.UpliftEffectiveStress, newOutput.UpliftEffectiveStress.GetAccuracy()); + Assert.AreEqual(newOutput.HeaveGradient, outputEntity.HeaveGradient, newOutput.HeaveGradient.GetAccuracy()); + Assert.AreEqual(newOutput.SellmeijerCreepCoefficient, outputEntity.SellmeijerCreepCoefficient, newOutput.SellmeijerCreepCoefficient.GetAccuracy()); + Assert.AreEqual(newOutput.SellmeijerCriticalFall, outputEntity.SellmeijerCriticalFall, newOutput.SellmeijerCriticalFall.GetAccuracy()); + Assert.AreEqual(newOutput.SellmeijerReducedFall, outputEntity.SellmeijerReducedFall, newOutput.SellmeijerReducedFall.GetAccuracy()); + } + } +} \ No newline at end of file Index: Riskeer/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/SemiProbabilistic/SemiProbabilisticPipingOutputCreateExtensionsTest.cs =================================================================== diff -u --- Riskeer/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/SemiProbabilistic/SemiProbabilisticPipingOutputCreateExtensionsTest.cs (revision 0) +++ Riskeer/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/SemiProbabilistic/SemiProbabilisticPipingOutputCreateExtensionsTest.cs (revision 1eb9ed53b927cff7ee19afe65f9d6cd2431e08ce) @@ -0,0 +1,95 @@ +// Copyright (C) Stichting Deltares 2019. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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 NUnit.Framework; +using Riskeer.Common.Data.TestUtil; +using Riskeer.Piping.Data.SemiProbabilistic; +using Riskeer.Storage.Core.Create.Piping.SemiProbabilistic; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.Piping.SemiProbabilistic +{ + [TestFixture] + public class SemiProbabilisticPipingOutputCreateExtensionsTest + { + [Test] + public void Create_OutputNull_ThrowsArgumentNullException() + { + // Call + void Call() => ((SemiProbabilisticPipingOutput) null).Create(); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("output", exception.ParamName); + } + + [Test] + public void Create_AllOutputValuesSet_ReturnEntity() + { + // Setup + var pipingOutput = new SemiProbabilisticPipingOutput(new SemiProbabilisticPipingOutput.ConstructionProperties + { + UpliftFactorOfSafety = 2.2, + HeaveFactorOfSafety = 4.4, + SellmeijerFactorOfSafety = 6.6, + UpliftEffectiveStress = 7.7, + HeaveGradient = 8.8, + SellmeijerCreepCoefficient = 9.9, + SellmeijerCriticalFall = 10.10, + SellmeijerReducedFall = 11.11 + }); + + // Call + PipingCalculationOutputEntity entity = pipingOutput.Create(); + + // Assert + Assert.AreEqual(pipingOutput.HeaveFactorOfSafety, entity.HeaveFactorOfSafety); + Assert.AreEqual(pipingOutput.SellmeijerFactorOfSafety, entity.SellmeijerFactorOfSafety); + Assert.AreEqual(pipingOutput.UpliftFactorOfSafety, entity.UpliftFactorOfSafety); + Assert.AreEqual(pipingOutput.UpliftEffectiveStress, entity.UpliftEffectiveStress, pipingOutput.UpliftEffectiveStress.GetAccuracy()); + Assert.AreEqual(pipingOutput.HeaveGradient, entity.HeaveGradient, pipingOutput.HeaveGradient.GetAccuracy()); + Assert.AreEqual(pipingOutput.SellmeijerCreepCoefficient, entity.SellmeijerCreepCoefficient, pipingOutput.SellmeijerCreepCoefficient.GetAccuracy()); + Assert.AreEqual(pipingOutput.SellmeijerCriticalFall, entity.SellmeijerCriticalFall, pipingOutput.SellmeijerCriticalFall.GetAccuracy()); + Assert.AreEqual(pipingOutput.SellmeijerReducedFall, entity.SellmeijerReducedFall, pipingOutput.SellmeijerReducedFall.GetAccuracy()); + } + + [Test] + public void Create_AllOutputValuesNaN_ReturnEntityWithNullValues() + { + // Setup + var pipingOutput = new SemiProbabilisticPipingOutput(new SemiProbabilisticPipingOutput.ConstructionProperties()); + + // Call + PipingCalculationOutputEntity entity = pipingOutput.Create(); + + // Assert + Assert.IsNull(entity.HeaveFactorOfSafety); + Assert.IsNull(entity.SellmeijerFactorOfSafety); + Assert.IsNull(entity.UpliftFactorOfSafety); + Assert.IsNull(entity.UpliftEffectiveStress); + Assert.IsNull(entity.HeaveGradient); + Assert.IsNull(entity.SellmeijerCreepCoefficient); + Assert.IsNull(entity.SellmeijerCriticalFall); + Assert.IsNull(entity.SellmeijerReducedFall); + } + } +} \ No newline at end of file Fisheye: Tag 1eb9ed53b927cff7ee19afe65f9d6cd2431e08ce refers to a dead (removed) revision in file `Riskeer/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/SemiProbabilisticPipingCalculationScenarioCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1eb9ed53b927cff7ee19afe65f9d6cd2431e08ce refers to a dead (removed) revision in file `Riskeer/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/SemiProbabilisticPipingOutputCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/SemiProbabilistic/SemiProbabilisticPipingCalculationEntityReadExtensionsTest.cs =================================================================== diff -u --- Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/SemiProbabilistic/SemiProbabilisticPipingCalculationEntityReadExtensionsTest.cs (revision 0) +++ Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/SemiProbabilistic/SemiProbabilisticPipingCalculationEntityReadExtensionsTest.cs (revision 1eb9ed53b927cff7ee19afe65f9d6cd2431e08ce) @@ -0,0 +1,374 @@ +// Copyright (C) Stichting Deltares 2019. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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 Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Riskeer.Common.Data.TestUtil; +using Riskeer.Piping.Data; +using Riskeer.Piping.Data.SemiProbabilistic; +using Riskeer.Piping.Data.SoilProfile; +using Riskeer.Piping.Data.TestUtil; +using Riskeer.Piping.Primitives; +using Riskeer.Piping.Primitives.TestUtil; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Read.Piping.SemiProbabilistic; +using Riskeer.Storage.Core.Serializers; +using Riskeer.Storage.Core.TestUtil.Hydraulics; + +namespace Riskeer.Storage.Core.Test.Read.Piping.SemiProbabilistic +{ + [TestFixture] + public class SemiProbabilisticPipingCalculationEntityReadExtensionsTest + { + [Test] + public void Read_CollectorIsNull_ThrowArgumentNullException() + { + // Setup + var entity = new PipingCalculationEntity(); + + // Call + void Call() => entity.Read(null, new GeneralPipingInput()); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("collector", exception.ParamName); + } + + [Test] + [TestCase(true, false, 0.98, "haha", "hihi", 0.0, 3.4, 5.8, 123)] + [TestCase(false, true, 0.0, null, null, double.NaN, double.NaN, double.NaN, 321)] + public void Read_ValidEntity_ReturnPipingCalculationScenario(bool isRelevant, bool useAssessmentLevelManualInput, double contribution, + string name, string comments, double entryPoint, double exitPoint, + double assessmentLevel, int seed) + { + // Setup + var random = new Random(seed); + + var entity = new PipingCalculationEntity + { + RelevantForScenario = Convert.ToByte(isRelevant), + ScenarioContribution = contribution.ToNaNAsNull(), + Name = name, + Comments = comments, + EntryPointL = entryPoint.ToNaNAsNull(), + ExitPointL = exitPoint.ToNaNAsNull(), + PhreaticLevelExitMean = GetRandomNullableDoubleInRange(random, -9999.99, 9999.99), + PhreaticLevelExitStandardDeviation = GetRandomNullableDoubleInRange(random, 0, 9999.99), + DampingFactorExitMean = GetRandomNullableDoubleInRange(random, 1e-6, 9999.99), + DampingFactorExitStandardDeviation = GetRandomNullableDoubleInRange(random, 0, 9999.99), + AssessmentLevel = assessmentLevel.ToNaNAsNull(), + UseAssessmentLevelManualInput = Convert.ToByte(useAssessmentLevelManualInput) + }; + + var collector = new ReadConversionCollector(); + var generalInputParameters = new GeneralPipingInput(); + + // Call + SemiProbabilisticPipingCalculationScenario calculation = entity.Read(collector, generalInputParameters); + + // Assert + Assert.AreEqual(isRelevant, calculation.IsRelevant); + Assert.AreEqual(contribution, calculation.Contribution, 1e-6); + Assert.AreEqual(name, calculation.Name); + Assert.AreEqual(comments, calculation.Comments.Body); + + 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.Value, 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.Value, 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); + + Assert.AreEqual(useAssessmentLevelManualInput, calculation.InputParameters.UseAssessmentLevelManualInput); + Assert.AreEqual(entity.AssessmentLevel.ToNullAsNaN(), calculation.InputParameters.AssessmentLevel.Value); + + Assert.IsNull(calculation.InputParameters.SurfaceLine); + Assert.IsNull(calculation.InputParameters.HydraulicBoundaryLocation); + Assert.IsNull(calculation.InputParameters.StochasticSoilModel); + Assert.IsNull(calculation.InputParameters.StochasticSoilProfile); + Assert.IsNull(calculation.Output); + } + + [Test] + public void Read_EntityWithSurfaceLineInCollector_CalculationHasAlreadyReadSurfaceLine() + { + // Setup + var surfaceLine = new PipingSurfaceLine(string.Empty); + surfaceLine.SetGeometry(new[] + { + new Point3D(1, 2, 3), + new Point3D(4, 5, 6) + }); + var surfaceLineEntity = new SurfaceLineEntity(); + var entity = new PipingCalculationEntity + { + SurfaceLineEntity = surfaceLineEntity, + EntryPointL = 1, + ExitPointL = 2, + DampingFactorExitMean = 1 + }; + + var collector = new ReadConversionCollector(); + collector.Read(surfaceLineEntity, surfaceLine); + + // Call + SemiProbabilisticPipingCalculationScenario calculation = entity.Read(collector, new GeneralPipingInput()); + + // Assert + Assert.AreSame(surfaceLine, calculation.InputParameters.SurfaceLine); + Assert.AreEqual(1, calculation.InputParameters.EntryPointL, 1e-6); + Assert.AreEqual(2, calculation.InputParameters.ExitPointL, 1e-6); + } + + [Test] + public void Read_EntityWithSurfaceLineNotYetInCollector_CalculationWithCreatedSurfaceLineAndRegisteredNewEntities() + { + // Setup + var points = new[] + { + new Point3D(1, 3, 4), + new Point3D(7, 10, 11) + }; + + var surfaceLineEntity = new SurfaceLineEntity + { + Name = "surface line", + PointsXml = new Point3DCollectionXmlSerializer().ToXml(points) + }; + + var entity = new PipingCalculationEntity + { + SurfaceLineEntity = surfaceLineEntity, + EntryPointL = 1, + ExitPointL = 2, + DampingFactorExitMean = 1 + }; + + var collector = new ReadConversionCollector(); + + // Call + SemiProbabilisticPipingCalculationScenario calculation = entity.Read(collector, new GeneralPipingInput()); + + // Assert + Assert.IsTrue(collector.ContainsPipingSurfaceLine(surfaceLineEntity)); + CollectionAssert.AreEqual(points, calculation.InputParameters.SurfaceLine.Points); + } + + [Test] + public void Read_EntityWithHydraulicBoundaryLocationInCollector_CalculationHasAlreadyReadHydraulicBoundaryLocation() + { + // Setup + var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + var hydraulicLocationEntity = new HydraulicLocationEntity(); + var entity = new PipingCalculationEntity + { + HydraulicLocationEntity = hydraulicLocationEntity, + EntryPointL = 1, + ExitPointL = 2, + DampingFactorExitMean = 1, + AssessmentLevel = 5.81, + UseAssessmentLevelManualInput = Convert.ToByte(false) + }; + + var collector = new ReadConversionCollector(); + collector.Read(hydraulicLocationEntity, hydraulicBoundaryLocation); + + // Call + SemiProbabilisticPipingCalculationScenario calculation = entity.Read(collector, new GeneralPipingInput()); + + // Assert + Assert.AreSame(hydraulicBoundaryLocation, calculation.InputParameters.HydraulicBoundaryLocation); + } + + [Test] + public void Read_EntityWithHydraulicBoundaryLocationNotYetInCollector_CalculationWithCreatedHydraulicBoundaryLocationAndRegisteredNewEntities() + { + // Setup + HydraulicLocationEntity hydraulicLocationEntity = HydraulicLocationEntityTestFactory.CreateHydraulicLocationEntity(); + var entity = new PipingCalculationEntity + { + HydraulicLocationEntity = hydraulicLocationEntity, + EntryPointL = 1, + ExitPointL = 2, + DampingFactorExitMean = 1, + UseAssessmentLevelManualInput = Convert.ToByte(false) + }; + + var collector = new ReadConversionCollector(); + + // Call + entity.Read(collector, new GeneralPipingInput()); + + // Assert + Assert.IsTrue(collector.Contains(hydraulicLocationEntity)); + } + + [Test] + public void Read_EntityWithStochasticSoilModelEntityInCollector_CalculationHasAlreadyReadStochasticSoilModel() + { + // Setup + PipingStochasticSoilModel stochasticSoilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel(); + var stochasticSoilModelEntity = new StochasticSoilModelEntity(); + + var stochasticSoilProfile = new PipingStochasticSoilProfile(1, PipingSoilProfileTestFactory.CreatePipingSoilProfile()); + var stochasticSoilProfileEntity = new PipingStochasticSoilProfileEntity + { + StochasticSoilModelEntity = stochasticSoilModelEntity + }; + + var entity = new PipingCalculationEntity + { + PipingStochasticSoilProfileEntity = stochasticSoilProfileEntity, + EntryPointL = 1, + ExitPointL = 2, + DampingFactorExitMean = 1 + }; + + var collector = new ReadConversionCollector(); + collector.Read(stochasticSoilProfileEntity, stochasticSoilProfile); + collector.Read(stochasticSoilModelEntity, stochasticSoilModel); + + // Call + SemiProbabilisticPipingCalculationScenario 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 PipingStochasticSoilProfileEntity + { + PipingSoilProfileEntity = new PipingSoilProfileEntity + { + Name = "SoilProfile", + PipingSoilLayerEntities = + { + new PipingSoilLayerEntity() + } + } + }; + + var random = new Random(21); + var geometry = new[] + { + new Point2D(random.NextDouble(), random.NextDouble()) + }; + var stochasticSoilModelEntity = new StochasticSoilModelEntity + { + Name = "StochasticSoilModel", + StochasticSoilModelSegmentPointXml = new Point2DCollectionXmlSerializer().ToXml(geometry), + PipingStochasticSoilProfileEntities = + { + stochasticSoilProfileEntity + } + }; + stochasticSoilProfileEntity.StochasticSoilModelEntity = stochasticSoilModelEntity; + + var entity = new PipingCalculationEntity + { + PipingStochasticSoilProfileEntity = stochasticSoilProfileEntity, + EntryPointL = 1, + ExitPointL = 2, + DampingFactorExitMean = 1 + }; + + var collector = new ReadConversionCollector(); + + // Call + entity.Read(collector, new GeneralPipingInput()); + + // Assert + Assert.IsTrue(collector.Contains(stochasticSoilProfileEntity)); + Assert.IsTrue(collector.ContainsPipingStochasticSoilModel(stochasticSoilModelEntity)); + } + + [Test] + public void Read_EntityWithPipingCalculationOutputEntity_CalculationWithPipingOutput() + { + // Setup + var entity = new PipingCalculationEntity + { + EntryPointL = 1, + ExitPointL = 2, + DampingFactorExitMean = 1, + PipingCalculationOutputEntities = + { + new PipingCalculationOutputEntity() + } + }; + + var collector = new ReadConversionCollector(); + + // Call + SemiProbabilisticPipingCalculationScenario calculation = entity.Read(collector, new GeneralPipingInput()); + + // Assert + SemiProbabilisticPipingOutput output = calculation.Output; + Assert.IsNotNull(output); + + Assert.IsNaN(output.HeaveFactorOfSafety); + Assert.IsNaN(output.SellmeijerFactorOfSafety); + Assert.IsNaN(output.UpliftFactorOfSafety); + Assert.IsNaN(output.UpliftEffectiveStress); + Assert.IsNaN(output.HeaveGradient); + Assert.IsNaN(output.SellmeijerCreepCoefficient); + Assert.IsNaN(output.SellmeijerCriticalFall); + Assert.IsNaN(output.SellmeijerReducedFall); + } + + private static void AssertRoundedDouble(double? expectedValue, RoundedDouble actualValue) + { + Assert.IsTrue(expectedValue.HasValue); + Assert.AreEqual(expectedValue.Value, actualValue, actualValue.GetAccuracy()); + } + + private static void AssertRoundedDouble(double expectedValue, RoundedDouble actualValue) + { + Assert.AreEqual(expectedValue, actualValue, actualValue.GetAccuracy()); + } + + private static double? GetRandomNullableDoubleInRange(Random random, double lowerLimit, double upperLimit) + { + double difference = upperLimit - lowerLimit; + return lowerLimit + random.NextDouble(0, difference); + } + } +} \ No newline at end of file Index: Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/SemiProbabilistic/SemiProbabilisticPipingCalculationOutputEntityReadExtensionsTest.cs =================================================================== diff -u --- Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/SemiProbabilistic/SemiProbabilisticPipingCalculationOutputEntityReadExtensionsTest.cs (revision 0) +++ Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/SemiProbabilistic/SemiProbabilisticPipingCalculationOutputEntityReadExtensionsTest.cs (revision 1eb9ed53b927cff7ee19afe65f9d6cd2431e08ce) @@ -0,0 +1,104 @@ +// Copyright (C) Stichting Deltares 2019. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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 NUnit.Framework; +using Riskeer.Piping.Data.SemiProbabilistic; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.Piping.SemiProbabilistic; + +namespace Riskeer.Storage.Core.Test.Read.Piping.SemiProbabilistic +{ + [TestFixture] + public class SemiProbabilisticPipingCalculationOutputEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + void Call() => ((PipingCalculationOutputEntity) null).Read(); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_ValidEntity_ReturnPipingOutput() + { + // Setup + var entity = new PipingCalculationOutputEntity + { + HeaveFactorOfSafety = 9.8, + UpliftFactorOfSafety = 3.2, + SellmeijerFactorOfSafety = 8.7, + UpliftEffectiveStress = 15.2, + HeaveGradient = 12.2, + SellmeijerCreepCoefficient = 1.4, + SellmeijerCriticalFall = 6.2, + SellmeijerReducedFall = 8.1 + }; + + // Call + SemiProbabilisticPipingOutput output = entity.Read(); + + // Assert + Assert.AreEqual(entity.HeaveFactorOfSafety, output.HeaveFactorOfSafety); + Assert.AreEqual(entity.SellmeijerFactorOfSafety, output.SellmeijerFactorOfSafety); + Assert.AreEqual(entity.UpliftFactorOfSafety, output.UpliftFactorOfSafety); + Assert.AreEqual(entity.UpliftEffectiveStress, output.UpliftEffectiveStress.Value); + Assert.AreEqual(entity.HeaveGradient, output.HeaveGradient.Value); + Assert.AreEqual(entity.SellmeijerCreepCoefficient, output.SellmeijerCreepCoefficient.Value); + Assert.AreEqual(entity.SellmeijerCriticalFall, output.SellmeijerCriticalFall.Value); + Assert.AreEqual(entity.SellmeijerReducedFall, output.SellmeijerReducedFall.Value); + } + + [Test] + public void Read_ValidEntityWithNullParameterValues_ReturnPipingOutput() + { + // Setup + var entity = new PipingCalculationOutputEntity + { + HeaveFactorOfSafety = null, + UpliftFactorOfSafety = null, + SellmeijerFactorOfSafety = null, + UpliftEffectiveStress = null, + HeaveGradient = null, + SellmeijerCreepCoefficient = null, + SellmeijerCriticalFall = null, + SellmeijerReducedFall = null + }; + + // Call + SemiProbabilisticPipingOutput output = entity.Read(); + + // Assert + Assert.IsNaN(output.HeaveFactorOfSafety); + Assert.IsNaN(output.SellmeijerFactorOfSafety); + Assert.IsNaN(output.UpliftFactorOfSafety); + Assert.IsNaN(output.UpliftEffectiveStress); + Assert.IsNaN(output.HeaveGradient); + Assert.IsNaN(output.SellmeijerCreepCoefficient); + Assert.IsNaN(output.SellmeijerCriticalFall); + Assert.IsNaN(output.SellmeijerReducedFall); + } + } +} \ No newline at end of file Fisheye: Tag 1eb9ed53b927cff7ee19afe65f9d6cd2431e08ce refers to a dead (removed) revision in file `Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/SemiProbabilisticPipingCalculationEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1eb9ed53b927cff7ee19afe65f9d6cd2431e08ce refers to a dead (removed) revision in file `Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/SemiProbabilisticPipingCalculationOutputEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff?