Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj =================================================================== diff -u -r749f4e50391ac399e02cb497966ae7d749d5fd1e -r64ad0bbe91a9c7e9229fa9800b93b65f619b9e31 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 749f4e50391ac399e02cb497966ae7d749d5fd1e) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 64ad0bbe91a9c7e9229fa9800b93b65f619b9e31) @@ -247,6 +247,7 @@ + Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/CalculationGroupEntityReadExtentions.cs =================================================================== diff -u -r3e5776001e28222d451a3af8488ba72cef6d017f -r64ad0bbe91a9c7e9229fa9800b93b65f619b9e31 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/CalculationGroupEntityReadExtentions.cs (.../CalculationGroupEntityReadExtentions.cs) (revision 3e5776001e28222d451a3af8488ba72cef6d017f) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/CalculationGroupEntityReadExtentions.cs (.../CalculationGroupEntityReadExtentions.cs) (revision 64ad0bbe91a9c7e9229fa9800b93b65f619b9e31) @@ -24,6 +24,7 @@ using Application.Ringtoets.Storage.DbContext; using Application.Ringtoets.Storage.Read.GrassCoverErosionInwards; using Application.Ringtoets.Storage.Read.GrassCoverErosionOutwards; +using Application.Ringtoets.Storage.Read.HeightStructures; using Application.Ringtoets.Storage.Read.Piping; using Application.Ringtoets.Storage.Read.StabilityStoneCover; using Application.Ringtoets.Storage.Read.WaveImpactAsphaltCover; @@ -161,6 +162,42 @@ /// The object keeping track of read operations. /// A new . /// Thrown when is null. + internal static CalculationGroup ReadAsHeightStructuresCalculationGroup(this CalculationGroupEntity entity, + ReadConversionCollector collector) + { + if (collector == null) + { + throw new ArgumentNullException("collector"); + } + + var group = new CalculationGroup(entity.Name, Convert.ToBoolean(entity.IsEditable)); + + foreach (object childEntity in GetChildEntitiesInOrder(entity)) + { + var childCalculationGroupEntity = childEntity as CalculationGroupEntity; + if (childCalculationGroupEntity != null) + { + group.Children.Add(childCalculationGroupEntity.ReadAsHeightStructuresCalculationGroup(collector)); + } + var childCalculationEntity = childEntity as HeightStructuresCalculationEntity; + if (childCalculationEntity != null) + { + group.Children.Add(childCalculationEntity.Read(collector)); + } + } + + return group; + } + + /// + /// Read the and use the information to construct + /// a . + /// + /// The to create + /// for. + /// The object keeping track of read operations. + /// A new . + /// Thrown when is null. internal static CalculationGroup ReadAsStabilityStoneCoverWaveConditionsCalculationGroup(this CalculationGroupEntity entity, ReadConversionCollector collector) { @@ -243,6 +280,10 @@ { sortedList.Add(calculationEntity.Order, calculationEntity); } + foreach (HeightStructuresCalculationEntity calculationEntity in entity.HeightStructuresCalculationEntities) + { + sortedList.Add(calculationEntity.Order, calculationEntity); + } foreach (StabilityStoneCoverWaveConditionsCalculationEntity calculationEntity in entity.StabilityStoneCoverWaveConditionsCalculationEntities) { sortedList.Add(calculationEntity.Order, calculationEntity); Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/FailureMechanismEntityReadExtensions.cs =================================================================== diff -u -r531a5378e2e0c670c8e4bc361765d5d63f429a62 -r64ad0bbe91a9c7e9229fa9800b93b65f619b9e31 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/FailureMechanismEntityReadExtensions.cs (.../FailureMechanismEntityReadExtensions.cs) (revision 531a5378e2e0c670c8e4bc361765d5d63f429a62) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/FailureMechanismEntityReadExtensions.cs (.../FailureMechanismEntityReadExtensions.cs) (revision 64ad0bbe91a9c7e9229fa9800b93b65f619b9e31) @@ -224,6 +224,7 @@ entity.ReadForeshoreProfiles(failureMechanism.ForeshoreProfiles, collector); entity.ReadHeightStructures(failureMechanism.HeightStructures, collector); entity.ReadGeneralInput(failureMechanism.GeneralInput); + ReadHeightStructuresRootCalculationGroup(entity.CalculationGroupEntity, failureMechanism.CalculationsGroup, collector); } private static void ReadHeightStructuresMechanismSectionResults(this FailureMechanismEntity entity, HeightStructuresFailureMechanism failureMechanism, ReadConversionCollector collector) @@ -248,6 +249,17 @@ generalInput.N = generalHeightStructuresInput.N; } + private static void ReadHeightStructuresRootCalculationGroup(CalculationGroupEntity rootCalculationGroupEntity, + CalculationGroup targetRootCalculationGroup, + ReadConversionCollector collector) + { + CalculationGroup rootCalculationGroup = rootCalculationGroupEntity.ReadAsHeightStructuresCalculationGroup(collector); + foreach (ICalculationBase calculationBase in rootCalculationGroup.Children) + { + targetRootCalculationGroup.Children.Add(calculationBase); + } + } + #endregion #region Strength Stability Lengthwise Construction Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/HeightStructures/HeightStructuresCalculationEntityReadExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/HeightStructures/HeightStructuresCalculationEntityReadExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/HeightStructures/HeightStructuresCalculationEntityReadExtensions.cs (revision 64ad0bbe91a9c7e9229fa9800b93b65f619b9e31) @@ -0,0 +1,90 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using Application.Ringtoets.Storage.DbContext; +using Core.Common.Base.Data; +using Ringtoets.Common.Data.Structures; +using Ringtoets.HeightStructures.Data; + +namespace Application.Ringtoets.Storage.Read.HeightStructures +{ + internal static class HeightStructuresCalculationEntityReadExtensions + { + /// + /// Reads the and use the + /// information to update a . + /// + /// The + /// to create for. + /// The object keeping track of read operations. + /// A new . + internal static StructuresCalculation Read(this HeightStructuresCalculationEntity entity, ReadConversionCollector collector) + { + if (collector == null) + { + throw new ArgumentNullException("collector"); + } + + var calculation = new StructuresCalculation + { + Name = entity.Name, + Comments = entity.Comments + }; + ReadInputParameters(calculation.InputParameters, entity, collector); + + return calculation; + } + + private static void ReadInputParameters(HeightStructuresInput inputParameters, HeightStructuresCalculationEntity entity, ReadConversionCollector collector) + { + if (entity.ForeshoreProfileEntity != null) + { + inputParameters.ForeshoreProfile = entity.ForeshoreProfileEntity.Read(collector); + } + if (entity.HeightStructureEntity != null) + { + inputParameters.Structure = entity.HeightStructureEntity.Read(collector); + } + if (entity.HydraulicLocationEntity != null) + { + inputParameters.HydraulicBoundaryLocation = entity.HydraulicLocationEntity.Read(collector); + } + + inputParameters.StructureNormalOrientation = (RoundedDouble) entity.StructureNormalOrientation.ToNullAsNaN(); + inputParameters.ModelFactorSuperCriticalFlow.Mean = (RoundedDouble) entity.ModelFactorSuperCriticalFlowMean.ToNullAsNaN(); + inputParameters.AllowedLevelIncreaseStorage.Mean = (RoundedDouble) entity.AllowedLevelIncreaseStorageMean.ToNullAsNaN(); + inputParameters.AllowedLevelIncreaseStorage.StandardDeviation = (RoundedDouble) entity.AllowedLevelIncreaseStorageStandardDeviation.ToNullAsNaN(); + inputParameters.StorageStructureArea.Mean = (RoundedDouble) entity.StorageStructureAreaMean.ToNullAsNaN(); + inputParameters.StorageStructureArea.CoefficientOfVariation = (RoundedDouble) entity.StorageStructureAreaCoefficientOfVariation.ToNullAsNaN(); + inputParameters.FlowWidthAtBottomProtection.Mean = (RoundedDouble) entity.FlowWidthAtBottomProtectionMean.ToNullAsNaN(); + inputParameters.FlowWidthAtBottomProtection.StandardDeviation = (RoundedDouble) entity.FlowWidthAtBottomProtectionStandardDeviation.ToNullAsNaN(); + inputParameters.CriticalOvertoppingDischarge.Mean = (RoundedDouble) entity.CriticalOvertoppingDischargeMean.ToNullAsNaN(); + inputParameters.CriticalOvertoppingDischarge.CoefficientOfVariation = (RoundedDouble) entity.CriticalOvertoppingDischargeCoefficientOfVariation.ToNullAsNaN(); + inputParameters.FailureProbabilityStructureWithErosion = entity.FailureProbabilityStructureWithErosion.ToNullAsNaN(); + inputParameters.WidthFlowApertures.Mean = (RoundedDouble) entity.WidthFlowAperturesMean.ToNullAsNaN(); + inputParameters.WidthFlowApertures.CoefficientOfVariation = (RoundedDouble) entity.WidthFlowAperturesCoefficientOfVariation.ToNullAsNaN(); + + inputParameters.UseBreakWater = Convert.ToBoolean(entity.UseBreakWater); + inputParameters.UseForeshore = Convert.ToBoolean(entity.UseForeshore); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj =================================================================== diff -u -r6913ef75b5ec527ab771006f3430cfafef8b680c -r64ad0bbe91a9c7e9229fa9800b93b65f619b9e31 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 6913ef75b5ec527ab771006f3430cfafef8b680c) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 64ad0bbe91a9c7e9229fa9800b93b65f619b9e31) @@ -96,6 +96,7 @@ + Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/HeightStructures/HeightStructuresFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u -r9c2ae58765574fa6fb31136c0361871f7f135c7a -r64ad0bbe91a9c7e9229fa9800b93b65f619b9e31 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/HeightStructures/HeightStructuresFailureMechanismCreateExtensionsTest.cs (.../HeightStructuresFailureMechanismCreateExtensionsTest.cs) (revision 9c2ae58765574fa6fb31136c0361871f7f135c7a) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/HeightStructures/HeightStructuresFailureMechanismCreateExtensionsTest.cs (.../HeightStructuresFailureMechanismCreateExtensionsTest.cs) (revision 64ad0bbe91a9c7e9229fa9800b93b65f619b9e31) @@ -172,7 +172,6 @@ var failureMechanism = new HeightStructuresFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(new CalculationGroup("A", true)); failureMechanism.CalculationsGroup.Children.Add(new CalculationGroup("B", true)); - var registry = new PersistenceRegistry(); Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/CalculationGroupEntityReadExtentionsTest.cs =================================================================== diff -u -r2973c5f790a5131e427bd5f73e2a620044199639 -r64ad0bbe91a9c7e9229fa9800b93b65f619b9e31 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/CalculationGroupEntityReadExtentionsTest.cs (.../CalculationGroupEntityReadExtentionsTest.cs) (revision 2973c5f790a5131e427bd5f73e2a620044199639) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/CalculationGroupEntityReadExtentionsTest.cs (.../CalculationGroupEntityReadExtentionsTest.cs) (revision 64ad0bbe91a9c7e9229fa9800b93b65f619b9e31) @@ -25,8 +25,10 @@ using Application.Ringtoets.Storage.Read; using NUnit.Framework; using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Structures; using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.GrassCoverErosionOutwards.Data; +using Ringtoets.HeightStructures.Data; using Ringtoets.Piping.Data; using Ringtoets.StabilityStoneCover.Data; using Ringtoets.WaveImpactAsphaltCover.Data; @@ -675,6 +677,215 @@ #endregion + #region HeightStructures + + [Test] + public void ReadAsHeightStructuresCalculationGroup_CollectorIsNull_ThrowArgumentNullException() + { + // Setup + var entity = new CalculationGroupEntity(); + + // Call + TestDelegate call = () => entity.ReadAsHeightStructuresCalculationGroup(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + [TestCase("HAbba", 1)] + [TestCase("Dooeis", 0)] + public void ReadAsHeightStructuresCalculationGroup_EntityWithoutChildren_CreateCalculationGroupWithoutChildren( + string name, byte isEditable) + { + // Setup + var entity = new CalculationGroupEntity + { + Name = name, + IsEditable = isEditable + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup group = entity.ReadAsHeightStructuresCalculationGroup(collector); + + // Assert + Assert.AreEqual(name, group.Name); + Assert.AreEqual(Convert.ToBoolean(isEditable), group.IsNameEditable); + CollectionAssert.IsEmpty(group.Children); + } + + [Test] + public void ReadAsHeightStructuresCalculationGroup_EntityWithChildGroups_CreateCalculationGroupWithChildGroups() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Name = "AB", + IsEditable = 0, + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Name = "ABA", + IsEditable = 0, + Order = 0 + }, + new CalculationGroupEntity + { + Name = "ABB", + IsEditable = 1, + Order = 1 + } + }, + Order = 1 + }, + new CalculationGroupEntity + { + Name = "AA", + IsEditable = 1, + Order = 0 + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + var rootGroup = rootGroupEntity.ReadAsHeightStructuresCalculationGroup(collector); + + // Assert + Assert.AreEqual("A", rootGroup.Name); + Assert.IsFalse(rootGroup.IsNameEditable); + + ICalculationBase[] rootChildren = rootGroup.Children.ToArray(); + var rootChildGroup1 = (CalculationGroup) rootChildren[0]; + Assert.AreEqual("AA", rootChildGroup1.Name); + Assert.IsTrue(rootChildGroup1.IsNameEditable); + CollectionAssert.IsEmpty(rootChildGroup1.Children); + var rootChildGroup2 = (CalculationGroup) rootChildren[1]; + Assert.AreEqual("AB", rootChildGroup2.Name); + Assert.IsFalse(rootChildGroup2.IsNameEditable); + + ICalculationBase[] rootChildGroup2Children = rootChildGroup2.Children.ToArray(); + var rootChildGroup1Child1 = (CalculationGroup) rootChildGroup2Children[0]; + Assert.AreEqual("ABA", rootChildGroup1Child1.Name); + Assert.IsFalse(rootChildGroup1Child1.IsNameEditable); + CollectionAssert.IsEmpty(rootChildGroup1Child1.Children); + var rootChildGroup1Child2 = (CalculationGroup) rootChildGroup2Children[1]; + Assert.AreEqual("ABB", rootChildGroup1Child2.Name); + Assert.IsTrue(rootChildGroup1Child2.IsNameEditable); + CollectionAssert.IsEmpty(rootChildGroup1Child2.Children); + } + + [Test] + public void ReadAsHeightStructuresCalculationGroup_EntityWithChildHeightStructuresCalculations_CreateCalculationGroupWithChildCalculations() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + HeightStructuresCalculationEntities = + { + new HeightStructuresCalculationEntity + { + Order = 0, + Name = "1", + FailureProbabilityStructureWithErosion = 1 + }, + new HeightStructuresCalculationEntity + { + Order = 1, + Name = "2", + FailureProbabilityStructureWithErosion = 1 + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + var rootGroup = rootGroupEntity.ReadAsHeightStructuresCalculationGroup(collector); + + // Assert + ICalculationBase[] rootChildren = rootGroup.Children.ToArray(); + Assert.AreEqual(2, rootChildren.Length); + + var rootChildCalculation1 = (StructuresCalculation)rootChildren[0]; + Assert.AreEqual("1", rootChildCalculation1.Name); + + var rootChildCalculation2 = (StructuresCalculation)rootChildren[1]; + Assert.AreEqual("2", rootChildCalculation2.Name); + } + + [Test] + public void ReadAsHeightStructuresCalculationGroup_EntityWithChildHeightStructuresCalculationAndGroups_CreateCalculationGroupWithChildCalculationsAndGroups() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + HeightStructuresCalculationEntities = + { + new HeightStructuresCalculationEntity + { + Order = 0, + Name = "calculation1", + FailureProbabilityStructureWithErosion = 1 + }, + new HeightStructuresCalculationEntity + { + Order = 2, + Name = "calculation2", + FailureProbabilityStructureWithErosion = 1 + } + }, + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Order = 1, + Name = "group1" + }, + new CalculationGroupEntity + { + Order = 3, + Name = "group2" + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + var rootGroup = rootGroupEntity.ReadAsHeightStructuresCalculationGroup(collector); + + // Assert + ICalculationBase[] rootChildren = rootGroup.Children.ToArray(); + Assert.AreEqual(4, rootChildren.Length); + + var rootChildCalculation1 = (StructuresCalculation)rootChildren[0]; + Assert.AreEqual("calculation1", rootChildCalculation1.Name); + + var rootChildGroup1 = (CalculationGroup) rootChildren[1]; + Assert.AreEqual("group1", rootChildGroup1.Name); + + var rootChildCalculation2 = (StructuresCalculation)rootChildren[2]; + Assert.AreEqual("calculation2", rootChildCalculation2.Name); + + var rootChildGroup2 = (CalculationGroup) rootChildren[3]; + Assert.AreEqual("group2", rootChildGroup2.Name); + } + + #endregion + #region Stability Stone Cover [Test] Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/HeightStructures/HeightStructuresCalculationEntityReadExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/HeightStructures/HeightStructuresCalculationEntityReadExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/HeightStructures/HeightStructuresCalculationEntityReadExtensionsTest.cs (revision 64ad0bbe91a9c7e9229fa9800b93b65f619b9e31) @@ -0,0 +1,169 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using Application.Ringtoets.Storage.DbContext; +using Application.Ringtoets.Storage.Read; +using Application.Ringtoets.Storage.Read.HeightStructures; +using Application.Ringtoets.Storage.Serializers; +using Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.HeightStructures.Data; + +namespace Application.Ringtoets.Storage.Test.Read.HeightStructures +{ + [TestFixture] + public class HeightStructuresCalculationEntityReadExtensionsTest + { + [Test] + public void Read_ReadConversionCollectorNull_ThrowArgumentNullException() + { + // Setup + var entity = new HeightStructuresCalculationEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + [TestCase("I have no comments", null, 827364)] + [TestCase("I have a comment", "I am comment", 231)] + public void Read_ValidEntity_ReturnCalculation(string name, string comments, int randomSeed) + { + // Setup + var random = new Random(randomSeed); + var entity = new HeightStructuresCalculationEntity + { + Name = name, + Comments = comments, + UseForeshore = Convert.ToByte(false), + UseBreakWater = Convert.ToByte(false), + StructureNormalOrientation = GetRandomDoubleFromRange(random, 0, 360), + ModelFactorSuperCriticalFlowMean = GetRandomDoubleFromRange(random, -9999.9999, 9999.9999), + AllowedLevelIncreaseStorageMean = GetRandomDoubleFromRange(random, 1e-6, 9999.9999), + AllowedLevelIncreaseStorageStandardDeviation = GetRandomDoubleFromRange(random, 1e-6, 9999.9999), + FlowWidthAtBottomProtectionMean = GetRandomDoubleFromRange(random, 1e-6, 9999.9999), + FlowWidthAtBottomProtectionStandardDeviation = GetRandomDoubleFromRange(random, 1e-6, 9999.9999), + CriticalOvertoppingDischargeMean = GetRandomDoubleFromRange(random, 1e-6, 9999.9999), + CriticalOvertoppingDischargeCoefficientOfVariation = GetRandomDoubleFromRange(random, 1e-6, 9999.9999), + FailureProbabilityStructureWithErosion = random.NextDouble(), + WidthFlowAperturesMean = GetRandomDoubleFromRange(random, 1e-6, 9999.9999), + WidthFlowAperturesCoefficientOfVariation = GetRandomDoubleFromRange(random, 1e-6, 9999.9999) + }; + + var collector = new ReadConversionCollector(); + + // Call + StructuresCalculation calculation = entity.Read(collector); + + // Assert + Assert.AreEqual(name, calculation.Name); + Assert.AreEqual(comments, calculation.Comments); + + HeightStructuresInput input = calculation.InputParameters; + Assert.IsFalse(input.UseForeshore); + Assert.IsFalse(input.UseBreakWater); + + AssertRoundedDouble(entity.StructureNormalOrientation, input.StructureNormalOrientation); + AssertRoundedDouble(entity.ModelFactorSuperCriticalFlowMean, input.ModelFactorSuperCriticalFlow.Mean); + AssertRoundedDouble(entity.AllowedLevelIncreaseStorageMean, input.AllowedLevelIncreaseStorage.Mean); + AssertRoundedDouble(entity.AllowedLevelIncreaseStorageStandardDeviation, input.AllowedLevelIncreaseStorage.StandardDeviation); + AssertRoundedDouble(entity.FlowWidthAtBottomProtectionMean, input.FlowWidthAtBottomProtection.Mean); + AssertRoundedDouble(entity.FlowWidthAtBottomProtectionStandardDeviation, input.FlowWidthAtBottomProtection.StandardDeviation); + AssertRoundedDouble(entity.CriticalOvertoppingDischargeMean, input.CriticalOvertoppingDischarge.Mean); + AssertRoundedDouble(entity.CriticalOvertoppingDischargeCoefficientOfVariation, input.CriticalOvertoppingDischarge.CoefficientOfVariation); + Assert.AreEqual(entity.FailureProbabilityStructureWithErosion, input.FailureProbabilityStructureWithErosion); + AssertRoundedDouble(entity.WidthFlowAperturesMean, input.WidthFlowApertures.Mean); + AssertRoundedDouble(entity.WidthFlowAperturesCoefficientOfVariation, input.WidthFlowApertures.CoefficientOfVariation); + + Assert.IsEmpty(input.ForeshoreGeometry); + Assert.IsNull(input.ForeshoreProfile); + Assert.IsNull(input.HydraulicBoundaryLocation); + Assert.IsNull(input.Structure); + Assert.IsFalse(calculation.HasOutput); + } + + [Test] + [TestCase(true, BreakWaterType.Dam, 123)] + [TestCase(false, BreakWaterType.Wall, 456)] + public void Read_EntityWithForeshoreProfile_ReturnCalculation(bool flagUsage, BreakWaterType type, int randomSeed) + { + // Setup + var random = new Random(randomSeed); + + double breakWaterHeight = random.NextDouble(); + var points = new[] + { + new Point2D(0, 0) + }; + string pointXml = new Point2DXmlSerializer().ToXml(points); + var foreshoreEntity = new ForeshoreProfileEntity + { + BreakWaterHeight = breakWaterHeight, + BreakWaterType = Convert.ToByte(type), + GeometryXml = pointXml + }; + + var entity = new HeightStructuresCalculationEntity + { + UseForeshore = Convert.ToByte(flagUsage), + UseBreakWater = Convert.ToByte(!flagUsage), + ForeshoreProfileEntity = foreshoreEntity, + BreakWaterType = Convert.ToInt16(type), + BreakWaterHeight = breakWaterHeight, + FailureProbabilityStructureWithErosion = 1 + }; + + var collector = new ReadConversionCollector(); + + // Call + StructuresCalculation calculation = entity.Read(collector); + + // Assert + HeightStructuresInput input = calculation.InputParameters; + Assert.AreEqual(flagUsage, input.UseForeshore); + Assert.AreEqual(!flagUsage, input.UseBreakWater); + Assert.AreEqual(type, input.BreakWater.Type); + Assert.AreEqual((RoundedDouble) breakWaterHeight, input.BreakWater.Height, input.BreakWater.Height.GetAccuracy()); + CollectionAssert.AreEqual(points, input.ForeshoreProfile.Geometry); + Assert.IsNotNull(input.ForeshoreProfile); + } + + private static void AssertRoundedDouble(double? entityValue, RoundedDouble roundedDouble) + { + Assert.AreEqual((RoundedDouble) entityValue.ToNullAsNaN(), roundedDouble, roundedDouble.GetAccuracy()); + } + + private static double GetRandomDoubleFromRange(Random random, double lowerLimit, double upperLimit) + { + double difference = upperLimit - lowerLimit; + return lowerLimit + random.NextDouble()*difference; + } + } +} \ No newline at end of file