Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj =================================================================== diff -u -r9c830d5c8a9e1a18eecba12531147ee223622268 -r91764687fd1e853385a63f56160f38cb4527c7a8 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 9c830d5c8a9e1a18eecba12531147ee223622268) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 91764687fd1e853385a63f56160f38cb4527c7a8) @@ -368,18 +368,18 @@ - + - + - - + + @@ -440,7 +440,7 @@ - + Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/FailureMechanismCreateExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/FailureMechanismCreateExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/FailureMechanismCreateExtensions.cs (revision 91764687fd1e853385a63f56160f38cb4527c7a8) @@ -0,0 +1,92 @@ +// 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 Application.Ringtoets.Storage.DbContext; +using Core.Common.Utils.Extensions; +using Ringtoets.Common.Data.FailureMechanism; + +namespace Application.Ringtoets.Storage.Create +{ + /// + /// Extension methods for related to creating a . + /// + internal static class FailureMechanismCreateExtensions + { + /// + /// Creates a based on the information of the . + /// + /// The failure mechanism to create a database entity for. + /// The type of the failure mechanism that is being created. + /// The object keeping track of create operations. + /// A new . + /// Thrown when is null. + internal static FailureMechanismEntity Create(this IFailureMechanism mechanism, FailureMechanismType type, PersistenceRegistry registry) + { + if (registry == null) + { + throw new ArgumentNullException(nameof(registry)); + } + + var entity = new FailureMechanismEntity + { + FailureMechanismType = (short) type, + IsRelevant = Convert.ToByte(mechanism.IsRelevant), + InputComments = mechanism.InputComments.Body.DeepClone(), + OutputComments = mechanism.OutputComments.Body.DeepClone(), + NotRelevantComments = mechanism.NotRelevantComments.Body.DeepClone() + }; + + mechanism.AddEntitiesForFailureMechanismSections(registry, entity); + + return entity; + } + + /// + /// Creates instances based on the information of the . + /// + /// The failure mechanism to create a database failure mechanism section entities for. + /// The object keeping track of create operations. + /// The to which to add the created entities. + /// Thrown when either: + /// + /// is null + /// is null + /// + /// + internal static void AddEntitiesForFailureMechanismSections(this IFailureMechanism mechanism, PersistenceRegistry registry, FailureMechanismEntity entity) + { + if (registry == null) + { + throw new ArgumentNullException(nameof(registry)); + } + if (entity == null) + { + throw new ArgumentNullException(nameof(entity)); + } + + foreach (FailureMechanismSection failureMechanismSection in mechanism.Sections) + { + entity.FailureMechanismSectionEntities.Add(failureMechanismSection.Create(registry)); + } + } + } +} \ No newline at end of file Fisheye: Tag 91764687fd1e853385a63f56160f38cb4527c7a8 refers to a dead (removed) revision in file `Application/Ringtoets/src/Application.Ringtoets.Storage/Create/IFailureMechanismCreateExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/HydraulicLocationOutputEntityReadExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/HydraulicLocationOutputEntityReadExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/HydraulicLocationOutputEntityReadExtensions.cs (revision 91764687fd1e853385a63f56160f38cb4527c7a8) @@ -0,0 +1,48 @@ +// 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 Ringtoets.Common.Data.Hydraulics; + +namespace Application.Ringtoets.Storage.Read +{ + /// + /// Extension methods for related to creating + /// a . + /// + internal static class HydraulicLocationOutputEntityReadExtensions + { + /// + /// Read the and use the information to construct a . + /// + /// The to create for. + /// A new . + internal static HydraulicBoundaryLocationOutput Read(this IHydraulicLocationOutputEntity entity) + { + return new HydraulicBoundaryLocationOutput(entity.Result.ToNullAsNaN(), + entity.TargetProbability.ToNullAsNaN(), + entity.TargetReliability.ToNullAsNaN(), + entity.CalculatedProbability.ToNullAsNaN(), + entity.CalculatedReliability.ToNullAsNaN(), + (CalculationConvergence) entity.CalculationConvergence); + } + } +} \ No newline at end of file Fisheye: Tag 91764687fd1e853385a63f56160f38cb4527c7a8 refers to a dead (removed) revision in file `Application/Ringtoets/src/Application.Ringtoets.Storage/Read/IHydraulicLocationOutputEntityReadExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 91764687fd1e853385a63f56160f38cb4527c7a8 refers to a dead (removed) revision in file `Application/Ringtoets/src/Application.Ringtoets.Storage/Read/IProbabilityAssessmentOutputEntityReadExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 91764687fd1e853385a63f56160f38cb4527c7a8 refers to a dead (removed) revision in file `Application/Ringtoets/src/Application.Ringtoets.Storage/Read/IStructureCalculationEntityReadExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 91764687fd1e853385a63f56160f38cb4527c7a8 refers to a dead (removed) revision in file `Application/Ringtoets/src/Application.Ringtoets.Storage/Read/IllustrationPoints/IIllustrationPointResultEntityReadExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/IllustrationPoints/IllustrationPointResultEntityReadExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/IllustrationPoints/IllustrationPointResultEntityReadExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/IllustrationPoints/IllustrationPointResultEntityReadExtensions.cs (revision 91764687fd1e853385a63f56160f38cb4527c7a8) @@ -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 System; +using Application.Ringtoets.Storage.DbContext; +using Ringtoets.Common.Data.IllustrationPoints; + +namespace Application.Ringtoets.Storage.Read.IllustrationPoints +{ + /// + /// Extension methods for related to creating an + /// . + /// + internal static class IllustrationPointResultEntityReadExtensions + { + /// + /// Reads the and uses the information to + /// construct an . + /// + /// The to create + /// a for. + /// A new . + /// Thrown when is null. + internal static IllustrationPointResult Read(this IllustrationPointResultEntity entity) + { + if (entity == null) + { + throw new ArgumentNullException(nameof(entity)); + } + return new IllustrationPointResult(entity.Description, + entity.Value); + } + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ProbabilityAssessmentOutputEntityReadExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ProbabilityAssessmentOutputEntityReadExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ProbabilityAssessmentOutputEntityReadExtensions.cs (revision 91764687fd1e853385a63f56160f38cb4527c7a8) @@ -0,0 +1,49 @@ +// 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 Ringtoets.Common.Data.Probability; + +namespace Application.Ringtoets.Storage.Read +{ + /// + /// Extension methods for related to creating a + /// . + /// + internal static class ProbabilityAssessmentOutputEntityReadExtensions + { + /// + /// Reads the + /// and use the information to construct a . + /// + /// The + /// to create for. + /// A new . + internal static ProbabilityAssessmentOutput Read(this IProbabilityAssessmentOutputEntity entity) + { + return new ProbabilityAssessmentOutput(entity.RequiredProbability.ToNullAsNaN(), + entity.RequiredReliability.ToNullAsNaN(), + entity.Probability.ToNullAsNaN(), + entity.Reliability.ToNullAsNaN(), + entity.FactorOfSafety.ToNullAsNaN()); + } + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/StructureCalculationEntityReadExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/StructureCalculationEntityReadExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/StructureCalculationEntityReadExtensions.cs (revision 91764687fd1e853385a63f56160f38cb4527c7a8) @@ -0,0 +1,92 @@ +// 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 Application.Ringtoets.Storage.DbContext; +using Core.Common.Base.Data; +using Ringtoets.Common.Data; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Structures; + +namespace Application.Ringtoets.Storage.Read +{ + /// + /// This class defines extension methods for read operations for the common code + /// among all instances based on the . + /// + internal static class StructureCalculationEntityReadExtensions + { + /// + /// Reads all the information from the entity and updated the given input object, + /// with the exception of the property. + /// + /// The type of structure residing in . + /// The entity. + /// The input object to update. + /// The object keeping track of read operations. + /// Thrown when + /// or is null. + public static void Read(this IStructuresCalculationEntity entity, + StructuresInputBase inputToUpdate, + ReadConversionCollector collector) where T : StructureBase + { + if (inputToUpdate == null) + { + throw new ArgumentNullException(nameof(inputToUpdate)); + } + if (collector == null) + { + throw new ArgumentNullException(nameof(collector)); + } + + if (entity.ForeshoreProfileEntity != null) + { + inputToUpdate.ForeshoreProfile = entity.ForeshoreProfileEntity.Read(collector); + } + if (entity.HydraulicLocationEntity != null) + { + inputToUpdate.HydraulicBoundaryLocation = entity.HydraulicLocationEntity.Read(collector); + } + + inputToUpdate.StructureNormalOrientation = (RoundedDouble) entity.StructureNormalOrientation.ToNullAsNaN(); + inputToUpdate.ModelFactorSuperCriticalFlow.Mean = (RoundedDouble) entity.ModelFactorSuperCriticalFlowMean.ToNullAsNaN(); + inputToUpdate.AllowedLevelIncreaseStorage.Mean = (RoundedDouble) entity.AllowedLevelIncreaseStorageMean.ToNullAsNaN(); + inputToUpdate.AllowedLevelIncreaseStorage.StandardDeviation = (RoundedDouble) entity.AllowedLevelIncreaseStorageStandardDeviation.ToNullAsNaN(); + inputToUpdate.StorageStructureArea.Mean = (RoundedDouble) entity.StorageStructureAreaMean.ToNullAsNaN(); + inputToUpdate.StorageStructureArea.CoefficientOfVariation = (RoundedDouble) entity.StorageStructureAreaCoefficientOfVariation.ToNullAsNaN(); + inputToUpdate.FlowWidthAtBottomProtection.Mean = (RoundedDouble) entity.FlowWidthAtBottomProtectionMean.ToNullAsNaN(); + inputToUpdate.FlowWidthAtBottomProtection.StandardDeviation = (RoundedDouble) entity.FlowWidthAtBottomProtectionStandardDeviation.ToNullAsNaN(); + inputToUpdate.CriticalOvertoppingDischarge.Mean = (RoundedDouble) entity.CriticalOvertoppingDischargeMean.ToNullAsNaN(); + inputToUpdate.CriticalOvertoppingDischarge.CoefficientOfVariation = (RoundedDouble) entity.CriticalOvertoppingDischargeCoefficientOfVariation.ToNullAsNaN(); + inputToUpdate.FailureProbabilityStructureWithErosion = entity.FailureProbabilityStructureWithErosion; + inputToUpdate.WidthFlowApertures.Mean = (RoundedDouble) entity.WidthFlowAperturesMean.ToNullAsNaN(); + inputToUpdate.WidthFlowApertures.StandardDeviation = (RoundedDouble) entity.WidthFlowAperturesStandardDeviation.ToNullAsNaN(); + inputToUpdate.StormDuration.Mean = (RoundedDouble) entity.StormDurationMean.ToNullAsNaN(); + + inputToUpdate.UseBreakWater = Convert.ToBoolean(entity.UseBreakWater); + inputToUpdate.BreakWater.Type = (BreakWaterType) entity.BreakWaterType; + inputToUpdate.BreakWater.Height = (RoundedDouble) entity.BreakWaterHeight.ToNullAsNaN(); + inputToUpdate.UseForeshore = Convert.ToBoolean(entity.UseForeshore); + + inputToUpdate.ShouldIllustrationPointsBeCalculated = Convert.ToBoolean(entity.ShouldIllustrationPointsBeCalculated); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj =================================================================== diff -u -r283d7e09d084caafac590fdf96bfc6a264604016 -r91764687fd1e853385a63f56160f38cb4527c7a8 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 283d7e09d084caafac590fdf96bfc6a264604016) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 91764687fd1e853385a63f56160f38cb4527c7a8) @@ -128,7 +128,7 @@ - + @@ -138,9 +138,9 @@ - + - + @@ -203,7 +203,7 @@ - + Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/FailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/FailureMechanismCreateExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/FailureMechanismCreateExtensionsTest.cs (revision 91764687fd1e853385a63f56160f38cb4527c7a8) @@ -0,0 +1,121 @@ +// 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 Application.Ringtoets.Storage.Create; +using Application.Ringtoets.Storage.DbContext; +using Application.Ringtoets.Storage.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.TestUtil; + +namespace Application.Ringtoets.Storage.Test.Create +{ + [TestFixture] + public class FailureMechanismCreateExtensionsTest + { + [Test] + public void AddEntitiesForFailureMechanismSections_WithoutCollector_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new TestFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.AddEntitiesForFailureMechanismSections(null, new FailureMechanismEntity()); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + public void AddEntitiesForFailureMechanismSections_WithoutEntity_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new TestFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.AddEntitiesForFailureMechanismSections(new PersistenceRegistry(), null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void AddEntitiesForFailureMechanismSections_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new TestFailureMechanism(); + var failureMechanismEntity = new FailureMechanismEntity(); + + // Call + failureMechanism.AddEntitiesForFailureMechanismSections(new PersistenceRegistry(), failureMechanismEntity); + + // Assert + Assert.IsEmpty(failureMechanismEntity.FailureMechanismSectionEntities); + } + + [Test] + public void AddEntitiesForFailureMechanismSections_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + var failureMechanism = new TestFailureMechanism(); + failureMechanism.AddSection(new TestFailureMechanismSection()); + var failureMechanismEntity = new FailureMechanismEntity(); + + // Call + failureMechanism.AddEntitiesForFailureMechanismSections(new PersistenceRegistry(), failureMechanismEntity); + + // Assert + Assert.AreEqual(1, failureMechanismEntity.FailureMechanismSectionEntities.Count); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + IFailureMechanism failureMechanism = new TestFailureMechanism("a", "cool"); + failureMechanism.InputComments.Body = originalInput; + failureMechanism.OutputComments.Body = originalOutput; + failureMechanism.NotRelevantComments.Body = originalNotRelevantText; + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(FailureMechanismType.DuneErosion, registry); + + // Assert + Assert.AreNotSame(originalInput, entity.InputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreNotSame(originalOutput, entity.OutputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreNotSame(originalNotRelevantText, entity.NotRelevantComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + } +} \ No newline at end of file Fisheye: Tag 91764687fd1e853385a63f56160f38cb4527c7a8 refers to a dead (removed) revision in file `Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/IFailureMechanismCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/HydraulicLocationOutputEntityReadExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/HydraulicLocationOutputEntityReadExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/HydraulicLocationOutputEntityReadExtensionsTest.cs (revision 91764687fd1e853385a63f56160f38cb4527c7a8) @@ -0,0 +1,114 @@ +// 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 Application.Ringtoets.Storage.DbContext; +using Application.Ringtoets.Storage.Read; +using Core.Common.Base.Data; +using NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; + +namespace Application.Ringtoets.Storage.Test.Read +{ + [TestFixture] + public class HydraulicLocationOutputEntityReadExtensionsTest + { + [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 TestHydraulicLocationOutputEntity + { + 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.GeneralResultSubMechanismIllustrationPoint); + } + + [Test] + public void Read_NaNParameters_ReturnsHydraulicBoundaryLocationOutputWithNaN( + [Values(CalculationConvergence.CalculatedNotConverged, CalculationConvergence.CalculatedConverged, + CalculationConvergence.NotCalculated)] CalculationConvergence convergence) + { + // Setup + var entity = new TestHydraulicLocationOutputEntity + { + 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.GeneralResultSubMechanismIllustrationPoint); + } + + 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 Fisheye: Tag 91764687fd1e853385a63f56160f38cb4527c7a8 refers to a dead (removed) revision in file `Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/IHydraulicLocationOutputEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 91764687fd1e853385a63f56160f38cb4527c7a8 refers to a dead (removed) revision in file `Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/IProbabilityAssessmentOutputEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 91764687fd1e853385a63f56160f38cb4527c7a8 refers to a dead (removed) revision in file `Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/IStructureCalculationEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/ProbabilityAssessmentOutputEntityReadExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/ProbabilityAssessmentOutputEntityReadExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/ProbabilityAssessmentOutputEntityReadExtensionsTest.cs (revision 91764687fd1e853385a63f56160f38cb4527c7a8) @@ -0,0 +1,98 @@ +// 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 Application.Ringtoets.Storage.DbContext; +using Application.Ringtoets.Storage.Read; +using Core.Common.Base.Data; +using NUnit.Framework; +using Ringtoets.Common.Data.Probability; +using Ringtoets.Common.Data.TestUtil; + +namespace Application.Ringtoets.Storage.Test.Read +{ + [TestFixture] + public class ProbabilityAssessmentOutputEntityReadExtensionsTest + { + [Test] + public void Read_ValidEntity_ReturnProbabilityAssessmentOutput() + { + // Setup + var random = new Random(159); + var entity = new TestProbabilityAssessmentOutputEntity + { + RequiredProbability = random.NextDouble(), + RequiredReliability = random.NextDouble(), + Probability = random.NextDouble(), + Reliability = random.NextDouble(), + FactorOfSafety = random.NextDouble() + }; + + // Call + ProbabilityAssessmentOutput output = entity.Read(); + + // Assert + Assert.AreEqual(entity.RequiredProbability, output.RequiredProbability); + AssertRoundedDouble(entity.RequiredReliability, output.RequiredReliability); + Assert.AreEqual(entity.Probability, output.Probability); + AssertRoundedDouble(entity.Reliability, output.Reliability); + AssertRoundedDouble(entity.FactorOfSafety, output.FactorOfSafety); + } + + [Test] + public void Read_ValidEntityWithNullValues_ReturnProbabilityAssessmentOutput() + { + // Setup + var entity = new TestProbabilityAssessmentOutputEntity + { + RequiredProbability = null, + RequiredReliability = null, + Probability = null, + Reliability = null, + FactorOfSafety = null + }; + + // Call + ProbabilityAssessmentOutput output = entity.Read(); + + // Assert + Assert.IsNaN(output.RequiredProbability); + Assert.IsNaN(output.RequiredReliability.Value); + Assert.IsNaN(output.Probability); + Assert.IsNaN(output.Reliability.Value); + Assert.IsNaN(output.FactorOfSafety.Value); + } + + private class TestProbabilityAssessmentOutputEntity : IProbabilityAssessmentOutputEntity + { + 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; } + } + + private static void AssertRoundedDouble(double? expectedValue, RoundedDouble actualValue) + { + Assert.AreEqual((RoundedDouble) expectedValue.ToNullAsNaN(), actualValue, actualValue.GetAccuracy()); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/StructureCalculationEntityReadExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/StructureCalculationEntityReadExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/StructureCalculationEntityReadExtensionsTest.cs (revision 91764687fd1e853385a63f56160f38cb4527c7a8) @@ -0,0 +1,244 @@ +// 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 Application.Ringtoets.Storage.DbContext; +using Application.Ringtoets.Storage.Read; +using Core.Common.Base.Data; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; + +namespace Application.Ringtoets.Storage.Test.Read +{ + [TestFixture] + public class StructureCalculationEntityReadExtensionsTest + { + [Test] + public void Read_InputToUpdateNull_ThrowArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var entity = mocks.Stub(); + mocks.ReplayAll(); + + var collector = new ReadConversionCollector(); + + // Call + TestDelegate call = () => entity.Read(null, collector); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("inputToUpdate", paramName); + mocks.VerifyAll(); + } + + [Test] + public void Read_ReadConversionCollectorIsNull_ThrowArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var entity = mocks.Stub(); + mocks.ReplayAll(); + + var inputToUpdate = new SimpleStructuresInput(); + + // Call + TestDelegate call = () => entity.Read(inputToUpdate, null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + mocks.VerifyAll(); + } + + [Test] + public void Read_ValidEntity_InputObjectUpdated() + { + // Setup + var random = new Random(78); + + var mocks = new MockRepository(); + var entity = mocks.Stub(); + entity.StructureNormalOrientation = random.GetFromRange(0, 360); + entity.ModelFactorSuperCriticalFlowMean = random.GetFromRange(-9999.9999, 9999.9999); + entity.AllowedLevelIncreaseStorageMean = random.GetFromRange(1e-6, 9999.9999); + entity.AllowedLevelIncreaseStorageStandardDeviation = random.GetFromRange(1e-6, 9999.9999); + entity.FlowWidthAtBottomProtectionMean = random.GetFromRange(1e-6, 9999.9999); + entity.FlowWidthAtBottomProtectionStandardDeviation = random.GetFromRange(1e-6, 9999.9999); + entity.CriticalOvertoppingDischargeMean = random.GetFromRange(1e-6, 9999.9999); + entity.CriticalOvertoppingDischargeCoefficientOfVariation = random.GetFromRange(1e-6, 9999.9999); + entity.FailureProbabilityStructureWithErosion = random.NextDouble(); + entity.WidthFlowAperturesMean = random.GetFromRange(1e-6, 9999.9999); + entity.WidthFlowAperturesStandardDeviation = random.GetFromRange(1e-6, 9999.9999); + entity.StormDurationMean = random.GetFromRange(1e-6, 9999.9999); + entity.UseForeshore = Convert.ToByte(random.NextBoolean()); + entity.UseBreakWater = Convert.ToByte(random.NextBoolean()); + entity.ShouldIllustrationPointsBeCalculated = Convert.ToByte(random.NextBoolean()); + mocks.ReplayAll(); + + var inputToUpdate = new SimpleStructuresInput(); + var collector = new ReadConversionCollector(); + + // Call + entity.Read(inputToUpdate, collector); + + // Assert + AssertBoolean(entity.UseForeshore, inputToUpdate.UseForeshore); + AssertBoolean(entity.UseBreakWater, inputToUpdate.UseBreakWater); + AssertBoolean(entity.ShouldIllustrationPointsBeCalculated, inputToUpdate.ShouldIllustrationPointsBeCalculated); + + AssertRoundedDouble(entity.StructureNormalOrientation, inputToUpdate.StructureNormalOrientation); + AssertRoundedDouble(entity.ModelFactorSuperCriticalFlowMean, inputToUpdate.ModelFactorSuperCriticalFlow.Mean); + AssertRoundedDouble(entity.AllowedLevelIncreaseStorageMean, inputToUpdate.AllowedLevelIncreaseStorage.Mean); + AssertRoundedDouble(entity.AllowedLevelIncreaseStorageStandardDeviation, inputToUpdate.AllowedLevelIncreaseStorage.StandardDeviation); + AssertRoundedDouble(entity.FlowWidthAtBottomProtectionMean, inputToUpdate.FlowWidthAtBottomProtection.Mean); + AssertRoundedDouble(entity.FlowWidthAtBottomProtectionStandardDeviation, inputToUpdate.FlowWidthAtBottomProtection.StandardDeviation); + AssertRoundedDouble(entity.CriticalOvertoppingDischargeMean, inputToUpdate.CriticalOvertoppingDischarge.Mean); + AssertRoundedDouble(entity.CriticalOvertoppingDischargeCoefficientOfVariation, inputToUpdate.CriticalOvertoppingDischarge.CoefficientOfVariation); + Assert.AreEqual(entity.FailureProbabilityStructureWithErosion, inputToUpdate.FailureProbabilityStructureWithErosion); + AssertRoundedDouble(entity.WidthFlowAperturesMean, inputToUpdate.WidthFlowApertures.Mean); + AssertRoundedDouble(entity.WidthFlowAperturesStandardDeviation, inputToUpdate.WidthFlowApertures.StandardDeviation); + AssertRoundedDouble(entity.StormDurationMean, inputToUpdate.StormDuration.Mean); + + Assert.IsEmpty(inputToUpdate.ForeshoreGeometry); + Assert.IsNull(inputToUpdate.ForeshoreProfile); + Assert.IsNull(inputToUpdate.HydraulicBoundaryLocation); + Assert.IsNull(inputToUpdate.Structure); + mocks.VerifyAll(); + } + + [Test] + public void Read_EntityWithParametersNull_InputObjectUpdatedWithNaN() + { + // Setup + var mocks = new MockRepository(); + var entity = mocks.Stub(); + entity.StructureNormalOrientation = null; + entity.ModelFactorSuperCriticalFlowMean = null; + entity.AllowedLevelIncreaseStorageMean = null; + entity.AllowedLevelIncreaseStorageStandardDeviation = null; + entity.FlowWidthAtBottomProtectionMean = null; + entity.FlowWidthAtBottomProtectionStandardDeviation = null; + entity.CriticalOvertoppingDischargeMean = null; + entity.CriticalOvertoppingDischargeCoefficientOfVariation = null; + entity.WidthFlowAperturesMean = null; + entity.WidthFlowAperturesStandardDeviation = null; + entity.StormDurationMean = null; + mocks.ReplayAll(); + + var inputToUpdate = new SimpleStructuresInput(); + var collector = new ReadConversionCollector(); + + // Call + entity.Read(inputToUpdate, collector); + + // Assert + Assert.IsNaN(inputToUpdate.StructureNormalOrientation); + Assert.IsNaN(inputToUpdate.ModelFactorSuperCriticalFlow.Mean); + Assert.IsNaN(inputToUpdate.AllowedLevelIncreaseStorage.Mean); + Assert.IsNaN(inputToUpdate.AllowedLevelIncreaseStorage.StandardDeviation); + Assert.IsNaN(inputToUpdate.FlowWidthAtBottomProtection.Mean); + Assert.IsNaN(inputToUpdate.FlowWidthAtBottomProtection.StandardDeviation); + Assert.IsNaN(inputToUpdate.CriticalOvertoppingDischarge.Mean); + Assert.IsNaN(inputToUpdate.CriticalOvertoppingDischarge.CoefficientOfVariation); + Assert.IsNaN(inputToUpdate.WidthFlowApertures.Mean); + Assert.IsNaN(inputToUpdate.WidthFlowApertures.StandardDeviation); + Assert.IsNaN(inputToUpdate.StormDuration.Mean); + mocks.VerifyAll(); + } + + [Test] + public void Read_EntityWithForeshoreProfileEntity_InputObjectUpdatedWithForeshoreProfile() + { + // Setup + var foreshoreProfile = new TestForeshoreProfile(); + var foreshoreEntity = new ForeshoreProfileEntity(); + + var mocks = new MockRepository(); + var entity = mocks.Stub(); + entity.ForeshoreProfileEntity = foreshoreEntity; + mocks.ReplayAll(); + + var inputToUpdate = new SimpleStructuresInput(); + var collector = new ReadConversionCollector(); + collector.Read(foreshoreEntity, foreshoreProfile); + + // Call + entity.Read(inputToUpdate, collector); + + // Assert + Assert.AreSame(foreshoreProfile, inputToUpdate.ForeshoreProfile); + mocks.VerifyAll(); + } + + [Test] + public void Read_EntityWithHydraulicLocationEntity_InputObjectUpdatedWithHydraulicBoundaryLocation() + { + // Setup + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(0, "A", 0, 0); + var hydraulicLocationEntity = new HydraulicLocationEntity(); + + var mocks = new MockRepository(); + var entity = mocks.Stub(); + entity.HydraulicLocationEntity = hydraulicLocationEntity; + mocks.ReplayAll(); + + var inputToUpdate = new SimpleStructuresInput(); + var collector = new ReadConversionCollector(); + collector.Read(hydraulicLocationEntity, hydraulicBoundaryLocation); + + // Call + entity.Read(inputToUpdate, collector); + + // Assert + Assert.AreSame(hydraulicBoundaryLocation, inputToUpdate.HydraulicBoundaryLocation); + mocks.VerifyAll(); + } + + private static void AssertBoolean(byte expectedByte, bool actual) + { + Assert.AreEqual(Convert.ToBoolean(expectedByte), actual); + } + + private static void AssertRoundedDouble(double? entityValue, RoundedDouble roundedDouble) + { + Assert.AreEqual((RoundedDouble) entityValue.ToNullAsNaN(), roundedDouble, roundedDouble.GetAccuracy()); + } + + private class SimpleStructuresInput : StructuresInputBase + { + public override bool IsStructureInputSynchronized + { + get + { + return false; + } + } + + public override void SynchronizeStructureInput() {} + } + } +} \ No newline at end of file