Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj =================================================================== diff -u -rb6d9cf0b9791ae6ba194c8d5ce93e610d42d0a50 -rea4051c2b13cdb0d1f93af36b5eb2eb527a1f49b --- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision b6d9cf0b9791ae6ba194c8d5ce93e610d42d0a50) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision ea4051c2b13cdb0d1f93af36b5eb2eb527a1f49b) @@ -370,6 +370,7 @@ RingtoetsEntities.tt + Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/GrassCoverErosionOutwards/GrassCoverErosionOutwardsHydraulicLocationOutputEntityReadExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/GrassCoverErosionOutwards/GrassCoverErosionOutwardsHydraulicLocationOutputEntityReadExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/GrassCoverErosionOutwards/GrassCoverErosionOutwardsHydraulicLocationOutputEntityReadExtensions.cs (revision ea4051c2b13cdb0d1f93af36b5eb2eb527a1f49b) @@ -0,0 +1,52 @@ +// 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.DbContext; +using Application.Ringtoets.Storage.Read.IllustrationPoints; +using Ringtoets.Common.Data.Hydraulics; + +namespace Application.Ringtoets.Storage.Create.GrassCoverErosionOutwards +{ + /// + /// Extension methods for related to creating + /// a . + /// + internal static class GrassCoverErosionOutwardsHydraulicLocationOutputEntityReadExtensions + { + /// + /// Read the and use the information + /// to construct a . + /// + /// The + /// to create for. + /// A new . + internal static HydraulicBoundaryLocationOutput Read(this GrassCoverErosionOutwardsHydraulicLocationOutputEntity entity) + { + return new HydraulicBoundaryLocationOutput(entity.Result.ToNullAsNaN(), + entity.TargetProbability.ToNullAsNaN(), + entity.TargetReliability.ToNullAsNaN(), + entity.CalculatedProbability.ToNullAsNaN(), + entity.CalculatedReliability.ToNullAsNaN(), + (CalculationConvergence)entity.CalculationConvergence, + entity.GeneralResultSubMechanismIllustrationPointEntity?.Read()); + } + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/GrassCoverErosionOutwards/GrassCoverErosionOutwardsHydraulicLocationEntityReadExtensions.cs =================================================================== diff -u -rc0532d07766ecad2566f7cfa4a97a9aeb6e8540c -rea4051c2b13cdb0d1f93af36b5eb2eb527a1f49b --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/GrassCoverErosionOutwards/GrassCoverErosionOutwardsHydraulicLocationEntityReadExtensions.cs (.../GrassCoverErosionOutwardsHydraulicLocationEntityReadExtensions.cs) (revision c0532d07766ecad2566f7cfa4a97a9aeb6e8540c) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/GrassCoverErosionOutwards/GrassCoverErosionOutwardsHydraulicLocationEntityReadExtensions.cs (.../GrassCoverErosionOutwardsHydraulicLocationEntityReadExtensions.cs) (revision ea4051c2b13cdb0d1f93af36b5eb2eb527a1f49b) @@ -21,6 +21,7 @@ using System; using System.Linq; +using Application.Ringtoets.Storage.Create.GrassCoverErosionOutwards; using Application.Ringtoets.Storage.DbContext; using Ringtoets.Common.Data.Hydraulics; @@ -47,10 +48,12 @@ { throw new ArgumentNullException(nameof(entity)); } + if (collector == null) { throw new ArgumentNullException(nameof(collector)); } + if (collector.Contains(entity)) { return collector.Get(entity); @@ -76,7 +79,7 @@ waveHeightCalculation.InputParameters.ShouldIllustrationPointsBeCalculated = Convert.ToBoolean(entity.ShouldWaveHeightIllustrationPointsBeCalculated); - IHydraulicLocationOutputEntity waveHeightOutputEntity = + GrassCoverErosionOutwardsHydraulicLocationOutputEntity waveHeightOutputEntity = GetGrassCoverErosionOutwardsHydraulicLocationOutputEntity(entity, HydraulicLocationOutputType.WaveHeight); if (waveHeightOutputEntity != null) { @@ -90,15 +93,15 @@ designWaterLevelCalculation.InputParameters.ShouldIllustrationPointsBeCalculated = Convert.ToBoolean(entity.ShouldDesignWaterLevelIllustrationPointsBeCalculated); - IHydraulicLocationOutputEntity designWaterLevelOutputEntity = + GrassCoverErosionOutwardsHydraulicLocationOutputEntity designWaterLevelOutputEntity = GetGrassCoverErosionOutwardsHydraulicLocationOutputEntity(entity, HydraulicLocationOutputType.DesignWaterLevel); if (designWaterLevelOutputEntity != null) { designWaterLevelCalculation.Output = designWaterLevelOutputEntity.Read(); } } - private static IHydraulicLocationOutputEntity GetGrassCoverErosionOutwardsHydraulicLocationOutputEntity( + private static GrassCoverErosionOutwardsHydraulicLocationOutputEntity GetGrassCoverErosionOutwardsHydraulicLocationOutputEntity( GrassCoverErosionOutwardsHydraulicLocationEntity entity, HydraulicLocationOutputType outputType) { return entity.GrassCoverErosionOutwardsHydraulicLocationOutputEntities.SingleOrDefault( Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/HydraulicLocationOutputEntityReadExtensions.cs =================================================================== diff -u -r5d924a3334b0532730e8ea4bd9e97a5d48a72344 -rea4051c2b13cdb0d1f93af36b5eb2eb527a1f49b --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/HydraulicLocationOutputEntityReadExtensions.cs (.../HydraulicLocationOutputEntityReadExtensions.cs) (revision 5d924a3334b0532730e8ea4bd9e97a5d48a72344) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/HydraulicLocationOutputEntityReadExtensions.cs (.../HydraulicLocationOutputEntityReadExtensions.cs) (revision ea4051c2b13cdb0d1f93af36b5eb2eb527a1f49b) @@ -26,17 +26,17 @@ namespace Application.Ringtoets.Storage.Read { /// - /// Extension methods for related to creating + /// Extension methods for related to creating /// a . /// internal static class HydraulicLocationOutputEntityReadExtensions { /// - /// Read the and use the information to construct a . + /// Read the and use the information to construct a . /// - /// The to create for. + /// The to create for. /// A new . - internal static HydraulicBoundaryLocationOutput Read(this IHydraulicLocationOutputEntity entity) + internal static HydraulicBoundaryLocationOutput Read(this HydraulicLocationOutputEntity entity) { return new HydraulicBoundaryLocationOutput(entity.Result.ToNullAsNaN(), entity.TargetProbability.ToNullAsNaN(), Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj =================================================================== diff -u -r22e7274397bad248dca5f486e190a933926835f6 -rea4051c2b13cdb0d1f93af36b5eb2eb527a1f49b --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 22e7274397bad248dca5f486e190a933926835f6) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision ea4051c2b13cdb0d1f93af36b5eb2eb527a1f49b) @@ -102,6 +102,7 @@ + Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/GrassCoverErosionOutwards/GrassCoverErosionOutwardsHydraulicLocationOutputEntityReadExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/GrassCoverErosionOutwards/GrassCoverErosionOutwardsHydraulicLocationOutputEntityReadExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/GrassCoverErosionOutwards/GrassCoverErosionOutwardsHydraulicLocationOutputEntityReadExtensionsTest.cs (revision ea4051c2b13cdb0d1f93af36b5eb2eb527a1f49b) @@ -0,0 +1,222 @@ +// 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.Collections.Generic; +using System.Linq; +using Application.Ringtoets.Storage.Create.GrassCoverErosionOutwards; +using Application.Ringtoets.Storage.DbContext; +using Core.Common.Base.Data; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.TestUtil; + +namespace Application.Ringtoets.Storage.Test.Read.GrassCoverErosionOutwards +{ + [TestFixture] + public class GrassCoverErosionOutwardsHydraulicLocationOutputEntityReadExtensionsTest + { + [Test] + [Combinatorial] + public void Read_ValidParameters_ReturnsHydraulicBoundaryLocationOutput( + [Values(HydraulicLocationOutputType.DesignWaterLevel, HydraulicLocationOutputType.WaveHeight)] + HydraulicLocationOutputType outputType, + [Values(CalculationConvergence.CalculatedNotConverged, CalculationConvergence.CalculatedConverged, + CalculationConvergence.NotCalculated)] + CalculationConvergence convergence) + { + // Setup + var random = new Random(22); + double result = random.NextDouble(); + double targetProbability = random.NextDouble(); + double targetReliability = random.NextDouble(); + double calculatedProbability = random.NextDouble(); + double calculatedReliability = random.NextDouble(); + var entity = new GrassCoverErosionOutwardsHydraulicLocationOutputEntity + { + HydraulicLocationOutputType = (byte) outputType, + Result = result, + TargetProbability = targetProbability, + TargetReliability = targetReliability, + CalculatedProbability = calculatedProbability, + CalculatedReliability = calculatedReliability, + CalculationConvergence = (byte) convergence + }; + + // Call + HydraulicBoundaryLocationOutput output = entity.Read(); + + // Assert + Assert.AreEqual((RoundedDouble) result, output.Result, output.Result.GetAccuracy()); + Assert.AreEqual(targetProbability, output.TargetProbability); + Assert.AreEqual((RoundedDouble) targetReliability, output.TargetReliability, output.TargetReliability.GetAccuracy()); + Assert.AreEqual(calculatedProbability, output.CalculatedProbability); + Assert.AreEqual((RoundedDouble) calculatedReliability, output.CalculatedReliability, output.CalculatedReliability.GetAccuracy()); + Assert.AreEqual(convergence, output.CalculationConvergence); + Assert.IsNull(output.GeneralResult); + } + + [Test] + public void Read_NaNParameters_ReturnsHydraulicBoundaryLocationOutputWithNaN( + [Values(CalculationConvergence.CalculatedNotConverged, CalculationConvergence.CalculatedConverged, + CalculationConvergence.NotCalculated)] + CalculationConvergence convergence) + { + // Setup + var entity = new GrassCoverErosionOutwardsHydraulicLocationOutputEntity + { + Result = double.NaN, + TargetProbability = double.NaN, + TargetReliability = double.NaN, + CalculatedProbability = double.NaN, + CalculatedReliability = double.NaN, + CalculationConvergence = (byte) convergence + }; + + // Call + HydraulicBoundaryLocationOutput output = entity.Read(); + + // Assert + Assert.IsNaN(output.Result); + Assert.IsNaN(output.TargetProbability); + Assert.IsNaN(output.TargetReliability); + Assert.IsNaN(output.CalculatedProbability); + Assert.IsNaN(output.CalculatedReliability); + Assert.AreEqual(convergence, output.CalculationConvergence); + Assert.IsNull(output.GeneralResult); + } + + [Test] + public void Read_EntityWithIllustrationPoints_ReturnsHydraulicBoundarLocationOutputWithGeneralResult() + { + // Setup + var random = new Random(21); + + var stochastEntities = new[] + { + new StochastEntity + { + Name = "stochastEntityOne", + Duration = random.NextDouble(), + Alpha = random.NextDouble(), + Order = 0 + } + }; + var topLevelIllustrationPointEntities = new[] + { + new TopLevelSubMechanismIllustrationPointEntity + { + WindDirectionName = "WindDirectionTwo", + WindDirectionAngle = random.NextDouble(), + ClosingSituation = "ClosingSituationTwo", + SubMechanismIllustrationPointEntity = new SubMechanismIllustrationPointEntity + { + Beta = random.NextDouble(), + Name = "IllustrationPointTwo" + }, + Order = 0 + } + }; + + var entity = new GrassCoverErosionOutwardsHydraulicLocationOutputEntity + { + Result = double.NaN, + TargetProbability = double.NaN, + TargetReliability = double.NaN, + CalculatedProbability = double.NaN, + CalculatedReliability = double.NaN, + CalculationConvergence = (byte) random.NextEnumValue(), + GeneralResultSubMechanismIllustrationPointEntity = new GeneralResultSubMechanismIllustrationPointEntity + { + GoverningWindDirectionName = "SSE", + GoverningWindDirectionAngle = random.NextDouble(), + StochastEntities = stochastEntities, + TopLevelSubMechanismIllustrationPointEntities = topLevelIllustrationPointEntities + } + }; + + // Call + HydraulicBoundaryLocationOutput output = entity.Read(); + + // Assert + GeneralResult generalResult = output.GeneralResult; + GeneralResultSubMechanismIllustrationPointEntity generalResultEntity = + entity.GeneralResultSubMechanismIllustrationPointEntity; + + AssertWindDirection(generalResultEntity, generalResult.GoverningWindDirection); + AssertStochasts(generalResultEntity.StochastEntities.ToArray(), generalResult.Stochasts.ToArray()); + AssertIllustrationPoints(generalResultEntity.TopLevelSubMechanismIllustrationPointEntities.ToArray(), + generalResult.TopLevelIllustrationPoints.ToArray()); + } + + private static void AssertIllustrationPoints( + IEnumerable entities, + IEnumerable illustrationPoints) + { + int expectedEntitiesCount = entities.Count(); + Assert.AreEqual(expectedEntitiesCount, illustrationPoints.Count()); + for (var i = 0; i < expectedEntitiesCount; i++) + { + AssertTopLevelSubMechanismIllustrationPoint(entities.ElementAt(i), illustrationPoints.ElementAt(i)); + } + } + + private static void AssertTopLevelSubMechanismIllustrationPoint( + TopLevelSubMechanismIllustrationPointEntity illustrationPointEntity, + TopLevelSubMechanismIllustrationPoint readTopLevelSubMechanismIllustrationPoint) + { + Assert.AreEqual(illustrationPointEntity.ClosingSituation, readTopLevelSubMechanismIllustrationPoint.ClosingSituation); + + WindDirection actualWindDirection = readTopLevelSubMechanismIllustrationPoint.WindDirection; + Assert.AreEqual(illustrationPointEntity.WindDirectionName, actualWindDirection.Name); + Assert.AreEqual(illustrationPointEntity.WindDirectionAngle, actualWindDirection.Angle, actualWindDirection.Angle); + + Assert.IsNotNull(readTopLevelSubMechanismIllustrationPoint.SubMechanismIllustrationPoint); + } + + private static void AssertStochasts(IEnumerable entities, IEnumerable stochasts) + { + int expectedEntitiesCount = entities.Count(); + Assert.AreEqual(expectedEntitiesCount, stochasts.Count()); + for (var i = 0; i < expectedEntitiesCount; i++) + { + AssertStochast(entities.ElementAt(i), stochasts.ElementAt(i)); + } + } + + private static void AssertStochast(StochastEntity stochastEntity, + Stochast readStochast) + { + Assert.AreEqual(stochastEntity.Name, readStochast.Name); + Assert.AreEqual(stochastEntity.Alpha, readStochast.Alpha, readStochast.Alpha.GetAccuracy()); + Assert.AreEqual(stochastEntity.Duration, readStochast.Duration, readStochast.Duration.GetAccuracy()); + } + + private static void AssertWindDirection(IGeneralResultEntity entity, WindDirection windDirection) + { + Assert.AreEqual(entity.GoverningWindDirectionName, windDirection.Name); + Assert.AreEqual(entity.GoverningWindDirectionAngle, windDirection.Angle, + windDirection.Angle.GetAccuracy()); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/HydraulicLocationOutputEntityReadExtensionsTest.cs =================================================================== diff -u -r6b8f6422c0a6f96f8e563bb6afb82a7a192142b4 -rea4051c2b13cdb0d1f93af36b5eb2eb527a1f49b --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/HydraulicLocationOutputEntityReadExtensionsTest.cs (.../HydraulicLocationOutputEntityReadExtensionsTest.cs) (revision 6b8f6422c0a6f96f8e563bb6afb82a7a192142b4) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/HydraulicLocationOutputEntityReadExtensionsTest.cs (.../HydraulicLocationOutputEntityReadExtensionsTest.cs) (revision ea4051c2b13cdb0d1f93af36b5eb2eb527a1f49b) @@ -50,9 +50,8 @@ double targetReliability = random.NextDouble(); double calculatedProbability = random.NextDouble(); double calculatedReliability = random.NextDouble(); - var entity = new TestHydraulicLocationOutputEntity + var entity = new HydraulicLocationOutputEntity { - HydraulicLocationOutputType = (byte) outputType, Result = result, TargetProbability = targetProbability, TargetReliability = targetReliability, @@ -80,7 +79,7 @@ CalculationConvergence.NotCalculated)] CalculationConvergence convergence) { // Setup - var entity = new TestHydraulicLocationOutputEntity + var entity = new HydraulicLocationOutputEntity { Result = double.NaN, TargetProbability = double.NaN, @@ -135,7 +134,7 @@ } }; - var entity = new TestHydraulicLocationOutputEntity + var entity = new HydraulicLocationOutputEntity { Result = double.NaN, TargetProbability = double.NaN, @@ -215,17 +214,5 @@ Assert.AreEqual(entity.GoverningWindDirectionAngle, windDirection.Angle, windDirection.Angle.GetAccuracy()); } - - private class TestHydraulicLocationOutputEntity : IHydraulicLocationOutputEntity - { - public double? Result { get; set; } - public double? TargetProbability { get; set; } - public double? TargetReliability { get; set; } - public double? CalculatedProbability { get; set; } - public double? CalculatedReliability { get; set; } - public byte CalculationConvergence { get; set; } - public byte HydraulicLocationOutputType { get; set; } - public GeneralResultSubMechanismIllustrationPointEntity GeneralResultSubMechanismIllustrationPointEntity { get; set; } - } } } \ No newline at end of file