Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj =================================================================== diff -u -r6c55d7ddb950eb8e434b9564367bffd9788876f8 -r4ad65cef966ec4b0e6f36b7a612aef4bdd088837 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 6c55d7ddb950eb8e434b9564367bffd9788876f8) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 4ad65cef966ec4b0e6f36b7a612aef4bdd088837) @@ -86,6 +86,7 @@ + Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/StructuresCalculationCreateExtensions.cs =================================================================== diff -u -r72e8e672bbfb506c8a9b71b8999591bae5cbafe7 -r4ad65cef966ec4b0e6f36b7a612aef4bdd088837 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/StructuresCalculationCreateExtensions.cs (.../StructuresCalculationCreateExtensions.cs) (revision 72e8e672bbfb506c8a9b71b8999591bae5cbafe7) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/StructuresCalculationCreateExtensions.cs (.../StructuresCalculationCreateExtensions.cs) (revision 4ad65cef966ec4b0e6f36b7a612aef4bdd088837) @@ -20,13 +20,10 @@ // All rights reserved. using System; -using System.Collections.Generic; -using Application.Ringtoets.Storage.Create.IllustrationPoints; using Application.Ringtoets.Storage.DbContext; using Core.Common.Utils.Extensions; using Ringtoets.ClosingStructures.Data; using Ringtoets.Common.Data; -using Ringtoets.Common.Data.Probability; using Ringtoets.Common.Data.Structures; using Ringtoets.HeightStructures.Data; using Ringtoets.StabilityPointStructures.Data; @@ -91,31 +88,6 @@ entityToUpdate.ShouldIllustrationPointsBeCalculated = Convert.ToByte(input.ShouldIllustrationPointsBeCalculated); } - private static void SetStructuresOutput(ICollection outputEntities, - StructuresOutput calculationOutput) - where TOutputEntity : IProbabilityAssessmentOutputEntity, - IHasGeneralResultFaultTreeIllustrationPointEntity, - new() - { - ProbabilityAssessmentOutput probabilityAssessmentOutput = calculationOutput.ProbabilityAssessmentOutput; - var outputEntity = probabilityAssessmentOutput.Create(); - - SetGeneralResult(outputEntity, calculationOutput); - - outputEntities.Add(outputEntity); - } - - private static void SetGeneralResult(IHasGeneralResultFaultTreeIllustrationPointEntity outputEntity, - StructuresOutput calculationOutput) - { - if (calculationOutput.HasGeneralResult) - { - outputEntity.GeneralResultFaultTreeIllustrationPointEntity = - calculationOutput.GeneralResult - .CreateGeneralResultFaultTreeIllustrationPointEntity(); - } - } - #region ClosingStructures /// @@ -194,7 +166,9 @@ { if (calculation.HasOutput) { - SetStructuresOutput(entity.ClosingStructuresOutputEntities, calculation.Output); + entity.ClosingStructuresOutputEntities.Add(calculation + .Output + .Create()); } } @@ -255,7 +229,9 @@ { if (calculation.HasOutput) { - SetStructuresOutput(entity.HeightStructuresOutputEntities, calculation.Output); + entity.HeightStructuresOutputEntities.Add(calculation + .Output + .Create()); } } @@ -368,7 +344,9 @@ { if (calculation.HasOutput) { - SetStructuresOutput(entity.StabilityPointStructuresOutputEntities, calculation.Output); + entity.StabilityPointStructuresOutputEntities.Add(calculation + .Output + .Create()); } } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/StructuresOutputCreateExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/StructuresOutputCreateExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/StructuresOutputCreateExtensions.cs (revision 4ad65cef966ec4b0e6f36b7a612aef4bdd088837) @@ -0,0 +1,64 @@ +// Copyright (C) Stichting Deltares 2017. 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 Application.Ringtoets.Storage.Create.IllustrationPoints; +using Application.Ringtoets.Storage.DbContext; +using Ringtoets.Common.Data.Probability; +using Ringtoets.Common.Data.Structures; + +namespace Application.Ringtoets.Storage.Create +{ + /// + /// Extension methods for related to creating structures + /// calculation output entities. + /// + internal static class StructuresOutputCreateExtensions + { + /// + /// Creates a based on the information of the + /// . + /// + /// The calculation output to create a database entity for. + /// A new . + public static TOutputEntity Create(this StructuresOutput calculationOutput) + where TOutputEntity : IProbabilityAssessmentOutputEntity, + IHasGeneralResultFaultTreeIllustrationPointEntity, + new() + { + ProbabilityAssessmentOutput probabilityAssessmentOutput = calculationOutput.ProbabilityAssessmentOutput; + var outputEntity = probabilityAssessmentOutput.Create(); + + SetGeneralResult(calculationOutput, outputEntity); + + return outputEntity; + } + + private static void SetGeneralResult(StructuresOutput calculationOutput, IHasGeneralResultFaultTreeIllustrationPointEntity outputEntity) + { + if (calculationOutput.HasGeneralResult) + { + outputEntity.GeneralResultFaultTreeIllustrationPointEntity = + calculationOutput.GeneralResult + .CreateGeneralResultFaultTreeIllustrationPointEntity(); + } + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj =================================================================== diff -u -race63dd1e2a052cb8774347958f3f2e2013c7400 -r4ad65cef966ec4b0e6f36b7a612aef4bdd088837 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision ace63dd1e2a052cb8774347958f3f2e2013c7400) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 4ad65cef966ec4b0e6f36b7a612aef4bdd088837) @@ -103,6 +103,7 @@ + Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/StructuresOutputCreateExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/StructuresOutputCreateExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/StructuresOutputCreateExtensionsTest.cs (revision 4ad65cef966ec4b0e6f36b7a612aef4bdd088837) @@ -0,0 +1,146 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Linq; +using Application.Ringtoets.Storage.Create; +using Application.Ringtoets.Storage.DbContext; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.Probability; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Data.TestUtil.IllustrationPoints; + +namespace Application.Ringtoets.Storage.Test.Create +{ + [TestFixture] + internal class StructuresOutputCreateExtensionsTest + { + [Test] + public void Create_CalculationWithOutput_ReturnEntityWithOutput() + { + // Setup + var random = new Random(567); + var output = new StructuresOutput( + new ProbabilityAssessmentOutput(random.NextDouble(), + random.NextDouble(), + random.NextDouble(), + random.NextDouble(), + random.NextDouble()), null); + + // Call + var entity = output.Create(); + + // Assert + Assert.IsNotNull(entity); + ProbabilityAssessmentOutput probabilityAssessmentOutput = output.ProbabilityAssessmentOutput; + Assert.AreEqual(probabilityAssessmentOutput.FactorOfSafety, entity.FactorOfSafety, + probabilityAssessmentOutput.FactorOfSafety.GetAccuracy()); + Assert.AreEqual(probabilityAssessmentOutput.Reliability, entity.Reliability, + probabilityAssessmentOutput.Reliability.GetAccuracy()); + Assert.AreEqual(probabilityAssessmentOutput.Probability, entity.Probability); + Assert.AreEqual(probabilityAssessmentOutput.RequiredReliability, entity.RequiredReliability, + probabilityAssessmentOutput.RequiredReliability.GetAccuracy()); + Assert.AreEqual(probabilityAssessmentOutput.RequiredProbability, entity.RequiredProbability); + AssertGeneralResult(output.GeneralResult, entity.GeneralResultFaultTreeIllustrationPointEntity); + } + + [Test] + public void Create_CalculationWithNaNOutput_ReturnEntityWithNullOutput() + { + // Setup + var output = new StructuresOutput( + new ProbabilityAssessmentOutput(double.NaN, + double.NaN, + double.NaN, + double.NaN, + double.NaN), null); + + // Call + var entity = output.Create(); + + // Assert + Assert.IsNotNull(entity); + Assert.IsNull(entity.FactorOfSafety); + Assert.IsNull(entity.Reliability); + Assert.IsNull(entity.Probability); + Assert.IsNull(entity.RequiredReliability); + Assert.IsNull(entity.RequiredProbability); + AssertGeneralResult(output.GeneralResult, entity.GeneralResultFaultTreeIllustrationPointEntity); + } + + [Test] + public void Create_CalculationWithOutputAndGeneralResult_ReturnEntityWithOutputAndGeneralResult() + { + // Setup + StructuresOutput output = new TestStructuresOutput(new TestGeneralResultFaultTreeIllustrationPoint()); + + // Call + var entity = output.Create(); + + // Assert + Assert.IsNotNull(entity); + ProbabilityAssessmentOutput probabilityAssessmentOutput = output.ProbabilityAssessmentOutput; + Assert.AreEqual(probabilityAssessmentOutput.FactorOfSafety, entity.FactorOfSafety, + probabilityAssessmentOutput.FactorOfSafety.GetAccuracy()); + Assert.AreEqual(probabilityAssessmentOutput.Reliability, entity.Reliability, + probabilityAssessmentOutput.Reliability.GetAccuracy()); + Assert.AreEqual(probabilityAssessmentOutput.Probability, entity.Probability); + Assert.AreEqual(probabilityAssessmentOutput.RequiredReliability, entity.RequiredReliability, + probabilityAssessmentOutput.RequiredReliability.GetAccuracy()); + Assert.AreEqual(probabilityAssessmentOutput.RequiredProbability, entity.RequiredProbability); + AssertGeneralResult(output.GeneralResult, entity.GeneralResultFaultTreeIllustrationPointEntity); + } + + private static void AssertGeneralResult(GeneralResult generalResult, + GeneralResultFaultTreeIllustrationPointEntity entity) + { + if (generalResult == null) + { + Assert.IsNull(entity); + return; + } + + Assert.IsNotNull(entity); + WindDirection governingWindDirection = generalResult.GoverningWindDirection; + TestHelper.AssertAreEqualButNotSame(governingWindDirection.Name, entity.GoverningWindDirectionName); + Assert.AreEqual(governingWindDirection.Angle, entity.GoverningWindDirectionAngle, + governingWindDirection.Angle.GetAccuracy()); + + Assert.AreEqual(generalResult.Stochasts.Count(), entity.StochastEntities.Count); + Assert.AreEqual(generalResult.TopLevelIllustrationPoints.Count(), + entity.TopLevelFaultTreeIllustrationPointEntities.Count); + } + + private class TestStructureOutputEntity : IProbabilityAssessmentOutputEntity, + IHasGeneralResultFaultTreeIllustrationPointEntity + { + public GeneralResultFaultTreeIllustrationPointEntity GeneralResultFaultTreeIllustrationPointEntity { get; set; } + public double? RequiredProbability { get; set; } + public double? RequiredReliability { get; set; } + public double? Probability { get; set; } + public double? Reliability { get; set; } + public double? FactorOfSafety { get; set; } + } + } +} \ No newline at end of file