Index: Ringtoets.sln =================================================================== diff -u -rbe18637e5ba22a4792cbae854df6161152dfea0b -r2d850ad8de01dd4896ada4999d18f787165ce644 --- Ringtoets.sln (.../Ringtoets.sln) (revision be18637e5ba22a4792cbae854df6161152dfea0b) +++ Ringtoets.sln (.../Ringtoets.sln) (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -1916,7 +1916,7 @@ {C90B77DA-E421-43CC-B82E-529651BC21AC} = {C90B77DA-E421-43CC-B82E-529651BC21AC} EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Riskeer.Storage.Core.Test", "Ringtoets\Storage\test\Ringtoets.Storage.Core.Test\Riskeer.Storage.Core.Test.csproj", "{594C5C6D-5833-4E1C-9F30-13A202628EEF}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Riskeer.Storage.Core.Test", "Ringtoets\Storage\test\Riskeer.Storage.Core.Test\Riskeer.Storage.Core.Test.csproj", "{594C5C6D-5833-4E1C-9F30-13A202628EEF}" ProjectSection(ProjectDependencies) = postProject {C90B77DA-E421-43CC-B82E-529651BC21AC} = {C90B77DA-E421-43CC-B82E-529651BC21AC} EndProjectSection Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/App.config'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/BackedUpFileWriterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/BackgroundDataIdentifiersTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/ColorConversionExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/AssessmentSectionCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/BackgroundDataCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/CalculationGroupCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/ClosingStructures/ClosingStructureCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/ClosingStructures/ClosingStructuresFailureMechanismCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/ClosingStructures/ClosingStructuresFailureMechanismSectionResultCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/DuneErosion/DuneErosionFailureMechanismCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/DuneErosion/DuneErosionFailureMechanismSectionResultCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/DuneErosion/DuneLocationCalculationCollectionCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/DuneErosion/DuneLocationCalculationCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/DuneErosion/DuneLocationCalculationOutputCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/DuneErosion/DuneLocationCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/FailureMechanismCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/FailureMechanismSectionCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/ForeshoreProfileCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/GrassCoverErosionInwards/DikeHeightOutputCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/GrassCoverErosionInwards/DikeProfileCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/GrassCoverErosionInwards/GrassCoverErosionInwardsCalculationCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/GrassCoverErosionInwards/GrassCoverErosionInwardsFailureMechanismCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/GrassCoverErosionInwards/GrassCoverErosionInwardsFailureMechanismSectionResultCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/GrassCoverErosionInwards/GrassCoverErosionInwardsOutputCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/GrassCoverErosionInwards/OvertoppingRateOutputCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/GrassCoverErosionOutwards/GrassCoverErosionOutwardsFailureMechanismCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/GrassCoverErosionOutwards/GrassCoverErosionOutwardsFailureMechanismSectionResultCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/GrassCoverErosionOutwards/GrassCoverErosionOutwardsWaveConditionsCalculationCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/GrassCoverErosionOutwards/GrassCoverErosionOutwardsWaveConditionsOutputCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/GrassCoverSlipOffInwards/GrassCoverSlipOffInwardsFailureMechanismCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/GrassCoverSlipOffInwards/GrassCoverSlipOffInwardsFailureMechanismSectionResultCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/GrassCoverSlipOffOutwards/GrassCoverSlipOffOutwardsFailureMechanismCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/GrassCoverSlipOffOutwards/GrassCoverSlipOffOutwardsFailureMechanismSectionResultCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/HeightStructures/HeightStructureCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/HeightStructures/HeightStructuresFailureMechanismCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/HeightStructures/HeightStructuresFailureMechanismSectionResultCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/HydraulicBoundaryLocationCalculationCollectionCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/HydraulicBoundaryLocationCalculationCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/HydraulicBoundaryLocationCalculationOutputCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/HydraulicBoundaryLocationCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/HydraulicLocationConfigurationSettingsCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/IllustrationPoints/GeneralResultCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/IllustrationPoints/IllustrationPointNodeCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/IllustrationPoints/IllustrationPointResultCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/IllustrationPoints/StochastCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/IllustrationPoints/SubMechanismIllustrationPointCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/IllustrationPoints/SubMechanismIllustrationPointStochastCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/IllustrationPoints/TopLevelFaultTreeIllustrationPointCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/IllustrationPoints/TopLevelSubMechanismIllustrationPointCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsCalculationScenarioCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsFailureMechanismCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsFailureMechanismSectionResultCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsOutputCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsPreconsolidationStressCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer1DCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer2DCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSoilProfile1DCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSoilProfile2DCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsStochasticSoilModelCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsStochasticSoilProfileCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSurfaceLineCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/MacrostabilityOutwards/MacroStabilityOutwardsFailureMechanismCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/MacrostabilityOutwards/MacroStabilityOutwardsFailureMechanismSectionResultCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/Microstability/MicrostabilityFailureMechanismCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/Microstability/MicrostabilityFailureMechanismSectionResultCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/PersistenceRegistryTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/Piping/PipingCalculationScenarioCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/Piping/PipingFailureMechanismCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/Piping/PipingFailureMechanismSectionResultCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/Piping/PipingOutputCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/Piping/PipingSoilLayerCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/Piping/PipingSoilProfileCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/Piping/PipingStochasticSoilModelCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/Piping/PipingStochasticSoilProfileCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/Piping/PipingSurfaceLineCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/PipingStructure/PipingStructureFailureMechanismCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/PipingStructure/PipingStructureFailureMechanismSectionResultCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/RiskeerProjectCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/StabilityPointStructures/StabilityPointStructureCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/StabilityPointStructures/StabilityPointStructuresFailureMechanismCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/StabilityPointStructures/StabilityPointStructuresFailureMechanismSectionResultCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/StabilityStoneCover/StabilityStoneCoverFailureMechanismCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/StabilityStoneCover/StabilityStoneCoverFailureMechanismSectionResultCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/StabilityStoneCover/StabilityStoneCoverWaveConditionsCalculationCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/StabilityStoneCover/StabilityStoneCoverWaveConditionsOutputCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/StrengthStabilityLengthwise/StrengthStabilityLengthwiseConstructionFailureMechanismCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/StrengthStabilityLengthwise/StrengthStabilityLengthwiseConstructionFailureMechanismSectionResultCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/StructuresCalculationCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/StructuresOutputCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/TechnicalInnovation/TechnicalInnovationFailureMechanismCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/TechnicalInnovation/TechnicalInnovationFailureMechanismSectionResultCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/WaterPressureAsphaltCover/WaterPressureAsphaltCoverFailureMechanismCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/WaterPressureAsphaltCover/WaterPressureAsphaltCoverFailureMechanismSectionResultCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/WaveImpactAsphaltCover/WaveImpactAsphaltCoverFailureMechanismCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/WaveImpactAsphaltCover/WaveImpactAsphaltCoverFailureMechanismSectionResultCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/WaveImpactAsphaltCover/WaveImpactAsphaltCoverWaveConditionsCalculationCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/WaveImpactAsphaltCover/WaveImpactAsphaltCoverWaveConditionsOutputCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/DbContext/RiskeerEntitiesTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/DoubleConversionExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Exceptions/CannotDeleteBackupFileExceptionTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Exceptions/CannotDetermineFingerprintExceptionTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Exceptions/EntityNotFoundExceptionTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/FingerprintHelperTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/IntegrationTests/StorageSqLiteIntegrationTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Properties/AssemblyInfo.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/AssessmentSectionEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/BackgroundDataEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/BackgroundDataMetaEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/CalculationGroupEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/ClosingStructures/ClosingStructureEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/ClosingStructures/ClosingStructuresCalculationEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/ClosingStructures/ClosingStructuresFailureMechanismMetaEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/ClosingStructures/ClosingStructuresSectionResultEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/DuneErosion/DuneErosionFailureMechanismMetaEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/DuneErosion/DuneErosionSectionResultEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/DuneErosion/DuneLocationCalculationCollectionEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/DuneErosion/DuneLocationCalculationEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/DuneErosion/DuneLocationCalculationOutputEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/DuneErosion/DuneLocationEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/FailureMechanismEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/FailureMechanismSectionEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/ForeshoreProfileReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/GrassCoverErosionInwards/DikeProfileEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/GrassCoverErosionInwards/GrassCoverErosionInwardsCalculationEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/GrassCoverErosionInwards/GrassCoverErosionInwardsDikeHeightOutputEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/GrassCoverErosionInwards/GrassCoverErosionInwardsFailureMechanismMetaEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/GrassCoverErosionInwards/GrassCoverErosionInwardsOutputEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/GrassCoverErosionInwards/GrassCoverErosionInwardsOvertoppingRateOutputEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/GrassCoverErosionInwards/GrassCoverErosionInwardsSectionResultEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/GrassCoverErosionOutwards/GrassCoverErosionOutwardsFailureMechanismMetaEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/GrassCoverErosionOutwards/GrassCoverErosionOutwardsSectionResultEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/GrassCoverErosionOutwards/GrassCoverErosionOutwardsWaveConditionsCalculationEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/GrassCoverErosionOutwards/GrassCoverErosionOutwardsWaveConditionsOutputEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/GrassCoverSlipOffInwardsSectionResultEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/GrassCoverSlipOffOutwardsSectionResultEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/HeightStructures/HeightStructureEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/HeightStructures/HeightStructuresCalculationEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/HeightStructures/HeightStructuresFailureMechanismMetaEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/HeightStructures/HeightStructuresSectionResultEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/HydraulicBoundaryDatabaseEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/HydraulicLocationCalculationCollectionEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/HydraulicLocationCalculationEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/HydraulicLocationEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/HydraulicLocationOutputEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/IllustrationPoints/FaultTreeIllustrationPointEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/IllustrationPoints/GeneralResultFaultTreeIllustrationPointEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/IllustrationPoints/GeneralResultSubMechanismIllustrationPointEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/IllustrationPoints/IllustrationPointResultEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/IllustrationPoints/StochastEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/IllustrationPoints/SubMechanismIllustrationPointEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/IllustrationPoints/SubMechanismIllustrationPointStochastEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/IllustrationPoints/TopLevelFaultTreeIllustrationPointEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/IllustrationPoints/TopLevelSubMechanismIllustrationPointReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsCalculationEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsCalculationOutputEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsFailureMechanismMetaEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsPreconsolidationStressEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsSectionResultEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsSoilLayerOneDEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsSoilLayerTwoDEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsSoilProfileOneDEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsSoilProfileTwoDEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsStochasticSoilProfileEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/MacroStabilityOutwards/MacroStabilityOutwardsFailureMechanismMetaEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/MacroStabilityOutwards/MacroStabilityOutwardsSectionResultEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/MicrostabilitySectionResultEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/Piping/PipingCalculationEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/Piping/PipingCalculationOutputEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/Piping/PipingFailureMechanismMetaEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/Piping/PipingSectionResultEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/Piping/PipingSoilLayerEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/Piping/PipingSoilProfileEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/Piping/PipingStochasticSoilProfileEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/PipingStructure/PipingStructureSectionResultEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/ProjectEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/ReadConversionCollectorTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/StabilityPointStructures/StabilityPointStructureEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/StabilityPointStructures/StabilityPointStructuresCalculationEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/StabilityPointStructures/StabilityPointStructuresFailureMechanismMetaEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/StabilityPointStructures/StabilityPointStructuresSectionResultEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/StabilityStoneCover/StabilityStoneCoverFailureMechanismMetaEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/StabilityStoneCover/StabilityStoneCoverSectionResultEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/StabilityStoneCover/StabilityStoneCoverWaveConditionsCalculationEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/StabilityStoneCover/StabilityStoneCoverWaveConditionsOutputEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/StochasticSoilModelEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/StrengthStabilityLengthwiseConstructionSectionResultEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/StructureCalculationEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/SurfaceLineEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/TechnicalInnovationSectionResultEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/WaterPressureAsphaltCoverSectionResultEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/WaveImpactAsphaltCover/WaveImpactAsphaltCoverFailureMechanismMetaEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/WaveImpactAsphaltCover/WaveImpactAsphaltCoverSectionResultEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/WaveImpactAsphaltCover/WaveImpactAsphaltCoverWaveConditionsCalculationEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Read/WaveImpactAsphaltCover/WaveImpactAsphaltCoverWaveConditionsOutputEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Riskeer.Storage.Core.Test.csproj'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/RiskeerDatabaseCreatorTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/RoundedDoubleConversionExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Serializers/DataCollectionSerializerTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Serializers/MacroStabilityInwardsSliceCollectionXmlSerializerTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Serializers/Point2DCollectionXmlSerializerTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Serializers/Point3DCollectionXmlSerializerTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Serializers/RoughnessPointCollectionXmlSerializerTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Serializers/TangentLineCollectionXmlSerializerTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/SqLiteEntityConnectionStringBuilderTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/StorageSqLiteTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/StorageSqliteCreatorTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/packages.config'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2d850ad8de01dd4896ada4999d18f787165ce644 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/test-data/DatabaseFiles/empty.rtd'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/App.config =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/App.config (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/App.config (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,40 @@ + + + + +
+ + + + + + + + + + + + + + \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/BackedUpFileWriterTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/BackedUpFileWriterTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/BackedUpFileWriterTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,263 @@ +// Copyright (C) Stichting Deltares 2018. 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.IO; +using System.Security.AccessControl; +using Core.Common.TestUtil; +using NUnit.Framework; +using Riskeer.Storage.Core.Exceptions; + +namespace Riskeer.Storage.Core.Test +{ + [TestFixture] + public class BackedUpFileWriterTest + { + private readonly string testWorkDir = TestHelper.GetScratchPadPath(nameof(BackedUpFileWriterTest)); + + [Test] + [TestCase("")] + [TestCase(null)] + [TestCase("\"")] + [TestCase("/")] + public void Constructor_InvalidPath_ThrowsArgumentException(string path) + { + // Call + TestDelegate test = () => new BackedUpFileWriter(path); + + // Assert + Assert.Throws(test); + } + + [Test] + public void Perform_ValidFile_TemporaryFileCreatedFromOriginalAndDeletedAfterwards() + { + // Setup + string writableDirectory = Path.Combine(testWorkDir, nameof(Perform_ValidFile_TemporaryFileCreatedFromOriginalAndDeletedAfterwards)); + string filePath = Path.Combine(writableDirectory, "iDoExist.txt"); + string temporaryFilePath = filePath + "~"; + const string testContent = "Some test text to write into file."; + + using (new DirectoryDisposeHelper(testWorkDir, nameof(Perform_ValidFile_TemporaryFileCreatedFromOriginalAndDeletedAfterwards))) + using (new FileDisposeHelper(filePath)) + using (new FileDisposeHelper(temporaryFilePath)) + { + File.WriteAllText(filePath, testContent); + + var writer = new BackedUpFileWriter(filePath); + + // Call + writer.Perform(() => + { + // Assert + Assert.IsFalse(File.Exists(filePath)); + Assert.IsTrue(File.Exists(temporaryFilePath)); + Assert.AreEqual(testContent, File.ReadAllText(temporaryFilePath)); + }); + Assert.False(File.Exists(temporaryFilePath)); + } + } + + [Test] + public void Perform_ActionThrowsExceptionValidPathFileExists_OriginalFileRevertedAndExceptionThrown() + { + // Setup + string writableDirectory = Path.Combine(testWorkDir, nameof(Perform_ActionThrowsExceptionValidPathFileExists_OriginalFileRevertedAndExceptionThrown)); + string filePath = Path.Combine(writableDirectory, "iDoExist.txt"); + string temporaryFilePath = filePath + "~"; + const string testContent = "Some test text to write into file."; + + using (new DirectoryDisposeHelper(testWorkDir, nameof(Perform_ActionThrowsExceptionValidPathFileExists_OriginalFileRevertedAndExceptionThrown))) + { + File.WriteAllText(filePath, testContent); + + var writer = new BackedUpFileWriter(filePath); + var exception = new IOException(); + + // Precondition + Assert.IsTrue(File.Exists(filePath)); + + // Call + TestDelegate test = () => writer.Perform(() => { throw exception; }); + + Exception actualException = Assert.Throws(exception.GetType(), test); + Assert.AreSame(exception, actualException); + + Assert.IsFalse(File.Exists(temporaryFilePath)); + Assert.IsTrue(File.Exists(filePath)); + Assert.AreEqual(testContent, File.ReadAllText(filePath)); + } + } + + [Test] + public void Perform_ValidPathFileExistsTemporaryFileExistsAndCannotBeDeleted_ThrowsIOException() + { + // Setup + string filePath = Path.Combine(testWorkDir, "iDoExist.txt"); + string temporaryFilePath = filePath + "~"; + + using (new FileDisposeHelper(filePath)) + using (var tempFileHelper = new FileDisposeHelper(temporaryFilePath)) + { + tempFileHelper.LockFiles(); + + var writer = new BackedUpFileWriter(filePath); + + // Call + TestDelegate test = () => writer.Perform(() => {}); + + // Assert + string message = Assert.Throws(test).Message; + string expectedMessage = $"Er bestaat al een tijdelijk bestand ({temporaryFilePath}) dat niet verwijderd kan worden. Dit bestand dient handmatig verwijderd te worden."; + Assert.AreEqual(message, expectedMessage); + } + } + + [Test] + public void Perform_ValidPathFileExistsDirectoryNotWritable_ThrowsIOException() + { + // Setup + string notWritableDirectory = Path.Combine(testWorkDir, nameof(Perform_ValidPathFileExistsDirectoryNotWritable_ThrowsIOException)); + string filePath = Path.Combine(notWritableDirectory, "iDoExist.txt"); + + using (var directoryHelper = new DirectoryDisposeHelper(testWorkDir, nameof(Perform_ValidPathFileExistsDirectoryNotWritable_ThrowsIOException))) + using (new FileDisposeHelper(filePath)) + { + var writer = new BackedUpFileWriter(filePath); + + // Call + TestDelegate test = () => writer.Perform(() => {}); + + directoryHelper.LockDirectory(FileSystemRights.Write); + // Assert + string expectedMessage = $"Kan geen tijdelijk bestand maken van het originele bestand ({filePath})."; + string message = Assert.Throws(test).Message; + Assert.AreEqual(expectedMessage, message); + } + } + + [Test] + public void Perform_TargetFileDoesNotExistDeleteRightsRevoked_DoesNotThrow() + { + // Setup + string noAccessDirectory = Path.Combine(testWorkDir, nameof(Perform_TargetFileDoesNotExistDeleteRightsRevoked_DoesNotThrow)); + string filePath = Path.Combine(noAccessDirectory, "iDoNotExist.txt"); + + using (var directoryHelper = new DirectoryDisposeHelper(testWorkDir, nameof(Perform_TargetFileDoesNotExistDeleteRightsRevoked_DoesNotThrow))) + { + var helper = new BackedUpFileWriter(filePath); + + // Call + TestDelegate test = () => helper.Perform(() => {}); + + directoryHelper.LockDirectory(FileSystemRights.Delete); + // Assert + Assert.DoesNotThrow(test); + } + } + + [Test] + public void Perform_TargetFileExistsCannotDeleteFile_ThrowsCannotDeleteBackupFileException() + { + // Setup + string filePath = Path.Combine(testWorkDir, nameof(Perform_TargetFileExistsCannotDeleteFile_ThrowsCannotDeleteBackupFileException)); + string temporaryFilePath = filePath + "~"; + + using (new FileDisposeHelper(filePath)) + using (var temporaryFileHelper = new FileDisposeHelper(temporaryFilePath)) + { + var helper = new BackedUpFileWriter(filePath); + + // Call + TestDelegate test = () => helper.Perform(() => temporaryFileHelper.LockFiles()); + + // Assert + string expectedMessage = $"Kan het tijdelijke bestand ({temporaryFilePath}) niet opruimen. Het tijdelijke bestand dient handmatig verwijderd te worden."; + string message = Assert.Throws(test).Message; + Assert.AreEqual(expectedMessage, message); + } + } + + [Test] + public void Perform_ActionThrowsExceptionTargetFileExistsCannotDeleteFile_ThrowsIOException() + { + // Setup + string filePath = Path.Combine(testWorkDir, nameof(Perform_ActionThrowsExceptionTargetFileExistsCannotDeleteFile_ThrowsIOException)); + string temporaryFilePath = filePath + "~"; + + using (new FileDisposeHelper(filePath)) + using (var temporaryFileHelper = new FileDisposeHelper(temporaryFilePath)) + { + var helper = new BackedUpFileWriter(filePath); + + // Call + TestDelegate test = () => helper.Perform(() => + { + temporaryFileHelper.LockFiles(); + throw new Exception(); + }); + + // Assert + string expectedMessage = $"Kan het originele bestand ({filePath}) niet herstellen. Het tijdelijke bestand dient handmatig hersteld te worden."; + string message = Assert.Throws(test).Message; + Assert.AreEqual(expectedMessage, message); + } + } + + [Test] + public void Perform_ActionThrowsExceptionTargetFileExistsCannotMoveFile_ThrowsIOException() + { + // Setup + string noAccessDirectory = Path.Combine(testWorkDir, nameof(Perform_ActionThrowsExceptionTargetFileExistsCannotMoveFile_ThrowsIOException)); + string filePath = Path.Combine(noAccessDirectory, "iDoExist.txt"); + + using (var directoryHelper = new DirectoryDisposeHelper(testWorkDir, nameof(Perform_ActionThrowsExceptionTargetFileExistsCannotMoveFile_ThrowsIOException))) + using (new FileDisposeHelper(filePath)) + { + var helper = new BackedUpFileWriter(filePath); + + // Call + TestDelegate test = () => helper.Perform(() => + { + directoryHelper.LockDirectory(FileSystemRights.FullControl); + throw new Exception(); + }); + + // Assert + string expectedMessage = $"Kan het originele bestand ({filePath}) niet herstellen. Het tijdelijke bestand dient handmatig hersteld te worden."; + string message = Assert.Throws(test).Message; + Assert.AreEqual(expectedMessage, message); + } + } + + [OneTimeSetUp] + public void SetUpFixture() + { + Directory.CreateDirectory(testWorkDir); + } + + [OneTimeTearDown] + public void TearDownFixture() + { + Directory.Delete(testWorkDir, true); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/BackgroundDataIdentifiersTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/BackgroundDataIdentifiersTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/BackgroundDataIdentifiersTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,39 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; + +namespace Riskeer.Storage.Core.Test +{ + [TestFixture] + public class BackgroundDataIdentifiersTest + { + [Test] + public void BackgroundDataIdentifiers_ExpectedValues() + { + Assert.AreEqual("IsConfigured", BackgroundDataIdentifiers.IsConfigured); + Assert.AreEqual("SourceCapabilitiesUrl", BackgroundDataIdentifiers.SourceCapabilitiesUrl); + Assert.AreEqual("SelectedCapabilityIdentifier", BackgroundDataIdentifiers.SelectedCapabilityIdentifier); + Assert.AreEqual("PreferredFormat", BackgroundDataIdentifiers.PreferredFormat); + Assert.AreEqual("WellKnownTileSource", BackgroundDataIdentifiers.WellKnownTileSource); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/ColorConversionExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/ColorConversionExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/ColorConversionExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,103 @@ +// Copyright (C) Stichting Deltares 2018. 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.Drawing; +using Core.Common.TestUtil; +using NUnit.Framework; + +namespace Riskeer.Storage.Core.Test +{ + [TestFixture] + public class ColorConversionExtensionsTest + { + [Test] + public void ToInt64_WithColor_ReturnsArgbValue() + { + // Setup + const int argb = 123; + Color color = Color.FromArgb(argb); + + // Call + long? result = color.ToInt64(); + + // Assert + Assert.AreEqual(argb, result); + } + + [Test] + public void ToInt64_WithEmptyColor_ReturnsNull() + { + // Call + long? result = Color.Empty.ToInt64(); + + // Assert + Assert.IsNull(result); + } + + [Test] + public void ToColor_WithValue_ReturnsColor() + { + // Setup + long? argb = 123; + + // Call + Color color = argb.ToColor(); + + // Assert + Assert.AreEqual(Color.FromArgb(Convert.ToInt32(argb)), color); + } + + [Test] + public void ToColor_ArgbNull_ReturnsEmptyColor() + { + // Call + Color color = ColorConversionExtensions.ToColor(null); + + // Assert + Assert.AreEqual(Color.Empty, color); + } + + [Test] + [TestCaseSource(nameof(ColorsToTest))] + public void GivenColor_WhenConversionRoundtrip_ThenSameColor(Color color) + { + // When + long? intValue = color.ToInt64(); + Color colorValue = intValue.ToColor(); + + // Then + Assert.AreEqual(color.ToArgb(), colorValue.ToArgb()); + } + + private static IEnumerable ColorsToTest() + { + var random = new Random(31); + yield return Color.Black; + yield return Color.White; + yield return Color.Empty; + yield return Color.Transparent; + yield return Color.FromArgb(random.Next()); + yield return Color.FromKnownColor(random.NextEnumValue()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/AssessmentSectionCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/AssessmentSectionCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/AssessmentSectionCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,340 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Contribution; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Integration.Data; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Create +{ + [TestFixture] + public class AssessmentSectionCreateExtensionsTest + { + [Test] + [TestCase(AssessmentSectionComposition.Dike)] + [TestCase(AssessmentSectionComposition.DikeAndDune)] + [TestCase(AssessmentSectionComposition.Dune)] + public void Create_WithoutCollector_ThrowsArgumentNullException(AssessmentSectionComposition assessmentSectionComposition) + { + // Setup + var assessmentSection = new AssessmentSection(assessmentSectionComposition); + + // Call + TestDelegate test = () => assessmentSection.Create(null, 0); + + // Assert + string parameterName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", parameterName); + } + + [Test] + [TestCase(AssessmentSectionComposition.Dike)] + [TestCase(AssessmentSectionComposition.DikeAndDune)] + [TestCase(AssessmentSectionComposition.Dune)] + public void Create_WithCollector_ReturnsAssessmentSectionEntityWithCompositionAndFailureMechanisms(AssessmentSectionComposition assessmentSectionComposition) + { + // Setup + const string testId = "testId"; + const string testName = "testName"; + const string comments = "Some text"; + const double lowerLimitNorm = 0.05; + const double signalingNorm = 0.02; + var random = new Random(65); + int order = random.Next(); + + const string mapDataName = "map data name"; + const double transparency = 0.3; + const bool isVisible = true; + const BackgroundDataType backgroundType = BackgroundDataType.Wmts; + var normativeNorm = random.NextEnumValue(); + var assessmentSection = new AssessmentSection(assessmentSectionComposition) + { + Id = testId, + Name = testName, + Comments = + { + Body = comments + }, + FailureMechanismContribution = + { + LowerLimitNorm = lowerLimitNorm, + SignalingNorm = signalingNorm, + NormativeNorm = normativeNorm + }, + BackgroundData = + { + Name = mapDataName, + Transparency = (RoundedDouble) transparency, + IsVisible = isVisible, + Configuration = new WmtsBackgroundDataConfiguration(false, null, null, null) + } + }; + var registry = new PersistenceRegistry(); + + // Call + AssessmentSectionEntity entity = assessmentSection.Create(registry, order); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(Convert.ToByte(assessmentSectionComposition), entity.Composition); + Assert.AreEqual(testId, entity.Id); + Assert.AreEqual(testName, entity.Name); + Assert.AreEqual(comments, entity.Comments); + Assert.AreEqual(lowerLimitNorm, entity.LowerLimitNorm); + Assert.AreEqual(signalingNorm, entity.SignalingNorm); + Assert.AreEqual(Convert.ToByte(normativeNorm), entity.NormativeNormType); + Assert.AreEqual(18, entity.FailureMechanismEntities.Count); + Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short) FailureMechanismType.Piping)); + Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short) FailureMechanismType.GrassRevetmentTopErosionAndInwards)); + Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short) FailureMechanismType.MacroStabilityInwards)); + Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short) FailureMechanismType.MacroStabilityOutwards)); + Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short) FailureMechanismType.Microstability)); + Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short) FailureMechanismType.StabilityStoneRevetment)); + Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short) FailureMechanismType.WaveImpactOnAsphaltRevetment)); + Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short) FailureMechanismType.WaterOverpressureAsphaltRevetment)); + Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short) FailureMechanismType.GrassRevetmentErosionOutwards)); + Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short) FailureMechanismType.GrassRevetmentSlidingOutwards)); + Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short) FailureMechanismType.GrassRevetmentSlidingInwards)); + Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short) FailureMechanismType.StructureHeight)); + Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short) FailureMechanismType.ReliabilityClosingOfStructure)); + Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short) FailureMechanismType.PipingAtStructure)); + Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short) FailureMechanismType.StabilityPointStructures)); + Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short) FailureMechanismType.StrengthAndStabilityParallelConstruction)); + Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short) FailureMechanismType.DuneErosion)); + Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short) FailureMechanismType.TechnicalInnovations)); + Assert.AreEqual(order, entity.Order); + + Assert.IsNull(entity.ReferenceLinePointXml); + + Assert.AreEqual(1, entity.BackgroundDataEntities.Count); + BackgroundDataEntity backgroundDataEntity = entity.BackgroundDataEntities.Single(); + Assert.IsNotNull(backgroundDataEntity); + Assert.AreEqual(mapDataName, backgroundDataEntity.Name); + Assert.AreEqual(transparency, backgroundDataEntity.Transparency); + Assert.AreEqual(Convert.ToByte(isVisible), backgroundDataEntity.IsVisible); + Assert.AreEqual(Convert.ToByte(backgroundType), backgroundDataEntity.BackgroundDataType); + + Assert.AreEqual(1, backgroundDataEntity.BackgroundDataMetaEntities.Count); + BackgroundDataMetaEntity isConfiguredMetaEntity = backgroundDataEntity.BackgroundDataMetaEntities.First(); + Assert.AreEqual("IsConfigured", isConfiguredMetaEntity.Key); + Assert.AreEqual("0", isConfiguredMetaEntity.Value); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalName = "name"; + const string originalComments = "comments"; + + var section = new AssessmentSection(AssessmentSectionComposition.Dike) + { + Name = originalName, + Comments = + { + Body = originalComments + } + }; + + var registry = new PersistenceRegistry(); + + // Call + AssessmentSectionEntity entity = section.Create(registry, 0); + + // Assert + Assert.AreNotSame(originalName, entity.Name, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreNotSame(originalComments, entity.Comments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + + Assert.AreEqual(originalName, entity.Name); + Assert.AreEqual(originalComments, entity.Comments); + } + + [Test] + public void Create_HydraulicBoundaryDatabaseNotLinked_SetsExpectedPropertiesToEntity() + { + // Setup + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + assessmentSection.SetHydraulicBoundaryLocationCalculations(assessmentSection.HydraulicBoundaryDatabase.Locations); + + var registry = new PersistenceRegistry(); + + // Call + AssessmentSectionEntity entity = assessmentSection.Create(registry, 0); + + // Assert + CollectionAssert.IsEmpty(entity.HydraulicBoundaryDatabaseEntities); + CollectionAssert.IsEmpty(entity.HydraulicLocationEntities); + + AssertHydraulicLocationCalculationCollectionEntities(assessmentSection, entity); + } + + [Test] + public void Create_HydraulicBoundaryDatabaseLinked_SetsExpectedPropertiesToEntity() + { + // Setup + const string testFilePath = "path"; + const string testVersion = "1"; + + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) + { + HydraulicBoundaryDatabase = + { + FilePath = testFilePath, + Version = testVersion, + Locations = + { + new HydraulicBoundaryLocation(-1, "name", 1, 2) + } + } + }; + assessmentSection.SetHydraulicBoundaryLocationCalculations(assessmentSection.HydraulicBoundaryDatabase.Locations); + SetHydraulicBoundaryLocationCalculationInputsOfAssessmentSection(assessmentSection); + + var registry = new PersistenceRegistry(); + + // Call + AssessmentSectionEntity entity = assessmentSection.Create(registry, 0); + + // Assert + HydraulicBoundaryDatabaseEntity hydraulicBoundaryDatabaseEntity = entity.HydraulicBoundaryDatabaseEntities.Single(); + + HydraulicBoundaryDatabase hydraulicBoundaryDatabase = assessmentSection.HydraulicBoundaryDatabase; + Assert.AreEqual(hydraulicBoundaryDatabase.FilePath, hydraulicBoundaryDatabaseEntity.FilePath); + Assert.AreEqual(hydraulicBoundaryDatabase.Version, hydraulicBoundaryDatabaseEntity.Version); + + HydraulicLocationConfigurationSettings settings = hydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings; + Assert.AreEqual(settings.FilePath, hydraulicBoundaryDatabaseEntity.HydraulicLocationConfigurationSettingsFilePath); + Assert.AreEqual(settings.ScenarioName, hydraulicBoundaryDatabaseEntity.HydraulicLocationConfigurationSettingsScenarioName); + Assert.AreEqual(settings.Year, hydraulicBoundaryDatabaseEntity.HydraulicLocationConfigurationSettingsYear); + Assert.AreEqual(settings.Scope, hydraulicBoundaryDatabaseEntity.HydraulicLocationConfigurationSettingsScope); + Assert.AreEqual(settings.SeaLevel, hydraulicBoundaryDatabaseEntity.HydraulicLocationConfigurationSettingsSeaLevel); + Assert.AreEqual(settings.RiverDischarge, hydraulicBoundaryDatabaseEntity.HydraulicLocationConfigurationSettingsRiverDischarge); + Assert.AreEqual(settings.LakeLevel, hydraulicBoundaryDatabaseEntity.HydraulicLocationConfigurationSettingsLakeLevel); + Assert.AreEqual(settings.WindDirection, hydraulicBoundaryDatabaseEntity.HydraulicLocationConfigurationSettingsWindDirection); + Assert.AreEqual(settings.WindSpeed, hydraulicBoundaryDatabaseEntity.HydraulicLocationConfigurationSettingsWindSpeed); + Assert.AreEqual(settings.Comment, hydraulicBoundaryDatabaseEntity.HydraulicLocationConfigurationSettingsComment); + + int expectedNrOfHydraulicBoundaryLocations = hydraulicBoundaryDatabase.Locations.Count; + Assert.AreEqual(expectedNrOfHydraulicBoundaryLocations, entity.HydraulicLocationEntities.Count); + + AssertHydraulicLocationCalculationCollectionEntities(assessmentSection, entity); + } + + [Test] + public void Create_WithReferenceLine_AddsReferenceLinePointEntities() + { + // Setup + var points = new[] + { + new Point2D(1, 0), + new Point2D(2, 3), + new Point2D(5, 3) + }; + + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + assessmentSection.ReferenceLine.SetGeometry(points); + + var registry = new PersistenceRegistry(); + + // Call + AssessmentSectionEntity entity = assessmentSection.Create(registry, 0); + + // Assert + string expectedXml = new Point2DCollectionXmlSerializer().ToXml(points); + Assert.AreEqual(expectedXml, entity.ReferenceLinePointXml); + } + + private static void AssertHydraulicLocationCalculationCollectionEntities(AssessmentSection assessmentSection, AssessmentSectionEntity entity) + { + AssertHydraulicLocationCalculationCollectionEntity(assessmentSection.WaveHeightCalculationsForFactorizedLowerLimitNorm, + entity.HydraulicLocationCalculationCollectionEntity); + AssertHydraulicLocationCalculationCollectionEntity(assessmentSection.WaveHeightCalculationsForLowerLimitNorm, + entity.HydraulicLocationCalculationCollectionEntity1); + AssertHydraulicLocationCalculationCollectionEntity(assessmentSection.WaveHeightCalculationsForSignalingNorm, + entity.HydraulicLocationCalculationCollectionEntity2); + AssertHydraulicLocationCalculationCollectionEntity(assessmentSection.WaveHeightCalculationsForFactorizedSignalingNorm, + entity.HydraulicLocationCalculationCollectionEntity3); + + AssertHydraulicLocationCalculationCollectionEntity(assessmentSection.WaterLevelCalculationsForFactorizedLowerLimitNorm, + entity.HydraulicLocationCalculationCollectionEntity4); + AssertHydraulicLocationCalculationCollectionEntity(assessmentSection.WaterLevelCalculationsForLowerLimitNorm, + entity.HydraulicLocationCalculationCollectionEntity5); + AssertHydraulicLocationCalculationCollectionEntity(assessmentSection.WaterLevelCalculationsForSignalingNorm, + entity.HydraulicLocationCalculationCollectionEntity6); + AssertHydraulicLocationCalculationCollectionEntity(assessmentSection.WaterLevelCalculationsForFactorizedSignalingNorm, + entity.HydraulicLocationCalculationCollectionEntity7); + } + + private static void SetHydraulicBoundaryLocationCalculationInputsOfAssessmentSection(AssessmentSection assessmentSection) + { + SetHydraulicBoundaryLocationCalculationInputs(assessmentSection.WaterLevelCalculationsForFactorizedSignalingNorm, 1); + SetHydraulicBoundaryLocationCalculationInputs(assessmentSection.WaterLevelCalculationsForSignalingNorm, 2); + SetHydraulicBoundaryLocationCalculationInputs(assessmentSection.WaterLevelCalculationsForLowerLimitNorm, 3); + SetHydraulicBoundaryLocationCalculationInputs(assessmentSection.WaterLevelCalculationsForFactorizedLowerLimitNorm, 4); + + SetHydraulicBoundaryLocationCalculationInputs(assessmentSection.WaveHeightCalculationsForFactorizedSignalingNorm, 5); + SetHydraulicBoundaryLocationCalculationInputs(assessmentSection.WaterLevelCalculationsForSignalingNorm, 6); + SetHydraulicBoundaryLocationCalculationInputs(assessmentSection.WaveHeightCalculationsForLowerLimitNorm, 7); + SetHydraulicBoundaryLocationCalculationInputs(assessmentSection.WaveHeightCalculationsForFactorizedLowerLimitNorm, 8); + } + + private static void SetHydraulicBoundaryLocationCalculationInputs(IEnumerable calculations, + int seed) + { + var random = new Random(seed); + foreach (HydraulicBoundaryLocationCalculation calculation in calculations) + { + calculation.InputParameters.ShouldIllustrationPointsBeCalculated = random.NextBoolean(); + } + } + + private static void AssertHydraulicLocationCalculationCollectionEntity(IEnumerable expectedCalculations, + HydraulicLocationCalculationCollectionEntity actualCollectionEntity) + { + Assert.IsNotNull(actualCollectionEntity); + + ICollection hydraulicLocationCalculationEntities = actualCollectionEntity.HydraulicLocationCalculationEntities; + Assert.AreEqual(expectedCalculations.Count(), hydraulicLocationCalculationEntities.Count); + + var i = 0; + foreach (HydraulicLocationCalculationEntity actualCalculationEntity in hydraulicLocationCalculationEntities) + { + HydraulicBoundaryLocationCalculation expectedCalculation = expectedCalculations.ElementAt(i); + Assert.AreEqual(Convert.ToByte(expectedCalculation.InputParameters.ShouldIllustrationPointsBeCalculated), + actualCalculationEntity.ShouldIllustrationPointsBeCalculated); + i++; + } + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/BackgroundDataCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/BackgroundDataCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/BackgroundDataCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,179 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Data; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.AssessmentSection; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create +{ + [TestFixture] + public class BackgroundDataCreateExtensionsTest + { + [Test] + public void Create_BackgroundDataNull_ThrowArgumentNullException() + { + // Call + TestDelegate test = () => ((BackgroundData) null).Create(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("backgroundData", exception.ParamName); + } + + [Test] + public void Create_BackgroundDataContainsConfiguredWMTSConfiguration_ReturnsBackgroundDataEntity() + { + // Setup + const string name = "background"; + const string sourceCapabilitiesUrl = "//url"; + const string selectedCapabilityName = "selectedName"; + const string preferredFormat = "image/png"; + const bool isVisible = true; + const bool isConfigured = true; + var transparancy = (RoundedDouble) 0.3; + + var configuration = new WmtsBackgroundDataConfiguration(isConfigured, + sourceCapabilitiesUrl, + selectedCapabilityName, + preferredFormat); + + var backgroundData = new BackgroundData(configuration) + { + IsVisible = isVisible, + Transparency = transparancy, + Name = name + }; + + // Call + BackgroundDataEntity entity = backgroundData.Create(); + + // Assert + Assert.AreEqual(name, entity.Name); + Assert.AreEqual(Convert.ToByte(isVisible), entity.IsVisible); + Assert.AreEqual(transparancy, entity.Transparency); + + var expectedKeyValuePairs = new Dictionary + { + { + BackgroundDataIdentifiers.IsConfigured, Convert.ToByte(isConfigured).ToString() + }, + { + BackgroundDataIdentifiers.SourceCapabilitiesUrl, sourceCapabilitiesUrl + }, + { + BackgroundDataIdentifiers.SelectedCapabilityIdentifier, selectedCapabilityName + }, + { + BackgroundDataIdentifiers.PreferredFormat, preferredFormat + } + }; + + IEnumerable> actualKeyValuePairs = entity.BackgroundDataMetaEntities.Select( + metaEntity => new KeyValuePair(metaEntity.Key, metaEntity.Value)); + CollectionAssert.AreEquivalent(expectedKeyValuePairs, actualKeyValuePairs); + } + + [Test] + public void Create_BackgroundDataContainsUnconfiguredWMTSConfiguration_ReturnsBackgroundDataEntity() + { + // Setup + const string name = "background"; + const bool isVisible = true; + const bool isConfigured = false; + var transparancy = (RoundedDouble) 0.3; + + var configuration = new WmtsBackgroundDataConfiguration(); + + var backgroundData = new BackgroundData(configuration) + { + IsVisible = isVisible, + Transparency = transparancy, + Name = name + }; + + // Call + BackgroundDataEntity entity = backgroundData.Create(); + + // Assert + Assert.AreEqual(name, entity.Name); + Assert.AreEqual(Convert.ToByte(isVisible), entity.IsVisible); + Assert.AreEqual(transparancy, entity.Transparency); + + var expectedKeyValuePairs = new Dictionary + { + { + BackgroundDataIdentifiers.IsConfigured, Convert.ToByte(isConfigured).ToString() + } + }; + + IEnumerable> actualKeyValuePairs = entity.BackgroundDataMetaEntities.Select( + metaEntity => new KeyValuePair(metaEntity.Key, metaEntity.Value)); + CollectionAssert.AreEquivalent(expectedKeyValuePairs, actualKeyValuePairs); + } + + [Test] + public void Create_BackgroundDataContainsWellKnownConfiguration_ReturnsBackgroundDataEntity() + { + // Setup + var random = new Random(21); + var wellKnownTileSource = random.NextEnumValue(); + + const string name = "background"; + const bool isVisible = true; + const BackgroundDataType backgroundDataType = BackgroundDataType.WellKnown; + var transparancy = (RoundedDouble) 0.3; + + var configuration = new WellKnownBackgroundDataConfiguration(wellKnownTileSource); + var backgroundData = new BackgroundData(configuration) + { + IsVisible = isVisible, + Transparency = transparancy, + Name = name + }; + + // Call + BackgroundDataEntity entity = backgroundData.Create(); + + // Assert + Assert.AreEqual(name, entity.Name); + Assert.AreEqual(Convert.ToByte(isVisible), entity.IsVisible); + Assert.AreEqual(transparancy, entity.Transparency); + Assert.AreEqual(Convert.ToByte(backgroundDataType), entity.BackgroundDataType); + + var expectedKeyValuePairs = new Dictionary + { + { + BackgroundDataIdentifiers.WellKnownTileSource, ((int) wellKnownTileSource).ToString() + } + }; + IEnumerable> actualKeyValuePairs = entity.BackgroundDataMetaEntities.Select( + metaEntity => new KeyValuePair(metaEntity.Key, metaEntity.Value)); + CollectionAssert.AreEquivalent(expectedKeyValuePairs, actualKeyValuePairs); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/CalculationGroupCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/CalculationGroupCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/CalculationGroupCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,1005 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.ClosingStructures.Data; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Structures; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.GrassCoverErosionOutwards.Data; +using Ringtoets.HeightStructures.Data; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.Piping.Data; +using Ringtoets.StabilityPointStructures.Data; +using Ringtoets.StabilityStoneCover.Data; +using Ringtoets.WaveImpactAsphaltCover.Data; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create +{ + [TestFixture] + public class CalculationGroupCreateExtensionsTest + { + [Test] + public void Create_RegistryIsNull_ThrowArgumentNullException() + { + // Setup + var group = new CalculationGroup(); + + // Call + TestDelegate call = () => group.Create(null, 0); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(0)] + [TestCase(123)] + public void Create_GroupWithoutChildren_CreateEntity(int order) + { + // Setup + const string name = "blaballab"; + var group = new CalculationGroup + { + Name = name + }; + + var registry = new PersistenceRegistry(); + + // Call + CalculationGroupEntity entity = group.Create(registry, order); + + // Assert + Assert.AreEqual(name, entity.Name); + Assert.AreEqual(order, entity.Order); + + CollectionAssert.IsEmpty(entity.CalculationGroupEntity1); + CollectionAssert.IsEmpty(entity.FailureMechanismEntities); + Assert.IsNull(entity.ParentCalculationGroupEntityId); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string name = "original"; + var group = new CalculationGroup + { + Name = name + }; + + var registry = new PersistenceRegistry(); + + // Call + CalculationGroupEntity entity = group.Create(registry, 0); + + // Assert + Assert.AreNotSame(name, entity.Name, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(name, entity.Name); + } + + [Test] + public void Create_GroupWithChildren_CreateEntities() + { + // Setup + const string name = "blaballab"; + var group = new CalculationGroup + { + Name = name + }; + group.Children.Add(new CalculationGroup + { + Name = "A", + Children = + { + new CalculationGroup + { + Name = "AA" + }, + new CalculationGroup + { + Name = "AB" + } + } + }); + group.Children.Add(new CalculationGroup + { + Name = "B" + }); + + var registry = new PersistenceRegistry(); + + // Call + CalculationGroupEntity entity = group.Create(registry, 0); + + // Assert + Assert.AreEqual(name, entity.Name); + Assert.AreEqual(0, entity.Order); + + CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity1.ToArray(); + Assert.AreEqual(2, childGroupEntities.Length); + + CalculationGroupEntity childEntity1 = childGroupEntities[0]; + Assert.AreEqual("A", childEntity1.Name); + Assert.AreEqual(0, childEntity1.Order); + Assert.AreEqual(2, childEntity1.CalculationGroupEntity1.Count); + CalculationGroupEntity childEntity1ChildEntity1 = childEntity1.CalculationGroupEntity1.ElementAt(0); + Assert.AreEqual("AA", childEntity1ChildEntity1.Name); + Assert.AreEqual(0, childEntity1ChildEntity1.Order); + CollectionAssert.IsEmpty(childEntity1ChildEntity1.CalculationGroupEntity1); + CalculationGroupEntity childEntity1ChildEntity2 = childEntity1.CalculationGroupEntity1.ElementAt(1); + Assert.AreEqual("AB", childEntity1ChildEntity2.Name); + Assert.AreEqual(1, childEntity1ChildEntity2.Order); + CollectionAssert.IsEmpty(childEntity1ChildEntity2.CalculationGroupEntity1); + + CalculationGroupEntity childEntity2 = childGroupEntities[1]; + Assert.AreEqual("B", childEntity2.Name); + Assert.AreEqual(1, childEntity2.Order); + CollectionAssert.IsEmpty(childEntity2.CalculationGroupEntity1); + } + + [Test] + public void Create_GroupWithChildPipingCalculations_CreateEntities() + { + // Setup + var generalInputParameters = new GeneralPipingInput(); + var group = new CalculationGroup + { + Children = + { + new PipingCalculationScenario(generalInputParameters) + { + Name = "A" + }, + new PipingCalculationScenario(generalInputParameters) + { + Name = "B" + } + } + }; + + var registry = new PersistenceRegistry(); + + // Call + CalculationGroupEntity entity = group.Create(registry, 0); + + // Assert + PipingCalculationEntity[] childCalculationEntities = entity.PipingCalculationEntities.ToArray(); + Assert.AreEqual(2, childCalculationEntities.Length); + + PipingCalculationEntity childEntity1 = childCalculationEntities[0]; + Assert.AreEqual("A", childEntity1.Name); + Assert.AreEqual(0, childEntity1.Order); + PipingCalculationEntity childEntity2 = childCalculationEntities[1]; + Assert.AreEqual("B", childEntity2.Name); + Assert.AreEqual(1, childEntity2.Order); + } + + [Test] + public void Create_GroupWithChildPipingCalculationsAndChildCalculationGroups_CreateEntities() + { + // Setup + var generalInputParameters = new GeneralPipingInput(); + var group = new CalculationGroup + { + Children = + { + new CalculationGroup + { + Name = "A" + }, + new PipingCalculationScenario(generalInputParameters) + { + Name = "B" + }, + new CalculationGroup + { + Name = "C" + }, + new PipingCalculationScenario(generalInputParameters) + { + Name = "D" + } + } + }; + + var registry = new PersistenceRegistry(); + + // Call + CalculationGroupEntity entity = group.Create(registry, 0); + + // Assert + CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity1.ToArray(); + PipingCalculationEntity[] childCalculationEntities = entity.PipingCalculationEntities.ToArray(); + Assert.AreEqual(2, childGroupEntities.Length); + Assert.AreEqual(2, childCalculationEntities.Length); + + CalculationGroupEntity childEntity1 = childGroupEntities[0]; + Assert.AreEqual("A", childEntity1.Name); + Assert.AreEqual(0, childEntity1.Order); + CollectionAssert.IsEmpty(childEntity1.CalculationGroupEntity1); + + PipingCalculationEntity childEntity2 = childCalculationEntities[0]; + Assert.AreEqual("B", childEntity2.Name); + Assert.AreEqual(1, childEntity2.Order); + + CalculationGroupEntity childEntity3 = childGroupEntities[1]; + Assert.AreEqual("C", childEntity3.Name); + Assert.AreEqual(2, childEntity3.Order); + CollectionAssert.IsEmpty(childEntity3.CalculationGroupEntity1); + + PipingCalculationEntity childEntity4 = childCalculationEntities[1]; + Assert.AreEqual("D", childEntity4.Name); + Assert.AreEqual(3, childEntity4.Order); + } + + [Test] + public void Create_GroupWithMacroStabilityInwardsCalculations_CreatesEntities() + { + // Setup + var group = new CalculationGroup + { + Children = + { + new MacroStabilityInwardsCalculationScenario + { + Name = "A" + }, + new MacroStabilityInwardsCalculationScenario + { + Name = "B" + } + } + }; + + var registry = new PersistenceRegistry(); + + // Call + CalculationGroupEntity entity = group.Create(registry, 0); + + // Assert + MacroStabilityInwardsCalculationEntity[] childCalculationEntities = entity.MacroStabilityInwardsCalculationEntities.ToArray(); + Assert.AreEqual(2, childCalculationEntities.Length); + + MacroStabilityInwardsCalculationEntity childEntity1 = childCalculationEntities[0]; + Assert.AreEqual("A", childEntity1.Name); + Assert.AreEqual(0, childEntity1.Order); + + MacroStabilityInwardsCalculationEntity childEntity2 = childCalculationEntities[1]; + Assert.AreEqual("B", childEntity2.Name); + Assert.AreEqual(1, childEntity2.Order); + } + + [Test] + public void Create_GroupWithChildMacroStabilityInwardsCalculationsAndChildCalculationGroups_CreateEntities() + { + // Setup + var group = new CalculationGroup + { + Children = + { + new CalculationGroup + { + Name = "A" + }, + new MacroStabilityInwardsCalculationScenario + { + Name = "B" + }, + new CalculationGroup + { + Name = "C" + }, + new MacroStabilityInwardsCalculationScenario + { + Name = "D" + } + } + }; + + var registry = new PersistenceRegistry(); + + // Call + CalculationGroupEntity entity = group.Create(registry, 0); + + // Assert + CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity1.ToArray(); + MacroStabilityInwardsCalculationEntity[] childCalculationEntities = entity.MacroStabilityInwardsCalculationEntities.ToArray(); + Assert.AreEqual(2, childGroupEntities.Length); + Assert.AreEqual(2, childCalculationEntities.Length); + + CalculationGroupEntity childEntity1 = childGroupEntities[0]; + Assert.AreEqual("A", childEntity1.Name); + Assert.AreEqual(0, childEntity1.Order); + CollectionAssert.IsEmpty(childEntity1.CalculationGroupEntity1); + + MacroStabilityInwardsCalculationEntity childEntity2 = childCalculationEntities[0]; + Assert.AreEqual("B", childEntity2.Name); + Assert.AreEqual(1, childEntity2.Order); + + CalculationGroupEntity childEntity3 = childGroupEntities[1]; + Assert.AreEqual("C", childEntity3.Name); + Assert.AreEqual(2, childEntity3.Order); + CollectionAssert.IsEmpty(childEntity3.CalculationGroupEntity1); + + MacroStabilityInwardsCalculationEntity childEntity4 = childCalculationEntities[1]; + Assert.AreEqual("D", childEntity4.Name); + Assert.AreEqual(3, childEntity4.Order); + } + + [Test] + public void Create_GroupWithChildGrassCoverErosionInwardsCalculations_CreateEntities() + { + // Setup + var group = new CalculationGroup + { + Children = + { + new GrassCoverErosionInwardsCalculation + { + Name = "A" + }, + new GrassCoverErosionInwardsCalculation + { + Name = "B" + } + } + }; + + var registry = new PersistenceRegistry(); + + // Call + CalculationGroupEntity entity = group.Create(registry, 0); + + // Assert + GrassCoverErosionInwardsCalculationEntity[] childCalculationEntities = entity.GrassCoverErosionInwardsCalculationEntities.ToArray(); + Assert.AreEqual(2, childCalculationEntities.Length); + + GrassCoverErosionInwardsCalculationEntity childEntity1 = childCalculationEntities[0]; + Assert.AreEqual("A", childEntity1.Name); + Assert.AreEqual(0, childEntity1.Order); + GrassCoverErosionInwardsCalculationEntity childEntity2 = childCalculationEntities[1]; + Assert.AreEqual("B", childEntity2.Name); + Assert.AreEqual(1, childEntity2.Order); + } + + [Test] + public void Create_GroupWithChildGrassCoverErosionInwardCalculationsAndChildCalculationGroups_CreateEntities() + { + // Setup + var group = new CalculationGroup + { + Children = + { + new CalculationGroup + { + Name = "A" + }, + new GrassCoverErosionInwardsCalculation + { + Name = "B" + }, + new CalculationGroup + { + Name = "C" + }, + new GrassCoverErosionInwardsCalculation + { + Name = "D" + } + } + }; + + var registry = new PersistenceRegistry(); + + // Call + CalculationGroupEntity entity = group.Create(registry, 0); + + // Assert + CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity1.ToArray(); + GrassCoverErosionInwardsCalculationEntity[] childCalculationEntities = entity.GrassCoverErosionInwardsCalculationEntities.ToArray(); + Assert.AreEqual(2, childGroupEntities.Length); + Assert.AreEqual(2, childCalculationEntities.Length); + + CalculationGroupEntity childEntity1 = childGroupEntities[0]; + Assert.AreEqual("A", childEntity1.Name); + Assert.AreEqual(0, childEntity1.Order); + CollectionAssert.IsEmpty(childEntity1.CalculationGroupEntity1); + + GrassCoverErosionInwardsCalculationEntity childEntity2 = childCalculationEntities[0]; + Assert.AreEqual("B", childEntity2.Name); + Assert.AreEqual(1, childEntity2.Order); + + CalculationGroupEntity childEntity3 = childGroupEntities[1]; + Assert.AreEqual("C", childEntity3.Name); + Assert.AreEqual(2, childEntity3.Order); + CollectionAssert.IsEmpty(childEntity3.CalculationGroupEntity1); + + GrassCoverErosionInwardsCalculationEntity childEntity4 = childCalculationEntities[1]; + Assert.AreEqual("D", childEntity4.Name); + Assert.AreEqual(3, childEntity4.Order); + } + + [Test] + public void Create_GroupWithChildGrassCoverErosionOutwardsWaveConditionsCalculations_CreateEntities() + { + // Setup + var group = new CalculationGroup + { + Children = + { + new GrassCoverErosionOutwardsWaveConditionsCalculation + { + Name = "A" + }, + new GrassCoverErosionOutwardsWaveConditionsCalculation + { + Name = "B" + } + } + }; + + var registry = new PersistenceRegistry(); + + // Call + CalculationGroupEntity entity = group.Create(registry, 0); + + // Assert + GrassCoverErosionOutwardsWaveConditionsCalculationEntity[] childCalculationEntities = entity.GrassCoverErosionOutwardsWaveConditionsCalculationEntities.ToArray(); + Assert.AreEqual(2, childCalculationEntities.Length); + + GrassCoverErosionOutwardsWaveConditionsCalculationEntity childEntity1 = childCalculationEntities[0]; + Assert.AreEqual("A", childEntity1.Name); + Assert.AreEqual(0, childEntity1.Order); + GrassCoverErosionOutwardsWaveConditionsCalculationEntity childEntity2 = childCalculationEntities[1]; + Assert.AreEqual("B", childEntity2.Name); + Assert.AreEqual(1, childEntity2.Order); + } + + [Test] + public void Create_GroupWithChildGrassCoverErosionOutwardsWaveConditionsCalculationsAndChildCalculationGroups_CreateEntities() + { + // Setup + var group = new CalculationGroup + { + Children = + { + new CalculationGroup + { + Name = "A" + }, + new GrassCoverErosionOutwardsWaveConditionsCalculation + { + Name = "B" + }, + new CalculationGroup + { + Name = "C" + }, + new GrassCoverErosionOutwardsWaveConditionsCalculation + { + Name = "D" + } + } + }; + + var registry = new PersistenceRegistry(); + + // Call + CalculationGroupEntity entity = group.Create(registry, 0); + + // Assert + CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity1.ToArray(); + GrassCoverErosionOutwardsWaveConditionsCalculationEntity[] childCalculationEntities = entity.GrassCoverErosionOutwardsWaveConditionsCalculationEntities.ToArray(); + Assert.AreEqual(2, childGroupEntities.Length); + Assert.AreEqual(2, childCalculationEntities.Length); + + CalculationGroupEntity childEntity1 = childGroupEntities[0]; + Assert.AreEqual("A", childEntity1.Name); + Assert.AreEqual(0, childEntity1.Order); + CollectionAssert.IsEmpty(childEntity1.CalculationGroupEntity1); + + GrassCoverErosionOutwardsWaveConditionsCalculationEntity childEntity2 = childCalculationEntities[0]; + Assert.AreEqual("B", childEntity2.Name); + Assert.AreEqual(1, childEntity2.Order); + + CalculationGroupEntity childEntity3 = childGroupEntities[1]; + Assert.AreEqual("C", childEntity3.Name); + Assert.AreEqual(2, childEntity3.Order); + CollectionAssert.IsEmpty(childEntity3.CalculationGroupEntity1); + + GrassCoverErosionOutwardsWaveConditionsCalculationEntity childEntity4 = childCalculationEntities[1]; + Assert.AreEqual("D", childEntity4.Name); + Assert.AreEqual(3, childEntity4.Order); + } + + [Test] + public void Create_GroupWithChildHeightStructuresCalculations_CreateEntities() + { + // Setup + var group = new CalculationGroup + { + Children = + { + new StructuresCalculation + { + Name = "A" + }, + new StructuresCalculation + { + Name = "B" + } + } + }; + + var registry = new PersistenceRegistry(); + + // Call + CalculationGroupEntity entity = group.Create(registry, 0); + + // Assert + HeightStructuresCalculationEntity[] childCalculationEntities = entity.HeightStructuresCalculationEntities.ToArray(); + Assert.AreEqual(2, childCalculationEntities.Length); + + HeightStructuresCalculationEntity childEntity1 = childCalculationEntities[0]; + Assert.AreEqual("A", childEntity1.Name); + Assert.AreEqual(0, childEntity1.Order); + HeightStructuresCalculationEntity childEntity2 = childCalculationEntities[1]; + Assert.AreEqual("B", childEntity2.Name); + Assert.AreEqual(1, childEntity2.Order); + } + + [Test] + public void Create_GroupWithChildHeightStructuresCalculationsAndChildCalculationGroups_CreateEntities() + { + // Setup + var group = new CalculationGroup + { + Children = + { + new CalculationGroup + { + Name = "A" + }, + new StructuresCalculation + { + Name = "B" + }, + new CalculationGroup + { + Name = "C" + }, + new StructuresCalculation + { + Name = "D" + } + } + }; + + var registry = new PersistenceRegistry(); + + // Call + CalculationGroupEntity entity = group.Create(registry, 0); + + // Assert + CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity1.ToArray(); + HeightStructuresCalculationEntity[] childCalculationEntities = entity.HeightStructuresCalculationEntities.ToArray(); + Assert.AreEqual(2, childGroupEntities.Length); + Assert.AreEqual(2, childCalculationEntities.Length); + + CalculationGroupEntity childEntity1 = childGroupEntities[0]; + Assert.AreEqual("A", childEntity1.Name); + Assert.AreEqual(0, childEntity1.Order); + CollectionAssert.IsEmpty(childEntity1.CalculationGroupEntity1); + + HeightStructuresCalculationEntity childEntity2 = childCalculationEntities[0]; + Assert.AreEqual("B", childEntity2.Name); + Assert.AreEqual(1, childEntity2.Order); + + CalculationGroupEntity childEntity3 = childGroupEntities[1]; + Assert.AreEqual("C", childEntity3.Name); + Assert.AreEqual(2, childEntity3.Order); + CollectionAssert.IsEmpty(childEntity3.CalculationGroupEntity1); + + HeightStructuresCalculationEntity childEntity4 = childCalculationEntities[1]; + Assert.AreEqual("D", childEntity4.Name); + Assert.AreEqual(3, childEntity4.Order); + } + + [Test] + public void Create_GroupWithChildStabilityStoneCoverWaveConditionsCalculations_CreateEntities() + { + // Setup + var group = new CalculationGroup + { + Children = + { + new StabilityStoneCoverWaveConditionsCalculation + { + Name = "A" + }, + new StabilityStoneCoverWaveConditionsCalculation + { + Name = "B" + } + } + }; + + var registry = new PersistenceRegistry(); + + // Call + CalculationGroupEntity entity = group.Create(registry, 0); + + // Assert + StabilityStoneCoverWaveConditionsCalculationEntity[] childCalculationEntities = entity.StabilityStoneCoverWaveConditionsCalculationEntities.ToArray(); + Assert.AreEqual(2, childCalculationEntities.Length); + + StabilityStoneCoverWaveConditionsCalculationEntity childEntity1 = childCalculationEntities[0]; + Assert.AreEqual("A", childEntity1.Name); + Assert.AreEqual(0, childEntity1.Order); + StabilityStoneCoverWaveConditionsCalculationEntity childEntity2 = childCalculationEntities[1]; + Assert.AreEqual("B", childEntity2.Name); + Assert.AreEqual(1, childEntity2.Order); + } + + [Test] + public void Create_GroupWithChildStabilityStoneCoverWaveConditionsCalculationsAndChildCalculationGroups_CreateEntities() + { + // Setup + var group = new CalculationGroup + { + Children = + { + new CalculationGroup + { + Name = "A" + }, + new StabilityStoneCoverWaveConditionsCalculation + { + Name = "B" + }, + new CalculationGroup + { + Name = "C" + }, + new StabilityStoneCoverWaveConditionsCalculation + { + Name = "D" + } + } + }; + + var registry = new PersistenceRegistry(); + + // Call + CalculationGroupEntity entity = group.Create(registry, 0); + + // Assert + CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity1.ToArray(); + StabilityStoneCoverWaveConditionsCalculationEntity[] childCalculationEntities = entity.StabilityStoneCoverWaveConditionsCalculationEntities.ToArray(); + Assert.AreEqual(2, childGroupEntities.Length); + Assert.AreEqual(2, childCalculationEntities.Length); + + CalculationGroupEntity childEntity1 = childGroupEntities[0]; + Assert.AreEqual("A", childEntity1.Name); + Assert.AreEqual(0, childEntity1.Order); + CollectionAssert.IsEmpty(childEntity1.CalculationGroupEntity1); + + StabilityStoneCoverWaveConditionsCalculationEntity childEntity2 = childCalculationEntities[0]; + Assert.AreEqual("B", childEntity2.Name); + Assert.AreEqual(1, childEntity2.Order); + + CalculationGroupEntity childEntity3 = childGroupEntities[1]; + Assert.AreEqual("C", childEntity3.Name); + Assert.AreEqual(2, childEntity3.Order); + CollectionAssert.IsEmpty(childEntity3.CalculationGroupEntity1); + + StabilityStoneCoverWaveConditionsCalculationEntity childEntity4 = childCalculationEntities[1]; + Assert.AreEqual("D", childEntity4.Name); + Assert.AreEqual(3, childEntity4.Order); + } + + [Test] + public void Create_GroupWithChildWaveImpactAsphaltCoverWaveConditionsCalculations_CreateEntities() + { + // Setup + var group = new CalculationGroup + { + Children = + { + new WaveImpactAsphaltCoverWaveConditionsCalculation + { + Name = "A" + }, + new WaveImpactAsphaltCoverWaveConditionsCalculation + { + Name = "B" + } + } + }; + + var registry = new PersistenceRegistry(); + + // Call + CalculationGroupEntity entity = group.Create(registry, 0); + + // Assert + WaveImpactAsphaltCoverWaveConditionsCalculationEntity[] childCalculationEntities = entity.WaveImpactAsphaltCoverWaveConditionsCalculationEntities.ToArray(); + Assert.AreEqual(2, childCalculationEntities.Length); + + WaveImpactAsphaltCoverWaveConditionsCalculationEntity childEntity1 = childCalculationEntities[0]; + Assert.AreEqual("A", childEntity1.Name); + Assert.AreEqual(0, childEntity1.Order); + WaveImpactAsphaltCoverWaveConditionsCalculationEntity childEntity2 = childCalculationEntities[1]; + Assert.AreEqual("B", childEntity2.Name); + Assert.AreEqual(1, childEntity2.Order); + } + + [Test] + public void Create_GroupWithChildWaveImpactAsphaltCoverWaveConditionsCalculationsAndChildCalculationGroups_CreateEntities() + { + // Setup + var group = new CalculationGroup + { + Children = + { + new CalculationGroup + { + Name = "A" + }, + new WaveImpactAsphaltCoverWaveConditionsCalculation + { + Name = "B" + }, + new CalculationGroup + { + Name = "C" + }, + new WaveImpactAsphaltCoverWaveConditionsCalculation + { + Name = "D" + } + } + }; + + var registry = new PersistenceRegistry(); + + // Call + CalculationGroupEntity entity = group.Create(registry, 0); + + // Assert + CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity1.ToArray(); + WaveImpactAsphaltCoverWaveConditionsCalculationEntity[] childCalculationEntities = entity.WaveImpactAsphaltCoverWaveConditionsCalculationEntities.ToArray(); + Assert.AreEqual(2, childGroupEntities.Length); + Assert.AreEqual(2, childCalculationEntities.Length); + + CalculationGroupEntity childEntity1 = childGroupEntities[0]; + Assert.AreEqual("A", childEntity1.Name); + Assert.AreEqual(0, childEntity1.Order); + CollectionAssert.IsEmpty(childEntity1.CalculationGroupEntity1); + + WaveImpactAsphaltCoverWaveConditionsCalculationEntity childEntity2 = childCalculationEntities[0]; + Assert.AreEqual("B", childEntity2.Name); + Assert.AreEqual(1, childEntity2.Order); + + CalculationGroupEntity childEntity3 = childGroupEntities[1]; + Assert.AreEqual("C", childEntity3.Name); + Assert.AreEqual(2, childEntity3.Order); + CollectionAssert.IsEmpty(childEntity3.CalculationGroupEntity1); + + WaveImpactAsphaltCoverWaveConditionsCalculationEntity childEntity4 = childCalculationEntities[1]; + Assert.AreEqual("D", childEntity4.Name); + Assert.AreEqual(3, childEntity4.Order); + } + + [Test] + public void Create_GroupWithChildClosingStructuresCalculations_CreateEntities() + { + // Setup + var group = new CalculationGroup + { + Children = + { + new StructuresCalculation + { + Name = "A" + }, + new StructuresCalculation + { + Name = "B" + } + } + }; + + var registry = new PersistenceRegistry(); + + // Call + CalculationGroupEntity entity = group.Create(registry, 0); + + // Assert + ClosingStructuresCalculationEntity[] childCalculationEntities = entity.ClosingStructuresCalculationEntities.ToArray(); + Assert.AreEqual(2, childCalculationEntities.Length); + + ClosingStructuresCalculationEntity childEntity1 = childCalculationEntities[0]; + Assert.AreEqual("A", childEntity1.Name); + Assert.AreEqual(0, childEntity1.Order); + ClosingStructuresCalculationEntity childEntity2 = childCalculationEntities[1]; + Assert.AreEqual("B", childEntity2.Name); + Assert.AreEqual(1, childEntity2.Order); + } + + [Test] + public void Create_GroupWithChildClosingStructuresCalculationsAndChildCalculationGroups_CreateEntities() + { + // Setup + var group = new CalculationGroup + { + Children = + { + new CalculationGroup + { + Name = "A" + }, + new StructuresCalculation + { + Name = "B" + }, + new CalculationGroup + { + Name = "C" + }, + new StructuresCalculation + { + Name = "D" + } + } + }; + + var registry = new PersistenceRegistry(); + + // Call + CalculationGroupEntity entity = group.Create(registry, 0); + + // Assert + CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity1.ToArray(); + ClosingStructuresCalculationEntity[] childCalculationEntities = entity.ClosingStructuresCalculationEntities.ToArray(); + Assert.AreEqual(2, childGroupEntities.Length); + Assert.AreEqual(2, childCalculationEntities.Length); + + CalculationGroupEntity childEntity1 = childGroupEntities[0]; + Assert.AreEqual("A", childEntity1.Name); + Assert.AreEqual(0, childEntity1.Order); + CollectionAssert.IsEmpty(childEntity1.CalculationGroupEntity1); + + ClosingStructuresCalculationEntity childEntity2 = childCalculationEntities[0]; + Assert.AreEqual("B", childEntity2.Name); + Assert.AreEqual(1, childEntity2.Order); + + CalculationGroupEntity childEntity3 = childGroupEntities[1]; + Assert.AreEqual("C", childEntity3.Name); + Assert.AreEqual(2, childEntity3.Order); + CollectionAssert.IsEmpty(childEntity3.CalculationGroupEntity1); + + ClosingStructuresCalculationEntity childEntity4 = childCalculationEntities[1]; + Assert.AreEqual("D", childEntity4.Name); + Assert.AreEqual(3, childEntity4.Order); + } + + [Test] + public void Create_GroupWithChildStabilityPointStructuresCalculations_CreateEntities() + { + // Setup + var group = new CalculationGroup + { + Children = + { + new StructuresCalculation + { + Name = "A" + }, + new StructuresCalculation + { + Name = "B" + } + } + }; + + var registry = new PersistenceRegistry(); + + // Call + CalculationGroupEntity entity = group.Create(registry, 0); + + // Assert + StabilityPointStructuresCalculationEntity[] childCalculationEntities = entity.StabilityPointStructuresCalculationEntities.ToArray(); + Assert.AreEqual(2, childCalculationEntities.Length); + + StabilityPointStructuresCalculationEntity childEntity1 = childCalculationEntities[0]; + Assert.AreEqual("A", childEntity1.Name); + Assert.AreEqual(0, childEntity1.Order); + StabilityPointStructuresCalculationEntity childEntity2 = childCalculationEntities[1]; + Assert.AreEqual("B", childEntity2.Name); + Assert.AreEqual(1, childEntity2.Order); + } + + [Test] + public void Create_GroupWithChildStabilityPointStructuresCalculationsAndChildCalculationGroups_CreateEntities() + { + // Setup + var group = new CalculationGroup + { + Children = + { + new CalculationGroup + { + Name = "A" + }, + new StructuresCalculation + { + Name = "B" + }, + new CalculationGroup + { + Name = "C" + }, + new StructuresCalculation + { + Name = "D" + } + } + }; + + var registry = new PersistenceRegistry(); + + // Call + CalculationGroupEntity entity = group.Create(registry, 0); + + // Assert + CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity1.ToArray(); + StabilityPointStructuresCalculationEntity[] childCalculationEntities = entity.StabilityPointStructuresCalculationEntities.ToArray(); + Assert.AreEqual(2, childGroupEntities.Length); + Assert.AreEqual(2, childCalculationEntities.Length); + + CalculationGroupEntity childEntity1 = childGroupEntities[0]; + Assert.AreEqual("A", childEntity1.Name); + Assert.AreEqual(0, childEntity1.Order); + CollectionAssert.IsEmpty(childEntity1.CalculationGroupEntity1); + + StabilityPointStructuresCalculationEntity childEntity2 = childCalculationEntities[0]; + Assert.AreEqual("B", childEntity2.Name); + Assert.AreEqual(1, childEntity2.Order); + + CalculationGroupEntity childEntity3 = childGroupEntities[1]; + Assert.AreEqual("C", childEntity3.Name); + Assert.AreEqual(2, childEntity3.Order); + CollectionAssert.IsEmpty(childEntity3.CalculationGroupEntity1); + + StabilityPointStructuresCalculationEntity childEntity4 = childCalculationEntities[1]; + Assert.AreEqual("D", childEntity4.Name); + Assert.AreEqual(3, childEntity4.Order); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/ClosingStructures/ClosingStructureCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/ClosingStructures/ClosingStructureCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/ClosingStructures/ClosingStructureCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,208 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.ClosingStructures.Data; +using Ringtoets.ClosingStructures.Data.TestUtil; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.ClosingStructures; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.ClosingStructures +{ + [TestFixture] + public class ClosingStructureCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowArgumentNullException() + { + // Setup + ClosingStructure structure = new TestClosingStructure(); + + // Call + TestDelegate call = () => structure.Create(null, 0); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + public void Create_ValidStructure_ReturnEntity() + { + // Setup + ClosingStructure structure = new TestClosingStructure(); + var registry = new PersistenceRegistry(); + + const int order = 4; + + // Call + ClosingStructureEntity entity = structure.Create(registry, order); + + // Assert + Assert.AreEqual(structure.Name, entity.Name); + Assert.AreNotSame(structure.Name, entity.Name); + Assert.AreEqual(structure.Id, entity.Id); + Assert.AreNotSame(structure.Id, entity.Id); + Assert.AreEqual(structure.Location.X, entity.X); + Assert.AreEqual(structure.Location.Y, entity.Y); + Assert.AreEqual(structure.StructureNormalOrientation.Value, entity.StructureNormalOrientation); + + Assert.AreEqual(structure.StorageStructureArea.Mean.Value, entity.StorageStructureAreaMean); + Assert.AreEqual(structure.StorageStructureArea.CoefficientOfVariation.Value, entity.StorageStructureAreaCoefficientOfVariation); + Assert.AreEqual(structure.AllowedLevelIncreaseStorage.Mean.Value, entity.AllowedLevelIncreaseStorageMean); + Assert.AreEqual(structure.AllowedLevelIncreaseStorage.StandardDeviation.Value, entity.AllowedLevelIncreaseStorageStandardDeviation); + Assert.AreEqual(structure.WidthFlowApertures.Mean.Value, entity.WidthFlowAperturesMean); + Assert.AreEqual(structure.WidthFlowApertures.StandardDeviation.Value, entity.WidthFlowAperturesStandardDeviation); + Assert.AreEqual(structure.LevelCrestStructureNotClosing.Mean.Value, entity.LevelCrestStructureNotClosingMean); + Assert.AreEqual(structure.LevelCrestStructureNotClosing.StandardDeviation.Value, entity.LevelCrestStructureNotClosingStandardDeviation); + Assert.AreEqual(structure.InsideWaterLevel.Mean.Value, entity.InsideWaterLevelMean); + Assert.AreEqual(structure.InsideWaterLevel.StandardDeviation.Value, entity.InsideWaterLevelStandardDeviation); + Assert.AreEqual(structure.ThresholdHeightOpenWeir.Mean.Value, entity.ThresholdHeightOpenWeirMean); + Assert.AreEqual(structure.ThresholdHeightOpenWeir.StandardDeviation.Value, entity.ThresholdHeightOpenWeirStandardDeviation); + Assert.AreEqual(structure.AreaFlowApertures.Mean.Value, entity.AreaFlowAperturesMean); + Assert.AreEqual(structure.AreaFlowApertures.StandardDeviation.Value, entity.AreaFlowAperturesStandardDeviation); + Assert.AreEqual(structure.CriticalOvertoppingDischarge.Mean.Value, entity.CriticalOvertoppingDischargeMean); + Assert.AreEqual(structure.CriticalOvertoppingDischarge.CoefficientOfVariation.Value, entity.CriticalOvertoppingDischargeCoefficientOfVariation); + Assert.AreEqual(structure.FlowWidthAtBottomProtection.Mean.Value, entity.FlowWidthAtBottomProtectionMean); + Assert.AreEqual(structure.FlowWidthAtBottomProtection.StandardDeviation.Value, entity.FlowWidthAtBottomProtectionStandardDeviation); + Assert.AreEqual(structure.ProbabilityOpenStructureBeforeFlooding, entity.ProbabilityOpenStructureBeforeFlooding); + Assert.AreEqual(structure.FailureProbabilityOpenStructure, entity.FailureProbabilityOpenStructure); + Assert.AreEqual(structure.IdenticalApertures, entity.IdenticalApertures); + Assert.AreEqual(structure.FailureProbabilityReparation, entity.FailureProbabilityReparation); + Assert.AreEqual(Convert.ToByte(structure.InflowModelType), entity.InflowModelType); + Assert.AreEqual(order, entity.Order); + + Assert.IsTrue(registry.Contains(structure)); + } + + [Test] + public void Create_NaNValue_ReturnEntityWithNullValue() + { + // Setup + var structure = new ClosingStructure(new ClosingStructure.ConstructionProperties + { + Name = "A", + Id = "B", + Location = new Point2D(double.NaN, double.NaN), + StructureNormalOrientation = RoundedDouble.NaN, + StorageStructureArea = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + AllowedLevelIncreaseStorage = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + WidthFlowApertures = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + LevelCrestStructureNotClosing = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + InsideWaterLevel = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + ThresholdHeightOpenWeir = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + AreaFlowApertures = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + CriticalOvertoppingDischarge = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + FlowWidthAtBottomProtection = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + ProbabilityOpenStructureBeforeFlooding = double.NaN, + FailureProbabilityOpenStructure = double.NaN, + FailureProbabilityReparation = double.NaN + }); + var registry = new PersistenceRegistry(); + + // Call + ClosingStructureEntity entity = structure.Create(registry, 0); + + // Assert + Assert.IsNull(entity.X); + Assert.IsNull(entity.Y); + Assert.IsNull(entity.StructureNormalOrientation); + Assert.IsNull(entity.StorageStructureAreaMean); + Assert.IsNull(entity.StorageStructureAreaCoefficientOfVariation); + Assert.IsNull(entity.AllowedLevelIncreaseStorageMean); + Assert.IsNull(entity.AllowedLevelIncreaseStorageStandardDeviation); + Assert.IsNull(entity.WidthFlowAperturesMean); + Assert.IsNull(entity.WidthFlowAperturesStandardDeviation); + Assert.IsNull(entity.LevelCrestStructureNotClosingMean); + Assert.IsNull(entity.LevelCrestStructureNotClosingStandardDeviation); + Assert.IsNull(entity.InsideWaterLevelMean); + Assert.IsNull(entity.InsideWaterLevelStandardDeviation); + Assert.IsNull(entity.ThresholdHeightOpenWeirMean); + Assert.IsNull(entity.ThresholdHeightOpenWeirStandardDeviation); + Assert.IsNull(entity.AreaFlowAperturesMean); + Assert.IsNull(entity.AreaFlowAperturesStandardDeviation); + Assert.IsNull(entity.CriticalOvertoppingDischargeMean); + Assert.IsNull(entity.CriticalOvertoppingDischargeCoefficientOfVariation); + Assert.IsNull(entity.FlowWidthAtBottomProtectionMean); + Assert.IsNull(entity.FlowWidthAtBottomProtectionStandardDeviation); + Assert.IsNull(entity.ProbabilityOpenStructureBeforeFlooding); + Assert.IsNull(entity.FailureProbabilityOpenStructure); + Assert.IsNull(entity.FailureProbabilityReparation); + } + + [Test] + public void Create_StructureAlreadyRegistered_ReturnRegisteredEntity() + { + // Setup + ClosingStructure structure = new TestClosingStructure(); + + var registeredEntity = new ClosingStructureEntity(); + var registry = new PersistenceRegistry(); + registry.Register(registeredEntity, structure); + + // Call + ClosingStructureEntity entity = structure.Create(registry, 0); + + // Assert + Assert.AreSame(registeredEntity, entity); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/ClosingStructures/ClosingStructuresFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/ClosingStructures/ClosingStructuresFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/ClosingStructures/ClosingStructuresFailureMechanismCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,263 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.ClosingStructures.Data; +using Ringtoets.ClosingStructures.Data.TestUtil; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.ClosingStructures; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.ClosingStructures +{ + [TestFixture] + public class ClosingStructuresFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new ClosingStructuresFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet(bool isRelevant) + { + // Setup + var failureMechanism = new ClosingStructuresFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + }, + GeneralInput = + { + N2A = new Random().Next(0, 40) + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.ReliabilityClosingOfStructure, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + + ClosingStructuresFailureMechanismMetaEntity metaEntity = entity.ClosingStructuresFailureMechanismMetaEntities.Single(); + Assert.AreEqual(failureMechanism.GeneralInput.N2A, metaEntity.N2A); + Assert.IsNull(metaEntity.ForeshoreProfileCollectionSourcePath); + Assert.IsNull(metaEntity.ClosingStructureCollectionSourcePath); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + var failureMechanism = new ClosingStructuresFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + TestHelper.AssertAreEqualButNotSame(failureMechanism.InputComments.Body, entity.InputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.OutputComments.Body, entity.OutputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new ClosingStructuresFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + Assert.IsNull(entity.FailureMechanismSectionCollectionSourcePath); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + const string filePath = "failureMechanismSections/file/path"; + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.SetSections(new[] + { + FailureMechanismSectionTestFactory.CreateFailureMechanismSection() + }, filePath); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.ClosingStructuresSectionResultEntities).Count()); + TestHelper.AssertAreEqualButNotSame(filePath, entity.FailureMechanismSectionCollectionSourcePath); + } + + [Test] + public void Create_WithForeshoreProfiles_ForeshoreProfileEntitiesCreated() + { + // Setup + var profile = new TestForeshoreProfile(); + + var failureMechanism = new ClosingStructuresFailureMechanism(); + const string filePath = "some/file/path/foreshoreProfiles"; + failureMechanism.ForeshoreProfiles.AddRange(new[] + { + profile + }, filePath); + + var persistenceRegistry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(persistenceRegistry); + + // Assert + Assert.AreEqual(1, entity.ForeshoreProfileEntities.Count); + Assert.IsTrue(persistenceRegistry.Contains(profile)); + + ClosingStructuresFailureMechanismMetaEntity metaEntity = + entity.ClosingStructuresFailureMechanismMetaEntities.Single(); + string metaEntityForeshoreProfileCollectionSourcePath = metaEntity.ForeshoreProfileCollectionSourcePath; + TestHelper.AssertAreEqualButNotSame(filePath, metaEntityForeshoreProfileCollectionSourcePath); + } + + [Test] + public void Create_WithClosingStructures_ClosingStructureEntitiesCreated() + { + // Setup + ClosingStructure structure = new TestClosingStructure(); + + var failureMechanism = new ClosingStructuresFailureMechanism(); + const string filePath = "some path"; + failureMechanism.ClosingStructures.AddRange(new[] + { + structure + }, filePath); + + var persistenceRegistry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(persistenceRegistry); + + // Assert + Assert.AreEqual(1, entity.ClosingStructureEntities.Count); + Assert.IsTrue(persistenceRegistry.Contains(structure)); + + ClosingStructuresFailureMechanismMetaEntity metaEntity = + entity.ClosingStructuresFailureMechanismMetaEntities.Single(); + string entitySourcePath = metaEntity.ClosingStructureCollectionSourcePath; + TestHelper.AssertAreEqualButNotSame(filePath, entitySourcePath); + } + + [Test] + public void Create_WithCalculationGroup_ReturnFailureMechanismEntityWithCalculationGroupEntities() + { + // Setup + StructuresCalculation calculation = new TestClosingStructuresCalculation(); + calculation.InputParameters.Structure = null; + calculation.InputParameters.HydraulicBoundaryLocation = null; + + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(new CalculationGroup + { + Name = "A" + }); + failureMechanism.CalculationsGroup.Children.Add(calculation); + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(failureMechanism.CalculationsGroup.Name, entity.CalculationGroupEntity.Name); + Assert.AreEqual(0, entity.CalculationGroupEntity.Order); + + CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity.CalculationGroupEntity1 + .OrderBy(cge => cge.Order) + .ToArray(); + Assert.AreEqual(1, childGroupEntities.Length); + CalculationGroupEntity childGroupEntity = childGroupEntities[0]; + Assert.AreEqual("A", childGroupEntity.Name); + Assert.AreEqual(0, childGroupEntity.Order); + + ClosingStructuresCalculationEntity[] calculationEntities = entity.CalculationGroupEntity.ClosingStructuresCalculationEntities + .OrderBy(ce => ce.Order) + .ToArray(); + ClosingStructuresCalculationEntity calculationEntity = calculationEntities[0]; + Assert.AreEqual("Nieuwe berekening", calculationEntity.Name); + Assert.AreEqual(1, calculationEntity.Order); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/ClosingStructures/ClosingStructuresFailureMechanismSectionResultCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/ClosingStructures/ClosingStructuresFailureMechanismSectionResultCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/ClosingStructures/ClosingStructuresFailureMechanismSectionResultCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,137 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.ClosingStructures.Data; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.ClosingStructures; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.ClosingStructures +{ + [TestFixture] + public class ClosingStructuresFailureMechanismSectionResultCreateExtensionsTest + { + [Test] + public void Create_FailureMechanismSectionResultNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((ClosingStructuresFailureMechanismSectionResult) null).Create(new PersistenceRegistry()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("result", exception.ParamName); + } + + [Test] + public void Create_PersistencyRegistryNull_ThrowsArgumentNullException() + { + // Setup + var sectionResult = new ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + TestDelegate test = () => sectionResult.Create(null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("registry", exception.ParamName); + } + + [Test] + public void Create_WithDifferentResults_ReturnsEntityWithExpectedResults() + { + // Setup + var random = new Random(21); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResult = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + double tailorMadeAssessmentProbability = random.NextDouble(); + bool useManualAssembly = random.NextBoolean(); + double manualAssemblyProbability = random.NextDouble(); + + var sectionResult = new ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + SimpleAssessmentResult = simpleAssessmentResult, + DetailedAssessmentResult = detailedAssessmentResult, + TailorMadeAssessmentResult = tailorMadeAssessmentResult, + TailorMadeAssessmentProbability = tailorMadeAssessmentProbability, + UseManualAssembly = useManualAssembly, + ManualAssemblyProbability = manualAssemblyProbability + }; + + // Call + ClosingStructuresSectionResultEntity entity = sectionResult.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(Convert.ToByte(simpleAssessmentResult), entity.SimpleAssessmentResult); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResult), entity.DetailedAssessmentResult); + Assert.AreEqual(Convert.ToByte(tailorMadeAssessmentResult), entity.TailorMadeAssessmentResult); + Assert.AreEqual(tailorMadeAssessmentProbability, entity.TailorMadeAssessmentProbability); + Assert.AreEqual(Convert.ToByte(useManualAssembly), entity.UseManualAssembly); + Assert.AreEqual(manualAssemblyProbability, entity.ManualAssemblyProbability); + Assert.IsNull(entity.ClosingStructuresCalculationEntityId); + } + + [Test] + public void Create_SectionResultWithNaNValues_ReturnsEntityWithExpectedResults() + { + // Setup + var sectionResult = new ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + TailorMadeAssessmentProbability = double.NaN, + ManualAssemblyProbability = double.NaN + }; + + // Call + ClosingStructuresSectionResultEntity entity = sectionResult.Create(new PersistenceRegistry()); + + // Assert + Assert.IsNull(entity.TailorMadeAssessmentProbability); + Assert.IsNull(entity.ManualAssemblyProbability); + } + + [Test] + public void Create_CalculationSet_ReturnEntityWithCalculationEntity() + { + // Setup + var calculation = new StructuresCalculation(); + var sectionResult = new ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + Calculation = calculation + }; + + var registry = new PersistenceRegistry(); + var calculationEntity = new ClosingStructuresCalculationEntity(); + registry.Register(calculationEntity, calculation); + + // Call + ClosingStructuresSectionResultEntity entity = sectionResult.Create(registry); + + // Assert + Assert.AreSame(calculationEntity, entity.ClosingStructuresCalculationEntity); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/DuneErosion/DuneErosionFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/DuneErosion/DuneErosionFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/DuneErosion/DuneErosionFailureMechanismCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,278 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.DuneErosion.Data; +using Ringtoets.DuneErosion.Data.TestUtil; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.DuneErosion; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.DuneErosion +{ + [TestFixture] + public class DuneErosionFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new DuneErosionFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet() + { + // Setup + var random = new Random(21); + var failureMechanism = new DuneErosionFailureMechanism + { + IsRelevant = random.NextBoolean(), + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + }, + GeneralInput = + { + N = random.NextRoundedDouble(1, 20) + } + }; + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.DuneErosion, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(failureMechanism.IsRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + + DuneErosionFailureMechanismMetaEntity metaEntity = entity.DuneErosionFailureMechanismMetaEntities.First(); + Assert.AreEqual(failureMechanism.GeneralInput.N, metaEntity.N, failureMechanism.GeneralInput.N.GetAccuracy()); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + var failureMechanism = new DuneErosionFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + TestHelper.AssertAreEqualButNotSame(failureMechanism.InputComments.Body, entity.InputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.OutputComments.Body, entity.OutputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new DuneErosionFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + Assert.IsNull(entity.FailureMechanismSectionCollectionSourcePath); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + const string filePath = "failureMechanismSections/file/path"; + var failureMechanism = new DuneErosionFailureMechanism(); + failureMechanism.SetSections(new[] + { + FailureMechanismSectionTestFactory.CreateFailureMechanismSection() + }, filePath); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.DuneErosionSectionResultEntities).Count()); + TestHelper.AssertAreEqualButNotSame(filePath, entity.FailureMechanismSectionCollectionSourcePath); + } + + [Test] + public void Create_WithoutDuneLocations_ReturnsEntityWithoutDuneLocations() + { + // Setup + var failureMechanism = new DuneErosionFailureMechanism(); + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + CollectionAssert.IsEmpty(entity.DuneLocationEntities); + + DuneErosionFailureMechanismMetaEntity metaEntity = entity.DuneErosionFailureMechanismMetaEntities.Single(); + AssertDuneLocationCalculationCollectionEntities(failureMechanism, registry, metaEntity); + } + + [Test] + public void Create_WithDuneLocations_ReturnsEntityWithDuneLocations() + { + // Setup + var duneLocation = new TestDuneLocation(); + var failureMechanism = new DuneErosionFailureMechanism(); + failureMechanism.SetDuneLocations(new[] + { + duneLocation + }); + SetDuneLocationCalculationOutput(failureMechanism); + + var duneLocationEntity = new DuneLocationEntity(); + var registry = new PersistenceRegistry(); + registry.Register(duneLocationEntity, duneLocation); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + DuneLocationEntity actualDuneLocationEntity = entity.DuneLocationEntities.Single(); + Assert.AreSame(duneLocationEntity, actualDuneLocationEntity); + + DuneErosionFailureMechanismMetaEntity metaEntity = entity.DuneErosionFailureMechanismMetaEntities.Single(); + AssertDuneLocationCalculationCollectionEntities(failureMechanism, registry, metaEntity); + } + + private static void AssertDuneLocationCalculationCollectionEntities(DuneErosionFailureMechanism failureMechanism, + PersistenceRegistry registry, + DuneErosionFailureMechanismMetaEntity metaEntity) + { + AssertDuneLocationCalculationCollectionEntity(failureMechanism.CalculationsForFactorizedLowerLimitNorm, + registry, + metaEntity.DuneLocationCalculationCollectionEntity); + AssertDuneLocationCalculationCollectionEntity(failureMechanism.CalculationsForLowerLimitNorm, + registry, + metaEntity.DuneLocationCalculationCollectionEntity1); + AssertDuneLocationCalculationCollectionEntity(failureMechanism.CalculationsForMechanismSpecificLowerLimitNorm, + registry, + metaEntity.DuneLocationCalculationCollectionEntity2); + AssertDuneLocationCalculationCollectionEntity(failureMechanism.CalculationsForMechanismSpecificSignalingNorm, + registry, + metaEntity.DuneLocationCalculationCollectionEntity3); + AssertDuneLocationCalculationCollectionEntity(failureMechanism.CalculationsForMechanismSpecificFactorizedSignalingNorm, + registry, + metaEntity.DuneLocationCalculationCollectionEntity4); + } + + private static void SetDuneLocationCalculationOutput(DuneErosionFailureMechanism failureMechanism) + { + SetDuneLocationCalculationOutput(failureMechanism.CalculationsForMechanismSpecificFactorizedSignalingNorm, 1); + SetDuneLocationCalculationOutput(failureMechanism.CalculationsForMechanismSpecificSignalingNorm, 2); + SetDuneLocationCalculationOutput(failureMechanism.CalculationsForMechanismSpecificLowerLimitNorm, 3); + SetDuneLocationCalculationOutput(failureMechanism.CalculationsForLowerLimitNorm, 4); + SetDuneLocationCalculationOutput(failureMechanism.CalculationsForFactorizedLowerLimitNorm, 5); + } + + private static void SetDuneLocationCalculationOutput(IEnumerable calculations, + int seed) + { + var random = new Random(seed); + foreach (DuneLocationCalculation calculation in calculations) + { + calculation.Output = random.NextBoolean() + ? new TestDuneLocationCalculationOutput() + : null; + } + } + + private static void AssertDuneLocationCalculationCollectionEntity(IEnumerable expectedCalculations, + PersistenceRegistry registry, + DuneLocationCalculationCollectionEntity actualCollectionEntity) + { + Assert.IsNotNull(actualCollectionEntity); + ICollection duneLocationCalculationEntities = actualCollectionEntity.DuneLocationCalculationEntities; + Assert.AreEqual(expectedCalculations.Count(), duneLocationCalculationEntities.Count); + + var i = 0; + foreach (DuneLocationCalculationEntity duneLocationCalculationEntity in duneLocationCalculationEntities) + { + DuneLocationCalculation expectedDuneLocationCalculation = expectedCalculations.ElementAt(i); + DuneLocation expectedDuneLocation = expectedDuneLocationCalculation.DuneLocation; + Assert.AreSame(registry.Get(expectedDuneLocation), duneLocationCalculationEntity.DuneLocationEntity); + + DuneLocationCalculationOutputEntity actualOutput = duneLocationCalculationEntity.DuneLocationCalculationOutputEntities.SingleOrDefault(); + if (expectedDuneLocationCalculation.Output != null) + { + Assert.IsNotNull(actualOutput); + } + else + { + Assert.IsNull(actualOutput); + } + + i++; + } + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/DuneErosion/DuneErosionFailureMechanismSectionResultCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/DuneErosion/DuneErosionFailureMechanismSectionResultCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/DuneErosion/DuneErosionFailureMechanismSectionResultCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,91 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.AssemblyTool.Data; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.DuneErosion.Data; +using Riskeer.Storage.Core.Create.DuneErosion; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.DuneErosion +{ + [TestFixture] + public class DuneErosionFailureMechanismSectionResultCreateExtensionsTest + { + [Test] + public void Create_SectionResultNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((DuneErosionFailureMechanismSectionResult) null).Create(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("result", exception.ParamName); + } + + [Test] + public void Create_WithDifferentResults_ReturnsEntityWithExpectedResults() + { + // Setup + var random = new Random(21); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResultForFactorizedSignalingNorm = random.NextEnumValue(); + var detailedAssessmentResultForSignalingNorm = random.NextEnumValue(); + var detailedAssessmentResultForMechanismSpecificLowerLimitNorm = random.NextEnumValue(); + var detailedAssessmentResultForLowerLimitNorm = random.NextEnumValue(); + var detailedAssessmentResultForFactorizedLowerLimitNorm = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + bool useManualAssembly = random.NextBoolean(); + var manualAssemblyCategoryGroup = random.NextEnumValue(); + + var sectionResult = new DuneErosionFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + SimpleAssessmentResult = simpleAssessmentResult, + DetailedAssessmentResultForFactorizedSignalingNorm = detailedAssessmentResultForFactorizedSignalingNorm, + DetailedAssessmentResultForSignalingNorm = detailedAssessmentResultForSignalingNorm, + DetailedAssessmentResultForMechanismSpecificLowerLimitNorm = detailedAssessmentResultForMechanismSpecificLowerLimitNorm, + DetailedAssessmentResultForLowerLimitNorm = detailedAssessmentResultForLowerLimitNorm, + DetailedAssessmentResultForFactorizedLowerLimitNorm = detailedAssessmentResultForFactorizedLowerLimitNorm, + TailorMadeAssessmentResult = tailorMadeAssessmentResult, + UseManualAssembly = useManualAssembly, + ManualAssemblyCategoryGroup = manualAssemblyCategoryGroup + }; + + // Call + DuneErosionSectionResultEntity entity = sectionResult.Create(); + + // Assert + Assert.AreEqual(Convert.ToByte(simpleAssessmentResult), entity.SimpleAssessmentResult); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResultForFactorizedSignalingNorm), entity.DetailedAssessmentResultForFactorizedSignalingNorm); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResultForSignalingNorm), entity.DetailedAssessmentResultForSignalingNorm); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResultForMechanismSpecificLowerLimitNorm), entity.DetailedAssessmentResultForMechanismSpecificLowerLimitNorm); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResultForLowerLimitNorm), entity.DetailedAssessmentResultForLowerLimitNorm); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResultForFactorizedLowerLimitNorm), entity.DetailedAssessmentResultForFactorizedLowerLimitNorm); + Assert.AreEqual(Convert.ToByte(tailorMadeAssessmentResult), entity.TailorMadeAssessmentResult); + Assert.AreEqual(Convert.ToByte(useManualAssembly), entity.UseManualAssembly); + Assert.AreEqual(Convert.ToByte(manualAssemblyCategoryGroup), entity.ManualAssemblyCategoryGroup); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/DuneErosion/DuneLocationCalculationCollectionCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/DuneErosion/DuneLocationCalculationCollectionCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/DuneErosion/DuneLocationCalculationCollectionCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,90 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.DuneErosion.Data; +using Ringtoets.DuneErosion.Data.TestUtil; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.DuneErosion; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.DuneErosion +{ + [TestFixture] + public class DuneLocationCalculationCollectionCreateExtensionsTest + { + [Test] + public void Create_CalculationsNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => + ((IEnumerable) null).Create(new PersistenceRegistry()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("calculations", exception.ParamName); + } + + [Test] + public void Create_RegistryNull_ThrowsArgumentNullException() + { + // Setup + IEnumerable calculations = + Enumerable.Empty(); + + // Call + TestDelegate call = () => calculations.Create(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("registry", exception.ParamName); + } + + [Test] + public void Create_WithValidCollectionAndArguments_ReturnsEntity() + { + // Setup + var duneLocation = new TestDuneLocation(); + var calculation = new DuneLocationCalculation(duneLocation); + DuneLocationCalculation[] calculations = + { + calculation + }; + + var duneLocationEntity = new DuneLocationEntity(); + var registry = new PersistenceRegistry(); + registry.Register(duneLocationEntity, duneLocation); + + // Call + DuneLocationCalculationCollectionEntity entity = calculations.Create(registry); + + // Assert + Assert.IsNotNull(entity); + + DuneLocationCalculationEntity calculationEntity = entity.DuneLocationCalculationEntities.Single(); + Assert.AreSame(duneLocationEntity, calculationEntity.DuneLocationEntity); + CollectionAssert.IsEmpty(calculationEntity.DuneLocationCalculationOutputEntities); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/DuneErosion/DuneLocationCalculationCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/DuneErosion/DuneLocationCalculationCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/DuneErosion/DuneLocationCalculationCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,145 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.DuneErosion.Data; +using Ringtoets.DuneErosion.Data.TestUtil; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.DuneErosion; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.DuneErosion +{ + [TestFixture] + public class DuneLocationCalculationCreateExtensionsTest + { + [Test] + public void Create_CalculationNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((DuneLocationCalculation) null).Create(new PersistenceRegistry()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("calculation", exception.ParamName); + } + + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var calculation = new DuneLocationCalculation(new TestDuneLocation()); + + // Call + TestDelegate call = () => calculation.Create(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("registry", exception.ParamName); + } + + [Test] + public void Create_CalculationWithoutOutput_ReturnsDuneLocationCalculationEntity() + { + // Setup + var duneLocation = new TestDuneLocation(); + var calculation = new DuneLocationCalculation(duneLocation); + + var registry = new PersistenceRegistry(); + var duneLocationEntity = new DuneLocationEntity(); + registry.Register(duneLocationEntity, duneLocation); + + // Call + DuneLocationCalculationEntity entity = calculation.Create(registry); + + // Assert + Assert.IsNotNull(entity); + CollectionAssert.IsEmpty(entity.DuneLocationCalculationOutputEntities); + } + + [Test] + public void Create_CalculationWithOutput_ReturnsDuneLocationCalculationEntityWithOutput() + { + // Setup + var random = new Random(21); + var output = new DuneLocationCalculationOutput(random.NextEnumValue(), new DuneLocationCalculationOutput.ConstructionProperties + { + WaterLevel = random.NextDouble(), + WaveHeight = random.NextDouble(), + WavePeriod = random.NextDouble(), + CalculatedProbability = random.NextDouble(), + CalculatedReliability = random.NextDouble(), + TargetProbability = random.NextDouble(), + TargetReliability = random.NextDouble() + }); + + var duneLocation = new TestDuneLocation(); + var calculation = new DuneLocationCalculation(duneLocation) + { + Output = output + }; + + var registry = new PersistenceRegistry(); + var duneLocationEntity = new DuneLocationEntity(); + registry.Register(duneLocationEntity, duneLocation); + + // Call + DuneLocationCalculationEntity entity = calculation.Create(registry); + + // Assert + Assert.IsNotNull(entity); + + DuneLocationCalculationOutputEntity outputEntity = entity.DuneLocationCalculationOutputEntities.Single(); + Assert.AreEqual(output.WaterLevel, outputEntity.WaterLevel, output.WaterLevel.GetAccuracy()); + Assert.AreEqual(output.WaveHeight, outputEntity.WaveHeight, output.WaveHeight.GetAccuracy()); + Assert.AreEqual(output.WavePeriod, outputEntity.WavePeriod, output.WavePeriod.GetAccuracy()); + Assert.AreEqual(output.TargetProbability, outputEntity.TargetProbability); + Assert.AreEqual(output.TargetReliability, outputEntity.TargetReliability, output.TargetReliability.GetAccuracy()); + Assert.AreEqual(output.CalculatedProbability, outputEntity.CalculatedProbability); + Assert.AreEqual(output.CalculatedReliability, outputEntity.CalculatedReliability, output.CalculatedReliability.GetAccuracy()); + Assert.AreEqual(Convert.ToByte(output.CalculationConvergence), outputEntity.CalculationConvergence); + } + + [Test] + public void Create_CalculationWithAlreadyRegisteredDuneLocation_ReturnsEntityWithDuneLocationEntity() + { + // Setup + var duneLocation = new TestDuneLocation(); + var calculation = new DuneLocationCalculation(duneLocation); + + var registry = new PersistenceRegistry(); + var duneLocationEntity = new DuneLocationEntity(); + registry.Register(duneLocationEntity, duneLocation); + + // Call + DuneLocationCalculationEntity entity = calculation.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreSame(duneLocationEntity, entity.DuneLocationEntity); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/DuneErosion/DuneLocationCalculationOutputCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/DuneErosion/DuneLocationCalculationOutputCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/DuneErosion/DuneLocationCalculationOutputCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,109 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.DuneErosion.Data; +using Riskeer.Storage.Core.Create.DuneErosion; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.DuneErosion +{ + [TestFixture] + public class DuneLocationCalculationOutputCreateExtensionsTest + { + [Test] + public void Create_DuneLocationCalculationOutputNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((DuneLocationCalculationOutput) null).Create(); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("output", paramName); + } + + [Test] + public void Create_WithValidParameters_ReturnsDuneLocationCalculationOutputEntity() + { + // Setup + var random = new Random(21); + var output = new DuneLocationCalculationOutput(random.NextEnumValue(), new DuneLocationCalculationOutput.ConstructionProperties + { + WaterLevel = random.NextDouble(), + WaveHeight = random.NextDouble(), + WavePeriod = random.NextDouble(), + TargetProbability = random.NextDouble(), + TargetReliability = random.NextDouble(), + CalculatedProbability = random.NextDouble(), + CalculatedReliability = random.NextDouble() + }); + + // Call + DuneLocationCalculationOutputEntity entity = output.Create(); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(output.WaterLevel, entity.WaterLevel, output.WaterLevel.GetAccuracy()); + Assert.AreEqual(output.WaveHeight, entity.WaveHeight, output.WaveHeight.GetAccuracy()); + Assert.AreEqual(output.WavePeriod, entity.WavePeriod, output.WavePeriod.GetAccuracy()); + Assert.AreEqual(output.TargetProbability, entity.TargetProbability); + Assert.AreEqual(output.TargetReliability, entity.TargetReliability, output.TargetReliability.GetAccuracy()); + Assert.AreEqual(output.CalculatedProbability, entity.CalculatedProbability); + Assert.AreEqual(output.CalculatedReliability, entity.CalculatedReliability, output.CalculatedReliability.GetAccuracy()); + Assert.AreEqual(Convert.ToByte(output.CalculationConvergence), entity.CalculationConvergence); + } + + [Test] + public void Create_WithNaNParameters_ReturnsDuneLocationCalculationOutputEntityWithNullValues() + { + // Setup + var random = new Random(21); + var output = new DuneLocationCalculationOutput(random.NextEnumValue(), new DuneLocationCalculationOutput.ConstructionProperties + { + WaterLevel = double.NaN, + WaveHeight = double.NaN, + WavePeriod = double.NaN, + TargetProbability = double.NaN, + TargetReliability = double.NaN, + CalculatedProbability = double.NaN, + CalculatedReliability = double.NaN + }); + + // Call + DuneLocationCalculationOutputEntity entity = output.Create(); + + // Assert + Assert.IsNotNull(entity); + Assert.IsNull(entity.WaterLevel); + Assert.IsNull(entity.WaveHeight); + Assert.IsNull(entity.WavePeriod); + Assert.IsNull(entity.TargetProbability); + Assert.IsNull(entity.TargetReliability); + Assert.IsNull(entity.CalculatedProbability); + Assert.IsNull(entity.CalculatedReliability); + Assert.AreEqual(Convert.ToByte(output.CalculationConvergence), entity.CalculationConvergence); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/DuneErosion/DuneLocationCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/DuneErosion/DuneLocationCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/DuneErosion/DuneLocationCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,165 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.DuneErosion.Data; +using Ringtoets.DuneErosion.Data.TestUtil; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.DuneErosion; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.DuneErosion +{ + [TestFixture] + public class DuneLocationCreateExtensionsTest + { + [Test] + public void Create_DuneLocationNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((DuneLocation) null).Create(new PersistenceRegistry(), 0); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("location", exception.ParamName); + } + + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var location = new TestDuneLocation(); + + // Call + TestDelegate test = () => location.Create(null, 0); + + // Assert + string parameterName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", parameterName); + } + + [Test] + public void Create_WithPersistenceRegistry_ReturnsDuneLocationEntityWithPropertiesSet() + { + // Setup + const string testName = "testName"; + var random = new Random(21); + double coordinateX = random.NextDouble(); + double coordinateY = random.NextDouble(); + int id = random.Next(0, 150); + int order = random.Next(); + var registry = new PersistenceRegistry(); + + var location = new DuneLocation(id, testName, new Point2D(coordinateX, coordinateY), + new DuneLocation.ConstructionProperties + { + CoastalAreaId = random.Next(), + Offset = random.NextDouble(), + Orientation = random.NextDouble(), + D50 = random.NextDouble() + }); + + // Call + DuneLocationEntity entity = location.Create(registry, order); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(id, entity.LocationId); + Assert.AreEqual(testName, entity.Name); + Assert.AreEqual(coordinateX, entity.LocationX); + Assert.AreEqual(coordinateY, entity.LocationY); + Assert.AreEqual(location.CoastalAreaId, entity.CoastalAreaId); + Assert.AreEqual(location.Offset, entity.Offset, location.Offset.GetAccuracy()); + Assert.AreEqual(location.Orientation, entity.Orientation, location.Orientation.GetAccuracy()); + Assert.AreEqual(location.D50, entity.D50, location.D50.GetAccuracy()); + Assert.AreEqual(order, entity.Order); + } + + [Test] + public void Create_WithNaNValues_ReturnsDuneLocationEntityWithNullPropertiesSet() + { + // Setup + var random = new Random(28); + int id = random.Next(0, 150); + int order = random.Next(); + var registry = new PersistenceRegistry(); + + var location = new DuneLocation(id, string.Empty, new Point2D(double.NaN, double.NaN), + new DuneLocation.ConstructionProperties + { + Offset = double.NaN, + Orientation = double.NaN, + D50 = double.NaN + }); + + // Call + DuneLocationEntity entity = location.Create(registry, order); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(id, entity.LocationId); + Assert.IsEmpty(entity.Name); + Assert.IsNull(entity.LocationX); + Assert.IsNull(entity.LocationY); + Assert.IsNull(entity.Offset); + Assert.IsNull(entity.Orientation); + Assert.IsNull(entity.D50); + Assert.AreEqual(order, entity.Order); + } + + [Test] + public void Create_StringPropertiesDoNotShareReferences() + { + // Setup + const string testName = "original name"; + var location = new DuneLocation(1, testName, new Point2D(0, 0), new DuneLocation.ConstructionProperties()); + var registry = new PersistenceRegistry(); + + // Call + DuneLocationEntity entity = location.Create(registry, 0); + + // Assert + Assert.IsNotNull(entity); + Assert.AreNotSame(testName, entity.Name, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(testName, entity.Name); + } + + [Test] + public void Create_DuneLocationSavedMultipleTimes_ReturnSameEntity() + { + // Setup + var location = new TestDuneLocation(); + + var registry = new PersistenceRegistry(); + + // Call + DuneLocationEntity entity1 = location.Create(registry, 0); + DuneLocationEntity entity2 = location.Create(registry, 1); + + // Assert + Assert.AreSame(entity1, entity2); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/FailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/FailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/FailureMechanismCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,124 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.TestUtil; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.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 + CollectionAssert.IsEmpty(failureMechanismEntity.FailureMechanismSectionEntities); + } + + [Test] + public void AddEntitiesForFailureMechanismSections_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + var failureMechanism = new TestFailureMechanism(); + FailureMechanismTestHelper.SetSections(failureMechanism, new[] + { + FailureMechanismSectionTestFactory.CreateFailureMechanismSection() + }); + 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"; + const string failureMechanismSectionsSourcePath = "File\\Path"; + IFailureMechanism failureMechanism = new TestFailureMechanism("a", "cool"); + failureMechanism.InputComments.Body = originalInput; + failureMechanism.OutputComments.Body = originalOutput; + failureMechanism.NotRelevantComments.Body = originalNotRelevantText; + failureMechanism.SetSections(new[] + { + FailureMechanismSectionTestFactory.CreateFailureMechanismSection() + }, failureMechanismSectionsSourcePath); + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(FailureMechanismType.DuneErosion, registry); + + // Assert + TestHelper.AssertAreEqualButNotSame(failureMechanism.InputComments.Body, entity.InputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.OutputComments.Body, entity.OutputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.FailureMechanismSectionSourcePath, entity.FailureMechanismSectionCollectionSourcePath); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/FailureMechanismSectionCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/FailureMechanismSectionCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/FailureMechanismSectionCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,95 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.TestUtil; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Create +{ + [TestFixture] + public class FailureMechanismSectionCreateExtensionsTest + { + [Test] + public void Create_WithoutCollector_ThrowsArgumentNullException() + { + // Setup + FailureMechanismSection failureMechanismSection = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + + // Call + TestDelegate test = () => failureMechanismSection.Create(null); + + // Assert + string parameterName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", parameterName); + } + + [Test] + public void Create_WithCollectorAndGeometry_ReturnsFailureMechanismSectionWithGeometryStringSet() + { + // Setup + const string testName = "testName"; + var geometryPoints = new[] + { + new Point2D(0, 0), + new Point2D(0, 0) + }; + var failureMechanismSection = new FailureMechanismSection(testName, geometryPoints); + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismSectionEntity entity = failureMechanismSection.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(testName, entity.Name); + string expectedXml = new Point2DCollectionXmlSerializer().ToXml(geometryPoints); + Assert.AreEqual(expectedXml, entity.FailureMechanismSectionPointXml); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string testName = "original name"; + var geometryPoints = new[] + { + new Point2D(0, 0), + new Point2D(0, 0) + }; + var failureMechanismSection = new FailureMechanismSection(testName, geometryPoints); + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismSectionEntity entity = failureMechanismSection.Create(registry); + + // Assert + Assert.AreNotSame(testName, entity.Name, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(testName, entity.Name); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/ForeshoreProfileCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/ForeshoreProfileCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/ForeshoreProfileCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,198 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.TestUtil; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Create +{ + [TestFixture] + public class ForeshoreProfileCreateExtensionsTest + { + [Test] + public void Create_WithoutCollector_ThrowsArgumentNullException() + { + // Setup + var foreshoreProfile = new TestForeshoreProfile(); + + // Call + TestDelegate test = () => foreshoreProfile.Create(null, 0); + + // Assert + string parameterName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", parameterName); + } + + [Test] + public void Create_WithSimpleProperties_ReturnsForeshoreProfileWithSimplePropertiesSet() + { + // Setup + const string name = "testName"; + const string id = "fpid"; + var random = new Random(21); + int order = random.Next(); + double orientation = random.NextDouble(); + double x0 = random.NextDouble(); + + var foreshoreProfile = new ForeshoreProfile(new Point2D(0, 0), Enumerable.Empty(), null, new ForeshoreProfile.ConstructionProperties + { + Id = id, + Name = name, + Orientation = orientation, + X0 = x0 + }); + var registry = new PersistenceRegistry(); + + // Call + ForeshoreProfileEntity entity = foreshoreProfile.Create(registry, order); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(order, entity.Order); + Assert.AreEqual(id, entity.Id); + Assert.AreEqual(name, entity.Name); + Assert.AreEqual(orientation, entity.Orientation, foreshoreProfile.Orientation.GetAccuracy()); + Assert.AreEqual(x0, entity.X0); + Assert.IsNull(entity.BreakWaterType); + Assert.IsNull(entity.BreakWaterHeight); + } + + [Test] + public void Create_WithNaNProperties_ReturnsForeshoreProfileWithPropertiesSetToNaN() + { + // Setup + var foreshoreProfile = new ForeshoreProfile( + new Point2D(0, 0), + Enumerable.Empty(), + new BreakWater(BreakWaterType.Caisson, double.NaN), + new ForeshoreProfile.ConstructionProperties + { + Id = "id", + Orientation = double.NaN, + X0 = double.NaN + }); + var registry = new PersistenceRegistry(); + + // Call + ForeshoreProfileEntity entity = foreshoreProfile.Create(registry, 0); + + // Assert + Assert.IsNotNull(entity); + Assert.IsNaN(entity.Orientation); + Assert.IsNaN(entity.X0); + Assert.IsNaN(entity.BreakWaterHeight); + } + + [Test] + public void Create_WithGeometry_ReturnsForeshoreProfileWithGeometryStringSet() + { + // Setup + int order = new Random(21).Next(); + var geometryPoints = new[] + { + new Point2D(0, 0), + new Point2D(0, 0) + }; + var foreshoreProfile = new TestForeshoreProfile(geometryPoints); + var registry = new PersistenceRegistry(); + + // Call + ForeshoreProfileEntity entity = foreshoreProfile.Create(registry, order); + + // Assert + Assert.IsNotNull(entity); + string expectedXml = new Point2DCollectionXmlSerializer().ToXml(geometryPoints); + Assert.AreEqual(expectedXml, entity.GeometryXml); + } + + [Test] + public void Create_WithBreakWater_ReturnsForeshoreProfileWithBreakWaterPropertiesSet() + { + // Setup + double height = new Random(21).NextDouble(); + const BreakWaterType breakWaterType = BreakWaterType.Caisson; + var foreshoreProfile = new TestForeshoreProfile(new BreakWater(breakWaterType, height)); + var registry = new PersistenceRegistry(); + + // Call + ForeshoreProfileEntity entity = foreshoreProfile.Create(registry, 0); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((int) breakWaterType, entity.BreakWaterType); + Assert.AreEqual(height, entity.BreakWaterHeight, foreshoreProfile.BreakWater.Height.GetAccuracy()); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string testName = "original name"; + const string testId = "test id"; + var foreshoreProfile = new ForeshoreProfile(new Point2D(0, 0), + Enumerable.Empty(), + null, + new ForeshoreProfile.ConstructionProperties + { + Id = testId, + Name = testName + }); + var registry = new PersistenceRegistry(); + + // Call + ForeshoreProfileEntity entity = foreshoreProfile.Create(registry, 0); + + // Assert + Assert.AreNotSame(testName, entity.Name, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(testName, entity.Name); + Assert.AreNotSame(testId, entity.Id, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(testId, entity.Id); + } + + [Test] + public void Create_ForeshoreProfileAlreadyRegistered_ReturnRegisteredEntity() + { + // Setup + var foreshoreProfile = new TestForeshoreProfile(); + var registry = new PersistenceRegistry(); + + ForeshoreProfileEntity entity1 = foreshoreProfile.Create(registry, 0); + + // Precondition: + Assert.IsTrue(registry.Contains(foreshoreProfile)); + + // Call + ForeshoreProfileEntity entity2 = foreshoreProfile.Create(registry, 0); + + // Assert + Assert.AreSame(entity1, entity2); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionInwards/DikeHeightOutputCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionInwards/DikeHeightOutputCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionInwards/DikeHeightOutputCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,111 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Data.TestUtil.IllustrationPoints; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.Storage.Core.TestUtil.IllustrationPoints; +using Riskeer.Storage.Core.Create.GrassCoverErosionInwards; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.GrassCoverErosionInwards +{ + [TestFixture] + public class DikeHeightOutputCreateExtensionsTest + { + [Test] + public void Create_OutputNull_ThrowArgumentNullException() + { + // Call + TestDelegate test = () => ((DikeHeightOutput) null).Create(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("output", exception.ParamName); + } + + [Test] + public void Create_WithValidParameters_ReturnsGrassCoverErosionInwardsDikeHeightOutputEntityWithOutputSet() + { + // Setup + var random = new Random(21); + var output = new DikeHeightOutput( + random.NextDouble(), random.NextDouble(), random.NextDouble(), random.NextDouble(), + random.NextDouble(), random.NextEnumValue(), null); + + // Call + GrassCoverErosionInwardsDikeHeightOutputEntity entity = output.Create(); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(output.DikeHeight, entity.DikeHeight, output.DikeHeight.GetAccuracy()); + Assert.AreEqual(output.TargetProbability, entity.TargetProbability); + Assert.AreEqual(output.TargetReliability, entity.TargetReliability, output.TargetReliability.GetAccuracy()); + Assert.AreEqual(output.CalculatedProbability, entity.CalculatedProbability); + Assert.AreEqual(output.CalculatedReliability, entity.CalculatedReliability, output.CalculatedReliability.GetAccuracy()); + Assert.AreEqual((byte) output.CalculationConvergence, entity.CalculationConvergence); + Assert.IsNull(entity.GeneralResultFaultTreeIllustrationPointEntity); + } + + [Test] + public void Create_WithNaNParameters_ReturnsGrassCoverErosionInwardsDikeHeightOutputEntityWithOutputNull() + { + // Setup + var random = new Random(21); + var output = new DikeHeightOutput(double.NaN, double.NaN, double.NaN, + double.NaN, double.NaN, random.NextEnumValue(), null); + + // Call + GrassCoverErosionInwardsDikeHeightOutputEntity entity = output.Create(); + + // Assert + Assert.IsNotNull(entity); + Assert.IsNull(entity.DikeHeight); + Assert.IsNull(entity.TargetProbability); + Assert.IsNull(entity.TargetReliability); + Assert.IsNull(entity.CalculatedProbability); + Assert.IsNull(entity.CalculatedReliability); + Assert.AreEqual((byte) output.CalculationConvergence, entity.CalculationConvergence); + Assert.IsNull(entity.GeneralResultFaultTreeIllustrationPointEntity); + } + + [Test] + public void Create_WithGeneralResult_ReturnsGrassCoverErosionInwardsDikeHeightOutputEntityWithGeneralResultEntity() + { + // Setup + var random = new Random(21); + var output = new DikeHeightOutput(double.NaN, double.NaN, double.NaN, + double.NaN, double.NaN, random.NextEnumValue(), + new TestGeneralResultFaultTreeIllustrationPoint()); + + // Call + GrassCoverErosionInwardsDikeHeightOutputEntity entity = output.Create(); + + // Assert + Assert.IsNotNull(entity); + GeneralResultEntityTestHelper.AssertGeneralResultPropertyValues(output.GeneralResult, entity.GeneralResultFaultTreeIllustrationPointEntity); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionInwards/DikeProfileCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionInwards/DikeProfileCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionInwards/DikeProfileCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,197 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.TestUtil; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.GrassCoverErosionInwards; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Create.GrassCoverErosionInwards +{ + [TestFixture] + public class DikeProfileCreateExtensionsTest + { + [Test] + public void Create_RegistryIsNull_ThrowArgumentNullException() + { + // Setup + DikeProfile dikeProfile = DikeProfileTestFactory.CreateDikeProfile(); + + // Call + TestDelegate call = () => dikeProfile.Create(null, 0); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + public void Create_WithoutBreakWater_ReturnEntityWithNullBreakWaterProperties() + { + // Setup + int order = new Random(22).Next(); + var dikeProfile = new DikeProfile(new Point2D(1.1, 2.2), + new[] + { + new RoughnessPoint(new Point2D(3.3, 4.4), 0.75), + new RoughnessPoint(new Point2D(5.5, 6.6), 0.75) + }, + new[] + { + new Point2D(7.7, 8.8), + new Point2D(9.9, 10.10) + }, + null, + new DikeProfile.ConstructionProperties + { + Id = "no_breakwater", + Name = "Dike profile without break water.", + DikeHeight = 11.11, + Orientation = 12.12, + X0 = 13.13 + }); + var registry = new PersistenceRegistry(); + + // Call + DikeProfileEntity entity = dikeProfile.Create(registry, order); + + // Assert + Assert.AreEqual(dikeProfile.WorldReferencePoint.X, entity.X); + Assert.AreEqual(dikeProfile.WorldReferencePoint.Y, entity.Y); + Assert.AreEqual(dikeProfile.X0, entity.X0); + Assert.AreEqual(order, entity.Order); + string convertedDikeGeometry = new RoughnessPointCollectionXmlSerializer().ToXml(dikeProfile.DikeGeometry); + Assert.AreEqual(convertedDikeGeometry, entity.DikeGeometryXml); + string convertedForeshoreGeometry = new Point2DCollectionXmlSerializer().ToXml(dikeProfile.ForeshoreGeometry); + Assert.AreEqual(convertedForeshoreGeometry, entity.ForeshoreXml); + Assert.AreEqual(dikeProfile.Orientation.Value, entity.Orientation); + Assert.AreEqual(dikeProfile.DikeHeight.Value, entity.DikeHeight); + Assert.AreEqual(dikeProfile.Id, entity.Id); + Assert.AreEqual(dikeProfile.Name, entity.Name); + + Assert.IsNull(entity.BreakWaterHeight); + Assert.IsNull(entity.BreakWaterType); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalId = "no_breakwater"; + const string originalName = "Dike profile without break water."; + var dikeProfile = new DikeProfile(new Point2D(1.1, 2.2), + new RoughnessPoint[0], + new Point2D[0], + null, + new DikeProfile.ConstructionProperties + { + Id = originalId, + Name = originalName + }); + var registry = new PersistenceRegistry(); + + // Call + DikeProfileEntity entity = dikeProfile.Create(registry, 0); + + // Assert + Assert.AreNotSame(originalName, entity.Name, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(originalName, entity.Name); + Assert.AreNotSame(originalId, entity.Id, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(originalId, entity.Id); + } + + [Test] + [TestCase(BreakWaterType.Caisson, 1.1)] + [TestCase(BreakWaterType.Dam, 2.2)] + [TestCase(BreakWaterType.Wall, -3.3)] + public void Create_WithBreakWater_ReturnEntity(BreakWaterType type, double height) + { + // Setup + int order = new Random(42).Next(); + var dikeProfile = new DikeProfile(new Point2D(1234.4567, 5678.432), + new[] + { + new RoughnessPoint(new Point2D(-6.6, -3.3), 0.75), + new RoughnessPoint(new Point2D(4.4, 5.5), 0.75) + }, + new[] + { + new Point2D(-12.12, -13.13), + new Point2D(-6.6, -3.3) + }, + new BreakWater(type, height), + new DikeProfile.ConstructionProperties + { + Id = "no_breakwater", + Name = "Dike profile without break water.", + DikeHeight = 98.76, + Orientation = 76.54, + X0 = -12.34 + }); + var registry = new PersistenceRegistry(); + + // Call + DikeProfileEntity entity = dikeProfile.Create(registry, order); + + // Assert + Assert.AreEqual(dikeProfile.WorldReferencePoint.X, entity.X); + Assert.AreEqual(dikeProfile.WorldReferencePoint.Y, entity.Y); + Assert.AreEqual(dikeProfile.X0, entity.X0); + Assert.AreEqual(order, entity.Order); + string convertedDikeGeometry = new RoughnessPointCollectionXmlSerializer().ToXml(dikeProfile.DikeGeometry); + Assert.AreEqual(convertedDikeGeometry, entity.DikeGeometryXml); + string convertedForeshoreGeometry = new Point2DCollectionXmlSerializer().ToXml(dikeProfile.ForeshoreGeometry); + Assert.AreEqual(convertedForeshoreGeometry, entity.ForeshoreXml); + Assert.AreEqual(dikeProfile.Orientation.Value, entity.Orientation); + Assert.AreEqual(dikeProfile.DikeHeight.Value, entity.DikeHeight); + Assert.AreEqual(dikeProfile.Id, entity.Id); + Assert.AreEqual(dikeProfile.Name, entity.Name); + + Assert.AreEqual((byte) type, entity.BreakWaterType); + Assert.AreEqual(height, entity.BreakWaterHeight); + } + + [Test] + public void Create_DikeProfileAlreadyRegistered_ReturnRegisteredEntity() + { + // Setup + DikeProfile dikeProfile = DikeProfileTestFactory.CreateDikeProfile(); + var registry = new PersistenceRegistry(); + DikeProfileEntity entity1 = dikeProfile.Create(registry, 0); + + // Precondition: + Assert.IsTrue(registry.Contains(dikeProfile)); + + // Call + DikeProfileEntity entity2 = dikeProfile.Create(registry, 0); + + // Assert + Assert.AreSame(entity1, entity2); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionInwards/GrassCoverErosionInwardsCalculationCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionInwards/GrassCoverErosionInwardsCalculationCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionInwards/GrassCoverErosionInwardsCalculationCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,269 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Data; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.GrassCoverErosionInwards.Data; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.GrassCoverErosionInwards; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.GrassCoverErosionInwards +{ + [TestFixture] + public class GrassCoverErosionInwardsCalculationCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowArgumentNullException() + { + // Setup + var calculation = new GrassCoverErosionInwardsCalculation(); + + // Call + TestDelegate call = () => calculation.Create(null, 0); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase("I am comment")] + [TestCase(null)] + public void Create_ValidCalculation_ReturnEntity(string comment) + { + // Setup + var random = new Random(12); + int order = random.Next(); + const string name = "GrassCoverErosionInwardsCalculation Name"; + var calculation = new GrassCoverErosionInwardsCalculation + { + Name = name, + Comments = + { + Body = comment + }, + InputParameters = + { + DikeProfile = null, + HydraulicBoundaryLocation = null, + DikeHeight = (RoundedDouble) 1.1, + Orientation = (RoundedDouble) 2.2, + BreakWater = + { + Height = (RoundedDouble) 3.3, + Type = BreakWaterType.Dam + }, + DikeHeightCalculationType = random.NextEnumValue(), + OvertoppingRateCalculationType = random.NextEnumValue(), + CriticalFlowRate = + { + Mean = (RoundedDouble) 4.4, + StandardDeviation = (RoundedDouble) 5.5 + }, + UseBreakWater = true, + UseForeshore = false, + ShouldDikeHeightIllustrationPointsBeCalculated = random.NextBoolean(), + ShouldOvertoppingOutputIllustrationPointsBeCalculated = random.NextBoolean(), + ShouldOvertoppingRateIllustrationPointsBeCalculated = random.NextBoolean() + }, + Output = null + }; + + var registry = new PersistenceRegistry(); + + // Call + GrassCoverErosionInwardsCalculationEntity entity = calculation.Create(registry, order); + + // Assert + Assert.AreEqual(name, entity.Name); + Assert.AreEqual(comment, entity.Comments); + Assert.AreEqual(order, entity.Order); + + Assert.IsNull(entity.DikeProfileEntity); + Assert.IsNull(entity.HydraulicLocationEntity); + + GrassCoverErosionInwardsInput input = calculation.InputParameters; + Assert.AreEqual(input.BreakWater.Height.Value, entity.BreakWaterHeight); + Assert.AreEqual((short) input.BreakWater.Type, entity.BreakWaterType); + Assert.AreEqual(Convert.ToByte(input.UseBreakWater), entity.UseBreakWater); + Assert.AreEqual(input.CriticalFlowRate.Mean.Value, entity.CriticalFlowRateMean); + Assert.AreEqual(input.CriticalFlowRate.StandardDeviation.Value, entity.CriticalFlowRateStandardDeviation); + Assert.AreEqual(input.Orientation.Value, entity.Orientation); + Assert.AreEqual(Convert.ToByte(input.DikeHeightCalculationType), entity.DikeHeightCalculationType); + Assert.AreEqual(Convert.ToByte(input.OvertoppingRateCalculationType), entity.OvertoppingRateCalculationType); + Assert.AreEqual(input.DikeHeight.Value, entity.DikeHeight); + Assert.AreEqual(Convert.ToByte(input.UseForeshore), entity.UseForeshore); + + Assert.AreEqual(Convert.ToByte(input.ShouldDikeHeightIllustrationPointsBeCalculated), + entity.ShouldDikeHeightIllustrationPointsBeCalculated); + Assert.AreEqual(Convert.ToByte(input.ShouldOvertoppingOutputIllustrationPointsBeCalculated), + entity.ShouldOvertoppingOutputIllustrationPointsBeCalculated); + Assert.AreEqual(Convert.ToByte(input.ShouldOvertoppingRateIllustrationPointsBeCalculated), + entity.ShouldOvertoppingRateIllustrationPointsBeCalculated); + + Assert.IsFalse(entity.GrassCoverErosionInwardsOutputEntities.Any()); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string name = "A"; + const string comment = "B"; + var calculation = new GrassCoverErosionInwardsCalculation + { + Name = name, + Comments = + { + Body = comment + } + }; + + var registry = new PersistenceRegistry(); + + // Call + GrassCoverErosionInwardsCalculationEntity entity = calculation.Create(registry, 0); + + // Assert + Assert.AreNotSame(name, entity.Name, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(name, entity.Name); + + Assert.AreNotSame(comment, entity.Comments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(comment, entity.Comments); + } + + [Test] + public void Create_NaNParameters_EntityWithNullFields() + { + // Setup + var calculation = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + Orientation = RoundedDouble.NaN, + CriticalFlowRate = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + DikeHeight = RoundedDouble.NaN, + BreakWater = + { + Height = RoundedDouble.NaN + } + } + }; + var registry = new PersistenceRegistry(); + + // Call + GrassCoverErosionInwardsCalculationEntity entity = calculation.Create(registry, 0); + + // Assert + Assert.IsNull(entity.Orientation); + Assert.IsNull(entity.CriticalFlowRateMean); + Assert.IsNull(entity.CriticalFlowRateStandardDeviation); + Assert.IsNull(entity.DikeHeight); + Assert.IsNull(entity.BreakWaterHeight); + } + + [Test] + public void Create_CalculationWithAlreadySavedDikeProfile_ReturnEntityWithDikeProfileEntity() + { + // Setup + DikeProfile dikeProfile = DikeProfileTestFactory.CreateDikeProfile(); + var calculation = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = dikeProfile + } + }; + + var dikeProfileEntity = new DikeProfileEntity(); + var registry = new PersistenceRegistry(); + registry.Register(dikeProfileEntity, dikeProfile); + + // Call + GrassCoverErosionInwardsCalculationEntity entity = calculation.Create(registry, 0); + + // Assert + Assert.AreSame(dikeProfileEntity, entity.DikeProfileEntity); + } + + [Test] + public void Create_CalculationWithAlreadySavedHydraulicBoundaryLocation_ReturnEntityWithHydraulicLocationEntity() + { + // Setup + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "A", 1, 1); + var calculation = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation + } + }; + + var hydraulicLocationEntity = new HydraulicLocationEntity(); + var registry = new PersistenceRegistry(); + registry.Register(hydraulicLocationEntity, hydraulicBoundaryLocation); + + // Call + GrassCoverErosionInwardsCalculationEntity entity = calculation.Create(registry, 0); + + // Assert + Assert.AreSame(hydraulicLocationEntity, entity.HydraulicLocationEntity); + } + + [Test] + public void Create_CalculationWithOutput_ReturnEntity() + { + // Setup + var random = new Random(456); + var overtoppingOutput = new OvertoppingOutput(random.NextDouble(), false, random.NextDouble(), null); + var output = new GrassCoverErosionInwardsOutput(overtoppingOutput, null, null); + + var calculation = new GrassCoverErosionInwardsCalculation + { + Output = output + }; + + var registry = new PersistenceRegistry(); + + // Call + GrassCoverErosionInwardsCalculationEntity entity = calculation.Create(registry, 0); + + // Assert + GrassCoverErosionInwardsOutputEntity outputEntity = entity.GrassCoverErosionInwardsOutputEntities.Single(); + Assert.AreEqual(overtoppingOutput.WaveHeight, outputEntity.WaveHeight); + Assert.AreEqual(overtoppingOutput.Reliability, outputEntity.Reliability); + Assert.IsNull(outputEntity.GeneralResultFaultTreeIllustrationPointEntity); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionInwards/GrassCoverErosionInwardsFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionInwards/GrassCoverErosionInwardsFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionInwards/GrassCoverErosionInwardsFailureMechanismCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,242 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.GrassCoverErosionInwards.Data; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.GrassCoverErosionInwards; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.GrassCoverErosionInwards +{ + [TestFixture] + public class GrassCoverErosionInwardsFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet(bool isRelevant) + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + }, + GeneralInput = + { + N = new Random().NextRoundedDouble(1, 20) + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.GrassRevetmentTopErosionAndInwards, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + + Assert.AreEqual(1, entity.GrassCoverErosionInwardsFailureMechanismMetaEntities.Count); + GrassCoverErosionInwardsFailureMechanismMetaEntity generalInputEntity = entity.GrassCoverErosionInwardsFailureMechanismMetaEntities.First(); + Assert.AreEqual(failureMechanism.GeneralInput.N, generalInputEntity.N); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + TestHelper.AssertAreEqualButNotSame(failureMechanism.InputComments.Body, entity.InputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.OutputComments.Body, entity.OutputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + Assert.IsNull(entity.FailureMechanismSectionCollectionSourcePath); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + const string filePath = "failureMechanismSections/file/path"; + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + failureMechanism.SetSections(new[] + { + FailureMechanismSectionTestFactory.CreateFailureMechanismSection() + }, filePath); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.GrassCoverErosionInwardsSectionResultEntities).Count()); + TestHelper.AssertAreEqualButNotSame(filePath, entity.FailureMechanismSectionCollectionSourcePath); + } + + [Test] + public void Create_WithoutDikeProfiles_EmptyDikeProfileEntities() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + CollectionAssert.IsEmpty(entity.DikeProfileEntities); + + GrassCoverErosionInwardsFailureMechanismMetaEntity generalInputEntity = + entity.GrassCoverErosionInwardsFailureMechanismMetaEntities.Single(); + Assert.IsNull(generalInputEntity.DikeProfileCollectionSourcePath); + } + + [Test] + public void Create_WithDikeProfiles_AddDikeProfileEntities() + { + // Setup + const string filePath = "some/path/to/my/dikeprofiles"; + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + failureMechanism.DikeProfiles.AddRange(new[] + { + DikeProfileTestFactory.CreateDikeProfile(string.Empty, "id1"), + DikeProfileTestFactory.CreateDikeProfile(string.Empty, "id2") + }, filePath); + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.AreEqual(2, entity.DikeProfileEntities.Count); + + GrassCoverErosionInwardsFailureMechanismMetaEntity generalInputEntity = + entity.GrassCoverErosionInwardsFailureMechanismMetaEntities.Single(); + TestHelper.AssertAreEqualButNotSame(filePath, generalInputEntity.DikeProfileCollectionSourcePath); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCalculationGroup_ReturnFailureMechanismEntityWithCalculationGroupEntities(bool isRelevant) + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(new CalculationGroup + { + Name = "A" + }); + failureMechanism.CalculationsGroup.Children.Add(new CalculationGroup + { + Name = "B" + }); + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(failureMechanism.CalculationsGroup.Name, entity.CalculationGroupEntity.Name); + Assert.AreEqual(0, entity.CalculationGroupEntity.Order); + + CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity.CalculationGroupEntity1 + .OrderBy(cge => cge.Order) + .ToArray(); + Assert.AreEqual(2, childGroupEntities.Length); + Assert.AreEqual("A", childGroupEntities[0].Name); + Assert.AreEqual(0, childGroupEntities[0].Order); + Assert.AreEqual("B", childGroupEntities[1].Name); + Assert.AreEqual(1, childGroupEntities[1].Order); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionInwards/GrassCoverErosionInwardsFailureMechanismSectionResultCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionInwards/GrassCoverErosionInwardsFailureMechanismSectionResultCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionInwards/GrassCoverErosionInwardsFailureMechanismSectionResultCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,137 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.GrassCoverErosionInwards.Data; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.GrassCoverErosionInwards; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.GrassCoverErosionInwards +{ + [TestFixture] + public class GrassCoverErosionInwardsFailureMechanismSectionResultCreateExtensionsTest + { + [Test] + public void Create_FailureMechanismSectionResultNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((GrassCoverErosionInwardsFailureMechanismSectionResult) null).Create(new PersistenceRegistry()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("result", exception.ParamName); + } + + [Test] + public void Create_PersistencyRegistryNull_ThrowsArgumentNullException() + { + // Setup + var sectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + TestDelegate test = () => sectionResult.Create(null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("registry", exception.ParamName); + } + + [Test] + public void Create_WithDifferentResults_ReturnsEntityWithExpectedResults() + { + // Setup + var random = new Random(21); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResult = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + double tailorMadeAssessmentProbability = random.NextDouble(); + bool useManualAssembly = random.NextBoolean(); + double manualAssemblyProbability = random.NextDouble(); + + var sectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + SimpleAssessmentResult = simpleAssessmentResult, + DetailedAssessmentResult = detailedAssessmentResult, + TailorMadeAssessmentResult = tailorMadeAssessmentResult, + TailorMadeAssessmentProbability = tailorMadeAssessmentProbability, + UseManualAssembly = useManualAssembly, + ManualAssemblyProbability = manualAssemblyProbability + }; + + // Call + GrassCoverErosionInwardsSectionResultEntity entity = sectionResult.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(Convert.ToByte(simpleAssessmentResult), entity.SimpleAssessmentResult); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResult), entity.DetailedAssessmentResult); + Assert.AreEqual(Convert.ToByte(tailorMadeAssessmentResult), entity.TailorMadeAssessmentResult); + Assert.AreEqual(tailorMadeAssessmentProbability, entity.TailorMadeAssessmentProbability); + Assert.AreEqual(Convert.ToByte(useManualAssembly), entity.UseManualAssembly); + Assert.AreEqual(manualAssemblyProbability, entity.ManualAssemblyProbability); + + Assert.IsNull(entity.GrassCoverErosionInwardsCalculationEntity); + } + + [Test] + public void Create_SectionResultWithNaNValues_ReturnsEntityWithExpectedResults() + { + // Setup + var sectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + TailorMadeAssessmentProbability = double.NaN, + ManualAssemblyProbability = double.NaN + }; + + // Call + GrassCoverErosionInwardsSectionResultEntity entity = sectionResult.Create(new PersistenceRegistry()); + + // Assert + Assert.IsNull(entity.TailorMadeAssessmentProbability); + Assert.IsNull(entity.ManualAssemblyProbability); + } + + [Test] + public void Create_CalculationSet_ReturnEntityWithCalculationEntity() + { + // Setup + var calculation = new GrassCoverErosionInwardsCalculation(); + var sectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + Calculation = calculation + }; + + var registry = new PersistenceRegistry(); + var calculationEntity = new GrassCoverErosionInwardsCalculationEntity(); + registry.Register(calculationEntity, calculation); + + // Call + GrassCoverErosionInwardsSectionResultEntity entity = sectionResult.Create(registry); + + // Assert + Assert.AreSame(calculationEntity, entity.GrassCoverErosionInwardsCalculationEntity); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionInwards/GrassCoverErosionInwardsOutputCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionInwards/GrassCoverErosionInwardsOutputCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionInwards/GrassCoverErosionInwardsOutputCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,168 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Data.TestUtil.IllustrationPoints; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.GrassCoverErosionInwards.Data.TestUtil; +using Ringtoets.Storage.Core.TestUtil.IllustrationPoints; +using Riskeer.Storage.Core.Create.GrassCoverErosionInwards; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.GrassCoverErosionInwards +{ + [TestFixture] + public class GrassCoverErosionInwardsOutputCreateExtensionsTest + { + [Test] + public void Create_ValidInput_ReturnGrassCoverErosionInwardsOutputEntity() + { + // Setup + var random = new Random(456); + var overtoppingOutput = new OvertoppingOutput(random.NextDouble(), false, random.NextDouble(), null); + + var dikeHeightConvergence = random.NextEnumValue(); + var overtoppingRateConvergence = random.NextEnumValue(); + + var dikeHeightOutput = new DikeHeightOutput(random.NextDouble(), random.NextDouble(), + random.NextDouble(), random.NextDouble(), + random.NextDouble(), dikeHeightConvergence, null); + var overtoppingRateOutput = new OvertoppingRateOutput(random.NextDouble(), random.NextDouble(), + random.NextDouble(), random.NextDouble(), + random.NextDouble(), overtoppingRateConvergence, null); + var output = new GrassCoverErosionInwardsOutput(overtoppingOutput, dikeHeightOutput, overtoppingRateOutput); + + // Call + GrassCoverErosionInwardsOutputEntity entity = output.Create(); + + // Assert + Assert.AreEqual(overtoppingOutput.WaveHeight.Value, entity.WaveHeight); + Assert.AreEqual(Convert.ToByte(overtoppingOutput.IsOvertoppingDominant), entity.IsOvertoppingDominant); + Assert.AreEqual(overtoppingOutput.Reliability, entity.Reliability); + + Assert.IsNull(entity.GeneralResultFaultTreeIllustrationPointEntity); + + GrassCoverErosionInwardsDikeHeightOutputEntity dikeHeightEntity = entity.GrassCoverErosionInwardsDikeHeightOutputEntities.First(); + Assert.AreEqual(dikeHeightOutput.DikeHeight, dikeHeightEntity.DikeHeight, dikeHeightOutput.DikeHeight.GetAccuracy()); + Assert.AreEqual(dikeHeightOutput.TargetProbability, dikeHeightEntity.TargetProbability); + Assert.AreEqual(dikeHeightOutput.TargetReliability, dikeHeightEntity.TargetReliability, dikeHeightOutput.TargetReliability.GetAccuracy()); + Assert.AreEqual(dikeHeightOutput.CalculatedProbability, dikeHeightEntity.CalculatedProbability); + Assert.AreEqual(dikeHeightOutput.CalculatedReliability, dikeHeightEntity.CalculatedReliability, dikeHeightOutput.CalculatedReliability.GetAccuracy()); + Assert.AreEqual((byte) dikeHeightOutput.CalculationConvergence, dikeHeightEntity.CalculationConvergence); + + GrassCoverErosionInwardsOvertoppingRateOutputEntity overtoppingRateEntity = entity.GrassCoverErosionInwardsOvertoppingRateOutputEntities.First(); + Assert.AreEqual(overtoppingRateOutput.OvertoppingRate, overtoppingRateEntity.OvertoppingRate, overtoppingRateOutput.OvertoppingRate.GetAccuracy()); + Assert.AreEqual(overtoppingRateOutput.TargetProbability, overtoppingRateEntity.TargetProbability); + Assert.AreEqual(overtoppingRateOutput.TargetReliability, overtoppingRateEntity.TargetReliability, overtoppingRateOutput.TargetReliability.GetAccuracy()); + Assert.AreEqual(overtoppingRateOutput.CalculatedProbability, overtoppingRateEntity.CalculatedProbability); + Assert.AreEqual(overtoppingRateOutput.CalculatedReliability, overtoppingRateEntity.CalculatedReliability, overtoppingRateOutput.CalculatedReliability.GetAccuracy()); + Assert.AreEqual((byte) overtoppingRateOutput.CalculationConvergence, overtoppingRateEntity.CalculationConvergence); + } + + [Test] + public void Create_NaNValues_ReturnGrassCoverErosionInwardsOutputEntity() + { + // Setup + var overtoppingOutput = new OvertoppingOutput(double.NaN, true, double.NaN, null); + var dikeHeightOutput = new TestDikeHeightOutput(double.NaN, CalculationConvergence.CalculatedConverged); + var overtoppingRateOutput = new TestOvertoppingRateOutput(double.NaN, CalculationConvergence.CalculatedConverged); + var output = new GrassCoverErosionInwardsOutput(overtoppingOutput, dikeHeightOutput, overtoppingRateOutput); + + // Call + GrassCoverErosionInwardsOutputEntity entity = output.Create(); + + // Assert + Assert.IsNull(entity.WaveHeight); + Assert.AreEqual(Convert.ToByte(overtoppingOutput.IsOvertoppingDominant), entity.IsOvertoppingDominant); + Assert.IsNull(entity.Reliability); + Assert.IsNull(entity.GeneralResultFaultTreeIllustrationPointEntity); + + GrassCoverErosionInwardsDikeHeightOutputEntity dikeHeightEntity = entity.GrassCoverErosionInwardsDikeHeightOutputEntities.First(); + Assert.IsNull(dikeHeightEntity.DikeHeight); + Assert.IsNull(dikeHeightEntity.TargetProbability); + Assert.IsNull(dikeHeightEntity.TargetReliability); + Assert.IsNull(dikeHeightEntity.CalculatedProbability); + Assert.IsNull(dikeHeightEntity.CalculatedReliability); + Assert.AreEqual((byte) dikeHeightOutput.CalculationConvergence, dikeHeightEntity.CalculationConvergence); + + GrassCoverErosionInwardsOvertoppingRateOutputEntity overtoppingRateEntity = entity.GrassCoverErosionInwardsOvertoppingRateOutputEntities.First(); + Assert.IsNull(overtoppingRateEntity.OvertoppingRate); + Assert.IsNull(overtoppingRateEntity.TargetProbability); + Assert.IsNull(overtoppingRateEntity.TargetReliability); + Assert.IsNull(overtoppingRateEntity.CalculatedProbability); + Assert.IsNull(overtoppingRateEntity.CalculatedReliability); + Assert.AreEqual((byte) overtoppingRateOutput.CalculationConvergence, overtoppingRateEntity.CalculationConvergence); + } + + [Test] + public void Create_DikeHeightOutputIsNull_NoDikeHeightOutputEntityCreated() + { + // Setup + var overtoppingOutput = new TestOvertoppingOutput(1); + var overtoppingRateOutput = new TestOvertoppingRateOutput(double.NaN, CalculationConvergence.CalculatedConverged); + var output = new GrassCoverErosionInwardsOutput(overtoppingOutput, null, overtoppingRateOutput); + + // Call + GrassCoverErosionInwardsOutputEntity entity = output.Create(); + + // Assert + Assert.IsFalse(entity.GrassCoverErosionInwardsDikeHeightOutputEntities.Any()); + } + + [Test] + public void Create_OvertoppingRateOutputIsNull_NoOvertoppingRateOutputEntityCreated() + { + // Setup + var overtoppingOutput = new TestOvertoppingOutput(1); + var dikeHeightOutput = new TestDikeHeightOutput(double.NaN, CalculationConvergence.CalculatedConverged); + var output = new GrassCoverErosionInwardsOutput(overtoppingOutput, dikeHeightOutput, null); + + // Call + GrassCoverErosionInwardsOutputEntity entity = output.Create(); + + // Assert + Assert.IsFalse(entity.GrassCoverErosionInwardsOvertoppingRateOutputEntities.Any()); + } + + [Test] + public void Create_WithGeneralResult_ReturnsGrassCoverErosionInwardsOutputEntityWithGeneralResultEntity() + { + // Setup + var overtoppingOutput = new OvertoppingOutput(double.NaN, + true, + double.NaN, + new TestGeneralResultFaultTreeIllustrationPoint()); + + var output = new GrassCoverErosionInwardsOutput(overtoppingOutput, null, null); + + // Call + GrassCoverErosionInwardsOutputEntity entity = output.Create(); + + // Assert + GeneralResultEntityTestHelper.AssertGeneralResultPropertyValues(output.OvertoppingOutput.GeneralResult, entity.GeneralResultFaultTreeIllustrationPointEntity); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionInwards/OvertoppingRateOutputCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionInwards/OvertoppingRateOutputCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionInwards/OvertoppingRateOutputCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,111 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Data.TestUtil.IllustrationPoints; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.Storage.Core.TestUtil.IllustrationPoints; +using Riskeer.Storage.Core.Create.GrassCoverErosionInwards; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.GrassCoverErosionInwards +{ + [TestFixture] + public class OvertoppingRateOutputCreateExtensionsTest + { + [Test] + public void Create_OutputNull_ThrowArgumentNullException() + { + // Call + TestDelegate test = () => ((OvertoppingRateOutput) null).Create(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("output", exception.ParamName); + } + + [Test] + public void Create_WithValidParameters_ReturnsGrassCoverErosionInwardsOvertoppingRateOutputEntityWithOutputSet() + { + // Setup + var random = new Random(21); + var output = new OvertoppingRateOutput( + random.NextDouble(), random.NextDouble(), random.NextDouble(), random.NextDouble(), + random.NextDouble(), random.NextEnumValue(), null); + + // Call + GrassCoverErosionInwardsOvertoppingRateOutputEntity entity = output.Create(); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(output.OvertoppingRate, entity.OvertoppingRate, output.OvertoppingRate.GetAccuracy()); + Assert.AreEqual(output.TargetProbability, entity.TargetProbability); + Assert.AreEqual(output.TargetReliability, entity.TargetReliability, output.TargetReliability.GetAccuracy()); + Assert.AreEqual(output.CalculatedProbability, entity.CalculatedProbability); + Assert.AreEqual(output.CalculatedReliability, entity.CalculatedReliability, output.CalculatedReliability.GetAccuracy()); + Assert.AreEqual((byte) output.CalculationConvergence, entity.CalculationConvergence); + Assert.IsNull(entity.GeneralResultFaultTreeIllustrationPointEntity); + } + + [Test] + public void Create_WithNaNParameters_ReturnsGrassCoverErosionInwardsOvertoppingRateOutputEntityWithOutputNull() + { + // Setup + var random = new Random(21); + var output = new OvertoppingRateOutput(double.NaN, double.NaN, double.NaN, + double.NaN, double.NaN, random.NextEnumValue(), null); + + // Call + GrassCoverErosionInwardsOvertoppingRateOutputEntity entity = output.Create(); + + // Assert + Assert.IsNotNull(entity); + Assert.IsNull(entity.OvertoppingRate); + Assert.IsNull(entity.TargetProbability); + Assert.IsNull(entity.TargetReliability); + Assert.IsNull(entity.CalculatedProbability); + Assert.IsNull(entity.CalculatedReliability); + Assert.AreEqual((byte) output.CalculationConvergence, entity.CalculationConvergence); + Assert.IsNull(entity.GeneralResultFaultTreeIllustrationPointEntity); + } + + [Test] + public void Create_WithGeneralResult_ReturnsGrassCoverErosionInwardsDikeHeightOutputEntityWithGeneralResultEntity() + { + // Setup + var random = new Random(21); + var output = new OvertoppingRateOutput(double.NaN, double.NaN, double.NaN, + double.NaN, double.NaN, random.NextEnumValue(), + new TestGeneralResultFaultTreeIllustrationPoint()); + + // Call + GrassCoverErosionInwardsOvertoppingRateOutputEntity entity = output.Create(); + + // Assert + Assert.IsNotNull(entity); + GeneralResultEntityTestHelper.AssertGeneralResultPropertyValues(output.GeneralResult, entity.GeneralResultFaultTreeIllustrationPointEntity); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionOutwards/GrassCoverErosionOutwardsFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionOutwards/GrassCoverErosionOutwardsFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionOutwards/GrassCoverErosionOutwardsFailureMechanismCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,352 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.GrassCoverErosionOutwards.Data; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.GrassCoverErosionOutwards; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.GrassCoverErosionOutwards +{ + [TestFixture] + public class GrassCoverErosionOutwardsFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet(bool isRelevant) + { + // Setup + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + }, + GeneralInput = + { + N = new Random(39).NextRoundedDouble(1, 20) + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.GrassRevetmentErosionOutwards, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + + Assert.AreEqual(1, entity.GrassCoverErosionOutwardsFailureMechanismMetaEntities.Count); + GrassCoverErosionOutwardsFailureMechanismMetaEntity generalInputEntity = entity.GrassCoverErosionOutwardsFailureMechanismMetaEntities.First(); + Assert.AreEqual(failureMechanism.GeneralInput.N, generalInputEntity.N); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + TestHelper.AssertAreEqualButNotSame(failureMechanism.InputComments.Body, entity.InputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.OutputComments.Body, entity.OutputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + Assert.IsNull(entity.FailureMechanismSectionCollectionSourcePath); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + const string filePath = "failureMechanismSections/file/path"; + failureMechanism.SetSections(new[] + { + FailureMechanismSectionTestFactory.CreateFailureMechanismSection() + }, filePath); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.GrassCoverErosionOutwardsSectionResultEntities).Count()); + TestHelper.AssertAreEqualButNotSame(failureMechanism.FailureMechanismSectionSourcePath, entity.FailureMechanismSectionCollectionSourcePath); + } + + [Test] + public void Create_WithoutForeshoreProfiles_EmptyForeshoreProfilesEntities() + { + // Setup + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.ForeshoreProfileEntities); + + GrassCoverErosionOutwardsFailureMechanismMetaEntity metaEntity = + entity.GrassCoverErosionOutwardsFailureMechanismMetaEntities.Single(); + Assert.IsNull(metaEntity.ForeshoreProfileCollectionSourcePath); + } + + [Test] + public void Create_WithForeshoreProfiles_ForeshoreProfilesEntitiesCreated() + { + // Setup + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + const string filePath = "some/path/to/foreshoreProfiles"; + failureMechanism.ForeshoreProfiles.AddRange(new[] + { + new TestForeshoreProfile() + }, filePath); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.ForeshoreProfileEntities.Count); + + GrassCoverErosionOutwardsFailureMechanismMetaEntity metaEntity = + entity.GrassCoverErosionOutwardsFailureMechanismMetaEntities.Single(); + string metaEntityForeshoreProfileCollectionSourcePath = metaEntity.ForeshoreProfileCollectionSourcePath; + TestHelper.AssertAreEqualButNotSame(filePath, metaEntityForeshoreProfileCollectionSourcePath); + } + + [Test] + [TestCase(true, TestName = "Create_WithCalculationGroup_ReturnFMEntityWithCalculationGroupEntities(true)")] + [TestCase(false, TestName = "Create_WithCalculationGroup_ReturnFMEntityWithCalculationGroupEntities(false)")] + public void Create_WithCalculationGroup_ReturnFailureMechanismEntityWithCalculationGroupEntities(bool isRelevant) + { + // Setup + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + failureMechanism.WaveConditionsCalculationGroup.Children.Add(new CalculationGroup + { + Name = "A" + }); + failureMechanism.WaveConditionsCalculationGroup.Children.Add(new CalculationGroup + { + Name = "B" + }); + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(failureMechanism.WaveConditionsCalculationGroup.Name, entity.CalculationGroupEntity.Name); + Assert.AreEqual(0, entity.CalculationGroupEntity.Order); + + CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity.CalculationGroupEntity1 + .OrderBy(cge => cge.Order) + .ToArray(); + Assert.AreEqual(2, childGroupEntities.Length); + Assert.AreEqual("A", childGroupEntities[0].Name); + Assert.AreEqual(0, childGroupEntities[0].Order); + Assert.AreEqual("B", childGroupEntities[1].Name); + Assert.AreEqual(1, childGroupEntities[1].Order); + } + + [Test] + public void Create_WithoutHydraulicBoundaryLocationCalculations_ReturnsFailureMechanismWithoutHydraulicLocationCalculationEntities() + { + // Setup + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + GrassCoverErosionOutwardsFailureMechanismMetaEntity metaEntity = + entity.GrassCoverErosionOutwardsFailureMechanismMetaEntities.Single(); + + AssertHydraulicLocationCalculationCollectionEntities(failureMechanism, registry, metaEntity); + } + + [Test] + public void Create_WithHydraulicBoundaryLocationCalculations_ReturnsFailureMechanismWithHydraulicLocationCalculationEntities() + { + // Setup + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(0, "A", 0, 0); + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + failureMechanism.SetHydraulicBoundaryLocationCalculations(new[] + { + hydraulicBoundaryLocation + }); + SetHydraulicBoundaryLocationCalculationInputsOfFailureMechanism(failureMechanism); + + var registry = new PersistenceRegistry(); + registry.Register(new HydraulicLocationEntity(), hydraulicBoundaryLocation); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + GrassCoverErosionOutwardsFailureMechanismMetaEntity metaEntity = + entity.GrassCoverErosionOutwardsFailureMechanismMetaEntities.Single(); + + AssertHydraulicLocationCalculationCollectionEntities(failureMechanism, registry, metaEntity); + } + + private static void AssertHydraulicLocationCalculationCollectionEntities(GrassCoverErosionOutwardsFailureMechanism expectedFailureMechanism, + PersistenceRegistry registry, + GrassCoverErosionOutwardsFailureMechanismMetaEntity actualEntity) + { + AssertHydraulicLocationCalculationCollectionEntity(expectedFailureMechanism.WaveHeightCalculationsForMechanismSpecificLowerLimitNorm, + registry, + actualEntity.HydraulicLocationCalculationCollectionEntity); + AssertHydraulicLocationCalculationCollectionEntity(expectedFailureMechanism.WaveHeightCalculationsForMechanismSpecificSignalingNorm, + registry, + actualEntity.HydraulicLocationCalculationCollectionEntity1); + AssertHydraulicLocationCalculationCollectionEntity(expectedFailureMechanism.WaveHeightCalculationsForMechanismSpecificFactorizedSignalingNorm, + registry, + actualEntity.HydraulicLocationCalculationCollectionEntity2); + + AssertHydraulicLocationCalculationCollectionEntity(expectedFailureMechanism.WaterLevelCalculationsForMechanismSpecificLowerLimitNorm, + registry, + actualEntity.HydraulicLocationCalculationCollectionEntity3); + AssertHydraulicLocationCalculationCollectionEntity(expectedFailureMechanism.WaterLevelCalculationsForMechanismSpecificSignalingNorm, + registry, + actualEntity.HydraulicLocationCalculationCollectionEntity4); + AssertHydraulicLocationCalculationCollectionEntity(expectedFailureMechanism.WaterLevelCalculationsForMechanismSpecificFactorizedSignalingNorm, + registry, + actualEntity.HydraulicLocationCalculationCollectionEntity5); + } + + private static void SetHydraulicBoundaryLocationCalculationInputsOfFailureMechanism(GrassCoverErosionOutwardsFailureMechanism failureMechanism) + { + SetHydraulicBoundaryLocationCalculationInputs(failureMechanism.WaterLevelCalculationsForMechanismSpecificFactorizedSignalingNorm, 1); + SetHydraulicBoundaryLocationCalculationInputs(failureMechanism.WaterLevelCalculationsForMechanismSpecificSignalingNorm, 2); + SetHydraulicBoundaryLocationCalculationInputs(failureMechanism.WaterLevelCalculationsForMechanismSpecificLowerLimitNorm, 3); + + SetHydraulicBoundaryLocationCalculationInputs(failureMechanism.WaveHeightCalculationsForMechanismSpecificFactorizedSignalingNorm, 4); + SetHydraulicBoundaryLocationCalculationInputs(failureMechanism.WaveHeightCalculationsForMechanismSpecificSignalingNorm, 5); + SetHydraulicBoundaryLocationCalculationInputs(failureMechanism.WaveHeightCalculationsForMechanismSpecificLowerLimitNorm, 6); + } + + private static void SetHydraulicBoundaryLocationCalculationInputs(IEnumerable calculations, + int seed) + { + var random = new Random(seed); + foreach (HydraulicBoundaryLocationCalculation calculation in calculations) + { + calculation.InputParameters.ShouldIllustrationPointsBeCalculated = random.NextBoolean(); + } + } + + private static void AssertHydraulicLocationCalculationCollectionEntity(IEnumerable expectedCalculations, + PersistenceRegistry registry, + HydraulicLocationCalculationCollectionEntity actualCollectionEntity) + { + Assert.IsNotNull(actualCollectionEntity); + + HydraulicBoundaryLocationCalculation[] expectedCalculationsArray = expectedCalculations.ToArray(); + ICollection hydraulicLocationCalculationEntities = actualCollectionEntity.HydraulicLocationCalculationEntities; + Assert.AreEqual(expectedCalculationsArray.Length, hydraulicLocationCalculationEntities.Count); + + var i = 0; + foreach (HydraulicLocationCalculationEntity actualCalculationEntity in hydraulicLocationCalculationEntities) + { + HydraulicBoundaryLocationCalculation expectedCalculation = expectedCalculationsArray[i]; + HydraulicBoundaryLocation expectedLocation = expectedCalculation.HydraulicBoundaryLocation; + Assert.AreSame(registry.Get(expectedLocation), actualCalculationEntity.HydraulicLocationEntity); + + Assert.AreEqual(Convert.ToByte(expectedCalculation.InputParameters.ShouldIllustrationPointsBeCalculated), + actualCalculationEntity.ShouldIllustrationPointsBeCalculated); + i++; + } + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionOutwards/GrassCoverErosionOutwardsFailureMechanismSectionResultCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionOutwards/GrassCoverErosionOutwardsFailureMechanismSectionResultCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionOutwards/GrassCoverErosionOutwardsFailureMechanismSectionResultCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,91 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.AssemblyTool.Data; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.GrassCoverErosionOutwards.Data; +using Riskeer.Storage.Core.Create.GrassCoverErosionOutwards; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.GrassCoverErosionOutwards +{ + [TestFixture] + public class GrassCoverErosionOutwardsFailureMechanismSectionResultCreateExtensionsTest + { + [Test] + public void Create_SectionResultNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((GrassCoverErosionOutwardsFailureMechanismSectionResult) null).Create(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("result", exception.ParamName); + } + + [Test] + public void Create_WithDifferentResults_ReturnsEntityWithExpectedResults() + { + // Setup + var random = new Random(21); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResultForFactorizedSignalingNorm = random.NextEnumValue(); + var detailedAssessmentResultForSignalingNorm = random.NextEnumValue(); + var detailedAssessmentResultForMechanismSpecificLowerLimitNorm = random.NextEnumValue(); + var detailedAssessmentResultForLowerLimitNorm = random.NextEnumValue(); + var detailedAssessmentResultForFactorizedLowerLimitNorm = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + bool useManualAssembly = random.NextBoolean(); + var manualAssemblyCategoryGroup = random.NextEnumValue(); + + var sectionResult = new GrassCoverErosionOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + SimpleAssessmentResult = simpleAssessmentResult, + DetailedAssessmentResultForFactorizedSignalingNorm = detailedAssessmentResultForFactorizedSignalingNorm, + DetailedAssessmentResultForSignalingNorm = detailedAssessmentResultForSignalingNorm, + DetailedAssessmentResultForMechanismSpecificLowerLimitNorm = detailedAssessmentResultForMechanismSpecificLowerLimitNorm, + DetailedAssessmentResultForLowerLimitNorm = detailedAssessmentResultForLowerLimitNorm, + DetailedAssessmentResultForFactorizedLowerLimitNorm = detailedAssessmentResultForFactorizedLowerLimitNorm, + TailorMadeAssessmentResult = tailorMadeAssessmentResult, + UseManualAssembly = useManualAssembly, + ManualAssemblyCategoryGroup = manualAssemblyCategoryGroup + }; + + // Call + GrassCoverErosionOutwardsSectionResultEntity entity = sectionResult.Create(); + + // Assert + Assert.AreEqual(Convert.ToByte(simpleAssessmentResult), entity.SimpleAssessmentResult); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResultForFactorizedSignalingNorm), entity.DetailedAssessmentResultForFactorizedSignalingNorm); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResultForSignalingNorm), entity.DetailedAssessmentResultForSignalingNorm); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResultForMechanismSpecificLowerLimitNorm), entity.DetailedAssessmentResultForMechanismSpecificLowerLimitNorm); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResultForLowerLimitNorm), entity.DetailedAssessmentResultForLowerLimitNorm); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResultForFactorizedLowerLimitNorm), entity.DetailedAssessmentResultForFactorizedLowerLimitNorm); + Assert.AreEqual(Convert.ToByte(tailorMadeAssessmentResult), entity.TailorMadeAssessmentResult); + Assert.AreEqual(Convert.ToByte(useManualAssembly), entity.UseManualAssembly); + Assert.AreEqual(Convert.ToByte(manualAssemblyCategoryGroup), entity.ManualAssemblyCategoryGroup); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionOutwards/GrassCoverErosionOutwardsWaveConditionsCalculationCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionOutwards/GrassCoverErosionOutwardsWaveConditionsCalculationCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionOutwards/GrassCoverErosionOutwardsWaveConditionsCalculationCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,238 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Data; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.GrassCoverErosionOutwards.Data; +using Ringtoets.Revetment.Data; +using Ringtoets.Revetment.Data.TestUtil; +using Ringtoets.Storage.Core.TestUtil.Hydraulics; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.GrassCoverErosionOutwards; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.GrassCoverErosionOutwards +{ + [TestFixture] + public class GrassCoverErosionOutwardsWaveConditionsCalculationCreateExtensionsTest + { + [Test] + public void Create_CalculationNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((GrassCoverErosionOutwardsWaveConditionsCalculation) null).Create(new PersistenceRegistry(), 0); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("calculation", exception.ParamName); + } + + [Test] + public void Create_PersistenceRegistryNull_ThrowArgumentNullException() + { + // Setup + var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation(); + + // Call + TestDelegate call = () => calculation.Create(null, 0); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual(paramName, "registry"); + } + + [Test] + public void Create_CalculationWithPropertiesSet_ReturnCalculationEntity() + { + // Setup + var random = new Random(21); + int order = random.Next(); + + var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation + { + InputParameters = + { + Orientation = random.NextRoundedDouble(0, 360), + UseBreakWater = random.NextBoolean(), + UseForeshore = random.NextBoolean(), + UpperBoundaryRevetment = (RoundedDouble) 6.10, + LowerBoundaryRevetment = (RoundedDouble) 3.58, + UpperBoundaryWaterLevels = (RoundedDouble) 5.88, + LowerBoundaryWaterLevels = (RoundedDouble) 3.40, + StepSize = random.NextEnumValue(), + CategoryType = random.NextEnumValue() + } + }; + + var registry = new PersistenceRegistry(); + + // Call + GrassCoverErosionOutwardsWaveConditionsCalculationEntity entity = calculation.Create(registry, order); + + // Assert + FailureMechanismCategoryWaveConditionsInput input = calculation.InputParameters; + Assert.AreEqual(input.Orientation, entity.Orientation, input.Orientation.GetAccuracy()); + Assert.AreEqual(Convert.ToByte(input.UseBreakWater), entity.UseBreakWater); + Assert.AreEqual(Convert.ToByte(input.UseForeshore), entity.UseForeshore); + Assert.AreEqual(input.UpperBoundaryRevetment, entity.UpperBoundaryRevetment, input.UpperBoundaryRevetment.GetAccuracy()); + Assert.AreEqual(input.LowerBoundaryRevetment, entity.LowerBoundaryRevetment, input.LowerBoundaryRevetment.GetAccuracy()); + Assert.AreEqual(input.UpperBoundaryWaterLevels, entity.UpperBoundaryWaterLevels, input.UpperBoundaryWaterLevels.GetAccuracy()); + Assert.AreEqual(input.LowerBoundaryWaterLevels, entity.LowerBoundaryWaterLevels, input.LowerBoundaryWaterLevels.GetAccuracy()); + Assert.AreEqual(Convert.ToByte(input.StepSize), entity.StepSize); + Assert.AreEqual(Convert.ToByte(input.CategoryType), entity.CategoryType); + + Assert.AreEqual(order, entity.Order); + Assert.IsNull(entity.CalculationGroupEntity); + CollectionAssert.IsEmpty(entity.GrassCoverErosionOutwardsWaveConditionsOutputEntities); + Assert.IsNull(entity.ForeshoreProfileEntity); + Assert.IsNull(entity.HydraulicLocationEntity); + } + + [Test] + public void Create_CalculationWithNaNProperties_ReturnCalculationEntity() + { + // Setup + var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation + { + InputParameters = + { + Orientation = RoundedDouble.NaN, + UpperBoundaryRevetment = RoundedDouble.NaN, + LowerBoundaryRevetment = RoundedDouble.NaN, + UpperBoundaryWaterLevels = RoundedDouble.NaN, + LowerBoundaryWaterLevels = RoundedDouble.NaN, + BreakWater = + { + Height = RoundedDouble.NaN + } + } + }; + + var registry = new PersistenceRegistry(); + + // Call + GrassCoverErosionOutwardsWaveConditionsCalculationEntity entity = calculation.Create(registry, 1234); + + // Assert + Assert.IsNull(entity.Orientation); + Assert.IsNull(entity.UpperBoundaryRevetment); + Assert.IsNull(entity.LowerBoundaryRevetment); + Assert.IsNull(entity.UpperBoundaryWaterLevels); + Assert.IsNull(entity.LowerBoundaryWaterLevels); + Assert.IsNull(entity.BreakWaterHeight); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string name = "A"; + const string comments = "B"; + var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation + { + Name = name, + Comments = + { + Body = comments + } + }; + + var registry = new PersistenceRegistry(); + + // Call + GrassCoverErosionOutwardsWaveConditionsCalculationEntity entity = calculation.Create(registry, 0); + + // Assert + TestHelper.AssertAreEqualButNotSame(calculation.Name, entity.Name); + TestHelper.AssertAreEqualButNotSame(calculation.Comments.Body, entity.Comments); + } + + [Test] + public void Create_GrassCoverErosionOutwardsHydraulicLocationEntity_EntityHasGrassCoverErosionOutwardsHydraulicLocationEntity() + { + // Setup + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "A", 2.3, 4.5); + + var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation + } + }; + + HydraulicLocationEntity hydraulicLocationEntity = HydraulicLocationEntityTestFactory.CreateHydraulicLocationEntity(); + var registry = new PersistenceRegistry(); + registry.Register(hydraulicLocationEntity, hydraulicBoundaryLocation); + + // Call + GrassCoverErosionOutwardsWaveConditionsCalculationEntity entity = calculation.Create(registry, 0); + + // Assert + Assert.AreSame(hydraulicLocationEntity, entity.HydraulicLocationEntity); + } + + [Test] + public void Create_HasForeshoreProfile_EntityHasForeshoreProfileEntity() + { + // Setup + var registry = new PersistenceRegistry(); + var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation + { + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile() + } + }; + + // Call + GrassCoverErosionOutwardsWaveConditionsCalculationEntity entity = calculation.Create(registry, 0); + + // Assert + Assert.IsNotNull(entity.ForeshoreProfileEntity); + } + + [Test] + public void Create_HasCalculationOutput_EntityHasCalculationOutputEntity() + { + // Setup + var registry = new PersistenceRegistry(); + var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation + { + Output = new GrassCoverErosionOutwardsWaveConditionsOutput(new[] + { + new TestWaveConditionsOutput() + }) + }; + + // Call + GrassCoverErosionOutwardsWaveConditionsCalculationEntity entity = calculation.Create(registry, 0); + + // Assert + Assert.AreEqual(1, entity.GrassCoverErosionOutwardsWaveConditionsOutputEntities.Count); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionOutwards/GrassCoverErosionOutwardsWaveConditionsOutputCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionOutwards/GrassCoverErosionOutwardsWaveConditionsOutputCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverErosionOutwards/GrassCoverErosionOutwardsWaveConditionsOutputCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,84 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Revetment.Data; +using Ringtoets.Revetment.Data.TestUtil; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.GrassCoverErosionOutwards +{ + [TestFixture] + public class GrassCoverErosionOutwardsWaveConditionsOutputCreateExtensionsTest + { + [Test] + public void Create_AllOutputValuesSet_ReturnEntity() + { + // Setup + var output = new TestWaveConditionsOutput(); + const int order = 22; + + // Call + GrassCoverErosionOutwardsWaveConditionsOutputEntity entity = output.CreateGrassCoverErosionOutwardsWaveConditionsOutputEntity(order); + + // Assert + Assert.AreEqual(output.WaterLevel, entity.WaterLevel, output.WaterLevel.GetAccuracy()); + Assert.AreEqual(output.WaveHeight, entity.WaveHeight, output.WaveHeight.GetAccuracy()); + Assert.AreEqual(output.WavePeakPeriod, entity.WavePeakPeriod, output.WavePeakPeriod.GetAccuracy()); + Assert.AreEqual(output.WaveAngle, entity.WaveAngle, output.WaveAngle.GetAccuracy()); + Assert.AreEqual(output.WaveDirection, entity.WaveDirection, output.WaveDirection.GetAccuracy()); + Assert.AreEqual(output.TargetProbability, entity.TargetProbability); + Assert.AreEqual(output.TargetReliability, entity.TargetReliability, output.TargetReliability.GetAccuracy()); + Assert.AreEqual(output.CalculatedProbability, entity.CalculatedProbability); + Assert.AreEqual(output.CalculatedReliability, entity.CalculatedReliability, output.CalculatedReliability.GetAccuracy()); + Assert.AreEqual(output.CalculationConvergence, (CalculationConvergence) entity.CalculationConvergence); + + Assert.IsNull(entity.GrassCoverErosionOutwardsWaveConditionsCalculationEntity); + } + + [Test] + public void Create_AllOutputValuesNaN_ReturnEntityWithNullValues() + { + // Setup + var output = new WaveConditionsOutput(double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, + double.NaN, double.NaN, double.NaN, CalculationConvergence.NotCalculated); + + // Call + GrassCoverErosionOutwardsWaveConditionsOutputEntity entity = output.CreateGrassCoverErosionOutwardsWaveConditionsOutputEntity(1); + + // Assert + Assert.IsNull(entity.WaterLevel); + Assert.IsNull(entity.WaveHeight); + Assert.IsNull(entity.WavePeakPeriod); + Assert.IsNull(entity.WaveAngle); + Assert.IsNull(entity.WaveDirection); + Assert.IsNull(entity.TargetProbability); + Assert.IsNull(entity.TargetReliability); + Assert.IsNull(entity.CalculatedProbability); + Assert.IsNull(entity.CalculatedReliability); + + Assert.IsNull(entity.GrassCoverErosionOutwardsWaveConditionsCalculationEntity); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverSlipOffInwards/GrassCoverSlipOffInwardsFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverSlipOffInwards/GrassCoverSlipOffInwardsFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverSlipOffInwards/GrassCoverSlipOffInwardsFailureMechanismCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,154 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Integration.Data.StandAlone; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.GrassCoverSlipOffInwards; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.GrassCoverSlipOffInwards +{ + [TestFixture] + public class GrassCoverSlipOffInwardsFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new GrassCoverSlipOffInwardsFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet(bool isRelevant) + { + // Setup + var failureMechanism = new GrassCoverSlipOffInwardsFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.GrassRevetmentSlidingInwards, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + var failureMechanism = new GrassCoverSlipOffInwardsFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + TestHelper.AssertAreEqualButNotSame(failureMechanism.InputComments.Body, entity.InputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.OutputComments.Body, entity.OutputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new GrassCoverSlipOffInwardsFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + Assert.IsNull(entity.FailureMechanismSectionCollectionSourcePath); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + const string filePath = "failureMechanismSections/file/path"; + var failureMechanism = new GrassCoverSlipOffInwardsFailureMechanism(); + failureMechanism.SetSections(new[] + { + FailureMechanismSectionTestFactory.CreateFailureMechanismSection() + }, filePath); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.GrassCoverSlipOffInwardsSectionResultEntities).Count()); + TestHelper.AssertAreEqualButNotSame(filePath, entity.FailureMechanismSectionCollectionSourcePath); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverSlipOffInwards/GrassCoverSlipOffInwardsFailureMechanismSectionResultCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverSlipOffInwards/GrassCoverSlipOffInwardsFailureMechanismSectionResultCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverSlipOffInwards/GrassCoverSlipOffInwardsFailureMechanismSectionResultCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,78 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.Integration.Data.StandAlone.SectionResults; +using Riskeer.Storage.Core.Create.GrassCoverSlipOffInwards; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.GrassCoverSlipOffInwards +{ + [TestFixture] + public class GrassCoverSlipOffInwardsFailureMechanismSectionResultCreateExtensionsTest + { + [Test] + public void Create_SectionResultNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((GrassCoverSlipOffInwardsFailureMechanismSectionResult) null).Create(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("result", exception.ParamName); + } + + [Test] + public void Create_WithDifferentResults_ReturnsEntityWithExpectedResults() + { + // Setup + var random = new Random(39); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResult = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + bool useManualAssembly = random.NextBoolean(); + var manualAssemblyCategoryGroup = random.NextEnumValue(); + + var sectionResult = new GrassCoverSlipOffInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + SimpleAssessmentResult = simpleAssessmentResult, + DetailedAssessmentResult = detailedAssessmentResult, + TailorMadeAssessmentResult = tailorMadeAssessmentResult, + UseManualAssembly = useManualAssembly, + ManualAssemblyCategoryGroup = manualAssemblyCategoryGroup + }; + + // Call + GrassCoverSlipOffInwardsSectionResultEntity entity = sectionResult.Create(); + + // Assert + Assert.AreEqual(Convert.ToByte(simpleAssessmentResult), entity.SimpleAssessmentResult); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResult), entity.DetailedAssessmentResult); + Assert.AreEqual(Convert.ToByte(tailorMadeAssessmentResult), entity.TailorMadeAssessmentResult); + Assert.AreEqual(Convert.ToByte(useManualAssembly), entity.UseManualAssembly); + Assert.AreEqual(Convert.ToByte(manualAssemblyCategoryGroup), entity.ManualAssemblyCategoryGroup); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverSlipOffOutwards/GrassCoverSlipOffOutwardsFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverSlipOffOutwards/GrassCoverSlipOffOutwardsFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverSlipOffOutwards/GrassCoverSlipOffOutwardsFailureMechanismCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,154 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Integration.Data.StandAlone; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.GrassCoverSlipOffOutwards; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.GrassCoverSlipOffOutwards +{ + [TestFixture] + public class GrassCoverSlipOffOutwardsFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new GrassCoverSlipOffOutwardsFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet(bool isRelevant) + { + // Setup + var failureMechanism = new GrassCoverSlipOffOutwardsFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.GrassRevetmentSlidingOutwards, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + var failureMechanism = new GrassCoverSlipOffOutwardsFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + TestHelper.AssertAreEqualButNotSame(failureMechanism.InputComments.Body, entity.InputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.OutputComments.Body, entity.OutputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new GrassCoverSlipOffOutwardsFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + Assert.IsNull(failureMechanism.FailureMechanismSectionSourcePath); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + const string filePath = "failureMechanismSections/file/path"; + var failureMechanism = new GrassCoverSlipOffOutwardsFailureMechanism(); + failureMechanism.SetSections(new[] + { + FailureMechanismSectionTestFactory.CreateFailureMechanismSection() + }, filePath); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.GrassCoverSlipOffOutwardsSectionResultEntities).Count()); + TestHelper.AssertAreEqualButNotSame(filePath, entity.FailureMechanismSectionCollectionSourcePath); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverSlipOffOutwards/GrassCoverSlipOffOutwardsFailureMechanismSectionResultCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverSlipOffOutwards/GrassCoverSlipOffOutwardsFailureMechanismSectionResultCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/GrassCoverSlipOffOutwards/GrassCoverSlipOffOutwardsFailureMechanismSectionResultCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,78 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.Integration.Data.StandAlone.SectionResults; +using Riskeer.Storage.Core.Create.GrassCoverSlipOffOutwards; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.GrassCoverSlipOffOutwards +{ + [TestFixture] + public class GrassCoverSlipOffOutwardsFailureMechanismSectionResultCreateExtensionsTest + { + [Test] + public void Create_SectionResultNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((GrassCoverSlipOffOutwardsFailureMechanismSectionResult) null).Create(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("result", exception.ParamName); + } + + [Test] + public void Create_WithDifferentResults_ReturnsEntityWithExpectedResults() + { + // Setup + var random = new Random(39); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResult = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + bool useManualAssembly = random.NextBoolean(); + var manualAssemblyCategoryGroup = random.NextEnumValue(); + + var sectionResult = new GrassCoverSlipOffOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + SimpleAssessmentResult = simpleAssessmentResult, + DetailedAssessmentResult = detailedAssessmentResult, + TailorMadeAssessmentResult = tailorMadeAssessmentResult, + UseManualAssembly = useManualAssembly, + ManualAssemblyCategoryGroup = manualAssemblyCategoryGroup + }; + + // Call + GrassCoverSlipOffOutwardsSectionResultEntity entity = sectionResult.Create(); + + // Assert + Assert.AreEqual(Convert.ToByte(simpleAssessmentResult), entity.SimpleAssessmentResult); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResult), entity.DetailedAssessmentResult); + Assert.AreEqual(Convert.ToByte(tailorMadeAssessmentResult), entity.TailorMadeAssessmentResult); + Assert.AreEqual(Convert.ToByte(useManualAssembly), entity.UseManualAssembly); + Assert.AreEqual(Convert.ToByte(manualAssemblyCategoryGroup), entity.ManualAssemblyCategoryGroup); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/HeightStructures/HeightStructureCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/HeightStructures/HeightStructureCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/HeightStructures/HeightStructureCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,172 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.HeightStructures.Data; +using Ringtoets.HeightStructures.Data.TestUtil; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.HeightStructures; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.HeightStructures +{ + [TestFixture] + public class HeightStructureCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowArgumentNullException() + { + // Setup + HeightStructure structure = new TestHeightStructure(); + + // Call + TestDelegate call = () => structure.Create(null, 0); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + public void Create_ValidStructure_ReturnEntity() + { + // Setup + HeightStructure structure = new TestHeightStructure(); + var registry = new PersistenceRegistry(); + + const int order = 4; + + // Call + HeightStructureEntity entity = structure.Create(registry, order); + + // Assert + Assert.AreEqual(structure.Name, entity.Name); + Assert.AreNotSame(structure.Name, entity.Name); + Assert.AreEqual(structure.Id, entity.Id); + Assert.AreNotSame(structure.Id, entity.Id); + Assert.AreEqual(structure.Location.X, entity.X); + Assert.AreEqual(structure.Location.Y, entity.Y); + Assert.AreEqual(structure.StructureNormalOrientation.Value, entity.StructureNormalOrientation); + Assert.AreEqual(structure.AllowedLevelIncreaseStorage.Mean.Value, entity.AllowedLevelIncreaseStorageMean); + Assert.AreEqual(structure.AllowedLevelIncreaseStorage.StandardDeviation.Value, entity.AllowedLevelIncreaseStorageStandardDeviation); + Assert.AreEqual(structure.CriticalOvertoppingDischarge.Mean.Value, entity.CriticalOvertoppingDischargeMean); + Assert.AreEqual(structure.CriticalOvertoppingDischarge.CoefficientOfVariation.Value, entity.CriticalOvertoppingDischargeCoefficientOfVariation); + Assert.AreEqual(structure.FailureProbabilityStructureWithErosion, entity.FailureProbabilityStructureWithErosion); + Assert.AreEqual(structure.FlowWidthAtBottomProtection.Mean.Value, entity.FlowWidthAtBottomProtectionMean); + Assert.AreEqual(structure.FlowWidthAtBottomProtection.StandardDeviation.Value, entity.FlowWidthAtBottomProtectionStandardDeviation); + Assert.AreEqual(structure.LevelCrestStructure.Mean.Value, entity.LevelCrestStructureMean); + Assert.AreEqual(structure.LevelCrestStructure.StandardDeviation.Value, entity.LevelCrestStructureStandardDeviation); + Assert.AreEqual(structure.StorageStructureArea.Mean.Value, entity.StorageStructureAreaMean); + Assert.AreEqual(structure.StorageStructureArea.CoefficientOfVariation.Value, entity.StorageStructureAreaCoefficientOfVariation); + Assert.AreEqual(structure.WidthFlowApertures.Mean.Value, entity.WidthFlowAperturesMean); + Assert.AreEqual(structure.WidthFlowApertures.StandardDeviation.Value, entity.WidthFlowAperturesStandardDeviation); + Assert.AreEqual(order, entity.Order); + + Assert.IsTrue(registry.Contains(structure)); + } + + [Test] + public void Create_NaNValue_ReturnEntityWithNullValue() + { + // Setup + var structure = new HeightStructure(new HeightStructure.ConstructionProperties + { + Name = "A", + Id = "B", + Location = new Point2D(double.NaN, double.NaN), + StructureNormalOrientation = RoundedDouble.NaN, + AllowedLevelIncreaseStorage = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + CriticalOvertoppingDischarge = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + FailureProbabilityStructureWithErosion = double.NaN, + FlowWidthAtBottomProtection = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + LevelCrestStructure = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + StorageStructureArea = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + WidthFlowApertures = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + } + }); + var registry = new PersistenceRegistry(); + + // Call + HeightStructureEntity entity = structure.Create(registry, 0); + + // Assert + Assert.IsNull(entity.X); + Assert.IsNull(entity.Y); + Assert.IsNull(entity.StructureNormalOrientation); + Assert.IsNull(entity.AllowedLevelIncreaseStorageMean); + Assert.IsNull(entity.AllowedLevelIncreaseStorageStandardDeviation); + Assert.IsNull(entity.CriticalOvertoppingDischargeMean); + Assert.IsNull(entity.CriticalOvertoppingDischargeCoefficientOfVariation); + Assert.IsNull(entity.FailureProbabilityStructureWithErosion); + Assert.IsNull(entity.FlowWidthAtBottomProtectionMean); + Assert.IsNull(entity.FlowWidthAtBottomProtectionStandardDeviation); + Assert.IsNull(entity.LevelCrestStructureMean); + Assert.IsNull(entity.LevelCrestStructureStandardDeviation); + Assert.IsNull(entity.StorageStructureAreaMean); + Assert.IsNull(entity.StorageStructureAreaCoefficientOfVariation); + Assert.IsNull(entity.WidthFlowAperturesMean); + Assert.IsNull(entity.WidthFlowAperturesStandardDeviation); + } + + [Test] + public void Create_StructureAlreadyRegistered_ReturnRegisteredEntity() + { + // Setup + var structure = new TestHeightStructure(); + + var registeredEntity = new HeightStructureEntity(); + var registry = new PersistenceRegistry(); + registry.Register(registeredEntity, structure); + + // Call + HeightStructureEntity entity = structure.Create(registry, 0); + + // Assert + Assert.AreSame(registeredEntity, entity); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/HeightStructures/HeightStructuresFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/HeightStructures/HeightStructuresFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/HeightStructures/HeightStructuresFailureMechanismCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,277 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.HeightStructures.Data; +using Ringtoets.HeightStructures.Data.TestUtil; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.HeightStructures; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.HeightStructures +{ + [TestFixture] + public class HeightStructuresFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new HeightStructuresFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet(bool isRelevant) + { + // Setup + var failureMechanism = new HeightStructuresFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + }, + GeneralInput = + { + N = new Random().NextRoundedDouble(1, 20) + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.StructureHeight, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + + HeightStructuresFailureMechanismMetaEntity metaEntity = entity.HeightStructuresFailureMechanismMetaEntities.First(); + Assert.AreEqual(failureMechanism.GeneralInput.N, metaEntity.N); + Assert.AreEqual(failureMechanism.HeightStructures.SourcePath, metaEntity.HeightStructureCollectionSourcePath); + Assert.AreEqual(failureMechanism.ForeshoreProfiles.SourcePath, metaEntity.ForeshoreProfileCollectionSourcePath); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + var failureMechanism = new HeightStructuresFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + TestHelper.AssertAreEqualButNotSame(failureMechanism.InputComments.Body, entity.InputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.OutputComments.Body, entity.OutputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new HeightStructuresFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + Assert.IsNull(entity.FailureMechanismSectionCollectionSourcePath); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + const string filePath = "failureMechanismSections/file/path"; + var failureMechanism = new HeightStructuresFailureMechanism(); + failureMechanism.SetSections(new[] + { + FailureMechanismSectionTestFactory.CreateFailureMechanismSection() + }, filePath); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.HeightStructuresSectionResultEntities).Count()); + TestHelper.AssertAreEqualButNotSame(failureMechanism.FailureMechanismSectionSourcePath, entity.FailureMechanismSectionCollectionSourcePath); + } + + [Test] + public void Create_WithForeshoreProfiles_ForeshoreProfileEntitiesCreated() + { + // Setup + var profile = new TestForeshoreProfile(); + + var failureMechanism = new HeightStructuresFailureMechanism(); + const string filePath = "some/path/to/foreshoreProfiles"; + failureMechanism.ForeshoreProfiles.AddRange(new[] + { + profile + }, filePath); + + var persistenceRegistry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(persistenceRegistry); + + // Assert + Assert.AreEqual(1, entity.ForeshoreProfileEntities.Count); + Assert.IsTrue(persistenceRegistry.Contains(profile)); + + HeightStructuresFailureMechanismMetaEntity metaEntity = + entity.HeightStructuresFailureMechanismMetaEntities.Single(); + string metaEntityForeshoreProfileCollectionSourcePath = metaEntity.ForeshoreProfileCollectionSourcePath; + TestHelper.AssertAreEqualButNotSame(filePath, metaEntityForeshoreProfileCollectionSourcePath); + } + + [Test] + public void Create_WithoutHeightStructures_EmptyHeightStructureEntities() + { + // Setup + var failureMechanism = new HeightStructuresFailureMechanism(); + + var persistenceRegistry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(persistenceRegistry); + + // Assert + Assert.AreEqual(0, entity.HeightStructureEntities.Count); + + HeightStructuresFailureMechanismMetaEntity metaEntity = + entity.HeightStructuresFailureMechanismMetaEntities.Single(); + Assert.IsNull(metaEntity.HeightStructureCollectionSourcePath); + } + + [Test] + public void Create_WithHeightStructures_HeightStructureEntitiesCreated() + { + // Setup + HeightStructure structure = new TestHeightStructure(); + + var failureMechanism = new HeightStructuresFailureMechanism(); + const string filePath = "some/path/to/structures"; + failureMechanism.HeightStructures.AddRange(new[] + { + structure + }, filePath); + + var persistenceRegistry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(persistenceRegistry); + + // Assert + Assert.AreEqual(1, entity.HeightStructureEntities.Count); + Assert.IsTrue(persistenceRegistry.Contains(structure)); + + HeightStructuresFailureMechanismMetaEntity metaEntity = + entity.HeightStructuresFailureMechanismMetaEntities.Single(); + string metaEntityHeightStructureCollectionSourcePath = metaEntity.HeightStructureCollectionSourcePath; + TestHelper.AssertAreEqualButNotSame(filePath, metaEntityHeightStructureCollectionSourcePath); + } + + [Test] + public void Create_WithCalculationGroup_ReturnFailureMechanismEntityWithCalculationGroupEntities() + { + // Setup + var failureMechanism = new HeightStructuresFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(new CalculationGroup + { + Name = "A" + }); + failureMechanism.CalculationsGroup.Children.Add(new CalculationGroup + { + Name = "B" + }); + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(failureMechanism.CalculationsGroup.Name, entity.CalculationGroupEntity.Name); + Assert.AreEqual(0, entity.CalculationGroupEntity.Order); + + CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity.CalculationGroupEntity1 + .OrderBy(cge => cge.Order) + .ToArray(); + Assert.AreEqual(2, childGroupEntities.Length); + CalculationGroupEntity childGroupEntity1 = childGroupEntities[0]; + Assert.AreEqual("A", childGroupEntity1.Name); + Assert.AreEqual(0, childGroupEntity1.Order); + CalculationGroupEntity childGroupEntity2 = childGroupEntities[1]; + Assert.AreEqual("B", childGroupEntity2.Name); + Assert.AreEqual(1, childGroupEntity2.Order); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/HeightStructures/HeightStructuresFailureMechanismSectionResultCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/HeightStructures/HeightStructuresFailureMechanismSectionResultCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/HeightStructures/HeightStructuresFailureMechanismSectionResultCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,137 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.HeightStructures.Data; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.HeightStructures; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.HeightStructures +{ + [TestFixture] + public class HeightStructuresFailureMechanismSectionResultCreateExtensionsTest + { + [Test] + public void Create_FailureMechanismSectionResultNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => HeightStructuresFailureMechanismSectionResultCreateExtensions.Create(null, new PersistenceRegistry()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("result", exception.ParamName); + } + + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var sectionResult = new HeightStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + TestDelegate test = () => sectionResult.Create(null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("registry", exception.ParamName); + } + + [Test] + public void Create_WithDifferentResults_ReturnsEntityWithExpectedResults() + { + // Setup + var random = new Random(21); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResult = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + double tailorMadeAssessmentProbability = random.NextDouble(); + bool useManualAssembly = random.NextBoolean(); + double manualAssemblyProbability = random.NextDouble(); + + var sectionResult = new HeightStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + SimpleAssessmentResult = simpleAssessmentResult, + DetailedAssessmentResult = detailedAssessmentResult, + TailorMadeAssessmentResult = tailorMadeAssessmentResult, + TailorMadeAssessmentProbability = tailorMadeAssessmentProbability, + UseManualAssembly = useManualAssembly, + ManualAssemblyProbability = manualAssemblyProbability + }; + + // Call + HeightStructuresSectionResultEntity entity = sectionResult.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(Convert.ToByte(simpleAssessmentResult), entity.SimpleAssessmentResult); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResult), entity.DetailedAssessmentResult); + Assert.AreEqual(Convert.ToByte(tailorMadeAssessmentResult), entity.TailorMadeAssessmentResult); + Assert.AreEqual(tailorMadeAssessmentProbability, entity.TailorMadeAssessmentProbability); + Assert.AreEqual(Convert.ToByte(useManualAssembly), entity.UseManualAssembly); + Assert.AreEqual(manualAssemblyProbability, entity.ManualAssemblyProbability); + Assert.IsNull(entity.HeightStructuresCalculationEntityId); + } + + [Test] + public void Create_SectionResultWithNaNValues_ReturnsEntityWithExpectedResults() + { + // Setup + var sectionResult = new HeightStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + TailorMadeAssessmentProbability = double.NaN, + ManualAssemblyProbability = double.NaN + }; + + // Call + HeightStructuresSectionResultEntity entity = sectionResult.Create(new PersistenceRegistry()); + + // Assert + Assert.IsNull(entity.TailorMadeAssessmentProbability); + Assert.IsNull(entity.ManualAssemblyProbability); + } + + [Test] + public void Create_CalculationSet_ReturnEntityWithCalculationEntity() + { + // Setup + var calculation = new StructuresCalculation(); + var sectionResult = new HeightStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + Calculation = calculation + }; + + var registry = new PersistenceRegistry(); + var calculationEntity = new HeightStructuresCalculationEntity(); + registry.Register(calculationEntity, calculation); + + // Call + HeightStructuresSectionResultEntity entity = sectionResult.Create(registry); + + // Assert + Assert.AreSame(calculationEntity, entity.HeightStructuresCalculationEntity); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/HydraulicBoundaryLocationCalculationCollectionCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/HydraulicBoundaryLocationCalculationCollectionCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/HydraulicBoundaryLocationCalculationCollectionCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,102 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create +{ + [TestFixture] + public class HydraulicBoundaryLocationCalculationCollectionCreateExtensionsTest + { + [Test] + public void Create_CalculationsNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => + ((IEnumerable) null).Create(new PersistenceRegistry()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("calculations", exception.ParamName); + } + + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + IEnumerable calculations = + Enumerable.Empty(); + + // Call + TestDelegate call = () => calculations.Create(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("registry", exception.ParamName); + } + + [Test] + public void Create_WithValidCollection_ReturnsEntityWithExpectedResults() + { + // Setup + var random = new Random(21); + + var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + var calculation = new HydraulicBoundaryLocationCalculation(hydraulicBoundaryLocation) + { + InputParameters = + { + ShouldIllustrationPointsBeCalculated = random.NextBoolean() + } + }; + + var calculationCollection = new ObservableList + { + calculation + }; + + var hydraulicLocationEntity = new HydraulicLocationEntity(); + var registry = new PersistenceRegistry(); + registry.Register(hydraulicLocationEntity, hydraulicBoundaryLocation); + + // Call + HydraulicLocationCalculationCollectionEntity entity = calculationCollection.Create(registry); + + // Assert + Assert.IsNotNull(entity); + + HydraulicLocationCalculationEntity hydraulicLocationCalculationEntity = entity.HydraulicLocationCalculationEntities.Single(); + Assert.AreSame(hydraulicLocationEntity, hydraulicLocationCalculationEntity.HydraulicLocationEntity); + Assert.AreEqual(Convert.ToByte(calculation.InputParameters.ShouldIllustrationPointsBeCalculated), + hydraulicLocationCalculationEntity.ShouldIllustrationPointsBeCalculated); + CollectionAssert.IsEmpty(hydraulicLocationCalculationEntity.HydraulicLocationOutputEntities); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/HydraulicBoundaryLocationCalculationCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/HydraulicBoundaryLocationCalculationCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/HydraulicBoundaryLocationCalculationCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,153 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create +{ + [TestFixture] + public class HydraulicBoundaryLocationCalculationCreateExtensionsTest + { + [Test] + public void Create_RegistryNull_ThrowsArgumentNullException() + { + // Setup + var calculation = new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation()); + + // Call + TestDelegate call = () => calculation.Create(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("registry", exception.ParamName); + } + + [Test] + public void Create_CalculationNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((HydraulicBoundaryLocationCalculation) null).Create(new PersistenceRegistry()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("calculation", exception.ParamName); + } + + [Test] + public void Create_CalculationWithoutOutput_ReturnsHydraulicLocationCalculationEntity() + { + // Setup + var random = new Random(33); + bool shouldIllustrationPointsBeCalculated = random.NextBoolean(); + + var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + var calculation = new HydraulicBoundaryLocationCalculation(hydraulicBoundaryLocation) + { + InputParameters = + { + ShouldIllustrationPointsBeCalculated = shouldIllustrationPointsBeCalculated + }, + Output = null + }; + + var registry = new PersistenceRegistry(); + var hydraulicLocationEntity = new HydraulicLocationEntity(); + registry.Register(hydraulicLocationEntity, hydraulicBoundaryLocation); + + // Call + HydraulicLocationCalculationEntity entity = calculation.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(Convert.ToByte(shouldIllustrationPointsBeCalculated), entity.ShouldIllustrationPointsBeCalculated); + Assert.IsEmpty(entity.HydraulicLocationOutputEntities); + } + + [Test] + public void Create_CalculationWithOutput_ReturnsHydraulicLocationCalculationEntityWithOutput() + { + // Setup + var random = new Random(33); + bool shouldIllustrationPointsBeCalculated = random.NextBoolean(); + + var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + var calculation = new HydraulicBoundaryLocationCalculation(hydraulicBoundaryLocation) + { + InputParameters = + { + ShouldIllustrationPointsBeCalculated = shouldIllustrationPointsBeCalculated + }, + Output = new HydraulicBoundaryLocationCalculationOutput( + random.NextDouble(), random.NextDouble(), random.NextDouble(), random.NextDouble(), + random.NextDouble(), random.NextEnumValue(), + null) + }; + + var registry = new PersistenceRegistry(); + var hydraulicLocationEntity = new HydraulicLocationEntity(); + registry.Register(hydraulicLocationEntity, hydraulicBoundaryLocation); + + // Call + HydraulicLocationCalculationEntity entity = calculation.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(Convert.ToByte(shouldIllustrationPointsBeCalculated), entity.ShouldIllustrationPointsBeCalculated); + + HydraulicLocationOutputEntity outputEntity = entity.HydraulicLocationOutputEntities.Single(); + + HydraulicBoundaryLocationCalculationOutput expectedOutput = calculation.Output; + Assert.AreEqual(expectedOutput.CalculatedProbability, outputEntity.CalculatedProbability); + Assert.AreEqual(expectedOutput.CalculatedReliability, outputEntity.CalculatedReliability); + Assert.AreEqual(expectedOutput.TargetReliability, outputEntity.TargetReliability); + Assert.AreEqual(expectedOutput.TargetProbability, outputEntity.TargetProbability); + Assert.IsNull(outputEntity.GeneralResultSubMechanismIllustrationPointEntity); + Assert.AreEqual(Convert.ToByte(expectedOutput.CalculationConvergence), outputEntity.CalculationConvergence); + } + + [Test] + public void Create_CalculationWithAlreadyCreatedHydraulicBoundaryLocation_ReturnsEntityWithHydraulicBoundaryLocationEntity() + { + // Setup + var hydraulicLocation = new TestHydraulicBoundaryLocation(); + + var registry = new PersistenceRegistry(); + var hydraulicLocationEntity = new HydraulicLocationEntity(); + registry.Register(hydraulicLocationEntity, hydraulicLocation); + + var calculation = new HydraulicBoundaryLocationCalculation(hydraulicLocation); + + // Call + HydraulicLocationCalculationEntity entity = calculation.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreSame(hydraulicLocationEntity, entity.HydraulicLocationEntity); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/HydraulicBoundaryLocationCalculationOutputCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/HydraulicBoundaryLocationCalculationOutputCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/HydraulicBoundaryLocationCalculationOutputCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,151 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Data.TestUtil.IllustrationPoints; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create +{ + [TestFixture] + public class HydraulicBoundaryLocationCalculationOutputCreateExtensionsTest + { + [Test] + public void CreateHydraulicLocationOutputEntity_HydraulicBoundaryLocationCalculationOutputNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((HydraulicBoundaryLocationCalculationOutput) null).CreateHydraulicLocationOutputEntity(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("output", exception.ParamName); + } + + [Test] + public void CreateHydraulicLocationOutputEntity_WithValidParameters_ReturnsHydraulicLocationEntityWithOutputSet() + { + // Setup + var random = new Random(21); + var output = new HydraulicBoundaryLocationCalculationOutput( + random.NextDouble(), random.NextDouble(), random.NextDouble(), random.NextDouble(), + random.NextDouble(), random.NextEnumValue(), null); + + // Call + HydraulicLocationOutputEntity entity = output.CreateHydraulicLocationOutputEntity(); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(output.Result, entity.Result, output.Result.GetAccuracy()); + Assert.AreEqual(output.TargetProbability, entity.TargetProbability); + Assert.AreEqual(output.TargetReliability, entity.TargetReliability, output.TargetReliability.GetAccuracy()); + Assert.AreEqual(output.CalculatedProbability, entity.CalculatedProbability); + Assert.AreEqual(output.CalculatedReliability, entity.CalculatedReliability, output.CalculatedReliability.GetAccuracy()); + Assert.AreEqual((byte) output.CalculationConvergence, entity.CalculationConvergence); + + AssertGeneralResult(output.GeneralResult, entity.GeneralResultSubMechanismIllustrationPointEntity); + } + + [Test] + public void CreateHydraulicLocationOutputEntity_WithNaNParameters_ReturnsHydraulicLocationEntityWithOutputNaN() + { + // Setup + var random = new Random(21); + var output = new HydraulicBoundaryLocationCalculationOutput(double.NaN, double.NaN, double.NaN, + double.NaN, double.NaN, random.NextEnumValue(), null); + + // Call + HydraulicLocationOutputEntity entity = output.CreateHydraulicLocationOutputEntity(); + + // Assert + Assert.IsNotNull(entity); + Assert.IsNull(entity.Result); + Assert.IsNull(entity.TargetProbability); + Assert.IsNull(entity.TargetReliability); + Assert.IsNull(entity.CalculatedProbability); + Assert.IsNull(entity.CalculatedReliability); + Assert.AreEqual((byte) output.CalculationConvergence, entity.CalculationConvergence); + + AssertGeneralResult(output.GeneralResult, entity.GeneralResultSubMechanismIllustrationPointEntity); + } + + [Test] + public void CreateHydraulicLocationOutputEntity_WithGeneralResult_ReturnsHydraulicLocationEntityWithGeneralResult() + { + // Setup + var random = new Random(21); + var output = new HydraulicBoundaryLocationCalculationOutput(double.NaN, double.NaN, double.NaN, + double.NaN, double.NaN, random.NextEnumValue(), + GetGeneralResult()); + + // Call + HydraulicLocationOutputEntity entity = output.CreateHydraulicLocationOutputEntity(); + + // Assert + AssertGeneralResult(output.GeneralResult, entity.GeneralResultSubMechanismIllustrationPointEntity); + } + + private static GeneralResult GetGeneralResult() + { + var random = new Random(55); + var generalResult = new GeneralResult( + WindDirectionTestFactory.CreateTestWindDirection(), + new[] + { + new Stochast("stochastOne", random.NextDouble(), random.NextDouble()) + }, + new[] + { + new TopLevelSubMechanismIllustrationPoint(WindDirectionTestFactory.CreateTestWindDirection(), + "IllustrationPointTwo", + new TestSubMechanismIllustrationPoint()) + }); + + return generalResult; + } + + private static void AssertGeneralResult(GeneralResult illustrationPoint, + GeneralResultSubMechanismIllustrationPointEntity entity) + { + if (illustrationPoint == null) + { + Assert.IsNull(entity); + return; + } + + Assert.IsNotNull(entity); + WindDirection governingWindDirection = illustrationPoint.GoverningWindDirection; + TestHelper.AssertAreEqualButNotSame(governingWindDirection.Name, entity.GoverningWindDirectionName); + Assert.AreEqual(governingWindDirection.Angle, entity.GoverningWindDirectionAngle, + governingWindDirection.Angle.GetAccuracy()); + + Assert.AreEqual(illustrationPoint.Stochasts.Count(), entity.StochastEntities.Count); + Assert.AreEqual(illustrationPoint.TopLevelIllustrationPoints.Count(), + entity.TopLevelSubMechanismIllustrationPointEntities.Count); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/HydraulicBoundaryLocationCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/HydraulicBoundaryLocationCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/HydraulicBoundaryLocationCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,121 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create +{ + [TestFixture] + public class HydraulicBoundaryLocationCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(-1, "testName", 2, 3); + + // Call + TestDelegate test = () => hydraulicBoundaryLocation.Create(null, 0); + + // Assert + string parameterName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", parameterName); + } + + [Test] + public void Create_HydraulicBoundaryLocationNull_ThrowsArgumentNullException() + { + // Setup + var random = new Random(21); + + // Call + TestDelegate call = () => ((HydraulicBoundaryLocation) null).Create(new PersistenceRegistry(), random.Next()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("location", exception.ParamName); + } + + [Test] + public void Create_WithPersistenceRegistry_ReturnsHydraulicLocationEntityWithPropertiesSet() + { + // Setup + const string testName = "testName"; + var random = new Random(21); + double coordinateX = random.NextDouble(); + double coordinateY = random.NextDouble(); + int id = random.Next(0, 150); + int order = random.Next(); + + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(id, testName, coordinateX, coordinateY); + var registry = new PersistenceRegistry(); + + // Call + HydraulicLocationEntity entity = hydraulicBoundaryLocation.Create(registry, order); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(id, entity.LocationId); + Assert.AreEqual(testName, entity.Name); + Assert.AreEqual(coordinateX, entity.LocationX); + Assert.AreEqual(coordinateY, entity.LocationY); + Assert.AreEqual(order, entity.Order); + } + + [Test] + public void Create_StringPropertiesDoNotShareReferences() + { + // Setup + const string testName = "original name"; + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, testName, 0, 0); + var registry = new PersistenceRegistry(); + + // Call + HydraulicLocationEntity entity = hydraulicBoundaryLocation.Create(registry, 0); + + // Assert + Assert.IsNotNull(entity); + Assert.AreNotSame(testName, entity.Name, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(testName, entity.Name); + } + + [Test] + public void Create_HydraulicBoundaryLocationSavedMultipleTimes_ReturnSameEntity() + { + // Setup + var hydraulicBoundaryLocations = new HydraulicBoundaryLocation(1, "A", 1.1, 2.2); + + var registry = new PersistenceRegistry(); + + // Call + HydraulicLocationEntity entity1 = hydraulicBoundaryLocations.Create(registry, 0); + HydraulicLocationEntity entity2 = hydraulicBoundaryLocations.Create(registry, 1); + + // Assert + Assert.AreSame(entity1, entity2); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/HydraulicLocationConfigurationSettingsCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/HydraulicLocationConfigurationSettingsCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/HydraulicLocationConfigurationSettingsCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,86 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create +{ + [TestFixture] + public class HydraulicLocationConfigurationSettingsCreateExtensionsTest + { + [Test] + public void Create_HydraulicBoundaryDatabaseNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((HydraulicBoundaryDatabase) null).Create(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("hydraulicBoundaryDatabase", exception.ParamName); + } + + [Test] + public void Create_ValidHydraulicBoundaryDatabase_ReturnsHydraulicBoundaryDatabaseEntity() + { + // Setup + var random = new Random(21); + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = "hydraulicBoundaryDatabasefilePath", + Version = "Version" + }; + hydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings.SetValues("hlcdFilePath", + "ScenarioName", + random.Next(), + "Scope", + "SeaLevel", + "RiverDischarge", + "LakeLevel", + "WindDirection", + "WindSpeed", + "Comment"); + + // Call + HydraulicBoundaryDatabaseEntity entity = hydraulicBoundaryDatabase.Create(); + + // Assert + TestHelper.AssertAreEqualButNotSame(hydraulicBoundaryDatabase.FilePath, entity.FilePath); + TestHelper.AssertAreEqualButNotSame(hydraulicBoundaryDatabase.Version, entity.Version); + + HydraulicLocationConfigurationSettings settings = hydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings; + TestHelper.AssertAreEqualButNotSame(settings.FilePath, entity.HydraulicLocationConfigurationSettingsFilePath); + TestHelper.AssertAreEqualButNotSame(settings.ScenarioName, entity.HydraulicLocationConfigurationSettingsScenarioName); + TestHelper.AssertAreEqualButNotSame(settings.Year, entity.HydraulicLocationConfigurationSettingsYear); + TestHelper.AssertAreEqualButNotSame(settings.Scope, entity.HydraulicLocationConfigurationSettingsScope); + TestHelper.AssertAreEqualButNotSame(settings.SeaLevel, entity.HydraulicLocationConfigurationSettingsSeaLevel); + TestHelper.AssertAreEqualButNotSame(settings.RiverDischarge, entity.HydraulicLocationConfigurationSettingsRiverDischarge); + TestHelper.AssertAreEqualButNotSame(settings.LakeLevel, entity.HydraulicLocationConfigurationSettingsLakeLevel); + TestHelper.AssertAreEqualButNotSame(settings.WindDirection, entity.HydraulicLocationConfigurationSettingsWindDirection); + TestHelper.AssertAreEqualButNotSame(settings.WindSpeed, entity.HydraulicLocationConfigurationSettingsWindSpeed); + TestHelper.AssertAreEqualButNotSame(settings.Comment, entity.HydraulicLocationConfigurationSettingsComment); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/IllustrationPoints/GeneralResultCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/IllustrationPoints/GeneralResultCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/IllustrationPoints/GeneralResultCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,320 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Data.TestUtil.IllustrationPoints; +using Riskeer.Storage.Core.Create.IllustrationPoints; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.IllustrationPoints +{ + [TestFixture] + public class GeneralResultCreateExtensionsTest + { + [Test] + public void CreateGeneralResultSubMechanismIllustrationPointEntity_GeneralResultNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((GeneralResult) null) + .CreateGeneralResultSubMechanismIllustrationPointEntity(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("generalResult", exception.ParamName); + } + + [Test] + public void CreateGeneralResultSubMechanismIllustrationPointEntity_ValidGeneralResult_ReturnsEntityWithoutStochastsAndTopLevelSubMechanismIllustrationPointEntities() + { + // Setup + var random = new Random(21); + + var generalResult = new GeneralResult( + new WindDirection("SSE", random.NextDouble()), + Enumerable.Empty(), + Enumerable.Empty()); + + // Call + GeneralResultSubMechanismIllustrationPointEntity entity = + generalResult.CreateGeneralResultSubMechanismIllustrationPointEntity(); + + // Assert + AssertGeneralResultSubMechanismIllustrationPointEntity(generalResult, entity); + } + + [Test] + public void CreateGeneralResultSubMechanismIllustrationPointEntity_ValidGeneralResultWithStochasts_ReturnsEntityWithStochastsEntities() + { + // Setup + var random = new Random(21); + + var generalResult = new GeneralResult( + new WindDirection("SSE", random.NextDouble()), + new[] + { + new Stochast("stochastOne", random.NextDouble(), random.NextDouble()), + new Stochast("stochastTwo", random.NextDouble(), random.NextDouble()) + }, + Enumerable.Empty()); + + // Call + GeneralResultSubMechanismIllustrationPointEntity entity = + generalResult.CreateGeneralResultSubMechanismIllustrationPointEntity(); + + // Assert + AssertGeneralResultSubMechanismIllustrationPointEntity(generalResult, entity); + } + + [Test] + public void CreateGeneralResultSubMechanismIllustrationPointEntity_ValidGeneralResultWithIllustrationPoints_ReturnsEntityWithTopLevelSubMechanismIllustrationPointEntities() + { + // Setup + var random = new Random(21); + + var generalResult = new GeneralResult( + new WindDirection("SSE", random.NextDouble()), + Enumerable.Empty(), + new[] + { + new TopLevelSubMechanismIllustrationPoint(WindDirectionTestFactory.CreateTestWindDirection(), + "IllustrationPointOne", + new TestSubMechanismIllustrationPoint()), + new TopLevelSubMechanismIllustrationPoint(WindDirectionTestFactory.CreateTestWindDirection(), + "IllustrationPointTwo", + new TestSubMechanismIllustrationPoint()) + }); + + // Call + GeneralResultSubMechanismIllustrationPointEntity entity = + generalResult.CreateGeneralResultSubMechanismIllustrationPointEntity(); + + // Assert + AssertGeneralResultSubMechanismIllustrationPointEntity(generalResult, entity); + } + + [Test] + public void CreateGeneralResultFaultTreeIllustrationPointEntity_GeneralResultNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((GeneralResult) null) + .CreateGeneralResultFaultTreeIllustrationPointEntity(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("generalResult", exception.ParamName); + } + + [Test] + public void CreateGeneralResultFaultTreeIllustrationPointEntity_ValidGeneralResult_ReturnsExpectedGeneralResultFaultTreeIllustrationPointEntity() + { + // Setup + var random = new Random(21); + + var generalResult = new GeneralResult( + new WindDirection("SSE", random.NextDouble()), + Enumerable.Empty(), + Enumerable.Empty()); + + // Call + GeneralResultFaultTreeIllustrationPointEntity entity = + generalResult.CreateGeneralResultFaultTreeIllustrationPointEntity(); + + // Assert + AssertGeneralResultFaultTreeIllustrationPointEntity(generalResult, entity); + } + + [Test] + public void CreateGeneralResultFaultTreeIllustrationPointEntity_ValidGeneralResultWithStochasts_ReturnsEntityWithStochastsEntities() + { + // Setup + var random = new Random(22); + + var generalResult = new GeneralResult( + new WindDirection("SSE", random.NextDouble()), + new[] + { + new Stochast("stochastOne", random.NextDouble(), random.NextDouble()), + new Stochast("stochastTwo", random.NextDouble(), random.NextDouble()) + }, + Enumerable.Empty()); + + // Call + GeneralResultFaultTreeIllustrationPointEntity entity = + generalResult.CreateGeneralResultFaultTreeIllustrationPointEntity(); + + // Assert + AssertGeneralResultFaultTreeIllustrationPointEntity(generalResult, entity); + } + + [Test] + public void CreateGeneralResultFaultTreeIllustrationPointEntity_ValidGeneralResultsWithIllustrationPoints_ReturnsEntityWithTopLevelFaultTreeIllustrationPointEntities() + { + // Setup + var random = new Random(22); + + var generalResult = new GeneralResult( + new WindDirection("SSE", random.NextDouble()), + Enumerable.Empty(), + new[] + { + new TopLevelFaultTreeIllustrationPoint( + WindDirectionTestFactory.CreateTestWindDirection(), + "IllustrationPointOne", + new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPoint())), + new TopLevelFaultTreeIllustrationPoint( + WindDirectionTestFactory.CreateTestWindDirection(), + "IllustrationPointTwo", + new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPoint())) + }); + + // Call + GeneralResultFaultTreeIllustrationPointEntity entity = + generalResult.CreateGeneralResultFaultTreeIllustrationPointEntity(); + + // Assert + AssertGeneralResultFaultTreeIllustrationPointEntity(generalResult, entity); + } + + private static void AssertGeneralResultSubMechanismIllustrationPointEntity( + GeneralResult generalResult, + GeneralResultSubMechanismIllustrationPointEntity entity) + { + AssertWindDirection(generalResult.GoverningWindDirection, entity); + + AssertStochastEntities(generalResult.Stochasts.ToArray(), entity.StochastEntities.ToArray()); + + AssertTopLevelIllustrationPointEntities(generalResult.TopLevelIllustrationPoints.ToArray(), + entity.TopLevelSubMechanismIllustrationPointEntities.ToArray()); + } + + private static void AssertGeneralResultFaultTreeIllustrationPointEntity( + GeneralResult generalResult, + GeneralResultFaultTreeIllustrationPointEntity entity) + { + AssertWindDirection(generalResult.GoverningWindDirection, entity); + + AssertStochastEntities(generalResult.Stochasts.ToArray(), entity.StochastEntities.ToArray()); + + AssertTopLevelIllustrationPointEntities(generalResult.TopLevelIllustrationPoints.ToArray(), + entity.TopLevelFaultTreeIllustrationPointEntities.ToArray()); + } + + private static void AssertWindDirection(WindDirection expectedWindDirection, + IGeneralResultEntity entity) + { + TestHelper.AssertAreEqualButNotSame(expectedWindDirection.Name, entity.GoverningWindDirectionName); + Assert.AreEqual(expectedWindDirection.Angle, entity.GoverningWindDirectionAngle, + expectedWindDirection.Angle.GetAccuracy()); + } + + private static void AssertStochastEntities(Stochast[] stochasts, StochastEntity[] stochastEntities) + { + Assert.AreEqual(stochasts.Length, stochastEntities.Length); + + for (var i = 0; i < stochasts.Length; i++) + { + AssertStochastEntity(stochasts[i], stochastEntities[i], i); + } + } + + private static void AssertStochastEntity(Stochast stochast, + StochastEntity stochastEntity, + int expectedOrder) + { + TestHelper.AssertAreEqualButNotSame(stochast.Name, stochastEntity.Name); + Assert.AreEqual(stochast.Duration, stochastEntity.Duration, stochast.Duration.GetAccuracy()); + Assert.AreEqual(stochast.Alpha, stochastEntity.Alpha, stochast.Alpha.GetAccuracy()); + + Assert.AreEqual(expectedOrder, stochastEntity.Order); + } + + private static void AssertTopLevelIllustrationPointEntities( + TTopLevelIllustrationPoint[] illustrationPoints, + TopLevelSubMechanismIllustrationPointEntity[] illustrationPointEntities) + where TTopLevelIllustrationPoint : TopLevelIllustrationPointBase + { + Assert.AreEqual(illustrationPoints.Length, illustrationPointEntities.Length); + + for (var i = 0; i < illustrationPoints.Length; i++) + { + AssertTopLevelIllustrationPointEntity(illustrationPoints[i], + illustrationPointEntities[i], + i); + } + } + + private static void AssertTopLevelIllustrationPointEntity( + TTopLevelIllustrationPoint illustrationPoint, + TopLevelSubMechanismIllustrationPointEntity illustrationPointEntity, + int expectedOrder) + where TTopLevelIllustrationPoint : TopLevelIllustrationPointBase + { + TestHelper.AssertAreEqualButNotSame(illustrationPoint.ClosingSituation, + illustrationPointEntity.ClosingSituation); + + WindDirection expectedWindDirection = illustrationPoint.WindDirection; + TestHelper.AssertAreEqualButNotSame(expectedWindDirection.Name, illustrationPointEntity.WindDirectionName); + Assert.AreEqual(expectedWindDirection.Angle, illustrationPointEntity.WindDirectionAngle, + expectedWindDirection.Angle.GetAccuracy()); + TestHelper.AssertAreEqualButNotSame(illustrationPoint.ClosingSituation, illustrationPointEntity.ClosingSituation); + + Assert.AreEqual(expectedOrder, illustrationPointEntity.Order); + } + + private static void AssertTopLevelIllustrationPointEntities( + TTopLevelIllustrationPoint[] illustrationPoints, + TopLevelFaultTreeIllustrationPointEntity[] illustrationPointEntities) + where TTopLevelIllustrationPoint : TopLevelIllustrationPointBase + { + Assert.AreEqual(illustrationPoints.Length, illustrationPointEntities.Length); + + for (var i = 0; i < illustrationPoints.Length; i++) + { + AssertTopLevelIllustrationPointEntity(illustrationPoints[i], + illustrationPointEntities[i], + i); + } + } + + private static void AssertTopLevelIllustrationPointEntity( + TTopLevelIllustrationPoint illustrationPoint, + TopLevelFaultTreeIllustrationPointEntity illustrationPointEntity, + int expectedOrder) + where TTopLevelIllustrationPoint : TopLevelIllustrationPointBase + { + TestHelper.AssertAreEqualButNotSame(illustrationPoint.ClosingSituation, + illustrationPointEntity.ClosingSituation); + + WindDirection expectedWindDirection = illustrationPoint.WindDirection; + TestHelper.AssertAreEqualButNotSame(expectedWindDirection.Name, illustrationPointEntity.WindDirectionName); + Assert.AreEqual(expectedWindDirection.Angle, illustrationPointEntity.WindDirectionAngle, + expectedWindDirection.Angle.GetAccuracy()); + TestHelper.AssertAreEqualButNotSame(illustrationPoint.ClosingSituation, illustrationPointEntity.ClosingSituation); + + Assert.AreEqual(expectedOrder, illustrationPointEntity.Order); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/IllustrationPoints/IllustrationPointNodeCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/IllustrationPoints/IllustrationPointNodeCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/IllustrationPoints/IllustrationPointNodeCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,251 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Data.TestUtil.IllustrationPoints; +using Riskeer.Storage.Core.Create.IllustrationPoints; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.IllustrationPoints +{ + [TestFixture] + public class IllustrationPointNodeCreateExtensionsTest + { + [Test] + public void Create_IllustrationPointNodeNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((IllustrationPointNode) null).Create(0); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("illustrationPointNode", exception.ParamName); + } + + [Test] + public void Create_IllustrationPointNodeWithFaultTreeIllustrationPoint_ReturnFaultTreeIllustrationPointEntity() + { + // Setup + var random = new Random(21); + + var illustrationPoint = new FaultTreeIllustrationPoint("Illustration point name", + random.NextDouble(), + Enumerable.Empty(), + random.NextEnumValue()); + int order = random.Next(); + + var node = new IllustrationPointNode(illustrationPoint); + + // Call + FaultTreeIllustrationPointEntity entity = node.Create(order); + + // Assert + Assert.IsNull(entity.ParentFaultTreeIllustrationPointEntityId); + TestHelper.AssertAreEqualButNotSame(illustrationPoint.Name, entity.Name); + Assert.AreEqual(illustrationPoint.Beta, entity.Beta, illustrationPoint.Beta.GetAccuracy()); + byte expectedCombinationType = Convert.ToByte(illustrationPoint.CombinationType); + Assert.AreEqual(expectedCombinationType, entity.CombinationType); + CollectionAssert.IsEmpty(entity.FaultTreeIllustrationPointEntity1); + CollectionAssert.IsEmpty(entity.StochastEntities); + CollectionAssert.IsEmpty(entity.SubMechanismIllustrationPointEntities); + CollectionAssert.IsEmpty(entity.TopLevelFaultTreeIllustrationPointEntities); + Assert.AreEqual(order, entity.Order); + } + + [Test] + public void Create_IllustrationPointNodeWithFaultTreeIllustrationPointAndStochast_ReturnFaultTreeIllustrationPointEntity() + { + // Setup + var random = new Random(21); + + var illustrationPoint = new FaultTreeIllustrationPoint( + "Illustration point name", + random.NextDouble(), + new[] + { + new Stochast("Stochast", + random.NextDouble(), + random.NextDouble()) + }, + random.NextEnumValue()); + int order = random.Next(); + + var node = new IllustrationPointNode(illustrationPoint); + + // Call + FaultTreeIllustrationPointEntity entity = node.Create(order); + + // Assert + Assert.IsNull(entity.ParentFaultTreeIllustrationPointEntityId); + TestHelper.AssertAreEqualButNotSame(illustrationPoint.Name, entity.Name); + Assert.AreEqual(illustrationPoint.Beta, entity.Beta, illustrationPoint.Beta.GetAccuracy()); + byte expectedCombinationType = Convert.ToByte(illustrationPoint.CombinationType); + Assert.AreEqual(expectedCombinationType, entity.CombinationType); + CollectionAssert.IsEmpty(entity.FaultTreeIllustrationPointEntity1); + CollectionAssert.IsEmpty(entity.SubMechanismIllustrationPointEntities); + CollectionAssert.IsEmpty(entity.TopLevelFaultTreeIllustrationPointEntities); + Assert.AreEqual(order, entity.Order); + + StochastEntity entityStochastEntity = entity.StochastEntities.Single(); + Stochast stochast = illustrationPoint.Stochasts.First(); + Assert.AreEqual(stochast.Name, entityStochastEntity.Name); + Assert.AreEqual(stochast.Alpha, entityStochastEntity.Alpha); + Assert.AreEqual(stochast.Duration, entityStochastEntity.Duration); + } + + [Test] + public void Create_IllustrationPointNodeWithSubMechanismIllustrationPoint_ThrowsNotSupportedException() + { + // Setup + var node = new IllustrationPointNode(new TestSubMechanismIllustrationPoint()); + + // Call + TestDelegate call = () => node.Create(0); + + // Assert + string message = Assert.Throws(call).Message; + Assert.AreEqual($"Illustration point type '{typeof(TestSubMechanismIllustrationPoint)}' is not supported.", message); + } + + [Test] + [TestCaseSource(nameof(GetValidIllustrationPointNodes))] + public void Create_IllustrationPointNodeWithValidChildren_ReturnFaultTreeIllustrationPointEntity( + IEnumerable children) + { + // Setup + var random = new Random(21); + + var illustrationPoint = new FaultTreeIllustrationPoint("Illustration point name A", + random.NextDouble(), + Enumerable.Empty(), + random.NextEnumValue()); + int order = random.Next(); + + var node = new IllustrationPointNode(illustrationPoint); + node.SetChildren(children.ToArray()); + + // Call + FaultTreeIllustrationPointEntity entity = node.Create(order); + + // Assert + AssertFaultTreeIllustrationPointEntity(illustrationPoint, entity); + AssertIllustrationPointEntities(node.Children.ToArray(), + entity.SubMechanismIllustrationPointEntities.ToArray(), + entity.FaultTreeIllustrationPointEntity1.ToArray()); + + Assert.AreEqual(order, entity.Order); + } + + private static IEnumerable GetValidIllustrationPointNodes() + { + yield return new TestCaseData(new List + { + new IllustrationPointNode(new TestSubMechanismIllustrationPoint("A")), + new IllustrationPointNode(new TestSubMechanismIllustrationPoint("B")) + }).SetName("SubMechanismIllustrationPoints"); + + yield return new TestCaseData(new List + { + new IllustrationPointNode(new TestSubMechanismIllustrationPoint("A")), + new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPointCombinationTypeAnd("B")) + }).SetName("SubMechanismAndFaultTreeIllustrationPoints"); + + yield return new TestCaseData(new List + { + new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPointCombinationTypeAnd("A")), + new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPointCombinationTypeAnd("B")) + }).SetName("FaultTreeIllustrationPoints"); + + var node = new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPointCombinationTypeAnd("A")); + node.SetChildren(new[] + { + new IllustrationPointNode(new TestSubMechanismIllustrationPoint("B")), + new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPointCombinationTypeAnd("C")) + }); + + yield return new TestCaseData(new List + { + new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPointCombinationTypeAnd("AA")), + node + }).SetName("FaultTreeIllustrationPointsWithChildren"); + } + + private static void AssertIllustrationPointEntities( + IllustrationPointNode[] children, + IEnumerable subMechanismIllustrationPointEntities, + IEnumerable faultTreeIllustrationPointEntity + ) + { + for (var i = 0; i < children.Length; i++) + { + int nrOfTotalCreatedEntities = subMechanismIllustrationPointEntities.Count() + faultTreeIllustrationPointEntity.Count(); + Assert.AreEqual(nrOfTotalCreatedEntities, children.Length); + + IllustrationPointNode child = children[i]; + + var subMechanismIllustrationPoint = child.Data as SubMechanismIllustrationPoint; + if (subMechanismIllustrationPoint != null) + { + SubMechanismIllustrationPointEntity illustrationPointEntity = subMechanismIllustrationPointEntities.Single(s => s.Order == i); + AssertSubMechanismIllustrationPointEntity(subMechanismIllustrationPoint, illustrationPointEntity); + } + + var faultTreeIllustrationPoint = child.Data as FaultTreeIllustrationPoint; + if (faultTreeIllustrationPoint != null) + { + FaultTreeIllustrationPointEntity illustrationPointEntity = faultTreeIllustrationPointEntity.Single(f => f.Order == i); + AssertFaultTreeIllustrationPointEntity(faultTreeIllustrationPoint, illustrationPointEntity); + + AssertIllustrationPointEntities(child.Children.ToArray(), + illustrationPointEntity.SubMechanismIllustrationPointEntities.ToArray(), + illustrationPointEntity.FaultTreeIllustrationPointEntity1.ToArray()); + } + } + } + + private static void AssertSubMechanismIllustrationPointEntity(IllustrationPointBase illustrationPoint, + SubMechanismIllustrationPointEntity illustrationPointEntity) + { + Assert.IsNotNull(illustrationPoint); + Assert.AreEqual(illustrationPoint.Beta, illustrationPointEntity.Beta, illustrationPoint.Beta.GetAccuracy()); + TestHelper.AssertAreEqualButNotSame(illustrationPoint.Name, illustrationPointEntity.Name); + + CollectionAssert.IsEmpty(illustrationPointEntity.IllustrationPointResultEntities); + CollectionAssert.IsEmpty(illustrationPointEntity.SubMechanismIllustrationPointStochastEntities); + } + + private static void AssertFaultTreeIllustrationPointEntity(FaultTreeIllustrationPoint illustrationPoint, + FaultTreeIllustrationPointEntity illustrationPointEntity) + { + Assert.IsNotNull(illustrationPoint); + Assert.AreEqual(illustrationPoint.Beta, illustrationPointEntity.Beta, illustrationPoint.Beta.GetAccuracy()); + Assert.AreEqual(Convert.ToByte(illustrationPoint.CombinationType), illustrationPointEntity.CombinationType); + TestHelper.AssertAreEqualButNotSame(illustrationPoint.Name, illustrationPointEntity.Name); + CollectionAssert.IsEmpty(illustrationPointEntity.StochastEntities); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/IllustrationPoints/IllustrationPointResultCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/IllustrationPoints/IllustrationPointResultCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/IllustrationPoints/IllustrationPointResultCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,65 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.TestUtil; +using Riskeer.Storage.Core.Create.IllustrationPoints; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.IllustrationPoints +{ + [TestFixture] + public class IllustrationPointResultCreateExtensionsTest + { + [Test] + public void Create_IllustrationPointResultNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((IllustrationPointResult) null).Create(0); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("illustrationPointResult", paramName); + } + + [Test] + public void Create_ValidIllustrationPointResult_ReturnIllustrationPointResultEntity() + { + // Setup + var random = new Random(123); + var illustrationPointResult = new IllustrationPointResult("Some description", + random.NextDouble()); + int order = random.Next(); + + // Call + IllustrationPointResultEntity entity = + illustrationPointResult.Create(order); + + // Assert + TestHelper.AssertAreEqualButNotSame(illustrationPointResult.Description, entity.Description); + Assert.AreEqual(illustrationPointResult.Value, entity.Value, illustrationPointResult.Value.GetAccuracy()); + Assert.AreEqual(order, entity.Order); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/IllustrationPoints/StochastCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/IllustrationPoints/StochastCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/IllustrationPoints/StochastCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,66 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.TestUtil; +using Riskeer.Storage.Core.Create.IllustrationPoints; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.IllustrationPoints +{ + [TestFixture] + public class StochastCreateExtensionsTest + { + [Test] + public void Create_StochastNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((Stochast) null).Create(0); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("stochast", paramName); + } + + [Test] + public void Create_ValidStochast_ReturnStochastEntity() + { + // Setup + var random = new Random(123); + var stochast = new Stochast("Some description", + random.NextDouble(), + random.NextDouble()); + int order = random.Next(); + + // Call + StochastEntity entity = stochast.Create(order); + + // Assert + TestHelper.AssertAreEqualButNotSame(stochast.Name, entity.Name); + Assert.AreEqual(stochast.Alpha, entity.Alpha, stochast.Alpha.GetAccuracy()); + Assert.AreEqual(stochast.Duration, entity.Duration, stochast.Duration.GetAccuracy()); + Assert.AreEqual(order, entity.Order); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/IllustrationPoints/SubMechanismIllustrationPointCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/IllustrationPoints/SubMechanismIllustrationPointCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/IllustrationPoints/SubMechanismIllustrationPointCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,165 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.TestUtil; +using Riskeer.Storage.Core.Create.IllustrationPoints; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.IllustrationPoints +{ + [TestFixture] + public class SubMechanismIllustrationPointCreateExtensionsTest + { + [Test] + public void Create_IllustrationPointNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((SubMechanismIllustrationPoint) null).Create(0); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("subMechanismIllustrationPoint", exception.ParamName); + } + + [Test] + public void Create_SubMechanismIllustrationPointWithoutResultsAndStochasts_ReturnSubMechanismIllustrationPointEntityWithoutResultsAndStochastsEntities() + { + // Setup + var random = new Random(21); + + var illustrationPoint = new SubMechanismIllustrationPoint("Illustration point name", + random.NextDouble(), + Enumerable.Empty(), + Enumerable.Empty()); + int order = random.Next(); + + // Call + SubMechanismIllustrationPointEntity entity = illustrationPoint.Create(order); + + // Assert + AssertCommonProperties(illustrationPoint, entity); + Assert.AreEqual(order, entity.Order); + CollectionAssert.IsEmpty(entity.IllustrationPointResultEntities); + CollectionAssert.IsEmpty(entity.SubMechanismIllustrationPointStochastEntities); + } + + [Test] + public void Create_ValidIllustrationPointWithStochasts_ReturnSubMechanismIllustrationPointEntityWithStochastEntities() + { + // Setup + var random = new Random(21); + var stochastOne = new SubMechanismIllustrationPointStochast("stochast name", + random.NextDouble(), + random.NextDouble(), + random.NextDouble()); + var stochastTwo = new SubMechanismIllustrationPointStochast("Stochast name two", + random.NextDouble(), + random.NextDouble(), + random.NextDouble()); + SubMechanismIllustrationPointStochast[] stochasts = + { + stochastOne, + stochastTwo + }; + + var illustrationPoint = new SubMechanismIllustrationPoint("Illustration point name", + random.NextDouble(), + stochasts, + Enumerable.Empty()); + int order = random.Next(); + + // Call + SubMechanismIllustrationPointEntity entity = illustrationPoint.Create(order); + + // Assert + AssertCommonProperties(illustrationPoint, entity); + Assert.AreEqual(order, entity.Order); + SubMechanismIllustrationPointStochastEntity[] stochastEntities = + entity.SubMechanismIllustrationPointStochastEntities.ToArray(); + int expectedNrOfStochasts = stochasts.Length; + Assert.AreEqual(expectedNrOfStochasts, stochastEntities.Length); + for (var i = 0; i < expectedNrOfStochasts; i++) + { + SubMechanismIllustrationPointStochast stochast = stochasts[i]; + SubMechanismIllustrationPointStochastEntity stochastEntity = stochastEntities[i]; + + TestHelper.AssertAreEqualButNotSame(stochast.Name, stochastEntity.Name); + Assert.AreEqual(stochast.Duration, stochastEntity.Duration, stochast.Duration.GetAccuracy()); + Assert.AreEqual(stochast.Alpha, stochastEntity.Alpha, stochast.Alpha.GetAccuracy()); + Assert.AreEqual(stochast.Realization, stochastEntity.Realization, stochast.Realization.GetAccuracy()); + Assert.AreEqual(i, stochastEntity.Order); + } + } + + [Test] + public void Create_MultipleResultsAndValidIllustrationPoint_ReturnSubMechanismIllustrationPointEntityWithResultEntities() + { + // Setup + var random = new Random(21); + + var illustrationPointResultOne = new IllustrationPointResult("result description", random.NextDouble()); + var illustrationPointResultTwo = new IllustrationPointResult("result description two", random.NextDouble()); + IllustrationPointResult[] illustrationPointResults = + { + illustrationPointResultOne, + illustrationPointResultTwo + }; + + var illustrationPoint = new SubMechanismIllustrationPoint("Illustration point name", + random.NextDouble(), + Enumerable.Empty(), + illustrationPointResults); + int order = random.Next(); + + // Call + SubMechanismIllustrationPointEntity entity = illustrationPoint.Create(order); + + // Assert + AssertCommonProperties(illustrationPoint, entity); + Assert.AreEqual(order, entity.Order); + IllustrationPointResultEntity[] resultEntities = entity.IllustrationPointResultEntities.ToArray(); + int expectedNrOfIllustrationPoints = illustrationPointResults.Length; + Assert.AreEqual(expectedNrOfIllustrationPoints, resultEntities.Length); + for (var i = 0; i < expectedNrOfIllustrationPoints; i++) + { + IllustrationPointResult illustrationPointResult = illustrationPointResults[i]; + IllustrationPointResultEntity illustrationPointResultEntity = resultEntities[i]; + + TestHelper.AssertAreEqualButNotSame(illustrationPointResult.Description, illustrationPointResultEntity.Description); + Assert.AreEqual(illustrationPointResult.Value, illustrationPointResultEntity.Value, + illustrationPointResult.Value.GetAccuracy()); + Assert.AreEqual(i, illustrationPointResultEntity.Order); + } + } + + private static void AssertCommonProperties(SubMechanismIllustrationPoint illustrationPoint, + SubMechanismIllustrationPointEntity entity) + { + TestHelper.AssertAreEqualButNotSame(illustrationPoint.Name, entity.Name); + Assert.AreEqual(illustrationPoint.Beta, entity.Beta, illustrationPoint.Beta.GetAccuracy()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/IllustrationPoints/SubMechanismIllustrationPointStochastCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/IllustrationPoints/SubMechanismIllustrationPointStochastCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/IllustrationPoints/SubMechanismIllustrationPointStochastCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,68 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.TestUtil; +using Riskeer.Storage.Core.Create.IllustrationPoints; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.IllustrationPoints +{ + [TestFixture] + public class SubMechanismIllustrationPointStochastCreateExtensionsTest + { + [Test] + public void Create_StochastNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((SubMechanismIllustrationPointStochast) null).Create(0); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("subMechanismIllustrationPointStochast", paramName); + } + + [Test] + public void Create_ValidStochast_ReturnSubMechanismIllustrationPointStochastEntity() + { + // Setup + var random = new Random(123); + var stochast = new SubMechanismIllustrationPointStochast("Some description", + random.NextDouble(), + random.NextDouble(), + random.NextDouble()); + int order = random.Next(); + + // Call + SubMechanismIllustrationPointStochastEntity entity = stochast.Create(order); + + // Assert + TestHelper.AssertAreEqualButNotSame(stochast.Name, entity.Name); + Assert.AreEqual(stochast.Alpha, entity.Alpha, stochast.Alpha.GetAccuracy()); + Assert.AreEqual(stochast.Duration, entity.Duration, stochast.Duration.GetAccuracy()); + Assert.AreEqual(stochast.Realization, entity.Realization, stochast.Realization.GetAccuracy()); + Assert.AreEqual(order, entity.Order); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/IllustrationPoints/TopLevelFaultTreeIllustrationPointCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/IllustrationPoints/TopLevelFaultTreeIllustrationPointCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/IllustrationPoints/TopLevelFaultTreeIllustrationPointCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,120 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Data.TestUtil.IllustrationPoints; +using Riskeer.Storage.Core.Create.IllustrationPoints; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.IllustrationPoints +{ + [TestFixture] + public class TopLevelFaultTreeIllustrationPointCreateExtensionsTest + { + [Test] + public void Create_TopLevelFaultTreeIllustrationPointNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((TopLevelFaultTreeIllustrationPoint) null).Create(0); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("topLevelFaultTreeIllustrationPoint", exception.ParamName); + } + + [Test] + public void Create_ValidTopLevelFaultTreeIllustrationPoint_ReturnsTopLevelFaultTreeIllustrationPointEntity() + { + // Setup + var random = new Random(21); + + var windDirection = new WindDirection("WindDirection Name", random.NextDouble()); + var illustrationPoint = new TopLevelFaultTreeIllustrationPoint( + windDirection, + "Just a situation", + new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPoint())); + int order = random.Next(); + + // Call + TopLevelFaultTreeIllustrationPointEntity entity = illustrationPoint.Create(order); + + // Assert + TestHelper.AssertAreEqualButNotSame(illustrationPoint.ClosingSituation, entity.ClosingSituation); + TestHelper.AssertAreEqualButNotSame(windDirection.Name, entity.WindDirectionName); + Assert.AreEqual(windDirection.Angle, entity.WindDirectionAngle, windDirection.Angle.GetAccuracy()); + CollectionAssert.IsEmpty(entity.FaultTreeIllustrationPointEntity.SubMechanismIllustrationPointEntities); + CollectionAssert.IsEmpty(entity.FaultTreeIllustrationPointEntity.FaultTreeIllustrationPointEntity1); + Assert.AreEqual(order, entity.Order); + } + + [Test] + public void Create_ValidTopLevelFaultTreeIllustrationPointWithChildren_ReturnsTopLevelFaultTreeIllustrationPointEntityWithChildren() + { + // Setup + var random = new Random(21); + + var windDirection = new WindDirection("WindDirection Name", random.NextDouble()); + var illustrationPointNode = new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPoint()); + illustrationPointNode.SetChildren(new[] + { + new IllustrationPointNode(new TestSubMechanismIllustrationPoint("Point A")), + new IllustrationPointNode(new TestSubMechanismIllustrationPoint("Point B")) + }); + + var topLevelIllustrationPoint = new TopLevelFaultTreeIllustrationPoint( + windDirection, + "Just a situation", + illustrationPointNode); + int order = random.Next(); + + // Call + TopLevelFaultTreeIllustrationPointEntity entity = topLevelIllustrationPoint.Create(order); + + // Assert + TestHelper.AssertAreEqualButNotSame(topLevelIllustrationPoint.ClosingSituation, entity.ClosingSituation); + TestHelper.AssertAreEqualButNotSame(windDirection.Name, entity.WindDirectionName); + Assert.AreEqual(windDirection.Angle, entity.WindDirectionAngle, windDirection.Angle.GetAccuracy()); + Assert.AreEqual(order, entity.Order); + + SubMechanismIllustrationPointEntity[] subMechanismIllustrationPointEntities = + entity.FaultTreeIllustrationPointEntity.SubMechanismIllustrationPointEntities.ToArray(); + Assert.AreEqual(2, subMechanismIllustrationPointEntities.Length); + + for (var i = 0; i < 2; i++) + { + var expectedIllustrationPoint = new TestSubMechanismIllustrationPoint(subMechanismIllustrationPointEntities[i].Name); + SubMechanismIllustrationPointEntity illustrationPointEntity = subMechanismIllustrationPointEntities[i]; + Assert.AreEqual(expectedIllustrationPoint.Name, illustrationPointEntity.Name); + Assert.AreEqual(expectedIllustrationPoint.Beta, illustrationPointEntity.Beta, expectedIllustrationPoint.Beta.GetAccuracy()); + Assert.AreEqual(expectedIllustrationPoint.IllustrationPointResults.Count(), + illustrationPointEntity.IllustrationPointResultEntities.Count); + Assert.AreEqual(expectedIllustrationPoint.Stochasts.Count(), + illustrationPointEntity.IllustrationPointResultEntities.Count); + Assert.AreEqual(i, illustrationPointEntity.Order); + } + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/IllustrationPoints/TopLevelSubMechanismIllustrationPointCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/IllustrationPoints/TopLevelSubMechanismIllustrationPointCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/IllustrationPoints/TopLevelSubMechanismIllustrationPointCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,81 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.TestUtil; +using Riskeer.Storage.Core.Create.IllustrationPoints; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.IllustrationPoints +{ + [TestFixture] + public class TopLevelSubMechanismIllustrationPointCreateExtensionsTest + { + [Test] + public void Create_TopLevelSubMechanismIllustrationPointNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((TopLevelSubMechanismIllustrationPoint) null).Create(0); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("topLevelSubMechanismIllustrationPoint", exception.ParamName); + } + + [Test] + public void Create_ValidTopLevelSubMechanismIllustrationPoint_ReturnsEntityWithSubMechanismIllustrationPointEntity() + { + // Setup + var random = new Random(21); + var illustrationPoint = new SubMechanismIllustrationPoint("Illustration point name", + random.NextDouble(), + Enumerable.Empty(), + Enumerable.Empty()); + + var windDirection = new WindDirection("WindDirection Name", random.NextDouble()); + var topLevelSubMechanismIllustrationPoint = new TopLevelSubMechanismIllustrationPoint(windDirection, + "Just a situation", + illustrationPoint); + int order = random.Next(); + + // Call + TopLevelSubMechanismIllustrationPointEntity entity = + topLevelSubMechanismIllustrationPoint.Create(order); + + // Assert + TestHelper.AssertAreEqualButNotSame(topLevelSubMechanismIllustrationPoint.ClosingSituation, entity.ClosingSituation); + Assert.AreEqual(order, entity.Order); + + TestHelper.AssertAreEqualButNotSame(windDirection.Name, entity.WindDirectionName); + Assert.AreEqual(windDirection.Angle, entity.WindDirectionAngle, windDirection.Angle.GetAccuracy()); + + SubMechanismIllustrationPointEntity subMechanismIllustrationPointEntity = entity.SubMechanismIllustrationPointEntity; + TestHelper.AssertAreEqualButNotSame(illustrationPoint.Name, subMechanismIllustrationPointEntity.Name); + Assert.AreEqual(illustrationPoint.Beta, subMechanismIllustrationPointEntity.Beta, illustrationPoint.Beta.GetAccuracy()); + CollectionAssert.IsEmpty(subMechanismIllustrationPointEntity.IllustrationPointResultEntities); + CollectionAssert.IsEmpty(subMechanismIllustrationPointEntity.SubMechanismIllustrationPointStochastEntities); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsCalculationScenarioCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsCalculationScenarioCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsCalculationScenarioCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,394 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Data; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.MacroStabilityInwards.Data.SoilProfile; +using Ringtoets.MacroStabilityInwards.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Data.TestUtil.SoilProfile; +using Ringtoets.MacroStabilityInwards.Primitives; +using Ringtoets.Storage.Core.TestUtil.MacroStabilityInwards; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.MacroStabilityInwards; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.MacroStabilityInwards +{ + [TestFixture] + public class MacroStabilityInwardsCalculationScenarioCreateExtensionsTest + { + [Test] + public void Create_RegistryNull_ThrowsArgumentNullException() + { + // Setup + var scenario = new MacroStabilityInwardsCalculationScenario(); + + // Call + TestDelegate call = () => scenario.Create(null, 0); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("registry", exception.ParamName); + } + + [Test] + public void Create_MacroStabilityInwardsCalculationScenarioWithNaNValues_ReturnsMacroStabilityInwardsCalculationEntityWithExpectedNullProperties() + { + // Setup + var scenario = new MacroStabilityInwardsCalculationScenario + { + Contribution = RoundedDouble.NaN, + InputParameters = + { + SlipPlaneMinimumDepth = RoundedDouble.NaN, + SlipPlaneMinimumLength = RoundedDouble.NaN, + MaximumSliceWidth = RoundedDouble.NaN, + AssessmentLevel = RoundedDouble.NaN, + WaterLevelRiverAverage = RoundedDouble.NaN, + XCoordinateDrainageConstruction = RoundedDouble.NaN, + ZCoordinateDrainageConstruction = RoundedDouble.NaN, + LocationInputExtreme = + { + WaterLevelPolder = RoundedDouble.NaN, + PhreaticLineOffsetBelowDikeTopAtRiver = RoundedDouble.NaN, + PhreaticLineOffsetBelowDikeTopAtPolder = RoundedDouble.NaN, + PhreaticLineOffsetBelowShoulderBaseInside = RoundedDouble.NaN, + PhreaticLineOffsetBelowDikeToeAtPolder = RoundedDouble.NaN, + PenetrationLength = RoundedDouble.NaN + }, + LocationInputDaily = + { + WaterLevelPolder = RoundedDouble.NaN, + PhreaticLineOffsetBelowDikeTopAtRiver = RoundedDouble.NaN, + PhreaticLineOffsetBelowDikeTopAtPolder = RoundedDouble.NaN, + PhreaticLineOffsetBelowShoulderBaseInside = RoundedDouble.NaN, + PhreaticLineOffsetBelowDikeToeAtPolder = RoundedDouble.NaN + }, + LeakageLengthOutwardsPhreaticLine3 = RoundedDouble.NaN, + LeakageLengthInwardsPhreaticLine3 = RoundedDouble.NaN, + LeakageLengthOutwardsPhreaticLine4 = RoundedDouble.NaN, + LeakageLengthInwardsPhreaticLine4 = RoundedDouble.NaN, + PiezometricHeadPhreaticLine2Outwards = RoundedDouble.NaN, + PiezometricHeadPhreaticLine2Inwards = RoundedDouble.NaN, + TangentLineZTop = RoundedDouble.NaN, + TangentLineZBottom = RoundedDouble.NaN, + LeftGrid = + { + XLeft = RoundedDouble.NaN, + XRight = RoundedDouble.NaN, + ZTop = RoundedDouble.NaN, + ZBottom = RoundedDouble.NaN + }, + RightGrid = + { + XLeft = RoundedDouble.NaN, + XRight = RoundedDouble.NaN, + ZTop = RoundedDouble.NaN, + ZBottom = RoundedDouble.NaN + }, + ZoneBoundaryLeft = RoundedDouble.NaN, + ZoneBoundaryRight = RoundedDouble.NaN + } + }; + var registry = new PersistenceRegistry(); + + // When + MacroStabilityInwardsCalculationEntity entity = scenario.Create(registry, 0); + + // Assert + Assert.IsNotNull(entity); + + Assert.IsNull(entity.ScenarioContribution); + + Assert.IsNull(entity.AssessmentLevel); + Assert.IsNull(entity.SlipPlaneMinimumDepth); + Assert.IsNull(entity.SlipPlaneMinimumLength); + Assert.IsNull(entity.MaximumSliceWidth); + Assert.IsNull(entity.WaterLevelRiverAverage); + Assert.IsNull(entity.DrainageConstructionCoordinateX); + Assert.IsNull(entity.DrainageConstructionCoordinateZ); + Assert.IsNull(entity.MinimumLevelPhreaticLineAtDikeTopRiver); + Assert.IsNull(entity.MinimumLevelPhreaticLineAtDikeTopPolder); + + Assert.IsNull(entity.LocationInputExtremeWaterLevelPolder); + Assert.IsNull(entity.LocationInputExtremePhreaticLineOffsetBelowDikeTopAtPolder); + Assert.IsNull(entity.LocationInputExtremePhreaticLineOffsetBelowDikeTopAtPolder); + Assert.IsNull(entity.LocationInputExtremePhreaticLineOffsetBelowShoulderBaseInside); + Assert.IsNull(entity.LocationInputExtremePhreaticLineOffsetDikeToeAtPolder); + Assert.IsNull(entity.LocationInputExtremePenetrationLength); + + Assert.IsNull(entity.LocationInputDailyWaterLevelPolder); + Assert.IsNull(entity.LocationInputDailyPhreaticLineOffsetBelowDikeTopAtPolder); + Assert.IsNull(entity.LocationInputDailyPhreaticLineOffsetBelowDikeTopAtPolder); + Assert.IsNull(entity.LocationInputDailyPhreaticLineOffsetBelowShoulderBaseInside); + Assert.IsNull(entity.LocationInputDailyPhreaticLineOffsetDikeToeAtPolder); + + Assert.IsNull(entity.LeakageLengthOutwardsPhreaticLine3); + Assert.IsNull(entity.LeakageLengthInwardsPhreaticLine3); + Assert.IsNull(entity.LeakageLengthOutwardsPhreaticLine4); + Assert.IsNull(entity.LeakageLengthInwardsPhreaticLine4); + Assert.IsNull(entity.PiezometricHeadPhreaticLine2Outwards); + Assert.IsNull(entity.PiezometricHeadPhreaticLine2Inwards); + + Assert.IsNull(entity.TangentLineZTop); + Assert.IsNull(entity.TangentLineZBottom); + + Assert.IsNull(entity.LeftGridXLeft); + Assert.IsNull(entity.LeftGridXRight); + Assert.IsNull(entity.LeftGridZTop); + Assert.IsNull(entity.LeftGridZBottom); + + Assert.IsNull(entity.RightGridXRight); + Assert.IsNull(entity.RightGridXRight); + Assert.IsNull(entity.RightGridZTop); + Assert.IsNull(entity.RightGridZBottom); + + Assert.IsNull(entity.ZoneBoundaryLeft); + Assert.IsNull(entity.ZoneBoundaryRight); + } + + [Test] + public void Create_MacroStabilityInwardsCalculationScenarioWithNumericAndBooleanPropertiesSet_ReturnsMacroStabilityInwardsCalculationEntity() + { + // Setup + var random = new Random(21); + var scenario = new MacroStabilityInwardsCalculationScenario + { + IsRelevant = random.NextBoolean(), + Contribution = random.NextRoundedDouble(), + InputParameters = + { + UseAssessmentLevelManualInput = random.NextBoolean(), + AssessmentLevel = random.NextRoundedDouble(), + SlipPlaneMinimumDepth = random.NextRoundedDouble(), + SlipPlaneMinimumLength = random.NextRoundedDouble(), + MaximumSliceWidth = random.NextRoundedDouble(), + MoveGrid = random.NextBoolean(), + DikeSoilScenario = random.NextEnumValue(), + WaterLevelRiverAverage = random.NextRoundedDouble(), + DrainageConstructionPresent = random.NextBoolean(), + XCoordinateDrainageConstruction = random.NextRoundedDouble(), + ZCoordinateDrainageConstruction = random.NextRoundedDouble(), + MinimumLevelPhreaticLineAtDikeTopRiver = random.NextRoundedDouble(), + MinimumLevelPhreaticLineAtDikeTopPolder = random.NextRoundedDouble(), + LocationInputExtreme = + { + WaterLevelPolder = random.NextRoundedDouble(), + UseDefaultOffsets = random.NextBoolean(), + PhreaticLineOffsetBelowDikeTopAtRiver = random.NextRoundedDouble(), + PhreaticLineOffsetBelowDikeTopAtPolder = random.NextRoundedDouble(), + PhreaticLineOffsetBelowShoulderBaseInside = random.NextRoundedDouble(), + PhreaticLineOffsetBelowDikeToeAtPolder = random.NextRoundedDouble(), + PenetrationLength = random.NextRoundedDouble() + }, + LocationInputDaily = + { + WaterLevelPolder = random.NextRoundedDouble(), + UseDefaultOffsets = random.NextBoolean(), + PhreaticLineOffsetBelowDikeTopAtRiver = random.NextRoundedDouble(), + PhreaticLineOffsetBelowDikeTopAtPolder = random.NextRoundedDouble(), + PhreaticLineOffsetBelowShoulderBaseInside = random.NextRoundedDouble(), + PhreaticLineOffsetBelowDikeToeAtPolder = random.NextRoundedDouble() + }, + AdjustPhreaticLine3And4ForUplift = random.NextBoolean(), + LeakageLengthOutwardsPhreaticLine3 = random.NextRoundedDouble(), + LeakageLengthInwardsPhreaticLine3 = random.NextRoundedDouble(), + LeakageLengthOutwardsPhreaticLine4 = random.NextRoundedDouble(), + LeakageLengthInwardsPhreaticLine4 = random.NextRoundedDouble(), + PiezometricHeadPhreaticLine2Outwards = random.NextRoundedDouble(), + PiezometricHeadPhreaticLine2Inwards = random.NextRoundedDouble(), + GridDeterminationType = random.NextEnumValue(), + TangentLineDeterminationType = random.NextEnumValue(), + TangentLineZTop = random.NextRoundedDouble(2.0, 3.0), + TangentLineZBottom = random.NextRoundedDouble(0.0, 1.0), + TangentLineNumber = random.Next(1, 50), + LeftGrid = + { + XLeft = random.NextRoundedDouble(0.0, 1.0), + XRight = random.NextRoundedDouble(2.0, 3.0), + NumberOfHorizontalPoints = random.Next(1, 100), + ZTop = random.NextRoundedDouble(2.0, 3.0), + ZBottom = random.NextRoundedDouble(0.0, 1.0), + NumberOfVerticalPoints = random.Next(1, 100) + }, + RightGrid = + { + XLeft = random.NextRoundedDouble(0.0, 1.0), + XRight = random.NextRoundedDouble(), + NumberOfHorizontalPoints = random.Next(1, 100), + ZTop = random.NextRoundedDouble(2.0, 3.0), + ZBottom = random.NextRoundedDouble(0.0, 1.0), + NumberOfVerticalPoints = random.Next(1, 100) + }, + CreateZones = random.NextBoolean(), + ZoningBoundariesDeterminationType = random.NextEnumValue(), + ZoneBoundaryLeft = random.NextRoundedDouble(), + ZoneBoundaryRight = random.NextRoundedDouble() + } + }; + + var registry = new PersistenceRegistry(); + int order = random.Next(); + + // Call + MacroStabilityInwardsCalculationEntity entity = scenario.Create(registry, order); + + // Assert + Assert.IsNotNull(entity); + + MacroStabilityInwardsCalculationEntityTestHelper.AssertCalculationScenarioPropertyValues(scenario, entity); + Assert.IsNull(entity.SurfaceLineEntity); + Assert.IsNull(entity.MacroStabilityInwardsStochasticSoilProfileEntity); + Assert.IsNull(entity.HydraulicLocationEntity); + Assert.AreEqual(order, entity.Order); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string name = "Calculation name"; + const string comment = "I am a comment"; + var scenario = new MacroStabilityInwardsCalculationScenario + { + Name = name, + Comments = + { + Body = comment + } + }; + + var registry = new PersistenceRegistry(); + + // Call + MacroStabilityInwardsCalculationEntity entity = scenario.Create(registry, 0); + + // Assert + Assert.IsNotNull(entity); + TestHelper.AssertAreEqualButNotSame(name, entity.Name); + TestHelper.AssertAreEqualButNotSame(comment, entity.Comment); + } + + [Test] + public void Create_CalculationWithAlreadyRegisteredHydraulicBoundaryLocation_ReturnsEntityWithHydraulicBoundaryLocationEntity() + { + // Setup + var hydraulicLocation = new TestHydraulicBoundaryLocation(); + var scenario = new MacroStabilityInwardsCalculationScenario + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicLocation + } + }; + + var registry = new PersistenceRegistry(); + var hydraulicLocationEntity = new HydraulicLocationEntity(); + registry.Register(hydraulicLocationEntity, hydraulicLocation); + + // Call + MacroStabilityInwardsCalculationEntity entity = scenario.Create(registry, 0); + + // Assert + Assert.IsNotNull(entity); + Assert.AreSame(hydraulicLocationEntity, entity.HydraulicLocationEntity); + } + + [Test] + public void Create_CalculationWithAlreadyRegisteredSurfaceLine_ReturnsEntityWithSurfaceLineEntity() + { + // Setup + var surfaceLine = new MacroStabilityInwardsSurfaceLine(string.Empty); + var scenario = new MacroStabilityInwardsCalculationScenario + { + InputParameters = + { + SurfaceLine = surfaceLine + } + }; + + var registry = new PersistenceRegistry(); + var surfaceLineEntity = new SurfaceLineEntity(); + registry.Register(surfaceLineEntity, surfaceLine); + + // Call + MacroStabilityInwardsCalculationEntity entity = scenario.Create(registry, 0); + + // Assert + Assert.IsNotNull(entity); + Assert.AreSame(surfaceLineEntity, entity.SurfaceLineEntity); + } + + [Test] + public void Create_CalculationWithAlreadyRegisteredStochasticSoilProfile_ReturnsEntityWithStochasticSoilModelEntity() + { + // Setup + var random = new Random(21); + var stochasticSoilProfile = new MacroStabilityInwardsStochasticSoilProfile(random.NextDouble(), + MacroStabilityInwardsSoilProfile1DTestFactory.CreateMacroStabilityInwardsSoilProfile1D()); + var scenario = new MacroStabilityInwardsCalculationScenario + { + InputParameters = + { + StochasticSoilProfile = stochasticSoilProfile + } + }; + + var registry = new PersistenceRegistry(); + var stochasticSoilProfileEntity = new MacroStabilityInwardsStochasticSoilProfileEntity(); + registry.Register(stochasticSoilProfileEntity, stochasticSoilProfile); + + // Call + MacroStabilityInwardsCalculationEntity entity = scenario.Create(registry, 0); + + // Assert + Assert.IsNotNull(entity); + MacroStabilityInwardsStochasticSoilProfileEntity expectedStochasticSoilProfileEntity = registry.Get(stochasticSoilProfile); + Assert.AreSame(expectedStochasticSoilProfileEntity, entity.MacroStabilityInwardsStochasticSoilProfileEntity); + } + + [Test] + public void Create_HasMacroStabilityInwardsOutput_ReturnsEntityWithOutputEntity() + { + // Setup + var scenario = new MacroStabilityInwardsCalculationScenario + { + Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() + }; + + var registry = new PersistenceRegistry(); + + // Call + MacroStabilityInwardsCalculationEntity entity = scenario.Create(registry, 0); + + // Assert + Assert.IsNotNull(entity); + MacroStabilityInwardsCalculationOutputEntity outputEntity = entity.MacroStabilityInwardsCalculationOutputEntities.FirstOrDefault(); + Assert.IsNotNull(outputEntity); + MacroStabilityInwardsCalculationOutputEntityTestHelper.AssertOutputPropertyValues(scenario.Output, outputEntity); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsFailureMechanismCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,344 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.MacroStabilityInwards.Data.SoilProfile; +using Ringtoets.MacroStabilityInwards.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Primitives; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.MacroStabilityInwards; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.MacroStabilityInwards +{ + [TestFixture] + public class MacroStabilityInwardsFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + public void Create_WithoutAllPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.MacroStabilityInwards, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(failureMechanism.IsRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + Assert.AreEqual(failureMechanism.FailureMechanismSectionSourcePath, entity.FailureMechanismSectionCollectionSourcePath); + + CollectionAssert.IsEmpty(entity.StochasticSoilModelEntities); + MacroStabilityInwardsFailureMechanismMetaEntity failureMechanismMetaEntity = entity.MacroStabilityInwardsFailureMechanismMetaEntities.First(); + Assert.AreEqual(failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput.A, failureMechanismMetaEntity.A); + Assert.AreEqual(failureMechanism.SurfaceLines.SourcePath, failureMechanismMetaEntity.SurfaceLineCollectionSourcePath); + Assert.AreEqual(failureMechanism.StochasticSoilModels.SourcePath, failureMechanismMetaEntity.StochasticSoilModelCollectionSourcePath); + } + + [Test] + public void Create_WithPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet() + { + // Setup + var random = new Random(31); + var failureMechanism = new MacroStabilityInwardsFailureMechanism + { + IsRelevant = random.NextBoolean(), + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + }, + MacroStabilityInwardsProbabilityAssessmentInput = + { + A = random.NextDouble() + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.MacroStabilityInwards, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(failureMechanism.IsRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + + CollectionAssert.IsEmpty(entity.StochasticSoilModelEntities); + CollectionAssert.IsEmpty(entity.SurfaceLineEntities); + MacroStabilityInwardsFailureMechanismMetaEntity failureMechanismMetaEntity = entity.MacroStabilityInwardsFailureMechanismMetaEntities.First(); + Assert.AreEqual(failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput.A, failureMechanismMetaEntity.A); + Assert.AreEqual(failureMechanism.SurfaceLines.SourcePath, failureMechanismMetaEntity.SurfaceLineCollectionSourcePath); + Assert.AreEqual(failureMechanism.StochasticSoilModels.SourcePath, failureMechanismMetaEntity.StochasticSoilModelCollectionSourcePath); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism + { + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + TestHelper.AssertAreEqualButNotSame(failureMechanism.InputComments.Body, entity.InputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.OutputComments.Body, entity.OutputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithStochasticSoilModels_ReturnsFailureMechanismEntityWithStochasticSoilModelEntities() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + MacroStabilityInwardsStochasticSoilModelCollection stochasticSoilModels = failureMechanism.StochasticSoilModels; + + stochasticSoilModels.AddRange(new[] + { + MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel("name"), + MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel("name2") + }, "some/path/to/file"); + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(stochasticSoilModels.Count, entity.StochasticSoilModelEntities.Count); + for (var i = 0; i < stochasticSoilModels.Count; i++) + { + AssertStochasticSoilModel(stochasticSoilModels[i], + entity.StochasticSoilModelEntities.ElementAt(i)); + } + + string stochasticSoilModelCollectionSourcePath = entity.MacroStabilityInwardsFailureMechanismMetaEntities + .Single() + .StochasticSoilModelCollectionSourcePath; + TestHelper.AssertAreEqualButNotSame(stochasticSoilModels.SourcePath, stochasticSoilModelCollectionSourcePath); + } + + [Test] + public void Create_WithSurfaceLines_ReturnFailureMechanismEntityWithSurfaceLineEntities() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + MacroStabilityInwardsSurfaceLineCollection surfaceLines = failureMechanism.SurfaceLines; + + surfaceLines.AddRange(new[] + { + CreateSurfaceLine(new Random(31)) + }, "path"); + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(surfaceLines.Count, entity.SurfaceLineEntities.Count); + for (var i = 0; i < surfaceLines.Count; i++) + { + AssertSurfaceLine(surfaceLines[i], entity.SurfaceLineEntities.ElementAt(i)); + } + + string surfaceLineCollectionSourcePath = entity.MacroStabilityInwardsFailureMechanismMetaEntities + .Single() + .SurfaceLineCollectionSourcePath; + TestHelper.AssertAreEqualButNotSame(surfaceLines.SourcePath, surfaceLineCollectionSourcePath); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.IsNotNull(entity); + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + Assert.IsNull(entity.FailureMechanismSectionCollectionSourcePath); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + const string filePath = "failureMechanismSections/file/path"; + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + FailureMechanismSection testFailureMechanismSection = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + failureMechanism.SetSections(new[] + { + testFailureMechanismSection + }, filePath); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.MacroStabilityInwardsSectionResultEntities).Count()); + TestHelper.AssertAreEqualButNotSame(filePath, entity.FailureMechanismSectionCollectionSourcePath); + } + + [Test] + public void Create_WithCalculationGroup_ReturnFailureMechanismWithCalculationGroupEntities() + { + // Setup + var calculationGroup = new CalculationGroup(); + var calculation = new MacroStabilityInwardsCalculationScenario(); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculationGroup); + failureMechanism.CalculationsGroup.Children.Add(calculation); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(failureMechanism.CalculationsGroup.Name, entity.CalculationGroupEntity.Name); + Assert.AreEqual(0, entity.CalculationGroupEntity.Order); + + CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity.CalculationGroupEntity1 + .OrderBy(cge => cge.Order) + .ToArray(); + Assert.AreEqual(1, childGroupEntities.Length); + CalculationGroupEntity childGroupEntity = childGroupEntities[0]; + Assert.AreEqual(calculationGroup.Name, childGroupEntity.Name); + Assert.AreEqual(0, childGroupEntity.Order); + + MacroStabilityInwardsCalculationEntity[] calculationEntities = entity.CalculationGroupEntity.MacroStabilityInwardsCalculationEntities + .OrderBy(ce => ce.Order) + .ToArray(); + Assert.AreEqual(1, calculationEntities.Length); + MacroStabilityInwardsCalculationEntity calculationEntity = calculationEntities[0]; + Assert.AreEqual(calculation.Name, calculationEntity.Name); + Assert.AreEqual(1, calculationEntity.Order); + } + + private static void AssertSurfaceLine(MacroStabilityInwardsSurfaceLine surfaceLine, SurfaceLineEntity entity) + { + Assert.AreEqual(surfaceLine.Name, entity.Name); + Assert.AreEqual(surfaceLine.ReferenceLineIntersectionWorldPoint.X, entity.ReferenceLineIntersectionX); + Assert.AreEqual(surfaceLine.ReferenceLineIntersectionWorldPoint.Y, entity.ReferenceLineIntersectionY); + + Assert.AreEqual(0, entity.PipingCharacteristicPointEntities.Count); + Assert.AreEqual(12, entity.MacroStabilityInwardsCharacteristicPointEntities.Count); + } + + private MacroStabilityInwardsSurfaceLine CreateSurfaceLine(Random random) + { + var surfaceLine = new MacroStabilityInwardsSurfaceLine(nameof(MacroStabilityInwardsSurfaceLine)) + { + ReferenceLineIntersectionWorldPoint = new Point2D(random.NextDouble(), random.NextDouble()) + }; + + var geometryPoints = new Point3D[12]; + for (var i = 0; i < geometryPoints.Length; i++) + { + geometryPoints[i] = new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()); + } + + surfaceLine.SetGeometry(geometryPoints); + + surfaceLine.SetDitchPolderSideAt(geometryPoints[1]); + surfaceLine.SetBottomDitchPolderSideAt(geometryPoints[2]); + surfaceLine.SetBottomDitchDikeSideAt(geometryPoints[3]); + surfaceLine.SetDitchDikeSideAt(geometryPoints[4]); + surfaceLine.SetDikeTopAtPolderAt(geometryPoints[5]); + surfaceLine.SetDikeTopAtRiverAt(geometryPoints[6]); + surfaceLine.SetShoulderBaseInsideAt(geometryPoints[7]); + surfaceLine.SetShoulderTopInsideAt(geometryPoints[8]); + surfaceLine.SetDikeToeAtRiverAt(geometryPoints[9]); + surfaceLine.SetDikeToeAtPolderAt(geometryPoints[10]); + surfaceLine.SetSurfaceLevelInsideAt(geometryPoints[11]); + surfaceLine.SetSurfaceLevelOutsideAt(geometryPoints[0]); + + return surfaceLine; + } + + private static void AssertStochasticSoilModel(MacroStabilityInwardsStochasticSoilModel model, StochasticSoilModelEntity entity) + { + Assert.AreEqual(model.Name, entity.Name); + Assert.AreEqual(model.StochasticSoilProfiles.Count(), entity.MacroStabilityInwardsStochasticSoilProfileEntities.Count); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsFailureMechanismSectionResultCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsFailureMechanismSectionResultCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsFailureMechanismSectionResultCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,99 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.MacroStabilityInwards.Data; +using Riskeer.Storage.Core.Create.MacroStabilityInwards; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.MacroStabilityInwards +{ + [TestFixture] + public class MacroStabilityInwardsFailureMechanismSectionResultCreateExtensionsTest + { + [Test] + public void Create_SectionResultNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((MacroStabilityInwardsFailureMechanismSectionResult) null).Create(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("result", exception.ParamName); + } + + [Test] + public void Create_WithDifferentResults_ReturnsEntityWithExpectedResults() + { + // Setup + var random = new Random(39); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResult = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + double tailorMadeAssessmentProbability = random.NextDouble(); + bool useManualAssembly = random.NextBoolean(); + double manualAssemblyProbability = random.NextDouble(); + + var sectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + SimpleAssessmentResult = simpleAssessmentResult, + DetailedAssessmentResult = detailedAssessmentResult, + TailorMadeAssessmentResult = tailorMadeAssessmentResult, + TailorMadeAssessmentProbability = tailorMadeAssessmentProbability, + UseManualAssembly = useManualAssembly, + ManualAssemblyProbability = manualAssemblyProbability + }; + + // Call + MacroStabilityInwardsSectionResultEntity entity = sectionResult.Create(); + + // Assert + Assert.AreEqual(Convert.ToByte(simpleAssessmentResult), entity.SimpleAssessmentResult); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResult), entity.DetailedAssessmentResult); + Assert.AreEqual(Convert.ToByte(tailorMadeAssessmentResult), entity.TailorMadeAssessmentResult); + Assert.AreEqual(tailorMadeAssessmentProbability, entity.TailorMadeAssessmentProbability); + Assert.AreEqual(Convert.ToByte(useManualAssembly), entity.UseManualAssembly); + Assert.AreEqual(manualAssemblyProbability, entity.ManualAssemblyProbability); + } + + [Test] + public void Create_SectionResultWithNaNValues_ReturnsEntityWithExpectedResults() + { + // Setup + var sectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + TailorMadeAssessmentProbability = double.NaN, + ManualAssemblyProbability = double.NaN + }; + + // Call + MacroStabilityInwardsSectionResultEntity result = sectionResult.Create(); + + // Assert + Assert.IsNull(result.TailorMadeAssessmentProbability); + Assert.IsNull(result.ManualAssemblyProbability); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsOutputCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsOutputCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsOutputCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,187 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.MacroStabilityInwards.Data.TestUtil; +using Ringtoets.Storage.Core.TestUtil.MacroStabilityInwards; +using Riskeer.Storage.Core.Create.MacroStabilityInwards; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.MacroStabilityInwards +{ + [TestFixture] + public class MacroStabilityInwardsOutputCreateExtensionsTest + { + [Test] + public void Create_OutputNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((MacroStabilityInwardsOutput) null).Create(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("output", exception.ParamName); + } + + [Test] + public void Create_WithValidValues_ReturnsEntityWithExpectedPropertiesSet() + { + // Setup + var random = new Random(21); + + MacroStabilityInwardsSlidingCircle leftCircle = CreateSlidingCircle(13); + MacroStabilityInwardsSlidingCircle rightCircle = CreateSlidingCircle(34); + IEnumerable slices = new[] + { + MacroStabilityInwardsSliceTestFactory.CreateSlice() + }; + var slidingCurve = new MacroStabilityInwardsSlidingCurve(leftCircle, + rightCircle, + slices, + random.NextDouble(), + random.NextDouble()); + + MacroStabilityInwardsGrid leftGrid = MacroStabilityInwardsGridTestFactory.Create(); + MacroStabilityInwardsGrid rightGrid = MacroStabilityInwardsGridTestFactory.Create(); + RoundedDouble[] tangentLines = + { + random.NextRoundedDouble() + }; + var slipPlane = new MacroStabilityInwardsSlipPlaneUpliftVan(leftGrid, rightGrid, tangentLines); + + var output = new MacroStabilityInwardsOutput(slidingCurve, slipPlane, new MacroStabilityInwardsOutput.ConstructionProperties + { + FactorOfStability = random.NextDouble(), + ForbiddenZonesXEntryMax = random.NextDouble(), + ForbiddenZonesXEntryMin = random.NextDouble(), + ZValue = random.NextDouble() + }); + + // Call + MacroStabilityInwardsCalculationOutputEntity entity = output.Create(); + + // Assert + Assert.IsNotNull(entity); + MacroStabilityInwardsCalculationOutputEntityTestHelper.AssertOutputPropertyValues(output, entity); + } + + [Test] + public void Create_WithNaNValues_ReturnsPropertyWithExpectedPropertiesSet() + { + // Setup + MacroStabilityInwardsSlidingCircle leftCircle = CreateSlidingCircleWithNaNValues(); + MacroStabilityInwardsSlidingCircle rightCircle = CreateSlidingCircleWithNaNValues(); + var slidingCurve = new MacroStabilityInwardsSlidingCurve(leftCircle, + rightCircle, + new MacroStabilityInwardsSlice[0], + double.NaN, + double.NaN); + + var slipPlane = new MacroStabilityInwardsSlipPlaneUpliftVan(CreateGridWithNaNValues(), + CreateGridWithNaNValues(), + new RoundedDouble[0]); + + var output = new MacroStabilityInwardsOutput(slidingCurve, slipPlane, new MacroStabilityInwardsOutput.ConstructionProperties()); + + // Call + MacroStabilityInwardsCalculationOutputEntity entity = output.Create(); + + // Assert + Assert.IsNotNull(entity); + Assert.IsNull(entity.FactorOfStability); + Assert.IsNull(entity.ForbiddenZonesXEntryMin); + Assert.IsNull(entity.ForbiddenZonesXEntryMax); + Assert.IsNull(entity.ZValue); + + Assert.IsNull(entity.SlipPlaneLeftGridXLeft); + Assert.IsNull(entity.SlipPlaneLeftGridXRight); + Assert.IsNull(entity.SlipPlaneLeftGridZTop); + Assert.IsNull(entity.SlipPlaneLeftGridZBottom); + + Assert.IsNull(entity.SlipPlaneRightGridXLeft); + Assert.IsNull(entity.SlipPlaneRightGridXRight); + Assert.IsNull(entity.SlipPlaneRightGridZTop); + Assert.IsNull(entity.SlipPlaneRightGridZBottom); + + Assert.IsNull(entity.SlidingCurveIteratedHorizontalForce); + Assert.IsNull(entity.SlidingCurveNonIteratedHorizontalForce); + + Assert.IsNull(entity.SlidingCurveLeftSlidingCircleCenterX); + Assert.IsNull(entity.SlidingCurveLeftSlidingCircleCenterY); + Assert.IsNull(entity.SlidingCurveLeftSlidingCircleRadius); + Assert.IsNull(entity.SlidingCurveLeftSlidingCircleIteratedForce); + Assert.IsNull(entity.SlidingCurveLeftSlidingCircleNonIteratedForce); + Assert.IsNull(entity.SlidingCurveLeftSlidingCircleDrivingMoment); + Assert.IsNull(entity.SlidingCurveLeftSlidingCircleResistingMoment); + + Assert.IsNull(entity.SlidingCurveRightSlidingCircleCenterX); + Assert.IsNull(entity.SlidingCurveRightSlidingCircleCenterY); + Assert.IsNull(entity.SlidingCurveRightSlidingCircleRadius); + Assert.IsNull(entity.SlidingCurveRightSlidingCircleIteratedForce); + Assert.IsNull(entity.SlidingCurveRightSlidingCircleNonIteratedForce); + Assert.IsNull(entity.SlidingCurveRightSlidingCircleDrivingMoment); + Assert.IsNull(entity.SlidingCurveRightSlidingCircleResistingMoment); + } + + #region Slip Plane Helpers + + private static MacroStabilityInwardsGrid CreateGridWithNaNValues() + { + return new MacroStabilityInwardsGrid(double.NaN, double.NaN, double.NaN, double.NaN); + } + + #endregion + + #region Sliding Curve Helpers + + private static MacroStabilityInwardsSlidingCircle CreateSlidingCircle(int seed) + { + var random = new Random(seed); + return new MacroStabilityInwardsSlidingCircle(new Point2D(random.NextDouble(), random.NextDouble()), + random.NextDouble(), + random.NextBoolean(), + random.NextDouble(), + random.NextDouble(), + random.NextDouble(), + random.NextDouble()); + } + + private static MacroStabilityInwardsSlidingCircle CreateSlidingCircleWithNaNValues() + { + var random = new Random(21); + return new MacroStabilityInwardsSlidingCircle(new Point2D(double.NaN, double.NaN), + double.NaN, + random.NextBoolean(), + double.NaN, + double.NaN, + double.NaN, + double.NaN); + } + + #endregion + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsPreconsolidationStressCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsPreconsolidationStressCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsPreconsolidationStressCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,103 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Probabilistics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Data.SoilProfile; +using Riskeer.Storage.Core.Create.MacroStabilityInwards; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.MacroStabilityInwards +{ + [TestFixture] + public class MacroStabilityInwardsPreconsolidationStressCreateExtensionsTest + { + [Test] + public void Create_PreconsolidationStressNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => ((MacroStabilityInwardsPreconsolidationStress) null).Create(0); + + // Assert + string parameterName = Assert.Throws(test).ParamName; + Assert.AreEqual("preconsolidationStress", parameterName); + } + + [Test] + public void Create_WithValidProperties_ReturnsEntityWithPropertiesSet() + { + // Setup + var random = new Random(31); + + var stress = new MacroStabilityInwardsPreconsolidationStress(new Point2D(random.NextDouble(), random.NextDouble()), + new VariationCoefficientLogNormalDistribution + { + Mean = (RoundedDouble) 0.005, + CoefficientOfVariation = random.NextRoundedDouble() + }); + int order = random.Next(); + + // Call + MacroStabilityInwardsPreconsolidationStressEntity entity = stress.Create(order); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(stress.Location.X, entity.CoordinateX); + Assert.AreEqual(stress.Location.Y, entity.CoordinateZ); + + VariationCoefficientLogNormalDistribution preconsolidationStressDistribution = stress.Stress; + Assert.AreEqual(preconsolidationStressDistribution.Mean, entity.PreconsolidationStressMean, + preconsolidationStressDistribution.GetAccuracy()); + Assert.AreEqual(preconsolidationStressDistribution.CoefficientOfVariation, entity.PreconsolidationStressCoefficientOfVariation, + preconsolidationStressDistribution.GetAccuracy()); + Assert.AreEqual(order, entity.Order); + } + + [Test] + public void Create_WithNaNValues_ReturnsEntityWithPropertiesSet() + { + // Setup + var random = new Random(31); + + var stress = new MacroStabilityInwardsPreconsolidationStress(new Point2D(random.NextDouble(), random.NextDouble()), + new VariationCoefficientLogNormalDistribution + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }); + int order = random.Next(); + + // Call + MacroStabilityInwardsPreconsolidationStressEntity entity = stress.Create(order); + + // Assert + Assert.IsNotNull(entity); + Assert.IsNull(entity.PreconsolidationStressMean); + Assert.IsNull(entity.PreconsolidationStressCoefficientOfVariation); + Assert.AreEqual(order, entity.Order); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer1DCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer1DCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer1DCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,257 @@ +// Copyright (C) Stichting Deltares 2018. 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.Drawing; +using Core.Common.Base.Data; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Probabilistics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Data.SoilProfile; +using Ringtoets.MacroStabilityInwards.Primitives; +using Riskeer.Storage.Core.Create.MacroStabilityInwards; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.MacroStabilityInwards +{ + [TestFixture] + public class MacroStabilityInwardsSoilLayer1DCreateExtensionsTest + { + [Test] + public void Create_SoilLayerNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => ((MacroStabilityInwardsSoilLayer1D) null).Create(0); + + // Assert + string parameterName = Assert.Throws(test).ParamName; + Assert.AreEqual("soilLayer", parameterName); + } + + [Test] + public void Create_WithValidProperties_ReturnsEntityWithPropertiesSet() + { + // Setup + var random = new Random(31); + var soilLayer = new MacroStabilityInwardsSoilLayer1D(random.NextDouble()) + { + Data = + { + IsAquifer = random.NextBoolean(), + MaterialName = "MaterialName", + Color = Color.FromKnownColor(random.NextEnumValue()), + UsePop = random.NextBoolean(), + ShearStrengthModel = random.NextEnumValue(), + AbovePhreaticLevel = + { + Mean = (RoundedDouble) 0.3, + CoefficientOfVariation = (RoundedDouble) 0.2, + Shift = (RoundedDouble) 0.1 + }, + BelowPhreaticLevel = + { + Mean = (RoundedDouble) 10, + CoefficientOfVariation = (RoundedDouble) 0.5, + Shift = (RoundedDouble) 2 + }, + Cohesion = + { + Mean = (RoundedDouble) 10, + CoefficientOfVariation = (RoundedDouble) 1 + }, + FrictionAngle = + { + Mean = (RoundedDouble) 12, + CoefficientOfVariation = (RoundedDouble) 0.8 + }, + ShearStrengthRatio = + { + Mean = (RoundedDouble) 10, + CoefficientOfVariation = (RoundedDouble) 0.6 + }, + StrengthIncreaseExponent = + { + Mean = (RoundedDouble) 11, + CoefficientOfVariation = (RoundedDouble) 0.7 + }, + Pop = + { + Mean = (RoundedDouble) 14, + CoefficientOfVariation = (RoundedDouble) 0.9 + } + } + }; + int order = random.Next(); + + // Call + MacroStabilityInwardsSoilLayerOneDEntity entity = soilLayer.Create(order); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(soilLayer.Top, entity.Top); + + MacroStabilityInwardsSoilLayerData data = soilLayer.Data; + Assert.AreEqual(Convert.ToByte(data.IsAquifer), entity.IsAquifer); + Assert.AreEqual(data.MaterialName, entity.MaterialName); + Assert.AreEqual(data.Color.ToInt64(), Convert.ToInt64(entity.Color)); + Assert.AreEqual(Convert.ToByte(data.UsePop), entity.UsePop); + Assert.AreEqual(Convert.ToByte(data.ShearStrengthModel), entity.ShearStrengthModel); + + VariationCoefficientLogNormalDistribution abovePhreaticLevelDistribution = data.AbovePhreaticLevel; + Assert.AreEqual(abovePhreaticLevelDistribution.Mean, entity.AbovePhreaticLevelMean, + abovePhreaticLevelDistribution.GetAccuracy()); + Assert.AreEqual(abovePhreaticLevelDistribution.CoefficientOfVariation, entity.AbovePhreaticLevelCoefficientOfVariation, + abovePhreaticLevelDistribution.GetAccuracy()); + Assert.AreEqual(abovePhreaticLevelDistribution.Shift, entity.AbovePhreaticLevelShift, + abovePhreaticLevelDistribution.GetAccuracy()); + + VariationCoefficientLogNormalDistribution belowPhreaticLevelDistribution = data.BelowPhreaticLevel; + Assert.AreEqual(belowPhreaticLevelDistribution.Mean, entity.BelowPhreaticLevelMean, + belowPhreaticLevelDistribution.GetAccuracy()); + Assert.AreEqual(belowPhreaticLevelDistribution.CoefficientOfVariation, entity.BelowPhreaticLevelCoefficientOfVariation, + belowPhreaticLevelDistribution.GetAccuracy()); + Assert.AreEqual(belowPhreaticLevelDistribution.Shift, entity.BelowPhreaticLevelShift, + belowPhreaticLevelDistribution.GetAccuracy()); + + VariationCoefficientLogNormalDistribution cohesionDistribution = data.Cohesion; + Assert.AreEqual(cohesionDistribution.Mean, entity.CohesionMean, + cohesionDistribution.GetAccuracy()); + Assert.AreEqual(cohesionDistribution.CoefficientOfVariation, entity.CohesionCoefficientOfVariation, + cohesionDistribution.GetAccuracy()); + + VariationCoefficientLogNormalDistribution frictionAngleDistribution = data.FrictionAngle; + Assert.AreEqual(frictionAngleDistribution.Mean, entity.FrictionAngleMean, + frictionAngleDistribution.GetAccuracy()); + Assert.AreEqual(frictionAngleDistribution.CoefficientOfVariation, entity.FrictionAngleCoefficientOfVariation, + frictionAngleDistribution.GetAccuracy()); + + VariationCoefficientLogNormalDistribution shearStrengthRatioDistribution = data.ShearStrengthRatio; + Assert.AreEqual(shearStrengthRatioDistribution.Mean, entity.ShearStrengthRatioMean, + shearStrengthRatioDistribution.GetAccuracy()); + Assert.AreEqual(shearStrengthRatioDistribution.CoefficientOfVariation, entity.ShearStrengthRatioCoefficientOfVariation, + shearStrengthRatioDistribution.GetAccuracy()); + + VariationCoefficientLogNormalDistribution strengthIncreaseExponentDistribution = data.StrengthIncreaseExponent; + Assert.AreEqual(strengthIncreaseExponentDistribution.Mean, entity.StrengthIncreaseExponentMean, + strengthIncreaseExponentDistribution.GetAccuracy()); + Assert.AreEqual(strengthIncreaseExponentDistribution.CoefficientOfVariation, entity.StrengthIncreaseExponentCoefficientOfVariation, + strengthIncreaseExponentDistribution.GetAccuracy()); + + VariationCoefficientLogNormalDistribution popDistribution = data.Pop; + Assert.AreEqual(popDistribution.Mean, entity.PopMean, popDistribution.GetAccuracy()); + Assert.AreEqual(popDistribution.CoefficientOfVariation, entity.PopCoefficientOfVariation, popDistribution.GetAccuracy()); + Assert.AreEqual(order, entity.Order); + } + + [Test] + public void Create_WithNaNProperties_ReturnsEntityWithPropertiesSetToNull() + { + // Setup + var soilLayer = new MacroStabilityInwardsSoilLayer1D(double.NaN) + { + Data = + { + AbovePhreaticLevel = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN, + Shift = RoundedDouble.NaN + }, + BelowPhreaticLevel = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN, + Shift = RoundedDouble.NaN + }, + Cohesion = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + FrictionAngle = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + ShearStrengthRatio = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + StrengthIncreaseExponent = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + Pop = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + } + } + }; + + // Call + MacroStabilityInwardsSoilLayerOneDEntity entity = soilLayer.Create(0); + + // Assert + Assert.IsNotNull(entity); + Assert.IsNull(entity.Top); + Assert.IsNull(entity.AbovePhreaticLevelMean); + Assert.IsNull(entity.AbovePhreaticLevelCoefficientOfVariation); + Assert.IsNull(entity.AbovePhreaticLevelShift); + Assert.IsNull(entity.BelowPhreaticLevelMean); + Assert.IsNull(entity.BelowPhreaticLevelCoefficientOfVariation); + Assert.IsNull(entity.BelowPhreaticLevelShift); + Assert.IsNull(entity.CohesionMean); + Assert.IsNull(entity.CohesionCoefficientOfVariation); + Assert.IsNull(entity.FrictionAngleMean); + Assert.IsNull(entity.FrictionAngleCoefficientOfVariation); + Assert.IsNull(entity.ShearStrengthRatioMean); + Assert.IsNull(entity.ShearStrengthRatioCoefficientOfVariation); + Assert.IsNull(entity.StrengthIncreaseExponentMean); + Assert.IsNull(entity.StrengthIncreaseExponentCoefficientOfVariation); + Assert.IsNull(entity.PopMean); + Assert.IsNull(entity.PopCoefficientOfVariation); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string materialName = "MaterialName"; + var soilLayer = new MacroStabilityInwardsSoilLayer1D(0) + { + Data = + { + MaterialName = materialName + } + }; + + // Call + MacroStabilityInwardsSoilLayerOneDEntity entity = soilLayer.Create(0); + + // Assert + TestHelper.AssertAreEqualButNotSame(materialName, entity.MaterialName); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer2DCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer2DCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer2DCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,306 @@ +// Copyright (C) Stichting Deltares 2018. 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.Drawing; +using System.Linq; +using Core.Common.Base.Data; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Probabilistics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Data.TestUtil.SoilProfile; +using Ringtoets.MacroStabilityInwards.Primitives; +using Ringtoets.MacroStabilityInwards.Primitives.TestUtil; +using Riskeer.Storage.Core.Create.MacroStabilityInwards; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Create.MacroStabilityInwards +{ + [TestFixture] + public class MacroStabilityInwardsSoilLayer2DCreateExtensionsTest + { + [Test] + public void Create_SoilLayerNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => ((MacroStabilityInwardsSoilLayer2D) null).Create(0); + + // Assert + string parameterName = Assert.Throws(test).ParamName; + Assert.AreEqual("soilLayer", parameterName); + } + + [Test] + public void Create_WithValidProperties_ReturnsEntityWithPropertiesSet() + { + // Setup + var random = new Random(31); + MacroStabilityInwardsSoilLayer2D soilLayer = CreateMacroStabilityInwardsSoilLayer2D(); + int order = random.Next(); + + // Call + MacroStabilityInwardsSoilLayerTwoDEntity entity = soilLayer.Create(order); + + // Assert + AssertMacroStabilityInwardsSoilLayerTwoDEntity(soilLayer, entity, order); + } + + [Test] + public void Create_WithNestedLayers_ReturnsEntityWithNestedLayersSet() + { + // Setup + MacroStabilityInwardsSoilLayer2D parentLayer = MacroStabilityInwardsSoilLayer2DTestFactory.CreateMacroStabilityInwardsSoilLayer2D(new[] + { + CreateMacroStabilityInwardsSoilLayer2D(), + CreateMacroStabilityInwardsSoilLayer2D(), + CreateMacroStabilityInwardsSoilLayer2D() + }); + + // Call + MacroStabilityInwardsSoilLayerTwoDEntity entity = parentLayer.Create(0); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(parentLayer.NestedLayers.Count(), entity.MacroStabilityInwardsSoilLayerTwoDEntity1.Count); + + for (var i = 0; i < parentLayer.NestedLayers.Count(); i++) + { + AssertMacroStabilityInwardsSoilLayerTwoDEntity(parentLayer.NestedLayers.ElementAt(i), + entity.MacroStabilityInwardsSoilLayerTwoDEntity1.ElementAt(i), + i); + } + } + + [Test] + public void Create_WithNaNProperties_ReturnsEntityWithPropertiesSetToNull() + { + // Setup + var soilLayer = new MacroStabilityInwardsSoilLayer2D(RingTestFactory.CreateRandomRing()) + { + Data = + { + AbovePhreaticLevel = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN, + Shift = RoundedDouble.NaN + }, + BelowPhreaticLevel = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN, + Shift = RoundedDouble.NaN + }, + Cohesion = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + FrictionAngle = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + ShearStrengthRatio = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + StrengthIncreaseExponent = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + Pop = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + } + } + }; + + // Call + MacroStabilityInwardsSoilLayerTwoDEntity entity = soilLayer.Create(0); + + // Assert + Assert.IsNotNull(entity); + Assert.IsNull(entity.AbovePhreaticLevelMean); + Assert.IsNull(entity.AbovePhreaticLevelCoefficientOfVariation); + Assert.IsNull(entity.AbovePhreaticLevelShift); + Assert.IsNull(entity.BelowPhreaticLevelMean); + Assert.IsNull(entity.BelowPhreaticLevelCoefficientOfVariation); + Assert.IsNull(entity.BelowPhreaticLevelShift); + Assert.IsNull(entity.CohesionMean); + Assert.IsNull(entity.CohesionCoefficientOfVariation); + Assert.IsNull(entity.FrictionAngleMean); + Assert.IsNull(entity.FrictionAngleCoefficientOfVariation); + Assert.IsNull(entity.ShearStrengthRatioMean); + Assert.IsNull(entity.ShearStrengthRatioCoefficientOfVariation); + Assert.IsNull(entity.StrengthIncreaseExponentMean); + Assert.IsNull(entity.StrengthIncreaseExponentCoefficientOfVariation); + Assert.IsNull(entity.PopMean); + Assert.IsNull(entity.PopCoefficientOfVariation); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string materialName = "MaterialName"; + var soilLayer = new MacroStabilityInwardsSoilLayer2D(RingTestFactory.CreateRandomRing()) + { + Data = + { + MaterialName = materialName + } + }; + + // Call + MacroStabilityInwardsSoilLayerTwoDEntity entity = soilLayer.Create(0); + + // Assert + TestHelper.AssertAreEqualButNotSame(materialName, entity.MaterialName); + } + + private static MacroStabilityInwardsSoilLayer2D CreateMacroStabilityInwardsSoilLayer2D() + { + var random = new Random(14); + return new MacroStabilityInwardsSoilLayer2D(RingTestFactory.CreateRandomRing()) + { + Data = + { + IsAquifer = random.NextBoolean(), + MaterialName = "MaterialName", + Color = Color.FromKnownColor(random.NextEnumValue()), + UsePop = random.NextBoolean(), + ShearStrengthModel = random.NextEnumValue(), + AbovePhreaticLevel = + { + Mean = random.NextRoundedDouble(2.0, 3.0), + CoefficientOfVariation = random.NextRoundedDouble(), + Shift = random.NextRoundedDouble(0.0, 1.0) + }, + BelowPhreaticLevel = + { + Mean = random.NextRoundedDouble(2.0, 3.0), + CoefficientOfVariation = random.NextRoundedDouble(), + Shift = random.NextRoundedDouble(0.0, 1.0) + }, + Cohesion = + { + Mean = random.NextRoundedDouble(), + CoefficientOfVariation = random.NextRoundedDouble() + }, + FrictionAngle = + { + Mean = random.NextRoundedDouble(), + CoefficientOfVariation = random.NextRoundedDouble() + }, + StrengthIncreaseExponent = + { + Mean = random.NextRoundedDouble(), + CoefficientOfVariation = random.NextRoundedDouble() + }, + ShearStrengthRatio = + { + Mean = random.NextRoundedDouble(), + CoefficientOfVariation = random.NextRoundedDouble() + }, + Pop = + { + Mean = random.NextRoundedDouble(), + CoefficientOfVariation = random.NextRoundedDouble() + } + } + }; + } + + private static void AssertMacroStabilityInwardsSoilLayerTwoDEntity(MacroStabilityInwardsSoilLayer2D soilLayer, + MacroStabilityInwardsSoilLayerTwoDEntity entity, int order) + { + Assert.IsNotNull(entity); + + MacroStabilityInwardsSoilLayerData data = soilLayer.Data; + Assert.AreEqual(Convert.ToByte(data.IsAquifer), entity.IsAquifer); + Assert.AreEqual(data.MaterialName, entity.MaterialName); + Assert.AreEqual(data.Color.ToInt64(), Convert.ToInt64(entity.Color)); + Assert.AreEqual(Convert.ToByte(data.UsePop), entity.UsePop); + Assert.AreEqual(Convert.ToByte(data.ShearStrengthModel), entity.ShearStrengthModel); + + VariationCoefficientLogNormalDistribution abovePhreaticLevelDistribution = data.AbovePhreaticLevel; + Assert.AreEqual(abovePhreaticLevelDistribution.Mean, entity.AbovePhreaticLevelMean, + abovePhreaticLevelDistribution.GetAccuracy()); + Assert.AreEqual(abovePhreaticLevelDistribution.CoefficientOfVariation, entity.AbovePhreaticLevelCoefficientOfVariation, + abovePhreaticLevelDistribution.GetAccuracy()); + Assert.AreEqual(abovePhreaticLevelDistribution.Shift, entity.AbovePhreaticLevelShift, + abovePhreaticLevelDistribution.GetAccuracy()); + + VariationCoefficientLogNormalDistribution belowPhreaticLevelDistribution = data.BelowPhreaticLevel; + Assert.AreEqual(belowPhreaticLevelDistribution.Mean, entity.BelowPhreaticLevelMean, + belowPhreaticLevelDistribution.GetAccuracy()); + Assert.AreEqual(belowPhreaticLevelDistribution.CoefficientOfVariation, entity.BelowPhreaticLevelCoefficientOfVariation, + belowPhreaticLevelDistribution.GetAccuracy()); + Assert.AreEqual(belowPhreaticLevelDistribution.Shift, entity.BelowPhreaticLevelShift, + belowPhreaticLevelDistribution.GetAccuracy()); + + VariationCoefficientLogNormalDistribution cohesionDistribution = data.Cohesion; + Assert.AreEqual(cohesionDistribution.Mean, entity.CohesionMean, + cohesionDistribution.GetAccuracy()); + Assert.AreEqual(cohesionDistribution.CoefficientOfVariation, entity.CohesionCoefficientOfVariation, + cohesionDistribution.GetAccuracy()); + + VariationCoefficientLogNormalDistribution frictionAngleDistribution = data.FrictionAngle; + Assert.AreEqual(frictionAngleDistribution.Mean, entity.FrictionAngleMean, + frictionAngleDistribution.GetAccuracy()); + Assert.AreEqual(frictionAngleDistribution.CoefficientOfVariation, entity.FrictionAngleCoefficientOfVariation, + frictionAngleDistribution.GetAccuracy()); + + VariationCoefficientLogNormalDistribution shearStrengthRatioDistribution = data.ShearStrengthRatio; + Assert.AreEqual(shearStrengthRatioDistribution.Mean, entity.ShearStrengthRatioMean, + shearStrengthRatioDistribution.GetAccuracy()); + Assert.AreEqual(shearStrengthRatioDistribution.CoefficientOfVariation, entity.ShearStrengthRatioCoefficientOfVariation, + shearStrengthRatioDistribution.GetAccuracy()); + + VariationCoefficientLogNormalDistribution strengthIncreaseExponentDistribution = data.StrengthIncreaseExponent; + Assert.AreEqual(strengthIncreaseExponentDistribution.Mean, entity.StrengthIncreaseExponentMean, + strengthIncreaseExponentDistribution.GetAccuracy()); + Assert.AreEqual(strengthIncreaseExponentDistribution.CoefficientOfVariation, entity.StrengthIncreaseExponentCoefficientOfVariation, + strengthIncreaseExponentDistribution.GetAccuracy()); + + VariationCoefficientLogNormalDistribution popDistribution = data.Pop; + Assert.AreEqual(popDistribution.Mean, entity.PopMean, popDistribution.GetAccuracy()); + Assert.AreEqual(popDistribution.CoefficientOfVariation, entity.PopCoefficientOfVariation, popDistribution.GetAccuracy()); + + Assert.AreEqual(order, entity.Order); + + AssertOuterRing(soilLayer.OuterRing, entity); + CollectionAssert.IsEmpty(entity.MacroStabilityInwardsSoilLayerTwoDEntity1); + } + + private static void AssertOuterRing(Ring outerRing, MacroStabilityInwardsSoilLayerTwoDEntity entity) + { + string expectedOuterRingXml = new Point2DCollectionXmlSerializer().ToXml(outerRing.Points); + Assert.AreEqual(expectedOuterRingXml, entity.OuterRingXml); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSoilProfile1DCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSoilProfile1DCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSoilProfile1DCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,147 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.MacroStabilityInwards.Data.SoilProfile; +using Ringtoets.MacroStabilityInwards.Data.TestUtil.SoilProfile; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.MacroStabilityInwards; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.MacroStabilityInwards +{ + [TestFixture] + public class MacroStabilityInwardsSoilProfile1DCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + MacroStabilityInwardsSoilProfile1D soilProfile = + MacroStabilityInwardsSoilProfile1DTestFactory.CreateMacroStabilityInwardsSoilProfile1D(); + + // Call + TestDelegate test = () => soilProfile.Create(null); + + // Assert + string parameterName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", parameterName); + } + + [Test] + public void Create_SoilProfileNull_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => ((MacroStabilityInwardsSoilProfile1D) null).Create(registry); + + // Assert + string parameterName = Assert.Throws(test).ParamName; + Assert.AreEqual("soilProfile", parameterName); + } + + [Test] + public void Create_WithValidProperties_ReturnsEntityWithPropertiesSet() + { + // Setup + var random = new Random(31); + const string name = "some name"; + double bottom = -random.NextDouble(); + var soilProfile = new MacroStabilityInwardsSoilProfile1D(name, bottom, new[] + { + new MacroStabilityInwardsSoilLayer1D(random.NextDouble()), + new MacroStabilityInwardsSoilLayer1D(random.NextDouble()) + }); + var registry = new PersistenceRegistry(); + + // Call + MacroStabilityInwardsSoilProfileOneDEntity entity = soilProfile.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(soilProfile.Bottom, entity.Bottom); + Assert.AreEqual(soilProfile.Layers.Count(), entity.MacroStabilityInwardsSoilLayerOneDEntities.Count); + + MacroStabilityInwardsSoilLayerOneDEntity firstLayerEntity = entity.MacroStabilityInwardsSoilLayerOneDEntities.ElementAt(0); + Assert.AreEqual(soilProfile.Layers.ElementAt(0).Top, firstLayerEntity.Top); + + MacroStabilityInwardsSoilLayerOneDEntity secondLayerEntity = entity.MacroStabilityInwardsSoilLayerOneDEntities.ElementAt(1); + Assert.AreEqual(soilProfile.Layers.ElementAt(1).Top, secondLayerEntity.Top); + } + + [Test] + public void Create_WithNaNProperties_ReturnsEntityWithPropertiesSetToNull() + { + // Setup + var random = new Random(31); + var soilProfile = new MacroStabilityInwardsSoilProfile1D("some name", double.NaN, new[] + { + new MacroStabilityInwardsSoilLayer1D(random.NextDouble()) + }); + var registry = new PersistenceRegistry(); + + // Call + MacroStabilityInwardsSoilProfileOneDEntity entity = soilProfile.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.IsNull(entity.Bottom); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string name = "some name"; + MacroStabilityInwardsSoilProfile1D soilProfile = + MacroStabilityInwardsSoilProfile1DTestFactory.CreateMacroStabilityInwardsSoilProfile1D(name); + var registry = new PersistenceRegistry(); + + // Call + MacroStabilityInwardsSoilProfileOneDEntity entity = soilProfile.Create(registry); + + // Assert + TestHelper.AssertAreEqualButNotSame(name, entity.Name); + } + + [Test] + public void GivenCreatedEntity_WhenCreateCalledOnSameObject_ThenSameEntityReturned() + { + // Given + MacroStabilityInwardsSoilProfile1D soilProfile = + MacroStabilityInwardsSoilProfile1DTestFactory.CreateMacroStabilityInwardsSoilProfile1D(); + var registry = new PersistenceRegistry(); + + MacroStabilityInwardsSoilProfileOneDEntity firstEntity = soilProfile.Create(registry); + + // When + MacroStabilityInwardsSoilProfileOneDEntity secondEntity = soilProfile.Create(registry); + + // Then + Assert.AreSame(firstEntity, secondEntity); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSoilProfile2DCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSoilProfile2DCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSoilProfile2DCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,154 @@ +// Copyright (C) Stichting Deltares 2018. 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.ObjectModel; +using System.Linq; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Probabilistics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Data.SoilProfile; +using Ringtoets.MacroStabilityInwards.Data.TestUtil.SoilProfile; +using Ringtoets.MacroStabilityInwards.Primitives; +using Ringtoets.MacroStabilityInwards.Primitives.TestUtil; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.MacroStabilityInwards; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.MacroStabilityInwards +{ + [TestFixture] + public class MacroStabilityInwardsSoilProfile2DCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + MacroStabilityInwardsSoilProfile2D soilProfile = CreateMacroStabilityInwardsSoilProfile2D(); + + // Call + TestDelegate test = () => soilProfile.Create(null); + + // Assert + string parameterName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", parameterName); + } + + [Test] + public void Create_SoilProfileNull_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => ((MacroStabilityInwardsSoilProfile2D) null).Create(registry); + + // Assert + string parameterName = Assert.Throws(test).ParamName; + Assert.AreEqual("soilProfile", parameterName); + } + + [Test] + public void Create_WithValidProperties_ReturnsEntityWithPropertiesSet() + { + // Setup + var soilProfile = new MacroStabilityInwardsSoilProfile2D("some name", new[] + { + MacroStabilityInwardsSoilLayer2DTestFactory.CreateMacroStabilityInwardsSoilLayer2D(), + MacroStabilityInwardsSoilLayer2DTestFactory.CreateMacroStabilityInwardsSoilLayer2D() + }, new[] + { + MacroStabilityInwardsPreconsolidationStressTestFactory.CreateMacroStabilityInwardsPreconsolidationStress() + }); + var registry = new PersistenceRegistry(); + + // Call + MacroStabilityInwardsSoilProfileTwoDEntity entity = soilProfile.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(soilProfile.Layers.Count(), entity.MacroStabilityInwardsSoilLayerTwoDEntities.Count); + Assert.AreEqual(soilProfile.PreconsolidationStresses.Count(), entity.MacroStabilityInwardsPreconsolidationStressEntities.Count); + + AssertPreconsolidationStress(soilProfile.PreconsolidationStresses.First(), + entity.MacroStabilityInwardsPreconsolidationStressEntities.First()); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + MacroStabilityInwardsSoilProfile2D soilProfile = CreateMacroStabilityInwardsSoilProfile2D("some name"); + var registry = new PersistenceRegistry(); + + // Call + MacroStabilityInwardsSoilProfileTwoDEntity entity = soilProfile.Create(registry); + + // Assert + TestHelper.AssertAreEqualButNotSame(soilProfile.Name, entity.Name); + } + + [Test] + public void GivenCreatedEntity_WhenCreateCalledOnSameObject_ThenSameEntityInstanceReturned() + { + // Given + MacroStabilityInwardsSoilProfile2D soilProfile = CreateMacroStabilityInwardsSoilProfile2D(); + var registry = new PersistenceRegistry(); + + MacroStabilityInwardsSoilProfileTwoDEntity firstEntity = soilProfile.Create(registry); + + // When + MacroStabilityInwardsSoilProfileTwoDEntity secondEntity = soilProfile.Create(registry); + + // Then + Assert.AreSame(firstEntity, secondEntity); + } + + private static void AssertPreconsolidationStress(MacroStabilityInwardsPreconsolidationStress preconsolidationStress, + MacroStabilityInwardsPreconsolidationStressEntity entity) + { + Assert.AreEqual(preconsolidationStress.Location.X, entity.CoordinateX); + Assert.AreEqual(preconsolidationStress.Location.Y, entity.CoordinateZ); + + VariationCoefficientLogNormalDistribution preconsolidationDistribution = preconsolidationStress.Stress; + Assert.AreEqual(preconsolidationDistribution.Mean, entity.PreconsolidationStressMean, + preconsolidationDistribution.GetAccuracy()); + Assert.AreEqual(preconsolidationDistribution.CoefficientOfVariation, entity.PreconsolidationStressCoefficientOfVariation, + preconsolidationDistribution.GetAccuracy()); + } + + private static MacroStabilityInwardsSoilProfile2D CreateMacroStabilityInwardsSoilProfile2D() + { + return CreateMacroStabilityInwardsSoilProfile2D(string.Empty); + } + + private static MacroStabilityInwardsSoilProfile2D CreateMacroStabilityInwardsSoilProfile2D(string name) + { + var layers = new Collection + { + new MacroStabilityInwardsSoilLayer2D(RingTestFactory.CreateRandomRing()) + }; + + return new MacroStabilityInwardsSoilProfile2D(name, layers, Enumerable.Empty()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsStochasticSoilModelCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsStochasticSoilModelCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsStochasticSoilModelCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,179 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.MacroStabilityInwards.Data.SoilProfile; +using Ringtoets.MacroStabilityInwards.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Data.TestUtil.SoilProfile; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.MacroStabilityInwards; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Create.MacroStabilityInwards +{ + [TestFixture] + public class MacroStabilityInwardsStochasticSoilModelCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + MacroStabilityInwardsStochasticSoilModel stochasticSoilModel = + MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel(); + + // Call + TestDelegate test = () => stochasticSoilModel.Create(null, 0); + + // Assert + string parameterName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", parameterName); + } + + [Test] + public void Create_StochasticSoilModelNull_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => ((MacroStabilityInwardsStochasticSoilModel) null).Create(registry, 0); + + // Assert + string parameterName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", parameterName); + } + + [Test] + public void Create_WithValidProperties_ReturnsStochasticSoilModelEntityWithPropertiesSet() + { + // Setup + var random = new Random(1); + int order = random.Next(); + MacroStabilityInwardsStochasticSoilModel stochasticSoilModel = + MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel(nameof(MacroStabilityInwardsStochasticSoilModel)); + var registry = new PersistenceRegistry(); + + // Call + StochasticSoilModelEntity entity = stochasticSoilModel.Create(registry, order); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(stochasticSoilModel.Name, entity.Name); + Assert.AreEqual(order, entity.Order); + CollectionAssert.IsEmpty(entity.PipingStochasticSoilProfileEntities); + } + + [Test] + public void Create_WithStochasticSoilProfiles_ReturnsStochasticSoilModelEntityWithPropertiesSet() + { + // Setup + var stochasticSoilProfiles = new[] + { + new MacroStabilityInwardsStochasticSoilProfile(0.1, MacroStabilityInwardsSoilProfile1DTestFactory.CreateMacroStabilityInwardsSoilProfile1D()), + new MacroStabilityInwardsStochasticSoilProfile(0.9, MacroStabilityInwardsSoilProfile2DTestFactory.CreateMacroStabilityInwardsSoilProfile2D()) + }; + MacroStabilityInwardsStochasticSoilModel stochasticSoilModel = + MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel("Model", stochasticSoilProfiles); + + var registry = new PersistenceRegistry(); + + // Call + StochasticSoilModelEntity entity = stochasticSoilModel.Create(registry, 0); + + // Assert + Assert.IsNotNull(entity); + CollectionAssert.IsEmpty(entity.PipingStochasticSoilProfileEntities); + Assert.AreEqual(stochasticSoilProfiles.Length, entity.MacroStabilityInwardsStochasticSoilProfileEntities.Count); + + MacroStabilityInwardsStochasticSoilProfile firstStochasticSoilProfile = stochasticSoilProfiles[0]; + MacroStabilityInwardsStochasticSoilProfileEntity firstStochasticSoilProfileEntity = entity.MacroStabilityInwardsStochasticSoilProfileEntities.First(); + Assert.AreEqual(firstStochasticSoilProfile.Probability, firstStochasticSoilProfileEntity.Probability); + Assert.IsNotNull(firstStochasticSoilProfileEntity.MacroStabilityInwardsSoilProfileOneDEntity); + Assert.IsNull(firstStochasticSoilProfileEntity.MacroStabilityInwardsSoilProfileTwoDEntity); + + MacroStabilityInwardsStochasticSoilProfile secondStochasticSoilProfile = stochasticSoilProfiles[1]; + MacroStabilityInwardsStochasticSoilProfileEntity secondStochasticSoilProfileEntity = entity.MacroStabilityInwardsStochasticSoilProfileEntities.ElementAt(1); + Assert.AreEqual(secondStochasticSoilProfile.Probability, secondStochasticSoilProfileEntity.Probability); + Assert.IsNull(secondStochasticSoilProfileEntity.MacroStabilityInwardsSoilProfileOneDEntity); + Assert.IsNotNull(secondStochasticSoilProfileEntity.MacroStabilityInwardsSoilProfileTwoDEntity); + } + + [Test] + public void Create_WithGeometryPoints_ReturnsStochasticSoilModelEntityWithPropertiesSet() + { + // Setup + var random = new Random(31); + MacroStabilityInwardsStochasticSoilModel stochasticSoilModel = + MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel("testName", new[] + { + new Point2D(random.NextDouble(), random.NextDouble()), + new Point2D(random.NextDouble(), random.NextDouble()) + }); + + var registry = new PersistenceRegistry(); + + // Call + StochasticSoilModelEntity entity = stochasticSoilModel.Create(registry, 0); + + // Assert + Assert.IsNotNull(entity); + string expectedXml = new Point2DCollectionXmlSerializer().ToXml(stochasticSoilModel.Geometry); + Assert.AreEqual(expectedXml, entity.StochasticSoilModelSegmentPointXml); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string name = "testName"; + MacroStabilityInwardsStochasticSoilModel stochasticSoilModel = + MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel(name); + var registry = new PersistenceRegistry(); + + // Call + StochasticSoilModelEntity entity = stochasticSoilModel.Create(registry, 0); + + // Assert + TestHelper.AssertAreEqualButNotSame(name, entity.Name); + } + + [Test] + public void GivenCreatedEntity_WhenCreateCalledOnSameObject_ThenSameEntityInstanceReturned() + { + // Given + MacroStabilityInwardsStochasticSoilModel stochasticSoilModel = MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel(); + var registry = new PersistenceRegistry(); + + StochasticSoilModelEntity firstEntity = stochasticSoilModel.Create(registry, 0); + + // When + StochasticSoilModelEntity secondEntity = stochasticSoilModel.Create(registry, 0); + + // Then + Assert.AreSame(firstEntity, secondEntity); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsStochasticSoilProfileCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsStochasticSoilProfileCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsStochasticSoilProfileCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,209 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.MacroStabilityInwards.Data.SoilProfile; +using Ringtoets.MacroStabilityInwards.Data.TestUtil.SoilProfile; +using Ringtoets.MacroStabilityInwards.Primitives; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.MacroStabilityInwards; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.MacroStabilityInwards +{ + [TestFixture] + public class MacroStabilityInwardsStochasticSoilProfileCreateExtensionsTest + { + [Test] + public void Create_StochasticSoilProfileNull_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => ((MacroStabilityInwardsStochasticSoilProfile) null).Create(registry, 0); + + // Assert + string parameterName = Assert.Throws(test).ParamName; + Assert.AreEqual("stochasticSoilProfile", parameterName); + } + + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var mockRepository = new MockRepository(); + var soilProfile = mockRepository.Stub>(); + mockRepository.ReplayAll(); + + var stochasticSoilProfile = new MacroStabilityInwardsStochasticSoilProfile(0, soilProfile); + + // Call + TestDelegate test = () => stochasticSoilProfile.Create(null, 0); + + // Assert + string parameterName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", parameterName); + + mockRepository.VerifyAll(); + } + + [Test] + public void Create_WithUnsupportedSoilProfile_ThrowsNotSupportedException() + { + // Setup + var stochasticSoilProfile = new MacroStabilityInwardsStochasticSoilProfile(0.5, new UnsupportedMacroStabilityInwardsSoilProfile()); + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => stochasticSoilProfile.Create(registry, 1); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual($"{nameof(UnsupportedMacroStabilityInwardsSoilProfile)} is not supported. " + + $"Supported types are: {nameof(MacroStabilityInwardsSoilProfile1D)} and {nameof(MacroStabilityInwardsSoilProfile2D)}.", exception.Message); + } + + [Test] + public void Create_WithMacroStabilityInwardsSoilProfile1D_ReturnsStochasticSoilProfileEntityWithPropertiesSet() + { + // Setup + var random = new Random(31); + MacroStabilityInwardsSoilProfile1D soilProfile = + MacroStabilityInwardsSoilProfile1DTestFactory.CreateMacroStabilityInwardsSoilProfile1D(nameof(MacroStabilityInwardsSoilProfile1D)); + var stochasticSoilProfile = new MacroStabilityInwardsStochasticSoilProfile(random.NextDouble(), soilProfile); + + int order = random.Next(); + + var registry = new PersistenceRegistry(); + + // Call + MacroStabilityInwardsStochasticSoilProfileEntity entity = stochasticSoilProfile.Create(registry, order); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(stochasticSoilProfile.Probability, entity.Probability); + Assert.AreEqual(soilProfile.Name, entity.MacroStabilityInwardsSoilProfileOneDEntity.Name); + Assert.IsNull(entity.MacroStabilityInwardsSoilProfileTwoDEntity); + Assert.AreEqual(order, entity.Order); + } + + [Test] + public void Create_WithMacroStabilityInwardsSoilProfile2D_ReturnsStochasticSoilProfileEntityWithPropertiesSet() + { + // Setup + var random = new Random(31); + MacroStabilityInwardsSoilProfile2D soilProfile = + MacroStabilityInwardsSoilProfile2DTestFactory.CreateMacroStabilityInwardsSoilProfile2D(); + var stochasticSoilProfile = new MacroStabilityInwardsStochasticSoilProfile(random.NextDouble(), soilProfile); + + int order = random.Next(); + + var registry = new PersistenceRegistry(); + + // Call + MacroStabilityInwardsStochasticSoilProfileEntity entity = stochasticSoilProfile.Create(registry, order); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(stochasticSoilProfile.Probability, entity.Probability); + Assert.IsNull(entity.MacroStabilityInwardsSoilProfileOneDEntity); + Assert.AreEqual(soilProfile.Name, entity.MacroStabilityInwardsSoilProfileTwoDEntity.Name); + Assert.AreEqual(order, entity.Order); + } + + [Test] + public void Create_DifferentStochasticSoilProfilesWithSameMacroStabilityInwardsSoilProfile1D_ReturnsEntityWithSameSoilProfileEntitySet() + { + // Setup + var random = new Random(31); + + MacroStabilityInwardsSoilProfile1D soilProfile = MacroStabilityInwardsSoilProfile1DTestFactory.CreateMacroStabilityInwardsSoilProfile1D(); + var firstStochasticSoilProfile = new MacroStabilityInwardsStochasticSoilProfile(random.NextDouble(), soilProfile); + var secondStochasticSoilProfile = new MacroStabilityInwardsStochasticSoilProfile(random.NextDouble(), soilProfile); + var registry = new PersistenceRegistry(); + + MacroStabilityInwardsStochasticSoilProfileEntity firstEntity = firstStochasticSoilProfile.Create(registry, 0); + + // Call + MacroStabilityInwardsStochasticSoilProfileEntity secondEntity = secondStochasticSoilProfile.Create(registry, 0); + + // Assert + Assert.AreSame(firstEntity.MacroStabilityInwardsSoilProfileOneDEntity, secondEntity.MacroStabilityInwardsSoilProfileOneDEntity); + Assert.IsNull(firstEntity.MacroStabilityInwardsSoilProfileTwoDEntity); + Assert.IsNull(secondEntity.MacroStabilityInwardsSoilProfileTwoDEntity); + } + + [Test] + public void Create_DifferentStochasticSoilProfilesWithSameMacroStabilityInwardsSoilProfile2D_ReturnsEntityWithSameSoilProfileEntitySet() + { + // Setup + var random = new Random(31); + + MacroStabilityInwardsSoilProfile2D soilProfile = MacroStabilityInwardsSoilProfile2DTestFactory.CreateMacroStabilityInwardsSoilProfile2D(); + var firstStochasticSoilProfile = new MacroStabilityInwardsStochasticSoilProfile(random.NextDouble(), soilProfile); + var secondStochasticSoilProfile = new MacroStabilityInwardsStochasticSoilProfile(random.NextDouble(), soilProfile); + var registry = new PersistenceRegistry(); + + MacroStabilityInwardsStochasticSoilProfileEntity firstEntity = firstStochasticSoilProfile.Create(registry, 0); + + // Call + MacroStabilityInwardsStochasticSoilProfileEntity secondEntity = secondStochasticSoilProfile.Create(registry, 0); + + // Assert + Assert.IsNull(firstEntity.MacroStabilityInwardsSoilProfileOneDEntity); + Assert.IsNull(secondEntity.MacroStabilityInwardsSoilProfileOneDEntity); + Assert.AreSame(firstEntity.MacroStabilityInwardsSoilProfileTwoDEntity, secondEntity.MacroStabilityInwardsSoilProfileTwoDEntity); + } + + [Test] + [TestCaseSource(nameof(GetMacroStabilityInwardsSoilProfiles))] + public void GivenCreatedEntity_WhenCreateCalledOnSameObject_ThenSameEntityInstanceReturned(IMacroStabilityInwardsSoilProfile soilProfile) + { + // Given + var stochasticSoilProfile = new MacroStabilityInwardsStochasticSoilProfile(0.4, soilProfile); + var registry = new PersistenceRegistry(); + + MacroStabilityInwardsStochasticSoilProfileEntity entity1 = stochasticSoilProfile.Create(registry, 0); + + // When + MacroStabilityInwardsStochasticSoilProfileEntity entity2 = stochasticSoilProfile.Create(registry, 0); + + // Then + Assert.AreSame(entity1, entity2); + } + + private class UnsupportedMacroStabilityInwardsSoilProfile : IMacroStabilityInwardsSoilProfile + { + public string Name { get; } + public IEnumerable Layers { get; } + } + + private static IEnumerable> GetMacroStabilityInwardsSoilProfiles() + { + yield return MacroStabilityInwardsSoilProfile1DTestFactory.CreateMacroStabilityInwardsSoilProfile1D(); + yield return MacroStabilityInwardsSoilProfile2DTestFactory.CreateMacroStabilityInwardsSoilProfile2D(); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSurfaceLineCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSurfaceLineCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSurfaceLineCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,367 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.MacroStabilityInwards.Primitives; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.MacroStabilityInwards; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Create.MacroStabilityInwards +{ + [TestFixture] + public class MacroStabilityInwardsSurfaceLineCreateExtensionsTest + { + [Test] + public void Create_SurfaceLineNull_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate call = () => ((MacroStabilityInwardsSurfaceLine) null).Create(registry, 0); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("surfaceLine", exception.ParamName); + } + + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var surfaceLine = new MacroStabilityInwardsSurfaceLine(string.Empty); + + // Call + TestDelegate call = () => surfaceLine.Create(null, 0); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("registry", exception.ParamName); + } + + [Test] + public void Create_SurfaceLineWithoutGeometry_ReturnSurfaceLineEntityWithoutAddingPointEntities() + { + // Setup + var random = new Random(31); + var registry = new PersistenceRegistry(); + var surfaceLine = new MacroStabilityInwardsSurfaceLine("Test") + { + ReferenceLineIntersectionWorldPoint = GetRandomPoint2D(random) + }; + int order = random.Next(); + + // Call + SurfaceLineEntity entity = surfaceLine.Create(registry, order); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(surfaceLine.Name, entity.Name); + Assert.AreEqual(surfaceLine.ReferenceLineIntersectionWorldPoint.X, entity.ReferenceLineIntersectionX); + Assert.AreEqual(surfaceLine.ReferenceLineIntersectionWorldPoint.Y, entity.ReferenceLineIntersectionY); + Assert.AreEqual(order, entity.Order); + + string expectedXml = new Point3DCollectionXmlSerializer().ToXml(new Point3D[0]); + Assert.AreEqual(expectedXml, entity.PointsXml); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + var registry = new PersistenceRegistry(); + var surfaceLine = new MacroStabilityInwardsSurfaceLine("Test"); + + // Call + SurfaceLineEntity entity = surfaceLine.Create(registry, 0); + + // Assert + TestHelper.AssertAreEqualButNotSame(surfaceLine.Name, entity.Name); + } + + [Test] + public void Create_SurfaceLineWithGeometryWithoutCharacteristicPoints_ReturnSurfaceLineEntityWithPointEntities() + { + // Setup + var random = new Random(31); + var surfaceLine = new MacroStabilityInwardsSurfaceLine("Test") + { + ReferenceLineIntersectionWorldPoint = GetRandomPoint2D(random) + }; + surfaceLine.SetGeometry(new[] + { + GetRandomPoint3D(random), + GetRandomPoint3D(random), + GetRandomPoint3D(random) + }); + + var registry = new PersistenceRegistry(); + int order = random.Next(); + + // Call + SurfaceLineEntity entity = surfaceLine.Create(registry, order); + + // Assert + Assert.AreEqual(surfaceLine.Name, entity.Name); + Assert.AreEqual(surfaceLine.ReferenceLineIntersectionWorldPoint.X, entity.ReferenceLineIntersectionX); + Assert.AreEqual(surfaceLine.ReferenceLineIntersectionWorldPoint.Y, entity.ReferenceLineIntersectionY); + Assert.AreEqual(order, entity.Order); + + string expectedXml = new Point3DCollectionXmlSerializer().ToXml(surfaceLine.Points); + Assert.AreEqual(expectedXml, entity.PointsXml); + } + + [Test] + public void Create_SurfaceLineWithGeometryAndCharacteristicPoints_ReturnSurfaceLineEntityWithPointEntitiesAndCharactersisticPointReferences() + { + // Setup + var random = new Random(31); + Point3D[] geometry = + { + GetRandomPoint3D(random), + GetRandomPoint3D(random), + GetRandomPoint3D(random), + GetRandomPoint3D(random), + GetRandomPoint3D(random), + GetRandomPoint3D(random), + GetRandomPoint3D(random), + GetRandomPoint3D(random), + GetRandomPoint3D(random), + GetRandomPoint3D(random), + GetRandomPoint3D(random), + GetRandomPoint3D(random), + GetRandomPoint3D(random), + GetRandomPoint3D(random), + GetRandomPoint3D(random) + }; + var surfaceLine = new MacroStabilityInwardsSurfaceLine("Test") + { + ReferenceLineIntersectionWorldPoint = GetRandomPoint2D(random) + }; + surfaceLine.SetGeometry(geometry); + + const int surfaceLevelOutsideIndex = 1; + surfaceLine.SetSurfaceLevelOutsideAt(geometry[surfaceLevelOutsideIndex]); + const int dikeTopAtPolderIndex = 2; + surfaceLine.SetDikeTopAtPolderAt(geometry[dikeTopAtPolderIndex]); + const int dikeTopAtRiverIndex = 3; + surfaceLine.SetDikeTopAtRiverAt(geometry[dikeTopAtRiverIndex]); + const int shoulderBaseInsideIndex = 4; + surfaceLine.SetShoulderBaseInsideAt(geometry[shoulderBaseInsideIndex]); + const int shoulderTopInsideIndex = 5; + surfaceLine.SetShoulderTopInsideAt(geometry[shoulderTopInsideIndex]); + const int bottomDitchDikeSideIndex = 6; + surfaceLine.SetBottomDitchDikeSideAt(geometry[bottomDitchDikeSideIndex]); + const int bottomDitchPolderSideIndex = 7; + surfaceLine.SetBottomDitchPolderSideAt(geometry[bottomDitchPolderSideIndex]); + const int dikeToeAtPolderIndex = 8; + surfaceLine.SetDikeToeAtPolderAt(geometry[dikeToeAtPolderIndex]); + const int dikeToeAtRiverIndex = 9; + surfaceLine.SetDikeToeAtRiverAt(geometry[dikeToeAtRiverIndex]); + const int ditchDikeSideIndex = 10; + surfaceLine.SetDitchDikeSideAt(geometry[ditchDikeSideIndex]); + const int ditchPolderSideIndex = 11; + surfaceLine.SetDitchPolderSideAt(geometry[ditchPolderSideIndex]); + const int surfaceLevelInsideIndex = 12; + surfaceLine.SetSurfaceLevelInsideAt(geometry[surfaceLevelInsideIndex]); + + var registry = new PersistenceRegistry(); + + // Call + SurfaceLineEntity entity = surfaceLine.Create(registry, 0); + + // Assert + Assert.AreEqual(surfaceLine.Name, entity.Name); + Assert.AreEqual(surfaceLine.ReferenceLineIntersectionWorldPoint.X, entity.ReferenceLineIntersectionX); + Assert.AreEqual(surfaceLine.ReferenceLineIntersectionWorldPoint.Y, entity.ReferenceLineIntersectionY); + + string expectedXml = new Point3DCollectionXmlSerializer().ToXml(geometry); + Assert.AreEqual(expectedXml, entity.PointsXml); + + Assert.AreEqual(12, entity.MacroStabilityInwardsCharacteristicPointEntities.Count); + foreach (MacroStabilityInwardsCharacteristicPointEntity characteristicPointEntity in entity.MacroStabilityInwardsCharacteristicPointEntities) + { + switch (characteristicPointEntity.Type) + { + case (byte) MacroStabilityInwardsCharacteristicPointType.SurfaceLevelOutside: + Assert.AreEqual(geometry[surfaceLevelOutsideIndex].X, characteristicPointEntity.X); + Assert.AreEqual(geometry[surfaceLevelOutsideIndex].Y, characteristicPointEntity.Y); + Assert.AreEqual(geometry[surfaceLevelOutsideIndex].Z, characteristicPointEntity.Z); + break; + case (byte) MacroStabilityInwardsCharacteristicPointType.DikeTopAtPolder: + Assert.AreEqual(geometry[dikeTopAtPolderIndex].X, characteristicPointEntity.X); + Assert.AreEqual(geometry[dikeTopAtPolderIndex].Y, characteristicPointEntity.Y); + Assert.AreEqual(geometry[dikeTopAtPolderIndex].Z, characteristicPointEntity.Z); + break; + case (byte) MacroStabilityInwardsCharacteristicPointType.DikeTopAtRiver: + Assert.AreEqual(geometry[dikeTopAtRiverIndex].X, characteristicPointEntity.X); + Assert.AreEqual(geometry[dikeTopAtRiverIndex].Y, characteristicPointEntity.Y); + Assert.AreEqual(geometry[dikeTopAtRiverIndex].Z, characteristicPointEntity.Z); + break; + case (byte) MacroStabilityInwardsCharacteristicPointType.ShoulderBaseInside: + Assert.AreEqual(geometry[shoulderBaseInsideIndex].X, characteristicPointEntity.X); + Assert.AreEqual(geometry[shoulderBaseInsideIndex].Y, characteristicPointEntity.Y); + Assert.AreEqual(geometry[shoulderBaseInsideIndex].Z, characteristicPointEntity.Z); + break; + case (byte) MacroStabilityInwardsCharacteristicPointType.ShoulderTopInside: + Assert.AreEqual(geometry[shoulderTopInsideIndex].X, characteristicPointEntity.X); + Assert.AreEqual(geometry[shoulderTopInsideIndex].Y, characteristicPointEntity.Y); + Assert.AreEqual(geometry[shoulderTopInsideIndex].Z, characteristicPointEntity.Z); + break; + case (byte) MacroStabilityInwardsCharacteristicPointType.BottomDitchDikeSide: + Assert.AreEqual(geometry[bottomDitchDikeSideIndex].X, characteristicPointEntity.X); + Assert.AreEqual(geometry[bottomDitchDikeSideIndex].Y, characteristicPointEntity.Y); + Assert.AreEqual(geometry[bottomDitchDikeSideIndex].Z, characteristicPointEntity.Z); + break; + case (byte) MacroStabilityInwardsCharacteristicPointType.BottomDitchPolderSide: + Assert.AreEqual(geometry[bottomDitchPolderSideIndex].X, characteristicPointEntity.X); + Assert.AreEqual(geometry[bottomDitchPolderSideIndex].Y, characteristicPointEntity.Y); + Assert.AreEqual(geometry[bottomDitchPolderSideIndex].Z, characteristicPointEntity.Z); + break; + case (byte) MacroStabilityInwardsCharacteristicPointType.DikeToeAtPolder: + Assert.AreEqual(geometry[dikeToeAtPolderIndex].X, characteristicPointEntity.X); + Assert.AreEqual(geometry[dikeToeAtPolderIndex].Y, characteristicPointEntity.Y); + Assert.AreEqual(geometry[dikeToeAtPolderIndex].Z, characteristicPointEntity.Z); + break; + case (byte) MacroStabilityInwardsCharacteristicPointType.DikeToeAtRiver: + Assert.AreEqual(geometry[dikeToeAtRiverIndex].X, characteristicPointEntity.X); + Assert.AreEqual(geometry[dikeToeAtRiverIndex].Y, characteristicPointEntity.Y); + Assert.AreEqual(geometry[dikeToeAtRiverIndex].Z, characteristicPointEntity.Z); + break; + case (byte) MacroStabilityInwardsCharacteristicPointType.DitchDikeSide: + Assert.AreEqual(geometry[ditchDikeSideIndex].X, characteristicPointEntity.X); + Assert.AreEqual(geometry[ditchDikeSideIndex].Y, characteristicPointEntity.Y); + Assert.AreEqual(geometry[ditchDikeSideIndex].Z, characteristicPointEntity.Z); + break; + case (byte) MacroStabilityInwardsCharacteristicPointType.DitchPolderSide: + Assert.AreEqual(geometry[ditchPolderSideIndex].X, characteristicPointEntity.X); + Assert.AreEqual(geometry[ditchPolderSideIndex].Y, characteristicPointEntity.Y); + Assert.AreEqual(geometry[ditchPolderSideIndex].Z, characteristicPointEntity.Z); + break; + case (byte) MacroStabilityInwardsCharacteristicPointType.SurfaceLevelInside: + Assert.AreEqual(geometry[surfaceLevelInsideIndex].X, characteristicPointEntity.X); + Assert.AreEqual(geometry[surfaceLevelInsideIndex].Y, characteristicPointEntity.Y); + Assert.AreEqual(geometry[surfaceLevelInsideIndex].Z, characteristicPointEntity.Z); + break; + default: + Assert.Fail("Invalid characteristic point type found: {0}", characteristicPointEntity.Type); + break; + } + } + } + + [Test] + public void Create_SurfaceLineWithCharacteristicPointsOnSameGeometryPoint_ReturnSurfaceLineEntityWithPointEntitiesAndCharactersisticPointReferences() + { + // Setup + var random = new Random(31); + var registry = new PersistenceRegistry(); + Point3D[] geometry = + { + GetRandomPoint3D(random) + }; + var surfaceLine = new MacroStabilityInwardsSurfaceLine("Test") + { + ReferenceLineIntersectionWorldPoint = new Point2D(random.NextDouble(), random.NextDouble()) + }; + surfaceLine.SetGeometry(geometry); + surfaceLine.SetSurfaceLevelOutsideAt(geometry[0]); + surfaceLine.SetDikeTopAtPolderAt(geometry[0]); + surfaceLine.SetDikeTopAtRiverAt(geometry[0]); + surfaceLine.SetShoulderBaseInsideAt(geometry[0]); + surfaceLine.SetShoulderTopInsideAt(geometry[0]); + surfaceLine.SetBottomDitchDikeSideAt(geometry[0]); + surfaceLine.SetBottomDitchPolderSideAt(geometry[0]); + surfaceLine.SetDikeToeAtPolderAt(geometry[0]); + surfaceLine.SetDikeToeAtRiverAt(geometry[0]); + surfaceLine.SetDitchDikeSideAt(geometry[0]); + surfaceLine.SetDitchPolderSideAt(geometry[0]); + surfaceLine.SetSurfaceLevelInsideAt(geometry[0]); + + // Call + SurfaceLineEntity entity = surfaceLine.Create(registry, 0); + + // Assert + Assert.AreEqual(surfaceLine.Name, entity.Name); + Assert.AreEqual(surfaceLine.ReferenceLineIntersectionWorldPoint.X, entity.ReferenceLineIntersectionX); + Assert.AreEqual(surfaceLine.ReferenceLineIntersectionWorldPoint.Y, entity.ReferenceLineIntersectionY); + + string expectedXml = new Point3DCollectionXmlSerializer().ToXml(geometry); + Assert.AreEqual(expectedXml, entity.PointsXml); + + Assert.AreEqual(12, entity.MacroStabilityInwardsCharacteristicPointEntities.Count); + CollectionAssert.AreEquivalent(new[] + { + (byte) MacroStabilityInwardsCharacteristicPointType.SurfaceLevelOutside, + (byte) MacroStabilityInwardsCharacteristicPointType.DikeTopAtPolder, + (byte) MacroStabilityInwardsCharacteristicPointType.DikeTopAtRiver, + (byte) MacroStabilityInwardsCharacteristicPointType.ShoulderBaseInside, + (byte) MacroStabilityInwardsCharacteristicPointType.ShoulderTopInside, + (byte) MacroStabilityInwardsCharacteristicPointType.BottomDitchDikeSide, + (byte) MacroStabilityInwardsCharacteristicPointType.BottomDitchPolderSide, + (byte) MacroStabilityInwardsCharacteristicPointType.DikeToeAtPolder, + (byte) MacroStabilityInwardsCharacteristicPointType.DikeToeAtRiver, + (byte) MacroStabilityInwardsCharacteristicPointType.DitchDikeSide, + (byte) MacroStabilityInwardsCharacteristicPointType.DitchPolderSide, + (byte) MacroStabilityInwardsCharacteristicPointType.SurfaceLevelInside + }, entity.MacroStabilityInwardsCharacteristicPointEntities + .Select(cpe => cpe.Type)); + + foreach (MacroStabilityInwardsCharacteristicPointEntity characteristicPointEntity in entity.MacroStabilityInwardsCharacteristicPointEntities) + { + Assert.AreEqual(geometry[0].X, characteristicPointEntity.X); + Assert.AreEqual(geometry[0].Y, characteristicPointEntity.Y); + Assert.AreEqual(geometry[0].Z, characteristicPointEntity.Z); + } + } + + [Test] + public void Create_CreatingEntityForSameSurfaceLine_ReturnSameEntity() + { + // Setup + var surfaceLine = new MacroStabilityInwardsSurfaceLine(string.Empty); + var registry = new PersistenceRegistry(); + + // Call + SurfaceLineEntity entity1 = surfaceLine.Create(registry, 0); + SurfaceLineEntity entity2 = surfaceLine.Create(registry, 0); + + // Assert + Assert.AreSame(entity1, entity2); + } + + private static Point3D GetRandomPoint3D(Random random) + { + return new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()); + } + + private static Point2D GetRandomPoint2D(Random random) + { + return new Point2D(random.NextDouble(), random.NextDouble()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacrostabilityOutwards/MacroStabilityOutwardsFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacrostabilityOutwards/MacroStabilityOutwardsFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacrostabilityOutwards/MacroStabilityOutwardsFailureMechanismCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,184 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Integration.Data.StandAlone; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.MacroStabilityOutwards; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.MacroStabilityOutwards +{ + [TestFixture] + public class MacroStabilityOutwardsFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + public void Create_WithoutAllPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet() + { + // Setup + var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.MacroStabilityOutwards, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(failureMechanism.IsRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + + CollectionAssert.IsEmpty(entity.StochasticSoilModelEntities); + MacroStabilityOutwardsFailureMechanismMetaEntity failureMechanismMetaEntity = entity.MacroStabilityOutwardsFailureMechanismMetaEntities.First(); + Assert.AreEqual(failureMechanism.MacroStabilityOutwardsProbabilityAssessmentInput.A, failureMechanismMetaEntity.A); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet(bool isRelevant) + { + // Setup + var random = new Random(31); + var failureMechanism = new MacroStabilityOutwardsFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + }, + MacroStabilityOutwardsProbabilityAssessmentInput = + { + A = random.NextDouble() + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.MacroStabilityOutwards, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + MacroStabilityOutwardsFailureMechanismMetaEntity failureMechanismMetaEntity = entity.MacroStabilityOutwardsFailureMechanismMetaEntities.First(); + Assert.AreEqual(failureMechanism.MacroStabilityOutwardsProbabilityAssessmentInput.A, failureMechanismMetaEntity.A); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + var failureMechanism = new MacroStabilityOutwardsFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + TestHelper.AssertAreEqualButNotSame(originalInput, entity.InputComments); + TestHelper.AssertAreEqualButNotSame(originalOutput, entity.OutputComments); + TestHelper.AssertAreEqualButNotSame(originalNotRelevantText, entity.NotRelevantComments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + Assert.IsNull(entity.FailureMechanismSectionCollectionSourcePath); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + const string filePath = "failureMechanismSection/File/Path"; + var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); + failureMechanism.SetSections(new[] + { + FailureMechanismSectionTestFactory.CreateFailureMechanismSection() + }, filePath); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.MacroStabilityOutwardsSectionResultEntities).Count()); + TestHelper.AssertAreEqualButNotSame(filePath, entity.FailureMechanismSectionCollectionSourcePath); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacrostabilityOutwards/MacroStabilityOutwardsFailureMechanismSectionResultCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacrostabilityOutwards/MacroStabilityOutwardsFailureMechanismSectionResultCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/MacrostabilityOutwards/MacroStabilityOutwardsFailureMechanismSectionResultCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,102 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.Integration.Data.StandAlone.SectionResults; +using Riskeer.Storage.Core.Create.MacroStabilityOutwards; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.MacroStabilityOutwards +{ + [TestFixture] + public class MacroStabilityOutwardsFailureMechanismSectionResultCreateExtensionsTest + { + [Test] + public void Create_SectionResultNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((MacroStabilityOutwardsFailureMechanismSectionResult) null).Create(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("result", exception.ParamName); + } + + [Test] + public void Create_WithDifferentResults_ReturnsEntityWithExpectedResults() + { + // Setup + var random = new Random(39); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResult = random.NextEnumValue(); + double detailedAssessmentProbability = random.NextDouble(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + double tailorMadeAssessmentProbability = random.NextDouble(); + bool useManualAssembly = random.NextBoolean(); + var manualAssemblyCategoryGroup = random.NextEnumValue(); + + var sectionResult = new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + SimpleAssessmentResult = simpleAssessmentResult, + DetailedAssessmentResult = detailedAssessmentResult, + DetailedAssessmentProbability = detailedAssessmentProbability, + TailorMadeAssessmentResult = tailorMadeAssessmentResult, + TailorMadeAssessmentProbability = tailorMadeAssessmentProbability, + UseManualAssembly = useManualAssembly, + ManualAssemblyCategoryGroup = manualAssemblyCategoryGroup + }; + + // Call + MacroStabilityOutwardsSectionResultEntity entity = sectionResult.Create(); + + // Assert + Assert.AreEqual(Convert.ToByte(simpleAssessmentResult), entity.SimpleAssessmentResult); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResult), entity.DetailedAssessmentResult); + Assert.AreEqual(detailedAssessmentProbability, entity.DetailedAssessmentProbability); + Assert.AreEqual(Convert.ToByte(tailorMadeAssessmentResult), entity.TailorMadeAssessmentResult); + Assert.AreEqual(tailorMadeAssessmentProbability, entity.TailorMadeAssessmentProbability); + Assert.AreEqual(Convert.ToByte(useManualAssembly), entity.UseManualAssembly); + Assert.AreEqual(Convert.ToByte(manualAssemblyCategoryGroup), entity.ManualAssemblyCategoryGroup); + } + + [Test] + public void Create_WithNaNProbabilities_ReturnsEntityWithExpectedResults() + { + // Setup + var sectionResult = new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + DetailedAssessmentProbability = double.NaN, + TailorMadeAssessmentProbability = double.NaN + }; + + // Call + MacroStabilityOutwardsSectionResultEntity result = sectionResult.Create(); + + // Assert + Assert.IsNull(result.DetailedAssessmentProbability); + Assert.IsNull(result.TailorMadeAssessmentProbability); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Microstability/MicrostabilityFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Microstability/MicrostabilityFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Microstability/MicrostabilityFailureMechanismCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,154 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Integration.Data.StandAlone; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.Microstability; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.Microstability +{ + [TestFixture] + public class MicrostabilityFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new MicrostabilityFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet(bool isRelevant) + { + // Setup + var failureMechanism = new MicrostabilityFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.Microstability, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + var failureMechanism = new MicrostabilityFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + TestHelper.AssertAreEqualButNotSame(failureMechanism.InputComments.Body, entity.InputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.OutputComments.Body, entity.OutputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new MicrostabilityFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + Assert.IsNull(entity.FailureMechanismSectionCollectionSourcePath); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + const string filePath = "failureMechanismSections/File/Path"; + var failureMechanism = new MicrostabilityFailureMechanism(); + failureMechanism.SetSections(new[] + { + FailureMechanismSectionTestFactory.CreateFailureMechanismSection() + }, filePath); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.MicrostabilitySectionResultEntities).Count()); + TestHelper.AssertAreEqualButNotSame(filePath, entity.FailureMechanismSectionCollectionSourcePath); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Microstability/MicrostabilityFailureMechanismSectionResultCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Microstability/MicrostabilityFailureMechanismSectionResultCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Microstability/MicrostabilityFailureMechanismSectionResultCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,78 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.Integration.Data.StandAlone.SectionResults; +using Riskeer.Storage.Core.Create.Microstability; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.Microstability +{ + [TestFixture] + public class MicrostabilityFailureMechanismSectionResultCreateExtensionsTest + { + [Test] + public void Create_SectionResultNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((MicrostabilityFailureMechanismSectionResult) null).Create(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("result", exception.ParamName); + } + + [Test] + public void Create_WithDifferentResults_ReturnsEntityWithExpectedResults() + { + // Setup + var random = new Random(39); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResult = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + bool useManualAssembly = random.NextBoolean(); + var manualAssemblyCategoryGroup = random.NextEnumValue(); + + var sectionResult = new MicrostabilityFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + SimpleAssessmentResult = simpleAssessmentResult, + DetailedAssessmentResult = detailedAssessmentResult, + TailorMadeAssessmentResult = tailorMadeAssessmentResult, + UseManualAssembly = useManualAssembly, + ManualAssemblyCategoryGroup = manualAssemblyCategoryGroup + }; + + // Call + MicrostabilitySectionResultEntity entity = sectionResult.Create(); + + // Assert + Assert.AreEqual(Convert.ToByte(simpleAssessmentResult), entity.SimpleAssessmentResult); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResult), entity.DetailedAssessmentResult); + Assert.AreEqual(Convert.ToByte(tailorMadeAssessmentResult), entity.TailorMadeAssessmentResult); + Assert.AreEqual(Convert.ToByte(useManualAssembly), entity.UseManualAssembly); + Assert.AreEqual(Convert.ToByte(manualAssemblyCategoryGroup), entity.ManualAssemblyCategoryGroup); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/PersistenceRegistryTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/PersistenceRegistryTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/PersistenceRegistryTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,629 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Geometry; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.ClosingStructures.Data; +using Ringtoets.ClosingStructures.Data.TestUtil; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.DuneErosion.Data; +using Ringtoets.DuneErosion.Data.TestUtil; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.HeightStructures.Data; +using Ringtoets.HeightStructures.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Data.SoilProfile; +using Ringtoets.MacroStabilityInwards.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Data.TestUtil.SoilProfile; +using Ringtoets.MacroStabilityInwards.Primitives; +using Ringtoets.Piping.Data.SoilProfile; +using Ringtoets.Piping.Data.TestUtil; +using Ringtoets.Piping.Primitives; +using Ringtoets.Piping.Primitives.TestUtil; +using Ringtoets.StabilityPointStructures.Data; +using Ringtoets.StabilityPointStructures.Data.TestUtil; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create +{ + [TestFixture] + public class PersistenceRegistryTest + { + /// + /// Test class to test the for the combination of + /// and . + /// + /// The data model. + /// The database entity. + private abstract class RegistryTest where TDataModel : class + where TEntity : class, new() + { + private readonly Action registerToRegistry; + private readonly Func containsInRegistry; + private readonly Func getFromRegistry; + + /// + /// Creates a new instance of . + /// + /// The action to perform to register the data model + /// to the registry. + /// The action to perform to check whether the data + /// model is registered in the registry. + /// The action to perform to get the data model from + /// the registry. + /// Thrown when any parameter is null. + /// + /// public DerivedRegistryTest() : base( + /// (r, e, m) => r.Register(e, m), + /// (r, m) => r.Contains(m), + /// (r, m) => r.Get(m)) {} + /// + /// + protected RegistryTest(Action registerToRegistry, + Func containsInRegistry, + Func getFromRegistry) + { + if (registerToRegistry == null) + { + throw new ArgumentNullException(nameof(registerToRegistry)); + } + + if (containsInRegistry == null) + { + throw new ArgumentNullException(nameof(containsInRegistry)); + } + + if (getFromRegistry == null) + { + throw new ArgumentNullException(nameof(getFromRegistry)); + } + + this.registerToRegistry = registerToRegistry; + this.containsInRegistry = containsInRegistry; + this.getFromRegistry = getFromRegistry; + } + + [Test] + public void Register_WithNullEntity_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => registerToRegistry(registry, null, CreateDataModel()); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Register_WithNullDataModel_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => registerToRegistry(registry, new TEntity(), null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + + [Test] + public void Contains_DataModelNull_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => containsInRegistry(registry, null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + + [Test] + public void Contains_DataModelAdded_ReturnsTrue() + { + // Setup + var registry = new PersistenceRegistry(); + TDataModel dataModel = CreateDataModel(); + registerToRegistry(registry, new TEntity(), dataModel); + + // Call + bool result = containsInRegistry(registry, dataModel); + + // Assert + Assert.IsTrue(result); + } + + [Test] + public void Contains_OtherDataModelAdded_ReturnsFalse() + { + // Setup + var registry = new PersistenceRegistry(); + registerToRegistry(registry, new TEntity(), CreateDataModel()); + + // Call + bool result = containsInRegistry(registry, CreateDataModel()); + + // Assert + Assert.IsFalse(result); + } + + [Test] + public void Contains_PersistenceRegistryEmpty_ReturnsFalse() + { + // Setup + var registry = new PersistenceRegistry(); + TDataModel dataModel = CreateDataModel(); + + // Call + bool result = containsInRegistry(registry, dataModel); + + // Assert + Assert.IsFalse(result); + } + + [Test] + public void Get_DataModelNull_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => getFromRegistry(registry, null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + + [Test] + public void Get_DataModelAdded_ReturnsEntity() + { + // Setup + var registry = new PersistenceRegistry(); + TDataModel dataModel = CreateDataModel(); + var entity = new TEntity(); + + registerToRegistry(registry, entity, dataModel); + + // Call + TEntity result = getFromRegistry(registry, dataModel); + + // Assert + Assert.AreSame(entity, result); + } + + [Test] + public void Get_NoDataModelAdded_ThrowsInvalidOperationException() + { + // Setup + var registry = new PersistenceRegistry(); + TDataModel dataModel = CreateDataModel(); + + // Call + TestDelegate test = () => getFromRegistry(registry, dataModel); + + // Assert + Assert.Throws(test); + } + + [Test] + public void Get_OtherDataModelAdded_ThrowsInvalidOperationException() + { + // Setup + var registry = new PersistenceRegistry(); + registerToRegistry(registry, new TEntity(), CreateDataModel()); + + // Call + TestDelegate test = () => getFromRegistry(registry, CreateDataModel()); + + // Assert + Assert.Throws(test); + } + + /// + /// Creates a new instance of . + /// + /// An instance of . + protected abstract TDataModel CreateDataModel(); + } + + [TestFixture] + private class HydraulicBoundaryLocationRegistryTest : RegistryTest + { + public HydraulicBoundaryLocationRegistryTest() : base( + (r, e, m) => r.Register(e, m), + (r, m) => r.Contains(m), + (r, m) => r.Get(m)) {} + + protected override HydraulicBoundaryLocation CreateDataModel() + { + return new TestHydraulicBoundaryLocation(nameof(HydraulicBoundaryLocation)); + } + } + + [TestFixture] + private class FailureMechanismSectionRegistryTest : RegistryTest + { + public FailureMechanismSectionRegistryTest() : base( + (r, e, m) => r.Register(e, m), + (r, m) => r.Contains(m), + (r, m) => r.Get(m)) {} + + protected override FailureMechanismSection CreateDataModel() + { + return FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + } + } + + [TestFixture] + private class DikeProfileRegistryTest : RegistryTest + { + public DikeProfileRegistryTest() : base( + (r, e, m) => r.Register(e, m), + (r, m) => r.Contains(m), + (r, m) => r.Get(m)) {} + + protected override DikeProfile CreateDataModel() + { + return DikeProfileTestFactory.CreateDikeProfile(); + } + } + + [TestFixture] + private class ForeshoreProfileRegistryTest : RegistryTest + { + public ForeshoreProfileRegistryTest() : base( + (r, e, m) => r.Register(e, m), + (r, m) => r.Contains(m), + (r, m) => r.Get(m)) {} + + protected override ForeshoreProfile CreateDataModel() + { + return new TestForeshoreProfile(); + } + } + + #region DuneErosion + + [TestFixture] + private class DuneLocationRegistryTest : RegistryTest + { + public DuneLocationRegistryTest() : base( + (r, e, m) => r.Register(e, m), + (r, m) => r.Contains(m), + (r, m) => r.Get(m)) {} + + protected override DuneLocation CreateDataModel() + { + return new TestDuneLocation(nameof(DuneLocation)); + } + } + + #endregion + + #region GrassCoverErosionInwards + + [TestFixture] + private class GrassCoverErosionInwardsCalculationRegistryTest : RegistryTest< + GrassCoverErosionInwardsCalculation, GrassCoverErosionInwardsCalculationEntity> + { + public GrassCoverErosionInwardsCalculationRegistryTest() : base( + (r, e, m) => r.Register(e, m), + (r, m) => r.Contains(m), + (r, m) => r.Get(m)) {} + + protected override GrassCoverErosionInwardsCalculation CreateDataModel() + { + return new GrassCoverErosionInwardsCalculation(); + } + } + + #endregion + + #region Piping + + [TestFixture] + private class PipingStochasticSoilModelRegistryTest : RegistryTest + { + public PipingStochasticSoilModelRegistryTest() : base( + (r, e, m) => r.Register(e, m), + (r, m) => r.Contains(m), + (r, m) => r.Get(m)) {} + + protected override PipingStochasticSoilModel CreateDataModel() + { + return PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel(nameof(PipingStochasticSoilModel)); + } + } + + [TestFixture] + private class PipingStochasticSoilProfileRegistryTest : RegistryTest + { + public PipingStochasticSoilProfileRegistryTest() : base( + (r, e, m) => r.Register(e, m), + (r, m) => r.Contains(m), + (r, m) => r.Get(m)) {} + + protected override PipingStochasticSoilProfile CreateDataModel() + { + return new PipingStochasticSoilProfile(0.2, PipingSoilProfileTestFactory.CreatePipingSoilProfile()); + } + } + + [TestFixture] + private class PipingSoilProfileRegistryTest : RegistryTest + { + public PipingSoilProfileRegistryTest() : base( + (r, e, m) => r.Register(e, m), + (r, m) => r.Contains(m), + (r, m) => r.Get(m)) {} + + protected override PipingSoilProfile CreateDataModel() + { + return PipingSoilProfileTestFactory.CreatePipingSoilProfile(); + } + } + + [TestFixture] + private class PipingSurfaceLineRegistryTest : RegistryTest + { + public PipingSurfaceLineRegistryTest() : base( + (r, e, m) => r.Register(e, m), + (r, m) => r.Contains(m), + (r, m) => r.Get(m)) {} + + protected override PipingSurfaceLine CreateDataModel() + { + return new PipingSurfaceLine(nameof(PipingSurfaceLine)); + } + } + + #endregion + + #region MacroStabilityInwards + + [TestFixture] + private class MacroStabilityInwardsStochasticSoilModelRegistryTest : RegistryTest + { + public MacroStabilityInwardsStochasticSoilModelRegistryTest() : base( + (r, e, m) => r.Register(e, m), + (r, m) => r.Contains(m), + (r, m) => r.Get(m)) {} + + protected override MacroStabilityInwardsStochasticSoilModel CreateDataModel() + { + return MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel(nameof(MacroStabilityInwardsStochasticSoilModel)); + } + } + + [TestFixture] + private class MacroStabilityInwardsStochasticSoilProfileRegistryTest : RegistryTest + { + private MockRepository mockRepository; + + [SetUp] + public void Setup() + { + mockRepository = new MockRepository(); + } + + [TearDown] + public void TearDown() + { + mockRepository.VerifyAll(); + } + + public MacroStabilityInwardsStochasticSoilProfileRegistryTest() : base( + (r, e, m) => r.Register(e, m), + (r, m) => r.Contains(m), + (r, m) => r.Get(m)) {} + + protected override MacroStabilityInwardsStochasticSoilProfile CreateDataModel() + { + var soilProfile = mockRepository.Stub>(); + mockRepository.ReplayAll(); + + return new MacroStabilityInwardsStochasticSoilProfile(0, soilProfile); + } + } + + [TestFixture] + private class MacroStabilityInwardsSoilProfileOneDRegistryTest : RegistryTest + { + public MacroStabilityInwardsSoilProfileOneDRegistryTest() : base( + (r, e, m) => r.Register(e, m), + (r, m) => r.Contains(m), + (r, m) => r.Get(m)) {} + + protected override MacroStabilityInwardsSoilProfile1D CreateDataModel() + { + return MacroStabilityInwardsSoilProfile1DTestFactory.CreateMacroStabilityInwardsSoilProfile1D(); + } + } + + [TestFixture] + private class MacroStabilityInwardsSoilProfileTwoDRegistryTest : RegistryTest + { + public MacroStabilityInwardsSoilProfileTwoDRegistryTest() : base( + (r, e, m) => r.Register(e, m), + (r, m) => r.Contains(m), + (r, m) => r.Get(m)) {} + + protected override MacroStabilityInwardsSoilProfile2D CreateDataModel() + { + return new MacroStabilityInwardsSoilProfile2D("", new[] + { + new MacroStabilityInwardsSoilLayer2D(new Ring(new[] + { + new Point2D(0, 0), + new Point2D(1, 1) + })) + }, Enumerable.Empty()); + } + } + + [TestFixture] + private class MacroStabilityInwardsSurfaceLineRegistryTest : RegistryTest + { + public MacroStabilityInwardsSurfaceLineRegistryTest() : base( + (r, e, m) => r.Register(e, m), + (r, m) => r.Contains(m), + (r, m) => r.Get(m)) {} + + protected override MacroStabilityInwardsSurfaceLine CreateDataModel() + { + return new MacroStabilityInwardsSurfaceLine(nameof(MacroStabilityInwardsSurfaceLine)); + } + } + + #endregion + + #region HeightStructures + + #region StabilityPointStructures + + [TestFixture] + private class StabilityPointStructureStructureRegistryTest : RegistryTest< + StabilityPointStructure, StabilityPointStructureEntity> + { + public StabilityPointStructureStructureRegistryTest() : base( + (r, e, m) => r.Register(e, m), + (r, m) => r.Contains(m), + (r, m) => r.Get(m)) {} + + protected override StabilityPointStructure CreateDataModel() + { + return new TestStabilityPointStructure(); + } + } + + [TestFixture] + private class StabilityPointStructuresCalculationRegistryTest : RegistryTest< + StructuresCalculation, StabilityPointStructuresCalculationEntity> + { + public StabilityPointStructuresCalculationRegistryTest() : base( + (r, e, m) => r.Register(e, m), + (r, m) => r.Contains(m), + (r, m) => r.Get(m)) {} + + protected override StructuresCalculation CreateDataModel() + { + return new StructuresCalculation(); + } + } + + #endregion + + [TestFixture] + private class HeightStructureRegistryTest : RegistryTest< + HeightStructure, HeightStructureEntity> + { + public HeightStructureRegistryTest() : base( + (r, e, m) => r.Register(e, m), + (r, m) => r.Contains(m), + (r, m) => r.Get(m)) {} + + protected override HeightStructure CreateDataModel() + { + return new TestHeightStructure(); + } + } + + [TestFixture] + private class HeightStructuresCalculationRegistryTest : RegistryTest< + StructuresCalculation, HeightStructuresCalculationEntity> + { + public HeightStructuresCalculationRegistryTest() : base( + (r, e, m) => r.Register(e, m), + (r, m) => r.Contains(m), + (r, m) => r.Get(m)) {} + + protected override StructuresCalculation CreateDataModel() + { + return new StructuresCalculation(); + } + } + + #endregion + + #region ClosingStructures + + [TestFixture] + private class ClosingStructureRegistryTest : RegistryTest< + ClosingStructure, ClosingStructureEntity> + { + public ClosingStructureRegistryTest() : base( + (r, e, m) => r.Register(e, m), + (r, m) => r.Contains(m), + (r, m) => r.Get(m)) {} + + protected override ClosingStructure CreateDataModel() + { + return new TestClosingStructure(); + } + } + + [TestFixture] + private class ClosingStructuresCalculationRegistryTest : RegistryTest< + StructuresCalculation, ClosingStructuresCalculationEntity> + { + public ClosingStructuresCalculationRegistryTest() : base( + (r, e, m) => r.Register(e, m), + (r, m) => r.Contains(m), + (r, m) => r.Get(m)) {} + + protected override StructuresCalculation CreateDataModel() + { + return new StructuresCalculation(); + } + } + + #endregion + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/PipingCalculationScenarioCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/PipingCalculationScenarioCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/PipingCalculationScenarioCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,274 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Data.SoilProfile; +using Ringtoets.Piping.Data.TestUtil; +using Ringtoets.Piping.Primitives; +using Ringtoets.Piping.Primitives.TestUtil; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.Piping; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.Piping +{ + [TestFixture] + public class PipingCalculationScenarioCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryIsNull_ThrowArgumentNullException() + { + // Setup + var calculation = new PipingCalculationScenario(new GeneralPipingInput()); + + // Call + TestDelegate call = () => calculation.Create(null, 0); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual(paramName, "registry"); + } + + [Test] + [TestCase(true, false, 0.0, "A", "", 2.2, 0.0, 5.8, 123, 827364)] + [TestCase(false, true, 1.0, null, null, double.NaN, double.NaN, double.NaN, 980754, 231)] + public void Create_PipingCalculationScenarioWithPropertiesSet_ReturnPipingCalculationEntity( + bool isRelevant, bool useAssessmentLevelManualInput, double contribution, string name, string comments, + double exitPoint, double entryPoint, double assessmentLevel, int order, int randomSeed) + { + // Setup + var random = new Random(randomSeed); + + var calculation = new PipingCalculationScenario(new GeneralPipingInput()) + { + IsRelevant = isRelevant, + Contribution = (RoundedDouble) contribution, + Name = name, + Comments = + { + Body = comments + }, + InputParameters = + { + ExitPointL = (RoundedDouble) exitPoint, + EntryPointL = (RoundedDouble) entryPoint, + PhreaticLevelExit = + { + Mean = random.NextRoundedDouble(-9999.9999, 9999.9999), + StandardDeviation = random.NextRoundedDouble(1e-6, 9999.9999) + }, + DampingFactorExit = + { + Mean = random.NextRoundedDouble(1e-6, 9999.9999), + StandardDeviation = random.NextRoundedDouble(1e-6, 9999.9999) + }, + UseAssessmentLevelManualInput = useAssessmentLevelManualInput, + AssessmentLevel = (RoundedDouble) assessmentLevel + } + }; + + var registry = new PersistenceRegistry(); + + // Call + PipingCalculationEntity entity = calculation.Create(registry, order); + + // Assert + Assert.AreEqual(Convert.ToByte(isRelevant), entity.RelevantForScenario); + Assert.AreEqual(contribution, entity.ScenarioContribution); + Assert.AreEqual(name, entity.Name); + Assert.AreEqual(comments, entity.Comments); + + Assert.AreEqual(exitPoint.ToNaNAsNull(), entity.ExitPointL); + Assert.AreEqual(entryPoint.ToNaNAsNull(), entity.EntryPointL); + + PipingInput input = calculation.InputParameters; + Assert.AreEqual(input.PhreaticLevelExit.Mean.Value, entity.PhreaticLevelExitMean); + Assert.AreEqual(input.PhreaticLevelExit.StandardDeviation.Value, entity.PhreaticLevelExitStandardDeviation); + Assert.AreEqual(input.DampingFactorExit.Mean.Value, entity.DampingFactorExitMean); + Assert.AreEqual(input.DampingFactorExit.StandardDeviation.Value, entity.DampingFactorExitStandardDeviation); + + Assert.AreEqual(Convert.ToByte(input.UseAssessmentLevelManualInput), entity.UseAssessmentLevelManualInput); + Assert.AreEqual(input.AssessmentLevel.ToNaNAsNull(), entity.AssessmentLevel); + + Assert.AreEqual(order, entity.Order); + Assert.AreEqual(0, entity.PipingCalculationEntityId); + Assert.IsNull(entity.CalculationGroupEntity); + + Assert.IsNull(entity.SurfaceLineEntity); + Assert.IsNull(entity.PipingStochasticSoilProfileEntity); + Assert.IsNull(entity.HydraulicLocationEntityId); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string name = "A"; + const string comments = "B"; + var calculation = new PipingCalculationScenario(new GeneralPipingInput()) + { + Name = name, + Comments = + { + Body = comments + } + }; + + var registry = new PersistenceRegistry(); + + // Call + PipingCalculationEntity entity = calculation.Create(registry, 0); + + // Assert + TestHelper.AssertAreEqualButNotSame(name, entity.Name); + TestHelper.AssertAreEqualButNotSame(comments, entity.Comments); + } + + [Test] + public void Create_HasSurfaceLineSet_EntityHasSurfaceLineEntity() + { + // Setup + var surfaceLine = new PipingSurfaceLine(string.Empty) + { + ReferenceLineIntersectionWorldPoint = new Point2D(1.1, 2.2) + }; + surfaceLine.SetGeometry(new[] + { + new Point3D(0.0, 0.0, 1.0), + new Point3D(3.3, 6.6, 1.0) + }); + + var registry = new PersistenceRegistry(); + SurfaceLineEntity surfaceLineEntity = surfaceLine.Create(registry, 0); + + var calculation = new PipingCalculationScenario(new GeneralPipingInput()) + { + InputParameters = + { + SurfaceLine = surfaceLine + } + }; + + // Call + PipingCalculationEntity entity = calculation.Create(registry, 0); + + // Assert + Assert.AreSame(surfaceLineEntity, entity.SurfaceLineEntity); + } + + [Test] + public void Create_HydraulicBoundaryLocation_EntityHasHydraulicLocationEntity() + { + // Setup + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "A", 2.3, 4.5); + + var registry = new PersistenceRegistry(); + HydraulicLocationEntity hydraulicLocationEntity = hydraulicBoundaryLocation.Create(registry, 0); + + var calculation = new PipingCalculationScenario(new GeneralPipingInput()) + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation + } + }; + + // Call + PipingCalculationEntity entity = calculation.Create(registry, 0); + + // Assert + Assert.AreSame(hydraulicLocationEntity, entity.HydraulicLocationEntity); + } + + [Test] + public void Create_StochasticSoilProfileSet_EntityHasStochasticSoilProfileEntity() + { + // Setup + PipingSoilProfile soilProfile = PipingSoilProfileTestFactory.CreatePipingSoilProfile(); + var stochasticSoilProfile = new PipingStochasticSoilProfile(0.6, soilProfile); + + PipingStochasticSoilModel soilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel("A", new[] + { + stochasticSoilProfile + }); + + var registry = new PersistenceRegistry(); + StochasticSoilModelEntity soilModelEntity = soilModel.Create(registry, 0); + + var calculation = new PipingCalculationScenario(new GeneralPipingInput()) + { + InputParameters = + { + StochasticSoilModel = soilModel, + StochasticSoilProfile = stochasticSoilProfile + } + }; + + // Call + PipingCalculationEntity entity = calculation.Create(registry, 0); + + // Assert + PipingStochasticSoilProfileEntity expectedStochasticSoilProfileEntity = soilModelEntity.PipingStochasticSoilProfileEntities.First(); + Assert.AreSame(expectedStochasticSoilProfileEntity, entity.PipingStochasticSoilProfileEntity); + Assert.IsTrue(registry.Contains(soilModel)); + } + + [Test] + public void Create_HasCalculationOutput_EntityHasPipingCalculationOutputEntity() + { + // Setup + var registry = new PersistenceRegistry(); + + PipingOutput newOutput = PipingOutputTestFactory.Create(); + var calculation = new PipingCalculationScenario(new GeneralPipingInput()) + { + Output = newOutput + }; + + // Call + PipingCalculationEntity entity = calculation.Create(registry, 0); + + // Assert + PipingCalculationOutputEntity outputEntity = entity.PipingCalculationOutputEntities.FirstOrDefault(); + + Assert.IsNotNull(outputEntity); + Assert.AreEqual(newOutput.HeaveFactorOfSafety, outputEntity.HeaveFactorOfSafety); + Assert.AreEqual(newOutput.HeaveZValue, outputEntity.HeaveZValue); + Assert.AreEqual(newOutput.SellmeijerFactorOfSafety, outputEntity.SellmeijerFactorOfSafety); + Assert.AreEqual(newOutput.SellmeijerZValue, outputEntity.SellmeijerZValue); + Assert.AreEqual(newOutput.UpliftFactorOfSafety, outputEntity.UpliftFactorOfSafety); + Assert.AreEqual(newOutput.UpliftZValue, outputEntity.UpliftZValue); + Assert.AreEqual(newOutput.UpliftEffectiveStress, outputEntity.UpliftEffectiveStress, newOutput.UpliftEffectiveStress.GetAccuracy()); + Assert.AreEqual(newOutput.HeaveGradient, outputEntity.HeaveGradient, newOutput.HeaveGradient.GetAccuracy()); + Assert.AreEqual(newOutput.SellmeijerCreepCoefficient, outputEntity.SellmeijerCreepCoefficient, newOutput.SellmeijerCreepCoefficient.GetAccuracy()); + Assert.AreEqual(newOutput.SellmeijerCriticalFall, outputEntity.SellmeijerCriticalFall, newOutput.SellmeijerCriticalFall.GetAccuracy()); + Assert.AreEqual(newOutput.SellmeijerReducedFall, outputEntity.SellmeijerReducedFall, newOutput.SellmeijerReducedFall.GetAccuracy()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/PipingFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/PipingFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/PipingFailureMechanismCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,316 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Data.SoilProfile; +using Ringtoets.Piping.Data.TestUtil; +using Ringtoets.Piping.Primitives; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.Piping; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.Piping +{ + [TestFixture] + public class PipingFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string parameterName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", parameterName); + } + + [Test] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet() + { + // Setup + var random = new Random(31); + var failureMechanism = new PipingFailureMechanism + { + IsRelevant = random.NextBoolean(), + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + }, + PipingProbabilityAssessmentInput = + { + A = random.NextDouble() + }, + GeneralInput = + { + WaterVolumetricWeight = random.NextRoundedDouble(0, 20) + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.Piping, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(failureMechanism.IsRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + CollectionAssert.IsEmpty(entity.StochasticSoilModelEntities); + CollectionAssert.IsEmpty(entity.SurfaceLineEntities); + + PipingFailureMechanismMetaEntity failureMechanismMetaEntity = entity.PipingFailureMechanismMetaEntities.ToArray()[0]; + Assert.AreEqual(failureMechanism.PipingProbabilityAssessmentInput.A, failureMechanismMetaEntity.A); + Assert.AreEqual(failureMechanism.GeneralInput.WaterVolumetricWeight.Value, failureMechanismMetaEntity.WaterVolumetricWeight); + Assert.AreEqual(failureMechanism.SurfaceLines.SourcePath, failureMechanismMetaEntity.SurfaceLineCollectionSourcePath); + Assert.AreEqual(failureMechanism.StochasticSoilModels.SourcePath, failureMechanismMetaEntity.StochasticSoilModelCollectionSourcePath); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + var failureMechanism = new PipingFailureMechanism + { + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + TestHelper.AssertAreEqualButNotSame(failureMechanism.InputComments.Body, entity.InputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.OutputComments.Body, entity.OutputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithStochasticSoilModels_ReturnsFailureMechanismEntityWithStochasticSoilModelEntities() + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + PipingStochasticSoilModelCollection stochasticSoilModels = failureMechanism.StochasticSoilModels; + + stochasticSoilModels.AddRange(new[] + { + PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel("name"), + PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel("name2") + }, "some/path/to/file"); + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(stochasticSoilModels.Count, entity.StochasticSoilModelEntities.Count); + for (var i = 0; i < stochasticSoilModels.Count; i++) + { + AssertStochasticSoilModel(stochasticSoilModels[i], + entity.StochasticSoilModelEntities.ElementAt(i)); + } + + string stochasticSoilModelCollectionSourcePath = entity.PipingFailureMechanismMetaEntities + .Single() + .StochasticSoilModelCollectionSourcePath; + TestHelper.AssertAreEqualButNotSame(stochasticSoilModels.SourcePath, stochasticSoilModelCollectionSourcePath); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.IsNotNull(entity); + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + Assert.IsNull(entity.FailureMechanismSectionCollectionSourcePath); + } + + [Test] + public void Create_WithSections_ReturnsWithFailureMechanismSectionEntitiesAndPipingResultEntities() + { + // Setup + const string filePath = "failureMechanismSections/File/Path"; + var failureMechanism = new PipingFailureMechanism(); + failureMechanism.SetSections(new[] + { + FailureMechanismSectionTestFactory.CreateFailureMechanismSection() + }, filePath); + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.PipingSectionResultEntities).Count()); + TestHelper.AssertAreEqualButNotSame(filePath, entity.FailureMechanismSectionCollectionSourcePath); + } + + [Test] + public void Create_WithSurfaceLines_ReturnFailureMechanismEntityWithSurfaceLineEntities() + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + PipingSurfaceLineCollection surfaceLines = failureMechanism.SurfaceLines; + + surfaceLines.AddRange(new[] + { + CreateSurfaceLine(new Random(31)) + }, "path"); + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(surfaceLines.Count, entity.SurfaceLineEntities.Count); + for (var i = 0; i < surfaceLines.Count; i++) + { + AssertSurfaceLine(surfaceLines[i], entity.SurfaceLineEntities.ElementAt(i)); + } + + string surfaceLineCollectionSourcePath = entity.PipingFailureMechanismMetaEntities + .Single() + .SurfaceLineCollectionSourcePath; + TestHelper.AssertAreEqualButNotSame(surfaceLines.SourcePath, surfaceLineCollectionSourcePath); + } + + [Test] + public void Create_WithCalculationGroup_ReturnFailureMechanismEntityWithCalculationGroupEntities() + { + // Setup + var calculationGroup = new CalculationGroup(); + var calculation = new PipingCalculationScenario(new GeneralPipingInput()); + + var failureMechanism = new PipingFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculationGroup); + failureMechanism.CalculationsGroup.Children.Add(calculation); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(failureMechanism.CalculationsGroup.Name, entity.CalculationGroupEntity.Name); + Assert.AreEqual(0, entity.CalculationGroupEntity.Order); + + CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity.CalculationGroupEntity1 + .OrderBy(cge => cge.Order) + .ToArray(); + Assert.AreEqual(1, childGroupEntities.Length); + CalculationGroupEntity childGroupEntity = childGroupEntities[0]; + Assert.AreEqual(calculationGroup.Name, childGroupEntity.Name); + Assert.AreEqual(0, childGroupEntity.Order); + + PipingCalculationEntity[] calculationEntities = entity.CalculationGroupEntity.PipingCalculationEntities + .OrderBy(ce => ce.Order) + .ToArray(); + Assert.AreEqual(1, calculationEntities.Length); + PipingCalculationEntity calculationEntity = calculationEntities[0]; + Assert.AreEqual(calculation.Name, calculationEntity.Name); + Assert.AreEqual(1, calculationEntity.Order); + } + + private static void AssertSurfaceLine(PipingSurfaceLine surfaceLine, SurfaceLineEntity entity) + { + Assert.AreEqual(surfaceLine.Name, entity.Name); + Assert.AreEqual(surfaceLine.ReferenceLineIntersectionWorldPoint.X, entity.ReferenceLineIntersectionX); + Assert.AreEqual(surfaceLine.ReferenceLineIntersectionWorldPoint.Y, entity.ReferenceLineIntersectionY); + + Assert.AreEqual(6, entity.PipingCharacteristicPointEntities.Count); + CollectionAssert.IsEmpty(entity.MacroStabilityInwardsCharacteristicPointEntities); + } + + private static void AssertStochasticSoilModel(PipingStochasticSoilModel model, StochasticSoilModelEntity entity) + { + Assert.AreEqual(model.Name, entity.Name); + Assert.AreEqual(model.StochasticSoilProfiles.Count(), entity.PipingStochasticSoilProfileEntities.Count); + CollectionAssert.IsEmpty(entity.MacroStabilityInwardsStochasticSoilProfileEntities); + } + + private PipingSurfaceLine CreateSurfaceLine(Random random) + { + var surfaceLine = new PipingSurfaceLine(nameof(PipingSurfaceLine)) + { + ReferenceLineIntersectionWorldPoint = new Point2D(random.NextDouble(), random.NextDouble()) + }; + + var geometryPoints = new Point3D[10]; + for (var i = 0; i < 10; i++) + { + geometryPoints[i] = new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()); + } + + surfaceLine.SetGeometry(geometryPoints); + + surfaceLine.SetBottomDitchDikeSideAt(geometryPoints[1]); + surfaceLine.SetBottomDitchPolderSideAt(geometryPoints[2]); + surfaceLine.SetDikeToeAtPolderAt(geometryPoints[3]); + surfaceLine.SetDikeToeAtRiverAt(geometryPoints[4]); + surfaceLine.SetDitchDikeSideAt(geometryPoints[5]); + surfaceLine.SetDitchPolderSideAt(geometryPoints[7]); + + return surfaceLine; + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/PipingFailureMechanismSectionResultCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/PipingFailureMechanismSectionResultCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/PipingFailureMechanismSectionResultCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,99 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.Piping.Data; +using Riskeer.Storage.Core.Create.Piping; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.Piping +{ + [TestFixture] + public class PipingFailureMechanismSectionResultCreateExtensionsTest + { + [Test] + public void Create_SectionResultNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((PipingFailureMechanismSectionResult) null).Create(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("result", exception.ParamName); + } + + [Test] + public void Create_WithDifferentResults_ReturnsEntityWithExpectedResults() + { + // Setup + var random = new Random(21); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResult = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + double tailorMadeAssessmentProbability = random.NextDouble(); + bool useManualAssembly = random.NextBoolean(); + double manualAssemblyProbability = random.NextDouble(); + + var sectionResult = new PipingFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + SimpleAssessmentResult = simpleAssessmentResult, + DetailedAssessmentResult = detailedAssessmentResult, + TailorMadeAssessmentResult = tailorMadeAssessmentResult, + TailorMadeAssessmentProbability = tailorMadeAssessmentProbability, + UseManualAssembly = useManualAssembly, + ManualAssemblyProbability = manualAssemblyProbability + }; + + // Call + PipingSectionResultEntity entity = sectionResult.Create(); + + // Assert + Assert.AreEqual(Convert.ToByte(simpleAssessmentResult), entity.SimpleAssessmentResult); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResult), entity.DetailedAssessmentResult); + Assert.AreEqual(Convert.ToByte(tailorMadeAssessmentResult), entity.TailorMadeAssessmentResult); + Assert.AreEqual(tailorMadeAssessmentProbability, entity.TailorMadeAssessmentProbability); + Assert.AreEqual(Convert.ToByte(useManualAssembly), entity.UseManualAssembly); + Assert.AreEqual(manualAssemblyProbability, entity.ManualAssemblyProbability); + } + + [Test] + public void Create_SectionResultWithNaNValues_ReturnsEntityWithExpectedResults() + { + // Setup + var sectionResult = new PipingFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + TailorMadeAssessmentProbability = double.NaN, + ManualAssemblyProbability = double.NaN + }; + + // Call + PipingSectionResultEntity entity = sectionResult.Create(); + + // Assert + Assert.IsNull(entity.TailorMadeAssessmentProbability); + Assert.IsNull(entity.ManualAssemblyProbability); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/PipingOutputCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/PipingOutputCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/PipingOutputCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,104 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Piping.Data; +using Riskeer.Storage.Core.Create.Piping; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.Piping +{ + [TestFixture] + public class PipingOutputCreateExtensionsTest + { + [Test] + public void Create_OutputNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((PipingOutput) null).Create(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("output", exception.ParamName); + } + + [Test] + public void Create_AllOutputValuesSet_ReturnEntity() + { + // Setup + var pipingOutput = new PipingOutput(new PipingOutput.ConstructionProperties + { + UpliftZValue = 1.1, + UpliftFactorOfSafety = 2.2, + HeaveZValue = 3.3, + HeaveFactorOfSafety = 4.4, + SellmeijerZValue = 5.5, + SellmeijerFactorOfSafety = 6.6, + UpliftEffectiveStress = 7.7, + HeaveGradient = 8.8, + SellmeijerCreepCoefficient = 9.9, + SellmeijerCriticalFall = 10.10, + SellmeijerReducedFall = 11.11 + }); + + // Call + PipingCalculationOutputEntity entity = pipingOutput.Create(); + + // Assert + Assert.AreEqual(pipingOutput.HeaveFactorOfSafety, entity.HeaveFactorOfSafety); + Assert.AreEqual(pipingOutput.HeaveZValue, entity.HeaveZValue); + Assert.AreEqual(pipingOutput.SellmeijerFactorOfSafety, entity.SellmeijerFactorOfSafety); + Assert.AreEqual(pipingOutput.SellmeijerZValue, entity.SellmeijerZValue); + Assert.AreEqual(pipingOutput.UpliftFactorOfSafety, entity.UpliftFactorOfSafety); + Assert.AreEqual(pipingOutput.UpliftZValue, entity.UpliftZValue); + Assert.AreEqual(pipingOutput.UpliftEffectiveStress, entity.UpliftEffectiveStress, pipingOutput.UpliftEffectiveStress.GetAccuracy()); + Assert.AreEqual(pipingOutput.HeaveGradient, entity.HeaveGradient, pipingOutput.HeaveGradient.GetAccuracy()); + Assert.AreEqual(pipingOutput.SellmeijerCreepCoefficient, entity.SellmeijerCreepCoefficient, pipingOutput.SellmeijerCreepCoefficient.GetAccuracy()); + Assert.AreEqual(pipingOutput.SellmeijerCriticalFall, entity.SellmeijerCriticalFall, pipingOutput.SellmeijerCriticalFall.GetAccuracy()); + Assert.AreEqual(pipingOutput.SellmeijerReducedFall, entity.SellmeijerReducedFall, pipingOutput.SellmeijerReducedFall.GetAccuracy()); + } + + [Test] + public void Create_AllOutputValuesNaN_ReturnEntityWithNullValues() + { + // Setup + var pipingOutput = new PipingOutput(new PipingOutput.ConstructionProperties()); + + // Call + PipingCalculationOutputEntity entity = pipingOutput.Create(); + + // Assert + Assert.IsNull(entity.HeaveFactorOfSafety); + Assert.IsNull(entity.HeaveZValue); + Assert.IsNull(entity.SellmeijerFactorOfSafety); + Assert.IsNull(entity.SellmeijerZValue); + Assert.IsNull(entity.UpliftFactorOfSafety); + Assert.IsNull(entity.UpliftZValue); + Assert.IsNull(entity.UpliftEffectiveStress); + Assert.IsNull(entity.HeaveGradient); + Assert.IsNull(entity.SellmeijerCreepCoefficient); + Assert.IsNull(entity.SellmeijerCriticalFall); + Assert.IsNull(entity.SellmeijerReducedFall); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/PipingSoilLayerCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/PipingSoilLayerCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/PipingSoilLayerCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,162 @@ +// Copyright (C) Stichting Deltares 2018. 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.Drawing; +using Core.Common.Base.Data; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Probabilistics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Piping.Primitives; +using Riskeer.Storage.Core.Create.Piping; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.Piping +{ + [TestFixture] + public class PipingSoilLayerCreateExtensionsTest + { + [Test] + public void Create_SoilLayerNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => ((PipingSoilLayer) null).Create(0); + + // Assert + string parameterName = Assert.Throws(test).ParamName; + Assert.AreEqual("layer", parameterName); + } + + [Test] + public void Create_WithValidProperties_ReturnsEntityWithPropertiesSet() + { + // Setup + var random = new Random(21); + int order = random.Next(); + var soilLayer = new PipingSoilLayer(random.NextDouble()) + { + IsAquifer = random.NextBoolean(), + Color = Color.FromKnownColor(random.NextEnumValue()), + MaterialName = "MaterialName", + BelowPhreaticLevel = new LogNormalDistribution + { + Mean = random.NextRoundedDouble(1, double.MaxValue), + StandardDeviation = random.NextRoundedDouble(), + Shift = random.NextRoundedDouble() + }, + DiameterD70 = new VariationCoefficientLogNormalDistribution + { + Mean = random.NextRoundedDouble(1, double.MaxValue), + CoefficientOfVariation = random.NextRoundedDouble() + }, + Permeability = new VariationCoefficientLogNormalDistribution + { + Mean = random.NextRoundedDouble(1, double.MaxValue), + CoefficientOfVariation = random.NextRoundedDouble() + } + }; + + // Call + PipingSoilLayerEntity entity = soilLayer.Create(order); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(soilLayer.Top, entity.Top); + Assert.AreEqual(Convert.ToByte(soilLayer.IsAquifer), entity.IsAquifer); + Assert.AreEqual(soilLayer.Color.ToInt64(), Convert.ToInt64(entity.Color)); + + Assert.AreEqual(soilLayer.BelowPhreaticLevel.Mean, entity.BelowPhreaticLevelMean, + soilLayer.BelowPhreaticLevel.GetAccuracy()); + Assert.AreEqual(soilLayer.BelowPhreaticLevel.StandardDeviation, entity.BelowPhreaticLevelDeviation, + soilLayer.BelowPhreaticLevel.GetAccuracy()); + Assert.AreEqual(soilLayer.BelowPhreaticLevel.Shift, entity.BelowPhreaticLevelShift, + soilLayer.BelowPhreaticLevel.GetAccuracy()); + + Assert.AreEqual(soilLayer.DiameterD70.Mean, entity.DiameterD70Mean, + soilLayer.DiameterD70.GetAccuracy()); + Assert.AreEqual(soilLayer.DiameterD70.CoefficientOfVariation, entity.DiameterD70CoefficientOfVariation, + soilLayer.DiameterD70.GetAccuracy()); + + Assert.AreEqual(soilLayer.Permeability.Mean, entity.PermeabilityMean, + soilLayer.Permeability.GetAccuracy()); + Assert.AreEqual(soilLayer.Permeability.CoefficientOfVariation, entity.PermeabilityCoefficientOfVariation, + soilLayer.Permeability.GetAccuracy()); + Assert.AreEqual(order, entity.Order); + } + + [Test] + public void Create_WithNaNProperties_ReturnsEntityWithPropertiesSetToNull() + { + // Setup + var soilLayer = new PipingSoilLayer(double.NaN) + { + BelowPhreaticLevel = new LogNormalDistribution + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN, + Shift = RoundedDouble.NaN + }, + DiameterD70 = new VariationCoefficientLogNormalDistribution + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + Permeability = new VariationCoefficientLogNormalDistribution + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + } + }; + + // Call + PipingSoilLayerEntity entity = soilLayer.Create(0); + + // Assert + Assert.IsNotNull(entity); + Assert.IsNull(entity.Top); + Assert.IsNull(entity.BelowPhreaticLevelMean); + Assert.IsNull(entity.BelowPhreaticLevelDeviation); + Assert.IsNull(entity.BelowPhreaticLevelShift); + Assert.IsNull(entity.DiameterD70Mean); + Assert.IsNull(entity.DiameterD70CoefficientOfVariation); + Assert.IsNull(entity.PermeabilityMean); + Assert.IsNull(entity.PermeabilityCoefficientOfVariation); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string materialName = "MaterialName"; + var soilLayer = new PipingSoilLayer(0) + { + MaterialName = materialName + }; + + // Call + PipingSoilLayerEntity entity = soilLayer.Create(0); + + // Assert + TestHelper.AssertAreEqualButNotSame(materialName, entity.MaterialName); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/PipingSoilProfileCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/PipingSoilProfileCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/PipingSoilProfileCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,115 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Piping.Primitives; +using Ringtoets.Piping.Primitives.TestUtil; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.Piping; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.Piping +{ + [TestFixture] + public class PipingSoilProfileCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + PipingSoilProfile soilProfile = PipingSoilProfileTestFactory.CreatePipingSoilProfile(); + + // Call + TestDelegate test = () => soilProfile.Create(null); + + // Assert + string parameterName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", parameterName); + } + + [Test] + public void Create_WithCollectorAndLayers_ReturnsPipingSoilProfileEntityWithPropertiesAndPipingSoilLayerEntitiesSet() + { + // Setup + var random = new Random(21); + + const string testName = "testName"; + double bottom = random.NextDouble(); + var layers = new[] + { + new PipingSoilLayer(bottom + 1), + new PipingSoilLayer(bottom + 2) + }; + var soilProfileType = random.NextEnumValue(); + var soilProfile = new PipingSoilProfile(testName, bottom, layers, soilProfileType); + var registry = new PersistenceRegistry(); + + // Call + PipingSoilProfileEntity entity = soilProfile.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(bottom, entity.Bottom); + Assert.AreEqual(Convert.ToByte(soilProfileType), entity.SourceType); + Assert.AreEqual(testName, entity.Name); + Assert.AreEqual(2, entity.PipingSoilLayerEntities.Count); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + var random = new Random(21); + const string testName = "testName"; + var layers = new[] + { + new PipingSoilLayer(1), + new PipingSoilLayer(2) + }; + var soilProfile = new PipingSoilProfile(testName, 0, layers, random.NextEnumValue()); + var registry = new PersistenceRegistry(); + + // Call + PipingSoilProfileEntity entity = soilProfile.Create(registry); + + // Assert + TestHelper.AssertAreEqualButNotSame(testName, entity.Name); + } + + [Test] + public void Create_ForTheSameEntityTwice_ReturnsSamePipingSoilProfileEntityInstance() + { + // Setup + PipingSoilProfile soilProfile = PipingSoilProfileTestFactory.CreatePipingSoilProfile(); + var registry = new PersistenceRegistry(); + + PipingSoilProfileEntity firstEntity = soilProfile.Create(registry); + + // Call + PipingSoilProfileEntity secondEntity = soilProfile.Create(registry); + + // Assert + Assert.AreSame(firstEntity, secondEntity); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/PipingStochasticSoilModelCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/PipingStochasticSoilModelCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/PipingStochasticSoilModelCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,166 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Piping.Data.SoilProfile; +using Ringtoets.Piping.Data.TestUtil; +using Ringtoets.Piping.Primitives.TestUtil; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.Piping; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Create.Piping +{ + [TestFixture] + public class PipingStochasticSoilModelCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + PipingStochasticSoilModel stochasticSoilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel(); + + // Call + TestDelegate test = () => stochasticSoilModel.Create(null, 0); + + // Assert + string parameterName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", parameterName); + } + + [Test] + public void Create_StochasticSoilModelNull_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => ((PipingStochasticSoilModel) null).Create(registry, 0); + + // Assert + string parameterName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", parameterName); + } + + [Test] + public void Create_WithCollector_ReturnsPipingStochasticSoilModelEntityWithPropertiesSet() + { + // Setup + var random = new Random(1); + int order = random.Next(); + const string testName = "testName"; + PipingStochasticSoilModel stochasticSoilModel = + PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel(testName); + var registry = new PersistenceRegistry(); + + // Call + StochasticSoilModelEntity entity = stochasticSoilModel.Create(registry, order); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(testName, entity.Name); + Assert.AreEqual(order, entity.Order); + CollectionAssert.IsEmpty(entity.MacroStabilityInwardsStochasticSoilProfileEntities); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string name = "testName"; + PipingStochasticSoilModel stochasticSoilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel(name); + var registry = new PersistenceRegistry(); + + // Call + StochasticSoilModelEntity entity = stochasticSoilModel.Create(registry, 0); + + // Assert + TestHelper.AssertAreEqualButNotSame(name, entity.Name); + } + + [Test] + public void Create_WithStochasticSoilProfiles_ReturnsStochasticSoilModelEntityWithPropertiesAndPipingStochasticSoilProfileEntitiesSet() + { + // Setup + PipingStochasticSoilModel stochasticSoilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel("testName", new[] + { + new PipingStochasticSoilProfile(1, PipingSoilProfileTestFactory.CreatePipingSoilProfile()) + }); + var registry = new PersistenceRegistry(); + + // Call + StochasticSoilModelEntity entity = stochasticSoilModel.Create(registry, 0); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(stochasticSoilModel.StochasticSoilProfiles.Count(), entity.PipingStochasticSoilProfileEntities.Count); + + PipingStochasticSoilProfileEntity stochastEntity = entity.PipingStochasticSoilProfileEntities.Single(); + Assert.AreEqual(stochasticSoilModel.StochasticSoilProfiles.Single().Probability, stochastEntity.Probability); + Assert.IsNotNull(stochastEntity.PipingSoilProfileEntity); + + CollectionAssert.IsEmpty(entity.MacroStabilityInwardsStochasticSoilProfileEntities); + } + + [Test] + public void Create_WithGeometryPoints_ReturnsStochasticSoilModelEntityWithPropertiesAndStochasticSoilModelSegmentPointEntitiesSet() + { + // Setup + var random = new Random(31); + PipingStochasticSoilModel stochasticSoilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel("testName", new[] + { + new Point2D(random.NextDouble(), random.NextDouble()), + new Point2D(random.NextDouble(), random.NextDouble()) + }); + + var registry = new PersistenceRegistry(); + + // Call + StochasticSoilModelEntity entity = stochasticSoilModel.Create(registry, 0); + + // Assert + Assert.IsNotNull(entity); + string expectedXml = new Point2DCollectionXmlSerializer().ToXml(stochasticSoilModel.Geometry); + Assert.AreEqual(expectedXml, entity.StochasticSoilModelSegmentPointXml); + } + + [Test] + public void Create_SameModelCreatedMultipleTimes_ReturnSameEntity() + { + // Setup + PipingStochasticSoilModel soilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel("A"); + + var registry = new PersistenceRegistry(); + + // Call + StochasticSoilModelEntity entity1 = soilModel.Create(registry, 0); + StochasticSoilModelEntity entity2 = soilModel.Create(registry, 0); + + // Assert + Assert.AreSame(entity1, entity2); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/PipingStochasticSoilProfileCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/PipingStochasticSoilProfileCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/PipingStochasticSoilProfileCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,103 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.Piping.Data.SoilProfile; +using Ringtoets.Piping.Primitives; +using Ringtoets.Piping.Primitives.TestUtil; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.Piping; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.Piping +{ + [TestFixture] + public class PipingStochasticSoilProfileCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var stochasticSoilProfile = new PipingStochasticSoilProfile(0.4, PipingSoilProfileTestFactory.CreatePipingSoilProfile()); + + // Call + TestDelegate test = () => stochasticSoilProfile.Create(null, 0); + + // Assert + string parameterName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", parameterName); + } + + [Test] + public void Create_WithCollector_ReturnsPipingStochasticSoilProfileEntityWithPropertiesSet() + { + // Setup + var random = new Random(21); + double probability = random.NextDouble(); + int order = random.Next(); + var stochasticSoilProfile = new PipingStochasticSoilProfile(probability, PipingSoilProfileTestFactory.CreatePipingSoilProfile()); + var registry = new PersistenceRegistry(); + + // Call + PipingStochasticSoilProfileEntity entity = stochasticSoilProfile.Create(registry, order); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(probability, entity.Probability); + Assert.IsNotNull(entity.PipingSoilProfileEntity); + Assert.AreEqual(order, entity.Order); + } + + [Test] + public void Create_DifferentStochasticSoilProfilesWithSamePipingSoilProfile_ReturnsPipingStochasticSoilProfileEntityWithSameSoilProfileEntitySet() + { + // Setup + PipingSoilProfile testPipingSoilProfile = PipingSoilProfileTestFactory.CreatePipingSoilProfile(); + var firstStochasticSoilProfile = new PipingStochasticSoilProfile(new Random(21).NextDouble(), testPipingSoilProfile); + var secondStochasticSoilProfile = new PipingStochasticSoilProfile(new Random(21).NextDouble(), testPipingSoilProfile); + var registry = new PersistenceRegistry(); + + // Call + PipingStochasticSoilProfileEntity firstEntity = firstStochasticSoilProfile.Create(registry, 0); + PipingStochasticSoilProfileEntity secondEntity = secondStochasticSoilProfile.Create(registry, 0); + + // Assert + Assert.AreSame(firstEntity.PipingSoilProfileEntity, secondEntity.PipingSoilProfileEntity); + } + + [Test] + public void Create_SamePipingStochasticSoilProfileMultipleTimes_ReturnSameEntity() + { + // Setup + PipingSoilProfile soilProfile = PipingSoilProfileTestFactory.CreatePipingSoilProfile(); + var stochasticSoilProfile = new PipingStochasticSoilProfile(0.4, soilProfile); + var registry = new PersistenceRegistry(); + + // Call + PipingStochasticSoilProfileEntity entity1 = stochasticSoilProfile.Create(registry, 0); + PipingStochasticSoilProfileEntity entity2 = stochasticSoilProfile.Create(registry, 0); + + // Assert + Assert.AreSame(entity1, entity2); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/PipingSurfaceLineCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/PipingSurfaceLineCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/PipingSurfaceLineCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,299 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Piping.Primitives; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.Piping; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Create.Piping +{ + [TestFixture] + public class PipingSurfaceLineCreateExtensionsTest + { + [Test] + public void Create_SurfaceLineNull_ThrowArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate call = () => ((PipingSurfaceLine) null).Create(registry, 0); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("surfaceLine", exception.ParamName); + } + + [Test] + public void Create_PersistenceRegistryNull_ThrowArgumentNullException() + { + // Setup + var surfaceLine = new PipingSurfaceLine(string.Empty); + + // Call + TestDelegate call = () => surfaceLine.Create(null, 0); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("registry", exception.ParamName); + } + + [Test] + public void Create_SurfaceLineWithoutGeometry_ReturnSurfaceLineEntityWithoutAddingPointEntities() + { + // Setup + var random = new Random(31); + int order = random.Next(); + var registry = new PersistenceRegistry(); + var surfaceLine = new PipingSurfaceLine("Test") + { + ReferenceLineIntersectionWorldPoint = new Point2D(random.NextDouble(), random.NextDouble()) + }; + + // Call + SurfaceLineEntity entity = surfaceLine.Create(registry, order); + + // Assert + Assert.AreEqual(surfaceLine.Name, entity.Name); + Assert.AreEqual(surfaceLine.ReferenceLineIntersectionWorldPoint.X, entity.ReferenceLineIntersectionX); + Assert.AreEqual(surfaceLine.ReferenceLineIntersectionWorldPoint.Y, entity.ReferenceLineIntersectionY); + Assert.AreEqual(order, entity.Order); + + Assert.IsNull(entity.FailureMechanismEntity); + IEnumerable points = new Point3D[0]; + string expectedXml = new Point3DCollectionXmlSerializer().ToXml(points); + Assert.AreEqual(expectedXml, entity.PointsXml); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + var registry = new PersistenceRegistry(); + var surfaceLine = new PipingSurfaceLine("Test"); + + // Call + SurfaceLineEntity entity = surfaceLine.Create(registry, 0); + + // Assert + TestHelper.AssertAreEqualButNotSame(surfaceLine.Name, entity.Name); + } + + [Test] + public void Create_SurfaceLineWithGeometryWithoutCharacteristicPoints_ReturnSurfaceLineEntityWithPointEntities() + { + // Setup + var random = new Random(31); + int order = random.Next(); + var registry = new PersistenceRegistry(); + var surfaceLine = new PipingSurfaceLine("Test") + { + ReferenceLineIntersectionWorldPoint = new Point2D(1.1, 2.2) + }; + surfaceLine.SetGeometry(new[] + { + new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()), + new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()), + new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()) + }); + + // Call + SurfaceLineEntity entity = surfaceLine.Create(registry, order); + + // Assert + Assert.AreEqual(surfaceLine.Name, entity.Name); + Assert.AreEqual(surfaceLine.ReferenceLineIntersectionWorldPoint.X, entity.ReferenceLineIntersectionX); + Assert.AreEqual(surfaceLine.ReferenceLineIntersectionWorldPoint.Y, entity.ReferenceLineIntersectionY); + Assert.AreEqual(order, entity.Order); + + string expectedXml = new Point3DCollectionXmlSerializer().ToXml(surfaceLine.Points); + Assert.AreEqual(expectedXml, entity.PointsXml); + + Assert.IsNull(entity.FailureMechanismEntity); + } + + [Test] + public void Create_SurfaceLineWithGeometryAndCharacteristicPoints_ReturnSurfaceLineEntityWithPointEntitiesAndCharactersisticPointReferences() + { + // Setup + var registry = new PersistenceRegistry(); + var random = new Random(31); + var geometry = new[] + { + new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()), + new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()), + new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()), + new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()), + new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()), + new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()), + new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()), + new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()) + }; + var surfaceLine = new PipingSurfaceLine("Test") + { + ReferenceLineIntersectionWorldPoint = new Point2D(random.NextDouble(), random.NextDouble()) + }; + surfaceLine.SetGeometry(geometry); + const int bottomDitchDikeIndex = 1; + surfaceLine.SetBottomDitchDikeSideAt(geometry[bottomDitchDikeIndex]); + const int bottomDitchPolderIndex = 2; + surfaceLine.SetBottomDitchPolderSideAt(geometry[bottomDitchPolderIndex]); + const int toePolderIndex = 3; + surfaceLine.SetDikeToeAtPolderAt(geometry[toePolderIndex]); + const int toeDikeIndex = 4; + surfaceLine.SetDikeToeAtRiverAt(geometry[toeDikeIndex]); + const int ditchDikeIndex = 5; + surfaceLine.SetDitchDikeSideAt(geometry[ditchDikeIndex]); + const int ditchPolderIndex = 6; + surfaceLine.SetDitchPolderSideAt(geometry[ditchPolderIndex]); + + // Call + SurfaceLineEntity entity = surfaceLine.Create(registry, 0); + + // Assert + Assert.AreEqual(surfaceLine.Name, entity.Name); + Assert.AreEqual(surfaceLine.ReferenceLineIntersectionWorldPoint.X, entity.ReferenceLineIntersectionX); + Assert.AreEqual(surfaceLine.ReferenceLineIntersectionWorldPoint.Y, entity.ReferenceLineIntersectionY); + + string expectedXml = new Point3DCollectionXmlSerializer().ToXml(geometry); + Assert.AreEqual(expectedXml, entity.PointsXml); + + Assert.AreEqual(6, entity.PipingCharacteristicPointEntities.Count); + foreach (PipingCharacteristicPointEntity characteristicPointEntity in entity.PipingCharacteristicPointEntities) + { + switch (characteristicPointEntity.Type) + { + case (byte) PipingCharacteristicPointType.BottomDitchDikeSide: + Assert.AreEqual(geometry[bottomDitchDikeIndex].X, characteristicPointEntity.X); + Assert.AreEqual(geometry[bottomDitchDikeIndex].Y, characteristicPointEntity.Y); + Assert.AreEqual(geometry[bottomDitchDikeIndex].Z, characteristicPointEntity.Z); + break; + case (byte) PipingCharacteristicPointType.BottomDitchPolderSide: + Assert.AreEqual(geometry[bottomDitchPolderIndex].X, characteristicPointEntity.X); + Assert.AreEqual(geometry[bottomDitchPolderIndex].Y, characteristicPointEntity.Y); + Assert.AreEqual(geometry[bottomDitchPolderIndex].Z, characteristicPointEntity.Z); + break; + case (byte) PipingCharacteristicPointType.DikeToeAtPolder: + Assert.AreEqual(geometry[toePolderIndex].X, characteristicPointEntity.X); + Assert.AreEqual(geometry[toePolderIndex].Y, characteristicPointEntity.Y); + Assert.AreEqual(geometry[toePolderIndex].Z, characteristicPointEntity.Z); + break; + case (byte) PipingCharacteristicPointType.DikeToeAtRiver: + Assert.AreEqual(geometry[toeDikeIndex].X, characteristicPointEntity.X); + Assert.AreEqual(geometry[toeDikeIndex].Y, characteristicPointEntity.Y); + Assert.AreEqual(geometry[toeDikeIndex].Z, characteristicPointEntity.Z); + break; + case (byte) PipingCharacteristicPointType.DitchDikeSide: + Assert.AreEqual(geometry[ditchDikeIndex].X, characteristicPointEntity.X); + Assert.AreEqual(geometry[ditchDikeIndex].Y, characteristicPointEntity.Y); + Assert.AreEqual(geometry[ditchDikeIndex].Z, characteristicPointEntity.Z); + break; + case (byte) PipingCharacteristicPointType.DitchPolderSide: + Assert.AreEqual(geometry[ditchPolderIndex].X, characteristicPointEntity.X); + Assert.AreEqual(geometry[ditchPolderIndex].Y, characteristicPointEntity.Y); + Assert.AreEqual(geometry[ditchPolderIndex].Z, characteristicPointEntity.Z); + break; + default: + Assert.Fail("Invalid characteristic point type found: {0}", characteristicPointEntity.Type); + break; + } + } + } + + [Test] + public void Create_SurfaceLineWithCharacteristicPointsOnSameGeometryPoint_ReturnSurfaceLineEntityWithPointEntitiesAndCharactersisticPointReferences() + { + // Setup + var random = new Random(31); + var registry = new PersistenceRegistry(); + var geometry = new[] + { + new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()) + }; + var surfaceLine = new PipingSurfaceLine("Test") + { + ReferenceLineIntersectionWorldPoint = new Point2D(random.NextDouble(), random.NextDouble()) + }; + surfaceLine.SetGeometry(geometry); + surfaceLine.SetBottomDitchDikeSideAt(geometry[0]); + surfaceLine.SetBottomDitchPolderSideAt(geometry[0]); + surfaceLine.SetDikeToeAtPolderAt(geometry[0]); + surfaceLine.SetDikeToeAtRiverAt(geometry[0]); + surfaceLine.SetDitchDikeSideAt(geometry[0]); + surfaceLine.SetDitchPolderSideAt(geometry[0]); + + // Call + SurfaceLineEntity entity = surfaceLine.Create(registry, 0); + + // Assert + Assert.AreEqual(surfaceLine.Name, entity.Name); + Assert.AreEqual(surfaceLine.ReferenceLineIntersectionWorldPoint.X, entity.ReferenceLineIntersectionX); + Assert.AreEqual(surfaceLine.ReferenceLineIntersectionWorldPoint.Y, entity.ReferenceLineIntersectionY); + + string expectedXml = new Point3DCollectionXmlSerializer().ToXml(geometry); + Assert.AreEqual(expectedXml, entity.PointsXml); + + Assert.AreEqual(6, entity.PipingCharacteristicPointEntities.Count); + + CollectionAssert.AreEquivalent(new[] + { + (byte) PipingCharacteristicPointType.DikeToeAtRiver, + (byte) PipingCharacteristicPointType.DikeToeAtPolder, + (byte) PipingCharacteristicPointType.DitchDikeSide, + (byte) PipingCharacteristicPointType.BottomDitchDikeSide, + (byte) PipingCharacteristicPointType.BottomDitchPolderSide, + (byte) PipingCharacteristicPointType.DitchPolderSide + }, entity.PipingCharacteristicPointEntities + .Select(cpe => cpe.Type)); + + foreach (PipingCharacteristicPointEntity characteristicPointEntity in entity.PipingCharacteristicPointEntities) + { + Assert.AreEqual(geometry[0].X, characteristicPointEntity.X); + Assert.AreEqual(geometry[0].Y, characteristicPointEntity.Y); + Assert.AreEqual(geometry[0].Z, characteristicPointEntity.Z); + } + } + + [Test] + public void Create_CreatingEntityForSameSurfaceLine_ReturnSamenEntity() + { + // Setup + var surfaceLine = new PipingSurfaceLine(string.Empty); + + var registry = new PersistenceRegistry(); + + // Call + SurfaceLineEntity entity1 = surfaceLine.Create(registry, 0); + SurfaceLineEntity entity2 = surfaceLine.Create(registry, 0); + + // Assert + Assert.AreSame(entity1, entity2); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/PipingStructure/PipingStructureFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/PipingStructure/PipingStructureFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/PipingStructure/PipingStructureFailureMechanismCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,155 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Integration.Data.StandAlone; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.PipingStructure; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.PipingStructure +{ + [TestFixture] + public class PipingStructureFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new PipingStructureFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet(bool isRelevant) + { + // Setup + var failureMechanism = new PipingStructureFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + }, + N = new Random().NextRoundedDouble(1, 20) + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.PipingAtStructure, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + Assert.AreEqual(failureMechanism.N, entity.PipingStructureFailureMechanismMetaEntities.Single().N); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + var failureMechanism = new PipingStructureFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + TestHelper.AssertAreEqualButNotSame(failureMechanism.InputComments.Body, entity.InputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.OutputComments.Body, entity.OutputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new PipingStructureFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + Assert.IsNull(entity.FailureMechanismSectionCollectionSourcePath); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + const string filePath = "failureMechanismSections/File/Path"; + var failureMechanism = new PipingStructureFailureMechanism(); + failureMechanism.SetSections(new[] + { + FailureMechanismSectionTestFactory.CreateFailureMechanismSection() + }, filePath); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.PipingStructureSectionResultEntities).Count()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/PipingStructure/PipingStructureFailureMechanismSectionResultCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/PipingStructure/PipingStructureFailureMechanismSectionResultCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/PipingStructure/PipingStructureFailureMechanismSectionResultCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,78 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.Integration.Data.StandAlone.SectionResults; +using Riskeer.Storage.Core.Create.PipingStructure; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.PipingStructure +{ + [TestFixture] + public class PipingStructureFailureMechanismSectionResultCreateExtensionsTest + { + [Test] + public void Create_SectionResultNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((PipingStructureFailureMechanismSectionResult) null).Create(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("result", exception.ParamName); + } + + [Test] + public void Create_WithDifferentResults_ReturnsEntityWithExpectedResults() + { + // Setup + var random = new Random(39); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResult = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + bool useManualAssembly = random.NextBoolean(); + var manualAssemblyCategoryGroup = random.NextEnumValue(); + + var sectionResult = new PipingStructureFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + SimpleAssessmentResult = simpleAssessmentResult, + DetailedAssessmentResult = detailedAssessmentResult, + TailorMadeAssessmentResult = tailorMadeAssessmentResult, + UseManualAssembly = useManualAssembly, + ManualAssemblyCategoryGroup = manualAssemblyCategoryGroup + }; + + // Call + PipingStructureSectionResultEntity entity = sectionResult.Create(); + + // Assert + Assert.AreEqual(Convert.ToByte(simpleAssessmentResult), entity.SimpleAssessmentResult); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResult), entity.DetailedAssessmentResult); + Assert.AreEqual(Convert.ToByte(tailorMadeAssessmentResult), entity.TailorMadeAssessmentResult); + Assert.AreEqual(Convert.ToByte(useManualAssembly), entity.UseManualAssembly); + Assert.AreEqual(Convert.ToByte(manualAssemblyCategoryGroup), entity.ManualAssemblyCategoryGroup); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/RiskeerProjectCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/RiskeerProjectCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/RiskeerProjectCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,106 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Integration.Data; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create +{ + [TestFixture] + public class RiskeerProjectCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var project = new RingtoetsProject(); + + // Call + TestDelegate test = () => project.Create(null); + + // Assert + string parameterName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", parameterName); + } + + [Test] + public void Create_WithCollector_ReturnsProjectEntityWithDescription() + { + // Setup + const string testdescription = "testDescription"; + var project = new RingtoetsProject + { + Description = testdescription + }; + var registry = new PersistenceRegistry(); + + // Call + ProjectEntity entity = project.Create(registry); + + // Assert + Assert.NotNull(entity); + Assert.AreEqual(testdescription, entity.Description); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string testdescription = "original description"; + var project = new RingtoetsProject + { + Description = testdescription + }; + var registry = new PersistenceRegistry(); + + // Call + ProjectEntity entity = project.Create(registry); + + // Assert + Assert.AreNotSame(testdescription, entity.Description); + Assert.AreEqual(testdescription, entity.Description); + } + + [Test] + public void Create_WithAssessmentSections_AddsSectionsToEntity() + { + // Setup + var project = new RingtoetsProject + { + AssessmentSections = + { + new AssessmentSection(AssessmentSectionComposition.Dike) + } + }; + var registry = new PersistenceRegistry(); + + // Call + ProjectEntity entity = project.Create(registry); + + // Assert + Assert.AreEqual(1, entity.AssessmentSectionEntities.Count); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StabilityPointStructures/StabilityPointStructureCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StabilityPointStructures/StabilityPointStructureCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StabilityPointStructures/StabilityPointStructureCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,300 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.StabilityPointStructures.Data; +using Ringtoets.StabilityPointStructures.Data.TestUtil; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.StabilityPointStructures; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.StabilityPointStructures +{ + [TestFixture] + public class StabilityPointStructureCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowArgumentNullException() + { + // Setup + StabilityPointStructure structure = new TestStabilityPointStructure(); + + // Call + TestDelegate call = () => structure.Create(null, 0); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + public void Create_ValidStructure_ReturnEntity() + { + // Setup + StabilityPointStructure structure = new TestStabilityPointStructure(); + var registry = new PersistenceRegistry(); + + const int order = 4; + + // Call + StabilityPointStructureEntity entity = structure.Create(registry, order); + + // Assert + Assert.AreEqual(structure.Name, entity.Name); + Assert.AreNotSame(structure.Name, entity.Name); + Assert.AreEqual(structure.Id, entity.Id); + Assert.AreNotSame(structure.Id, entity.Id); + Assert.AreEqual(structure.Location.X, entity.X); + Assert.AreEqual(structure.Location.Y, entity.Y); + Assert.AreEqual(structure.StructureNormalOrientation.Value, entity.StructureNormalOrientation); + + Assert.AreEqual(structure.StorageStructureArea.Mean.Value, entity.StorageStructureAreaMean); + Assert.AreEqual(structure.StorageStructureArea.CoefficientOfVariation.Value, entity.StorageStructureAreaCoefficientOfVariation); + Assert.AreEqual(structure.AllowedLevelIncreaseStorage.Mean.Value, entity.AllowedLevelIncreaseStorageMean); + Assert.AreEqual(structure.AllowedLevelIncreaseStorage.StandardDeviation.Value, entity.AllowedLevelIncreaseStorageStandardDeviation); + Assert.AreEqual(structure.WidthFlowApertures.Mean.Value, entity.WidthFlowAperturesMean); + Assert.AreEqual(structure.WidthFlowApertures.StandardDeviation.Value, entity.WidthFlowAperturesStandardDeviation); + Assert.AreEqual(structure.InsideWaterLevel.Mean.Value, entity.InsideWaterLevelMean); + Assert.AreEqual(structure.InsideWaterLevel.StandardDeviation.Value, entity.InsideWaterLevelStandardDeviation); + Assert.AreEqual(structure.ThresholdHeightOpenWeir.Mean.Value, entity.ThresholdHeightOpenWeirMean); + Assert.AreEqual(structure.ThresholdHeightOpenWeir.StandardDeviation.Value, entity.ThresholdHeightOpenWeirStandardDeviation); + Assert.AreEqual(structure.CriticalOvertoppingDischarge.Mean.Value, entity.CriticalOvertoppingDischargeMean); + Assert.AreEqual(structure.CriticalOvertoppingDischarge.CoefficientOfVariation.Value, entity.CriticalOvertoppingDischargeCoefficientOfVariation); + Assert.AreEqual(structure.FlowWidthAtBottomProtection.Mean.Value, entity.FlowWidthAtBottomProtectionMean); + Assert.AreEqual(structure.FlowWidthAtBottomProtection.StandardDeviation.Value, entity.FlowWidthAtBottomProtectionStandardDeviation); + Assert.AreEqual(structure.ConstructiveStrengthLinearLoadModel.Mean.Value, entity.ConstructiveStrengthLinearLoadModelMean); + Assert.AreEqual(structure.ConstructiveStrengthLinearLoadModel.CoefficientOfVariation.Value, entity.ConstructiveStrengthLinearLoadModelCoefficientOfVariation); + Assert.AreEqual(structure.ConstructiveStrengthQuadraticLoadModel.Mean.Value, entity.ConstructiveStrengthQuadraticLoadModelMean); + Assert.AreEqual(structure.ConstructiveStrengthQuadraticLoadModel.CoefficientOfVariation.Value, entity.ConstructiveStrengthQuadraticLoadModelCoefficientOfVariation); + Assert.AreEqual(structure.BankWidth.Mean.Value, entity.BankWidthMean); + Assert.AreEqual(structure.BankWidth.StandardDeviation.Value, entity.BankWidthStandardDeviation); + Assert.AreEqual(structure.InsideWaterLevelFailureConstruction.Mean.Value, entity.InsideWaterLevelFailureConstructionMean); + Assert.AreEqual(structure.InsideWaterLevelFailureConstruction.StandardDeviation.Value, entity.InsideWaterLevelFailureConstructionStandardDeviation); + Assert.AreEqual(structure.EvaluationLevel.Value, entity.EvaluationLevel); + Assert.AreEqual(structure.LevelCrestStructure.Mean.Value, entity.LevelCrestStructureMean); + Assert.AreEqual(structure.LevelCrestStructure.StandardDeviation.Value, entity.LevelCrestStructureStandardDeviation); + Assert.AreEqual(structure.VerticalDistance.Value, entity.VerticalDistance); + Assert.AreEqual(structure.FailureProbabilityRepairClosure, entity.FailureProbabilityRepairClosure); + Assert.AreEqual(structure.FailureCollisionEnergy.Mean.Value, entity.FailureCollisionEnergyMean); + Assert.AreEqual(structure.FailureCollisionEnergy.CoefficientOfVariation.Value, entity.FailureCollisionEnergyCoefficientOfVariation); + Assert.AreEqual(structure.ShipMass.Mean.Value, entity.ShipMassMean); + Assert.AreEqual(structure.ShipMass.CoefficientOfVariation.Value, entity.ShipMassCoefficientOfVariation); + Assert.AreEqual(structure.ShipVelocity.Mean.Value, entity.ShipVelocityMean); + Assert.AreEqual(structure.ShipVelocity.CoefficientOfVariation.Value, entity.ShipVelocityCoefficientOfVariation); + Assert.AreEqual(structure.LevellingCount, entity.LevellingCount); + Assert.AreEqual(structure.ProbabilityCollisionSecondaryStructure, entity.ProbabilityCollisionSecondaryStructure); + Assert.AreEqual(structure.FlowVelocityStructureClosable.Mean.Value, entity.FlowVelocityStructureClosableMean); + Assert.AreEqual(structure.StabilityLinearLoadModel.Mean.Value, entity.StabilityLinearLoadModelMean); + Assert.AreEqual(structure.StabilityLinearLoadModel.CoefficientOfVariation.Value, entity.StabilityLinearLoadModelCoefficientOfVariation); + Assert.AreEqual(structure.StabilityQuadraticLoadModel.Mean.Value, entity.StabilityQuadraticLoadModelMean); + Assert.AreEqual(structure.StabilityQuadraticLoadModel.CoefficientOfVariation.Value, entity.StabilityQuadraticLoadModelCoefficientOfVariation); + Assert.AreEqual(structure.AreaFlowApertures.Mean.Value, entity.AreaFlowAperturesMean); + Assert.AreEqual(structure.AreaFlowApertures.StandardDeviation.Value, entity.AreaFlowAperturesStandardDeviation); + Assert.AreEqual(Convert.ToByte(structure.InflowModelType), entity.InflowModelType); + Assert.AreEqual(order, entity.Order); + + Assert.IsTrue(registry.Contains(structure)); + } + + [Test] + public void Create_NaNValue_ReturnEntityWithNullValue() + { + // Setup + var structure = new StabilityPointStructure(new StabilityPointStructure.ConstructionProperties + { + Name = "A", + Id = "B", + Location = new Point2D(double.NaN, double.NaN), + StructureNormalOrientation = RoundedDouble.NaN, + StorageStructureArea = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + AllowedLevelIncreaseStorage = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + WidthFlowApertures = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + InsideWaterLevel = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + ThresholdHeightOpenWeir = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + CriticalOvertoppingDischarge = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + FlowWidthAtBottomProtection = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + ConstructiveStrengthLinearLoadModel = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + ConstructiveStrengthQuadraticLoadModel = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + BankWidth = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + InsideWaterLevelFailureConstruction = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + EvaluationLevel = RoundedDouble.NaN, + LevelCrestStructure = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + VerticalDistance = RoundedDouble.NaN, + FailureProbabilityRepairClosure = double.NaN, + FailureCollisionEnergy = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + ShipMass = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + ShipVelocity = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + ProbabilityCollisionSecondaryStructure = double.NaN, + FlowVelocityStructureClosable = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + StabilityLinearLoadModel = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + StabilityQuadraticLoadModel = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + AreaFlowApertures = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + } + }); + var registry = new PersistenceRegistry(); + + // Call + StabilityPointStructureEntity entity = structure.Create(registry, 0); + + // Assert + Assert.IsNull(entity.X); + Assert.IsNull(entity.Y); + Assert.IsNull(entity.StructureNormalOrientation); + + Assert.IsNull(entity.StorageStructureAreaMean); + Assert.IsNull(entity.StorageStructureAreaCoefficientOfVariation); + Assert.IsNull(entity.AllowedLevelIncreaseStorageMean); + Assert.IsNull(entity.AllowedLevelIncreaseStorageStandardDeviation); + Assert.IsNull(entity.WidthFlowAperturesMean); + Assert.IsNull(entity.WidthFlowAperturesStandardDeviation); + Assert.IsNull(entity.InsideWaterLevelMean); + Assert.IsNull(entity.InsideWaterLevelStandardDeviation); + Assert.IsNull(entity.ThresholdHeightOpenWeirMean); + Assert.IsNull(entity.ThresholdHeightOpenWeirStandardDeviation); + Assert.IsNull(entity.CriticalOvertoppingDischargeMean); + Assert.IsNull(entity.CriticalOvertoppingDischargeCoefficientOfVariation); + Assert.IsNull(entity.FlowWidthAtBottomProtectionMean); + Assert.IsNull(entity.FlowWidthAtBottomProtectionStandardDeviation); + Assert.IsNull(entity.ConstructiveStrengthLinearLoadModelMean); + Assert.IsNull(entity.ConstructiveStrengthLinearLoadModelCoefficientOfVariation); + Assert.IsNull(entity.ConstructiveStrengthQuadraticLoadModelMean); + Assert.IsNull(entity.ConstructiveStrengthQuadraticLoadModelCoefficientOfVariation); + Assert.IsNull(entity.BankWidthMean); + Assert.IsNull(entity.BankWidthStandardDeviation); + Assert.IsNull(entity.InsideWaterLevelFailureConstructionMean); + Assert.IsNull(entity.InsideWaterLevelFailureConstructionStandardDeviation); + Assert.IsNull(entity.EvaluationLevel); + Assert.IsNull(entity.LevelCrestStructureMean); + Assert.IsNull(entity.LevelCrestStructureStandardDeviation); + Assert.IsNull(entity.VerticalDistance); + Assert.IsNull(entity.FailureProbabilityRepairClosure); + Assert.IsNull(entity.FailureCollisionEnergyMean); + Assert.IsNull(entity.FailureCollisionEnergyCoefficientOfVariation); + Assert.IsNull(entity.ShipMassMean); + Assert.IsNull(entity.ShipMassCoefficientOfVariation); + Assert.IsNull(entity.ShipVelocityMean); + Assert.IsNull(entity.ShipVelocityCoefficientOfVariation); + Assert.IsNull(entity.ProbabilityCollisionSecondaryStructure); + Assert.IsNull(entity.FlowVelocityStructureClosableMean); + Assert.IsNull(entity.StabilityLinearLoadModelMean); + Assert.IsNull(entity.StabilityLinearLoadModelCoefficientOfVariation); + Assert.IsNull(entity.StabilityQuadraticLoadModelMean); + Assert.IsNull(entity.StabilityQuadraticLoadModelCoefficientOfVariation); + Assert.IsNull(entity.AreaFlowAperturesMean); + Assert.IsNull(entity.AreaFlowAperturesStandardDeviation); + } + + [Test] + public void Create_StructureAlreadyRegistered_ReturnRegisteredEntity() + { + // Setup + var structure = new TestStabilityPointStructure(); + + var registeredEntity = new StabilityPointStructureEntity(); + var registry = new PersistenceRegistry(); + registry.Register(registeredEntity, structure); + + // Call + StabilityPointStructureEntity entity = structure.Create(registry, 0); + + // Assert + Assert.AreSame(registeredEntity, entity); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StabilityPointStructures/StabilityPointStructuresFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StabilityPointStructures/StabilityPointStructuresFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StabilityPointStructures/StabilityPointStructuresFailureMechanismCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,295 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.StabilityPointStructures.Data; +using Ringtoets.StabilityPointStructures.Data.TestUtil; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.StabilityPointStructures; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.StabilityPointStructures +{ + [TestFixture] + public class StabilityPointStructuresFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndPropertiesSet_ReturnsExpectedEntity(bool isRelevant) + { + // Setup + var failureMechanism = new StabilityPointStructuresFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + }, + GeneralInput = + { + N = new Random().NextRoundedDouble(1, 20) + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.StabilityPointStructures, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + + StabilityPointStructuresFailureMechanismMetaEntity metaEntity = entity.StabilityPointStructuresFailureMechanismMetaEntities.Single(); + Assert.AreEqual(failureMechanism.GeneralInput.N, metaEntity.N); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + var failureMechanism = new StabilityPointStructuresFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + TestHelper.AssertAreEqualButNotSame(failureMechanism.InputComments.Body, entity.InputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.OutputComments.Body, entity.OutputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + Assert.IsNull(entity.FailureMechanismSectionCollectionSourcePath); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + const string sourcePath = "failureMechanismSections/File/Path"; + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + failureMechanism.SetSections(new[] + { + FailureMechanismSectionTestFactory.CreateFailureMechanismSection() + }, sourcePath); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.StabilityPointStructuresSectionResultEntities).Count()); + TestHelper.AssertAreEqualButNotSame(sourcePath, entity.FailureMechanismSectionCollectionSourcePath); + } + + [Test] + public void Create_WithoutForeshoreProfiles_EmptyForeshoreProfilesEntities() + { + // Setup + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.ForeshoreProfileEntities); + + StabilityPointStructuresFailureMechanismMetaEntity metaEntity = + entity.StabilityPointStructuresFailureMechanismMetaEntities.Single(); + Assert.IsNull(metaEntity.ForeshoreProfileCollectionSourcePath); + } + + [Test] + public void Create_WithForeshoreProfiles_ForeshoreProfileEntitiesCreated() + { + // Setup + var profile = new TestForeshoreProfile(); + + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + const string filePath = "some/path/to/foreshoreProfiles"; + failureMechanism.ForeshoreProfiles.AddRange(new[] + { + profile + }, filePath); + + var persistenceRegistry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(persistenceRegistry); + + // Assert + Assert.AreEqual(1, entity.ForeshoreProfileEntities.Count); + Assert.IsTrue(persistenceRegistry.Contains(profile)); + + StabilityPointStructuresFailureMechanismMetaEntity metaEntity = + entity.StabilityPointStructuresFailureMechanismMetaEntities.Single(); + string metaEntityForeshoreProfileCollectionSourcePath = metaEntity.ForeshoreProfileCollectionSourcePath; + TestHelper.AssertAreEqualButNotSame(filePath, metaEntityForeshoreProfileCollectionSourcePath); + } + + [Test] + public void Create_WithoutStabilityPointStructures_EmptyStabilityPointStructuresEntities() + { + // Setup + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.StabilityPointStructureEntities); + + StabilityPointStructuresFailureMechanismMetaEntity metaEntity = + entity.StabilityPointStructuresFailureMechanismMetaEntities.Single(); + Assert.IsNull(metaEntity.StabilityPointStructureCollectionSourcePath); + } + + [Test] + public void Create_WithStabilityPointStructures_StabilityPointStructureEntitiesCreated() + { + // Setup + StabilityPointStructure structure = new TestStabilityPointStructure(); + + const string filePath = "path/to/structures"; + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + failureMechanism.StabilityPointStructures.AddRange(new[] + { + structure + }, filePath); + + var persistenceRegistry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(persistenceRegistry); + + // Assert + Assert.AreEqual(1, entity.StabilityPointStructureEntities.Count); + Assert.IsTrue(persistenceRegistry.Contains(structure)); + + StabilityPointStructuresFailureMechanismMetaEntity metaEntity = + entity.StabilityPointStructuresFailureMechanismMetaEntities.Single(); + TestHelper.AssertAreEqualButNotSame(filePath, metaEntity.StabilityPointStructureCollectionSourcePath); + } + + [Test] + public void Create_WithCalculationGroup_ReturnFailureMechanismEntityWithCalculationGroupEntities() + { + // Setup + StructuresCalculation calculation = new TestStabilityPointStructuresCalculation(); + calculation.InputParameters.Structure = null; + calculation.InputParameters.HydraulicBoundaryLocation = null; + + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(new CalculationGroup + { + Name = "A" + }); + failureMechanism.CalculationsGroup.Children.Add(calculation); + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(failureMechanism.CalculationsGroup.Name, entity.CalculationGroupEntity.Name); + Assert.AreEqual(0, entity.CalculationGroupEntity.Order); + + CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity.CalculationGroupEntity1 + .OrderBy(cge => cge.Order) + .ToArray(); + Assert.AreEqual(1, childGroupEntities.Length); + CalculationGroupEntity childGroupEntity = childGroupEntities[0]; + Assert.AreEqual("A", childGroupEntity.Name); + Assert.AreEqual(0, childGroupEntity.Order); + + StabilityPointStructuresCalculationEntity[] calculationEntities = entity.CalculationGroupEntity.StabilityPointStructuresCalculationEntities + .OrderBy(ce => ce.Order) + .ToArray(); + StabilityPointStructuresCalculationEntity calculationEntity = calculationEntities[0]; + Assert.AreEqual("Nieuwe berekening", calculationEntity.Name); + Assert.AreEqual(1, calculationEntity.Order); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StabilityPointStructures/StabilityPointStructuresFailureMechanismSectionResultCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StabilityPointStructures/StabilityPointStructuresFailureMechanismSectionResultCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StabilityPointStructures/StabilityPointStructuresFailureMechanismSectionResultCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,138 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.StabilityPointStructures.Data; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.StabilityPointStructures; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.StabilityPointStructures +{ + [TestFixture] + public class StabilityPointStructuresFailureMechanismSectionResultCreateExtensionsTest + { + [Test] + public void Create_FailureMechanismSectionResultNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((StabilityPointStructuresFailureMechanismSectionResult) null).Create(new PersistenceRegistry()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("result", exception.ParamName); + } + + [Test] + public void Create_PersistencyRegistryNull_ThrowsArgumentNullException() + { + // Setup + var sectionResult = new StabilityPointStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + TestDelegate test = () => sectionResult.Create(null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("registry", exception.ParamName); + } + + [Test] + public void Create_WithDifferentResults_ReturnsEntityWithExpectedResults() + { + // Setup + var random = new Random(21); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResult = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + double tailorMadeAssessmentProbability = random.NextDouble(); + bool useManualAssembly = random.NextBoolean(); + double manualAssemblyProbability = random.NextDouble(); + + var sectionResult = new StabilityPointStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + SimpleAssessmentResult = simpleAssessmentResult, + DetailedAssessmentResult = detailedAssessmentResult, + TailorMadeAssessmentResult = tailorMadeAssessmentResult, + TailorMadeAssessmentProbability = tailorMadeAssessmentProbability, + UseManualAssembly = useManualAssembly, + ManualAssemblyProbability = manualAssemblyProbability + }; + + // Call + StabilityPointStructuresSectionResultEntity entity = sectionResult.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(Convert.ToByte(simpleAssessmentResult), entity.SimpleAssessmentResult); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResult), entity.DetailedAssessmentResult); + Assert.AreEqual(Convert.ToByte(tailorMadeAssessmentResult), entity.TailorMadeAssessmentResult); + Assert.AreEqual(tailorMadeAssessmentProbability, entity.TailorMadeAssessmentProbability); + Assert.AreEqual(Convert.ToByte(useManualAssembly), entity.UseManualAssembly); + Assert.AreEqual(manualAssemblyProbability, entity.ManualAssemblyProbability); + + Assert.IsNull(entity.StabilityPointStructuresCalculationEntityId); + } + + [Test] + public void Create_SectionResultWithNaNValues_ReturnsEntityWithExpectedResults() + { + // Setup + var sectionResult = new StabilityPointStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + TailorMadeAssessmentProbability = double.NaN, + ManualAssemblyProbability = double.NaN + }; + + // Call + StabilityPointStructuresSectionResultEntity entity = sectionResult.Create(new PersistenceRegistry()); + + // Assert + Assert.IsNull(entity.TailorMadeAssessmentProbability); + Assert.IsNull(entity.ManualAssemblyProbability); + } + + [Test] + public void Create_CalculationSet_ReturnEntityWithCalculationEntity() + { + // Setup + var calculation = new StructuresCalculation(); + var sectionResult = new StabilityPointStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + Calculation = calculation + }; + + var registry = new PersistenceRegistry(); + var calculationEntity = new StabilityPointStructuresCalculationEntity(); + registry.Register(calculationEntity, calculation); + + // Call + StabilityPointStructuresSectionResultEntity entity = sectionResult.Create(registry); + + // Assert + Assert.AreSame(calculationEntity, entity.StabilityPointStructuresCalculationEntity); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StabilityStoneCover/StabilityStoneCoverFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StabilityStoneCover/StabilityStoneCoverFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StabilityStoneCover/StabilityStoneCoverFailureMechanismCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,237 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.StabilityStoneCover.Data; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.StabilityStoneCover; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.StabilityStoneCover +{ + [TestFixture] + public class StabilityStoneCoverFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new StabilityStoneCoverFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet(bool isRelevant) + { + // Setup + var failureMechanism = new StabilityStoneCoverFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + }, + GeneralInput = + { + N = new Random().NextRoundedDouble(1, 20) + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.StabilityStoneRevetment, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + Assert.AreEqual(failureMechanism.GeneralInput.N, entity.StabilityStoneCoverFailureMechanismMetaEntities.Single().N); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + var failureMechanism = new StabilityStoneCoverFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + TestHelper.AssertAreEqualButNotSame(failureMechanism.InputComments.Body, entity.InputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.OutputComments.Body, entity.OutputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new StabilityStoneCoverFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + Assert.IsNull(entity.FailureMechanismSectionCollectionSourcePath); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + const string filePath = "failureMechanismSections/File/Path"; + var failureMechanism = new StabilityStoneCoverFailureMechanism(); + failureMechanism.SetSections(new[] + { + FailureMechanismSectionTestFactory.CreateFailureMechanismSection() + }, filePath); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.StabilityStoneCoverSectionResultEntities).Count()); + TestHelper.AssertAreEqualButNotSame(filePath, entity.FailureMechanismSectionCollectionSourcePath); + } + + [Test] + public void Create_WithoutForeshoreProfiles_EmptyForeshoreProfilesEntities() + { + // Setup + var failureMechanism = new StabilityStoneCoverFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.ForeshoreProfileEntities); + + StabilityStoneCoverFailureMechanismMetaEntity metaEntity = + entity.StabilityStoneCoverFailureMechanismMetaEntities.Single(); + Assert.IsNull(metaEntity.ForeshoreProfileCollectionSourcePath); + } + + [Test] + public void Create_WithForeshoreProfiles_ForeshoreProfilesEntitiesCreated() + { + // Setup + var failureMechanism = new StabilityStoneCoverFailureMechanism(); + const string filePath = "some/path/to/foreshoreProfiles"; + failureMechanism.ForeshoreProfiles.AddRange(new[] + { + new TestForeshoreProfile() + }, + filePath); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.ForeshoreProfileEntities.Count); + + StabilityStoneCoverFailureMechanismMetaEntity metaEntity = + entity.StabilityStoneCoverFailureMechanismMetaEntities.Single(); + string metaEntityForeshoreProfileCollectionSourcePath = metaEntity.ForeshoreProfileCollectionSourcePath; + TestHelper.AssertAreEqualButNotSame(filePath, metaEntityForeshoreProfileCollectionSourcePath); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCalculationGroup_ReturnFailureMechanismEntityWithCalculationGroupEntities(bool isRelevant) + { + // Setup + var failureMechanism = new StabilityStoneCoverFailureMechanism(); + failureMechanism.WaveConditionsCalculationGroup.Children.Add(new CalculationGroup + { + Name = "A" + }); + failureMechanism.WaveConditionsCalculationGroup.Children.Add(new CalculationGroup + { + Name = "B" + }); + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(failureMechanism.WaveConditionsCalculationGroup.Name, entity.CalculationGroupEntity.Name); + Assert.AreEqual(0, entity.CalculationGroupEntity.Order); + + CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity.CalculationGroupEntity1 + .OrderBy(cge => cge.Order) + .ToArray(); + Assert.AreEqual(2, childGroupEntities.Length); + Assert.AreEqual("A", childGroupEntities[0].Name); + Assert.AreEqual(0, childGroupEntities[0].Order); + Assert.AreEqual("B", childGroupEntities[1].Name); + Assert.AreEqual(1, childGroupEntities[1].Order); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StabilityStoneCover/StabilityStoneCoverFailureMechanismSectionResultCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StabilityStoneCover/StabilityStoneCoverFailureMechanismSectionResultCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StabilityStoneCover/StabilityStoneCoverFailureMechanismSectionResultCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,91 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.AssemblyTool.Data; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.StabilityStoneCover.Data; +using Riskeer.Storage.Core.Create.StabilityStoneCover; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.StabilityStoneCover +{ + [TestFixture] + public class StabilityStoneCoverFailureMechanismSectionResultCreateExtensionsTest + { + [Test] + public void Create_SectionResultNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((StabilityStoneCoverFailureMechanismSectionResult) null).Create(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("result", exception.ParamName); + } + + [Test] + public void Create_WithDifferentResults_ReturnsEntityWithExpectedResults() + { + // Setup + var random = new Random(21); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResultForFactorizedSignalingNorm = random.NextEnumValue(); + var detailedAssessmentResultForSignalingNorm = random.NextEnumValue(); + var detailedAssessmentResultForMechanismSpecificLowerLimitNorm = random.NextEnumValue(); + var detailedAssessmentResultForLowerLimitNorm = random.NextEnumValue(); + var detailedAssessmentResultForFactorizedLowerLimitNorm = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + bool useManualAssembly = random.NextBoolean(); + var manualAssemblyCategoryGroup = random.NextEnumValue(); + + var sectionResult = new StabilityStoneCoverFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + SimpleAssessmentResult = simpleAssessmentResult, + DetailedAssessmentResultForFactorizedSignalingNorm = detailedAssessmentResultForFactorizedSignalingNorm, + DetailedAssessmentResultForSignalingNorm = detailedAssessmentResultForSignalingNorm, + DetailedAssessmentResultForMechanismSpecificLowerLimitNorm = detailedAssessmentResultForMechanismSpecificLowerLimitNorm, + DetailedAssessmentResultForLowerLimitNorm = detailedAssessmentResultForLowerLimitNorm, + DetailedAssessmentResultForFactorizedLowerLimitNorm = detailedAssessmentResultForFactorizedLowerLimitNorm, + TailorMadeAssessmentResult = tailorMadeAssessmentResult, + UseManualAssembly = useManualAssembly, + ManualAssemblyCategoryGroup = manualAssemblyCategoryGroup + }; + + // Call + StabilityStoneCoverSectionResultEntity entity = sectionResult.Create(); + + // Assert + Assert.AreEqual(Convert.ToByte(simpleAssessmentResult), entity.SimpleAssessmentResult); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResultForFactorizedSignalingNorm), entity.DetailedAssessmentResultForFactorizedSignalingNorm); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResultForSignalingNorm), entity.DetailedAssessmentResultForSignalingNorm); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResultForMechanismSpecificLowerLimitNorm), entity.DetailedAssessmentResultForMechanismSpecificLowerLimitNorm); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResultForLowerLimitNorm), entity.DetailedAssessmentResultForLowerLimitNorm); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResultForFactorizedLowerLimitNorm), entity.DetailedAssessmentResultForFactorizedLowerLimitNorm); + Assert.AreEqual(Convert.ToByte(tailorMadeAssessmentResult), entity.TailorMadeAssessmentResult); + Assert.AreEqual(Convert.ToByte(useManualAssembly), entity.UseManualAssembly); + Assert.AreEqual(Convert.ToByte(manualAssemblyCategoryGroup), entity.ManualAssemblyCategoryGroup); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StabilityStoneCover/StabilityStoneCoverWaveConditionsCalculationCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StabilityStoneCover/StabilityStoneCoverWaveConditionsCalculationCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StabilityStoneCover/StabilityStoneCoverWaveConditionsCalculationCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,245 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Data; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Revetment.Data; +using Ringtoets.Revetment.Data.TestUtil; +using Ringtoets.StabilityStoneCover.Data; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.StabilityStoneCover; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.StabilityStoneCover +{ + [TestFixture] + public class StabilityStoneCoverWaveConditionsCalculationCreateExtensionsTest + { + [Test] + public void Create_CalculationNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((StabilityStoneCoverWaveConditionsCalculation) null).Create(new PersistenceRegistry(), 0); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("calculation", exception.ParamName); + } + + [Test] + public void Create_PersistenceRegistryNull_ThrowArgumentNullException() + { + // Setup + var calculation = new StabilityStoneCoverWaveConditionsCalculation(); + + // Call + TestDelegate call = () => calculation.Create(null, 0); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual(paramName, "registry"); + } + + [Test] + public void Create_CalculationWithPropertiesSet_ReturnCalculationEntity() + { + // Setup + var random = new Random(21); + int order = random.Next(); + + var calculation = new StabilityStoneCoverWaveConditionsCalculation + { + InputParameters = + { + Orientation = random.NextRoundedDouble(0, 360), + UseBreakWater = random.NextBoolean(), + UseForeshore = random.NextBoolean(), + UpperBoundaryRevetment = (RoundedDouble) 6.10, + LowerBoundaryRevetment = (RoundedDouble) 3.58, + UpperBoundaryWaterLevels = (RoundedDouble) 5.88, + LowerBoundaryWaterLevels = (RoundedDouble) 3.40, + StepSize = random.NextEnumValue(), + CategoryType = random.NextEnumValue() + } + }; + + var registry = new PersistenceRegistry(); + + // Call + StabilityStoneCoverWaveConditionsCalculationEntity entity = calculation.Create(registry, order); + + // Assert + AssessmentSectionCategoryWaveConditionsInput input = calculation.InputParameters; + Assert.AreEqual(input.Orientation, entity.Orientation, input.Orientation.GetAccuracy()); + Assert.AreEqual(Convert.ToByte(input.UseBreakWater), entity.UseBreakWater); + Assert.AreEqual(Convert.ToByte(input.UseForeshore), entity.UseForeshore); + Assert.AreEqual(input.UpperBoundaryRevetment, entity.UpperBoundaryRevetment, input.UpperBoundaryRevetment.GetAccuracy()); + Assert.AreEqual(input.LowerBoundaryRevetment, entity.LowerBoundaryRevetment, input.LowerBoundaryRevetment.GetAccuracy()); + Assert.AreEqual(input.UpperBoundaryWaterLevels, entity.UpperBoundaryWaterLevels, input.UpperBoundaryWaterLevels.GetAccuracy()); + Assert.AreEqual(input.LowerBoundaryWaterLevels, entity.LowerBoundaryWaterLevels, input.LowerBoundaryWaterLevels.GetAccuracy()); + Assert.AreEqual(Convert.ToByte(input.StepSize), entity.StepSize); + Assert.AreEqual(Convert.ToByte(input.CategoryType), entity.CategoryType); + + Assert.AreEqual(order, entity.Order); + Assert.IsNull(entity.CalculationGroupEntity); + CollectionAssert.IsEmpty(entity.StabilityStoneCoverWaveConditionsOutputEntities); + Assert.IsNull(entity.ForeshoreProfileEntity); + Assert.IsNull(entity.HydraulicLocationEntity); + } + + [Test] + public void Create_CalculationWithNaNProperties_ReturnCalculationEntity() + { + // Setup + var calculation = new StabilityStoneCoverWaveConditionsCalculation + { + InputParameters = + { + Orientation = RoundedDouble.NaN, + UpperBoundaryRevetment = RoundedDouble.NaN, + LowerBoundaryRevetment = RoundedDouble.NaN, + UpperBoundaryWaterLevels = RoundedDouble.NaN, + LowerBoundaryWaterLevels = RoundedDouble.NaN, + BreakWater = + { + Height = RoundedDouble.NaN + } + } + }; + + var registry = new PersistenceRegistry(); + + // Call + StabilityStoneCoverWaveConditionsCalculationEntity entity = calculation.Create(registry, 1234); + + // Assert + Assert.IsNull(entity.Orientation); + Assert.IsNull(entity.UpperBoundaryRevetment); + Assert.IsNull(entity.LowerBoundaryRevetment); + Assert.IsNull(entity.UpperBoundaryWaterLevels); + Assert.IsNull(entity.LowerBoundaryWaterLevels); + Assert.IsNull(entity.BreakWaterHeight); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string name = "A"; + const string comments = "B"; + var calculation = new StabilityStoneCoverWaveConditionsCalculation + { + Name = name, + Comments = + { + Body = comments + } + }; + + var registry = new PersistenceRegistry(); + + // Call + StabilityStoneCoverWaveConditionsCalculationEntity entity = calculation.Create(registry, 0); + + // Assert + TestHelper.AssertAreEqualButNotSame(calculation.Name, entity.Name); + TestHelper.AssertAreEqualButNotSame(calculation.Comments.Body, entity.Comments); + } + + [Test] + public void Create_HydraulicBoundaryLocation_EntityHasHydraulicLocationEntity() + { + // Setup + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "A", 2.3, 4.5); + + var registry = new PersistenceRegistry(); + HydraulicLocationEntity hydraulicLocationEntity = hydraulicBoundaryLocation.Create(registry, 0); + + var calculation = new StabilityStoneCoverWaveConditionsCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation + } + }; + + // Call + StabilityStoneCoverWaveConditionsCalculationEntity entity = calculation.Create(registry, 0); + + // Assert + Assert.AreSame(hydraulicLocationEntity, entity.HydraulicLocationEntity); + } + + [Test] + public void Create_HasForeshoreProfile_EntityHasForeshoreProfileEntity() + { + // Setup + var registry = new PersistenceRegistry(); + var calculation = new StabilityStoneCoverWaveConditionsCalculation + { + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile() + } + }; + + // Call + StabilityStoneCoverWaveConditionsCalculationEntity entity = calculation.Create(registry, 0); + + // Assert + Assert.IsNotNull(entity.ForeshoreProfileEntity); + } + + [Test] + public void Create_HasCalculationOutputs_EntityHasOrderedCalculationOutputEntity() + { + // Setup + var registry = new PersistenceRegistry(); + var calculation = new StabilityStoneCoverWaveConditionsCalculation + { + Output = new StabilityStoneCoverWaveConditionsOutput(new[] + { + new TestWaveConditionsOutput() + }, new[] + { + new TestWaveConditionsOutput() + }) + }; + + // Call + StabilityStoneCoverWaveConditionsCalculationEntity entity = calculation.Create(registry, 0); + + // Assert + Assert.AreEqual(2, entity.StabilityStoneCoverWaveConditionsOutputEntities.Count); + Assert.AreEqual(new[] + { + 0, + 1 + }, entity.StabilityStoneCoverWaveConditionsOutputEntities.Select(oe => oe.Order)); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StabilityStoneCover/StabilityStoneCoverWaveConditionsOutputCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StabilityStoneCover/StabilityStoneCoverWaveConditionsOutputCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StabilityStoneCover/StabilityStoneCoverWaveConditionsOutputCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,94 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Revetment.Data; +using Ringtoets.Revetment.Data.TestUtil; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.StabilityStoneCover +{ + [TestFixture] + public class StabilityStoneCoverWaveConditionsOutputCreateExtensionsTest + { + [Test] + [TestCase(WaveConditionsOutputType.Blocks)] + [TestCase(WaveConditionsOutputType.Columns)] + public void Create_AllOutputValuesSet_ReturnEntity(WaveConditionsOutputType outputType) + { + // Setup + var output = new TestWaveConditionsOutput(); + const int order = 22; + + // Call + StabilityStoneCoverWaveConditionsOutputEntity entity = output.CreateStabilityStoneCoverWaveConditionsOutputEntity(outputType, order); + + // Assert + Assert.AreEqual(order, entity.Order); + Assert.AreEqual(output.WaterLevel, entity.WaterLevel, output.WaterLevel.GetAccuracy()); + Assert.AreEqual(output.WaveHeight, entity.WaveHeight, output.WaveHeight.GetAccuracy()); + Assert.AreEqual(output.WavePeakPeriod, entity.WavePeakPeriod, output.WavePeakPeriod.GetAccuracy()); + Assert.AreEqual(output.WaveAngle, entity.WaveAngle, output.WaveAngle.GetAccuracy()); + Assert.AreEqual(Convert.ToByte(outputType), entity.OutputType); + Assert.AreEqual(output.WaveDirection, entity.WaveDirection, output.WaveDirection.GetAccuracy()); + Assert.AreEqual(output.TargetProbability, entity.TargetProbability); + Assert.AreEqual(output.TargetReliability, entity.TargetReliability, output.TargetReliability.GetAccuracy()); + Assert.AreEqual(output.CalculatedProbability, entity.CalculatedProbability); + Assert.AreEqual(output.CalculatedReliability, entity.CalculatedReliability, output.CalculatedReliability.GetAccuracy()); + Assert.AreEqual(output.CalculationConvergence, (CalculationConvergence) entity.CalculationConvergence); + + Assert.AreEqual(0, entity.StabilityStoneCoverWaveConditionsOutputEntityId); + Assert.AreEqual(0, entity.StabilityStoneCoverWaveConditionsCalculationEntityId); + } + + [Test] + [TestCase(WaveConditionsOutputType.Blocks)] + [TestCase(WaveConditionsOutputType.Columns)] + public void Create_AllOutputValuesNaN_ReturnEntityWithNullValues(WaveConditionsOutputType outputType) + { + // Setup + var output = new WaveConditionsOutput(double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, + double.NaN, double.NaN, double.NaN, CalculationConvergence.NotCalculated); + + // Call + StabilityStoneCoverWaveConditionsOutputEntity entity = output.CreateStabilityStoneCoverWaveConditionsOutputEntity(outputType, 22); + + // Assert + Assert.IsNull(entity.WaterLevel); + Assert.IsNull(entity.WaveHeight); + Assert.IsNull(entity.WavePeakPeriod); + Assert.IsNull(entity.WaveAngle); + Assert.AreEqual(Convert.ToByte(outputType), entity.OutputType); + Assert.IsNull(entity.WaveDirection); + Assert.IsNull(entity.TargetProbability); + Assert.IsNull(entity.TargetReliability); + Assert.IsNull(entity.CalculatedProbability); + Assert.IsNull(entity.CalculatedReliability); + + Assert.AreEqual(0, entity.StabilityStoneCoverWaveConditionsOutputEntityId); + Assert.AreEqual(0, entity.StabilityStoneCoverWaveConditionsCalculationEntityId); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StrengthStabilityLengthwise/StrengthStabilityLengthwiseConstructionFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StrengthStabilityLengthwise/StrengthStabilityLengthwiseConstructionFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StrengthStabilityLengthwise/StrengthStabilityLengthwiseConstructionFailureMechanismCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,154 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Integration.Data.StandAlone; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.StrengthStabilityLengthwise; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.StrengthStabilityLengthwise +{ + [TestFixture] + public class StrengthStabilityLengthwiseConstructionFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new StrengthStabilityLengthwiseConstructionFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndProperties_ReturnsExpectedEntity(bool isRelevant) + { + // Setup + var failureMechanism = new StrengthStabilityLengthwiseConstructionFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.StrengthAndStabilityParallelConstruction, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + var failureMechanism = new StrengthStabilityLengthwiseConstructionFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + TestHelper.AssertAreEqualButNotSame(failureMechanism.InputComments.Body, entity.InputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.OutputComments.Body, entity.OutputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new StrengthStabilityLengthwiseConstructionFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + Assert.IsNull(entity.FailureMechanismSectionCollectionSourcePath); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + const string filePath = "failureMechanismSections/File/Path"; + var failureMechanism = new StrengthStabilityLengthwiseConstructionFailureMechanism(); + failureMechanism.SetSections(new[] + { + FailureMechanismSectionTestFactory.CreateFailureMechanismSection() + }, filePath); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.StrengthStabilityLengthwiseConstructionSectionResultEntities).Count()); + TestHelper.AssertAreEqualButNotSame(filePath, entity.FailureMechanismSectionCollectionSourcePath); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StrengthStabilityLengthwise/StrengthStabilityLengthwiseConstructionFailureMechanismSectionResultCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StrengthStabilityLengthwise/StrengthStabilityLengthwiseConstructionFailureMechanismSectionResultCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StrengthStabilityLengthwise/StrengthStabilityLengthwiseConstructionFailureMechanismSectionResultCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,75 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.Integration.Data.StandAlone.SectionResults; +using Riskeer.Storage.Core.Create.StrengthStabilityLengthwise; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.StrengthStabilityLengthwise +{ + [TestFixture] + public class StrengthStabilityLengthwiseConstructionFailureMechanismSectionResultCreateExtensionsTest + { + [Test] + public void Create_SectionResultNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((StrengthStabilityLengthwiseConstructionFailureMechanismSectionResult) null).Create(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("result", exception.ParamName); + } + + [Test] + public void Create_WithDifferentResults_ReturnsEntityWithExpectedResults() + { + // Setup + var random = new Random(39); + var simpleAssessmentResult = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + bool useManualAssembly = random.NextBoolean(); + var manualAssemblyCategoryGroup = random.NextEnumValue(); + + var sectionResult = new StrengthStabilityLengthwiseConstructionFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + SimpleAssessmentResult = simpleAssessmentResult, + TailorMadeAssessmentResult = tailorMadeAssessmentResult, + UseManualAssembly = useManualAssembly, + ManualAssemblyCategoryGroup = manualAssemblyCategoryGroup + }; + + // Call + StrengthStabilityLengthwiseConstructionSectionResultEntity entity = sectionResult.Create(); + + // Assert + Assert.AreEqual(Convert.ToByte(simpleAssessmentResult), entity.SimpleAssessmentResult); + Assert.AreEqual(Convert.ToByte(tailorMadeAssessmentResult), entity.TailorMadeAssessmentResult); + Assert.AreEqual(Convert.ToByte(useManualAssembly), entity.UseManualAssembly); + Assert.AreEqual(Convert.ToByte(manualAssemblyCategoryGroup), entity.ManualAssemblyCategoryGroup); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StructuresCalculationCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StructuresCalculationCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StructuresCalculationCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,1219 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Data; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.ClosingStructures.Data; +using Ringtoets.ClosingStructures.Data.TestUtil; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.HeightStructures.Data; +using Ringtoets.HeightStructures.Data.TestUtil; +using Ringtoets.StabilityPointStructures.Data; +using Ringtoets.StabilityPointStructures.Data.TestUtil; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create +{ + [TestFixture] + public class StructuresCalculationCreateExtensionsTest + { + private static void AssertStructuresOutputEntity(StructuresOutput output, T outputEntity) + where T : IHasGeneralResultFaultTreeIllustrationPointEntity, IStructuresOutputEntity + { + Assert.AreEqual(output.Reliability, outputEntity.Reliability); + + Assert.IsNull(outputEntity.GeneralResultFaultTreeIllustrationPointEntity); + } + + #region CreateForHeightStructures + + [Test] + public void CreateForHeightStructures_PersistenceRegistryNull_ThrowArgumentNullException() + { + // Setup + var calculation = new StructuresCalculation(); + + // Call + TestDelegate call = () => calculation.CreateForHeightStructures(null, 0); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase("I have no comments", null, 0, 827364)] + [TestCase("I have a comment", "I am comment", 98, 231)] + public void CreateForHeightStructures_ValidCalculation_ReturnEntity(string name, string comments, int order, int randomSeed) + { + // Setup + var random = new Random(randomSeed); + + var calculation = new StructuresCalculation + { + Name = name, + Comments = + { + Body = comments + }, + InputParameters = + { + StructureNormalOrientation = random.NextRoundedDouble(0, 360), + ModelFactorSuperCriticalFlow = + { + Mean = random.NextRoundedDouble(-9999.9999, 9999.9999) + }, + AllowedLevelIncreaseStorage = + { + Mean = random.NextRoundedDouble(1e-6, 9999.9999), + StandardDeviation = random.NextRoundedDouble(1e-6, 9999.9999) + }, + StorageStructureArea = + { + Mean = random.NextRoundedDouble(1e-6, 9999.9999), + CoefficientOfVariation = random.NextRoundedDouble(1e-6, 9999.9999) + }, + FlowWidthAtBottomProtection = + { + Mean = random.NextRoundedDouble(1e-6, 9999.9999), + StandardDeviation = random.NextRoundedDouble(1e-6, 9999.9999) + }, + CriticalOvertoppingDischarge = + { + Mean = random.NextRoundedDouble(1e-6, 9999.9999), + CoefficientOfVariation = random.NextRoundedDouble(1e-6, 9999.9999) + }, + FailureProbabilityStructureWithErosion = random.NextDouble(), + WidthFlowApertures = + { + Mean = random.NextRoundedDouble(-9999.9999, 9999.9999), + StandardDeviation = random.NextRoundedDouble(1e-6, 9999.9999) + }, + StormDuration = + { + Mean = random.NextRoundedDouble(1e-6, 9999.9999), + CoefficientOfVariation = random.NextRoundedDouble(1e-6, 9999.9999) + }, + DeviationWaveDirection = random.NextRoundedDouble(), + LevelCrestStructure = + { + Mean = random.NextRoundedDouble(-9999.9999, 9999.9999), + StandardDeviation = random.NextRoundedDouble(1e-6, 9999.9999) + }, + UseBreakWater = true, + UseForeshore = false, + BreakWater = + { + Height = random.NextRoundedDouble(), + Type = BreakWaterType.Dam + }, + ShouldIllustrationPointsBeCalculated = random.NextBoolean() + } + }; + + var registry = new PersistenceRegistry(); + + // Call + HeightStructuresCalculationEntity entity = calculation.CreateForHeightStructures(registry, order); + + // Assert + Assert.AreEqual(0, entity.HeightStructuresCalculationEntityId); + TestHelper.AssertAreEqualButNotSame(name, entity.Name); + TestHelper.AssertAreEqualButNotSame(comments, entity.Comments); + Assert.AreEqual(order, entity.Order); + + HeightStructuresInput input = calculation.InputParameters; + Assert.AreEqual(input.StructureNormalOrientation.Value, entity.StructureNormalOrientation); + Assert.AreEqual(input.ModelFactorSuperCriticalFlow.Mean.Value, entity.ModelFactorSuperCriticalFlowMean); + Assert.AreEqual(input.AllowedLevelIncreaseStorage.Mean.Value, entity.AllowedLevelIncreaseStorageMean); + Assert.AreEqual(input.AllowedLevelIncreaseStorage.StandardDeviation.Value, entity.AllowedLevelIncreaseStorageStandardDeviation); + Assert.AreEqual(input.StorageStructureArea.Mean.Value, entity.StorageStructureAreaMean); + Assert.AreEqual(input.StorageStructureArea.CoefficientOfVariation.Value, entity.StorageStructureAreaCoefficientOfVariation); + Assert.AreEqual(input.FlowWidthAtBottomProtection.Mean.Value, entity.FlowWidthAtBottomProtectionMean); + Assert.AreEqual(input.FlowWidthAtBottomProtection.StandardDeviation.Value, entity.FlowWidthAtBottomProtectionStandardDeviation); + Assert.AreEqual(input.CriticalOvertoppingDischarge.Mean.Value, entity.CriticalOvertoppingDischargeMean); + Assert.AreEqual(input.CriticalOvertoppingDischarge.CoefficientOfVariation.Value, entity.CriticalOvertoppingDischargeCoefficientOfVariation); + Assert.AreEqual(input.FailureProbabilityStructureWithErosion, entity.FailureProbabilityStructureWithErosion); + Assert.AreEqual(input.WidthFlowApertures.Mean.Value, entity.WidthFlowAperturesMean); + Assert.AreEqual(input.WidthFlowApertures.StandardDeviation.Value, entity.WidthFlowAperturesStandardDeviation); + Assert.AreEqual(input.StormDuration.Mean.Value, entity.StormDurationMean); + + Assert.AreEqual(input.LevelCrestStructure.Mean.Value, entity.LevelCrestStructureMean); + Assert.AreEqual(input.LevelCrestStructure.StandardDeviation.Value, entity.LevelCrestStructureStandardDeviation); + Assert.AreEqual(input.DeviationWaveDirection.Value, entity.DeviationWaveDirection); + + Assert.IsNull(entity.CalculationGroupEntity); + Assert.IsNull(entity.ForeshoreProfileEntityId); + Assert.IsNull(entity.HeightStructureEntityId); + Assert.IsNull(entity.HydraulicLocationEntityId); + + Assert.AreEqual(input.BreakWater.Height.Value, entity.BreakWaterHeight); + Assert.AreEqual((short) input.BreakWater.Type, entity.BreakWaterType); + Assert.AreEqual(Convert.ToByte(input.UseBreakWater), entity.UseBreakWater); + Assert.AreEqual(Convert.ToByte(input.UseForeshore), entity.UseForeshore); + + Assert.AreEqual(Convert.ToByte(input.ShouldIllustrationPointsBeCalculated), entity.ShouldIllustrationPointsBeCalculated); + + CollectionAssert.IsEmpty(entity.HeightStructuresOutputEntities); + } + + [Test] + public void CreateForHeightStructures_NaNParameters_EntityWithNullFields() + { + // Setup + var calculation = new StructuresCalculation + { + InputParameters = + { + StructureNormalOrientation = RoundedDouble.NaN, + ModelFactorSuperCriticalFlow = + { + Mean = RoundedDouble.NaN + }, + AllowedLevelIncreaseStorage = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + StorageStructureArea = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + FlowWidthAtBottomProtection = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + CriticalOvertoppingDischarge = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + WidthFlowApertures = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + StormDuration = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + LevelCrestStructure = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + DeviationWaveDirection = RoundedDouble.NaN, + BreakWater = + { + Height = RoundedDouble.NaN + } + } + }; + var registry = new PersistenceRegistry(); + + // Call + HeightStructuresCalculationEntity entity = calculation.CreateForHeightStructures(registry, 0); + + // Assert + Assert.IsNull(entity.StructureNormalOrientation); + Assert.IsNull(entity.ModelFactorSuperCriticalFlowMean); + Assert.IsNull(entity.AllowedLevelIncreaseStorageMean); + Assert.IsNull(entity.AllowedLevelIncreaseStorageStandardDeviation); + Assert.IsNull(entity.StorageStructureAreaMean); + Assert.IsNull(entity.StorageStructureAreaCoefficientOfVariation); + Assert.IsNull(entity.FlowWidthAtBottomProtectionMean); + Assert.IsNull(entity.FlowWidthAtBottomProtectionStandardDeviation); + Assert.IsNull(entity.CriticalOvertoppingDischargeMean); + Assert.IsNull(entity.CriticalOvertoppingDischargeCoefficientOfVariation); + Assert.IsNull(entity.WidthFlowAperturesMean); + Assert.IsNull(entity.WidthFlowAperturesStandardDeviation); + Assert.IsNull(entity.StormDurationMean); + Assert.IsNull(entity.DeviationWaveDirection); + Assert.IsNull(entity.LevelCrestStructureMean); + Assert.IsNull(entity.LevelCrestStructureStandardDeviation); + + Assert.IsNull(entity.BreakWaterHeight); + } + + [Test] + public void CreateForHeightStructures_CalculationWithAlreadySavedHydraulicBoundaryLocation_ReturnEntityWithHydraulicLocationEntity() + { + // Setup + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "A", 1, 1); + var calculation = new StructuresCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation + } + }; + + var hydraulicLocationEntity = new HydraulicLocationEntity(); + var registry = new PersistenceRegistry(); + registry.Register(hydraulicLocationEntity, hydraulicBoundaryLocation); + + // Call + HeightStructuresCalculationEntity entity = calculation.CreateForHeightStructures(registry, 0); + + // Assert + Assert.AreSame(hydraulicLocationEntity, entity.HydraulicLocationEntity); + } + + [Test] + public void CreateForHeightStructures_CalculationWithAlreadySavedHeightStructure_ReturnEntityWithHeightStructureEntity() + { + // Setup + var heightStructure = new TestHeightStructure(); + var calculation = new StructuresCalculation + { + InputParameters = + { + Structure = heightStructure + } + }; + + var heightStructureEntity = new HeightStructureEntity(); + var registry = new PersistenceRegistry(); + registry.Register(heightStructureEntity, heightStructure); + + // Call + HeightStructuresCalculationEntity entity = calculation.CreateForHeightStructures(registry, 0); + + // Assert + Assert.AreSame(heightStructureEntity, entity.HeightStructureEntity); + } + + [Test] + public void CreateForHeightStructures_CalculationWithAlreadySavedForeshoreProfile_ReturnEntityWithForeshoreProfileEntity() + { + // Setup + var foreshoreProfile = new TestForeshoreProfile(); + var calculation = new StructuresCalculation + { + InputParameters = + { + ForeshoreProfile = foreshoreProfile + } + }; + + var foreshoreProfileEntity = new ForeshoreProfileEntity(); + var registry = new PersistenceRegistry(); + registry.Register(foreshoreProfileEntity, foreshoreProfile); + + // Call + HeightStructuresCalculationEntity entity = calculation.CreateForHeightStructures(registry, 0); + + // Assert + Assert.AreSame(foreshoreProfileEntity, entity.ForeshoreProfileEntity); + } + + [Test] + public void CreateForHeightStructures_CalculationWithOutput_ReturnEntity() + { + // Setup + var calculation = new StructuresCalculation + { + Output = new TestStructuresOutput() + }; + + var registry = new PersistenceRegistry(); + + // Call + HeightStructuresCalculationEntity entity = calculation.CreateForHeightStructures(registry, 0); + + // Assert + AssertStructuresOutputEntity(calculation.Output, entity.HeightStructuresOutputEntities.Single()); + } + + #endregion + + #region CreateForClosingStructures + + [Test] + public void CreateForClosingStructures_RegistryIsNull_ThrowArgumentNullException() + { + // Setup + var calculation = new StructuresCalculation(); + + // Call + TestDelegate call = () => calculation.CreateForClosingStructures(null, 0); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + public void CreateForClosingStructures_ValidCalculation_ReturnClosingStructuresCalculationEntity() + { + // Setup + var random = new Random(45); + var calculation = new StructuresCalculation + { + Name = "A", + Comments = + { + Body = "B" + }, + InputParameters = + { + StormDuration = + { + Mean = random.NextRoundedDouble() + }, + StructureNormalOrientation = random.NextRoundedDouble(), + FailureProbabilityStructureWithErosion = random.NextRoundedDouble(), + UseForeshore = random.NextBoolean(), + UseBreakWater = random.NextBoolean(), + BreakWater = + { + Type = BreakWaterType.Dam, + Height = random.NextRoundedDouble() + }, + AllowedLevelIncreaseStorage = + { + Mean = random.NextRoundedDouble(), + StandardDeviation = random.NextRoundedDouble() + }, + StorageStructureArea = + { + Mean = random.NextRoundedDouble(), + CoefficientOfVariation = random.NextRoundedDouble() + }, + FlowWidthAtBottomProtection = + { + Mean = random.NextRoundedDouble(), + StandardDeviation = random.NextRoundedDouble() + }, + CriticalOvertoppingDischarge = + { + Mean = random.NextRoundedDouble(), + CoefficientOfVariation = random.NextRoundedDouble() + }, + ModelFactorSuperCriticalFlow = + { + Mean = random.NextRoundedDouble() + }, + WidthFlowApertures = + { + Mean = random.NextRoundedDouble(), + StandardDeviation = random.NextRoundedDouble() + }, + InflowModelType = ClosingStructureInflowModelType.VerticalWall, + InsideWaterLevel = + { + Mean = random.NextRoundedDouble(), + StandardDeviation = random.NextRoundedDouble() + }, + DeviationWaveDirection = random.NextRoundedDouble(), + DrainCoefficient = + { + Mean = random.NextRoundedDouble() + }, + FactorStormDurationOpenStructure = random.NextRoundedDouble(), + ThresholdHeightOpenWeir = + { + Mean = random.NextRoundedDouble(), + StandardDeviation = random.NextRoundedDouble() + }, + AreaFlowApertures = + { + Mean = random.NextRoundedDouble(), + StandardDeviation = random.NextRoundedDouble() + }, + FailureProbabilityOpenStructure = random.NextRoundedDouble(), + FailureProbabilityReparation = random.NextRoundedDouble(), + IdenticalApertures = random.Next(), + LevelCrestStructureNotClosing = + { + Mean = random.NextRoundedDouble(), + StandardDeviation = random.NextRoundedDouble() + }, + ProbabilityOpenStructureBeforeFlooding = random.NextRoundedDouble(), + ShouldIllustrationPointsBeCalculated = random.NextBoolean() + } + }; + + var registry = new PersistenceRegistry(); + + const int order = 67; + + // Call + ClosingStructuresCalculationEntity entity = calculation.CreateForClosingStructures(registry, order); + + // Assert + TestHelper.AssertAreEqualButNotSame(calculation.Name, entity.Name); + TestHelper.AssertAreEqualButNotSame(calculation.Comments.Body, entity.Comments); + + ClosingStructuresInput inputParameters = calculation.InputParameters; + Assert.AreEqual(inputParameters.StormDuration.Mean.Value, entity.StormDurationMean); + Assert.AreEqual(inputParameters.StructureNormalOrientation.Value, entity.StructureNormalOrientation); + Assert.AreEqual(inputParameters.FailureProbabilityStructureWithErosion, entity.FailureProbabilityStructureWithErosion); + Assert.IsNull(entity.ClosingStructureEntity); + Assert.IsNull(entity.HydraulicLocationEntity); + Assert.IsNull(entity.ForeshoreProfileEntity); + Assert.AreEqual(Convert.ToByte(inputParameters.UseForeshore), entity.UseForeshore); + Assert.AreEqual(Convert.ToByte(inputParameters.UseBreakWater), entity.UseBreakWater); + Assert.AreEqual(Convert.ToInt16(inputParameters.BreakWater.Type), entity.BreakWaterType); + Assert.AreEqual(inputParameters.BreakWater.Height.Value, entity.BreakWaterHeight); + Assert.AreEqual(inputParameters.AllowedLevelIncreaseStorage.Mean.Value, entity.AllowedLevelIncreaseStorageMean); + Assert.AreEqual(inputParameters.AllowedLevelIncreaseStorage.StandardDeviation.Value, entity.AllowedLevelIncreaseStorageStandardDeviation); + Assert.AreEqual(inputParameters.StorageStructureArea.Mean.Value, entity.StorageStructureAreaMean); + Assert.AreEqual(inputParameters.StorageStructureArea.CoefficientOfVariation.Value, entity.StorageStructureAreaCoefficientOfVariation); + Assert.AreEqual(inputParameters.FlowWidthAtBottomProtection.Mean.Value, entity.FlowWidthAtBottomProtectionMean); + Assert.AreEqual(inputParameters.FlowWidthAtBottomProtection.StandardDeviation.Value, entity.FlowWidthAtBottomProtectionStandardDeviation); + Assert.AreEqual(inputParameters.CriticalOvertoppingDischarge.Mean.Value, entity.CriticalOvertoppingDischargeMean); + Assert.AreEqual(inputParameters.CriticalOvertoppingDischarge.CoefficientOfVariation.Value, entity.CriticalOvertoppingDischargeCoefficientOfVariation); + Assert.AreEqual(inputParameters.ModelFactorSuperCriticalFlow.Mean.Value, entity.ModelFactorSuperCriticalFlowMean); + Assert.AreEqual(inputParameters.WidthFlowApertures.Mean.Value, entity.WidthFlowAperturesMean); + Assert.AreEqual(inputParameters.WidthFlowApertures.StandardDeviation.Value, entity.WidthFlowAperturesStandardDeviation); + Assert.AreEqual(Convert.ToByte(inputParameters.InflowModelType), entity.InflowModelType); + Assert.AreEqual(inputParameters.InsideWaterLevel.Mean.Value, entity.InsideWaterLevelMean); + Assert.AreEqual(inputParameters.InsideWaterLevel.StandardDeviation.Value, entity.InsideWaterLevelStandardDeviation); + Assert.AreEqual(inputParameters.DeviationWaveDirection.Value, entity.DeviationWaveDirection); + Assert.AreEqual(inputParameters.DrainCoefficient.Mean.Value, entity.DrainCoefficientMean); + Assert.AreEqual(inputParameters.FactorStormDurationOpenStructure.Value, entity.FactorStormDurationOpenStructure); + Assert.AreEqual(inputParameters.ThresholdHeightOpenWeir.Mean.Value, entity.ThresholdHeightOpenWeirMean); + Assert.AreEqual(inputParameters.ThresholdHeightOpenWeir.StandardDeviation.Value, entity.ThresholdHeightOpenWeirStandardDeviation); + Assert.AreEqual(inputParameters.AreaFlowApertures.Mean.Value, entity.AreaFlowAperturesMean); + Assert.AreEqual(inputParameters.AreaFlowApertures.StandardDeviation.Value, entity.AreaFlowAperturesStandardDeviation); + Assert.AreEqual(inputParameters.FailureProbabilityOpenStructure, entity.FailureProbabilityOpenStructure); + Assert.AreEqual(inputParameters.FailureProbabilityReparation, entity.FailureProbabilityReparation); + Assert.AreEqual(inputParameters.IdenticalApertures, entity.IdenticalApertures); + Assert.AreEqual(inputParameters.LevelCrestStructureNotClosing.Mean.Value, entity.LevelCrestStructureNotClosingMean); + Assert.AreEqual(inputParameters.LevelCrestStructureNotClosing.StandardDeviation.Value, entity.LevelCrestStructureNotClosingStandardDeviation); + Assert.AreEqual(inputParameters.ProbabilityOpenStructureBeforeFlooding, entity.ProbabilityOpenStructureBeforeFlooding); + Assert.AreEqual(Convert.ToByte(inputParameters.ShouldIllustrationPointsBeCalculated), entity.ShouldIllustrationPointsBeCalculated); + Assert.AreEqual(order, entity.Order); + + CollectionAssert.IsEmpty(entity.ClosingStructuresOutputEntities); + } + + [Test] + public void CreateForClosingStructures_CalculationWithParametersNaN_ReturnEntityWithNullParameters() + { + // Setup + var calculation = new StructuresCalculation + { + InputParameters = + { + StormDuration = + { + Mean = RoundedDouble.NaN + }, + StructureNormalOrientation = RoundedDouble.NaN, + BreakWater = + { + Height = RoundedDouble.NaN + }, + AllowedLevelIncreaseStorage = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + StorageStructureArea = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + FlowWidthAtBottomProtection = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + CriticalOvertoppingDischarge = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + ModelFactorSuperCriticalFlow = + { + Mean = RoundedDouble.NaN + }, + WidthFlowApertures = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + InsideWaterLevel = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + DeviationWaveDirection = RoundedDouble.NaN, + DrainCoefficient = + { + Mean = RoundedDouble.NaN + }, + FactorStormDurationOpenStructure = RoundedDouble.NaN, + ThresholdHeightOpenWeir = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + AreaFlowApertures = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + LevelCrestStructureNotClosing = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + } + } + }; + + var registry = new PersistenceRegistry(); + + const int order = 67; + + // Call + ClosingStructuresCalculationEntity entity = calculation.CreateForClosingStructures(registry, order); + + // Assert + Assert.IsNull(entity.StormDurationMean); + Assert.IsNull(entity.StructureNormalOrientation); + Assert.IsNull(entity.BreakWaterHeight); + Assert.IsNull(entity.AllowedLevelIncreaseStorageMean); + Assert.IsNull(entity.AllowedLevelIncreaseStorageStandardDeviation); + Assert.IsNull(entity.StorageStructureAreaMean); + Assert.IsNull(entity.StorageStructureAreaCoefficientOfVariation); + Assert.IsNull(entity.FlowWidthAtBottomProtectionMean); + Assert.IsNull(entity.FlowWidthAtBottomProtectionStandardDeviation); + Assert.IsNull(entity.CriticalOvertoppingDischargeMean); + Assert.IsNull(entity.CriticalOvertoppingDischargeCoefficientOfVariation); + Assert.IsNull(entity.ModelFactorSuperCriticalFlowMean); + Assert.IsNull(entity.WidthFlowAperturesMean); + Assert.IsNull(entity.WidthFlowAperturesStandardDeviation); + Assert.IsNull(entity.InsideWaterLevelMean); + Assert.IsNull(entity.InsideWaterLevelStandardDeviation); + Assert.IsNull(entity.DeviationWaveDirection); + Assert.IsNull(entity.DrainCoefficientMean); + Assert.IsNull(entity.FactorStormDurationOpenStructure); + Assert.IsNull(entity.ThresholdHeightOpenWeirMean); + Assert.IsNull(entity.ThresholdHeightOpenWeirStandardDeviation); + Assert.IsNull(entity.AreaFlowAperturesMean); + Assert.IsNull(entity.AreaFlowAperturesStandardDeviation); + Assert.IsNull(entity.LevelCrestStructureNotClosingMean); + Assert.IsNull(entity.LevelCrestStructureNotClosingStandardDeviation); + } + + [Test] + public void CreateForClosingStructures_CalculationWithStructure_ReturnEntityWithStructureEntity() + { + // Setup + ClosingStructure alreadyRegisteredStructure = new TestClosingStructure(); + var calculation = new StructuresCalculation + { + InputParameters = + { + Structure = alreadyRegisteredStructure + } + }; + + var registry = new PersistenceRegistry(); + registry.Register(new ClosingStructureEntity(), alreadyRegisteredStructure); + + // Call + ClosingStructuresCalculationEntity entity = calculation.CreateForClosingStructures(registry, 0); + + // Assert + Assert.IsNotNull(entity.ClosingStructureEntity); + } + + [Test] + public void CreateForClosingStructures_CalculationWithHydraulicBoundaryLocation_ReturnEntityWithHydraulicLocationEntity() + { + // Setup + var alreadyRegisteredHydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "A", 2, 3); + var calculation = new StructuresCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = alreadyRegisteredHydraulicBoundaryLocation + } + }; + + var registry = new PersistenceRegistry(); + registry.Register(new HydraulicLocationEntity(), alreadyRegisteredHydraulicBoundaryLocation); + + // Call + ClosingStructuresCalculationEntity entity = calculation.CreateForClosingStructures(registry, 0); + + // Assert + Assert.IsNotNull(entity.HydraulicLocationEntity); + } + + [Test] + public void CreateForClosingStructures_CalculationWithForeshoreProfile_ReturnEntityWithForeshoreProfileEntity() + { + // Setup + var alreadyRegisteredForeshoreProfile = new TestForeshoreProfile(); + var calculation = new StructuresCalculation + { + InputParameters = + { + ForeshoreProfile = alreadyRegisteredForeshoreProfile + } + }; + + var registry = new PersistenceRegistry(); + registry.Register(new ForeshoreProfileEntity(), alreadyRegisteredForeshoreProfile); + + // Call + ClosingStructuresCalculationEntity entity = calculation.CreateForClosingStructures(registry, 0); + + // Assert + Assert.IsNotNull(entity.ForeshoreProfileEntity); + } + + [Test] + public void CreateForClosingStructures_CalculationWithOutput_ReturnEntity() + { + // Setup + var calculation = new StructuresCalculation + { + Output = new TestStructuresOutput() + }; + + var registry = new PersistenceRegistry(); + + // Call + ClosingStructuresCalculationEntity entity = calculation.CreateForClosingStructures(registry, 0); + + // Assert + AssertStructuresOutputEntity(calculation.Output, entity.ClosingStructuresOutputEntities.Single()); + } + + #endregion + + #region CreateForStabilityPointStructures + + [Test] + public void CreateForStabilityPointStructures_RegistryIsNull_ThrowArgumentNullException() + { + // Setup + var calculation = new StructuresCalculation(); + + // Call + TestDelegate call = () => calculation.CreateForStabilityPointStructures(null, 0); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + public void CreateForStabilityPointStructures_ValidCalculation_ReturnStabilityPointStructuresCalculationEntity() + { + // Setup + var random = new Random(45); + var calculation = new StructuresCalculation + { + Name = "A", + Comments = + { + Body = "B" + }, + InputParameters = + { + StormDuration = + { + Mean = random.NextRoundedDouble() + }, + StructureNormalOrientation = random.NextRoundedDouble(), + FailureProbabilityStructureWithErosion = random.NextDouble(), + UseForeshore = random.NextBoolean(), + UseBreakWater = random.NextBoolean(), + BreakWater = + { + Type = BreakWaterType.Dam, + Height = random.NextRoundedDouble() + }, + AllowedLevelIncreaseStorage = + { + Mean = random.NextRoundedDouble(), + StandardDeviation = random.NextRoundedDouble() + }, + StorageStructureArea = + { + Mean = random.NextRoundedDouble(), + CoefficientOfVariation = random.NextRoundedDouble() + }, + FlowWidthAtBottomProtection = + { + Mean = random.NextRoundedDouble(), + StandardDeviation = random.NextRoundedDouble() + }, + CriticalOvertoppingDischarge = + { + Mean = random.NextRoundedDouble(), + CoefficientOfVariation = random.NextRoundedDouble() + }, + WidthFlowApertures = + { + Mean = random.NextRoundedDouble(), + StandardDeviation = random.NextRoundedDouble() + }, + InsideWaterLevel = + { + Mean = random.NextRoundedDouble(), + StandardDeviation = random.NextRoundedDouble() + }, + ThresholdHeightOpenWeir = + { + Mean = random.NextRoundedDouble(), + StandardDeviation = random.NextRoundedDouble() + }, + ConstructiveStrengthLinearLoadModel = + { + Mean = random.NextRoundedDouble(), + CoefficientOfVariation = random.NextRoundedDouble() + }, + ConstructiveStrengthQuadraticLoadModel = + { + Mean = random.NextRoundedDouble(), + CoefficientOfVariation = random.NextRoundedDouble() + }, + BankWidth = + { + Mean = random.NextRoundedDouble(), + StandardDeviation = random.NextRoundedDouble() + }, + InsideWaterLevelFailureConstruction = + { + Mean = random.NextRoundedDouble(), + StandardDeviation = random.NextRoundedDouble() + }, + EvaluationLevel = random.NextRoundedDouble(), + LevelCrestStructure = + { + Mean = random.NextRoundedDouble(), + StandardDeviation = random.NextRoundedDouble() + }, + VerticalDistance = random.NextRoundedDouble(), + FailureProbabilityRepairClosure = random.NextDouble(), + FailureCollisionEnergy = + { + Mean = random.NextRoundedDouble(), + CoefficientOfVariation = random.NextRoundedDouble() + }, + ShipMass = + { + Mean = random.NextRoundedDouble(), + CoefficientOfVariation = random.NextRoundedDouble() + }, + ShipVelocity = + { + Mean = random.NextRoundedDouble(), + CoefficientOfVariation = random.NextRoundedDouble() + }, + LevellingCount = random.Next(), + ProbabilityCollisionSecondaryStructure = random.NextDouble(), + FlowVelocityStructureClosable = + { + Mean = random.NextRoundedDouble(), + CoefficientOfVariation = random.NextRoundedDouble() + }, + StabilityLinearLoadModel = + { + Mean = random.NextRoundedDouble(), + CoefficientOfVariation = random.NextRoundedDouble() + }, + StabilityQuadraticLoadModel = + { + Mean = random.NextRoundedDouble(), + CoefficientOfVariation = random.NextRoundedDouble() + }, + AreaFlowApertures = + { + Mean = random.NextRoundedDouble(), + StandardDeviation = random.NextRoundedDouble() + }, + InflowModelType = StabilityPointStructureInflowModelType.LowSill, + LoadSchematizationType = LoadSchematizationType.Quadratic, + VolumicWeightWater = random.NextRoundedDouble(), + FactorStormDurationOpenStructure = random.NextRoundedDouble(), + DrainCoefficient = + { + Mean = random.NextRoundedDouble() + }, + ShouldIllustrationPointsBeCalculated = random.NextBoolean() + } + }; + + var registry = new PersistenceRegistry(); + + const int order = 67; + + // Call + StabilityPointStructuresCalculationEntity entity = calculation.CreateForStabilityPointStructures(registry, order); + + // Assert + TestHelper.AssertAreEqualButNotSame(calculation.Name, entity.Name); + TestHelper.AssertAreEqualButNotSame(calculation.Comments.Body, entity.Comments); + + StabilityPointStructuresInput inputParameters = calculation.InputParameters; + Assert.AreEqual(inputParameters.StormDuration.Mean.Value, entity.StormDurationMean); + Assert.AreEqual(inputParameters.StructureNormalOrientation.Value, entity.StructureNormalOrientation); + Assert.AreEqual(inputParameters.FailureProbabilityStructureWithErosion, entity.FailureProbabilityStructureWithErosion); + Assert.IsNull(entity.StabilityPointStructureEntity); + Assert.IsNull(entity.HydraulicLocationEntity); + Assert.IsNull(entity.ForeshoreProfileEntity); + Assert.AreEqual(Convert.ToByte(inputParameters.UseForeshore), entity.UseForeshore); + Assert.AreEqual(Convert.ToByte(inputParameters.UseBreakWater), entity.UseBreakWater); + Assert.AreEqual(Convert.ToInt16(inputParameters.BreakWater.Type), entity.BreakWaterType); + Assert.AreEqual(inputParameters.BreakWater.Height.Value, entity.BreakWaterHeight); + Assert.AreEqual(inputParameters.AllowedLevelIncreaseStorage.Mean.Value, entity.AllowedLevelIncreaseStorageMean); + Assert.AreEqual(inputParameters.AllowedLevelIncreaseStorage.StandardDeviation.Value, entity.AllowedLevelIncreaseStorageStandardDeviation); + Assert.AreEqual(inputParameters.StorageStructureArea.Mean.Value, entity.StorageStructureAreaMean); + Assert.AreEqual(inputParameters.StorageStructureArea.CoefficientOfVariation.Value, entity.StorageStructureAreaCoefficientOfVariation); + Assert.AreEqual(inputParameters.FlowWidthAtBottomProtection.Mean.Value, entity.FlowWidthAtBottomProtectionMean); + Assert.AreEqual(inputParameters.FlowWidthAtBottomProtection.StandardDeviation.Value, entity.FlowWidthAtBottomProtectionStandardDeviation); + Assert.AreEqual(inputParameters.CriticalOvertoppingDischarge.Mean.Value, entity.CriticalOvertoppingDischargeMean); + Assert.AreEqual(inputParameters.CriticalOvertoppingDischarge.CoefficientOfVariation.Value, entity.CriticalOvertoppingDischargeCoefficientOfVariation); + Assert.AreEqual(inputParameters.WidthFlowApertures.Mean.Value, entity.WidthFlowAperturesMean); + Assert.AreEqual(inputParameters.WidthFlowApertures.StandardDeviation.Value, entity.WidthFlowAperturesStandardDeviation); + + Assert.AreEqual(inputParameters.InsideWaterLevel.Mean.Value, entity.InsideWaterLevelMean); + Assert.AreEqual(inputParameters.InsideWaterLevel.StandardDeviation.Value, entity.InsideWaterLevelStandardDeviation); + Assert.AreEqual(inputParameters.ThresholdHeightOpenWeir.Mean.Value, entity.ThresholdHeightOpenWeirMean); + Assert.AreEqual(inputParameters.ThresholdHeightOpenWeir.StandardDeviation.Value, entity.ThresholdHeightOpenWeirStandardDeviation); + Assert.AreEqual(inputParameters.ConstructiveStrengthLinearLoadModel.Mean.Value, entity.ConstructiveStrengthLinearLoadModelMean); + Assert.AreEqual(inputParameters.ConstructiveStrengthLinearLoadModel.CoefficientOfVariation.Value, entity.ConstructiveStrengthLinearLoadModelCoefficientOfVariation); + Assert.AreEqual(inputParameters.ConstructiveStrengthQuadraticLoadModel.Mean.Value, entity.ConstructiveStrengthQuadraticLoadModelMean); + Assert.AreEqual(inputParameters.ConstructiveStrengthQuadraticLoadModel.CoefficientOfVariation.Value, entity.ConstructiveStrengthQuadraticLoadModelCoefficientOfVariation); + Assert.AreEqual(inputParameters.BankWidth.Mean.Value, entity.BankWidthMean); + Assert.AreEqual(inputParameters.BankWidth.StandardDeviation.Value, entity.BankWidthStandardDeviation); + Assert.AreEqual(inputParameters.InsideWaterLevelFailureConstruction.Mean.Value, entity.InsideWaterLevelFailureConstructionMean); + Assert.AreEqual(inputParameters.InsideWaterLevelFailureConstruction.StandardDeviation.Value, entity.InsideWaterLevelFailureConstructionStandardDeviation); + Assert.AreEqual(inputParameters.EvaluationLevel.Value, entity.EvaluationLevel); + Assert.AreEqual(inputParameters.LevelCrestStructure.Mean.Value, entity.LevelCrestStructureMean); + Assert.AreEqual(inputParameters.LevelCrestStructure.StandardDeviation.Value, entity.LevelCrestStructureStandardDeviation); + Assert.AreEqual(inputParameters.VerticalDistance.Value, entity.VerticalDistance); + Assert.AreEqual(inputParameters.FailureProbabilityRepairClosure, entity.FailureProbabilityRepairClosure); + Assert.AreEqual(inputParameters.FailureCollisionEnergy.Mean.Value, entity.FailureCollisionEnergyMean); + Assert.AreEqual(inputParameters.FailureCollisionEnergy.CoefficientOfVariation.Value, entity.FailureCollisionEnergyCoefficientOfVariation); + Assert.AreEqual(inputParameters.ShipMass.Mean.Value, entity.ShipMassMean); + Assert.AreEqual(inputParameters.ShipMass.CoefficientOfVariation.Value, entity.ShipMassCoefficientOfVariation); + Assert.AreEqual(inputParameters.ShipVelocity.Mean.Value, entity.ShipVelocityMean); + Assert.AreEqual(inputParameters.ShipVelocity.CoefficientOfVariation.Value, entity.ShipVelocityCoefficientOfVariation); + Assert.AreEqual(inputParameters.LevellingCount, entity.LevellingCount); + Assert.AreEqual(inputParameters.ProbabilityCollisionSecondaryStructure, entity.ProbabilityCollisionSecondaryStructure); + Assert.AreEqual(inputParameters.FlowVelocityStructureClosable.Mean.Value, entity.FlowVelocityStructureClosableMean); + Assert.AreEqual(inputParameters.StabilityLinearLoadModel.Mean.Value, entity.StabilityLinearLoadModelMean); + Assert.AreEqual(inputParameters.StabilityLinearLoadModel.CoefficientOfVariation.Value, entity.StabilityLinearLoadModelCoefficientOfVariation); + Assert.AreEqual(inputParameters.StabilityQuadraticLoadModel.Mean.Value, entity.StabilityQuadraticLoadModelMean); + Assert.AreEqual(inputParameters.StabilityQuadraticLoadModel.CoefficientOfVariation.Value, entity.StabilityQuadraticLoadModelCoefficientOfVariation); + Assert.AreEqual(inputParameters.AreaFlowApertures.Mean.Value, entity.AreaFlowAperturesMean); + Assert.AreEqual(inputParameters.AreaFlowApertures.StandardDeviation.Value, entity.AreaFlowAperturesStandardDeviation); + Assert.AreEqual(Convert.ToByte(inputParameters.InflowModelType), entity.InflowModelType); + Assert.AreEqual(Convert.ToByte(inputParameters.LoadSchematizationType), entity.LoadSchematizationType); + Assert.AreEqual(inputParameters.VolumicWeightWater.Value, entity.VolumicWeightWater); + Assert.AreEqual(inputParameters.FactorStormDurationOpenStructure.Value, entity.FactorStormDurationOpenStructure); + Assert.AreEqual(inputParameters.DrainCoefficient.Mean.Value, entity.DrainCoefficientMean); + Assert.AreEqual(Convert.ToByte(inputParameters.ShouldIllustrationPointsBeCalculated), entity.ShouldIllustrationPointsBeCalculated); + Assert.AreEqual(order, entity.Order); + + CollectionAssert.IsEmpty(entity.StabilityPointStructuresOutputEntities); + } + + [Test] + public void CreateForStabilityPointStructures_CalculationWithParametersNaN_ReturnEntityWithNullParameters() + { + // Setup + var calculation = new StructuresCalculation + { + InputParameters = + { + StormDuration = + { + Mean = RoundedDouble.NaN + }, + StructureNormalOrientation = RoundedDouble.NaN, + BreakWater = + { + Type = BreakWaterType.Dam, + Height = RoundedDouble.NaN + }, + AllowedLevelIncreaseStorage = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + StorageStructureArea = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + FlowWidthAtBottomProtection = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + CriticalOvertoppingDischarge = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + WidthFlowApertures = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + InsideWaterLevel = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + ThresholdHeightOpenWeir = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + ConstructiveStrengthLinearLoadModel = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + ConstructiveStrengthQuadraticLoadModel = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + BankWidth = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + InsideWaterLevelFailureConstruction = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + EvaluationLevel = RoundedDouble.NaN, + LevelCrestStructure = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + VerticalDistance = RoundedDouble.NaN, + FailureCollisionEnergy = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + ShipMass = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + ShipVelocity = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + FlowVelocityStructureClosable = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + StabilityLinearLoadModel = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + StabilityQuadraticLoadModel = + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }, + AreaFlowApertures = + { + Mean = RoundedDouble.NaN, + StandardDeviation = RoundedDouble.NaN + }, + VolumicWeightWater = RoundedDouble.NaN, + FactorStormDurationOpenStructure = RoundedDouble.NaN, + DrainCoefficient = + { + Mean = RoundedDouble.NaN + } + } + }; + + var registry = new PersistenceRegistry(); + + const int order = 67; + + // Call + StabilityPointStructuresCalculationEntity entity = calculation.CreateForStabilityPointStructures(registry, order); + + // Assert + Assert.IsNull(entity.StormDurationMean); + Assert.IsNull(entity.StructureNormalOrientation); + Assert.IsNull(entity.BreakWaterHeight); + Assert.IsNull(entity.AllowedLevelIncreaseStorageMean); + Assert.IsNull(entity.AllowedLevelIncreaseStorageStandardDeviation); + Assert.IsNull(entity.StorageStructureAreaMean); + Assert.IsNull(entity.StorageStructureAreaCoefficientOfVariation); + Assert.IsNull(entity.FlowWidthAtBottomProtectionMean); + Assert.IsNull(entity.FlowWidthAtBottomProtectionStandardDeviation); + Assert.IsNull(entity.CriticalOvertoppingDischargeMean); + Assert.IsNull(entity.CriticalOvertoppingDischargeCoefficientOfVariation); + Assert.IsNull(entity.WidthFlowAperturesMean); + Assert.IsNull(entity.WidthFlowAperturesStandardDeviation); + + Assert.IsNull(entity.InsideWaterLevelMean); + Assert.IsNull(entity.InsideWaterLevelStandardDeviation); + Assert.IsNull(entity.ThresholdHeightOpenWeirMean); + Assert.IsNull(entity.ThresholdHeightOpenWeirStandardDeviation); + Assert.IsNull(entity.ConstructiveStrengthLinearLoadModelMean); + Assert.IsNull(entity.ConstructiveStrengthLinearLoadModelCoefficientOfVariation); + Assert.IsNull(entity.ConstructiveStrengthQuadraticLoadModelMean); + Assert.IsNull(entity.ConstructiveStrengthQuadraticLoadModelCoefficientOfVariation); + Assert.IsNull(entity.BankWidthMean); + Assert.IsNull(entity.BankWidthStandardDeviation); + Assert.IsNull(entity.InsideWaterLevelFailureConstructionMean); + Assert.IsNull(entity.InsideWaterLevelFailureConstructionStandardDeviation); + Assert.IsNull(entity.EvaluationLevel); + Assert.IsNull(entity.LevelCrestStructureMean); + Assert.IsNull(entity.LevelCrestStructureStandardDeviation); + Assert.IsNull(entity.VerticalDistance); + Assert.IsNull(entity.FailureCollisionEnergyMean); + Assert.IsNull(entity.FailureCollisionEnergyCoefficientOfVariation); + Assert.IsNull(entity.ShipMassMean); + Assert.IsNull(entity.ShipMassCoefficientOfVariation); + Assert.IsNull(entity.ShipVelocityMean); + Assert.IsNull(entity.ShipVelocityCoefficientOfVariation); + Assert.IsNull(entity.FlowVelocityStructureClosableMean); + Assert.IsNull(entity.StabilityLinearLoadModelMean); + Assert.IsNull(entity.StabilityLinearLoadModelCoefficientOfVariation); + Assert.IsNull(entity.StabilityQuadraticLoadModelMean); + Assert.IsNull(entity.StabilityQuadraticLoadModelCoefficientOfVariation); + Assert.IsNull(entity.AreaFlowAperturesMean); + Assert.IsNull(entity.AreaFlowAperturesStandardDeviation); + Assert.IsNull(entity.VolumicWeightWater); + Assert.IsNull(entity.FactorStormDurationOpenStructure); + Assert.IsNull(entity.DrainCoefficientMean); + } + + [Test] + public void CreateForStabilityPointStructures_CalculationWithStructure_ReturnEntityWithStructureEntity() + { + // Setup + StabilityPointStructure alreadyRegisteredStructure = new TestStabilityPointStructure(); + var calculation = new StructuresCalculation + { + InputParameters = + { + Structure = alreadyRegisteredStructure + } + }; + + var registry = new PersistenceRegistry(); + registry.Register(new StabilityPointStructureEntity(), alreadyRegisteredStructure); + + // Call + StabilityPointStructuresCalculationEntity entity = calculation.CreateForStabilityPointStructures(registry, 0); + + // Assert + Assert.IsNotNull(entity.StabilityPointStructureEntity); + } + + [Test] + public void CreateForStabilityPointStructures_CalculationWithHydraulicBoundaryLocation_ReturnEntityWithHydraulicLocationEntity() + { + // Setup + var alreadyRegisteredHydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "A", 2, 3); + var calculation = new StructuresCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = alreadyRegisteredHydraulicBoundaryLocation + } + }; + + var registry = new PersistenceRegistry(); + registry.Register(new HydraulicLocationEntity(), alreadyRegisteredHydraulicBoundaryLocation); + + // Call + StabilityPointStructuresCalculationEntity entity = calculation.CreateForStabilityPointStructures(registry, 0); + + // Assert + Assert.IsNotNull(entity.HydraulicLocationEntity); + } + + [Test] + public void CreateForStabilityPointStructures_CalculationWithForeshoreProfile_ReturnEntityWithForeshoreProfileEntity() + { + // Setup + var alreadyRegisteredForeshoreProfile = new TestForeshoreProfile(); + var calculation = new StructuresCalculation + { + InputParameters = + { + ForeshoreProfile = alreadyRegisteredForeshoreProfile + } + }; + + var registry = new PersistenceRegistry(); + registry.Register(new ForeshoreProfileEntity(), alreadyRegisteredForeshoreProfile); + + // Call + StabilityPointStructuresCalculationEntity entity = calculation.CreateForStabilityPointStructures(registry, 0); + + // Assert + Assert.IsNotNull(entity.ForeshoreProfileEntity); + } + + [Test] + public void CreateForStabilityPointStructures_CalculationWithOutput_ReturnEntity() + { + // Setup + var calculation = new StructuresCalculation + { + Output = new TestStructuresOutput() + }; + + var registry = new PersistenceRegistry(); + + // Call + StabilityPointStructuresCalculationEntity entity = calculation.CreateForStabilityPointStructures(registry, 0); + + // Assert + AssertStructuresOutputEntity(calculation.Output, entity.StabilityPointStructuresOutputEntities.Single()); + } + + #endregion + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StructuresOutputCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StructuresOutputCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/StructuresOutputCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,103 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil.IllustrationPoints; +using Ringtoets.Storage.Core.TestUtil.IllustrationPoints; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create +{ + [TestFixture] + internal class StructuresOutputCreateExtensionsTest + { + [Test] + public void Constructor_StructuresOutputNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((StructuresOutput) null).Create(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("structuresOutput", exception.ParamName); + } + + [Test] + public void Create_CalculationWithOutput_ReturnEntityWithOutput() + { + // Setup + var random = new Random(567); + var output = new StructuresOutput( + random.NextDouble(), null); + + // Call + var entity = output.Create(); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(output.Reliability, entity.Reliability); + Assert.IsNull(entity.GeneralResultFaultTreeIllustrationPointEntity); + } + + [Test] + public void Create_CalculationWithNaNOutput_ReturnEntityWithNullOutput() + { + // Setup + var output = new StructuresOutput( + double.NaN, null); + + // Call + var entity = output.Create(); + + // Assert + Assert.IsNotNull(entity); + Assert.IsNull(entity.Reliability); + Assert.IsNull(entity.GeneralResultFaultTreeIllustrationPointEntity); + } + + [Test] + public void Create_CalculationWithOutputAndGeneralResult_ReturnEntityWithOutputAndGeneralResult() + { + // Setup + var random = new Random(567); + var output = new StructuresOutput(random.NextDouble(), + new TestGeneralResultFaultTreeIllustrationPoint()); + + // Call + var entity = output.Create(); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(output.Reliability, entity.Reliability); + GeneralResultEntityTestHelper.AssertGeneralResultPropertyValues(output.GeneralResult, entity.GeneralResultFaultTreeIllustrationPointEntity); + } + + private class TestStructureOutputEntity : IStructuresOutputEntity, + IHasGeneralResultFaultTreeIllustrationPointEntity + { + public GeneralResultFaultTreeIllustrationPointEntity GeneralResultFaultTreeIllustrationPointEntity { get; set; } + public double? Reliability { get; set; } + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/TechnicalInnovation/TechnicalInnovationFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/TechnicalInnovation/TechnicalInnovationFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/TechnicalInnovation/TechnicalInnovationFailureMechanismCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,154 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Integration.Data.StandAlone; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.TechnicalInnovation; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.TechnicalInnovation +{ + [TestFixture] + public class TechnicalInnovationFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new TechnicalInnovationFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet(bool isRelevant) + { + // Setup + var failureMechanism = new TechnicalInnovationFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.TechnicalInnovations, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + var failureMechanism = new TechnicalInnovationFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + TestHelper.AssertAreEqualButNotSame(failureMechanism.InputComments.Body, entity.InputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.OutputComments.Body, entity.OutputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new TechnicalInnovationFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + Assert.IsNull(entity.FailureMechanismSectionCollectionSourcePath); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + const string filePath = "failureMechanismSections/File/Path"; + var failureMechanism = new TechnicalInnovationFailureMechanism(); + failureMechanism.SetSections(new[] + { + FailureMechanismSectionTestFactory.CreateFailureMechanismSection() + }, filePath); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.TechnicalInnovationSectionResultEntities).Count()); + TestHelper.AssertAreEqualButNotSame(filePath, entity.FailureMechanismSectionCollectionSourcePath); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/TechnicalInnovation/TechnicalInnovationFailureMechanismSectionResultCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/TechnicalInnovation/TechnicalInnovationFailureMechanismSectionResultCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/TechnicalInnovation/TechnicalInnovationFailureMechanismSectionResultCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,75 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.Integration.Data.StandAlone.SectionResults; +using Riskeer.Storage.Core.Create.TechnicalInnovation; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.TechnicalInnovation +{ + [TestFixture] + public class TechnicalInnovationFailureMechanismSectionResultCreateExtensionsTest + { + [Test] + public void Create_SectionResultNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((TechnicalInnovationFailureMechanismSectionResult) null).Create(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("result", exception.ParamName); + } + + [Test] + public void Create_WithDifferentResults_ReturnsEntityWithExpectedResults() + { + // Setup + var random = new Random(39); + var simpleAssessmentResult = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + bool useManualAssembly = random.NextBoolean(); + var manualAssemblyCategoryGroup = random.NextEnumValue(); + + var sectionResult = new TechnicalInnovationFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + SimpleAssessmentResult = simpleAssessmentResult, + TailorMadeAssessmentResult = tailorMadeAssessmentResult, + UseManualAssembly = useManualAssembly, + ManualAssemblyCategoryGroup = manualAssemblyCategoryGroup + }; + + // Call + TechnicalInnovationSectionResultEntity entity = sectionResult.Create(); + + // Assert + Assert.AreEqual(Convert.ToByte(simpleAssessmentResult), entity.SimpleAssessmentResult); + Assert.AreEqual(Convert.ToByte(tailorMadeAssessmentResult), entity.TailorMadeAssessmentResult); + Assert.AreEqual(Convert.ToByte(useManualAssembly), entity.UseManualAssembly); + Assert.AreEqual(Convert.ToByte(manualAssemblyCategoryGroup), entity.ManualAssemblyCategoryGroup); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/WaterPressureAsphaltCover/WaterPressureAsphaltCoverFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/WaterPressureAsphaltCover/WaterPressureAsphaltCoverFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/WaterPressureAsphaltCover/WaterPressureAsphaltCoverFailureMechanismCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,154 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Integration.Data.StandAlone; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.WaterPressureAsphaltCover; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.WaterPressureAsphaltCover +{ + [TestFixture] + public class WaterPressureAsphaltCoverFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new WaterPressureAsphaltCoverFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet(bool isRelevant) + { + // Setup + var failureMechanism = new WaterPressureAsphaltCoverFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.WaterOverpressureAsphaltRevetment, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + var failureMechanism = new WaterPressureAsphaltCoverFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + TestHelper.AssertAreEqualButNotSame(failureMechanism.InputComments.Body, entity.InputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.OutputComments.Body, entity.OutputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new WaterPressureAsphaltCoverFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + Assert.IsNull(entity.FailureMechanismSectionCollectionSourcePath); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + const string filePath = "failureMechanismSections/File/Path"; + var failureMechanism = new WaterPressureAsphaltCoverFailureMechanism(); + failureMechanism.SetSections(new[] + { + FailureMechanismSectionTestFactory.CreateFailureMechanismSection() + }, filePath); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.WaterPressureAsphaltCoverSectionResultEntities).Count()); + TestHelper.AssertAreEqualButNotSame(filePath, entity.FailureMechanismSectionCollectionSourcePath); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/WaterPressureAsphaltCover/WaterPressureAsphaltCoverFailureMechanismSectionResultCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/WaterPressureAsphaltCover/WaterPressureAsphaltCoverFailureMechanismSectionResultCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/WaterPressureAsphaltCover/WaterPressureAsphaltCoverFailureMechanismSectionResultCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,75 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.Integration.Data.StandAlone.SectionResults; +using Riskeer.Storage.Core.Create.WaterPressureAsphaltCover; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.WaterPressureAsphaltCover +{ + [TestFixture] + public class WaterPressureAsphaltCoverFailureMechanismSectionResultCreateExtensionsTest + { + [Test] + public void Create_SectionResultNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((WaterPressureAsphaltCoverFailureMechanismSectionResult) null).Create(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("result", exception.ParamName); + } + + [Test] + public void Create_WithDifferentResults_ReturnsEntityWithExpectedResults() + { + // Setup + var random = new Random(39); + var simpleAssessmentResult = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + bool useManualAssembly = random.NextBoolean(); + var manualAssemblyCategoryGroup = random.NextEnumValue(); + + var sectionResult = new WaterPressureAsphaltCoverFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + SimpleAssessmentResult = simpleAssessmentResult, + TailorMadeAssessmentResult = tailorMadeAssessmentResult, + UseManualAssembly = useManualAssembly, + ManualAssemblyCategoryGroup = manualAssemblyCategoryGroup + }; + + // Call + WaterPressureAsphaltCoverSectionResultEntity entity = sectionResult.Create(); + + // Assert + Assert.AreEqual(Convert.ToByte(simpleAssessmentResult), entity.SimpleAssessmentResult); + Assert.AreEqual(Convert.ToByte(tailorMadeAssessmentResult), entity.TailorMadeAssessmentResult); + Assert.AreEqual(Convert.ToByte(useManualAssembly), entity.UseManualAssembly); + Assert.AreEqual(Convert.ToByte(manualAssemblyCategoryGroup), entity.ManualAssemblyCategoryGroup); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/WaveImpactAsphaltCover/WaveImpactAsphaltCoverFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/WaveImpactAsphaltCover/WaveImpactAsphaltCoverFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/WaveImpactAsphaltCover/WaveImpactAsphaltCoverFailureMechanismCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,237 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.WaveImpactAsphaltCover.Data; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.WaveImpactAsphaltCover; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.WaveImpactAsphaltCover +{ + [TestFixture] + public class WaveImpactAsphaltCoverFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet(bool isRelevant) + { + // Setup + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + }, + GeneralWaveImpactAsphaltCoverInput = + { + DeltaL = new Random(39).NextRoundedDouble(0.1, 2000.0) + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.WaveImpactOnAsphaltRevetment, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + Assert.AreEqual(failureMechanism.GeneralWaveImpactAsphaltCoverInput.DeltaL, + entity.WaveImpactAsphaltCoverFailureMechanismMetaEntities.Single().DeltaL); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + TestHelper.AssertAreEqualButNotSame(failureMechanism.InputComments.Body, entity.InputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.OutputComments.Body, entity.OutputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + Assert.IsNull(entity.FailureMechanismSectionCollectionSourcePath); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + const string filePath = "failureMechanismSections/File/Path"; + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + failureMechanism.SetSections(new[] + { + FailureMechanismSectionTestFactory.CreateFailureMechanismSection() + }, filePath); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.WaveImpactAsphaltCoverSectionResultEntities).Count()); + TestHelper.AssertAreEqualButNotSame(filePath, entity.FailureMechanismSectionCollectionSourcePath); + } + + [Test] + public void Create_WithoutForeshoreProfiles_EmptyForeshoreProfilesEntities() + { + // Setup + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.ForeshoreProfileEntities); + + WaveImpactAsphaltCoverFailureMechanismMetaEntity metaEntity = + entity.WaveImpactAsphaltCoverFailureMechanismMetaEntities.Single(); + Assert.IsNull(metaEntity.ForeshoreProfileCollectionSourcePath); + } + + [Test] + public void Create_WithForeshoreProfiles_ForeshoreProfilesEntitiesCreated() + { + // Setup + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + const string filePath = "some/path/to/foreshoreProfiles"; + failureMechanism.ForeshoreProfiles.AddRange(new[] + { + new TestForeshoreProfile() + }, filePath); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.ForeshoreProfileEntities.Count); + + WaveImpactAsphaltCoverFailureMechanismMetaEntity metaEntity = + entity.WaveImpactAsphaltCoverFailureMechanismMetaEntities.Single(); + string metaEntityForeshoreProfileCollectionSourcePath = metaEntity.ForeshoreProfileCollectionSourcePath; + TestHelper.AssertAreEqualButNotSame(filePath, metaEntityForeshoreProfileCollectionSourcePath); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCalculationGroup_ReturnFailureMechanismEntityWithCalculationGroupEntities(bool isRelevant) + { + // Setup + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + failureMechanism.WaveConditionsCalculationGroup.Children.Add(new CalculationGroup + { + Name = "A" + }); + failureMechanism.WaveConditionsCalculationGroup.Children.Add(new CalculationGroup + { + Name = "B" + }); + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(failureMechanism.WaveConditionsCalculationGroup.Name, entity.CalculationGroupEntity.Name); + Assert.AreEqual(0, entity.CalculationGroupEntity.Order); + + CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity.CalculationGroupEntity1 + .OrderBy(cge => cge.Order) + .ToArray(); + Assert.AreEqual(2, childGroupEntities.Length); + Assert.AreEqual("A", childGroupEntities[0].Name); + Assert.AreEqual(0, childGroupEntities[0].Order); + Assert.AreEqual("B", childGroupEntities[1].Name); + Assert.AreEqual(1, childGroupEntities[1].Order); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/WaveImpactAsphaltCover/WaveImpactAsphaltCoverFailureMechanismSectionResultCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/WaveImpactAsphaltCover/WaveImpactAsphaltCoverFailureMechanismSectionResultCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/WaveImpactAsphaltCover/WaveImpactAsphaltCoverFailureMechanismSectionResultCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,91 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.AssemblyTool.Data; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.WaveImpactAsphaltCover.Data; +using Riskeer.Storage.Core.Create.WaveImpactAsphaltCover; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.WaveImpactAsphaltCover +{ + [TestFixture] + public class WaveImpactAsphaltCoverFailureMechanismSectionResultCreateExtensionsTest + { + [Test] + public void Create_SectionResultNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((WaveImpactAsphaltCoverFailureMechanismSectionResult) null).Create(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("result", exception.ParamName); + } + + [Test] + public void Create_WithDifferentResults_ReturnsEntityWithExpectedResults() + { + // Setup + var random = new Random(); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResultForFactorizedSignalingNorm = random.NextEnumValue(); + var detailedAssessmentResultForSignalingNorm = random.NextEnumValue(); + var detailedAssessmentResultForMechanismSpecificLowerLimitNorm = random.NextEnumValue(); + var detailedAssessmentResultForLowerLimitNorm = random.NextEnumValue(); + var detailedAssessmentResultForFactorizedLowerLimitNorm = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + bool useManualAssembly = random.NextBoolean(); + var manualAssemblyCategoryGroup = random.NextEnumValue(); + + var sectionResult = new WaveImpactAsphaltCoverFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + SimpleAssessmentResult = simpleAssessmentResult, + DetailedAssessmentResultForFactorizedSignalingNorm = detailedAssessmentResultForFactorizedSignalingNorm, + DetailedAssessmentResultForSignalingNorm = detailedAssessmentResultForSignalingNorm, + DetailedAssessmentResultForMechanismSpecificLowerLimitNorm = detailedAssessmentResultForMechanismSpecificLowerLimitNorm, + DetailedAssessmentResultForLowerLimitNorm = detailedAssessmentResultForLowerLimitNorm, + DetailedAssessmentResultForFactorizedLowerLimitNorm = detailedAssessmentResultForFactorizedLowerLimitNorm, + TailorMadeAssessmentResult = tailorMadeAssessmentResult, + UseManualAssembly = useManualAssembly, + ManualAssemblyCategoryGroup = manualAssemblyCategoryGroup + }; + + // Call + WaveImpactAsphaltCoverSectionResultEntity entity = sectionResult.Create(); + + // Assert + Assert.AreEqual(Convert.ToByte(simpleAssessmentResult), entity.SimpleAssessmentResult); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResultForFactorizedSignalingNorm), entity.DetailedAssessmentResultForFactorizedSignalingNorm); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResultForSignalingNorm), entity.DetailedAssessmentResultForSignalingNorm); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResultForMechanismSpecificLowerLimitNorm), entity.DetailedAssessmentResultForMechanismSpecificLowerLimitNorm); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResultForLowerLimitNorm), entity.DetailedAssessmentResultForLowerLimitNorm); + Assert.AreEqual(Convert.ToByte(detailedAssessmentResultForFactorizedLowerLimitNorm), entity.DetailedAssessmentResultForFactorizedLowerLimitNorm); + Assert.AreEqual(Convert.ToByte(tailorMadeAssessmentResult), entity.TailorMadeAssessmentResult); + Assert.AreEqual(Convert.ToByte(useManualAssembly), entity.UseManualAssembly); + Assert.AreEqual(Convert.ToByte(manualAssemblyCategoryGroup), entity.ManualAssemblyCategoryGroup); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/WaveImpactAsphaltCover/WaveImpactAsphaltCoverWaveConditionsCalculationCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/WaveImpactAsphaltCover/WaveImpactAsphaltCoverWaveConditionsCalculationCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/WaveImpactAsphaltCover/WaveImpactAsphaltCoverWaveConditionsCalculationCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,243 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Data; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Revetment.Data; +using Ringtoets.Revetment.Data.TestUtil; +using Ringtoets.WaveImpactAsphaltCover.Data; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.Create.WaveImpactAsphaltCover; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.WaveImpactAsphaltCover +{ + [TestFixture] + public class WaveImpactAsphaltCoverWaveConditionsCalculationCreateExtensionsTest + { + [Test] + public void Create_CalculationNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((WaveImpactAsphaltCoverWaveConditionsCalculation) null).Create(new PersistenceRegistry(), 0); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("calculation", exception.ParamName); + } + + [Test] + public void Create_PersistenceRegistryNull_ThrowArgumentNullException() + { + // Setup + var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation(); + + // Call + TestDelegate call = () => calculation.Create(null, 0); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual(paramName, "registry"); + } + + [Test] + public void Create_CalculationWithPropertiesSet_ReturnCalculationEntity() + { + // Setup + var random = new Random(21); + int order = random.Next(); + + var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation + { + InputParameters = + { + Orientation = random.NextRoundedDouble(0, 360), + UseBreakWater = random.NextBoolean(), + UseForeshore = random.NextBoolean(), + UpperBoundaryRevetment = (RoundedDouble) 6.10, + LowerBoundaryRevetment = (RoundedDouble) 3.58, + UpperBoundaryWaterLevels = (RoundedDouble) 5.88, + LowerBoundaryWaterLevels = (RoundedDouble) 3.40, + StepSize = random.NextEnumValue(), + CategoryType = random.NextEnumValue() + } + }; + + var registry = new PersistenceRegistry(); + + // Call + WaveImpactAsphaltCoverWaveConditionsCalculationEntity entity = calculation.Create(registry, order); + + // Assert + AssessmentSectionCategoryWaveConditionsInput input = calculation.InputParameters; + Assert.AreEqual(input.Orientation, entity.Orientation, input.Orientation.GetAccuracy()); + Assert.AreEqual(Convert.ToByte(input.UseBreakWater), entity.UseBreakWater); + Assert.AreEqual(Convert.ToByte(input.UseForeshore), entity.UseForeshore); + Assert.AreEqual(input.UpperBoundaryRevetment, entity.UpperBoundaryRevetment, input.UpperBoundaryRevetment.GetAccuracy()); + Assert.AreEqual(input.LowerBoundaryRevetment, entity.LowerBoundaryRevetment, input.LowerBoundaryRevetment.GetAccuracy()); + Assert.AreEqual(input.UpperBoundaryWaterLevels, entity.UpperBoundaryWaterLevels, input.UpperBoundaryWaterLevels.GetAccuracy()); + Assert.AreEqual(input.LowerBoundaryWaterLevels, entity.LowerBoundaryWaterLevels, input.LowerBoundaryWaterLevels.GetAccuracy()); + Assert.AreEqual(Convert.ToByte(input.StepSize), entity.StepSize); + Assert.AreEqual(Convert.ToByte(input.CategoryType), entity.CategoryType); + + Assert.AreEqual(order, entity.Order); + Assert.IsNull(entity.CalculationGroupEntity); + CollectionAssert.IsEmpty(entity.WaveImpactAsphaltCoverWaveConditionsOutputEntities); + Assert.IsNull(entity.ForeshoreProfileEntity); + Assert.IsNull(entity.HydraulicLocationEntity); + } + + [Test] + public void Create_CalculationWithNaNProperties_ReturnCalculationEntity() + { + // Setup + var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation + { + InputParameters = + { + Orientation = RoundedDouble.NaN, + UpperBoundaryRevetment = RoundedDouble.NaN, + LowerBoundaryRevetment = RoundedDouble.NaN, + UpperBoundaryWaterLevels = RoundedDouble.NaN, + LowerBoundaryWaterLevels = RoundedDouble.NaN, + BreakWater = + { + Height = RoundedDouble.NaN + } + } + }; + + var registry = new PersistenceRegistry(); + + // Call + WaveImpactAsphaltCoverWaveConditionsCalculationEntity entity = calculation.Create(registry, 1234); + + // Assert + Assert.IsNull(entity.Orientation); + Assert.IsNull(entity.UpperBoundaryRevetment); + Assert.IsNull(entity.LowerBoundaryRevetment); + Assert.IsNull(entity.UpperBoundaryWaterLevels); + Assert.IsNull(entity.LowerBoundaryWaterLevels); + Assert.IsNull(entity.BreakWaterHeight); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string name = "A"; + const string comments = "B"; + var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation + { + Name = name, + Comments = + { + Body = comments + } + }; + + var registry = new PersistenceRegistry(); + + // Call + WaveImpactAsphaltCoverWaveConditionsCalculationEntity entity = calculation.Create(registry, 0); + + // Assert + TestHelper.AssertAreEqualButNotSame(calculation.Name, entity.Name); + TestHelper.AssertAreEqualButNotSame(calculation.Comments.Body, entity.Comments); + } + + [Test] + public void Create_WaveImpactAsphaltCoverHydraulicLocationEntity_EntityHasWaveImpactAsphaltCoverHydraulicLocationEntity() + { + // Setup + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "A", 2.3, 4.5); + + var registry = new PersistenceRegistry(); + HydraulicLocationEntity hydraulicLocationEntity = hydraulicBoundaryLocation.Create(registry, 0); + + var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation + } + }; + + // Call + WaveImpactAsphaltCoverWaveConditionsCalculationEntity entity = calculation.Create(registry, 0); + + // Assert + Assert.AreSame(hydraulicLocationEntity, entity.HydraulicLocationEntity); + } + + [Test] + public void Create_HasForeshoreProfile_EntityHasForeshoreProfileEntity() + { + // Setup + var registry = new PersistenceRegistry(); + var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation + { + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile() + } + }; + + // Call + WaveImpactAsphaltCoverWaveConditionsCalculationEntity entity = calculation.Create(registry, 0); + + // Assert + Assert.IsNotNull(entity.ForeshoreProfileEntity); + } + + [Test] + public void Create_HasCalculationOutputs_EntityHasOrderedCalculationOutputEntity() + { + // Setup + var registry = new PersistenceRegistry(); + var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation + { + Output = new WaveImpactAsphaltCoverWaveConditionsOutput(new[] + { + new TestWaveConditionsOutput(), + new TestWaveConditionsOutput() + }) + }; + + // Call + WaveImpactAsphaltCoverWaveConditionsCalculationEntity entity = calculation.Create(registry, 0); + + // Assert + Assert.AreEqual(2, entity.WaveImpactAsphaltCoverWaveConditionsOutputEntities.Count); + Assert.AreEqual(new[] + { + 0, + 1 + }, entity.WaveImpactAsphaltCoverWaveConditionsOutputEntities.Select(oe => oe.Order)); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/WaveImpactAsphaltCover/WaveImpactAsphaltCoverWaveConditionsOutputCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/WaveImpactAsphaltCover/WaveImpactAsphaltCoverWaveConditionsOutputCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Create/WaveImpactAsphaltCover/WaveImpactAsphaltCoverWaveConditionsOutputCreateExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,85 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Revetment.Data; +using Ringtoets.Revetment.Data.TestUtil; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create.WaveImpactAsphaltCover +{ + [TestFixture] + public class WaveImpactAsphaltCoverWaveConditionsOutputCreateExtensionsTest + { + [Test] + public void Create_AllOutputValuesSet_ReturnEntity() + { + // Setup + var output = new TestWaveConditionsOutput(); + const int order = 22; + + // Call + WaveImpactAsphaltCoverWaveConditionsOutputEntity entity = output.CreateWaveImpactAsphaltCoverWaveConditionsOutputEntity(order); + + // Assert + Assert.AreEqual(order, entity.Order); + Assert.AreEqual(output.WaterLevel, entity.WaterLevel, output.WaterLevel.GetAccuracy()); + Assert.AreEqual(output.WaveHeight, entity.WaveHeight, output.WaveHeight.GetAccuracy()); + Assert.AreEqual(output.WavePeakPeriod, entity.WavePeakPeriod, output.WavePeakPeriod.GetAccuracy()); + Assert.AreEqual(output.WaveAngle, entity.WaveAngle, output.WaveAngle.GetAccuracy()); + Assert.AreEqual(output.WaveDirection, entity.WaveDirection, output.WaveDirection.GetAccuracy()); + Assert.AreEqual(output.TargetProbability, entity.TargetProbability); + Assert.AreEqual(output.TargetReliability, entity.TargetReliability, output.TargetReliability.GetAccuracy()); + Assert.AreEqual(output.CalculatedProbability, entity.CalculatedProbability); + Assert.AreEqual(output.CalculatedReliability, entity.CalculatedReliability, output.CalculatedReliability.GetAccuracy()); + Assert.AreEqual(output.CalculationConvergence, (CalculationConvergence) entity.CalculationConvergence); + + Assert.IsNull(entity.WaveImpactAsphaltCoverWaveConditionsCalculationEntity); + } + + [Test] + public void Create_AllOutputValuesNaN_ReturnEntityWithNullValues() + { + // Setup + var output = new WaveConditionsOutput(double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, + double.NaN, double.NaN, double.NaN, CalculationConvergence.NotCalculated); + + // Call + WaveImpactAsphaltCoverWaveConditionsOutputEntity entity = output.CreateWaveImpactAsphaltCoverWaveConditionsOutputEntity(22); + + // Assert + Assert.IsNull(entity.WaterLevel); + Assert.IsNull(entity.WaveHeight); + Assert.IsNull(entity.WavePeakPeriod); + Assert.IsNull(entity.WaveAngle); + Assert.IsNull(entity.WaveDirection); + Assert.IsNull(entity.TargetProbability); + Assert.IsNull(entity.TargetReliability); + Assert.IsNull(entity.CalculatedProbability); + Assert.IsNull(entity.CalculatedReliability); + + Assert.IsNull(entity.WaveImpactAsphaltCoverWaveConditionsCalculationEntity); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/DbContext/RiskeerEntitiesTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/DbContext/RiskeerEntitiesTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/DbContext/RiskeerEntitiesTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,88 @@ +// Copyright (C) Stichting Deltares 2018. 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.Data.Entity.Infrastructure; +using System.Globalization; +using NUnit.Framework; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.DbContext +{ + [TestFixture] + public class RiskeerEntitiesTest + { + private const string entityConnectionString = "metadata=res://*/DbContext.RingtoetsEntities.csdl|" + + "res://*/DbContext.RiskeerEntities.ssdl|" + + "res://*/DbContext.RiskeerEntities.msl;" + + "provider=System.Data.SQLite.EF6;" + + "provider connection string=\"{0}\""; + + private const string connectionString = "failifmissing=True;data source=C:\\file.sqlite;" + + "read only=False;" + + "foreign keys=True;" + + "version=3;" + + "pooling=False"; + + [Test] + public void Constructor_WithConnectionString_ExpectedValues() + { + // Setup + string fullConnectionString = string.Format(CultureInfo.CurrentCulture, entityConnectionString, + connectionString); + + // Call + using (var ringtoetsEntities = new RiskeerEntities(fullConnectionString)) + { + // Assert + Assert.IsInstanceOf(ringtoetsEntities); + Assert.AreEqual(connectionString, ringtoetsEntities.Database.Connection.ConnectionString); + Assert.IsFalse(ringtoetsEntities.Configuration.LazyLoadingEnabled); + } + } + + [Test] + public void OnModelCreating_Always_ThrowsUnintentionalCodeFirstException() + { + // Setup + string fullConnectionString = string.Format(CultureInfo.CurrentCulture, entityConnectionString, + connectionString); + + // Call + using (var ringtoetsEntities = new TestRiskeerEntities(fullConnectionString)) + { + TestDelegate test = () => ringtoetsEntities.CallOnModelCreating(); + + // Assert + Assert.Throws(test); + } + } + + private class TestRiskeerEntities : RiskeerEntities + { + public TestRiskeerEntities(string connString) : base(connString) {} + + public void CallOnModelCreating() + { + OnModelCreating(null); + } + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/DoubleConversionExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/DoubleConversionExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/DoubleConversionExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,86 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; + +namespace Riskeer.Storage.Core.Test +{ + [TestFixture] + public class DoubleConversionExtensionsTest + { + [Test] + public void ToNaNAsNull_ValueIsNaN_ReturnNull() + { + // Call + double? value = double.NaN.ToNaNAsNull(); + + // Assert + Assert.IsNull(value); + } + + [Test] + [TestCase(1.1)] + [TestCase(-2.2)] + [TestCase(double.MinValue)] + [TestCase(double.MaxValue)] + [TestCase(double.PositiveInfinity)] + [TestCase(double.NegativeInfinity)] + public void ToNaNAsNull_NotNaNValue_ReturnThatValue(double original) + { + // Call + double? value = original.ToNaNAsNull(); + + // Assert + Assert.IsTrue(value.HasValue); + Assert.AreEqual(original, value.Value); + } + + [Test] + public void ToNullAsNaN_NullValue_ReturnNaN() + { + // Call + double value = ((double?) null).ToNullAsNaN(); + + // Assert + Assert.IsNaN(value); + } + + [Test] + [TestCase(956.654)] + [TestCase(-456.789)] + [TestCase(double.MinValue)] + [TestCase(double.MaxValue)] + [TestCase(double.PositiveInfinity)] + [TestCase(double.NegativeInfinity)] + [TestCase(double.NaN)] + public void ToNullAsNaN_NotNullValue_ReturnThatValue(double value) + { + // Setup + double? original = value; + + // Call + double convertedValue = original.ToNullAsNaN(); + + // Assert + Assert.AreEqual(value, convertedValue); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Exceptions/CannotDeleteBackupFileExceptionTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Exceptions/CannotDeleteBackupFileExceptionTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Exceptions/CannotDeleteBackupFileExceptionTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,32 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Riskeer.Storage.Core.Exceptions; + +namespace Riskeer.Storage.Core.Test.Exceptions +{ + [TestFixture] + public class CannotDeleteBackupFileExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Exceptions/CannotDetermineFingerprintExceptionTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Exceptions/CannotDetermineFingerprintExceptionTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Exceptions/CannotDetermineFingerprintExceptionTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,32 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Riskeer.Storage.Core.Exceptions; + +namespace Riskeer.Storage.Core.Test.Exceptions +{ + [TestFixture] + public class CannotDetermineFingerprintExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Exceptions/EntityNotFoundExceptionTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Exceptions/EntityNotFoundExceptionTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Exceptions/EntityNotFoundExceptionTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,32 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Riskeer.Storage.Core.Exceptions; + +namespace Riskeer.Storage.Core.Test.Exceptions +{ + [TestFixture] + public class EntityNotFoundExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/FingerprintHelperTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/FingerprintHelperTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/FingerprintHelperTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,181 @@ +// Copyright (C) Stichting Deltares 2018. 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.Diagnostics; +using System.Linq; +using NUnit.Framework; +using Ringtoets.Integration.Data; +using Ringtoets.Storage.Core.TestUtil; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test +{ + [TestFixture] + public class FingerprintHelperTest + { + [Test] + public void Get_EntityIsNull_ThrowArgumentNullException() + { + // Call + TestDelegate call = () => FingerprintHelper.Get(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void GivenProjectEntity_WhenGeneratingFingerprintMultipleTime_ThenHashRemainsEqual() + { + // Given + RingtoetsProject project = RiskeerProjectTestHelper.GetFullTestProject(); + ProjectEntity entity = project.Create(new PersistenceRegistry()); + + // When + byte[] hash1 = FingerprintHelper.Get(entity); + byte[] hash2 = FingerprintHelper.Get(entity); + + // Then + Assert.IsNotNull(hash1); + CollectionAssert.IsNotEmpty(hash1); + CollectionAssert.AreEqual(hash1, hash2); + } + + [Test] + public void GivenProjectEntity_WhenComparingFingerprintsBeforeAndAfterChange_ThenHashDifferent() + { + // Given + RingtoetsProject project = RiskeerProjectTestHelper.GetFullTestProject(); + ProjectEntity entity = project.Create(new PersistenceRegistry()); + + // When + byte[] hash1 = FingerprintHelper.Get(entity); + entity.AssessmentSectionEntities.First().Name = "Something completely different"; + byte[] hash2 = FingerprintHelper.Get(entity); + + // Then + Assert.IsNotNull(hash1); + CollectionAssert.IsNotEmpty(hash1); + CollectionAssert.AreNotEqual(hash1, hash2); + } + + [Test] + public void GivenProjectEntity_WhenGeneratingFingerprintEqualData_ThenHashRemainsEqual() + { + // Setup + RingtoetsProject project1 = RiskeerProjectTestHelper.GetFullTestProject(); + RingtoetsProject project2 = RiskeerProjectTestHelper.GetFullTestProject(); + ProjectEntity entity1 = project1.Create(new PersistenceRegistry()); + ProjectEntity entity2 = project2.Create(new PersistenceRegistry()); + + // Call + byte[] hash1 = FingerprintHelper.Get(entity1); + byte[] hash2 = FingerprintHelper.Get(entity2); + + // Assert + Assert.IsNotNull(hash1); + CollectionAssert.IsNotEmpty(hash1); + CollectionAssert.AreEqual(hash1, hash2); + } + + [Test] + public void AreEqual_ArraysAreNotEqual_ReturnFalse() + { + // Setup + var random = new Random(42); + const int arraySize = 10; + var array1 = new byte[arraySize]; + var array2 = new byte[arraySize]; + random.NextBytes(array1); + random.NextBytes(array2); + + // Precondition + CollectionAssert.AreNotEqual(array1, array2); + + // Call + bool areCollectionEqual = FingerprintHelper.AreEqual(array1, array2); + + // Assert + Assert.IsFalse(areCollectionEqual); + } + + [Test] + public void AreEqual_ArraysAreEqual_ReturnTrue() + { + // Setup + var random = new Random(42); + const int arraySize = 10; + var array1 = new byte[arraySize]; + random.NextBytes(array1); + + // Precondition + CollectionAssert.AreEqual(array1, array1); + + // Call + bool areCollectionEqual = FingerprintHelper.AreEqual(array1, array1); + + // Assert + Assert.IsTrue(areCollectionEqual); + } + + [Test] + public void GivenNotEqualData_WhenComparingPerformance_ThenPerformanceShouldBeBetterThanLinq() + { + // Given + var random = new Random(42); + const int arraySize = 100000000; + var array1 = new byte[arraySize]; + var array2 = new byte[arraySize]; + random.NextBytes(array1); + random.NextBytes(array2); + + // Precondition + CollectionAssert.AreNotEqual(array1, array2); + + // When + var stopwatch = new Stopwatch(); + long timeToBeat = 0, actualTime = 0; + for (var i = 0; i < 100000; i++) + { + stopwatch.Start(); + Assert.IsFalse(SlowBaselineLinqEquality(array1, array2)); + stopwatch.Stop(); + timeToBeat += stopwatch.ElapsedTicks; + + stopwatch.Reset(); + stopwatch.Start(); + Assert.IsFalse(FingerprintHelper.AreEqual(array1, array2)); + stopwatch.Stop(); + actualTime += stopwatch.ElapsedTicks; + } + + // Then + Assert.Less(actualTime, timeToBeat, $"actualTime '{actualTime}' is not less than timeToBeat '{timeToBeat}'"); + } + + private static bool SlowBaselineLinqEquality(byte[] array1, byte[] array2) + { + return array1.SequenceEqual(array2); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/IntegrationTests/StorageSqLiteIntegrationTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/IntegrationTests/StorageSqLiteIntegrationTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/IntegrationTests/StorageSqLiteIntegrationTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,2353 @@ +// Copyright (C) Stichting Deltares 2018. 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.IO; +using System.Linq; +using System.Threading; +using Core.Common.Base.Geometry; +using Core.Common.Base.Storage; +using Core.Common.Gui; +using Core.Common.Gui.Forms.MainWindow; +using Core.Common.Gui.Settings; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.ClosingStructures.Data; +using Ringtoets.Common.Data; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Contribution; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.DuneErosion.Data; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.GrassCoverErosionOutwards.Data; +using Ringtoets.HeightStructures.Data; +using Ringtoets.Integration.Data; +using Ringtoets.Integration.Data.StandAlone; +using Ringtoets.Integration.Data.StandAlone.SectionResults; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.MacroStabilityInwards.Data.SoilProfile; +using Ringtoets.MacroStabilityInwards.Primitives; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Data.SoilProfile; +using Ringtoets.Piping.Primitives; +using Ringtoets.Revetment.Data; +using Ringtoets.StabilityPointStructures.Data; +using Ringtoets.StabilityStoneCover.Data; +using Ringtoets.Storage.Core.TestUtil; +using Ringtoets.WaveImpactAsphaltCover.Data; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.IntegrationTests +{ + [TestFixture] + public class StorageSqLiteIntegrationTest + { + private const string tempExtension = ".temp"; + private DirectoryDisposeHelper directoryDisposeHelper; + + [Test] + public void SaveProjectAs_DuplicateItemsInProjectSaveAsNewFile_ProjectAsEntitiesInFile() + { + // Setup + RingtoetsProject fullProject = RiskeerProjectTestHelper.GetFullTestProject(); + RingtoetsProject duplicateProject = RiskeerProjectTestHelper.GetFullTestProject(); + + AssessmentSection duplicateAssessmentSection = duplicateProject.AssessmentSections.First(); + fullProject.AssessmentSections.Add(duplicateAssessmentSection); + + string ringtoetsFile = GetRandomRingtoetsFile(); + + var storage = new StorageSqLite(); + storage.StageProject(fullProject); + + // Call + storage.SaveProjectAs(ringtoetsFile); + var firstProject = (RingtoetsProject) storage.LoadProject(ringtoetsFile); + + // Assert + AssertProjectsAreEqual(fullProject, firstProject); + } + + [Test] + public void SaveProjectAs_SaveAsNewFile_ProjectAsEntitiesInBothFiles() + { + // Setup + RingtoetsProject fullProject = RiskeerProjectTestHelper.GetFullTestProject(); + string firstRingtoetsFile = GetRandomRingtoetsFile(); + string secondRingtoetsFile = GetRandomRingtoetsFile(); + + var storage = new StorageSqLite(); + storage.StageProject(fullProject); + storage.SaveProjectAs(firstRingtoetsFile); + + // Call + storage.StageProject(fullProject); + storage.SaveProjectAs(secondRingtoetsFile); + var firstProject = (RingtoetsProject) storage.LoadProject(firstRingtoetsFile); + var secondProject = (RingtoetsProject) storage.LoadProject(secondRingtoetsFile); + + // Assert + AssertProjectsAreEqual(firstProject, secondProject); + } + + [Test] + public void GivenRingtoetsProject_WhenComparingFingerPrintsVariousScenariosUnchangedData_ThenFingerprintUnchanged() + { + // Given + RingtoetsProject fullProject = RiskeerProjectTestHelper.GetFullTestProject(); + string tempRingtoetsFile = GetRandomRingtoetsFile(); + + // When + ProjectEntity entityBeforeSave = fullProject.Create(new PersistenceRegistry()); + + byte[] hash1 = FingerprintHelper.Get(entityBeforeSave); + + var storage = new StorageSqLite(); + storage.StageProject(fullProject); + storage.SaveProjectAs(tempRingtoetsFile); + + ProjectEntity entityAfterSave = fullProject.Create(new PersistenceRegistry()); + byte[] hash2 = FingerprintHelper.Get(entityAfterSave); + + var openedProject = (RingtoetsProject) storage.LoadProject(tempRingtoetsFile); + ProjectEntity entityAfterOpening = openedProject.Create(new PersistenceRegistry()); + + byte[] hash3 = FingerprintHelper.Get(entityAfterOpening); + + // Then + CollectionAssert.AreEqual(hash1, hash2); + CollectionAssert.AreEqual(hash1, hash3); + } + + [Test] + public void LoadProject_FullTestProjectSaved_ProjectAsEntitiesInNewStorage() + { + // Setup + var storage = new StorageSqLite(); + RingtoetsProject fullProject = RiskeerProjectTestHelper.GetFullTestProject(); + storage.StageProject(fullProject); + string tempRingtoetsFile = GetRandomRingtoetsFile(); + storage.SaveProjectAs(tempRingtoetsFile); + + // Call + var loadedProject = (RingtoetsProject) storage.LoadProject(tempRingtoetsFile); + + // Assert + AssertProjectsAreEqual(fullProject, loadedProject); + } + + [Test] + [Apartment(ApartmentState.STA)] + [TestCase(null)] + [TestCase("")] + [TestCase(" ")] + public void GivenRingtoetsGuiWithStorageSqlAndMigrator_WhenRunWithEmptyFile_DefaultProjectStillSet(string testFile) + { + // Given + var mocks = new MockRepository(); + var projectMigrator = mocks.Stub(); + mocks.ReplayAll(); + + var projectStore = new StorageSqLite(); + + using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, new RingtoetsProjectFactory(), new GuiCoreSettings())) + { + // When + gui.Run(testFile); + + // Then + Assert.AreEqual(null, gui.ProjectFilePath); + Assert.NotNull(gui.Project); + Assert.AreEqual("Project", gui.Project.Name); + Assert.IsEmpty(gui.Project.Description); + Assert.IsInstanceOf(gui.Project); + CollectionAssert.IsEmpty(((RingtoetsProject) gui.Project).AssessmentSections); + } + + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void GivenRingtoetsGuiWithStorageSqlAndMigrator_WhenRunWithValidFile_ProjectSet() + { + // Given + string tempRingtoetsFile = GetRandomRingtoetsFile(); + string expectedProjectName = Path.GetFileNameWithoutExtension(tempRingtoetsFile); + + var mocks = new MockRepository(); + var projectMigrator = mocks.Stub(); + projectMigrator.Stub(pm => pm.ShouldMigrate(tempRingtoetsFile)).Return(MigrationRequired.No); + mocks.ReplayAll(); + + var projectStore = new StorageSqLite(); + + RingtoetsProject fullProject = RiskeerProjectTestHelper.GetFullTestProject(); + string expectedProjectDescription = fullProject.Description; + + SqLiteDatabaseHelper.CreateValidRingtoetsDatabase(tempRingtoetsFile, fullProject); + + using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, new RingtoetsProjectFactory(), new GuiCoreSettings())) + { + // When + Action action = () => gui.Run(tempRingtoetsFile); + + // Then + Tuple[] expectedMessages = + { + Tuple.Create("Openen van project is gestart.", LogLevelConstant.Info), + Tuple.Create("Openen van project is gelukt.", LogLevelConstant.Info) + }; + TestHelper.AssertLogMessagesWithLevelAreGenerated(action, expectedMessages, 3); + Assert.AreEqual(tempRingtoetsFile, gui.ProjectFilePath); + Assert.NotNull(gui.Project); + Assert.AreEqual(expectedProjectName, gui.Project.Name); + Assert.AreEqual(expectedProjectDescription, gui.Project.Description); + + Assert.IsInstanceOf(gui.Project); + AssertProjectsAreEqual(fullProject, (RingtoetsProject) gui.Project); + } + + mocks.VerifyAll(); + } + + [OneTimeSetUp] + public void SetUp() + { + directoryDisposeHelper = new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(StorageSqLiteIntegrationTest)); + } + + [OneTimeTearDown] + public void TearDown() + { + GC.Collect(); + GC.WaitForPendingFinalizers(); + directoryDisposeHelper.Dispose(); + } + + private static string GetRandomRingtoetsFile() + { + return Path.Combine(TestHelper.GetScratchPadPath(), nameof(StorageSqLiteIntegrationTest), + string.Concat(Path.GetRandomFileName(), tempExtension)); + } + + private static void AssertProjectsAreEqual(RingtoetsProject expectedProject, RingtoetsProject actualProject) + { + Assert.NotNull(expectedProject); + Assert.NotNull(actualProject); + Assert.AreNotSame(expectedProject, actualProject); + + List expectedProjectAssessmentSections = expectedProject.AssessmentSections; + List actualProjectAssessmentSections = actualProject.AssessmentSections; + Assert.AreEqual(expectedProjectAssessmentSections.Count, actualProjectAssessmentSections.Count); + for (var i = 0; i < expectedProjectAssessmentSections.Count; i++) + { + AssessmentSection expectedAssessmentSection = expectedProjectAssessmentSections[i]; + AssessmentSection actualAssessmentSection = actualProjectAssessmentSections[i]; + + Assert.AreEqual(expectedAssessmentSection.Id, actualAssessmentSection.Id); + Assert.AreEqual(expectedAssessmentSection.Name, actualAssessmentSection.Name); + AssertComments(expectedAssessmentSection.Comments, actualAssessmentSection.Comments); + + FailureMechanismContribution expectedContribution = expectedAssessmentSection.FailureMechanismContribution; + FailureMechanismContribution actualContribution = actualAssessmentSection.FailureMechanismContribution; + Assert.AreEqual(expectedContribution.LowerLimitNorm, actualContribution.LowerLimitNorm); + Assert.AreEqual(expectedContribution.SignalingNorm, actualContribution.SignalingNorm); + Assert.AreEqual(expectedContribution.NormativeNorm, actualContribution.NormativeNorm); + + BackgroundDataTestHelper.AssertBackgroundData(expectedAssessmentSection.BackgroundData, actualAssessmentSection.BackgroundData); + AssertHydraulicBoundaryDatabase(expectedAssessmentSection.HydraulicBoundaryDatabase, actualAssessmentSection.HydraulicBoundaryDatabase); + AssertHydraulicBoundaryLocationCalculations(expectedAssessmentSection, actualAssessmentSection); + AssertReferenceLine(expectedAssessmentSection.ReferenceLine, actualAssessmentSection.ReferenceLine); + + IFailureMechanism[] expectedProjectFailureMechanisms = expectedAssessmentSection.GetFailureMechanisms().ToArray(); + IFailureMechanism[] actualProjectFailureMechanisms = actualAssessmentSection.GetFailureMechanisms().ToArray(); + for (var fmi = 0; fmi < expectedProjectFailureMechanisms.Length; fmi++) + { + AssertFailureMechanism(expectedProjectFailureMechanisms[fmi], actualProjectFailureMechanisms[fmi]); + } + + AssertPipingFailureMechanism(expectedAssessmentSection.Piping, actualAssessmentSection.Piping); + AssertMacroStabilityOutwardsFailureMechanism(expectedAssessmentSection.MacroStabilityOutwards, actualAssessmentSection.MacroStabilityOutwards); + AssertMacroStabilityInwardsFailureMechanism(expectedAssessmentSection.MacroStabilityInwards, actualAssessmentSection.MacroStabilityInwards); + AssertGrassCoverErosionInwardsFailureMechanism(expectedAssessmentSection.GrassCoverErosionInwards, actualAssessmentSection.GrassCoverErosionInwards); + AssertGrassCoverErosionOutwardsFailureMechanism(expectedAssessmentSection.GrassCoverErosionOutwards, actualAssessmentSection.GrassCoverErosionOutwards); + AssertPipingStructureFailureMechanism(expectedAssessmentSection.PipingStructure, actualAssessmentSection.PipingStructure); + AssertStabilityStoneCoverFailureMechanism(expectedAssessmentSection.StabilityStoneCover, actualAssessmentSection.StabilityStoneCover); + AssertWaveImpactAsphaltCoverFailureMechanism(expectedAssessmentSection.WaveImpactAsphaltCover, actualAssessmentSection.WaveImpactAsphaltCover); + AssertHeightStructuresFailureMechanism(expectedAssessmentSection.HeightStructures, actualAssessmentSection.HeightStructures); + AssertClosingStructuresFailureMechanism(expectedAssessmentSection.ClosingStructures, actualAssessmentSection.ClosingStructures); + AssertDuneErosionFailureMechanism(expectedAssessmentSection.DuneErosion, actualAssessmentSection.DuneErosion); + AssertStabilityPointStructuresFailureMechanism(expectedAssessmentSection.StabilityPointStructures, actualAssessmentSection.StabilityPointStructures); + + AssertFailureMechanismSectionResults( + expectedAssessmentSection.Piping.SectionResults, + actualAssessmentSection.Piping.SectionResults); + AssertFailureMechanismSectionResults( + expectedAssessmentSection.GrassCoverErosionInwards.SectionResults, + actualAssessmentSection.GrassCoverErosionInwards.SectionResults); + AssertFailureMechanismSectionResults( + expectedAssessmentSection.HeightStructures.SectionResults, + actualAssessmentSection.HeightStructures.SectionResults); + AssertFailureMechanismSectionResults( + expectedAssessmentSection.StrengthStabilityLengthwiseConstruction.SectionResults, + actualAssessmentSection.StrengthStabilityLengthwiseConstruction.SectionResults); + AssertFailureMechanismSectionResults( + expectedAssessmentSection.TechnicalInnovation.SectionResults, + actualAssessmentSection.TechnicalInnovation.SectionResults); + AssertFailureMechanismSectionResults( + expectedAssessmentSection.WaterPressureAsphaltCover.SectionResults, + actualAssessmentSection.WaterPressureAsphaltCover.SectionResults); + AssertFailureMechanismSectionResults( + expectedAssessmentSection.ClosingStructures.SectionResults, + actualAssessmentSection.ClosingStructures.SectionResults); + AssertFailureMechanismSectionResults( + expectedAssessmentSection.MacroStabilityOutwards.SectionResults, + actualAssessmentSection.MacroStabilityOutwards.SectionResults); + AssertFailureMechanismSectionResults( + expectedAssessmentSection.MacroStabilityInwards.SectionResults, + actualAssessmentSection.MacroStabilityInwards.SectionResults); + AssertFailureMechanismSectionResults( + expectedAssessmentSection.WaveImpactAsphaltCover.SectionResults, + actualAssessmentSection.WaveImpactAsphaltCover.SectionResults); + AssertFailureMechanismSectionResults( + expectedAssessmentSection.GrassCoverErosionOutwards.SectionResults, + actualAssessmentSection.GrassCoverErosionOutwards.SectionResults); + AssertFailureMechanismSectionResults( + expectedAssessmentSection.GrassCoverSlipOffInwards.SectionResults, + actualAssessmentSection.GrassCoverSlipOffInwards.SectionResults); + AssertFailureMechanismSectionResults( + expectedAssessmentSection.GrassCoverSlipOffOutwards.SectionResults, + actualAssessmentSection.GrassCoverSlipOffOutwards.SectionResults); + AssertFailureMechanismSectionResults( + expectedAssessmentSection.Microstability.SectionResults, + actualAssessmentSection.Microstability.SectionResults); + AssertFailureMechanismSectionResults( + expectedAssessmentSection.PipingStructure.SectionResults, + actualAssessmentSection.PipingStructure.SectionResults); + AssertFailureMechanismSectionResults( + expectedAssessmentSection.DuneErosion.SectionResults, + actualAssessmentSection.DuneErosion.SectionResults); + AssertFailureMechanismSectionResults( + expectedAssessmentSection.StabilityStoneCover.SectionResults, + actualAssessmentSection.StabilityStoneCover.SectionResults); + AssertFailureMechanismSectionResults( + expectedAssessmentSection.StabilityPointStructures.SectionResults, + actualAssessmentSection.StabilityPointStructures.SectionResults); + } + } + + private static void AssertFailureMechanismSectionResults( + IEnumerable expectedSectionResults, + IEnumerable actualSectionResults) + { + AssertCollectionAndItems(expectedSectionResults, + actualSectionResults, + (expectedItem, actualItem) => + { + Assert.AreEqual(expectedItem.SimpleAssessmentResult, actualItem.SimpleAssessmentResult); + Assert.AreEqual(expectedItem.TailorMadeAssessmentResult, actualItem.TailorMadeAssessmentResult); + Assert.AreEqual(expectedItem.UseManualAssembly, actualItem.UseManualAssembly); + Assert.AreEqual(expectedItem.ManualAssemblyCategoryGroup, actualItem.ManualAssemblyCategoryGroup); + }); + } + + private static void AssertFailureMechanismSectionResults( + IEnumerable expectedSectionResults, + IEnumerable actualSectionResults) + { + AssertCollectionAndItems(expectedSectionResults, + actualSectionResults, + (expectedItem, actualItem) => + { + Assert.AreEqual(expectedItem.SimpleAssessmentResult, actualItem.SimpleAssessmentResult); + Assert.AreEqual(expectedItem.TailorMadeAssessmentResult, actualItem.TailorMadeAssessmentResult); + Assert.AreEqual(expectedItem.UseManualAssembly, actualItem.UseManualAssembly); + Assert.AreEqual(expectedItem.ManualAssemblyCategoryGroup, actualItem.ManualAssemblyCategoryGroup); + }); + } + + private static void AssertFailureMechanismSectionResults( + IEnumerable expectedSectionResults, + IEnumerable actualSectionResults) + { + AssertCollectionAndItems(expectedSectionResults, + actualSectionResults, + (expectedItem, actualItem) => + { + Assert.AreEqual(expectedItem.SimpleAssessmentResult, actualItem.SimpleAssessmentResult); + Assert.AreEqual(expectedItem.TailorMadeAssessmentResult, actualItem.TailorMadeAssessmentResult); + Assert.AreEqual(expectedItem.UseManualAssembly, actualItem.UseManualAssembly); + Assert.AreEqual(expectedItem.ManualAssemblyCategoryGroup, actualItem.ManualAssemblyCategoryGroup); + }); + } + + private static void AssertFailureMechanismSectionResults( + IEnumerable expectedSectionResults, + IEnumerable actualSectionResults) + { + AssertCollectionAndItems(expectedSectionResults, + actualSectionResults, + (expectedItem, actualItem) => + { + Assert.AreEqual(expectedItem.SimpleAssessmentResult, actualItem.SimpleAssessmentResult); + Assert.AreEqual(expectedItem.DetailedAssessmentResult, actualItem.DetailedAssessmentResult); + Assert.AreEqual(expectedItem.TailorMadeAssessmentResult, actualItem.TailorMadeAssessmentResult); + Assert.AreEqual(expectedItem.UseManualAssembly, actualItem.UseManualAssembly); + Assert.AreEqual(expectedItem.ManualAssemblyCategoryGroup, actualItem.ManualAssemblyCategoryGroup); + }); + } + + private static void AssertFailureMechanismSectionResults( + IEnumerable expectedSectionResults, + IEnumerable actualSectionResults) + { + AssertCollectionAndItems(expectedSectionResults, + actualSectionResults, + (expectedItem, actualItem) => + { + Assert.AreEqual(expectedItem.SimpleAssessmentResult, actualItem.SimpleAssessmentResult); + Assert.AreEqual(expectedItem.DetailedAssessmentResult, actualItem.DetailedAssessmentResult); + Assert.AreEqual(expectedItem.TailorMadeAssessmentResult, actualItem.TailorMadeAssessmentResult); + Assert.AreEqual(expectedItem.UseManualAssembly, actualItem.UseManualAssembly); + Assert.AreEqual(expectedItem.ManualAssemblyCategoryGroup, actualItem.ManualAssemblyCategoryGroup); + }); + } + + private static void AssertFailureMechanismSectionResults( + IEnumerable expectedSectionResults, + IEnumerable actualSectionResults) + { + AssertCollectionAndItems(expectedSectionResults, + actualSectionResults, + (expectedItem, actualItem) => + { + Assert.AreEqual(expectedItem.SimpleAssessmentResult, actualItem.SimpleAssessmentResult); + Assert.AreEqual(expectedItem.DetailedAssessmentResult, actualItem.DetailedAssessmentResult); + Assert.AreEqual(expectedItem.TailorMadeAssessmentResult, actualItem.TailorMadeAssessmentResult); + Assert.AreEqual(expectedItem.UseManualAssembly, actualItem.UseManualAssembly); + Assert.AreEqual(expectedItem.ManualAssemblyCategoryGroup, actualItem.ManualAssemblyCategoryGroup); + }); + } + + private static void AssertFailureMechanism(IFailureMechanism expectedFailureMechanism, + IFailureMechanism actualFailureMechanism) + { + Assert.AreEqual(expectedFailureMechanism.Name, actualFailureMechanism.Name); + Assert.AreEqual(expectedFailureMechanism.Code, actualFailureMechanism.Code); + Assert.AreEqual(expectedFailureMechanism.IsRelevant, actualFailureMechanism.IsRelevant); + AssertComments(expectedFailureMechanism.InputComments, actualFailureMechanism.InputComments); + AssertComments(expectedFailureMechanism.OutputComments, actualFailureMechanism.OutputComments); + AssertComments(expectedFailureMechanism.NotRelevantComments, actualFailureMechanism.NotRelevantComments); + AssertFailureMechanismSections(expectedFailureMechanism.Sections, actualFailureMechanism.Sections); + Assert.AreEqual(expectedFailureMechanism.FailureMechanismSectionSourcePath, actualFailureMechanism.FailureMechanismSectionSourcePath); + } + + private static void AssertFailureMechanismSections(IEnumerable expectedSections, + IEnumerable actualSections) + { + AssertCollectionAndItems(expectedSections, + actualSections, + (expectedItem, actualItem) => + { + Assert.AreEqual(expectedItem.Name, actualItem.Name); + CollectionAssert.AreEqual(expectedItem.Points, actualItem.Points); + }); + } + + private static void AssertReferenceLine(ReferenceLine expectedReferenceLine, ReferenceLine actualReferenceLine) + { + Assert.IsNotNull(expectedReferenceLine); + + CollectionAssert.AreEqual(expectedReferenceLine.Points, actualReferenceLine.Points); + } + + private static void AssertSegmentPoints(IEnumerable expectedSoilModelSegmentPoints, + IEnumerable actualSoilModelSegmentPoints) + { + Assert.Greater(expectedSoilModelSegmentPoints.Count(), 0); + + CollectionAssert.AreEqual(expectedSoilModelSegmentPoints, actualSoilModelSegmentPoints); + } + + private static void AssertCalculationGroup(CalculationGroup expectedRootCalculationGroup, + CalculationGroup actualRootCalculationGroup) + { + Assert.AreEqual(expectedRootCalculationGroup.Name, actualRootCalculationGroup.Name); + + Assert.AreEqual(expectedRootCalculationGroup.Children.Count, actualRootCalculationGroup.Children.Count); + for (var i = 0; i < expectedRootCalculationGroup.Children.Count; i++) + { + ICalculationBase expectedChild = expectedRootCalculationGroup.Children[i]; + ICalculationBase actualChild = actualRootCalculationGroup.Children[i]; + + Assert.AreEqual(expectedChild.GetType(), actualChild.GetType()); + + var expectedChildGroup = expectedChild as CalculationGroup; + if (expectedChildGroup != null) + { + AssertCalculationGroup(expectedChildGroup, (CalculationGroup) actualChild); + } + + var expectedPipingCalculation = expectedChild as PipingCalculationScenario; + if (expectedPipingCalculation != null) + { + AssertPipingCalculationScenario(expectedPipingCalculation, (PipingCalculationScenario) actualChild); + } + + var expectedMacroStabilityInwardsCalculation = expectedChild as MacroStabilityInwardsCalculationScenario; + if (expectedMacroStabilityInwardsCalculation != null) + { + AssertMacroStabilityInwardsCalculationScenario(expectedMacroStabilityInwardsCalculation, (MacroStabilityInwardsCalculationScenario) actualChild); + } + + var expectedGrassCoverErosionInwardsCalculation = expectedChild as GrassCoverErosionInwardsCalculation; + if (expectedGrassCoverErosionInwardsCalculation != null) + { + AssertGrassCoverErosionInwardsCalculation(expectedGrassCoverErosionInwardsCalculation, (GrassCoverErosionInwardsCalculation) actualChild); + } + + var expectedGrassCoverErosionOutwardsCalculation = expectedChild as GrassCoverErosionOutwardsWaveConditionsCalculation; + if (expectedGrassCoverErosionOutwardsCalculation != null) + { + AssertGrassCoverErosionOutwardsWaveConditionsCalculation(expectedGrassCoverErosionOutwardsCalculation, (GrassCoverErosionOutwardsWaveConditionsCalculation) actualChild); + } + + var expectedHeightStructuresCalculation = expectedChild as StructuresCalculation; + if (expectedHeightStructuresCalculation != null) + { + AssertStructuresCalculation(expectedHeightStructuresCalculation, (StructuresCalculation) actualChild); + } + + var expectedClosingStructuresCalculation = expectedChild as StructuresCalculation; + if (expectedClosingStructuresCalculation != null) + { + AssertStructuresCalculation(expectedClosingStructuresCalculation, (StructuresCalculation) actualChild); + } + + var expectedStabilityPointStructuresCalculation = expectedChild as StructuresCalculation; + if (expectedStabilityPointStructuresCalculation != null) + { + AssertStructuresCalculation(expectedStabilityPointStructuresCalculation, (StructuresCalculation) actualChild); + } + + var expectedStabilityStoneCoverWaveConditionsCalculation = expectedChild as StabilityStoneCoverWaveConditionsCalculation; + if (expectedStabilityStoneCoverWaveConditionsCalculation != null) + { + AssertStabilityStoneCoverWaveConditionsCalculation(expectedStabilityStoneCoverWaveConditionsCalculation, (StabilityStoneCoverWaveConditionsCalculation) actualChild); + } + + var expectedWaveImpactAsphaltCoverWaveConditionsCalculation = expectedChild as WaveImpactAsphaltCoverWaveConditionsCalculation; + if (expectedWaveImpactAsphaltCoverWaveConditionsCalculation != null) + { + AssertWaveImpactAsphaltCoverWaveConditionsCalculation(expectedWaveImpactAsphaltCoverWaveConditionsCalculation, (WaveImpactAsphaltCoverWaveConditionsCalculation) actualChild); + } + } + } + + private static void AssertWaveConditionsInput(WaveConditionsInput expectedInput, WaveConditionsInput actualInput) + { + AssertReferencedObject(() => expectedInput.ForeshoreProfile, + () => actualInput.ForeshoreProfile, + AssertForeshoreProfile); + AssertReferencedObject(() => expectedInput.HydraulicBoundaryLocation, + () => actualInput.HydraulicBoundaryLocation, + AssertHydraulicBoundaryLocation); + + AssertBreakWater(expectedInput.BreakWater, actualInput.BreakWater); + Assert.AreEqual(expectedInput.Orientation, actualInput.Orientation); + Assert.AreEqual(expectedInput.UseBreakWater, actualInput.UseBreakWater); + Assert.AreEqual(expectedInput.UseForeshore, actualInput.UseForeshore); + Assert.AreEqual(expectedInput.UpperBoundaryRevetment, actualInput.UpperBoundaryRevetment); + Assert.AreEqual(expectedInput.LowerBoundaryRevetment, actualInput.LowerBoundaryRevetment); + Assert.AreEqual(expectedInput.UpperBoundaryWaterLevels, actualInput.UpperBoundaryWaterLevels); + Assert.AreEqual(expectedInput.LowerBoundaryWaterLevels, actualInput.LowerBoundaryWaterLevels); + Assert.AreEqual(expectedInput.StepSize, actualInput.StepSize); + } + + private static void AssertWaveConditionsOutputs(IEnumerable expectedOutputs, + IEnumerable actualOutputs) + { + AssertCollectionAndItems(expectedOutputs, + actualOutputs, + AssertWaveConditionsOutput); + } + + private static void AssertWaveConditionsOutput(WaveConditionsOutput expectedOutput, + WaveConditionsOutput actualOutput) + { + Assert.AreEqual(expectedOutput.WaterLevel, actualOutput.WaterLevel, expectedOutput.WaterLevel.GetAccuracy()); + Assert.AreEqual(expectedOutput.WaveHeight, actualOutput.WaveHeight, expectedOutput.WaveHeight.GetAccuracy()); + Assert.AreEqual(expectedOutput.WavePeakPeriod, actualOutput.WavePeakPeriod, expectedOutput.WavePeakPeriod.GetAccuracy()); + Assert.AreEqual(expectedOutput.WaveAngle, actualOutput.WaveAngle, expectedOutput.WaveAngle.GetAccuracy()); + Assert.AreEqual(expectedOutput.WaveDirection, actualOutput.WaveDirection, expectedOutput.WaveDirection.GetAccuracy()); + Assert.AreEqual(expectedOutput.TargetProbability, actualOutput.TargetProbability); + Assert.AreEqual(expectedOutput.TargetReliability, actualOutput.TargetReliability, expectedOutput.TargetReliability.GetAccuracy()); + Assert.AreEqual(expectedOutput.CalculatedProbability, actualOutput.CalculatedProbability); + Assert.AreEqual(expectedOutput.CalculatedReliability, actualOutput.CalculatedReliability, expectedOutput.CalculatedReliability.GetAccuracy()); + Assert.AreEqual(expectedOutput.CalculationConvergence, actualOutput.CalculationConvergence); + } + + private static void AssertDikeProfiles(DikeProfileCollection expectedDikeProfiles, DikeProfileCollection actualDikeProfiles) + { + Assert.AreEqual(expectedDikeProfiles.SourcePath, actualDikeProfiles.SourcePath); + AssertCollectionAndItems(expectedDikeProfiles, + actualDikeProfiles, + AssertDikeProfile); + } + + private static void AssertDikeProfile(DikeProfile expectedDikeProfile, DikeProfile actualDikeProfile) + { + Assert.AreEqual(expectedDikeProfile.Name, actualDikeProfile.Name); + Assert.AreEqual(expectedDikeProfile.WorldReferencePoint, actualDikeProfile.WorldReferencePoint); + Assert.AreEqual(expectedDikeProfile.X0, actualDikeProfile.X0); + Assert.AreEqual(expectedDikeProfile.Orientation, actualDikeProfile.Orientation); + AssertBreakWater(expectedDikeProfile.BreakWater, actualDikeProfile.BreakWater); + CollectionAssert.AreEqual(expectedDikeProfile.ForeshoreGeometry, actualDikeProfile.ForeshoreGeometry); + AssertRoughnessPoints(expectedDikeProfile.DikeGeometry, actualDikeProfile.DikeGeometry); + Assert.AreEqual(expectedDikeProfile.DikeHeight, actualDikeProfile.DikeHeight); + } + + private static void AssertForeshoreProfiles(ForeshoreProfileCollection expectedForeshoreProfiles, + ForeshoreProfileCollection actualForeshoreProfiles) + { + Assert.AreEqual(expectedForeshoreProfiles.SourcePath, actualForeshoreProfiles.SourcePath); + AssertCollectionAndItems(expectedForeshoreProfiles, + actualForeshoreProfiles, + AssertForeshoreProfile); + } + + private static void AssertForeshoreProfile(ForeshoreProfile expectedDikeProfile, ForeshoreProfile actualDikeProfile) + { + Assert.AreEqual(expectedDikeProfile.Name, actualDikeProfile.Name); + Assert.AreEqual(expectedDikeProfile.WorldReferencePoint, actualDikeProfile.WorldReferencePoint); + Assert.AreEqual(expectedDikeProfile.X0, actualDikeProfile.X0); + Assert.AreEqual(expectedDikeProfile.Orientation, actualDikeProfile.Orientation); + AssertBreakWater(expectedDikeProfile.BreakWater, actualDikeProfile.BreakWater); + CollectionAssert.AreEqual(expectedDikeProfile.Geometry, actualDikeProfile.Geometry); + } + + private static void AssertBreakWater(BreakWater expectedBreakWater, BreakWater actualBreakWater) + { + if (expectedBreakWater == null) + { + Assert.IsNull(actualBreakWater); + } + else + { + Assert.AreEqual(expectedBreakWater.Height, actualBreakWater.Height); + Assert.AreEqual(expectedBreakWater.Type, actualBreakWater.Type); + } + } + + private static void AssertRoughnessPoints(IEnumerable expectedRoughnessPoints, + IEnumerable actualRoughnessPoints) + { + AssertCollectionAndItems(expectedRoughnessPoints, + actualRoughnessPoints, + AssertRoughnessPoint); + } + + private static void AssertRoughnessPoint(RoughnessPoint expectedRoughnessPoint, RoughnessPoint actualRoughnessPoint) + { + Assert.AreEqual(expectedRoughnessPoint.Point, actualRoughnessPoint.Point); + Assert.AreEqual(expectedRoughnessPoint.Roughness, actualRoughnessPoint.Roughness); + } + + private static void AssertComments(Comment expectedComments, Comment actualComments) + { + Assert.AreEqual(expectedComments.Body, actualComments.Body); + } + + private static void AssertStructureInputBase(StructuresInputBase expectedInput, + StructuresInputBase actualInput) where T : StructureBase + { + AssertReferencedObject(() => expectedInput.ForeshoreProfile, + () => actualInput.ForeshoreProfile, + AssertForeshoreProfile); + AssertReferencedObject(() => expectedInput.HydraulicBoundaryLocation, + () => actualInput.HydraulicBoundaryLocation, + AssertHydraulicBoundaryLocation); + + Assert.AreEqual(expectedInput.StructureNormalOrientation, actualInput.StructureNormalOrientation); + DistributionAssert.AreEqual(expectedInput.AllowedLevelIncreaseStorage, actualInput.AllowedLevelIncreaseStorage); + DistributionAssert.AreEqual(expectedInput.StorageStructureArea, actualInput.StorageStructureArea); + DistributionAssert.AreEqual(expectedInput.FlowWidthAtBottomProtection, actualInput.FlowWidthAtBottomProtection); + DistributionAssert.AreEqual(expectedInput.CriticalOvertoppingDischarge, actualInput.CriticalOvertoppingDischarge); + Assert.AreEqual(expectedInput.FailureProbabilityStructureWithErosion, actualInput.FailureProbabilityStructureWithErosion); + DistributionAssert.AreEqual(expectedInput.WidthFlowApertures, actualInput.WidthFlowApertures); + DistributionAssert.AreEqual(expectedInput.StormDuration, actualInput.StormDuration); + Assert.AreEqual(expectedInput.UseBreakWater, actualInput.UseBreakWater); + AssertBreakWater(expectedInput.BreakWater, actualInput.BreakWater); + } + + /// + /// Asserts two collections with items of on the + /// length of the collections and whether the items are equal according to + /// . + /// + /// The item type to assert. + /// The expected collection to assert + /// against to. + /// The actual collection to assert. + /// The action to compare items in the collection + /// against each other. + /// Thrown when the collections are + /// not of equal length or when the items within the collection are not equal. + private static void AssertCollectionAndItems(IEnumerable expectedCollection, + IEnumerable actualCollection, + Action assertAction) + { + T[] expectedArray = expectedCollection.ToArray(); + T[] actualArray = actualCollection.ToArray(); + int expectedNrOfItems = expectedArray.Length; + Assert.AreEqual(expectedNrOfItems, actualArray.Length); + + for (var i = 0; i < expectedNrOfItems; i++) + { + assertAction(expectedArray[i], actualArray[i]); + } + } + + /// + /// Asserts two referenced objects of and whether + /// the objects are equal. + /// + /// The type to assert. + /// The function to perform to retrieve the expected object. + /// The function to perform to retrieve the actual object + /// The action to compare the objects against each other. + /// Thrown when the items are not equal. + private static void AssertReferencedObject(Func getExpectedReference, + Func getActualReference, + Action assertAction) + { + T expectedReferenceValue = getExpectedReference(); + if (expectedReferenceValue == null) + { + Assert.IsNull(getActualReference()); + } + else + { + assertAction(expectedReferenceValue, getActualReference()); + } + } + + #region StabilityPointStructures FailureMechanism + + private static void AssertStabilityPointStructuresFailureMechanism(StabilityPointStructuresFailureMechanism expectedFailureMechanism, + StabilityPointStructuresFailureMechanism actualFailureMechanism) + { + Assert.AreEqual(expectedFailureMechanism.GeneralInput.N, actualFailureMechanism.GeneralInput.N); + + AssertForeshoreProfiles(expectedFailureMechanism.ForeshoreProfiles, actualFailureMechanism.ForeshoreProfiles); + AssertStabilityPointStructures(expectedFailureMechanism.StabilityPointStructures, actualFailureMechanism.StabilityPointStructures); + AssertCalculationGroup(expectedFailureMechanism.CalculationsGroup, actualFailureMechanism.CalculationsGroup); + } + + private static void AssertFailureMechanismSectionResults(IEnumerable expectedSectionResults, + IEnumerable actualSectionResults) + { + AssertCollectionAndItems(expectedSectionResults, + actualSectionResults, + (expectedItem, actualItem) => + { + Assert.AreEqual(expectedItem.SimpleAssessmentResult, actualItem.SimpleAssessmentResult); + Assert.AreEqual(expectedItem.DetailedAssessmentResult, actualItem.DetailedAssessmentResult); + Assert.AreEqual(expectedItem.TailorMadeAssessmentResult, actualItem.TailorMadeAssessmentResult); + Assert.AreEqual(expectedItem.TailorMadeAssessmentProbability, actualItem.TailorMadeAssessmentProbability, 1e-6); + Assert.AreEqual(expectedItem.UseManualAssembly, actualItem.UseManualAssembly); + Assert.AreEqual(expectedItem.ManualAssemblyProbability, actualItem.ManualAssemblyProbability, 1e-6); + + if (expectedItem.Calculation == null) + { + Assert.IsNull(actualItem.Calculation); + } + else + { + AssertStructuresCalculation(expectedItem.Calculation, actualItem.Calculation); + } + }); + } + + private static void AssertStabilityPointStructures(StructureCollection expectedStabilityPointStructures, + StructureCollection actualStabilityPointStructures) + { + Assert.AreEqual(expectedStabilityPointStructures.Count, actualStabilityPointStructures.Count); + for (var i = 0; i < expectedStabilityPointStructures.Count; i++) + { + AssertStabilityPointStructure(expectedStabilityPointStructures[i], actualStabilityPointStructures[i]); + } + } + + private static void AssertStabilityPointStructure(StabilityPointStructure expectedStabilityPointStructure, + StabilityPointStructure actualStabilityPointStructure) + { + Assert.AreEqual(expectedStabilityPointStructure.Name, actualStabilityPointStructure.Name); + Assert.AreEqual(expectedStabilityPointStructure.Id, actualStabilityPointStructure.Id); + Assert.AreEqual(expectedStabilityPointStructure.Location, actualStabilityPointStructure.Location); + Assert.AreEqual(expectedStabilityPointStructure.StructureNormalOrientation, actualStabilityPointStructure.StructureNormalOrientation); + + DistributionAssert.AreEqual(expectedStabilityPointStructure.StorageStructureArea, actualStabilityPointStructure.StorageStructureArea); + DistributionAssert.AreEqual(expectedStabilityPointStructure.AllowedLevelIncreaseStorage, actualStabilityPointStructure.AllowedLevelIncreaseStorage); + DistributionAssert.AreEqual(expectedStabilityPointStructure.WidthFlowApertures, actualStabilityPointStructure.WidthFlowApertures); + DistributionAssert.AreEqual(expectedStabilityPointStructure.InsideWaterLevel, actualStabilityPointStructure.InsideWaterLevel); + DistributionAssert.AreEqual(expectedStabilityPointStructure.ThresholdHeightOpenWeir, actualStabilityPointStructure.ThresholdHeightOpenWeir); + DistributionAssert.AreEqual(expectedStabilityPointStructure.CriticalOvertoppingDischarge, actualStabilityPointStructure.CriticalOvertoppingDischarge); + DistributionAssert.AreEqual(expectedStabilityPointStructure.FlowWidthAtBottomProtection, actualStabilityPointStructure.FlowWidthAtBottomProtection); + DistributionAssert.AreEqual(expectedStabilityPointStructure.ConstructiveStrengthLinearLoadModel, actualStabilityPointStructure.ConstructiveStrengthLinearLoadModel); + DistributionAssert.AreEqual(expectedStabilityPointStructure.ConstructiveStrengthQuadraticLoadModel, actualStabilityPointStructure.ConstructiveStrengthQuadraticLoadModel); + DistributionAssert.AreEqual(expectedStabilityPointStructure.BankWidth, actualStabilityPointStructure.BankWidth); + DistributionAssert.AreEqual(expectedStabilityPointStructure.InsideWaterLevelFailureConstruction, actualStabilityPointStructure.InsideWaterLevelFailureConstruction); + Assert.AreEqual(expectedStabilityPointStructure.EvaluationLevel, actualStabilityPointStructure.EvaluationLevel); + DistributionAssert.AreEqual(expectedStabilityPointStructure.LevelCrestStructure, actualStabilityPointStructure.LevelCrestStructure); + Assert.AreEqual(expectedStabilityPointStructure.VerticalDistance, actualStabilityPointStructure.VerticalDistance); + Assert.AreEqual(expectedStabilityPointStructure.FailureProbabilityRepairClosure, actualStabilityPointStructure.FailureProbabilityRepairClosure); + DistributionAssert.AreEqual(expectedStabilityPointStructure.FailureCollisionEnergy, actualStabilityPointStructure.FailureCollisionEnergy); + DistributionAssert.AreEqual(expectedStabilityPointStructure.ShipMass, actualStabilityPointStructure.ShipMass); + DistributionAssert.AreEqual(expectedStabilityPointStructure.ShipVelocity, actualStabilityPointStructure.ShipVelocity); + Assert.AreEqual(expectedStabilityPointStructure.LevellingCount, actualStabilityPointStructure.LevellingCount); + Assert.AreEqual(expectedStabilityPointStructure.ProbabilityCollisionSecondaryStructure, actualStabilityPointStructure.ProbabilityCollisionSecondaryStructure); + DistributionAssert.AreEqual(expectedStabilityPointStructure.FlowVelocityStructureClosable, actualStabilityPointStructure.FlowVelocityStructureClosable); + DistributionAssert.AreEqual(expectedStabilityPointStructure.StabilityLinearLoadModel, actualStabilityPointStructure.StabilityLinearLoadModel); + DistributionAssert.AreEqual(expectedStabilityPointStructure.StabilityQuadraticLoadModel, actualStabilityPointStructure.StabilityQuadraticLoadModel); + DistributionAssert.AreEqual(expectedStabilityPointStructure.AreaFlowApertures, actualStabilityPointStructure.AreaFlowApertures); + Assert.AreEqual(expectedStabilityPointStructure.InflowModelType, actualStabilityPointStructure.InflowModelType); + } + + private static void AssertStructuresCalculation(StructuresCalculation expectedCalculation, + StructuresCalculation actualCalculation) + { + Assert.AreEqual(expectedCalculation.Name, actualCalculation.Name); + AssertComments(expectedCalculation.Comments, actualCalculation.Comments); + + AssertStabilityPointStructuresInput(expectedCalculation.InputParameters, actualCalculation.InputParameters); + + if (!expectedCalculation.HasOutput) + { + Assert.IsFalse(actualCalculation.HasOutput); + return; + } + + StructuresOutput expectedOutput = expectedCalculation.Output; + StructuresOutput actualOutput = actualCalculation.Output; + Assert.IsNotNull(actualOutput); + Assert.AreEqual(expectedOutput.Reliability, actualOutput.Reliability); + + AssertGeneralResultTopLevelFaultTreeIllustrationPoint( + expectedOutput.GeneralResult, + actualOutput.GeneralResult); + } + + private static void AssertStabilityPointStructuresInput(StabilityPointStructuresInput expectedInput, + StabilityPointStructuresInput actualInput) + { + AssertStructureInputBase(expectedInput, actualInput); + + AssertReferencedObject(() => expectedInput.Structure, + () => actualInput.Structure, + AssertStabilityPointStructure); + + DistributionAssert.AreEqual(expectedInput.InsideWaterLevel, actualInput.InsideWaterLevel); + DistributionAssert.AreEqual(expectedInput.ThresholdHeightOpenWeir, actualInput.ThresholdHeightOpenWeir); + DistributionAssert.AreEqual(expectedInput.ConstructiveStrengthLinearLoadModel, actualInput.ConstructiveStrengthLinearLoadModel); + DistributionAssert.AreEqual(expectedInput.ConstructiveStrengthQuadraticLoadModel, actualInput.ConstructiveStrengthQuadraticLoadModel); + DistributionAssert.AreEqual(expectedInput.BankWidth, actualInput.BankWidth); + DistributionAssert.AreEqual(expectedInput.InsideWaterLevelFailureConstruction, actualInput.InsideWaterLevelFailureConstruction); + Assert.AreEqual(expectedInput.EvaluationLevel, actualInput.EvaluationLevel); + DistributionAssert.AreEqual(expectedInput.LevelCrestStructure, actualInput.LevelCrestStructure); + Assert.AreEqual(expectedInput.VerticalDistance, actualInput.VerticalDistance); + Assert.AreEqual(expectedInput.FailureProbabilityRepairClosure, actualInput.FailureProbabilityRepairClosure); + DistributionAssert.AreEqual(expectedInput.FailureCollisionEnergy, actualInput.FailureCollisionEnergy); + DistributionAssert.AreEqual(expectedInput.ShipMass, actualInput.ShipMass); + DistributionAssert.AreEqual(expectedInput.ShipVelocity, actualInput.ShipVelocity); + Assert.AreEqual(expectedInput.LevellingCount, actualInput.LevellingCount); + Assert.AreEqual(expectedInput.ProbabilityCollisionSecondaryStructure, actualInput.ProbabilityCollisionSecondaryStructure); + DistributionAssert.AreEqual(expectedInput.FlowVelocityStructureClosable, actualInput.FlowVelocityStructureClosable); + DistributionAssert.AreEqual(expectedInput.StabilityLinearLoadModel, actualInput.StabilityLinearLoadModel); + DistributionAssert.AreEqual(expectedInput.StabilityQuadraticLoadModel, actualInput.StabilityQuadraticLoadModel); + DistributionAssert.AreEqual(expectedInput.AreaFlowApertures, actualInput.AreaFlowApertures); + Assert.AreEqual(expectedInput.InflowModelType, actualInput.InflowModelType); + Assert.AreEqual(expectedInput.LoadSchematizationType, actualInput.LoadSchematizationType); + Assert.AreEqual(expectedInput.VolumicWeightWater, actualInput.VolumicWeightWater); + Assert.AreEqual(expectedInput.FactorStormDurationOpenStructure, actualInput.FactorStormDurationOpenStructure); + DistributionAssert.AreEqual(expectedInput.DrainCoefficient, actualInput.DrainCoefficient); + } + + #endregion + + #region ClosingStructures FailureMechanism + + private static void AssertClosingStructuresFailureMechanism(ClosingStructuresFailureMechanism expectedFailureMechanism, + ClosingStructuresFailureMechanism actualFailureMechanism) + { + Assert.AreEqual(expectedFailureMechanism.GeneralInput.N2A, actualFailureMechanism.GeneralInput.N2A); + + AssertForeshoreProfiles(expectedFailureMechanism.ForeshoreProfiles, actualFailureMechanism.ForeshoreProfiles); + AssertClosingStructures(expectedFailureMechanism.ClosingStructures, actualFailureMechanism.ClosingStructures); + AssertCalculationGroup(expectedFailureMechanism.CalculationsGroup, actualFailureMechanism.CalculationsGroup); + } + + private static void AssertFailureMechanismSectionResults(IEnumerable expectedSectionResults, + IEnumerable actualSectionResults) + { + AssertCollectionAndItems(expectedSectionResults, + actualSectionResults, + (expectedItem, actualItem) => + { + Assert.AreEqual(expectedItem.SimpleAssessmentResult, actualItem.SimpleAssessmentResult); + Assert.AreEqual(expectedItem.DetailedAssessmentResult, actualItem.DetailedAssessmentResult); + Assert.AreEqual(expectedItem.TailorMadeAssessmentResult, actualItem.TailorMadeAssessmentResult); + Assert.AreEqual(expectedItem.TailorMadeAssessmentProbability, actualItem.TailorMadeAssessmentProbability, 1e-6); + Assert.AreEqual(expectedItem.UseManualAssembly, actualItem.UseManualAssembly); + Assert.AreEqual(expectedItem.ManualAssemblyProbability, actualItem.ManualAssemblyProbability, 1e-6); + + if (expectedItem.Calculation == null) + { + Assert.IsNull(actualItem.Calculation); + } + else + { + AssertStructuresCalculation(expectedItem.Calculation, actualItem.Calculation); + } + }); + } + + private static void AssertClosingStructures(StructureCollection expectedClosingStructures, + StructureCollection actualClosingStructures) + { + Assert.AreEqual(expectedClosingStructures.SourcePath, actualClosingStructures.SourcePath); + AssertCollectionAndItems(expectedClosingStructures, + actualClosingStructures, + AssertClosingStructure); + } + + private static void AssertClosingStructure(ClosingStructure expectedClosingStructure, + ClosingStructure actualClosingStructure) + { + Assert.AreEqual(expectedClosingStructure.Name, actualClosingStructure.Name); + Assert.AreEqual(expectedClosingStructure.Id, actualClosingStructure.Id); + Assert.AreEqual(expectedClosingStructure.Location, actualClosingStructure.Location); + Assert.AreEqual(expectedClosingStructure.StructureNormalOrientation, actualClosingStructure.StructureNormalOrientation); + + DistributionAssert.AreEqual(expectedClosingStructure.StorageStructureArea, actualClosingStructure.StorageStructureArea); + DistributionAssert.AreEqual(expectedClosingStructure.AllowedLevelIncreaseStorage, actualClosingStructure.AllowedLevelIncreaseStorage); + DistributionAssert.AreEqual(expectedClosingStructure.WidthFlowApertures, actualClosingStructure.WidthFlowApertures); + DistributionAssert.AreEqual(expectedClosingStructure.LevelCrestStructureNotClosing, actualClosingStructure.LevelCrestStructureNotClosing); + DistributionAssert.AreEqual(expectedClosingStructure.InsideWaterLevel, actualClosingStructure.InsideWaterLevel); + DistributionAssert.AreEqual(expectedClosingStructure.ThresholdHeightOpenWeir, actualClosingStructure.ThresholdHeightOpenWeir); + DistributionAssert.AreEqual(expectedClosingStructure.AreaFlowApertures, actualClosingStructure.AreaFlowApertures); + DistributionAssert.AreEqual(expectedClosingStructure.CriticalOvertoppingDischarge, actualClosingStructure.CriticalOvertoppingDischarge); + DistributionAssert.AreEqual(expectedClosingStructure.FlowWidthAtBottomProtection, actualClosingStructure.FlowWidthAtBottomProtection); + Assert.AreEqual(expectedClosingStructure.ProbabilityOpenStructureBeforeFlooding, actualClosingStructure.ProbabilityOpenStructureBeforeFlooding); + Assert.AreEqual(expectedClosingStructure.FailureProbabilityOpenStructure, actualClosingStructure.FailureProbabilityOpenStructure); + Assert.AreEqual(expectedClosingStructure.IdenticalApertures, actualClosingStructure.IdenticalApertures); + Assert.AreEqual(expectedClosingStructure.FailureProbabilityReparation, actualClosingStructure.FailureProbabilityReparation); + Assert.AreEqual(expectedClosingStructure.InflowModelType, actualClosingStructure.InflowModelType); + } + + private static void AssertStructuresCalculation(StructuresCalculation expectedCalculation, + StructuresCalculation actualCalculation) + { + Assert.AreEqual(expectedCalculation.Name, actualCalculation.Name); + AssertComments(expectedCalculation.Comments, actualCalculation.Comments); + + AssertClosingStructuresInput(expectedCalculation.InputParameters, actualCalculation.InputParameters); + + if (!expectedCalculation.HasOutput) + { + Assert.IsFalse(actualCalculation.HasOutput); + return; + } + + StructuresOutput expectedOutput = expectedCalculation.Output; + StructuresOutput actualOutput = actualCalculation.Output; + Assert.IsNotNull(actualOutput); + Assert.AreEqual(expectedOutput.Reliability, actualOutput.Reliability); + + AssertGeneralResultTopLevelFaultTreeIllustrationPoint( + expectedOutput.GeneralResult, + actualOutput.GeneralResult); + } + + private static void AssertClosingStructuresInput(ClosingStructuresInput expectedInput, + ClosingStructuresInput actualInput) + { + AssertStructureInputBase(expectedInput, actualInput); + + AssertReferencedObject(() => expectedInput.Structure, + () => actualInput.Structure, + AssertClosingStructure); + + Assert.AreEqual(expectedInput.InflowModelType, actualInput.InflowModelType); + DistributionAssert.AreEqual(expectedInput.InsideWaterLevel, actualInput.InsideWaterLevel); + Assert.AreEqual(expectedInput.DeviationWaveDirection, actualInput.DeviationWaveDirection); + DistributionAssert.AreEqual(expectedInput.ModelFactorSuperCriticalFlow, actualInput.ModelFactorSuperCriticalFlow); + DistributionAssert.AreEqual(expectedInput.DrainCoefficient, actualInput.DrainCoefficient); + Assert.AreEqual(expectedInput.FactorStormDurationOpenStructure, actualInput.FactorStormDurationOpenStructure); + DistributionAssert.AreEqual(expectedInput.ThresholdHeightOpenWeir, actualInput.ThresholdHeightOpenWeir); + DistributionAssert.AreEqual(expectedInput.AreaFlowApertures, actualInput.AreaFlowApertures); + Assert.AreEqual(expectedInput.FailureProbabilityOpenStructure, actualInput.FailureProbabilityOpenStructure); + Assert.AreEqual(expectedInput.FailureProbabilityReparation, actualInput.FailureProbabilityReparation); + Assert.AreEqual(expectedInput.IdenticalApertures, actualInput.IdenticalApertures); + DistributionAssert.AreEqual(expectedInput.LevelCrestStructureNotClosing, actualInput.LevelCrestStructureNotClosing); + Assert.AreEqual(expectedInput.ProbabilityOpenStructureBeforeFlooding, actualInput.ProbabilityOpenStructureBeforeFlooding); + } + + #endregion + + #region DuneErosion FailureMechanism + + private static void AssertDuneErosionFailureMechanism(DuneErosionFailureMechanism expectedFailureMechanism, + DuneErosionFailureMechanism actualFailureMechanism) + { + Assert.AreEqual(expectedFailureMechanism.GeneralInput.N, actualFailureMechanism.GeneralInput.N); + + AssertDuneLocations(expectedFailureMechanism.DuneLocations, actualFailureMechanism.DuneLocations); + AssertDuneLocationCalculations(expectedFailureMechanism, actualFailureMechanism); + } + + private static void AssertFailureMechanismSectionResults( + IEnumerable expectedSectionResults, + IEnumerable actualSectionResults) + { + AssertCollectionAndItems(expectedSectionResults, + actualSectionResults, + (expectedItem, actualItem) => + { + Assert.AreEqual(expectedItem.SimpleAssessmentResult, actualItem.SimpleAssessmentResult); + Assert.AreEqual(expectedItem.DetailedAssessmentResultForFactorizedSignalingNorm, actualItem.DetailedAssessmentResultForFactorizedSignalingNorm); + Assert.AreEqual(expectedItem.DetailedAssessmentResultForSignalingNorm, actualItem.DetailedAssessmentResultForSignalingNorm); + Assert.AreEqual(expectedItem.DetailedAssessmentResultForMechanismSpecificLowerLimitNorm, actualItem.DetailedAssessmentResultForMechanismSpecificLowerLimitNorm); + Assert.AreEqual(expectedItem.DetailedAssessmentResultForLowerLimitNorm, actualItem.DetailedAssessmentResultForLowerLimitNorm); + Assert.AreEqual(expectedItem.DetailedAssessmentResultForFactorizedLowerLimitNorm, actualItem.DetailedAssessmentResultForFactorizedLowerLimitNorm); + Assert.AreEqual(expectedItem.TailorMadeAssessmentResult, actualItem.TailorMadeAssessmentResult); + Assert.AreEqual(expectedItem.UseManualAssembly, actualItem.UseManualAssembly); + Assert.AreEqual(expectedItem.ManualAssemblyCategoryGroup, actualItem.ManualAssemblyCategoryGroup); + }); + } + + private static void AssertDuneLocations(IEnumerable expectedDuneLocations, + IEnumerable actualDuneLocations) + { + AssertCollectionAndItems(expectedDuneLocations, + actualDuneLocations, + AssertDuneBoundaryLocation); + } + + private static void AssertDuneLocationCalculations(DuneErosionFailureMechanism expectedFailureMechanism, + DuneErosionFailureMechanism actualFailureMechanism) + { + AssertDuneLocationCalculations(expectedFailureMechanism.CalculationsForMechanismSpecificFactorizedSignalingNorm, + actualFailureMechanism.CalculationsForMechanismSpecificFactorizedSignalingNorm); + + AssertDuneLocationCalculations(expectedFailureMechanism.CalculationsForMechanismSpecificSignalingNorm, + actualFailureMechanism.CalculationsForMechanismSpecificSignalingNorm); + + AssertDuneLocationCalculations(expectedFailureMechanism.CalculationsForMechanismSpecificLowerLimitNorm, + actualFailureMechanism.CalculationsForMechanismSpecificLowerLimitNorm); + + AssertDuneLocationCalculations(expectedFailureMechanism.CalculationsForLowerLimitNorm, + actualFailureMechanism.CalculationsForLowerLimitNorm); + + AssertDuneLocationCalculations(expectedFailureMechanism.CalculationsForFactorizedLowerLimitNorm, + actualFailureMechanism.CalculationsForFactorizedLowerLimitNorm); + } + + private static void AssertDuneLocationCalculations(IEnumerable expectedDuneLocationCalculations, + IEnumerable actualDuneLocationCalculations) + { + AssertCollectionAndItems(expectedDuneLocationCalculations, + actualDuneLocationCalculations, + AssertDuneLocationCalculation); + } + + private static void AssertDuneBoundaryLocation(DuneLocation expectedLocation, DuneLocation actualLocation) + { + Assert.AreEqual(expectedLocation.Id, actualLocation.Id); + Assert.AreEqual(expectedLocation.Name, actualLocation.Name); + Assert.AreEqual(expectedLocation.Location, actualLocation.Location); + Assert.AreEqual(expectedLocation.CoastalAreaId, actualLocation.CoastalAreaId); + Assert.AreEqual(expectedLocation.Offset, actualLocation.Offset); + Assert.AreEqual(expectedLocation.Orientation, actualLocation.Orientation); + Assert.AreEqual(expectedLocation.D50, actualLocation.D50); + } + + private static void AssertDuneLocationCalculation(DuneLocationCalculation expectedCalculation, DuneLocationCalculation actualCalculation) + { + AssertDuneBoundaryLocation(expectedCalculation.DuneLocation, actualCalculation.DuneLocation); + AssertDuneLocationCalculationOutput(expectedCalculation.Output, actualCalculation.Output); + } + + private static void AssertDuneLocationCalculationOutput(DuneLocationCalculationOutput expectedOutput, DuneLocationCalculationOutput actualOutput) + { + if (expectedOutput == null) + { + Assert.IsNull(actualOutput); + return; + } + + Assert.AreEqual(expectedOutput.WaterLevel, actualOutput.WaterLevel); + Assert.AreEqual(expectedOutput.WaveHeight, actualOutput.WaveHeight); + Assert.AreEqual(expectedOutput.WavePeriod, actualOutput.WavePeriod); + Assert.AreEqual(expectedOutput.TargetProbability, actualOutput.TargetProbability); + Assert.AreEqual(expectedOutput.TargetReliability, actualOutput.TargetReliability); + Assert.AreEqual(expectedOutput.CalculatedProbability, actualOutput.CalculatedProbability); + Assert.AreEqual(expectedOutput.CalculatedReliability, actualOutput.CalculatedReliability); + Assert.AreEqual(expectedOutput.CalculationConvergence, actualOutput.CalculationConvergence); + } + + #endregion + + #region HeightStructures FailureMechanism + + private static void AssertHeightStructuresFailureMechanism(HeightStructuresFailureMechanism expectedFailureMechanism, + HeightStructuresFailureMechanism actualFailureMechanism) + { + Assert.AreEqual(expectedFailureMechanism.GeneralInput.N, actualFailureMechanism.GeneralInput.N); + + AssertForeshoreProfiles(expectedFailureMechanism.ForeshoreProfiles, actualFailureMechanism.ForeshoreProfiles); + AssertHeightStructures(expectedFailureMechanism.HeightStructures, actualFailureMechanism.HeightStructures); + AssertCalculationGroup(expectedFailureMechanism.CalculationsGroup, actualFailureMechanism.CalculationsGroup); + } + + private static void AssertFailureMechanismSectionResults(IEnumerable expectedSectionResults, + IEnumerable actualSectionResults) + { + AssertCollectionAndItems(expectedSectionResults, + actualSectionResults, + (expectedItem, actualItem) => + { + Assert.AreEqual(expectedItem.SimpleAssessmentResult, actualItem.SimpleAssessmentResult); + Assert.AreEqual(expectedItem.DetailedAssessmentResult, actualItem.DetailedAssessmentResult); + Assert.AreEqual(expectedItem.TailorMadeAssessmentResult, actualItem.TailorMadeAssessmentResult); + Assert.AreEqual(expectedItem.TailorMadeAssessmentProbability, actualItem.TailorMadeAssessmentProbability, 1e-6); + Assert.AreEqual(expectedItem.UseManualAssembly, actualItem.UseManualAssembly); + Assert.AreEqual(expectedItem.ManualAssemblyProbability, actualItem.ManualAssemblyProbability, 1e-6); + + if (expectedItem.Calculation == null) + { + Assert.IsNull(actualItem.Calculation); + } + else + { + AssertStructuresCalculation(expectedItem.Calculation, actualItem.Calculation); + } + }); + } + + private static void AssertHeightStructures(StructureCollection expectedHeightStructures, + StructureCollection actualHeightStructures) + { + Assert.AreEqual(expectedHeightStructures.SourcePath, actualHeightStructures.SourcePath); + AssertCollectionAndItems(expectedHeightStructures, + actualHeightStructures, + AssertHeightStructure); + } + + private static void AssertHeightStructure(HeightStructure expectedHeightStructure, + HeightStructure actualHeightStructure) + { + Assert.AreEqual(expectedHeightStructure.Name, actualHeightStructure.Name); + Assert.AreEqual(expectedHeightStructure.Id, actualHeightStructure.Id); + Assert.AreEqual(expectedHeightStructure.Location, actualHeightStructure.Location); + Assert.AreEqual(expectedHeightStructure.StructureNormalOrientation, actualHeightStructure.StructureNormalOrientation); + + DistributionAssert.AreEqual(expectedHeightStructure.LevelCrestStructure, actualHeightStructure.LevelCrestStructure); + DistributionAssert.AreEqual(expectedHeightStructure.FlowWidthAtBottomProtection, actualHeightStructure.FlowWidthAtBottomProtection); + DistributionAssert.AreEqual(expectedHeightStructure.CriticalOvertoppingDischarge, actualHeightStructure.CriticalOvertoppingDischarge); + DistributionAssert.AreEqual(expectedHeightStructure.WidthFlowApertures, actualHeightStructure.WidthFlowApertures); + Assert.AreEqual(expectedHeightStructure.FailureProbabilityStructureWithErosion, actualHeightStructure.FailureProbabilityStructureWithErosion); + DistributionAssert.AreEqual(expectedHeightStructure.StorageStructureArea, actualHeightStructure.StorageStructureArea); + DistributionAssert.AreEqual(expectedHeightStructure.AllowedLevelIncreaseStorage, actualHeightStructure.AllowedLevelIncreaseStorage); + } + + private static void AssertStructuresCalculation(StructuresCalculation expectedCalculation, + StructuresCalculation actualCalculation) + { + Assert.AreEqual(expectedCalculation.Name, actualCalculation.Name); + AssertComments(expectedCalculation.Comments, actualCalculation.Comments); + + AssertHeightStructuresInput(expectedCalculation.InputParameters, actualCalculation.InputParameters); + + if (!expectedCalculation.HasOutput) + { + Assert.IsFalse(actualCalculation.HasOutput); + return; + } + + StructuresOutput expectedOutput = expectedCalculation.Output; + StructuresOutput actualOutput = actualCalculation.Output; + Assert.IsNotNull(actualOutput); + Assert.AreEqual(expectedOutput.Reliability, actualOutput.Reliability); + + AssertGeneralResultTopLevelFaultTreeIllustrationPoint( + expectedOutput.GeneralResult, + actualOutput.GeneralResult); + } + + private static void AssertHeightStructuresInput(HeightStructuresInput expectedInput, + HeightStructuresInput actualInput) + { + AssertStructureInputBase(expectedInput, actualInput); + + AssertReferencedObject(() => expectedInput.Structure, + () => actualInput.Structure, + AssertHeightStructure); + + Assert.AreEqual(expectedInput.DeviationWaveDirection, actualInput.DeviationWaveDirection); + DistributionAssert.AreEqual(expectedInput.ModelFactorSuperCriticalFlow, actualInput.ModelFactorSuperCriticalFlow); + DistributionAssert.AreEqual(expectedInput.LevelCrestStructure, actualInput.LevelCrestStructure); + } + + #endregion + + #region Piping FailureMechanism + + private static void AssertPipingFailureMechanism(PipingFailureMechanism expectedFailureMechanism, + PipingFailureMechanism actualFailureMechanism) + { + AssertPipingProbabilityAssessmentInput(expectedFailureMechanism.PipingProbabilityAssessmentInput, actualFailureMechanism.PipingProbabilityAssessmentInput); + AssertPipingStochasticSoilModels(expectedFailureMechanism.StochasticSoilModels, actualFailureMechanism.StochasticSoilModels); + AssertCalculationGroup(expectedFailureMechanism.CalculationsGroup, actualFailureMechanism.CalculationsGroup); + + Assert.AreEqual(expectedFailureMechanism.SurfaceLines.SourcePath, actualFailureMechanism.SurfaceLines.SourcePath); + AssertCollectionAndItems(expectedFailureMechanism.SurfaceLines, + actualFailureMechanism.SurfaceLines, + AssertPipingSurfaceLine); + } + + private static void AssertFailureMechanismSectionResults( + IEnumerable expectedSectionResults, + IEnumerable actualSectionResults) + { + AssertCollectionAndItems(expectedSectionResults, + actualSectionResults, + (expectedItem, actualItem) => + { + Assert.AreEqual(expectedItem.SimpleAssessmentResult, actualItem.SimpleAssessmentResult); + Assert.AreEqual(expectedItem.DetailedAssessmentResult, actualItem.DetailedAssessmentResult); + Assert.AreEqual(expectedItem.TailorMadeAssessmentResult, actualItem.TailorMadeAssessmentResult); + Assert.AreEqual(expectedItem.TailorMadeAssessmentProbability, actualItem.TailorMadeAssessmentProbability, 1e-6); + Assert.AreEqual(expectedItem.UseManualAssembly, actualItem.UseManualAssembly); + Assert.AreEqual(expectedItem.ManualAssemblyProbability, actualItem.ManualAssemblyProbability, 1e-6); + }); + } + + private static void AssertPipingProbabilityAssessmentInput(PipingProbabilityAssessmentInput expectedModel, + PipingProbabilityAssessmentInput actualModel) + { + Assert.AreEqual(expectedModel.A, actualModel.A); + } + + private static void AssertPipingCalculationScenario(PipingCalculationScenario expectedPipingCalculation, + PipingCalculationScenario actualPipingCalculation) + { + Assert.AreEqual(expectedPipingCalculation.IsRelevant, actualPipingCalculation.IsRelevant); + Assert.AreEqual(expectedPipingCalculation.Contribution, actualPipingCalculation.Contribution); + Assert.AreEqual(expectedPipingCalculation.Name, actualPipingCalculation.Name); + AssertComments(expectedPipingCalculation.Comments, actualPipingCalculation.Comments); + + AssertPipingInput(expectedPipingCalculation.InputParameters, actualPipingCalculation.InputParameters); + AssertPipingOutput(expectedPipingCalculation.Output, actualPipingCalculation.Output); + } + + private static void AssertPipingInput(PipingInput expectedPipingInput, PipingInput actualPipingInput) + { + AssertReferencedObject(() => expectedPipingInput.HydraulicBoundaryLocation, + () => actualPipingInput.HydraulicBoundaryLocation, + AssertHydraulicBoundaryLocation); + + AssertReferencedObject(() => expectedPipingInput.SurfaceLine, + () => actualPipingInput.SurfaceLine, + AssertPipingSurfaceLine); + AssertReferencedObject(() => expectedPipingInput.StochasticSoilModel, + () => actualPipingInput.StochasticSoilModel, + AssertPipingStochasticSoilModel); + AssertReferencedObject(() => expectedPipingInput.StochasticSoilProfile, + () => actualPipingInput.StochasticSoilProfile, + AssertPipingStochasticSoilProfile); + + Assert.AreEqual(expectedPipingInput.ExitPointL, actualPipingInput.ExitPointL); + Assert.AreEqual(expectedPipingInput.EntryPointL, actualPipingInput.EntryPointL); + Assert.AreEqual(expectedPipingInput.PhreaticLevelExit.Mean, actualPipingInput.PhreaticLevelExit.Mean); + Assert.AreEqual(expectedPipingInput.PhreaticLevelExit.StandardDeviation, actualPipingInput.PhreaticLevelExit.StandardDeviation); + Assert.AreEqual(expectedPipingInput.DampingFactorExit.Mean, actualPipingInput.DampingFactorExit.Mean); + Assert.AreEqual(expectedPipingInput.DampingFactorExit.StandardDeviation, actualPipingInput.DampingFactorExit.StandardDeviation); + Assert.AreEqual(expectedPipingInput.UseAssessmentLevelManualInput, actualPipingInput.UseAssessmentLevelManualInput); + Assert.AreEqual(expectedPipingInput.AssessmentLevel, actualPipingInput.AssessmentLevel); + } + + private static void AssertPipingOutput(PipingOutput expectedOutput, PipingOutput actualOutput) + { + if (expectedOutput == null) + { + Assert.IsNull(actualOutput); + } + else + { + Assert.AreEqual(expectedOutput.HeaveGradient, actualOutput.HeaveGradient); + Assert.AreEqual(expectedOutput.HeaveFactorOfSafety, actualOutput.HeaveFactorOfSafety); + Assert.AreEqual(expectedOutput.HeaveZValue, actualOutput.HeaveZValue); + Assert.AreEqual(expectedOutput.UpliftEffectiveStress, actualOutput.UpliftEffectiveStress); + Assert.AreEqual(expectedOutput.UpliftFactorOfSafety, actualOutput.UpliftFactorOfSafety); + Assert.AreEqual(expectedOutput.UpliftZValue, actualOutput.UpliftZValue); + Assert.AreEqual(expectedOutput.SellmeijerCreepCoefficient, actualOutput.SellmeijerCreepCoefficient); + Assert.AreEqual(expectedOutput.SellmeijerCriticalFall, actualOutput.SellmeijerCriticalFall); + Assert.AreEqual(expectedOutput.SellmeijerReducedFall, actualOutput.SellmeijerReducedFall); + Assert.AreEqual(expectedOutput.SellmeijerFactorOfSafety, actualOutput.SellmeijerFactorOfSafety); + Assert.AreEqual(expectedOutput.SellmeijerZValue, actualOutput.SellmeijerZValue); + } + } + + private static void AssertPipingStochasticSoilModels(PipingStochasticSoilModelCollection expectedModels, + PipingStochasticSoilModelCollection actualModels) + { + Assert.AreEqual(expectedModels.SourcePath, actualModels.SourcePath); + AssertCollectionAndItems(expectedModels, actualModels, AssertPipingStochasticSoilModel); + } + + private static void AssertPipingStochasticSoilModel(PipingStochasticSoilModel expectedSoilModel, PipingStochasticSoilModel actualSoilModel) + { + Assert.AreEqual(expectedSoilModel.Name, actualSoilModel.Name); + AssertSegmentPoints(expectedSoilModel.Geometry, actualSoilModel.Geometry); + AssertCollectionAndItems(expectedSoilModel.StochasticSoilProfiles, actualSoilModel.StochasticSoilProfiles, + AssertPipingStochasticSoilProfile); + } + + private static void AssertPipingStochasticSoilProfile(PipingStochasticSoilProfile expectedProfile, PipingStochasticSoilProfile actualProfile) + { + Assert.AreEqual(expectedProfile.Probability, actualProfile.Probability); + AssertPipingSoilProfile(expectedProfile.SoilProfile, actualProfile.SoilProfile); + } + + private static void AssertPipingSoilProfile(PipingSoilProfile expectedProfile, PipingSoilProfile actualProfile) + { + Assert.AreEqual(expectedProfile.Bottom, actualProfile.Bottom); + Assert.AreEqual(expectedProfile.Name, actualProfile.Name); + Assert.AreEqual(expectedProfile.SoilProfileSourceType, actualProfile.SoilProfileSourceType); + AssertCollectionAndItems(expectedProfile.Layers, actualProfile.Layers, + AssertPipingSoilLayer); + } + + private static void AssertPipingSoilLayer(PipingSoilLayer expectedLayer, PipingSoilLayer actualLayer) + { + Assert.AreEqual(expectedLayer.Top, actualLayer.Top); + Assert.AreEqual(expectedLayer.IsAquifer, actualLayer.IsAquifer); + Assert.AreEqual(expectedLayer.Color.ToArgb(), actualLayer.Color.ToArgb()); + + DistributionAssert.AreEqual(expectedLayer.BelowPhreaticLevel, actualLayer.BelowPhreaticLevel); + DistributionAssert.AreEqual(expectedLayer.DiameterD70, actualLayer.DiameterD70); + DistributionAssert.AreEqual(expectedLayer.Permeability, actualLayer.Permeability); + } + + private static void AssertPipingSurfaceLine(PipingSurfaceLine expectedSurfaceLine, + PipingSurfaceLine actualSurfaceLine) + { + Assert.AreEqual(expectedSurfaceLine.Name, actualSurfaceLine.Name); + Assert.AreEqual(expectedSurfaceLine.ReferenceLineIntersectionWorldPoint, actualSurfaceLine.ReferenceLineIntersectionWorldPoint); + + CollectionAssert.AreEqual(expectedSurfaceLine.Points, actualSurfaceLine.Points); + + Assert.AreEqual(expectedSurfaceLine.BottomDitchDikeSide, actualSurfaceLine.BottomDitchDikeSide); + Assert.AreEqual(expectedSurfaceLine.BottomDitchPolderSide, actualSurfaceLine.BottomDitchPolderSide); + Assert.AreEqual(expectedSurfaceLine.DikeToeAtPolder, actualSurfaceLine.DikeToeAtPolder); + Assert.AreEqual(expectedSurfaceLine.DikeToeAtRiver, actualSurfaceLine.DikeToeAtRiver); + Assert.AreEqual(expectedSurfaceLine.DitchDikeSide, actualSurfaceLine.DitchDikeSide); + Assert.AreEqual(expectedSurfaceLine.DitchPolderSide, actualSurfaceLine.DitchPolderSide); + } + + #endregion + + #region MacroStabilityInwards FailureMechanism + + private static void AssertMacroStabilityInwardsFailureMechanism(MacroStabilityInwardsFailureMechanism expectedFailureMechanism, + MacroStabilityInwardsFailureMechanism actualFailureMechanism) + { + AssertMacroStabilityInwardsProbabilityAssessmentInput(expectedFailureMechanism.MacroStabilityInwardsProbabilityAssessmentInput, + actualFailureMechanism.MacroStabilityInwardsProbabilityAssessmentInput); + AssertMacroStabilityInwardsStochasticSoilModels(expectedFailureMechanism.StochasticSoilModels, + actualFailureMechanism.StochasticSoilModels); + AssertCalculationGroup(expectedFailureMechanism.CalculationsGroup, actualFailureMechanism.CalculationsGroup); + + Assert.AreEqual(expectedFailureMechanism.SurfaceLines.SourcePath, actualFailureMechanism.SurfaceLines.SourcePath); + AssertCollectionAndItems(expectedFailureMechanism.SurfaceLines, + actualFailureMechanism.SurfaceLines, + AssertMacroStabilityInwardsSurfaceLine); + } + + private static void AssertFailureMechanismSectionResults( + IEnumerable expectedSectionResults, + IEnumerable actualSectionResults) + { + AssertCollectionAndItems(expectedSectionResults, + actualSectionResults, + (expectedItem, actualItem) => + { + Assert.AreEqual(expectedItem.SimpleAssessmentResult, actualItem.SimpleAssessmentResult); + Assert.AreEqual(expectedItem.DetailedAssessmentResult, actualItem.DetailedAssessmentResult); + Assert.AreEqual(expectedItem.TailorMadeAssessmentResult, actualItem.TailorMadeAssessmentResult); + Assert.AreEqual(expectedItem.TailorMadeAssessmentProbability, actualItem.TailorMadeAssessmentProbability, 1e-6); + Assert.AreEqual(expectedItem.UseManualAssembly, actualItem.UseManualAssembly); + Assert.AreEqual(expectedItem.ManualAssemblyProbability, actualItem.ManualAssemblyProbability, 1e-6); + }); + } + + private static void AssertMacroStabilityInwardsProbabilityAssessmentInput(MacroStabilityInwardsProbabilityAssessmentInput expectedModel, + MacroStabilityInwardsProbabilityAssessmentInput actualModel) + { + Assert.AreEqual(expectedModel.A, actualModel.A); + } + + private static void AssertMacroStabilityInwardsStochasticSoilModels(MacroStabilityInwardsStochasticSoilModelCollection expectedModels, + MacroStabilityInwardsStochasticSoilModelCollection actualModels) + { + Assert.AreEqual(expectedModels.SourcePath, actualModels.SourcePath); + AssertCollectionAndItems(expectedModels, actualModels, AssertMacroStabilityInwardsStochasticSoilModel); + } + + private static void AssertMacroStabilityInwardsStochasticSoilModel(MacroStabilityInwardsStochasticSoilModel expectedSoilModel, + MacroStabilityInwardsStochasticSoilModel actualSoilModel) + { + Assert.AreEqual(expectedSoilModel.Name, actualSoilModel.Name); + AssertSegmentPoints(expectedSoilModel.Geometry, actualSoilModel.Geometry); + AssertCollectionAndItems(expectedSoilModel.StochasticSoilProfiles, + actualSoilModel.StochasticSoilProfiles, + AssertMacroStabilityInwardsStochasticSoilProfile); + } + + private static void AssertMacroStabilityInwardsStochasticSoilProfile(MacroStabilityInwardsStochasticSoilProfile expectedProfile, + MacroStabilityInwardsStochasticSoilProfile actualProfile) + { + Assert.AreEqual(expectedProfile.Probability, actualProfile.Probability); + + var expectedSoilProfile1D = expectedProfile.SoilProfile as MacroStabilityInwardsSoilProfile1D; + if (expectedSoilProfile1D != null) + { + var actualSoilProfile1D = actualProfile.SoilProfile as MacroStabilityInwardsSoilProfile1D; + Assert.IsNotNull(actualSoilProfile1D); + AssertMacroStabilityInwardsSoilProfile(expectedSoilProfile1D, actualSoilProfile1D); + } + + var expectedSoilProfile2D = expectedProfile.SoilProfile as MacroStabilityInwardsSoilProfile2D; + if (expectedSoilProfile2D != null) + { + var actualSoilProfile2D = actualProfile.SoilProfile as MacroStabilityInwardsSoilProfile2D; + Assert.IsNotNull(actualSoilProfile2D); + AssertMacroStabilityInwardsSoilProfile(expectedSoilProfile2D, actualSoilProfile2D); + } + } + + private static void AssertMacroStabilityInwardsSoilProfile(MacroStabilityInwardsSoilProfile1D expectedSoilProfile, + MacroStabilityInwardsSoilProfile1D actualSoilProfile) + { + Assert.AreEqual(expectedSoilProfile.Bottom, actualSoilProfile.Bottom); + Assert.AreEqual(expectedSoilProfile.Name, actualSoilProfile.Name); + AssertCollectionAndItems(expectedSoilProfile.Layers, + actualSoilProfile.Layers, + AssertMacroStabilityInwardsSoilLayer); + } + + private static void AssertMacroStabilityInwardsSoilProfile(MacroStabilityInwardsSoilProfile2D expectedSoilProfile, + MacroStabilityInwardsSoilProfile2D actualSoilProfile) + { + Assert.AreEqual(expectedSoilProfile.Name, actualSoilProfile.Name); + AssertCollectionAndItems(expectedSoilProfile.Layers, + actualSoilProfile.Layers, + AssertMacroStabilityInwardsSoilLayer); + } + + private static void AssertMacroStabilityInwardsSoilLayer(MacroStabilityInwardsSoilLayer1D expectedLayer, + MacroStabilityInwardsSoilLayer1D actualLayer) + { + Assert.AreEqual(expectedLayer.Top, actualLayer.Top); + AssertMacroStabilityInwardsSoilLayerData(expectedLayer.Data, actualLayer.Data); + } + + private static void AssertMacroStabilityInwardsSoilLayer(MacroStabilityInwardsSoilLayer2D expectedLayer, + MacroStabilityInwardsSoilLayer2D actualLayer) + { + Assert.AreEqual(expectedLayer.OuterRing, actualLayer.OuterRing); + AssertMacroStabilityInwardsSoilLayerData(expectedLayer.Data, actualLayer.Data); + + AssertCollectionAndItems(expectedLayer.NestedLayers, actualLayer.NestedLayers, AssertMacroStabilityInwardsSoilLayer); + } + + private static void AssertMacroStabilityInwardsSoilLayerData(MacroStabilityInwardsSoilLayerData expectedData, + MacroStabilityInwardsSoilLayerData actualData) + { + Assert.AreEqual(expectedData.IsAquifer, actualData.IsAquifer); + Assert.AreEqual(expectedData.MaterialName, actualData.MaterialName); + Assert.AreEqual(expectedData.Color.ToArgb(), actualData.Color.ToArgb()); + Assert.AreEqual(expectedData.UsePop, actualData.UsePop); + Assert.AreEqual(expectedData.ShearStrengthModel, actualData.ShearStrengthModel); + DistributionAssert.AreEqual(expectedData.AbovePhreaticLevel, actualData.AbovePhreaticLevel); + DistributionAssert.AreEqual(expectedData.BelowPhreaticLevel, actualData.BelowPhreaticLevel); + DistributionAssert.AreEqual(expectedData.Cohesion, actualData.Cohesion); + DistributionAssert.AreEqual(expectedData.FrictionAngle, actualData.FrictionAngle); + DistributionAssert.AreEqual(expectedData.ShearStrengthRatio, actualData.ShearStrengthRatio); + DistributionAssert.AreEqual(expectedData.StrengthIncreaseExponent, actualData.StrengthIncreaseExponent); + DistributionAssert.AreEqual(expectedData.Pop, actualData.Pop); + } + + private static void AssertMacroStabilityInwardsSurfaceLine(MacroStabilityInwardsSurfaceLine expectedSurfaceLine, + MacroStabilityInwardsSurfaceLine actualSurfaceLine) + { + Assert.AreEqual(expectedSurfaceLine.Name, actualSurfaceLine.Name); + Assert.AreEqual(expectedSurfaceLine.ReferenceLineIntersectionWorldPoint, actualSurfaceLine.ReferenceLineIntersectionWorldPoint); + + CollectionAssert.AreEqual(expectedSurfaceLine.Points, actualSurfaceLine.Points); + + Assert.AreEqual(expectedSurfaceLine.SurfaceLevelOutside, actualSurfaceLine.SurfaceLevelOutside); + Assert.AreEqual(expectedSurfaceLine.DikeToeAtRiver, actualSurfaceLine.DikeToeAtRiver); + Assert.AreEqual(expectedSurfaceLine.DikeTopAtPolder, actualSurfaceLine.DikeTopAtPolder); + Assert.AreEqual(expectedSurfaceLine.DikeTopAtRiver, actualSurfaceLine.DikeTopAtRiver); + Assert.AreEqual(expectedSurfaceLine.ShoulderBaseInside, actualSurfaceLine.ShoulderBaseInside); + Assert.AreEqual(expectedSurfaceLine.ShoulderTopInside, actualSurfaceLine.ShoulderTopInside); + Assert.AreEqual(expectedSurfaceLine.DikeToeAtPolder, actualSurfaceLine.DikeToeAtPolder); + Assert.AreEqual(expectedSurfaceLine.DitchDikeSide, actualSurfaceLine.DitchDikeSide); + Assert.AreEqual(expectedSurfaceLine.BottomDitchDikeSide, actualSurfaceLine.BottomDitchDikeSide); + Assert.AreEqual(expectedSurfaceLine.BottomDitchPolderSide, actualSurfaceLine.BottomDitchPolderSide); + Assert.AreEqual(expectedSurfaceLine.DitchPolderSide, actualSurfaceLine.DitchPolderSide); + Assert.AreEqual(expectedSurfaceLine.SurfaceLevelInside, actualSurfaceLine.SurfaceLevelInside); + } + + private static void AssertMacroStabilityInwardsCalculationScenario(MacroStabilityInwardsCalculationScenario expectedMacroStabilityInwardsCalculation, + MacroStabilityInwardsCalculationScenario actualMacroStabilityInwardsCalculation) + { + Assert.AreEqual(expectedMacroStabilityInwardsCalculation.IsRelevant, actualMacroStabilityInwardsCalculation.IsRelevant); + Assert.AreEqual(expectedMacroStabilityInwardsCalculation.Contribution, actualMacroStabilityInwardsCalculation.Contribution); + Assert.AreEqual(expectedMacroStabilityInwardsCalculation.Name, actualMacroStabilityInwardsCalculation.Name); + AssertComments(expectedMacroStabilityInwardsCalculation.Comments, actualMacroStabilityInwardsCalculation.Comments); + + AssertMacroStabilityInwardsInput(expectedMacroStabilityInwardsCalculation.InputParameters, + actualMacroStabilityInwardsCalculation.InputParameters); + + AssertMacroStabilityInwardsOutput(expectedMacroStabilityInwardsCalculation.Output, + actualMacroStabilityInwardsCalculation.Output); + } + + private static void AssertMacroStabilityInwardsInput(MacroStabilityInwardsInput expectedInput, MacroStabilityInwardsInput actualInput) + { + AssertReferencedObject(() => expectedInput.HydraulicBoundaryLocation, + () => actualInput.HydraulicBoundaryLocation, + AssertHydraulicBoundaryLocation); + + AssertReferencedObject(() => expectedInput.SurfaceLine, + () => actualInput.SurfaceLine, + AssertMacroStabilityInwardsSurfaceLine); + AssertReferencedObject(() => expectedInput.StochasticSoilModel, + () => actualInput.StochasticSoilModel, + AssertMacroStabilityInwardsStochasticSoilModel); + AssertReferencedObject(() => expectedInput.StochasticSoilProfile, + () => actualInput.StochasticSoilProfile, + AssertMacroStabilityInwardsStochasticSoilProfile); + + Assert.AreEqual(expectedInput.AssessmentLevel, actualInput.AssessmentLevel); + Assert.AreEqual(expectedInput.UseAssessmentLevelManualInput, actualInput.UseAssessmentLevelManualInput); + Assert.AreEqual(expectedInput.SlipPlaneMinimumDepth, actualInput.SlipPlaneMinimumDepth); + Assert.AreEqual(expectedInput.SlipPlaneMinimumLength, actualInput.SlipPlaneMinimumLength); + Assert.AreEqual(expectedInput.MaximumSliceWidth, actualInput.MaximumSliceWidth); + Assert.AreEqual(expectedInput.MoveGrid, actualInput.MoveGrid); + Assert.AreEqual(expectedInput.DikeSoilScenario, actualInput.DikeSoilScenario); + Assert.AreEqual(expectedInput.WaterLevelRiverAverage, actualInput.WaterLevelRiverAverage); + Assert.AreEqual(expectedInput.DrainageConstructionPresent, actualInput.DrainageConstructionPresent); + Assert.AreEqual(expectedInput.XCoordinateDrainageConstruction, actualInput.XCoordinateDrainageConstruction); + Assert.AreEqual(expectedInput.ZCoordinateDrainageConstruction, actualInput.ZCoordinateDrainageConstruction); + Assert.AreEqual(expectedInput.MinimumLevelPhreaticLineAtDikeTopRiver, actualInput.MinimumLevelPhreaticLineAtDikeTopRiver); + Assert.AreEqual(expectedInput.MinimumLevelPhreaticLineAtDikeTopPolder, actualInput.MinimumLevelPhreaticLineAtDikeTopPolder); + + AsssertMacroStabilityInwardsLocationInputBase(expectedInput.LocationInputDaily, actualInput.LocationInputDaily); + AssertMacroStabilityInwardsLocationInput(expectedInput.LocationInputExtreme, actualInput.LocationInputExtreme); + + Assert.AreEqual(expectedInput.AdjustPhreaticLine3And4ForUplift, actualInput.AdjustPhreaticLine3And4ForUplift); + Assert.AreEqual(expectedInput.LeakageLengthOutwardsPhreaticLine3, actualInput.LeakageLengthOutwardsPhreaticLine3); + Assert.AreEqual(expectedInput.LeakageLengthInwardsPhreaticLine3, actualInput.LeakageLengthInwardsPhreaticLine3); + Assert.AreEqual(expectedInput.LeakageLengthOutwardsPhreaticLine4, actualInput.LeakageLengthOutwardsPhreaticLine4); + Assert.AreEqual(expectedInput.LeakageLengthInwardsPhreaticLine4, actualInput.LeakageLengthInwardsPhreaticLine4); + Assert.AreEqual(expectedInput.PiezometricHeadPhreaticLine2Outwards, actualInput.PiezometricHeadPhreaticLine2Outwards); + Assert.AreEqual(expectedInput.PiezometricHeadPhreaticLine2Inwards, actualInput.PiezometricHeadPhreaticLine2Inwards); + + Assert.AreEqual(expectedInput.GridDeterminationType, actualInput.GridDeterminationType); + Assert.AreEqual(expectedInput.TangentLineDeterminationType, actualInput.TangentLineDeterminationType); + + Assert.AreEqual(expectedInput.TangentLineZTop, actualInput.TangentLineZTop); + Assert.AreEqual(expectedInput.TangentLineZBottom, actualInput.TangentLineZBottom); + Assert.AreEqual(expectedInput.TangentLineNumber, actualInput.TangentLineNumber); + + AssertMacroStabilityInwardsGrid(expectedInput.LeftGrid, actualInput.LeftGrid); + AssertMacroStabilityInwardsGrid(expectedInput.RightGrid, actualInput.RightGrid); + + Assert.AreEqual(expectedInput.CreateZones, actualInput.CreateZones); + } + + private static void AssertMacroStabilityInwardsGrid(MacroStabilityInwardsGrid expectedGrid, MacroStabilityInwardsGrid actualGrid) + { + Assert.AreEqual(expectedGrid.XLeft, actualGrid.XLeft); + Assert.AreEqual(expectedGrid.XRight, actualGrid.XRight); + Assert.AreEqual(expectedGrid.NumberOfHorizontalPoints, actualGrid.NumberOfHorizontalPoints); + + Assert.AreEqual(expectedGrid.ZTop, actualGrid.ZTop); + Assert.AreEqual(expectedGrid.ZBottom, actualGrid.ZBottom); + Assert.AreEqual(expectedGrid.NumberOfVerticalPoints, actualGrid.NumberOfVerticalPoints); + } + + private static void AsssertMacroStabilityInwardsLocationInputBase(IMacroStabilityInwardsLocationInput expectedLocationInput, + IMacroStabilityInwardsLocationInput actuaLocationInput) + { + Assert.AreEqual(expectedLocationInput.WaterLevelPolder, actuaLocationInput.WaterLevelPolder); + Assert.AreEqual(expectedLocationInput.UseDefaultOffsets, actuaLocationInput.UseDefaultOffsets); + Assert.AreEqual(expectedLocationInput.PhreaticLineOffsetBelowDikeTopAtRiver, actuaLocationInput.PhreaticLineOffsetBelowDikeTopAtRiver); + Assert.AreEqual(expectedLocationInput.PhreaticLineOffsetBelowDikeTopAtPolder, actuaLocationInput.PhreaticLineOffsetBelowDikeTopAtPolder); + Assert.AreEqual(expectedLocationInput.PhreaticLineOffsetBelowShoulderBaseInside, actuaLocationInput.PhreaticLineOffsetBelowShoulderBaseInside); + Assert.AreEqual(expectedLocationInput.PhreaticLineOffsetBelowDikeToeAtPolder, actuaLocationInput.PhreaticLineOffsetBelowDikeToeAtPolder); + } + + private static void AssertMacroStabilityInwardsLocationInput(IMacroStabilityInwardsLocationInputExtreme expectedLocationInput, + IMacroStabilityInwardsLocationInputExtreme actualLocationInput) + { + AsssertMacroStabilityInwardsLocationInputBase(expectedLocationInput, actualLocationInput); + Assert.AreEqual(expectedLocationInput.PenetrationLength, actualLocationInput.PenetrationLength); + } + + private static void AssertMacroStabilityInwardsOutput(MacroStabilityInwardsOutput expectedOutput, + MacroStabilityInwardsOutput actualOutput) + { + if (expectedOutput == null) + { + Assert.IsNull(actualOutput); + } + else + { + Assert.AreEqual(expectedOutput.FactorOfStability, actualOutput.FactorOfStability); + Assert.AreEqual(expectedOutput.ZValue, actualOutput.ZValue); + Assert.AreEqual(expectedOutput.ForbiddenZonesXEntryMin, actualOutput.ForbiddenZonesXEntryMin); + Assert.AreEqual(expectedOutput.ForbiddenZonesXEntryMax, actualOutput.ForbiddenZonesXEntryMax); + + AssertMacroStabilityInwardsSlidingCurve(expectedOutput.SlidingCurve, actualOutput.SlidingCurve); + AssertMacroStabilityInwardsSlipPlaneUpliftVan(expectedOutput.SlipPlane, actualOutput.SlipPlane); + } + } + + private static void AssertMacroStabilityInwardsSlipPlaneUpliftVan(MacroStabilityInwardsSlipPlaneUpliftVan expectedSlipPlane, + MacroStabilityInwardsSlipPlaneUpliftVan actualSlipPlane) + { + AssertMacroStabilityInwardsGrid(expectedSlipPlane.LeftGrid, actualSlipPlane.LeftGrid); + AssertMacroStabilityInwardsGrid(expectedSlipPlane.RightGrid, actualSlipPlane.RightGrid); + CollectionAssert.AreEqual(expectedSlipPlane.TangentLines, actualSlipPlane.TangentLines); + } + + private static void AssertMacroStabilityInwardsSlidingCurve(MacroStabilityInwardsSlidingCurve expectedCurve, + MacroStabilityInwardsSlidingCurve actualCurve) + { + Assert.AreEqual(expectedCurve.NonIteratedHorizontalForce, actualCurve.NonIteratedHorizontalForce); + Assert.AreEqual(expectedCurve.IteratedHorizontalForce, actualCurve.IteratedHorizontalForce); + + AssertMacroStabilityInwardsSlidingCircle(expectedCurve.LeftCircle, actualCurve.LeftCircle); + AssertMacroStabilityInwardsSlidingCircle(expectedCurve.RightCircle, actualCurve.RightCircle); + + AssertCollectionAndItems(expectedCurve.Slices, actualCurve.Slices, AssertMacroStabilityInwardsSlice); + } + + private static void AssertMacroStabilityInwardsSlidingCircle(MacroStabilityInwardsSlidingCircle expectedCircle, + MacroStabilityInwardsSlidingCircle actualCircle) + { + Assert.AreEqual(expectedCircle.Center, actualCircle.Center); + Assert.AreEqual(expectedCircle.Radius, actualCircle.Radius); + Assert.AreEqual(expectedCircle.IsActive, actualCircle.IsActive); + Assert.AreEqual(expectedCircle.NonIteratedForce, actualCircle.NonIteratedForce); + Assert.AreEqual(expectedCircle.IteratedForce, actualCircle.IteratedForce); + Assert.AreEqual(expectedCircle.DrivingMoment, actualCircle.DrivingMoment); + Assert.AreEqual(expectedCircle.ResistingMoment, actualCircle.ResistingMoment); + } + + private static void AssertMacroStabilityInwardsSlice(MacroStabilityInwardsSlice expectedSlice, + MacroStabilityInwardsSlice actualSlice) + { + Assert.AreEqual(expectedSlice.TopLeftPoint, actualSlice.TopLeftPoint); + Assert.AreEqual(expectedSlice.TopRightPoint, actualSlice.TopRightPoint); + Assert.AreEqual(expectedSlice.BottomLeftPoint, actualSlice.BottomLeftPoint); + Assert.AreEqual(expectedSlice.BottomRightPoint, actualSlice.BottomRightPoint); + + Assert.AreEqual(expectedSlice.Cohesion, actualSlice.Cohesion); + Assert.AreEqual(expectedSlice.FrictionAngle, actualSlice.FrictionAngle); + Assert.AreEqual(expectedSlice.CriticalPressure, actualSlice.CriticalPressure); + Assert.AreEqual(expectedSlice.OverConsolidationRatio, actualSlice.OverConsolidationRatio); + Assert.AreEqual(expectedSlice.Pop, actualSlice.Pop); + Assert.AreEqual(expectedSlice.DegreeOfConsolidationPorePressureSoil, actualSlice.DegreeOfConsolidationPorePressureSoil); + Assert.AreEqual(expectedSlice.DegreeOfConsolidationPorePressureLoad, actualSlice.DegreeOfConsolidationPorePressureLoad); + Assert.AreEqual(expectedSlice.Dilatancy, actualSlice.Dilatancy); + Assert.AreEqual(expectedSlice.ExternalLoad, actualSlice.ExternalLoad); + Assert.AreEqual(expectedSlice.HydrostaticPorePressure, actualSlice.HydrostaticPorePressure); + Assert.AreEqual(expectedSlice.LeftForce, actualSlice.LeftForce); + Assert.AreEqual(expectedSlice.LeftForceAngle, actualSlice.LeftForceAngle); + Assert.AreEqual(expectedSlice.LeftForceY, actualSlice.LeftForceY); + Assert.AreEqual(expectedSlice.RightForce, actualSlice.RightForce); + Assert.AreEqual(expectedSlice.RightForceAngle, actualSlice.RightForceAngle); + Assert.AreEqual(expectedSlice.RightForceY, actualSlice.RightForceY); + Assert.AreEqual(expectedSlice.LoadStress, actualSlice.LoadStress); + Assert.AreEqual(expectedSlice.NormalStress, actualSlice.NormalStress); + Assert.AreEqual(expectedSlice.PorePressure, actualSlice.PorePressure); + Assert.AreEqual(expectedSlice.HorizontalPorePressure, actualSlice.HorizontalPorePressure); + Assert.AreEqual(expectedSlice.VerticalPorePressure, actualSlice.VerticalPorePressure); + Assert.AreEqual(expectedSlice.PiezometricPorePressure, actualSlice.PiezometricPorePressure); + Assert.AreEqual(expectedSlice.EffectiveStress, actualSlice.EffectiveStress); + Assert.AreEqual(expectedSlice.EffectiveStressDaily, actualSlice.EffectiveStressDaily); + Assert.AreEqual(expectedSlice.ExcessPorePressure, actualSlice.ExcessPorePressure); + Assert.AreEqual(expectedSlice.ShearStress, actualSlice.ShearStress); + Assert.AreEqual(expectedSlice.SoilStress, actualSlice.SoilStress); + Assert.AreEqual(expectedSlice.TotalPorePressure, actualSlice.TotalPorePressure); + Assert.AreEqual(expectedSlice.TotalStress, actualSlice.TotalStress); + Assert.AreEqual(expectedSlice.Weight, actualSlice.Weight); + } + + #endregion + + #region GrassCoverErosionInwards FailureMechanism + + private static void AssertGrassCoverErosionInwardsFailureMechanism(GrassCoverErosionInwardsFailureMechanism expectedFailureMechanism, + GrassCoverErosionInwardsFailureMechanism actualFailureMechanism) + { + Assert.AreEqual(expectedFailureMechanism.GeneralInput.N, actualFailureMechanism.GeneralInput.N); + AssertDikeProfiles(expectedFailureMechanism.DikeProfiles, actualFailureMechanism.DikeProfiles); + AssertCalculationGroup(expectedFailureMechanism.CalculationsGroup, actualFailureMechanism.CalculationsGroup); + } + + private static void AssertFailureMechanismSectionResults( + IEnumerable expectedSectionResults, + IEnumerable actualSectionResults) + { + AssertCollectionAndItems(expectedSectionResults, + actualSectionResults, + (expectedItem, actualItem) => + { + Assert.AreEqual(expectedItem.SimpleAssessmentResult, actualItem.SimpleAssessmentResult); + Assert.AreEqual(expectedItem.DetailedAssessmentResult, actualItem.DetailedAssessmentResult); + Assert.AreEqual(expectedItem.TailorMadeAssessmentResult, actualItem.TailorMadeAssessmentResult); + Assert.AreEqual(expectedItem.TailorMadeAssessmentProbability, actualItem.TailorMadeAssessmentProbability, 1e-6); + Assert.AreEqual(expectedItem.UseManualAssembly, actualItem.UseManualAssembly); + Assert.AreEqual(expectedItem.ManualAssemblyProbability, actualItem.ManualAssemblyProbability, 1e-6); + + if (expectedItem.Calculation == null) + { + Assert.IsNull(expectedItem.Calculation); + } + else + { + AssertGrassCoverErosionInwardsCalculation(expectedItem.Calculation, actualItem.Calculation); + } + }); + } + + private static void AssertGrassCoverErosionInwardsCalculation(GrassCoverErosionInwardsCalculation expectedCalculation, + GrassCoverErosionInwardsCalculation actualCalculation) + { + Assert.AreEqual(expectedCalculation.Name, actualCalculation.Name); + AssertComments(expectedCalculation.Comments, actualCalculation.Comments); + + AssertGrassCoverErosionInwardsInput(expectedCalculation.InputParameters, actualCalculation.InputParameters); + + if (expectedCalculation.HasOutput) + { + AssertGrassCoverErosionInwardsOutput(expectedCalculation.Output, actualCalculation.Output); + } + else + { + Assert.IsFalse(actualCalculation.HasOutput); + } + } + + private static void AssertGrassCoverErosionInwardsInput(GrassCoverErosionInwardsInput expectedInput, + GrassCoverErosionInwardsInput actualInput) + { + AssertReferencedObject(() => expectedInput.DikeProfile, + () => actualInput.DikeProfile, + AssertDikeProfile); + AssertReferencedObject(() => expectedInput.HydraulicBoundaryLocation, + () => actualInput.HydraulicBoundaryLocation, + AssertHydraulicBoundaryLocation); + + AssertBreakWater(expectedInput.BreakWater, actualInput.BreakWater); + Assert.AreEqual(expectedInput.Orientation, actualInput.Orientation); + Assert.AreEqual(expectedInput.UseBreakWater, actualInput.UseBreakWater); + Assert.AreEqual(expectedInput.UseForeshore, actualInput.UseForeshore); + Assert.AreEqual(expectedInput.DikeHeight, actualInput.DikeHeight); + Assert.AreEqual(expectedInput.CriticalFlowRate.Mean, actualInput.CriticalFlowRate.Mean); + Assert.AreEqual(expectedInput.CriticalFlowRate.StandardDeviation, actualInput.CriticalFlowRate.StandardDeviation); + Assert.AreEqual(expectedInput.DikeHeightCalculationType, actualInput.DikeHeightCalculationType); + Assert.AreEqual(expectedInput.OvertoppingRateCalculationType, actualInput.OvertoppingRateCalculationType); + } + + private static void AssertGrassCoverErosionInwardsOutput(GrassCoverErosionInwardsOutput expectedOutput, + GrassCoverErosionInwardsOutput actualOutput) + { + AssertOvertoppingOutput(expectedOutput.OvertoppingOutput, actualOutput.OvertoppingOutput); + AssertDikeHeightOutput(expectedOutput.DikeHeightOutput, actualOutput.DikeHeightOutput); + AssertOvertoppingRateOutput(expectedOutput.OvertoppingRateOutput, actualOutput.OvertoppingRateOutput); + } + + private static void AssertOvertoppingOutput(OvertoppingOutput expectedOutput, + OvertoppingOutput actualOutput) + { + Assert.AreEqual(expectedOutput.WaveHeight, actualOutput.WaveHeight); + Assert.AreEqual(expectedOutput.IsOvertoppingDominant, actualOutput.IsOvertoppingDominant); + Assert.AreEqual(expectedOutput.Reliability, actualOutput.Reliability); + + AssertGeneralResultTopLevelFaultTreeIllustrationPoint(expectedOutput.GeneralResult, actualOutput.GeneralResult); + } + + private static void AssertDikeHeightOutput(DikeHeightOutput expectedOutput, + DikeHeightOutput actualOutput) + { + AssertHydraulicLoadsOutput(expectedOutput, actualOutput); + + Assert.AreEqual(expectedOutput.DikeHeight, actualOutput.DikeHeight); + } + + private static void AssertOvertoppingRateOutput(OvertoppingRateOutput expectedOutput, + OvertoppingRateOutput actualOutput) + { + AssertHydraulicLoadsOutput(expectedOutput, actualOutput); + + Assert.AreEqual(expectedOutput.OvertoppingRate, actualOutput.OvertoppingRate); + } + + private static void AssertHydraulicLoadsOutput(HydraulicLoadsOutput expectedOutput, + HydraulicLoadsOutput actualOutput) + { + if (expectedOutput == null) + { + Assert.IsNull(actualOutput); + return; + } + + Assert.AreEqual(expectedOutput.TargetProbability, actualOutput.TargetProbability); + Assert.AreEqual(expectedOutput.TargetReliability, actualOutput.TargetReliability); + Assert.AreEqual(expectedOutput.CalculatedProbability, actualOutput.CalculatedProbability); + Assert.AreEqual(expectedOutput.CalculatedReliability, actualOutput.CalculatedReliability); + AssertGeneralResultTopLevelFaultTreeIllustrationPoint(expectedOutput.GeneralResult, actualOutput.GeneralResult); + } + + #endregion + + #region GrassCoverErosionOutwards FailureMechanism + + private static void AssertGrassCoverErosionOutwardsFailureMechanism(GrassCoverErosionOutwardsFailureMechanism expectedFailureMechanism, + GrassCoverErosionOutwardsFailureMechanism actualFailureMechanism) + { + Assert.AreEqual(expectedFailureMechanism.GeneralInput.N, actualFailureMechanism.GeneralInput.N); + AssertForeshoreProfiles(expectedFailureMechanism.ForeshoreProfiles, actualFailureMechanism.ForeshoreProfiles); + AssertHydraulicBoundaryLocationCalculations(expectedFailureMechanism, actualFailureMechanism); + AssertCalculationGroup(expectedFailureMechanism.WaveConditionsCalculationGroup, actualFailureMechanism.WaveConditionsCalculationGroup); + } + + private static void AssertHydraulicBoundaryLocationCalculations(GrassCoverErosionOutwardsFailureMechanism expected, + GrassCoverErosionOutwardsFailureMechanism actual) + { + AssertHydraulicBoundaryLocationCalculations(expected.WaterLevelCalculationsForMechanismSpecificFactorizedSignalingNorm, + actual.WaterLevelCalculationsForMechanismSpecificFactorizedSignalingNorm); + AssertHydraulicBoundaryLocationCalculations(expected.WaterLevelCalculationsForMechanismSpecificSignalingNorm, + actual.WaterLevelCalculationsForMechanismSpecificSignalingNorm); + AssertHydraulicBoundaryLocationCalculations(expected.WaterLevelCalculationsForMechanismSpecificLowerLimitNorm, + actual.WaterLevelCalculationsForMechanismSpecificLowerLimitNorm); + + AssertHydraulicBoundaryLocationCalculations(expected.WaveHeightCalculationsForMechanismSpecificFactorizedSignalingNorm, + actual.WaveHeightCalculationsForMechanismSpecificFactorizedSignalingNorm); + AssertHydraulicBoundaryLocationCalculations(expected.WaveHeightCalculationsForMechanismSpecificSignalingNorm, + actual.WaveHeightCalculationsForMechanismSpecificSignalingNorm); + AssertHydraulicBoundaryLocationCalculations(expected.WaveHeightCalculationsForMechanismSpecificLowerLimitNorm, + actual.WaveHeightCalculationsForMechanismSpecificLowerLimitNorm); + } + + private static void AssertFailureMechanismSectionResults(IEnumerable expectedSectionResults, + IEnumerable actualSectionResults) + { + AssertCollectionAndItems(expectedSectionResults, + actualSectionResults, + (expectedItem, actualItem) => + { + Assert.AreEqual(expectedItem.SimpleAssessmentResult, actualItem.SimpleAssessmentResult); + Assert.AreEqual(expectedItem.DetailedAssessmentResultForFactorizedSignalingNorm, actualItem.DetailedAssessmentResultForFactorizedSignalingNorm); + Assert.AreEqual(expectedItem.DetailedAssessmentResultForSignalingNorm, actualItem.DetailedAssessmentResultForSignalingNorm); + Assert.AreEqual(expectedItem.DetailedAssessmentResultForMechanismSpecificLowerLimitNorm, actualItem.DetailedAssessmentResultForMechanismSpecificLowerLimitNorm); + Assert.AreEqual(expectedItem.DetailedAssessmentResultForLowerLimitNorm, actualItem.DetailedAssessmentResultForLowerLimitNorm); + Assert.AreEqual(expectedItem.DetailedAssessmentResultForFactorizedLowerLimitNorm, actualItem.DetailedAssessmentResultForFactorizedLowerLimitNorm); + Assert.AreEqual(expectedItem.TailorMadeAssessmentResult, actualItem.TailorMadeAssessmentResult); + Assert.AreEqual(expectedItem.UseManualAssembly, actualItem.UseManualAssembly); + Assert.AreEqual(expectedItem.ManualAssemblyCategoryGroup, actualItem.ManualAssemblyCategoryGroup); + }); + } + + private static void AssertGrassCoverErosionOutwardsWaveConditionsCalculation(GrassCoverErosionOutwardsWaveConditionsCalculation expectedCalculation, + GrassCoverErosionOutwardsWaveConditionsCalculation actualCalculation) + { + Assert.AreEqual(expectedCalculation.Name, actualCalculation.Name); + AssertComments(expectedCalculation.Comments, actualCalculation.Comments); + + AssertWaveConditionsInput(expectedCalculation.InputParameters, actualCalculation.InputParameters); + + if (expectedCalculation.HasOutput) + { + AssertWaveConditionsOutputs(expectedCalculation.Output.Items.ToArray(), actualCalculation.Output.Items.ToArray()); + } + else + { + Assert.IsFalse(actualCalculation.HasOutput); + } + } + + #endregion + + #region StabilityStoneCover FailureMechanism + + private static void AssertStabilityStoneCoverFailureMechanism(StabilityStoneCoverFailureMechanism expectedFailureMechanism, + StabilityStoneCoverFailureMechanism actualFailureMechanism) + { + Assert.AreEqual(expectedFailureMechanism.GeneralInput.N, actualFailureMechanism.GeneralInput.N); + + AssertForeshoreProfiles(expectedFailureMechanism.ForeshoreProfiles, actualFailureMechanism.ForeshoreProfiles); + AssertCalculationGroup(expectedFailureMechanism.WaveConditionsCalculationGroup, actualFailureMechanism.WaveConditionsCalculationGroup); + } + + private static void AssertFailureMechanismSectionResults(IEnumerable expectedSectionResults, + IEnumerable actualSectionResults) + { + AssertCollectionAndItems(expectedSectionResults, + actualSectionResults, + (expectedItem, actualItem) => + { + Assert.AreEqual(expectedItem.SimpleAssessmentResult, actualItem.SimpleAssessmentResult); + Assert.AreEqual(expectedItem.DetailedAssessmentResultForFactorizedSignalingNorm, actualItem.DetailedAssessmentResultForFactorizedSignalingNorm); + Assert.AreEqual(expectedItem.DetailedAssessmentResultForSignalingNorm, actualItem.DetailedAssessmentResultForSignalingNorm); + Assert.AreEqual(expectedItem.DetailedAssessmentResultForMechanismSpecificLowerLimitNorm, actualItem.DetailedAssessmentResultForMechanismSpecificLowerLimitNorm); + Assert.AreEqual(expectedItem.DetailedAssessmentResultForLowerLimitNorm, actualItem.DetailedAssessmentResultForLowerLimitNorm); + Assert.AreEqual(expectedItem.DetailedAssessmentResultForFactorizedLowerLimitNorm, actualItem.DetailedAssessmentResultForFactorizedLowerLimitNorm); + Assert.AreEqual(expectedItem.TailorMadeAssessmentResult, actualItem.TailorMadeAssessmentResult); + Assert.AreEqual(expectedItem.UseManualAssembly, actualItem.UseManualAssembly); + Assert.AreEqual(expectedItem.ManualAssemblyCategoryGroup, actualItem.ManualAssemblyCategoryGroup); + }); + } + + private static void AssertStabilityStoneCoverWaveConditionsCalculation(StabilityStoneCoverWaveConditionsCalculation expectedCalculation, + StabilityStoneCoverWaveConditionsCalculation actualCalculation) + { + Assert.AreEqual(expectedCalculation.Name, actualCalculation.Name); + AssertComments(expectedCalculation.Comments, actualCalculation.Comments); + + AssertWaveConditionsInput(expectedCalculation.InputParameters, actualCalculation.InputParameters); + + if (expectedCalculation.HasOutput) + { + AssertWaveConditionsOutputs(expectedCalculation.Output.BlocksOutput.ToArray(), actualCalculation.Output.BlocksOutput.ToArray()); + AssertWaveConditionsOutputs(expectedCalculation.Output.ColumnsOutput.ToArray(), actualCalculation.Output.ColumnsOutput.ToArray()); + } + else + { + Assert.IsFalse(actualCalculation.HasOutput); + } + } + + #endregion + + #region WaveImpactAsphaltCover FailureMechanism + + private static void AssertWaveImpactAsphaltCoverFailureMechanism(WaveImpactAsphaltCoverFailureMechanism expectedFailureMechanism, + WaveImpactAsphaltCoverFailureMechanism actualFailureMechanism) + { + Assert.AreEqual(expectedFailureMechanism.GeneralWaveImpactAsphaltCoverInput.DeltaL, actualFailureMechanism.GeneralWaveImpactAsphaltCoverInput.DeltaL); + + AssertForeshoreProfiles(expectedFailureMechanism.ForeshoreProfiles, actualFailureMechanism.ForeshoreProfiles); + AssertCalculationGroup(expectedFailureMechanism.WaveConditionsCalculationGroup, actualFailureMechanism.WaveConditionsCalculationGroup); + } + + private static void AssertFailureMechanismSectionResults(IEnumerable expectedSectionResults, + IEnumerable actualSectionResults) + { + AssertCollectionAndItems(expectedSectionResults, actualSectionResults, (expectedItem, actualItem) => + { + Assert.AreEqual(expectedItem.SimpleAssessmentResult, actualItem.SimpleAssessmentResult); + Assert.AreEqual(expectedItem.DetailedAssessmentResultForFactorizedSignalingNorm, actualItem.DetailedAssessmentResultForFactorizedSignalingNorm); + Assert.AreEqual(expectedItem.DetailedAssessmentResultForSignalingNorm, actualItem.DetailedAssessmentResultForSignalingNorm); + Assert.AreEqual(expectedItem.DetailedAssessmentResultForMechanismSpecificLowerLimitNorm, actualItem.DetailedAssessmentResultForMechanismSpecificLowerLimitNorm); + Assert.AreEqual(expectedItem.DetailedAssessmentResultForLowerLimitNorm, actualItem.DetailedAssessmentResultForLowerLimitNorm); + Assert.AreEqual(expectedItem.DetailedAssessmentResultForFactorizedLowerLimitNorm, actualItem.DetailedAssessmentResultForFactorizedLowerLimitNorm); + Assert.AreEqual(expectedItem.TailorMadeAssessmentResult, actualItem.TailorMadeAssessmentResult); + Assert.AreEqual(expectedItem.UseManualAssembly, actualItem.UseManualAssembly); + Assert.AreEqual(expectedItem.ManualAssemblyCategoryGroup, actualItem.ManualAssemblyCategoryGroup); + }); + } + + private static void AssertWaveImpactAsphaltCoverWaveConditionsCalculation(WaveImpactAsphaltCoverWaveConditionsCalculation expectedCalculation, + WaveImpactAsphaltCoverWaveConditionsCalculation actualCalculation) + { + Assert.AreEqual(expectedCalculation.Name, actualCalculation.Name); + AssertComments(expectedCalculation.Comments, actualCalculation.Comments); + + AssertWaveConditionsInput(expectedCalculation.InputParameters, actualCalculation.InputParameters); + + if (expectedCalculation.HasOutput) + { + AssertWaveConditionsOutputs(expectedCalculation.Output.Items.ToArray(), actualCalculation.Output.Items.ToArray()); + } + else + { + Assert.IsFalse(actualCalculation.HasOutput); + } + } + + #endregion + + #region PipingStructure FailureMechanism + + private static void AssertPipingStructureFailureMechanism(PipingStructureFailureMechanism expectedFailureMechanism, + PipingStructureFailureMechanism actualFailureMechanism) + { + Assert.AreEqual(expectedFailureMechanism.N, actualFailureMechanism.N); + } + + private static void AssertFailureMechanismSectionResults( + IEnumerable expectedSectionResults, + IEnumerable actualSectionResults) + { + AssertCollectionAndItems(expectedSectionResults, + actualSectionResults, + (expectedItem, actualItem) => + { + Assert.AreEqual(expectedItem.SimpleAssessmentResult, actualItem.SimpleAssessmentResult); + Assert.AreEqual(expectedItem.DetailedAssessmentResult, actualItem.DetailedAssessmentResult); + Assert.AreEqual(expectedItem.TailorMadeAssessmentResult, actualItem.TailorMadeAssessmentResult); + Assert.AreEqual(expectedItem.UseManualAssembly, actualItem.UseManualAssembly); + Assert.AreEqual(expectedItem.ManualAssemblyCategoryGroup, actualItem.ManualAssemblyCategoryGroup); + }); + } + + #endregion + + #region MacroStabilityOutwards FailureMechanism + + private static void AssertMacroStabilityOutwardsFailureMechanism(MacroStabilityOutwardsFailureMechanism expectedFailureMechanism, + MacroStabilityOutwardsFailureMechanism actualFailureMechanism) + { + Assert.AreEqual(expectedFailureMechanism.MacroStabilityOutwardsProbabilityAssessmentInput.A, actualFailureMechanism.MacroStabilityOutwardsProbabilityAssessmentInput.A); + } + + private static void AssertFailureMechanismSectionResults( + IEnumerable expectedSectionResults, + IEnumerable actualSectionResults) + { + AssertCollectionAndItems(expectedSectionResults, + actualSectionResults, + (expectedItem, actualItem) => + { + Assert.AreEqual(expectedItem.SimpleAssessmentResult, actualItem.SimpleAssessmentResult); + Assert.AreEqual(expectedItem.DetailedAssessmentResult, actualItem.DetailedAssessmentResult); + Assert.AreEqual(expectedItem.DetailedAssessmentProbability, actualItem.DetailedAssessmentProbability); + Assert.AreEqual(expectedItem.TailorMadeAssessmentResult, actualItem.TailorMadeAssessmentResult); + Assert.AreEqual(expectedItem.TailorMadeAssessmentProbability, actualItem.TailorMadeAssessmentProbability); + Assert.AreEqual(expectedItem.UseManualAssembly, actualItem.UseManualAssembly); + Assert.AreEqual(expectedItem.ManualAssemblyCategoryGroup, actualItem.ManualAssemblyCategoryGroup); + }); + } + + #endregion + + #region Hydraulic Boundary Database + + private static void AssertHydraulicBoundaryDatabase(HydraulicBoundaryDatabase expectedBoundaryDatabase, + HydraulicBoundaryDatabase actualBoundaryDatabase) + { + Assert.IsNotNull(expectedBoundaryDatabase); + Assert.AreEqual(expectedBoundaryDatabase.Version, actualBoundaryDatabase.Version); + Assert.AreEqual(expectedBoundaryDatabase.FilePath, actualBoundaryDatabase.FilePath); + + AssertHydraulicLocationConfigurationSettings(expectedBoundaryDatabase.HydraulicLocationConfigurationSettings, + actualBoundaryDatabase.HydraulicLocationConfigurationSettings); + + Assert.AreEqual(expectedBoundaryDatabase.Locations.Count, actualBoundaryDatabase.Locations.Count); + + AssertHydraulicBoundaryLocations(expectedBoundaryDatabase.Locations, actualBoundaryDatabase.Locations); + } + + private static void AssertHydraulicLocationConfigurationSettings(HydraulicLocationConfigurationSettings expectedSettings, + HydraulicLocationConfigurationSettings actualSettings) + { + Assert.AreEqual(expectedSettings.FilePath, actualSettings.FilePath); + Assert.AreEqual(expectedSettings.ScenarioName, actualSettings.ScenarioName); + Assert.AreEqual(expectedSettings.Year, actualSettings.Year); + Assert.AreEqual(expectedSettings.Scope, actualSettings.Scope); + Assert.AreEqual(expectedSettings.SeaLevel, actualSettings.SeaLevel); + Assert.AreEqual(expectedSettings.RiverDischarge, actualSettings.RiverDischarge); + Assert.AreEqual(expectedSettings.LakeLevel, actualSettings.LakeLevel); + Assert.AreEqual(expectedSettings.WindDirection, actualSettings.WindDirection); + Assert.AreEqual(expectedSettings.WindSpeed, actualSettings.WindSpeed); + Assert.AreEqual(expectedSettings.Comment, actualSettings.Comment); + } + + private static void AssertHydraulicBoundaryLocations(IEnumerable expectedHydraulicBoundaryLocations, + IEnumerable actualHydraulicBoundaryLocations) + { + AssertCollectionAndItems(expectedHydraulicBoundaryLocations, + actualHydraulicBoundaryLocations, + AssertHydraulicBoundaryLocation); + } + + private static void AssertHydraulicBoundaryLocation(HydraulicBoundaryLocation expectedBoundaryLocation, + HydraulicBoundaryLocation actualBoundaryLocation) + { + Assert.AreEqual(expectedBoundaryLocation.Id, actualBoundaryLocation.Id); + Assert.AreEqual(expectedBoundaryLocation.Name, actualBoundaryLocation.Name); + Assert.AreEqual(expectedBoundaryLocation.Location, actualBoundaryLocation.Location); + } + + #endregion + + #region Hydraulic Boundary Location Calculations + + private static void AssertHydraulicBoundaryLocationCalculations(AssessmentSection expected, + AssessmentSection actual) + { + AssertHydraulicBoundaryLocationCalculations(expected.WaterLevelCalculationsForFactorizedSignalingNorm, + actual.WaterLevelCalculationsForFactorizedSignalingNorm); + AssertHydraulicBoundaryLocationCalculations(expected.WaterLevelCalculationsForSignalingNorm, + actual.WaterLevelCalculationsForSignalingNorm); + AssertHydraulicBoundaryLocationCalculations(expected.WaterLevelCalculationsForLowerLimitNorm, + actual.WaterLevelCalculationsForLowerLimitNorm); + AssertHydraulicBoundaryLocationCalculations(expected.WaterLevelCalculationsForFactorizedLowerLimitNorm, + actual.WaterLevelCalculationsForFactorizedLowerLimitNorm); + + AssertHydraulicBoundaryLocationCalculations(expected.WaveHeightCalculationsForFactorizedSignalingNorm, + actual.WaveHeightCalculationsForFactorizedSignalingNorm); + AssertHydraulicBoundaryLocationCalculations(expected.WaveHeightCalculationsForSignalingNorm, + actual.WaveHeightCalculationsForSignalingNorm); + AssertHydraulicBoundaryLocationCalculations(expected.WaveHeightCalculationsForLowerLimitNorm, + actual.WaveHeightCalculationsForLowerLimitNorm); + AssertHydraulicBoundaryLocationCalculations(expected.WaveHeightCalculationsForFactorizedLowerLimitNorm, + actual.WaveHeightCalculationsForFactorizedLowerLimitNorm); + } + + private static void AssertHydraulicBoundaryLocationCalculations(IEnumerable expected, + IEnumerable actual) + { + AssertCollectionAndItems(expected, actual, + AssertHydraulicBoundaryLocationCalculation); + } + + private static void AssertHydraulicBoundaryLocationCalculation(HydraulicBoundaryLocationCalculation expected, HydraulicBoundaryLocationCalculation actual) + { + AssertHydraulicBoundaryLocation(expected.HydraulicBoundaryLocation, actual.HydraulicBoundaryLocation); + Assert.AreEqual(expected.InputParameters.ShouldIllustrationPointsBeCalculated, actual.InputParameters.ShouldIllustrationPointsBeCalculated); + AssertHydraulicBoundaryLocationCalculationOutput(expected.Output, actual.Output); + } + + private static void AssertHydraulicBoundaryLocationCalculationOutput(HydraulicBoundaryLocationCalculationOutput expectedOutput, + HydraulicBoundaryLocationCalculationOutput actualOutput) + { + if (expectedOutput == null) + { + Assert.IsNull(actualOutput); + return; + } + + Assert.AreEqual(expectedOutput.Result, actualOutput.Result); + Assert.AreEqual(expectedOutput.TargetProbability, actualOutput.TargetProbability); + Assert.AreEqual(expectedOutput.TargetReliability, actualOutput.TargetReliability); + Assert.AreEqual(expectedOutput.CalculatedProbability, actualOutput.CalculatedProbability); + Assert.AreEqual(expectedOutput.CalculatedReliability, actualOutput.CalculatedReliability); + Assert.AreEqual(expectedOutput.CalculationConvergence, actualOutput.CalculationConvergence); + + AssertGeneralResultTopLevelSubMechanismIllustrationPoint(expectedOutput.GeneralResult, + actualOutput.GeneralResult); + } + + #endregion + + #region IllustrationPoints + + private static void AssertGeneralResultTopLevelFaultTreeIllustrationPoint( + GeneralResult expected, + GeneralResult actual) + { + if (expected == null) + { + Assert.IsNull(actual); + return; + } + + AssertWindDirection(expected.GoverningWindDirection, + actual.GoverningWindDirection); + + AssertCollectionAndItems(expected.Stochasts, + actual.Stochasts, + AssertStochast); + + AssertCollectionAndItems(expected.TopLevelIllustrationPoints, + actual.TopLevelIllustrationPoints, + AssertTopLevelFaultTreeIllustrationPoint); + } + + private static void AssertTopLevelFaultTreeIllustrationPoint( + TopLevelFaultTreeIllustrationPoint expected, + TopLevelFaultTreeIllustrationPoint actual) + { + AssertWindDirection(expected.WindDirection, actual.WindDirection); + + Assert.AreEqual(expected.ClosingSituation, actual.ClosingSituation); + + AssertIllustrationPointNode(expected.FaultTreeNodeRoot, actual.FaultTreeNodeRoot); + } + + private static void AssertIllustrationPointNode(IllustrationPointNode expected, + IllustrationPointNode actual) + { + var expectedFaultTreeIllustrationPoint = expected.Data as FaultTreeIllustrationPoint; + if (expectedFaultTreeIllustrationPoint != null) + { + var actualFaultTreeIllustrationPoint = actual.Data as FaultTreeIllustrationPoint; + Assert.IsNotNull(actualFaultTreeIllustrationPoint); + + AssertFaultTreeIllustrationPoint(expectedFaultTreeIllustrationPoint, + actualFaultTreeIllustrationPoint); + + AssertCollectionAndItems(expected.Children, + actual.Children, + AssertIllustrationPointNode); + return; + } + + var expectedSubMechanismIllustrationPoint = expected.Data as SubMechanismIllustrationPoint; + if (expectedSubMechanismIllustrationPoint != null) + { + var actualSubMechanismIllustrationPoint = actual.Data as SubMechanismIllustrationPoint; + Assert.IsNotNull(actualSubMechanismIllustrationPoint); + + AssertSubMechanismIllustrationPoint(expectedSubMechanismIllustrationPoint, + actualSubMechanismIllustrationPoint); + return; + } + + Assert.Fail($"Expected data type {expected.Data.GetType()} is not supported."); + } + + private static void AssertFaultTreeIllustrationPoint(FaultTreeIllustrationPoint expected, + FaultTreeIllustrationPoint actual) + { + Assert.AreEqual(expected.Name, actual.Name); + Assert.AreEqual(expected.Beta, actual.Beta); + Assert.AreEqual(expected.CombinationType, actual.CombinationType); + + AssertCollectionAndItems(expected.Stochasts, actual.Stochasts, AssertStochast); + } + + private static void AssertGeneralResultTopLevelSubMechanismIllustrationPoint( + GeneralResult expectedGeneralResult, + GeneralResult actualGeneralResult) + { + if (expectedGeneralResult == null) + { + Assert.IsNull(actualGeneralResult); + return; + } + + AssertWindDirection(expectedGeneralResult.GoverningWindDirection, + actualGeneralResult.GoverningWindDirection); + + AssertCollectionAndItems(expectedGeneralResult.Stochasts, + actualGeneralResult.Stochasts, + AssertStochast); + + AssertCollectionAndItems(expectedGeneralResult.TopLevelIllustrationPoints, + actualGeneralResult.TopLevelIllustrationPoints, + AssertTopLevelSubMechanismIllustrationPoint); + } + + private static void AssertWindDirection(WindDirection expectedWindDirection, + WindDirection actualWindDirection) + { + Assert.AreEqual(expectedWindDirection.Name, actualWindDirection.Name); + Assert.AreEqual(expectedWindDirection.Angle, actualWindDirection.Angle); + } + + private static void AssertStochast(Stochast expectedStochast, + Stochast actualStochast) + { + Assert.AreEqual(expectedStochast.Name, actualStochast.Name); + Assert.AreEqual(expectedStochast.Alpha, actualStochast.Alpha); + Assert.AreEqual(expectedStochast.Duration, actualStochast.Duration); + } + + private static void AssertTopLevelSubMechanismIllustrationPoint( + TopLevelSubMechanismIllustrationPoint expectedTopLevelSubMechanismIllustrationPoint, + TopLevelSubMechanismIllustrationPoint actualTopLevelSubMechanismIllustrationPoint) + { + Assert.AreEqual(expectedTopLevelSubMechanismIllustrationPoint.ClosingSituation, + actualTopLevelSubMechanismIllustrationPoint.ClosingSituation); + + WindDirection expectedWindDirection = expectedTopLevelSubMechanismIllustrationPoint.WindDirection; + WindDirection actualWindDirection = actualTopLevelSubMechanismIllustrationPoint.WindDirection; + AssertWindDirection(expectedWindDirection, actualWindDirection); + + AssertSubMechanismIllustrationPoint(expectedTopLevelSubMechanismIllustrationPoint.SubMechanismIllustrationPoint, + actualTopLevelSubMechanismIllustrationPoint.SubMechanismIllustrationPoint); + } + + private static void AssertSubMechanismIllustrationPoint( + SubMechanismIllustrationPoint expectedSubMechanismIllustrationPoint, + SubMechanismIllustrationPoint actualSubMechanismIllustrationPoint) + { + Assert.AreEqual(expectedSubMechanismIllustrationPoint.Name, actualSubMechanismIllustrationPoint.Name); + Assert.AreEqual(expectedSubMechanismIllustrationPoint.Beta, actualSubMechanismIllustrationPoint.Beta); + + AssertCollectionAndItems(expectedSubMechanismIllustrationPoint.Stochasts, + actualSubMechanismIllustrationPoint.Stochasts, + AssertSubMechanismIllustrationPointStochast); + AssertCollectionAndItems(expectedSubMechanismIllustrationPoint.IllustrationPointResults, + actualSubMechanismIllustrationPoint.IllustrationPointResults, + AssertIllustrationPointResult); + } + + private static void AssertSubMechanismIllustrationPointStochast( + SubMechanismIllustrationPointStochast expectedStochast, + SubMechanismIllustrationPointStochast actualStochast) + { + AssertStochast(expectedStochast, actualStochast); + Assert.AreEqual(expectedStochast.Realization, actualStochast.Realization); + } + + private static void AssertIllustrationPointResult( + IllustrationPointResult expectedResult, + IllustrationPointResult actualResult) + { + Assert.AreEqual(expectedResult.Description, actualResult.Description); + Assert.AreEqual(expectedResult.Value, actualResult.Value); + } + + #endregion + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Properties/AssemblyInfo.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Properties/AssemblyInfo.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Properties/AssemblyInfo.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,25 @@ +// Copyright (C) Stichting Deltares 2018. 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.Reflection; + +[assembly: AssemblyTitle("Riskeer.Storage.Core.Test")] +[assembly: AssemblyProduct("Riskeer.Storage.Core.Test")] \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/AssessmentSectionEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/AssessmentSectionEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/AssessmentSectionEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,1207 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Contribution; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.GrassCoverErosionOutwards.Data; +using Ringtoets.Integration.Data; +using Ringtoets.Integration.Data.StandAlone.Input; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.Storage.Core.TestUtil.Hydraulics; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Read +{ + [TestFixture] + public class AssessmentSectionEntityReadExtensionsTest + { + [Test] + public void Read_WithoutCollector_ThrowsArgumentNullException() + { + // Setup + var entity = new AssessmentSectionEntity(); + + // Call + TestDelegate test = () => entity.Read(null); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("collector", parameter); + } + + [Test] + [TestCase(AssessmentSectionComposition.Dike)] + [TestCase(AssessmentSectionComposition.DikeAndDune)] + [TestCase(AssessmentSectionComposition.Dune)] + public void Read_WithCollector_ReturnsNewAssessmentSection(AssessmentSectionComposition assessmentSectionComposition) + { + // Setup + const string testId = "testId"; + const string testName = "testName"; + const string comments = "Some text"; + const double lowerLimitNorm = 0.05; + const double signalingNorm = 0.02; + var normativeNorm = new Random(9).NextEnumValue(); + var entity = new AssessmentSectionEntity + { + Id = testId, + Name = testName, + Composition = Convert.ToByte(assessmentSectionComposition), + Comments = comments, + LowerLimitNorm = lowerLimitNorm, + SignalingNorm = signalingNorm, + NormativeNormType = Convert.ToByte(normativeNorm) + }; + entity.BackgroundDataEntities.Add(CreateBackgroundDataEntity()); + + var collector = new ReadConversionCollector(); + + // Call + AssessmentSection section = entity.Read(collector); + + // Assert + Assert.IsNotNull(section); + Assert.AreEqual(testId, section.Id); + Assert.AreEqual(testName, section.Name); + Assert.AreEqual(comments, section.Comments.Body); + + Assert.AreEqual(lowerLimitNorm, section.FailureMechanismContribution.LowerLimitNorm); + Assert.AreEqual(signalingNorm, section.FailureMechanismContribution.SignalingNorm); + Assert.AreEqual(normativeNorm, section.FailureMechanismContribution.NormativeNorm); + + Assert.AreEqual(assessmentSectionComposition, section.Composition); + CollectionAssert.IsEmpty(section.ReferenceLine.Points); + + HydraulicBoundaryDatabase hydraulicBoundaryDatabase = section.HydraulicBoundaryDatabase; + Assert.IsNotNull(hydraulicBoundaryDatabase); + CollectionAssert.IsEmpty(hydraulicBoundaryDatabase.Locations); + Assert.IsNull(hydraulicBoundaryDatabase.FilePath); + Assert.IsNull(hydraulicBoundaryDatabase.Version); + + HydraulicLocationConfigurationSettings settings = hydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings; + Assert.IsNull(settings.FilePath); + Assert.IsNull(settings.ScenarioName); + Assert.AreEqual(0, settings.Year); + Assert.IsNull(settings.Scope); + Assert.IsNull(settings.SeaLevel); + Assert.IsNull(settings.RiverDischarge); + Assert.IsNull(settings.LakeLevel); + Assert.IsNull(settings.WindDirection); + Assert.IsNull(settings.WindSpeed); + Assert.IsNull(settings.Comment); + } + + [Test] + public void Read_WithBackgroundData_ReturnsNewAssessmentSectionWithBackgroundData() + { + // Setup + var random = new Random(21); + + const string mapDataName = "Background"; + double transparency = random.NextDouble(0, 1); + bool isVisible = random.NextBoolean(); + const BackgroundDataType backgroundDataType = BackgroundDataType.WellKnown; + + var wellKnownTileSource = random.NextEnumValue(); + string wellKnownTileSourceValue = ((int) wellKnownTileSource).ToString(); + + var backgroundDataMetaEntities = new[] + { + new BackgroundDataMetaEntity + { + Key = BackgroundDataIdentifiers.WellKnownTileSource, + Value = wellKnownTileSourceValue + } + }; + + AssessmentSectionEntity entity = CreateAssessmentSectionEntity(); + var backgroundDataEntity = new BackgroundDataEntity + { + Name = mapDataName, + Transparency = transparency, + IsVisible = Convert.ToByte(isVisible), + BackgroundDataType = Convert.ToByte(backgroundDataType), + BackgroundDataMetaEntities = backgroundDataMetaEntities + }; + + entity.BackgroundDataEntities.Add(backgroundDataEntity); + + var collector = new ReadConversionCollector(); + + // Call + AssessmentSection section = entity.Read(collector); + + // Assert + BackgroundData backgroundData = section.BackgroundData; + Assert.AreEqual(isVisible, backgroundData.IsVisible); + Assert.AreEqual(transparency, backgroundData.Transparency, + backgroundData.Transparency.GetAccuracy()); + Assert.AreEqual(mapDataName, backgroundData.Name); + + Assert.IsNotNull(backgroundData.Configuration); + var configuration = (WellKnownBackgroundDataConfiguration) backgroundData.Configuration; + Assert.AreEqual(wellKnownTileSource, configuration.WellKnownTileSource); + } + + [Test] + public void Read_WithReferenceLineEntities_ReturnsNewAssessmentSectionWithReferenceLineWithGeometry() + { + // Setup + AssessmentSectionEntity entity = CreateAssessmentSectionEntity(); + + var random = new Random(21); + double firstX = random.NextDouble(); + double firstY = random.NextDouble(); + double secondX = random.NextDouble(); + double secondY = random.NextDouble(); + + var points = new[] + { + new Point2D(firstX, firstY), + new Point2D(secondX, secondY) + }; + entity.ReferenceLinePointXml = new Point2DCollectionXmlSerializer().ToXml(points); + entity.BackgroundDataEntities.Add(CreateBackgroundDataEntity()); + + var collector = new ReadConversionCollector(); + + // Call + AssessmentSection section = entity.Read(collector); + + // Assert + CollectionAssert.AreEqual(points, section.ReferenceLine.Points); + } + + [Test] + public void Read_WithHydraulicBoundaryLocationCalculations_ReturnsNewAssessmentSectionWithHydraulicBoundaryLocationCalculationsSet() + { + // Setup + AssessmentSectionEntity entity = CreateAssessmentSectionEntity(); + entity.HydraulicBoundaryDatabaseEntities.Add(CreateHydraulicDatabaseEntity()); + entity.BackgroundDataEntities.Add(CreateBackgroundDataEntity()); + + HydraulicLocationEntity hydraulicLocationEntity = HydraulicLocationEntityTestFactory.CreateHydraulicLocationEntity(); + hydraulicLocationEntity.Name = "A"; + hydraulicLocationEntity.Order = 1; + entity.HydraulicLocationEntities.Add(hydraulicLocationEntity); + + entity.HydraulicLocationCalculationCollectionEntity = CreateHydraulicLocationCollectionCalculationEntity(hydraulicLocationEntity, 1); + entity.HydraulicLocationCalculationCollectionEntity1 = CreateHydraulicLocationCollectionCalculationEntity(hydraulicLocationEntity, 2); + entity.HydraulicLocationCalculationCollectionEntity2 = CreateHydraulicLocationCollectionCalculationEntity(hydraulicLocationEntity, 3); + entity.HydraulicLocationCalculationCollectionEntity3 = CreateHydraulicLocationCollectionCalculationEntity(hydraulicLocationEntity, 4); + entity.HydraulicLocationCalculationCollectionEntity4 = CreateHydraulicLocationCollectionCalculationEntity(hydraulicLocationEntity, 5); + entity.HydraulicLocationCalculationCollectionEntity5 = CreateHydraulicLocationCollectionCalculationEntity(hydraulicLocationEntity, 6); + entity.HydraulicLocationCalculationCollectionEntity6 = CreateHydraulicLocationCollectionCalculationEntity(hydraulicLocationEntity, 7); + entity.HydraulicLocationCalculationCollectionEntity7 = CreateHydraulicLocationCollectionCalculationEntity(hydraulicLocationEntity, 8); + + var collector = new ReadConversionCollector(); + + // Call + AssessmentSection section = entity.Read(collector); + + // Assert + HydraulicBoundaryLocation hydraulicBoundaryLocation = section.HydraulicBoundaryDatabase.Locations.Single(); + + HydraulicBoundaryLocationCalculation calculation = section.WaterLevelCalculationsForFactorizedSignalingNorm.Single(); + HydraulicLocationCalculationEntity hydraulicLocationCalculationEntity = entity.HydraulicLocationCalculationCollectionEntity7 + .HydraulicLocationCalculationEntities + .Single(); + AssertHydraulicBoundaryLocationCalculation(hydraulicLocationCalculationEntity, + hydraulicBoundaryLocation, + calculation); + + calculation = section.WaterLevelCalculationsForSignalingNorm.Single(); + hydraulicLocationCalculationEntity = entity.HydraulicLocationCalculationCollectionEntity6 + .HydraulicLocationCalculationEntities + .Single(); + AssertHydraulicBoundaryLocationCalculation(hydraulicLocationCalculationEntity, + hydraulicBoundaryLocation, + calculation); + + calculation = section.WaterLevelCalculationsForLowerLimitNorm.Single(); + hydraulicLocationCalculationEntity = entity.HydraulicLocationCalculationCollectionEntity5 + .HydraulicLocationCalculationEntities + .Single(); + AssertHydraulicBoundaryLocationCalculation(hydraulicLocationCalculationEntity, + hydraulicBoundaryLocation, + calculation); + + calculation = section.WaterLevelCalculationsForFactorizedLowerLimitNorm.Single(); + hydraulicLocationCalculationEntity = entity.HydraulicLocationCalculationCollectionEntity4 + .HydraulicLocationCalculationEntities + .Single(); + AssertHydraulicBoundaryLocationCalculation(hydraulicLocationCalculationEntity, + hydraulicBoundaryLocation, + calculation); + + calculation = section.WaveHeightCalculationsForFactorizedSignalingNorm.Single(); + hydraulicLocationCalculationEntity = entity.HydraulicLocationCalculationCollectionEntity3 + .HydraulicLocationCalculationEntities + .Single(); + AssertHydraulicBoundaryLocationCalculation(hydraulicLocationCalculationEntity, + hydraulicBoundaryLocation, + calculation); + + calculation = section.WaveHeightCalculationsForSignalingNorm.Single(); + hydraulicLocationCalculationEntity = entity.HydraulicLocationCalculationCollectionEntity2 + .HydraulicLocationCalculationEntities + .Single(); + AssertHydraulicBoundaryLocationCalculation(hydraulicLocationCalculationEntity, + hydraulicBoundaryLocation, + calculation); + + calculation = section.WaveHeightCalculationsForLowerLimitNorm.Single(); + hydraulicLocationCalculationEntity = entity.HydraulicLocationCalculationCollectionEntity1 + .HydraulicLocationCalculationEntities + .Single(); + AssertHydraulicBoundaryLocationCalculation(hydraulicLocationCalculationEntity, + hydraulicBoundaryLocation, + calculation); + + calculation = section.WaveHeightCalculationsForFactorizedLowerLimitNorm.Single(); + hydraulicLocationCalculationEntity = entity.HydraulicLocationCalculationCollectionEntity + .HydraulicLocationCalculationEntities + .Single(); + AssertHydraulicBoundaryLocationCalculation(hydraulicLocationCalculationEntity, + hydraulicBoundaryLocation, + calculation); + } + + [Test] + public void Read_WithoutHydraulicBoundaryLocationDatabase_ReturnsNewAssessementSectionWithoutHydraulicBoundaryLocationAndCalculations() + { + // Setup + AssessmentSectionEntity entity = CreateAssessmentSectionEntity(); + entity.BackgroundDataEntities.Add(CreateBackgroundDataEntity()); + + var collector = new ReadConversionCollector(); + + // Call + AssessmentSection section = entity.Read(collector); + + // Assert + HydraulicBoundaryDatabase hydraulicBoundaryDatabase = section.HydraulicBoundaryDatabase; + CollectionAssert.IsEmpty(hydraulicBoundaryDatabase.Locations); + Assert.IsNull(hydraulicBoundaryDatabase.FilePath); + Assert.IsNull(hydraulicBoundaryDatabase.Version); + + CollectionAssert.IsEmpty(section.WaterLevelCalculationsForFactorizedSignalingNorm); + CollectionAssert.IsEmpty(section.WaterLevelCalculationsForSignalingNorm); + CollectionAssert.IsEmpty(section.WaterLevelCalculationsForLowerLimitNorm); + CollectionAssert.IsEmpty(section.WaterLevelCalculationsForFactorizedLowerLimitNorm); + CollectionAssert.IsEmpty(section.WaveHeightCalculationsForFactorizedSignalingNorm); + CollectionAssert.IsEmpty(section.WaveHeightCalculationsForSignalingNorm); + CollectionAssert.IsEmpty(section.WaveHeightCalculationsForLowerLimitNorm); + CollectionAssert.IsEmpty(section.WaveHeightCalculationsForFactorizedLowerLimitNorm); + + GrassCoverErosionOutwardsFailureMechanism failureMechanism = section.GrassCoverErosionOutwards; + CollectionAssert.IsEmpty(failureMechanism.WaterLevelCalculationsForMechanismSpecificFactorizedSignalingNorm); + CollectionAssert.IsEmpty(failureMechanism.WaterLevelCalculationsForMechanismSpecificSignalingNorm); + CollectionAssert.IsEmpty(failureMechanism.WaterLevelCalculationsForMechanismSpecificLowerLimitNorm); + CollectionAssert.IsEmpty(failureMechanism.WaveHeightCalculationsForMechanismSpecificFactorizedSignalingNorm); + CollectionAssert.IsEmpty(failureMechanism.WaveHeightCalculationsForMechanismSpecificSignalingNorm); + CollectionAssert.IsEmpty(failureMechanism.WaveHeightCalculationsForMechanismSpecificLowerLimitNorm); + } + + [Test] + public void Read_WithHydraulicDatabaseLocations_ReturnsNewAssessmentSectionWithLocationsSet() + { + // Setup + AssessmentSectionEntity entity = CreateAssessmentSectionEntity(); + entity.HydraulicBoundaryDatabaseEntities.Add(CreateHydraulicDatabaseEntity()); + entity.BackgroundDataEntities.Add(CreateBackgroundDataEntity()); + + HydraulicLocationEntity hydraulicLocationEntityOne = HydraulicLocationEntityTestFactory.CreateHydraulicLocationEntity(); + hydraulicLocationEntityOne.Name = "A"; + hydraulicLocationEntityOne.Order = 1; + entity.HydraulicLocationEntities.Add(hydraulicLocationEntityOne); + HydraulicLocationEntity hydraulicLocationEntityTwo = HydraulicLocationEntityTestFactory.CreateHydraulicLocationEntity(); + hydraulicLocationEntityOne.Name = "B"; + hydraulicLocationEntityOne.Order = 0; + entity.HydraulicLocationEntities.Add(hydraulicLocationEntityTwo); + + entity.HydraulicLocationCalculationCollectionEntity = new HydraulicLocationCalculationCollectionEntity(); + entity.HydraulicLocationCalculationCollectionEntity1 = new HydraulicLocationCalculationCollectionEntity(); + entity.HydraulicLocationCalculationCollectionEntity2 = new HydraulicLocationCalculationCollectionEntity(); + entity.HydraulicLocationCalculationCollectionEntity3 = new HydraulicLocationCalculationCollectionEntity(); + entity.HydraulicLocationCalculationCollectionEntity4 = new HydraulicLocationCalculationCollectionEntity(); + entity.HydraulicLocationCalculationCollectionEntity5 = new HydraulicLocationCalculationCollectionEntity(); + entity.HydraulicLocationCalculationCollectionEntity6 = new HydraulicLocationCalculationCollectionEntity(); + entity.HydraulicLocationCalculationCollectionEntity7 = new HydraulicLocationCalculationCollectionEntity(); + + var collector = new ReadConversionCollector(); + + // Call + AssessmentSection section = entity.Read(collector); + + // Assert + IEnumerable hydraulicBoundaryLocations = section.HydraulicBoundaryDatabase.Locations; + Assert.AreEqual(2, hydraulicBoundaryLocations.Count()); + CollectionAssert.AreEqual(new[] + { + "B", + "A" + }, hydraulicBoundaryLocations.Select(l => l.Name)); + + GrassCoverErosionOutwardsFailureMechanism failureMechanism = section.GrassCoverErosionOutwards; + AssertGrassCoverErosionOutwardsHydraulicBoundaryLocationCalculations(hydraulicBoundaryLocations, failureMechanism.WaterLevelCalculationsForMechanismSpecificFactorizedSignalingNorm); + AssertGrassCoverErosionOutwardsHydraulicBoundaryLocationCalculations(hydraulicBoundaryLocations, failureMechanism.WaterLevelCalculationsForMechanismSpecificSignalingNorm); + AssertGrassCoverErosionOutwardsHydraulicBoundaryLocationCalculations(hydraulicBoundaryLocations, failureMechanism.WaterLevelCalculationsForMechanismSpecificLowerLimitNorm); + + AssertGrassCoverErosionOutwardsHydraulicBoundaryLocationCalculations(hydraulicBoundaryLocations, failureMechanism.WaveHeightCalculationsForMechanismSpecificFactorizedSignalingNorm); + AssertGrassCoverErosionOutwardsHydraulicBoundaryLocationCalculations(hydraulicBoundaryLocations, failureMechanism.WaveHeightCalculationsForMechanismSpecificSignalingNorm); + AssertGrassCoverErosionOutwardsHydraulicBoundaryLocationCalculations(hydraulicBoundaryLocations, failureMechanism.WaveHeightCalculationsForMechanismSpecificLowerLimitNorm); + } + + [Test] + public void Read_WithHydraulicBoundaryLocationDatabase_ReturnsNewAssessmentSectionWithHydraulicLocationConfigurationSettingsSet() + { + // Setup + var random = new Random(21); + AssessmentSectionEntity entity = CreateAssessmentSectionEntity(); + var hydraulicBoundaryDatabaseEntity = new HydraulicBoundaryDatabaseEntity + { + FilePath = "hydraulicBoundaryDatabaseFilePath", + Version = "hydraulicBoundaryDatabaseVersion", + HydraulicLocationConfigurationSettingsFilePath = "hlcdFilePath", + HydraulicLocationConfigurationSettingsScenarioName = "ScenarioName", + HydraulicLocationConfigurationSettingsYear = random.Next(), + HydraulicLocationConfigurationSettingsScope = "Scope", + HydraulicLocationConfigurationSettingsSeaLevel = "SeaLevel", + HydraulicLocationConfigurationSettingsRiverDischarge = "RiverDischarge", + HydraulicLocationConfigurationSettingsLakeLevel = "LakeLevel", + HydraulicLocationConfigurationSettingsWindDirection = "WindDirection", + HydraulicLocationConfigurationSettingsWindSpeed = "WindSpeed", + HydraulicLocationConfigurationSettingsComment = "Comment" + }; + + entity.BackgroundDataEntities.Add(CreateBackgroundDataEntity()); + entity.HydraulicBoundaryDatabaseEntities.Add(hydraulicBoundaryDatabaseEntity); + entity.HydraulicLocationCalculationCollectionEntity = new HydraulicLocationCalculationCollectionEntity(); + entity.HydraulicLocationCalculationCollectionEntity1 = new HydraulicLocationCalculationCollectionEntity(); + entity.HydraulicLocationCalculationCollectionEntity2 = new HydraulicLocationCalculationCollectionEntity(); + entity.HydraulicLocationCalculationCollectionEntity3 = new HydraulicLocationCalculationCollectionEntity(); + entity.HydraulicLocationCalculationCollectionEntity4 = new HydraulicLocationCalculationCollectionEntity(); + entity.HydraulicLocationCalculationCollectionEntity5 = new HydraulicLocationCalculationCollectionEntity(); + entity.HydraulicLocationCalculationCollectionEntity6 = new HydraulicLocationCalculationCollectionEntity(); + entity.HydraulicLocationCalculationCollectionEntity7 = new HydraulicLocationCalculationCollectionEntity(); + + var collector = new ReadConversionCollector(); + + // Call + AssessmentSection section = entity.Read(collector); + + // Assert + HydraulicBoundaryDatabase hydraulicBoundaryDatabase = section.HydraulicBoundaryDatabase; + Assert.AreEqual(hydraulicBoundaryDatabaseEntity.FilePath, hydraulicBoundaryDatabase.FilePath); + Assert.AreEqual(hydraulicBoundaryDatabaseEntity.Version, hydraulicBoundaryDatabase.Version); + + HydraulicLocationConfigurationSettings settings = hydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings; + Assert.AreEqual(hydraulicBoundaryDatabaseEntity.HydraulicLocationConfigurationSettingsFilePath, settings.FilePath); + Assert.AreEqual(hydraulicBoundaryDatabaseEntity.HydraulicLocationConfigurationSettingsScenarioName, settings.ScenarioName); + Assert.AreEqual(hydraulicBoundaryDatabaseEntity.HydraulicLocationConfigurationSettingsYear, settings.Year); + Assert.AreEqual(hydraulicBoundaryDatabaseEntity.HydraulicLocationConfigurationSettingsScope, settings.Scope); + Assert.AreEqual(hydraulicBoundaryDatabaseEntity.HydraulicLocationConfigurationSettingsSeaLevel, settings.SeaLevel); + Assert.AreEqual(hydraulicBoundaryDatabaseEntity.HydraulicLocationConfigurationSettingsRiverDischarge, settings.RiverDischarge); + Assert.AreEqual(hydraulicBoundaryDatabaseEntity.HydraulicLocationConfigurationSettingsLakeLevel, settings.LakeLevel); + Assert.AreEqual(hydraulicBoundaryDatabaseEntity.HydraulicLocationConfigurationSettingsWindDirection, settings.WindDirection); + Assert.AreEqual(hydraulicBoundaryDatabaseEntity.HydraulicLocationConfigurationSettingsWindSpeed, settings.WindSpeed); + Assert.AreEqual(hydraulicBoundaryDatabaseEntity.HydraulicLocationConfigurationSettingsComment, settings.Comment); + } + + [Test] + public void Read_WithPipingFailureMechanismProperties_ReturnsNewAssessmentSectionWithPropertiesInPipingFailureMechanism() + { + // Setup + AssessmentSectionEntity entity = CreateAssessmentSectionEntity(); + var random = new Random(21); + bool isRelevant = random.NextBoolean(); + double parameterA = random.NextDouble() / 10; + const string inputComments = "Some input text"; + const string outputComments = "Some output text"; + const string notRelevantComments = "Really not relevant"; + + var failureMechanismEntity = new FailureMechanismEntity + { + FailureMechanismType = (int) FailureMechanismType.Piping, + CalculationGroupEntity = new CalculationGroupEntity(), + IsRelevant = Convert.ToByte(isRelevant), + InputComments = inputComments, + OutputComments = outputComments, + NotRelevantComments = notRelevantComments, + PipingFailureMechanismMetaEntities = + { + new PipingFailureMechanismMetaEntity + { + A = parameterA + } + } + }; + entity.FailureMechanismEntities.Add(failureMechanismEntity); + entity.BackgroundDataEntities.Add(CreateBackgroundDataEntity()); + + var collector = new ReadConversionCollector(); + + // Call + AssessmentSection section = entity.Read(collector); + + // Assert + Assert.AreEqual(isRelevant, section.Piping.IsRelevant); + Assert.AreEqual(inputComments, section.Piping.InputComments.Body); + Assert.AreEqual(outputComments, section.Piping.OutputComments.Body); + Assert.AreEqual(notRelevantComments, section.Piping.NotRelevantComments.Body); + Assert.AreEqual(parameterA, section.Piping.PipingProbabilityAssessmentInput.A); + Assert.IsNull(section.Piping.FailureMechanismSectionSourcePath); + Assert.IsNull(section.Piping.StochasticSoilModels.SourcePath); + Assert.IsNull(section.Piping.SurfaceLines.SourcePath); + } + + [Test] + public void Read_WithMacroStabilityInwardsFailureMechanismProperties_ReturnsNewAssessmentSectionWithPropertiesInMacroStabilityInwardsFailureMechanism() + { + // Setup + AssessmentSectionEntity entity = CreateAssessmentSectionEntity(); + var random = new Random(21); + bool isRelevant = random.NextBoolean(); + double parameterA = random.NextDouble(); + const string inputComments = "Some input text"; + const string outputComments = "Some output text"; + const string notRelevantComments = "Really not relevant"; + + var failureMechanismEntity = new FailureMechanismEntity + { + FailureMechanismType = (int) FailureMechanismType.MacroStabilityInwards, + CalculationGroupEntity = new CalculationGroupEntity(), + IsRelevant = Convert.ToByte(isRelevant), + InputComments = inputComments, + OutputComments = outputComments, + NotRelevantComments = notRelevantComments, + MacroStabilityInwardsFailureMechanismMetaEntities = + { + new MacroStabilityInwardsFailureMechanismMetaEntity + { + A = parameterA + } + } + }; + entity.FailureMechanismEntities.Add(failureMechanismEntity); + entity.BackgroundDataEntities.Add(CreateBackgroundDataEntity()); + + var collector = new ReadConversionCollector(); + + // Call + AssessmentSection section = entity.Read(collector); + + // Assert + Assert.AreEqual(isRelevant, section.MacroStabilityInwards.IsRelevant); + Assert.AreEqual(inputComments, section.MacroStabilityInwards.InputComments.Body); + Assert.AreEqual(outputComments, section.MacroStabilityInwards.OutputComments.Body); + Assert.AreEqual(notRelevantComments, section.MacroStabilityInwards.NotRelevantComments.Body); + Assert.IsNull(section.MacroStabilityInwards.FailureMechanismSectionSourcePath); + Assert.IsNull(section.MacroStabilityInwards.StochasticSoilModels.SourcePath); + Assert.IsNull(section.MacroStabilityInwards.SurfaceLines.SourcePath); + + MacroStabilityInwardsProbabilityAssessmentInput probabilityAssessmentInput = section.MacroStabilityInwards + .MacroStabilityInwardsProbabilityAssessmentInput; + Assert.AreEqual(parameterA, probabilityAssessmentInput.A); + } + + [Test] + public void Read_WithMacroStabilityOutwardsFailureMechanismProperties_ReturnsNewAssessmentSectionWithPropertiesInMacroStabilityOutwardsFailureMechanism() + { + // Setup + AssessmentSectionEntity entity = CreateAssessmentSectionEntity(); + var random = new Random(21); + bool isRelevant = random.NextBoolean(); + double parameterA = random.NextDouble(); + const string inputComments = "Some input text"; + const string outputComments = "Some output text"; + const string notRelevantComments = "Really not relevant"; + + var failureMechanismEntity = new FailureMechanismEntity + { + FailureMechanismType = (int) FailureMechanismType.MacroStabilityOutwards, + IsRelevant = Convert.ToByte(isRelevant), + InputComments = inputComments, + OutputComments = outputComments, + NotRelevantComments = notRelevantComments, + MacroStabilityOutwardsFailureMechanismMetaEntities = + { + new MacroStabilityOutwardsFailureMechanismMetaEntity + { + A = parameterA + } + } + }; + entity.FailureMechanismEntities.Add(failureMechanismEntity); + entity.BackgroundDataEntities.Add(CreateBackgroundDataEntity()); + + var collector = new ReadConversionCollector(); + + // Call + AssessmentSection section = entity.Read(collector); + + // Assert + Assert.AreEqual(isRelevant, section.MacroStabilityOutwards.IsRelevant); + Assert.AreEqual(inputComments, section.MacroStabilityOutwards.InputComments.Body); + Assert.AreEqual(outputComments, section.MacroStabilityOutwards.OutputComments.Body); + Assert.AreEqual(notRelevantComments, section.MacroStabilityOutwards.NotRelevantComments.Body); + Assert.IsNull(section.MacroStabilityOutwards.FailureMechanismSectionSourcePath); + + MacroStabilityOutwardsProbabilityAssessmentInput probabilityAssessmentInput = section.MacroStabilityOutwards + .MacroStabilityOutwardsProbabilityAssessmentInput; + Assert.AreEqual(parameterA, probabilityAssessmentInput.A); + } + + [Test] + public void Read_WithGrassCoverErosionInwardsWithProperties_ReturnsGrassCoverErosionInwardsWithProperties() + { + // Setup + AssessmentSectionEntity entity = CreateAssessmentSectionEntity(); + var random = new Random(21); + bool isRelevant = random.NextBoolean(); + double n = random.NextDouble(1.0, 20.0); + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + + var failureMechanismEntity = new FailureMechanismEntity + { + FailureMechanismType = (int) FailureMechanismType.GrassRevetmentTopErosionAndInwards, + CalculationGroupEntity = new CalculationGroupEntity(), + IsRelevant = Convert.ToByte(isRelevant), + InputComments = originalInput, + OutputComments = originalOutput, + NotRelevantComments = originalNotRelevantText, + GrassCoverErosionInwardsFailureMechanismMetaEntities = + { + new GrassCoverErosionInwardsFailureMechanismMetaEntity + { + N = n + } + } + }; + entity.FailureMechanismEntities.Add(failureMechanismEntity); + entity.BackgroundDataEntities.Add(CreateBackgroundDataEntity()); + + var collector = new ReadConversionCollector(); + + // Call + AssessmentSection section = entity.Read(collector); + + // Assert + Assert.AreEqual(isRelevant, section.GrassCoverErosionInwards.IsRelevant); + Assert.AreEqual(originalInput, section.GrassCoverErosionInwards.InputComments.Body); + Assert.AreEqual(originalOutput, section.GrassCoverErosionInwards.OutputComments.Body); + Assert.AreEqual(originalNotRelevantText, section.GrassCoverErosionInwards.NotRelevantComments.Body); + Assert.IsNull(section.GrassCoverErosionInwards.FailureMechanismSectionSourcePath); + Assert.IsNull(section.GrassCoverErosionInwards.DikeProfiles.SourcePath); + + RoundedDouble actualN = section.GrassCoverErosionInwards.GeneralInput.N; + Assert.AreEqual(n, actualN, actualN.GetAccuracy()); + } + + [Test] + public void Read_WithGrassCoverErosionOutwardsWithProperties_ReturnsGrassCoverErosionOutwardsWithProperties() + { + // Setup + AssessmentSectionEntity entity = CreateAssessmentSectionEntity(); + var random = new Random(21); + bool isRelevant = random.NextBoolean(); + double n = random.NextDouble(1.0, 20.0); + const string inputComments = "Some input text"; + const string outputComments = "Some output text"; + const string notRelevantComments = "Really not relevant"; + + var failureMechanismEntity = new FailureMechanismEntity + { + FailureMechanismType = (int) FailureMechanismType.GrassRevetmentErosionOutwards, + CalculationGroupEntity = new CalculationGroupEntity(), + IsRelevant = Convert.ToByte(isRelevant), + InputComments = inputComments, + OutputComments = outputComments, + NotRelevantComments = notRelevantComments, + GrassCoverErosionOutwardsFailureMechanismMetaEntities = + { + new GrassCoverErosionOutwardsFailureMechanismMetaEntity + { + N = n, + HydraulicLocationCalculationCollectionEntity = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity1 = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity2 = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity3 = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity4 = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity5 = new HydraulicLocationCalculationCollectionEntity() + } + } + }; + entity.FailureMechanismEntities.Add(failureMechanismEntity); + entity.BackgroundDataEntities.Add(CreateBackgroundDataEntity()); + + var collector = new ReadConversionCollector(); + + // Call + AssessmentSection section = entity.Read(collector); + + // Assert + Assert.AreEqual(isRelevant, section.GrassCoverErosionOutwards.IsRelevant); + Assert.AreEqual(inputComments, section.GrassCoverErosionOutwards.InputComments.Body); + Assert.AreEqual(outputComments, section.GrassCoverErosionOutwards.OutputComments.Body); + Assert.AreEqual(notRelevantComments, section.GrassCoverErosionOutwards.NotRelevantComments.Body); + Assert.IsNull(section.GrassCoverErosionOutwards.FailureMechanismSectionSourcePath); + Assert.IsNull(section.GrassCoverErosionOutwards.ForeshoreProfiles.SourcePath); + + RoundedDouble actualN = section.GrassCoverErosionOutwards.GeneralInput.N; + Assert.AreEqual(n, actualN, actualN.GetAccuracy()); + } + + [Test] + public void Read_WithStabilityStoneCoverWithProperties_ReturnsStabilityStoneCoverWithProperties() + { + // Setup + AssessmentSectionEntity entity = CreateAssessmentSectionEntity(); + var random = new Random(21); + bool isRelevant = random.NextBoolean(); + double n = random.NextDouble(1.0, 20.0); + const string inputComments = "Some input text"; + const string outputComments = "Some output text"; + const string notRelevantComments = "Really not relevant"; + + var failureMechanismEntity = new FailureMechanismEntity + { + FailureMechanismType = (int) FailureMechanismType.StabilityStoneRevetment, + CalculationGroupEntity = new CalculationGroupEntity(), + IsRelevant = Convert.ToByte(isRelevant), + InputComments = inputComments, + OutputComments = outputComments, + NotRelevantComments = notRelevantComments, + StabilityStoneCoverFailureMechanismMetaEntities = + { + new StabilityStoneCoverFailureMechanismMetaEntity + { + N = n + } + } + }; + entity.FailureMechanismEntities.Add(failureMechanismEntity); + entity.BackgroundDataEntities.Add(CreateBackgroundDataEntity()); + + var collector = new ReadConversionCollector(); + + // Call + AssessmentSection section = entity.Read(collector); + + // Assert + Assert.AreEqual(isRelevant, section.StabilityStoneCover.IsRelevant); + Assert.AreEqual(inputComments, section.StabilityStoneCover.InputComments.Body); + Assert.AreEqual(outputComments, section.StabilityStoneCover.OutputComments.Body); + Assert.AreEqual(notRelevantComments, section.StabilityStoneCover.NotRelevantComments.Body); + Assert.IsNull(section.StabilityStoneCover.FailureMechanismSectionSourcePath); + Assert.IsNull(section.StabilityStoneCover.ForeshoreProfiles.SourcePath); + + RoundedDouble actualN = section.StabilityStoneCover.GeneralInput.N; + Assert.AreEqual(n, actualN, actualN.GetAccuracy()); + } + + [Test] + public void Read_WithWaveImpactAsphaltCoverWithProperties_ReturnsWaveImpactAsphaltCoverWithProperties() + { + // Setup + AssessmentSectionEntity entity = CreateAssessmentSectionEntity(); + var random = new Random(21); + bool isRelevant = random.NextBoolean(); + double deltaL = random.NextDouble(1.0, 20.0); + const string inputComments = "Some input text"; + const string outputComments = "Some output text"; + const string notRelevantComments = "Really not relevant"; + + var failureMechanismEntity = new FailureMechanismEntity + { + FailureMechanismType = (int) FailureMechanismType.WaveImpactOnAsphaltRevetment, + CalculationGroupEntity = new CalculationGroupEntity(), + IsRelevant = Convert.ToByte(isRelevant), + InputComments = inputComments, + OutputComments = outputComments, + NotRelevantComments = notRelevantComments, + WaveImpactAsphaltCoverFailureMechanismMetaEntities = + { + new WaveImpactAsphaltCoverFailureMechanismMetaEntity + { + DeltaL = deltaL + } + } + }; + entity.FailureMechanismEntities.Add(failureMechanismEntity); + entity.BackgroundDataEntities.Add(CreateBackgroundDataEntity()); + + var collector = new ReadConversionCollector(); + + // Call + AssessmentSection section = entity.Read(collector); + + // Assert + Assert.AreEqual(isRelevant, section.WaveImpactAsphaltCover.IsRelevant); + Assert.AreEqual(inputComments, section.WaveImpactAsphaltCover.InputComments.Body); + Assert.AreEqual(outputComments, section.WaveImpactAsphaltCover.OutputComments.Body); + Assert.AreEqual(notRelevantComments, section.WaveImpactAsphaltCover.NotRelevantComments.Body); + Assert.IsNull(section.WaveImpactAsphaltCover.FailureMechanismSectionSourcePath); + Assert.IsNull(section.WaveImpactAsphaltCover.ForeshoreProfiles.SourcePath); + + RoundedDouble actualDeltaL = section.WaveImpactAsphaltCover.GeneralWaveImpactAsphaltCoverInput.DeltaL; + Assert.AreEqual(deltaL, actualDeltaL, actualDeltaL.GetAccuracy()); + } + + [Test] + public void Read_WithHeightStructuresWithProperties_ReturnsHeightStructuresWithProperties() + { + // Setup + AssessmentSectionEntity entity = CreateAssessmentSectionEntity(); + var random = new Random(21); + bool isRelevant = random.NextBoolean(); + double n = random.NextDouble(1.0, 20.0); + const string inputComments = "Some input text"; + const string outputComments = "Some output text"; + const string notRelevantComments = "Really not relevant"; + + var failureMechanismEntity = new FailureMechanismEntity + { + FailureMechanismType = (int) FailureMechanismType.StructureHeight, + CalculationGroupEntity = new CalculationGroupEntity(), + IsRelevant = Convert.ToByte(isRelevant), + InputComments = inputComments, + OutputComments = outputComments, + NotRelevantComments = notRelevantComments, + HeightStructuresFailureMechanismMetaEntities = + { + new HeightStructuresFailureMechanismMetaEntity + { + N = n + } + } + }; + entity.FailureMechanismEntities.Add(failureMechanismEntity); + entity.BackgroundDataEntities.Add(CreateBackgroundDataEntity()); + + var collector = new ReadConversionCollector(); + + // Call + AssessmentSection section = entity.Read(collector); + + // Assert + Assert.AreEqual(isRelevant, section.HeightStructures.IsRelevant); + Assert.AreEqual(inputComments, section.HeightStructures.InputComments.Body); + Assert.AreEqual(outputComments, section.HeightStructures.OutputComments.Body); + Assert.AreEqual(notRelevantComments, section.HeightStructures.NotRelevantComments.Body); + Assert.IsNull(section.HeightStructures.FailureMechanismSectionSourcePath); + Assert.IsNull(section.HeightStructures.HeightStructures.SourcePath); + + RoundedDouble actualN = section.HeightStructures.GeneralInput.N; + Assert.AreEqual(n, actualN, actualN.GetAccuracy()); + } + + [Test] + public void Read_WithClosingStructuresWithProperties_ReturnsClosingStructuresWithProperties() + { + // Setup + AssessmentSectionEntity entity = CreateAssessmentSectionEntity(); + var random = new Random(21); + bool isRelevant = random.NextBoolean(); + int n2a = random.Next(1, 40); + const string inputComments = "Some input text"; + const string outputComments = "Some output text"; + const string notRelevantComments = "Really not relevant"; + + var failureMechanismEntity = new FailureMechanismEntity + { + FailureMechanismType = (int) FailureMechanismType.ReliabilityClosingOfStructure, + CalculationGroupEntity = new CalculationGroupEntity(), + IsRelevant = Convert.ToByte(isRelevant), + InputComments = inputComments, + OutputComments = outputComments, + NotRelevantComments = notRelevantComments, + ClosingStructuresFailureMechanismMetaEntities = + { + new ClosingStructuresFailureMechanismMetaEntity + { + N2A = n2a + } + } + }; + entity.FailureMechanismEntities.Add(failureMechanismEntity); + entity.BackgroundDataEntities.Add(CreateBackgroundDataEntity()); + + var collector = new ReadConversionCollector(); + + // Call + AssessmentSection section = entity.Read(collector); + + // Assert + Assert.AreEqual(isRelevant, section.ClosingStructures.IsRelevant); + Assert.AreEqual(inputComments, section.ClosingStructures.InputComments.Body); + Assert.AreEqual(outputComments, section.ClosingStructures.OutputComments.Body); + Assert.AreEqual(notRelevantComments, section.ClosingStructures.NotRelevantComments.Body); + Assert.IsNull(section.ClosingStructures.FailureMechanismSectionSourcePath); + Assert.AreEqual(n2a, section.ClosingStructures.GeneralInput.N2A); + } + + [Test] + public void Read_WithStabilityPointStructuresWithProperties_ReturnsStabilityPointStructuresWithProperties() + { + // Setup + AssessmentSectionEntity entity = CreateAssessmentSectionEntity(); + var random = new Random(21); + bool isRelevant = random.NextBoolean(); + double n = random.NextDouble(1.0, 20.0); + const string inputComments = "Some input text"; + const string outputComments = "Some output text"; + const string notRelevantComments = "Really not relevant"; + + var failureMechanismEntity = new FailureMechanismEntity + { + FailureMechanismType = (int) FailureMechanismType.StabilityPointStructures, + CalculationGroupEntity = new CalculationGroupEntity(), + IsRelevant = Convert.ToByte(isRelevant), + InputComments = inputComments, + OutputComments = outputComments, + NotRelevantComments = notRelevantComments, + StabilityPointStructuresFailureMechanismMetaEntities = + { + new StabilityPointStructuresFailureMechanismMetaEntity + { + N = n + } + } + }; + entity.FailureMechanismEntities.Add(failureMechanismEntity); + entity.BackgroundDataEntities.Add(CreateBackgroundDataEntity()); + + var collector = new ReadConversionCollector(); + + // Call + AssessmentSection section = entity.Read(collector); + + // Assert + Assert.AreEqual(isRelevant, section.StabilityPointStructures.IsRelevant); + Assert.AreEqual(inputComments, section.StabilityPointStructures.InputComments.Body); + Assert.AreEqual(outputComments, section.StabilityPointStructures.OutputComments.Body); + Assert.AreEqual(notRelevantComments, section.StabilityPointStructures.NotRelevantComments.Body); + Assert.IsNull(section.StabilityPointStructures.FailureMechanismSectionSourcePath); + Assert.IsNull(section.StabilityPointStructures.StabilityPointStructures.SourcePath); + + RoundedDouble actualN = section.StabilityPointStructures.GeneralInput.N; + Assert.AreEqual(n, actualN, actualN.GetAccuracy()); + } + + [Test] + public void Read_WithDuneErosionWithProperties_ReturnsDuneErosionWithProperties() + { + // Setup + AssessmentSectionEntity entity = CreateAssessmentSectionEntity(); + const string inputComments = "Some input text"; + const string outputComments = "Some output text"; + const string notRelevantComments = "Really not relevant"; + var random = new Random(39); + bool isRelevant = random.NextBoolean(); + double n = random.NextDouble(1.0, 20.0); + + var failureMechanismEntity = new FailureMechanismEntity + { + FailureMechanismType = (int) FailureMechanismType.DuneErosion, + CalculationGroupEntity = new CalculationGroupEntity(), + IsRelevant = Convert.ToByte(isRelevant), + InputComments = inputComments, + OutputComments = outputComments, + NotRelevantComments = notRelevantComments, + DuneErosionFailureMechanismMetaEntities = + { + new DuneErosionFailureMechanismMetaEntity + { + N = n, + DuneLocationCalculationCollectionEntity = new DuneLocationCalculationCollectionEntity(), + DuneLocationCalculationCollectionEntity1 = new DuneLocationCalculationCollectionEntity(), + DuneLocationCalculationCollectionEntity2 = new DuneLocationCalculationCollectionEntity(), + DuneLocationCalculationCollectionEntity3 = new DuneLocationCalculationCollectionEntity(), + DuneLocationCalculationCollectionEntity4 = new DuneLocationCalculationCollectionEntity() + } + } + }; + entity.FailureMechanismEntities.Add(failureMechanismEntity); + entity.BackgroundDataEntities.Add(CreateBackgroundDataEntity()); + + var collector = new ReadConversionCollector(); + + // Call + AssessmentSection section = entity.Read(collector); + + // Assert + Assert.AreEqual(isRelevant, section.DuneErosion.IsRelevant); + Assert.AreEqual(inputComments, section.DuneErosion.InputComments.Body); + Assert.AreEqual(outputComments, section.DuneErosion.OutputComments.Body); + Assert.AreEqual(notRelevantComments, section.DuneErosion.NotRelevantComments.Body); + Assert.IsNull(section.DuneErosion.FailureMechanismSectionSourcePath); + + RoundedDouble actualN = section.DuneErosion.GeneralInput.N; + Assert.AreEqual(n, actualN, actualN.GetAccuracy()); + } + + [Test] + public void Read_WithPipingStructureFailureMechanismProperties_ReturnsNewAssessmentSectionWithPropertiesInPipingStructureFailureMechanism() + { + // Setup + AssessmentSectionEntity entity = CreateAssessmentSectionEntity(); + var random = new Random(21); + bool isRelevant = random.NextBoolean(); + double parameterN = random.NextDouble(1.0, 20.0); + const string inputComments = "Some input text"; + const string outputComments = "Some output text"; + const string notRelevantComments = "Really not relevant"; + + var failureMechanismEntity = new FailureMechanismEntity + { + FailureMechanismType = (int) FailureMechanismType.PipingAtStructure, + IsRelevant = Convert.ToByte(isRelevant), + InputComments = inputComments, + OutputComments = outputComments, + NotRelevantComments = notRelevantComments, + PipingStructureFailureMechanismMetaEntities = + { + new PipingStructureFailureMechanismMetaEntity + { + N = parameterN + } + } + }; + entity.FailureMechanismEntities.Add(failureMechanismEntity); + entity.BackgroundDataEntities.Add(CreateBackgroundDataEntity()); + + var collector = new ReadConversionCollector(); + + // Call + AssessmentSection section = entity.Read(collector); + + // Assert + Assert.AreEqual(isRelevant, section.PipingStructure.IsRelevant); + Assert.AreEqual(inputComments, section.PipingStructure.InputComments.Body); + Assert.AreEqual(outputComments, section.PipingStructure.OutputComments.Body); + Assert.AreEqual(notRelevantComments, section.PipingStructure.NotRelevantComments.Body); + Assert.IsNull(section.PipingStructure.FailureMechanismSectionSourcePath); + + RoundedDouble actualN = section.PipingStructure.N; + Assert.AreEqual(parameterN, actualN, actualN.GetAccuracy()); + } + + [Test] + public void Read_WithStandAloneFailureMechanisms_ReturnsNewAssessmentSectionWithFailureMechanismsSet() + { + // Setup + var random = new Random(31); + AssessmentSectionEntity entity = CreateAssessmentSectionEntity(); + + bool microstabilityIsRelevant = random.NextBoolean(); + bool strengthAndStabilityParallelConstructionIsRelevant = random.NextBoolean(); + bool waterOverpressureAsphaltRevetmentIsRelevant = random.NextBoolean(); + bool grassRevetmentSlidingOutwardsIsRelevant = random.NextBoolean(); + bool grassRevetmentSlidingInwardsIsRelevant = random.NextBoolean(); + bool technicalInnovationsIsRelevant = random.NextBoolean(); + + FailureMechanismEntity microstability = CreateFailureMechanismEntity( + microstabilityIsRelevant, + FailureMechanismType.Microstability); + FailureMechanismEntity strengthAndStabilityParallelConstruction = CreateFailureMechanismEntity( + strengthAndStabilityParallelConstructionIsRelevant, + FailureMechanismType.StrengthAndStabilityParallelConstruction); + FailureMechanismEntity waterOverpressureAsphaltRevetment = CreateFailureMechanismEntity( + waterOverpressureAsphaltRevetmentIsRelevant, + FailureMechanismType.WaterOverpressureAsphaltRevetment); + FailureMechanismEntity grassRevetmentSlidingOutwards = CreateFailureMechanismEntity( + grassRevetmentSlidingOutwardsIsRelevant, + FailureMechanismType.GrassRevetmentSlidingOutwards); + FailureMechanismEntity grassRevetmentSlidingInwards = CreateFailureMechanismEntity( + grassRevetmentSlidingInwardsIsRelevant, + FailureMechanismType.GrassRevetmentSlidingInwards); + FailureMechanismEntity technicalInnovation = CreateFailureMechanismEntity( + technicalInnovationsIsRelevant, + FailureMechanismType.TechnicalInnovations); + + entity.FailureMechanismEntities.Add(microstability); + entity.FailureMechanismEntities.Add(strengthAndStabilityParallelConstruction); + entity.FailureMechanismEntities.Add(waterOverpressureAsphaltRevetment); + entity.FailureMechanismEntities.Add(grassRevetmentSlidingOutwards); + entity.FailureMechanismEntities.Add(grassRevetmentSlidingInwards); + entity.FailureMechanismEntities.Add(technicalInnovation); + entity.BackgroundDataEntities.Add(CreateBackgroundDataEntity()); + + var collector = new ReadConversionCollector(); + + // Call + AssessmentSection section = entity.Read(collector); + + // Assert + AssertFailureMechanismEqual(microstabilityIsRelevant, + microstability.InputComments, + microstability.OutputComments, + microstability.NotRelevantComments, + section.Microstability); + AssertFailureMechanismEqual(strengthAndStabilityParallelConstructionIsRelevant, + strengthAndStabilityParallelConstruction.InputComments, + strengthAndStabilityParallelConstruction.OutputComments, + strengthAndStabilityParallelConstruction.NotRelevantComments, + section.StrengthStabilityLengthwiseConstruction); + AssertFailureMechanismEqual(waterOverpressureAsphaltRevetmentIsRelevant, + waterOverpressureAsphaltRevetment.InputComments, + waterOverpressureAsphaltRevetment.OutputComments, + waterOverpressureAsphaltRevetment.NotRelevantComments, + section.WaterPressureAsphaltCover); + AssertFailureMechanismEqual(grassRevetmentSlidingOutwardsIsRelevant, + grassRevetmentSlidingOutwards.InputComments, + grassRevetmentSlidingOutwards.OutputComments, + grassRevetmentSlidingOutwards.NotRelevantComments, + section.GrassCoverSlipOffOutwards); + AssertFailureMechanismEqual(technicalInnovationsIsRelevant, + technicalInnovation.InputComments, + technicalInnovation.OutputComments, + technicalInnovation.NotRelevantComments, + section.TechnicalInnovation); + } + + private static void AssertHydraulicBoundaryLocationCalculation(HydraulicLocationCalculationEntity expectedEntity, + HydraulicBoundaryLocation expectedHydraulicBoundaryLocation, + HydraulicBoundaryLocationCalculation actualCalculation) + { + Assert.AreSame(expectedHydraulicBoundaryLocation, actualCalculation.HydraulicBoundaryLocation); + Assert.AreEqual(Convert.ToBoolean(expectedEntity.ShouldIllustrationPointsBeCalculated), + actualCalculation.InputParameters.ShouldIllustrationPointsBeCalculated); + Assert.IsNull(actualCalculation.Output); + } + + private static void AssertGrassCoverErosionOutwardsHydraulicBoundaryLocationCalculations(IEnumerable hydraulicBoundaryLocations, + IEnumerable actualCalculations) + { + Dictionary dictionary = + actualCalculations.ToDictionary(calc => calc.HydraulicBoundaryLocation, calc => calc); + + Assert.AreEqual(hydraulicBoundaryLocations.Count(), dictionary.Count); + foreach (HydraulicBoundaryLocation hydraulicBoundaryLocation in hydraulicBoundaryLocations) + { + HydraulicBoundaryLocationCalculation calculation = dictionary[hydraulicBoundaryLocation]; + Assert.IsNotNull(calculation); + Assert.IsNull(calculation.Output); + Assert.IsFalse(calculation.InputParameters.ShouldIllustrationPointsBeCalculated); + } + } + + private static HydraulicLocationCalculationCollectionEntity CreateHydraulicLocationCollectionCalculationEntity(HydraulicLocationEntity hydraulicLocationEntity, + int seed) + { + var random = new Random(seed); + return new HydraulicLocationCalculationCollectionEntity + { + HydraulicLocationCalculationEntities = + { + new HydraulicLocationCalculationEntity + { + HydraulicLocationEntity = hydraulicLocationEntity, + ShouldIllustrationPointsBeCalculated = Convert.ToByte(random.NextBoolean()) + } + } + }; + } + + private static AssessmentSectionEntity CreateAssessmentSectionEntity() + { + return new AssessmentSectionEntity + { + LowerLimitNorm = 1.0 / 30000, + SignalingNorm = 1.0 / 300000, + NormativeNormType = Convert.ToByte(NormType.Signaling), + Composition = Convert.ToByte(AssessmentSectionComposition.Dike) + }; + } + + private static BackgroundDataEntity CreateBackgroundDataEntity() + { + return new BackgroundDataEntity + { + Name = "Background", + Transparency = 0.0, + IsVisible = 0, + BackgroundDataType = 1, + BackgroundDataMetaEntities = new[] + { + new BackgroundDataMetaEntity + { + Key = BackgroundDataIdentifiers.IsConfigured, + Value = "0" + } + } + }; + } + + private static HydraulicBoundaryDatabaseEntity CreateHydraulicDatabaseEntity() + { + return new HydraulicBoundaryDatabaseEntity + { + FilePath = "hydraulicBoundaryDatabaseFilePath", + Version = "hydraulicBoundaryDatabaseVersion", + HydraulicLocationConfigurationSettingsFilePath = "hlcdFilePath", + HydraulicLocationConfigurationSettingsScenarioName = "ScenarioName", + HydraulicLocationConfigurationSettingsYear = 1, + HydraulicLocationConfigurationSettingsScope = "Scope" + }; + } + + private static FailureMechanismEntity CreateFailureMechanismEntity(bool isRelevant, + FailureMechanismType failureMechanismType) + { + return new FailureMechanismEntity + { + FailureMechanismType = (short) failureMechanismType, + IsRelevant = Convert.ToByte(isRelevant), + InputComments = string.Concat("InputComment", failureMechanismType.ToString()), + OutputComments = string.Concat("OutputComment", failureMechanismType.ToString()), + NotRelevantComments = string.Concat("NotRelevantComment", failureMechanismType.ToString()) + }; + } + + private static void AssertFailureMechanismEqual(bool expectedIsRelevant, + string expectedInputComments, string expectedOutputComments, + string expectedNotRelevantComments, IFailureMechanism failureMechanism) + { + Assert.AreEqual(expectedIsRelevant, failureMechanism.IsRelevant); + Assert.AreEqual(expectedInputComments, failureMechanism.InputComments.Body); + Assert.AreEqual(expectedOutputComments, failureMechanism.OutputComments.Body); + Assert.AreEqual(expectedNotRelevantComments, failureMechanism.NotRelevantComments.Body); + Assert.IsNull(failureMechanism.FailureMechanismSectionSourcePath); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/BackgroundDataEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/BackgroundDataEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/BackgroundDataEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,196 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.AssessmentSection; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; + +namespace Riskeer.Storage.Core.Test.Read +{ + [TestFixture] + public class BackgroundDataEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowArgumentNullException() + { + // Call + TestDelegate test = () => ((BackgroundDataEntity) null).Read(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_EntityWithWmtsData_ReturnBackgroundData() + { + // Setup + const string name = "map data"; + const string url = "//url"; + const string capabilityName = "capability name"; + const string preferredFormat = "image/jpeg"; + const bool isVisible = false; + const double transparancy = 0.4; + const bool isConfigured = true; + + const BackgroundDataType backgroundDataType = BackgroundDataType.Wmts; + var backgroundDataMetaEntities = new[] + { + new BackgroundDataMetaEntity + { + Key = BackgroundDataIdentifiers.IsConfigured, + Value = Convert.ToByte(isConfigured).ToString() + }, + new BackgroundDataMetaEntity + { + Key = BackgroundDataIdentifiers.SourceCapabilitiesUrl, + Value = url + }, + new BackgroundDataMetaEntity + { + Key = BackgroundDataIdentifiers.SelectedCapabilityIdentifier, + Value = capabilityName + }, + new BackgroundDataMetaEntity + { + Key = BackgroundDataIdentifiers.PreferredFormat, + Value = preferredFormat + } + }; + + var entity = new BackgroundDataEntity + { + Name = name, + BackgroundDataMetaEntities = backgroundDataMetaEntities, + IsVisible = Convert.ToByte(isVisible), + Transparency = transparancy, + BackgroundDataType = Convert.ToByte(backgroundDataType) + }; + + // Call + BackgroundData backgroundData = entity.Read(); + + // Assert + Assert.AreEqual(isVisible, backgroundData.IsVisible); + Assert.AreEqual(transparancy, backgroundData.Transparency.Value); + Assert.AreEqual(name, backgroundData.Name); + + Assert.IsNotNull(backgroundData.Configuration); + var configuration = (WmtsBackgroundDataConfiguration) backgroundData.Configuration; + Assert.AreEqual(isConfigured, configuration.IsConfigured); + Assert.AreEqual(url, configuration.SourceCapabilitiesUrl); + Assert.AreEqual(capabilityName, configuration.SelectedCapabilityIdentifier); + Assert.AreEqual(preferredFormat, configuration.PreferredFormat); + } + + [Test] + public void Read_EntityWithWellKnownData_ReturnBackgroundData() + { + // Setup + const string name = "map data"; + const bool isVisible = false; + const double transparancy = 0.4; + + const BackgroundDataType backgroundDataType = BackgroundDataType.WellKnown; + + var random = new Random(21); + var wellKnownTileSource = random.NextEnumValue(); + + var entity = new BackgroundDataEntity + { + Name = name, + BackgroundDataMetaEntities = new List + { + new BackgroundDataMetaEntity + { + Key = BackgroundDataIdentifiers.WellKnownTileSource, + Value = ((int) wellKnownTileSource).ToString() + } + }, + IsVisible = Convert.ToByte(isVisible), + Transparency = transparancy, + BackgroundDataType = Convert.ToByte(backgroundDataType) + }; + + // Call + BackgroundData backgroundData = entity.Read(); + + // Assert + Assert.AreEqual(isVisible, backgroundData.IsVisible); + Assert.AreEqual(transparancy, backgroundData.Transparency.Value); + + Assert.AreEqual(name, backgroundData.Name); + + Assert.IsNotNull(backgroundData.Configuration); + var configuration = (WellKnownBackgroundDataConfiguration) backgroundData.Configuration; + Assert.AreEqual(wellKnownTileSource, configuration.WellKnownTileSource); + } + + [Test] + public void Read_WmtsConfigurationIsConfiguredFalse_NoParametersAdded() + { + // Setup + const bool isConfigured = false; + + var entity = new BackgroundDataEntity + { + BackgroundDataMetaEntities = new List + { + new BackgroundDataMetaEntity + { + Key = BackgroundDataIdentifiers.IsConfigured, + Value = Convert.ToByte(isConfigured).ToString() + }, + new BackgroundDataMetaEntity + { + Key = BackgroundDataIdentifiers.SourceCapabilitiesUrl, + Value = "//url" + }, + new BackgroundDataMetaEntity + { + Key = BackgroundDataIdentifiers.SelectedCapabilityIdentifier, + Value = "capability name" + }, + new BackgroundDataMetaEntity + { + Key = BackgroundDataIdentifiers.PreferredFormat, + Value = "image/jpeg" + } + }, + BackgroundDataType = Convert.ToByte(BackgroundDataType.Wmts) + }; + + // Call + BackgroundData backgroundData = entity.Read(); + + // Assert + var configuration = (WmtsBackgroundDataConfiguration) backgroundData.Configuration; + Assert.AreEqual(false, configuration.IsConfigured); + Assert.IsNull(configuration.SourceCapabilitiesUrl); + Assert.IsNull(configuration.SelectedCapabilityIdentifier); + Assert.IsNull(configuration.PreferredFormat); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/BackgroundDataMetaEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/BackgroundDataMetaEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/BackgroundDataMetaEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,62 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; + +namespace Riskeer.Storage.Core.Test.Read +{ + [TestFixture] + public class BackgroundDataMetaEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowArgumentNullException() + { + // Call + TestDelegate test = () => ((BackgroundDataMetaEntity) null).Read(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_WithEntity_ReturnKeyValuePairWithData() + { + // Setup + var entity = new BackgroundDataMetaEntity + { + Key = "Test key", + Value = "Test value" + }; + + // Call + KeyValuePair data = entity.Read(); + + // Assert + Assert.AreEqual(entity.Key, data.Key); + Assert.AreEqual(entity.Value, data.Value); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/CalculationGroupEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/CalculationGroupEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/CalculationGroupEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,1811 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.ClosingStructures.Data; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Structures; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.GrassCoverErosionOutwards.Data; +using Ringtoets.HeightStructures.Data; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.Piping.Data; +using Ringtoets.StabilityPointStructures.Data; +using Ringtoets.StabilityStoneCover.Data; +using Ringtoets.WaveImpactAsphaltCover.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; + +namespace Riskeer.Storage.Core.Test.Read +{ + [TestFixture] + public class CalculationGroupEntityReadExtensionsTest + { + #region Piping + + [Test] + public void ReadAsPipingCalculationGroup_ReadConversionCollectorIsNull_ThrowArgumentNullException() + { + // Setup + var entity = new CalculationGroupEntity(); + var generalPipingInput = new GeneralPipingInput(); + + // Call + TestDelegate call = () => entity.ReadAsPipingCalculationGroup(null, generalPipingInput); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void ReadAsPipingCalculationGroup_GeneralPipingInputIsNull_ThrowArgumentNullException() + { + // Setup + var entity = new CalculationGroupEntity(); + var collector = new ReadConversionCollector(); + + // Call + TestDelegate call = () => entity.ReadAsPipingCalculationGroup(collector, null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("generalPipingInput", paramName); + } + + [Test] + public void ReadAsPipingCalculationGroup_EntityWithoutChildren_CreateCalculationGroupWithoutChildren() + { + // Setup + var entity = new CalculationGroupEntity + { + Name = "A" + }; + + var collector = new ReadConversionCollector(); + var generalPipingInput = new GeneralPipingInput(); + + // Call + CalculationGroup group = entity.ReadAsPipingCalculationGroup(collector, generalPipingInput); + + // Assert + Assert.AreEqual(entity.Name, group.Name); + CollectionAssert.IsEmpty(group.Children); + } + + [Test] + public void ReadAsPipingCalculationGroup_EntityWithChildGroups_CreateCalculationGroupWithChildGroups() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Name = "AA", + Order = 0 + }, + new CalculationGroupEntity + { + Name = "AB", + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Name = "ABB", + Order = 1 + }, + new CalculationGroupEntity + { + Name = "ABA", + Order = 0 + } + }, + Order = 1 + } + } + }; + + var collector = new ReadConversionCollector(); + var generalPipingInput = new GeneralPipingInput(); + + // Call + CalculationGroup rootGroup = rootGroupEntity.ReadAsPipingCalculationGroup(collector, generalPipingInput); + + // Assert + Assert.AreEqual("A", rootGroup.Name); + + List rootChildren = rootGroup.Children; + var rootChildGroup1 = (CalculationGroup) rootChildren[0]; + Assert.AreEqual("AA", rootChildGroup1.Name); + CollectionAssert.IsEmpty(rootChildGroup1.Children); + var rootChildGroup2 = (CalculationGroup) rootChildren[1]; + Assert.AreEqual("AB", rootChildGroup2.Name); + + List rootChildGroup2Children = rootChildGroup2.Children; + var rootChildGroup1Child1 = (CalculationGroup) rootChildGroup2Children[0]; + Assert.AreEqual("ABA", rootChildGroup1Child1.Name); + CollectionAssert.IsEmpty(rootChildGroup1Child1.Children); + var rootChildGroup1Child2 = (CalculationGroup) rootChildGroup2Children[1]; + Assert.AreEqual("ABB", rootChildGroup1Child2.Name); + CollectionAssert.IsEmpty(rootChildGroup1Child2.Children); + } + + [Test] + public void ReadAsPipingCalculationGroup_EntityWithChildPipingCalculations_CreateCalculationGroupWithChildCalculations() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + PipingCalculationEntities = + { + new PipingCalculationEntity + { + Order = 1, + Name = "2", + DampingFactorExitMean = 2 + }, + new PipingCalculationEntity + { + Order = 0, + Name = "1", + DampingFactorExitMean = 1 + } + } + }; + + var collector = new ReadConversionCollector(); + var generalPipingInput = new GeneralPipingInput(); + + // Call + CalculationGroup rootGroup = rootGroupEntity.ReadAsPipingCalculationGroup(collector, generalPipingInput); + + // Assert + List rootChildren = rootGroup.Children; + Assert.AreEqual(2, rootChildren.Count); + + var rootChildCalculation1 = (PipingCalculationScenario) rootChildren[0]; + Assert.AreEqual("1", rootChildCalculation1.Name); + + var rootChildCalculation2 = (PipingCalculationScenario) rootChildren[1]; + Assert.AreEqual("2", rootChildCalculation2.Name); + } + + [Test] + public void ReadAsPipingCalculationGroup_EntityWithChildPipingCalculationsAndGroups_CreateCalculationGroupWithChildCalculationsAndGroups() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + PipingCalculationEntities = + { + new PipingCalculationEntity + { + Order = 0, + Name = "calculation1", + DampingFactorExitMean = 1 + }, + new PipingCalculationEntity + { + Order = 2, + Name = "calculation2", + DampingFactorExitMean = 2 + } + }, + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Order = 3, + Name = "group2" + }, + new CalculationGroupEntity + { + Order = 1, + Name = "group1" + } + } + }; + + var collector = new ReadConversionCollector(); + var generalPipingInput = new GeneralPipingInput(); + + // Call + CalculationGroup rootGroup = rootGroupEntity.ReadAsPipingCalculationGroup(collector, generalPipingInput); + + // Assert + List rootChildren = rootGroup.Children; + Assert.AreEqual(4, rootChildren.Count); + + var rootChildCalculation1 = (PipingCalculationScenario) rootChildren[0]; + Assert.AreEqual("calculation1", rootChildCalculation1.Name); + + var rootChildGroup1 = (CalculationGroup) rootChildren[1]; + Assert.AreEqual("group1", rootChildGroup1.Name); + + var rootChildCalculation2 = (PipingCalculationScenario) rootChildren[2]; + Assert.AreEqual("calculation2", rootChildCalculation2.Name); + + var rootChildGroup2 = (CalculationGroup) rootChildren[3]; + Assert.AreEqual("group2", rootChildGroup2.Name); + } + + #endregion + + #region Macro Stability Inwards + + [Test] + public void ReadAsMacroStabilityInwardsCalculationGroup_ReadConversionCollectorIsNull_ThrowArgumentNullException() + { + // Setup + var entity = new CalculationGroupEntity(); + + // Call + TestDelegate call = () => entity.ReadAsMacroStabilityInwardsCalculationGroup(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void ReadAsMacroStabilityInwardsCalculationGroup_EntityWithoutChildren_CreateCalculationGroupWithoutChildren() + { + // Setup + var entity = new CalculationGroupEntity + { + Name = "A" + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup group = entity.ReadAsMacroStabilityInwardsCalculationGroup(collector); + + // Assert + Assert.AreEqual(entity.Name, group.Name); + CollectionAssert.IsEmpty(group.Children); + } + + [Test] + public void ReadAsMacroStabilityInwardsCalculationGroup_EntityWithChildGroups_CreateCalculationGroupWithChildGroups() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Name = "AA", + Order = 0 + }, + new CalculationGroupEntity + { + Name = "AB", + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Name = "ABB", + Order = 1 + }, + new CalculationGroupEntity + { + Name = "ABA", + Order = 0 + } + }, + Order = 1 + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup rootGroup = rootGroupEntity.ReadAsMacroStabilityInwardsCalculationGroup(collector); + + // Assert + Assert.AreEqual("A", rootGroup.Name); + + List rootChildren = rootGroup.Children; + var rootChildGroup1 = (CalculationGroup) rootChildren[0]; + Assert.AreEqual("AA", rootChildGroup1.Name); + CollectionAssert.IsEmpty(rootChildGroup1.Children); + var rootChildGroup2 = (CalculationGroup) rootChildren[1]; + Assert.AreEqual("AB", rootChildGroup2.Name); + + List rootChildGroup2Children = rootChildGroup2.Children; + var rootChildGroup1Child1 = (CalculationGroup) rootChildGroup2Children[0]; + Assert.AreEqual("ABA", rootChildGroup1Child1.Name); + CollectionAssert.IsEmpty(rootChildGroup1Child1.Children); + var rootChildGroup1Child2 = (CalculationGroup) rootChildGroup2Children[1]; + Assert.AreEqual("ABB", rootChildGroup1Child2.Name); + CollectionAssert.IsEmpty(rootChildGroup1Child2.Children); + } + + [Test] + public void ReadAsMacroStabilityInwardsCalculationGroup_EntityWithChildMacroStabilityInwardsCalculations_CreateCalculationGroupWithChildCalculations() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + MacroStabilityInwardsCalculationEntities = + { + new MacroStabilityInwardsCalculationEntity + { + Order = 1, + Name = "2", + TangentLineNumber = 1, + LeftGridNrOfHorizontalPoints = 5, + LeftGridNrOfVerticalPoints = 5, + RightGridNrOfHorizontalPoints = 5, + RightGridNrOfVerticalPoints = 5 + }, + new MacroStabilityInwardsCalculationEntity + { + Order = 0, + Name = "1", + TangentLineNumber = 1, + LeftGridNrOfHorizontalPoints = 5, + LeftGridNrOfVerticalPoints = 5, + RightGridNrOfHorizontalPoints = 5, + RightGridNrOfVerticalPoints = 5 + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup rootGroup = rootGroupEntity.ReadAsMacroStabilityInwardsCalculationGroup(collector); + + // Assert + List rootChildren = rootGroup.Children; + Assert.AreEqual(2, rootChildren.Count); + + var rootChildCalculation1 = (MacroStabilityInwardsCalculationScenario) rootChildren[0]; + Assert.AreEqual("1", rootChildCalculation1.Name); + + var rootChildCalculation2 = (MacroStabilityInwardsCalculationScenario) rootChildren[1]; + Assert.AreEqual("2", rootChildCalculation2.Name); + } + + [Test] + public void ReadAsMacroStabilityInwardsCalculationGroup_EntityWithChildMacroStabilityInwardsCalculationsAndGroups_CreateCalculationGroupWithChildCalculationsAndGroups() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + MacroStabilityInwardsCalculationEntities = + { + new MacroStabilityInwardsCalculationEntity + { + Order = 0, + Name = "calculation1", + TangentLineNumber = 1, + LeftGridNrOfHorizontalPoints = 5, + LeftGridNrOfVerticalPoints = 5, + RightGridNrOfHorizontalPoints = 5, + RightGridNrOfVerticalPoints = 5 + }, + new MacroStabilityInwardsCalculationEntity + { + Order = 2, + Name = "calculation2", + TangentLineNumber = 2, + LeftGridNrOfHorizontalPoints = 5, + LeftGridNrOfVerticalPoints = 5, + RightGridNrOfHorizontalPoints = 5, + RightGridNrOfVerticalPoints = 5 + } + }, + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Order = 3, + Name = "group2" + }, + new CalculationGroupEntity + { + Order = 1, + Name = "group1" + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup rootGroup = rootGroupEntity.ReadAsMacroStabilityInwardsCalculationGroup(collector); + + // Assert + List rootChildren = rootGroup.Children; + Assert.AreEqual(4, rootChildren.Count); + + var rootChildCalculation1 = (MacroStabilityInwardsCalculationScenario) rootChildren[0]; + Assert.AreEqual("calculation1", rootChildCalculation1.Name); + + var rootChildGroup1 = (CalculationGroup) rootChildren[1]; + Assert.AreEqual("group1", rootChildGroup1.Name); + + var rootChildCalculation2 = (MacroStabilityInwardsCalculationScenario) rootChildren[2]; + Assert.AreEqual("calculation2", rootChildCalculation2.Name); + + var rootChildGroup2 = (CalculationGroup) rootChildren[3]; + Assert.AreEqual("group2", rootChildGroup2.Name); + } + + #endregion + + #region Grass Cover Erosion Inwards + + [Test] + public void ReadAsGrassCoverErosionInwardsCalculationGroup_CollectorIsNull_ThrowArgumentNullException() + { + // Setup + var entity = new CalculationGroupEntity(); + + // Call + TestDelegate call = () => entity.ReadAsGrassCoverErosionInwardsCalculationGroup(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void ReadAsGrassCoverErosionInwardsCalculationGroup_EntityWithoutChildren_CreateCalculationGroupWithoutChildren() + { + // Setup + var entity = new CalculationGroupEntity + { + Name = "A" + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup group = entity.ReadAsGrassCoverErosionInwardsCalculationGroup(collector); + + // Assert + Assert.AreEqual(entity.Name, group.Name); + CollectionAssert.IsEmpty(group.Children); + } + + [Test] + public void ReadAsGrassCoverErosionInwardsCalculationGroup_EntityWithChildGroups_CreateCalculationGroupWithChildGroups() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Name = "AB", + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Name = "ABB", + Order = 1 + }, + new CalculationGroupEntity + { + Name = "ABA", + Order = 0 + } + }, + Order = 1 + }, + new CalculationGroupEntity + { + Name = "AA", + Order = 0 + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup rootGroup = rootGroupEntity.ReadAsGrassCoverErosionInwardsCalculationGroup(collector); + + // Assert + Assert.AreEqual("A", rootGroup.Name); + + List rootChildren = rootGroup.Children; + var rootChildGroup1 = (CalculationGroup) rootChildren[0]; + Assert.AreEqual("AA", rootChildGroup1.Name); + CollectionAssert.IsEmpty(rootChildGroup1.Children); + var rootChildGroup2 = (CalculationGroup) rootChildren[1]; + Assert.AreEqual("AB", rootChildGroup2.Name); + + List rootChildGroup2Children = rootChildGroup2.Children; + var rootChildGroup1Child1 = (CalculationGroup) rootChildGroup2Children[0]; + Assert.AreEqual("ABA", rootChildGroup1Child1.Name); + CollectionAssert.IsEmpty(rootChildGroup1Child1.Children); + var rootChildGroup1Child2 = (CalculationGroup) rootChildGroup2Children[1]; + Assert.AreEqual("ABB", rootChildGroup1Child2.Name); + CollectionAssert.IsEmpty(rootChildGroup1Child2.Children); + } + + [Test] + public void ReadAsGrassCoverErosionInwardsCalculationGroup_EntityWithChildGrassCoverErosionInwardsCalculations_CreateCalculationGroupWithChildCalculations() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + GrassCoverErosionInwardsCalculationEntities = + { + new GrassCoverErosionInwardsCalculationEntity + { + Order = 0, + Name = "1" + }, + new GrassCoverErosionInwardsCalculationEntity + { + Order = 1, + Name = "2" + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup rootGroup = rootGroupEntity.ReadAsGrassCoverErosionInwardsCalculationGroup(collector); + + // Assert + List rootChildren = rootGroup.Children; + Assert.AreEqual(2, rootChildren.Count); + + var rootChildCalculation1 = (GrassCoverErosionInwardsCalculation) rootChildren[0]; + Assert.AreEqual("1", rootChildCalculation1.Name); + + var rootChildCalculation2 = (GrassCoverErosionInwardsCalculation) rootChildren[1]; + Assert.AreEqual("2", rootChildCalculation2.Name); + } + + [Test] + public void ReadAsGrassCoverErosionInwardsCalculationGroup_EntityWithChildGrassCoverErosionInwardsCalculationsAndGroups_CreateCalculationGroupWithChildCalculationsAndGroups() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + GrassCoverErosionInwardsCalculationEntities = + { + new GrassCoverErosionInwardsCalculationEntity + { + Order = 2, + Name = "calculation2" + }, + new GrassCoverErosionInwardsCalculationEntity + { + Order = 0, + Name = "calculation1" + } + }, + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Order = 1, + Name = "group1" + }, + new CalculationGroupEntity + { + Order = 3, + Name = "group2" + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup rootGroup = rootGroupEntity.ReadAsGrassCoverErosionInwardsCalculationGroup(collector); + + // Assert + List rootChildren = rootGroup.Children; + Assert.AreEqual(4, rootChildren.Count); + + var rootChildCalculation1 = (GrassCoverErosionInwardsCalculation) rootChildren[0]; + Assert.AreEqual("calculation1", rootChildCalculation1.Name); + + var rootChildGroup1 = (CalculationGroup) rootChildren[1]; + Assert.AreEqual("group1", rootChildGroup1.Name); + + var rootChildCalculation2 = (GrassCoverErosionInwardsCalculation) rootChildren[2]; + Assert.AreEqual("calculation2", rootChildCalculation2.Name); + + var rootChildGroup2 = (CalculationGroup) rootChildren[3]; + Assert.AreEqual("group2", rootChildGroup2.Name); + } + + #endregion + + #region Grass Cover Erosion Outwards + + [Test] + public void ReadAsGrassCoverErosionOutwardsWaveConditionsCalculationGroup_CollectorIsNull_ThrowArgumentNullException() + { + // Setup + var entity = new CalculationGroupEntity(); + + // Call + TestDelegate call = () => entity.ReadAsGrassCoverErosionOutwardsWaveConditionsCalculationGroup(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void ReadAsGrassCoverErosionOutwardsWaveConditionsCalculationGroup_EntityWithoutChildren_CreateCalculationGroupWithoutChildren() + { + // Setup + var entity = new CalculationGroupEntity + { + Name = "A" + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup group = entity.ReadAsGrassCoverErosionOutwardsWaveConditionsCalculationGroup(collector); + + // Assert + Assert.AreEqual(entity.Name, group.Name); + CollectionAssert.IsEmpty(group.Children); + } + + [Test] + public void ReadAsGrassCoverErosionOutwardsWaveConditionsCalculationGroup_EntityWithChildGroups_CreateCalculationGroupWithChildGroups() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Name = "AB", + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Name = "ABA", + Order = 0 + }, + new CalculationGroupEntity + { + Name = "ABB", + Order = 1 + } + }, + Order = 1 + }, + new CalculationGroupEntity + { + Name = "AA", + Order = 0 + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup rootGroup = rootGroupEntity.ReadAsGrassCoverErosionOutwardsWaveConditionsCalculationGroup(collector); + + // Assert + Assert.AreEqual("A", rootGroup.Name); + + List rootChildren = rootGroup.Children; + var rootChildGroup1 = (CalculationGroup) rootChildren[0]; + Assert.AreEqual("AA", rootChildGroup1.Name); + CollectionAssert.IsEmpty(rootChildGroup1.Children); + var rootChildGroup2 = (CalculationGroup) rootChildren[1]; + Assert.AreEqual("AB", rootChildGroup2.Name); + + List rootChildGroup2Children = rootChildGroup2.Children; + var rootChildGroup1Child1 = (CalculationGroup) rootChildGroup2Children[0]; + Assert.AreEqual("ABA", rootChildGroup1Child1.Name); + CollectionAssert.IsEmpty(rootChildGroup1Child1.Children); + var rootChildGroup1Child2 = (CalculationGroup) rootChildGroup2Children[1]; + Assert.AreEqual("ABB", rootChildGroup1Child2.Name); + CollectionAssert.IsEmpty(rootChildGroup1Child2.Children); + } + + [Test] + public void ReadAsGrassCoverErosionOutwardsWaveConditionsCalculationGroup_EntityWithChildGrassCoverErosionOutwardsWaveConditionsCalculations_CreateCalculationGroupWithChildCalculations() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + GrassCoverErosionOutwardsWaveConditionsCalculationEntities = + { + new GrassCoverErosionOutwardsWaveConditionsCalculationEntity + { + Order = 0, + Name = "1" + }, + new GrassCoverErosionOutwardsWaveConditionsCalculationEntity + { + Order = 1, + Name = "2" + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup rootGroup = rootGroupEntity.ReadAsGrassCoverErosionOutwardsWaveConditionsCalculationGroup(collector); + + // Assert + List rootChildren = rootGroup.Children; + Assert.AreEqual(2, rootChildren.Count); + + var rootChildCalculation1 = (GrassCoverErosionOutwardsWaveConditionsCalculation) rootChildren[0]; + Assert.AreEqual("1", rootChildCalculation1.Name); + + var rootChildCalculation2 = (GrassCoverErosionOutwardsWaveConditionsCalculation) rootChildren[1]; + Assert.AreEqual("2", rootChildCalculation2.Name); + } + + [Test] + public void ReadAsGrassCoverErosionOutwardsWaveConditionsCalculationGroup_EntityWithChildGrassCoverErosionOutwardsWaveConditionsCalculationsAndGroups_CreateCalculationGroupWithChildCalculationsAndGroups() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + GrassCoverErosionOutwardsWaveConditionsCalculationEntities = + { + new GrassCoverErosionOutwardsWaveConditionsCalculationEntity + { + Order = 0, + Name = "calculation1" + }, + new GrassCoverErosionOutwardsWaveConditionsCalculationEntity + { + Order = 2, + Name = "calculation2" + } + }, + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Order = 1, + Name = "group1" + }, + new CalculationGroupEntity + { + Order = 3, + Name = "group2" + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup rootGroup = rootGroupEntity.ReadAsGrassCoverErosionOutwardsWaveConditionsCalculationGroup(collector); + + // Assert + List rootChildren = rootGroup.Children; + Assert.AreEqual(4, rootChildren.Count); + + var rootChildCalculation1 = (GrassCoverErosionOutwardsWaveConditionsCalculation) rootChildren[0]; + Assert.AreEqual("calculation1", rootChildCalculation1.Name); + + var rootChildGroup1 = (CalculationGroup) rootChildren[1]; + Assert.AreEqual("group1", rootChildGroup1.Name); + + var rootChildCalculation2 = (GrassCoverErosionOutwardsWaveConditionsCalculation) rootChildren[2]; + Assert.AreEqual("calculation2", rootChildCalculation2.Name); + + var rootChildGroup2 = (CalculationGroup) rootChildren[3]; + Assert.AreEqual("group2", rootChildGroup2.Name); + } + + #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] + public void ReadAsHeightStructuresCalculationGroup_EntityWithoutChildren_CreateCalculationGroupWithoutChildren() + { + // Setup + var entity = new CalculationGroupEntity + { + Name = "A" + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup group = entity.ReadAsHeightStructuresCalculationGroup(collector); + + // Assert + Assert.AreEqual(entity.Name, group.Name); + CollectionAssert.IsEmpty(group.Children); + } + + [Test] + public void ReadAsHeightStructuresCalculationGroup_EntityWithChildGroups_CreateCalculationGroupWithChildGroups() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Name = "AB", + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Name = "ABA", + Order = 0 + }, + new CalculationGroupEntity + { + Name = "ABB", + Order = 1 + } + }, + Order = 1 + }, + new CalculationGroupEntity + { + Name = "AA", + Order = 0 + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup rootGroup = rootGroupEntity.ReadAsHeightStructuresCalculationGroup(collector); + + // Assert + Assert.AreEqual("A", rootGroup.Name); + + List rootChildren = rootGroup.Children; + var rootChildGroup1 = (CalculationGroup) rootChildren[0]; + Assert.AreEqual("AA", rootChildGroup1.Name); + CollectionAssert.IsEmpty(rootChildGroup1.Children); + var rootChildGroup2 = (CalculationGroup) rootChildren[1]; + Assert.AreEqual("AB", rootChildGroup2.Name); + + List rootChildGroup2Children = rootChildGroup2.Children; + var rootChildGroup1Child1 = (CalculationGroup) rootChildGroup2Children[0]; + Assert.AreEqual("ABA", rootChildGroup1Child1.Name); + CollectionAssert.IsEmpty(rootChildGroup1Child1.Children); + var rootChildGroup1Child2 = (CalculationGroup) rootChildGroup2Children[1]; + Assert.AreEqual("ABB", rootChildGroup1Child2.Name); + CollectionAssert.IsEmpty(rootChildGroup1Child2.Children); + } + + [Test] + public void ReadAsHeightStructuresCalculationGroup_EntityWithChildHeightStructuresCalculations_CreateCalculationGroupWithChildCalculations() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + HeightStructuresCalculationEntities = + { + new HeightStructuresCalculationEntity + { + Order = 0, + Name = "1" + }, + new HeightStructuresCalculationEntity + { + Order = 1, + Name = "2" + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup rootGroup = rootGroupEntity.ReadAsHeightStructuresCalculationGroup(collector); + + // Assert + List rootChildren = rootGroup.Children; + Assert.AreEqual(2, rootChildren.Count); + + 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" + }, + new HeightStructuresCalculationEntity + { + Order = 2, + Name = "calculation2" + } + }, + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Order = 1, + Name = "group1" + }, + new CalculationGroupEntity + { + Order = 3, + Name = "group2" + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup rootGroup = rootGroupEntity.ReadAsHeightStructuresCalculationGroup(collector); + + // Assert + List rootChildren = rootGroup.Children; + Assert.AreEqual(4, rootChildren.Count); + + 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 ClosingStructures + + [Test] + public void ReadAsClosingStructuresCalculationGroup_CollectorIsNull_ThrowArgumentNullException() + { + // Setup + var entity = new CalculationGroupEntity(); + + // Call + TestDelegate call = () => entity.ReadAsClosingStructuresCalculationGroup(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void ReadAsClosingStructuresCalculationGroup_EntityWithoutChildren_CreateCalculationGroupWithoutChildren() + { + // Setup + var entity = new CalculationGroupEntity + { + Name = "A" + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup group = entity.ReadAsClosingStructuresCalculationGroup(collector); + + // Assert + Assert.AreEqual(entity.Name, group.Name); + CollectionAssert.IsEmpty(group.Children); + } + + [Test] + public void ReadAsClosingStructuresCalculationGroup_EntityWithChildGroups_CreateCalculationGroupWithChildGroups() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Name = "AB", + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Name = "ABA", + Order = 0 + }, + new CalculationGroupEntity + { + Name = "ABB", + Order = 1 + } + }, + Order = 1 + }, + new CalculationGroupEntity + { + Name = "AA", + Order = 0 + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup rootGroup = rootGroupEntity.ReadAsClosingStructuresCalculationGroup(collector); + + // Assert + Assert.AreEqual("A", rootGroup.Name); + + List rootChildren = rootGroup.Children; + var rootChildGroup1 = (CalculationGroup) rootChildren[0]; + Assert.AreEqual("AA", rootChildGroup1.Name); + CollectionAssert.IsEmpty(rootChildGroup1.Children); + var rootChildGroup2 = (CalculationGroup) rootChildren[1]; + Assert.AreEqual("AB", rootChildGroup2.Name); + + List rootChildGroup2Children = rootChildGroup2.Children; + var rootChildGroup1Child1 = (CalculationGroup) rootChildGroup2Children[0]; + Assert.AreEqual("ABA", rootChildGroup1Child1.Name); + CollectionAssert.IsEmpty(rootChildGroup1Child1.Children); + var rootChildGroup1Child2 = (CalculationGroup) rootChildGroup2Children[1]; + Assert.AreEqual("ABB", rootChildGroup1Child2.Name); + CollectionAssert.IsEmpty(rootChildGroup1Child2.Children); + } + + [Test] + public void ReadAsClosingStructuresCalculationGroup_EntityWithChildClosingStructuresCalculations_CreateCalculationGroupWithChildCalculations() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + ClosingStructuresCalculationEntities = + { + new ClosingStructuresCalculationEntity + { + Order = 0, + Name = "1", + IdenticalApertures = 1 + }, + new ClosingStructuresCalculationEntity + { + Order = 1, + Name = "2", + IdenticalApertures = 1 + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup rootGroup = rootGroupEntity.ReadAsClosingStructuresCalculationGroup(collector); + + // Assert + List rootChildren = rootGroup.Children; + Assert.AreEqual(2, rootChildren.Count); + + var rootChildCalculation1 = (StructuresCalculation) rootChildren[0]; + Assert.AreEqual("1", rootChildCalculation1.Name); + + var rootChildCalculation2 = (StructuresCalculation) rootChildren[1]; + Assert.AreEqual("2", rootChildCalculation2.Name); + } + + [Test] + public void ReadAsClosingStructuresCalculationGroup_EntityWithChildClosingStructuresCalculationAndGroups_CreateCalculationGroupWithChildCalculationsAndGroups() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + ClosingStructuresCalculationEntities = + { + new ClosingStructuresCalculationEntity + { + Order = 0, + Name = "calculation1", + IdenticalApertures = 1 + }, + new ClosingStructuresCalculationEntity + { + Order = 2, + Name = "calculation2", + IdenticalApertures = 1 + } + }, + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Order = 1, + Name = "group1" + }, + new CalculationGroupEntity + { + Order = 3, + Name = "group2" + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup rootGroup = rootGroupEntity.ReadAsClosingStructuresCalculationGroup(collector); + + // Assert + List rootChildren = rootGroup.Children; + Assert.AreEqual(4, rootChildren.Count); + + 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 StabilityPointStructures + + [Test] + public void ReadAsStabilityPointStructuresCalculationGroup_CollectorIsNull_ThrowArgumentNullException() + { + // Setup + var entity = new CalculationGroupEntity(); + + // Call + TestDelegate call = () => entity.ReadAsStabilityPointStructuresCalculationGroup(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void ReadAsStabilityPointStructuresCalculationGroup_EntityWithoutChildren_CreateCalculationGroupWithoutChildren() + { + // Setup + var entity = new CalculationGroupEntity + { + Name = "A" + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup group = entity.ReadAsStabilityPointStructuresCalculationGroup(collector); + + // Assert + Assert.AreEqual(entity.Name, group.Name); + CollectionAssert.IsEmpty(group.Children); + } + + [Test] + public void ReadAsStabilityPointStructuresCalculationGroup_EntityWithChildGroups_CreateCalculationGroupWithChildGroups() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Name = "AB", + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Name = "ABA", + Order = 0 + }, + new CalculationGroupEntity + { + Name = "ABB", + Order = 1 + } + }, + Order = 1 + }, + new CalculationGroupEntity + { + Name = "AA", + Order = 0 + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup rootGroup = rootGroupEntity.ReadAsStabilityPointStructuresCalculationGroup(collector); + + // Assert + Assert.AreEqual("A", rootGroup.Name); + + List rootChildren = rootGroup.Children; + var rootChildGroup1 = (CalculationGroup) rootChildren[0]; + Assert.AreEqual("AA", rootChildGroup1.Name); + CollectionAssert.IsEmpty(rootChildGroup1.Children); + var rootChildGroup2 = (CalculationGroup) rootChildren[1]; + Assert.AreEqual("AB", rootChildGroup2.Name); + + List rootChildGroup2Children = rootChildGroup2.Children; + var rootChildGroup1Child1 = (CalculationGroup) rootChildGroup2Children[0]; + Assert.AreEqual("ABA", rootChildGroup1Child1.Name); + CollectionAssert.IsEmpty(rootChildGroup1Child1.Children); + var rootChildGroup1Child2 = (CalculationGroup) rootChildGroup2Children[1]; + Assert.AreEqual("ABB", rootChildGroup1Child2.Name); + CollectionAssert.IsEmpty(rootChildGroup1Child2.Children); + } + + [Test] + public void ReadAsStabilityPointStructuresCalculationGroup_EntityWithChildStabilityPointStructuresCalculations_CreateCalculationGroupWithChildCalculations() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + StabilityPointStructuresCalculationEntities = + { + new StabilityPointStructuresCalculationEntity + { + Order = 0, + Name = "1" + }, + new StabilityPointStructuresCalculationEntity + { + Order = 1, + Name = "2" + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup rootGroup = rootGroupEntity.ReadAsStabilityPointStructuresCalculationGroup(collector); + + // Assert + List rootChildren = rootGroup.Children; + Assert.AreEqual(2, rootChildren.Count); + + var rootChildCalculation1 = (StructuresCalculation) rootChildren[0]; + Assert.AreEqual("1", rootChildCalculation1.Name); + + var rootChildCalculation2 = (StructuresCalculation) rootChildren[1]; + Assert.AreEqual("2", rootChildCalculation2.Name); + } + + [Test] + public void ReadAsStabilityPointStructuresCalculationGroup_EntityWithChildStabilityPointStructuresCalculationAndGroups_CreateCalculationGroupWithChildCalculationsAndGroups() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + StabilityPointStructuresCalculationEntities = + { + new StabilityPointStructuresCalculationEntity + { + Order = 0, + Name = "calculation1" + }, + new StabilityPointStructuresCalculationEntity + { + Order = 2, + Name = "calculation2" + } + }, + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Order = 1, + Name = "group1" + }, + new CalculationGroupEntity + { + Order = 3, + Name = "group2" + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup rootGroup = rootGroupEntity.ReadAsStabilityPointStructuresCalculationGroup(collector); + + // Assert + List rootChildren = rootGroup.Children; + Assert.AreEqual(4, rootChildren.Count); + + 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] + public void ReadAsStabilityStoneCoverWaveConditionsCalculationGroup_CollectorIsNull_ThrowArgumentNullException() + { + // Setup + var entity = new CalculationGroupEntity(); + + // Call + TestDelegate call = () => entity.ReadAsStabilityStoneCoverWaveConditionsCalculationGroup(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void ReadAsStabilityStoneCoverWaveConditionsCalculationGroup_EntityWithoutChildren_CreateCalculationGroupWithoutChildren() + { + // Setup + var entity = new CalculationGroupEntity + { + Name = "A" + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup group = entity.ReadAsStabilityStoneCoverWaveConditionsCalculationGroup(collector); + + // Assert + Assert.AreEqual(entity.Name, group.Name); + CollectionAssert.IsEmpty(group.Children); + } + + [Test] + public void ReadAsStabilityStoneCoverWaveConditionsCalculationGroup_EntityWithChildGroups_CreateCalculationGroupWithChildGroups() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Name = "AB", + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Name = "ABA", + Order = 0 + }, + new CalculationGroupEntity + { + Name = "ABB", + Order = 1 + } + }, + Order = 1 + }, + new CalculationGroupEntity + { + Name = "AA", + Order = 0 + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup rootGroup = rootGroupEntity.ReadAsStabilityStoneCoverWaveConditionsCalculationGroup(collector); + + // Assert + Assert.AreEqual("A", rootGroup.Name); + + List rootChildren = rootGroup.Children; + var rootChildGroup1 = (CalculationGroup) rootChildren[0]; + Assert.AreEqual("AA", rootChildGroup1.Name); + CollectionAssert.IsEmpty(rootChildGroup1.Children); + var rootChildGroup2 = (CalculationGroup) rootChildren[1]; + Assert.AreEqual("AB", rootChildGroup2.Name); + + List rootChildGroup2Children = rootChildGroup2.Children; + var rootChildGroup1Child1 = (CalculationGroup) rootChildGroup2Children[0]; + Assert.AreEqual("ABA", rootChildGroup1Child1.Name); + CollectionAssert.IsEmpty(rootChildGroup1Child1.Children); + var rootChildGroup1Child2 = (CalculationGroup) rootChildGroup2Children[1]; + Assert.AreEqual("ABB", rootChildGroup1Child2.Name); + CollectionAssert.IsEmpty(rootChildGroup1Child2.Children); + } + + [Test] + public void ReadAsStabilityStoneCoverWaveConditionsCalculationGroup_EntityWithChildStabilityStoneCoverWaveConditionsCalculations_CreateCalculationGroupWithChildCalculations() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + StabilityStoneCoverWaveConditionsCalculationEntities = + { + new StabilityStoneCoverWaveConditionsCalculationEntity + { + Order = 1, + Name = "2" + }, + new StabilityStoneCoverWaveConditionsCalculationEntity + { + Order = 0, + Name = "1" + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup rootGroup = rootGroupEntity.ReadAsStabilityStoneCoverWaveConditionsCalculationGroup(collector); + + // Assert + List rootChildren = rootGroup.Children; + Assert.AreEqual(2, rootChildren.Count); + + var rootChildCalculation1 = (StabilityStoneCoverWaveConditionsCalculation) rootChildren[0]; + Assert.AreEqual("1", rootChildCalculation1.Name); + + var rootChildCalculation2 = (StabilityStoneCoverWaveConditionsCalculation) rootChildren[1]; + Assert.AreEqual("2", rootChildCalculation2.Name); + } + + [Test] + public void ReadAsStabilityStoneCoverWaveConditionsCalculationGroup_EntityWithChildStabilityStoneCoverWaveConditionsCalculationsAndGroups_CreateCalculationGroupWithChildCalculationsAndGroups() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + StabilityStoneCoverWaveConditionsCalculationEntities = + { + new StabilityStoneCoverWaveConditionsCalculationEntity + { + Order = 0, + Name = "calculation1" + }, + new StabilityStoneCoverWaveConditionsCalculationEntity + { + Order = 2, + Name = "calculation2" + } + }, + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Order = 3, + Name = "group2" + }, + new CalculationGroupEntity + { + Order = 1, + Name = "group1" + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup rootGroup = rootGroupEntity.ReadAsStabilityStoneCoverWaveConditionsCalculationGroup(collector); + + // Assert + List rootChildren = rootGroup.Children; + Assert.AreEqual(4, rootChildren.Count); + + var rootChildCalculation1 = (StabilityStoneCoverWaveConditionsCalculation) rootChildren[0]; + Assert.AreEqual("calculation1", rootChildCalculation1.Name); + + var rootChildGroup1 = (CalculationGroup) rootChildren[1]; + Assert.AreEqual("group1", rootChildGroup1.Name); + + var rootChildCalculation2 = (StabilityStoneCoverWaveConditionsCalculation) rootChildren[2]; + Assert.AreEqual("calculation2", rootChildCalculation2.Name); + + var rootChildGroup2 = (CalculationGroup) rootChildren[3]; + Assert.AreEqual("group2", rootChildGroup2.Name); + } + + #endregion + + #region Wave Impact Asphalt Cover + + [Test] + public void ReadAsWaveImpactAsphaltCoverWaveConditionsCalculationGroup_CollectorIsNull_ThrowArgumentNullException() + { + // Setup + var entity = new CalculationGroupEntity(); + + // Call + TestDelegate call = () => entity.ReadAsWaveImpactAsphaltCoverWaveConditionsCalculationGroup(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void ReadAsWaveImpactAsphaltCoverWaveConditionsCalculationGroup_EntityWithoutChildren_CreateCalculationGroupWithoutChildren() + { + // Setup + var entity = new CalculationGroupEntity + { + Name = "A" + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup group = entity.ReadAsWaveImpactAsphaltCoverWaveConditionsCalculationGroup(collector); + + // Assert + Assert.AreEqual(entity.Name, group.Name); + CollectionAssert.IsEmpty(group.Children); + } + + [Test] + public void ReadAsWaveImpactAsphaltCoverWaveConditionsCalculationGroup_EntityWithChildGroups_CreateCalculationGroupWithChildGroups() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Name = "AB", + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Name = "ABA", + Order = 0 + }, + new CalculationGroupEntity + { + Name = "ABB", + Order = 1 + } + }, + Order = 1 + }, + new CalculationGroupEntity + { + Name = "AA", + Order = 0 + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup rootGroup = rootGroupEntity.ReadAsWaveImpactAsphaltCoverWaveConditionsCalculationGroup(collector); + + // Assert + Assert.AreEqual("A", rootGroup.Name); + + List rootChildren = rootGroup.Children; + var rootChildGroup1 = (CalculationGroup) rootChildren[0]; + Assert.AreEqual("AA", rootChildGroup1.Name); + CollectionAssert.IsEmpty(rootChildGroup1.Children); + var rootChildGroup2 = (CalculationGroup) rootChildren[1]; + Assert.AreEqual("AB", rootChildGroup2.Name); + + List rootChildGroup2Children = rootChildGroup2.Children; + var rootChildGroup1Child1 = (CalculationGroup) rootChildGroup2Children[0]; + Assert.AreEqual("ABA", rootChildGroup1Child1.Name); + CollectionAssert.IsEmpty(rootChildGroup1Child1.Children); + var rootChildGroup1Child2 = (CalculationGroup) rootChildGroup2Children[1]; + Assert.AreEqual("ABB", rootChildGroup1Child2.Name); + CollectionAssert.IsEmpty(rootChildGroup1Child2.Children); + } + + [Test] + public void ReadAsWaveImpactAsphaltCoverWaveConditionsCalculationGroup_EntityWithChildWaveImpactAsphaltCoverWaveConditionsCalculations_CreateCalculationGroupWithChildCalculations() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + WaveImpactAsphaltCoverWaveConditionsCalculationEntities = + { + new WaveImpactAsphaltCoverWaveConditionsCalculationEntity + { + Order = 1, + Name = "2" + }, + new WaveImpactAsphaltCoverWaveConditionsCalculationEntity + { + Order = 0, + Name = "1" + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup rootGroup = rootGroupEntity.ReadAsWaveImpactAsphaltCoverWaveConditionsCalculationGroup(collector); + + // Assert + List rootChildren = rootGroup.Children; + Assert.AreEqual(2, rootChildren.Count); + + var rootChildCalculation1 = (WaveImpactAsphaltCoverWaveConditionsCalculation) rootChildren[0]; + Assert.AreEqual("1", rootChildCalculation1.Name); + + var rootChildCalculation2 = (WaveImpactAsphaltCoverWaveConditionsCalculation) rootChildren[1]; + Assert.AreEqual("2", rootChildCalculation2.Name); + } + + [Test] + public void ReadAsWaveImpactAsphaltCoverWaveConditionsCalculationGroup_EntityWithChildWaveImpactAsphaltCoverWaveConditionsCalculationsAndGroups_CreateCalculationGroupWithChildCalculationsAndGroups() + { + // Setup + var rootGroupEntity = new CalculationGroupEntity + { + Name = "A", + WaveImpactAsphaltCoverWaveConditionsCalculationEntities = + { + new WaveImpactAsphaltCoverWaveConditionsCalculationEntity + { + Order = 0, + Name = "calculation1" + }, + new WaveImpactAsphaltCoverWaveConditionsCalculationEntity + { + Order = 2, + Name = "calculation2" + } + }, + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Order = 3, + Name = "group2" + }, + new CalculationGroupEntity + { + Order = 1, + Name = "group1" + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + CalculationGroup rootGroup = rootGroupEntity.ReadAsWaveImpactAsphaltCoverWaveConditionsCalculationGroup(collector); + + // Assert + List rootChildren = rootGroup.Children; + Assert.AreEqual(4, rootChildren.Count); + + var rootChildCalculation1 = (WaveImpactAsphaltCoverWaveConditionsCalculation) rootChildren[0]; + Assert.AreEqual("calculation1", rootChildCalculation1.Name); + + var rootChildGroup1 = (CalculationGroup) rootChildren[1]; + Assert.AreEqual("group1", rootChildGroup1.Name); + + var rootChildCalculation2 = (WaveImpactAsphaltCoverWaveConditionsCalculation) rootChildren[2]; + Assert.AreEqual("calculation2", rootChildCalculation2.Name); + + var rootChildGroup2 = (CalculationGroup) rootChildren[3]; + Assert.AreEqual("group2", rootChildGroup2.Name); + } + + #endregion + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/ClosingStructures/ClosingStructureEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/ClosingStructures/ClosingStructureEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/ClosingStructures/ClosingStructureEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,228 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.ClosingStructures.Data; +using Ringtoets.ClosingStructures.Data.TestUtil; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Read.ClosingStructures; + +namespace Riskeer.Storage.Core.Test.Read.ClosingStructures +{ + [TestFixture] + public class ClosingStructureEntityReadExtensionsTest + { + [Test] + public void Read_ReadConversionCollectorNull_ThrowArgumentNullException() + { + // Setup + var entity = new ClosingStructureEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void Read_EntityNotReadBefore_RegisterEntity() + { + // Setup + var entity = new ClosingStructureEntity + { + Name = "name", + Id = "id" + }; + + var collector = new ReadConversionCollector(); + + // Precondition + Assert.IsFalse(collector.Contains(entity)); + + // Call + ClosingStructure calculation = entity.Read(collector); + + // Assert + Assert.IsTrue(collector.Contains(entity)); + Assert.AreSame(calculation, collector.Get(entity)); + } + + [Test] + public void Read_ValidEntity_ReturnClosingStructure() + { + // Setup + var entity = new ClosingStructureEntity + { + Name = "A", + Id = "B", + X = 1.1, + Y = 2.2, + StructureNormalOrientation = 3.3, + StorageStructureAreaMean = 4.4, + StorageStructureAreaCoefficientOfVariation = 5.5, + AllowedLevelIncreaseStorageMean = 6.6, + AllowedLevelIncreaseStorageStandardDeviation = 7.7, + WidthFlowAperturesMean = 8.8, + WidthFlowAperturesStandardDeviation = 9.9, + LevelCrestStructureNotClosingMean = 10.10, + LevelCrestStructureNotClosingStandardDeviation = 11.11, + InsideWaterLevelMean = 12.12, + InsideWaterLevelStandardDeviation = 13.13, + ThresholdHeightOpenWeirMean = 14.14, + ThresholdHeightOpenWeirStandardDeviation = 15.15, + AreaFlowAperturesMean = 16.16, + AreaFlowAperturesStandardDeviation = 17.17, + CriticalOvertoppingDischargeMean = 18.18, + CriticalOvertoppingDischargeCoefficientOfVariation = 19.19, + FlowWidthAtBottomProtectionMean = 20.20, + FlowWidthAtBottomProtectionStandardDeviation = 21.21, + ProbabilityOpenStructureBeforeFlooding = 22.22, + FailureProbabilityOpenStructure = 23.23, + IdenticalApertures = 24, + FailureProbabilityReparation = 25.25, + InflowModelType = Convert.ToByte(ClosingStructureInflowModelType.FloodedCulvert) + }; + + var collector = new ReadConversionCollector(); + + // Call + ClosingStructure structure = entity.Read(collector); + + // Assert + Assert.AreEqual(entity.Name, structure.Name); + Assert.AreEqual(entity.Id, structure.Id); + Assert.AreEqual(entity.X, structure.Location.X); + Assert.AreEqual(entity.Y, structure.Location.Y); + Assert.AreEqual(entity.StructureNormalOrientation, structure.StructureNormalOrientation.Value); + Assert.AreEqual(entity.StorageStructureAreaMean, structure.StorageStructureArea.Mean.Value); + Assert.AreEqual(entity.StorageStructureAreaCoefficientOfVariation, structure.StorageStructureArea.CoefficientOfVariation.Value); + Assert.AreEqual(entity.AllowedLevelIncreaseStorageMean, structure.AllowedLevelIncreaseStorage.Mean.Value); + Assert.AreEqual(entity.AllowedLevelIncreaseStorageStandardDeviation, structure.AllowedLevelIncreaseStorage.StandardDeviation.Value); + Assert.AreEqual(entity.WidthFlowAperturesMean, structure.WidthFlowApertures.Mean.Value); + Assert.AreEqual(entity.WidthFlowAperturesStandardDeviation, structure.WidthFlowApertures.StandardDeviation.Value); + Assert.AreEqual(entity.LevelCrestStructureNotClosingMean, structure.LevelCrestStructureNotClosing.Mean.Value); + Assert.AreEqual(entity.LevelCrestStructureNotClosingStandardDeviation, structure.LevelCrestStructureNotClosing.StandardDeviation.Value); + Assert.AreEqual(entity.InsideWaterLevelMean, structure.InsideWaterLevel.Mean.Value); + Assert.AreEqual(entity.InsideWaterLevelStandardDeviation, structure.InsideWaterLevel.StandardDeviation.Value); + Assert.AreEqual(entity.ThresholdHeightOpenWeirMean, structure.ThresholdHeightOpenWeir.Mean.Value); + Assert.AreEqual(entity.ThresholdHeightOpenWeirStandardDeviation, structure.ThresholdHeightOpenWeir.StandardDeviation.Value); + Assert.AreEqual(entity.AreaFlowAperturesMean, structure.AreaFlowApertures.Mean.Value); + Assert.AreEqual(entity.AreaFlowAperturesStandardDeviation, structure.AreaFlowApertures.StandardDeviation.Value); + Assert.AreEqual(entity.CriticalOvertoppingDischargeMean, structure.CriticalOvertoppingDischarge.Mean.Value); + Assert.AreEqual(entity.CriticalOvertoppingDischargeCoefficientOfVariation, structure.CriticalOvertoppingDischarge.CoefficientOfVariation.Value); + Assert.AreEqual(entity.FlowWidthAtBottomProtectionMean, structure.FlowWidthAtBottomProtection.Mean.Value); + Assert.AreEqual(entity.FlowWidthAtBottomProtectionStandardDeviation, structure.FlowWidthAtBottomProtection.StandardDeviation.Value); + Assert.AreEqual(entity.ProbabilityOpenStructureBeforeFlooding, structure.ProbabilityOpenStructureBeforeFlooding); + Assert.AreEqual(entity.FailureProbabilityOpenStructure, structure.FailureProbabilityOpenStructure); + Assert.AreEqual(entity.IdenticalApertures, structure.IdenticalApertures); + Assert.AreEqual(entity.FailureProbabilityReparation, structure.FailureProbabilityReparation); + Assert.AreEqual((ClosingStructureInflowModelType) entity.InflowModelType, structure.InflowModelType); + + Assert.IsTrue(collector.Contains(entity)); + } + + [Test] + public void Read_NullValues_ReturnClosingStructureWithNaN() + { + // Setup + var entity = new ClosingStructureEntity + { + Name = "A", + Id = "B", + X = null, + Y = null, + StructureNormalOrientation = null, + StorageStructureAreaMean = null, + StorageStructureAreaCoefficientOfVariation = null, + AllowedLevelIncreaseStorageMean = null, + AllowedLevelIncreaseStorageStandardDeviation = null, + WidthFlowAperturesMean = null, + WidthFlowAperturesStandardDeviation = null, + LevelCrestStructureNotClosingMean = null, + LevelCrestStructureNotClosingStandardDeviation = null, + InsideWaterLevelMean = null, + InsideWaterLevelStandardDeviation = null, + ThresholdHeightOpenWeirMean = null, + ThresholdHeightOpenWeirStandardDeviation = null, + AreaFlowAperturesMean = null, + AreaFlowAperturesStandardDeviation = null, + CriticalOvertoppingDischargeMean = null, + CriticalOvertoppingDischargeCoefficientOfVariation = null, + FlowWidthAtBottomProtectionMean = null, + FlowWidthAtBottomProtectionStandardDeviation = null, + ProbabilityOpenStructureBeforeFlooding = null, + FailureProbabilityOpenStructure = null + }; + + var collector = new ReadConversionCollector(); + + // Call + ClosingStructure structure = entity.Read(collector); + + // Assert + Assert.IsNaN(structure.Location.X); + Assert.IsNaN(structure.Location.Y); + Assert.IsNaN(structure.StructureNormalOrientation); + + Assert.IsNaN(structure.StorageStructureArea.Mean); + Assert.IsNaN(structure.StorageStructureArea.CoefficientOfVariation); + Assert.IsNaN(structure.AllowedLevelIncreaseStorage.Mean); + Assert.IsNaN(structure.AllowedLevelIncreaseStorage.StandardDeviation); + Assert.IsNaN(structure.WidthFlowApertures.Mean); + Assert.IsNaN(structure.WidthFlowApertures.StandardDeviation); + Assert.IsNaN(structure.LevelCrestStructureNotClosing.Mean); + Assert.IsNaN(structure.LevelCrestStructureNotClosing.StandardDeviation); + Assert.IsNaN(structure.InsideWaterLevel.Mean); + Assert.IsNaN(structure.InsideWaterLevel.StandardDeviation); + Assert.IsNaN(structure.ThresholdHeightOpenWeir.Mean); + Assert.IsNaN(structure.ThresholdHeightOpenWeir.StandardDeviation); + Assert.IsNaN(structure.AreaFlowApertures.Mean); + Assert.IsNaN(structure.AreaFlowApertures.StandardDeviation); + Assert.IsNaN(structure.CriticalOvertoppingDischarge.Mean); + Assert.IsNaN(structure.CriticalOvertoppingDischarge.CoefficientOfVariation); + Assert.IsNaN(structure.FlowWidthAtBottomProtection.Mean); + Assert.IsNaN(structure.FlowWidthAtBottomProtection.StandardDeviation); + Assert.IsNaN(structure.ProbabilityOpenStructureBeforeFlooding); + Assert.IsNaN(structure.FailureProbabilityOpenStructure); + Assert.IsNaN(structure.FailureProbabilityReparation); + } + + [Test] + public void Read_EntityRegistered_ReturnRegisteredStructure() + { + // Setup + var entity = new ClosingStructureEntity(); + ClosingStructure registeredStructure = new TestClosingStructure(); + var collector = new ReadConversionCollector(); + collector.Read(entity, registeredStructure); + + // Call + ClosingStructure readStructure = entity.Read(collector); + + // Assert + Assert.AreSame(registeredStructure, readStructure); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/ClosingStructures/ClosingStructuresCalculationEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/ClosingStructures/ClosingStructuresCalculationEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/ClosingStructures/ClosingStructuresCalculationEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,350 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.ClosingStructures.Data; +using Ringtoets.ClosingStructures.Data.TestUtil; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Read.ClosingStructures; + +namespace Riskeer.Storage.Core.Test.Read.ClosingStructures +{ + [TestFixture] + public class ClosingStructuresCalculationEntityReadExtensionsTest + { + [Test] + public void Read_ReadConversionCollectorNull_ThrowArgumentNullException() + { + // Setup + var entity = new ClosingStructuresCalculationEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void Read_EntityNotReadBefore_RegisterEntity() + { + // Setup + var entity = new ClosingStructuresCalculationEntity + { + IdenticalApertures = 1 + }; + + var collector = new ReadConversionCollector(); + + // Precondition + Assert.IsFalse(collector.Contains(entity)); + + // Call + StructuresCalculation calculation = entity.Read(collector); + + // Assert + Assert.IsTrue(collector.Contains(entity)); + Assert.AreSame(calculation, collector.Get(entity)); + } + + [Test] + public void Read_ValidEntity_ReturnClosingStructuresCalculation() + { + // Setup + var entity = new ClosingStructuresCalculationEntity + { + Name = "name", + Comments = "comments", + StructureNormalOrientation = 1.1, + ModelFactorSuperCriticalFlowMean = 2.2, + AllowedLevelIncreaseStorageMean = 3.3, + AllowedLevelIncreaseStorageStandardDeviation = 4.4, + StorageStructureAreaMean = 5.5, + StorageStructureAreaCoefficientOfVariation = 6.6, + FlowWidthAtBottomProtectionMean = 7.7, + FlowWidthAtBottomProtectionStandardDeviation = 8.8, + CriticalOvertoppingDischargeMean = 9.9, + CriticalOvertoppingDischargeCoefficientOfVariation = 10.10, + FailureProbabilityStructureWithErosion = 0.11, + WidthFlowAperturesMean = 12.12, + WidthFlowAperturesStandardDeviation = 13.13, + StormDurationMean = 14.14, + UseBreakWater = Convert.ToByte(true), + BreakWaterType = Convert.ToByte(BreakWaterType.Wall), + BreakWaterHeight = 15.15, + UseForeshore = Convert.ToByte(true), + InflowModelType = Convert.ToByte(ClosingStructureInflowModelType.LowSill), + InsideWaterLevelMean = 16.16, + InsideWaterLevelStandardDeviation = 17.17, + DeviationWaveDirection = 18.18, + DrainCoefficientMean = 19.19, + FactorStormDurationOpenStructure = 20.20, + ThresholdHeightOpenWeirMean = 21.21, + ThresholdHeightOpenWeirStandardDeviation = 22.22, + AreaFlowAperturesMean = 23.23, + AreaFlowAperturesStandardDeviation = 24.24, + FailureProbabilityOpenStructure = 0.25, + FailureProbabilityReparation = 0.26, + IdenticalApertures = 27, + LevelCrestStructureNotClosingMean = 28.28, + LevelCrestStructureNotClosingStandardDeviation = 29.29, + ProbabilityOpenStructureBeforeFlooding = 0.30 + }; + var collector = new ReadConversionCollector(); + + // Call + StructuresCalculation calculation = entity.Read(collector); + + // Assert + Assert.AreEqual(entity.Name, calculation.Name); + Assert.AreEqual(entity.Comments, calculation.Comments.Body); + + ClosingStructuresInput inputParameters = calculation.InputParameters; + Assert.IsNull(inputParameters.ForeshoreProfile); + Assert.IsNull(inputParameters.Structure); + Assert.IsNull(inputParameters.HydraulicBoundaryLocation); + Assert.AreEqual(entity.StructureNormalOrientation, inputParameters.StructureNormalOrientation.Value); + Assert.AreEqual(entity.ModelFactorSuperCriticalFlowMean, inputParameters.ModelFactorSuperCriticalFlow.Mean.Value); + Assert.AreEqual(entity.AllowedLevelIncreaseStorageMean, inputParameters.AllowedLevelIncreaseStorage.Mean.Value); + Assert.AreEqual(entity.AllowedLevelIncreaseStorageStandardDeviation, inputParameters.AllowedLevelIncreaseStorage.StandardDeviation.Value); + Assert.AreEqual(entity.StorageStructureAreaMean, inputParameters.StorageStructureArea.Mean.Value); + Assert.AreEqual(entity.StorageStructureAreaCoefficientOfVariation, inputParameters.StorageStructureArea.CoefficientOfVariation.Value); + Assert.AreEqual(entity.FlowWidthAtBottomProtectionMean, inputParameters.FlowWidthAtBottomProtection.Mean.Value); + Assert.AreEqual(entity.FlowWidthAtBottomProtectionStandardDeviation, inputParameters.FlowWidthAtBottomProtection.StandardDeviation.Value); + Assert.AreEqual(entity.CriticalOvertoppingDischargeMean, inputParameters.CriticalOvertoppingDischarge.Mean.Value); + Assert.AreEqual(entity.CriticalOvertoppingDischargeCoefficientOfVariation, inputParameters.CriticalOvertoppingDischarge.CoefficientOfVariation.Value); + Assert.AreEqual(entity.FailureProbabilityStructureWithErosion, inputParameters.FailureProbabilityStructureWithErosion); + Assert.AreEqual(entity.WidthFlowAperturesMean, inputParameters.WidthFlowApertures.Mean.Value); + Assert.AreEqual(entity.WidthFlowAperturesStandardDeviation, inputParameters.WidthFlowApertures.StandardDeviation.Value); + Assert.AreEqual(entity.StormDurationMean, inputParameters.StormDuration.Mean.Value); + Assert.AreEqual(Convert.ToBoolean(entity.UseBreakWater), inputParameters.UseBreakWater); + Assert.AreEqual((BreakWaterType) entity.BreakWaterType, inputParameters.BreakWater.Type); + Assert.AreEqual(entity.BreakWaterHeight, inputParameters.BreakWater.Height.Value); + Assert.AreEqual(Convert.ToBoolean(entity.UseForeshore), inputParameters.UseForeshore); + + Assert.AreEqual((ClosingStructureInflowModelType) entity.InflowModelType, inputParameters.InflowModelType); + Assert.AreEqual(entity.InsideWaterLevelMean, inputParameters.InsideWaterLevel.Mean.Value); + Assert.AreEqual(entity.InsideWaterLevelStandardDeviation, inputParameters.InsideWaterLevel.StandardDeviation.Value); + Assert.AreEqual(entity.DeviationWaveDirection, inputParameters.DeviationWaveDirection.Value); + Assert.AreEqual(entity.DrainCoefficientMean, inputParameters.DrainCoefficient.Mean.Value); + Assert.AreEqual(entity.FactorStormDurationOpenStructure, inputParameters.FactorStormDurationOpenStructure.Value); + Assert.AreEqual(entity.ThresholdHeightOpenWeirMean, inputParameters.ThresholdHeightOpenWeir.Mean.Value); + Assert.AreEqual(entity.ThresholdHeightOpenWeirStandardDeviation, inputParameters.ThresholdHeightOpenWeir.StandardDeviation.Value); + Assert.AreEqual(entity.AreaFlowAperturesMean, inputParameters.AreaFlowApertures.Mean.Value); + Assert.AreEqual(entity.AreaFlowAperturesStandardDeviation, inputParameters.AreaFlowApertures.StandardDeviation.Value); + Assert.AreEqual(entity.FailureProbabilityOpenStructure, inputParameters.FailureProbabilityOpenStructure); + Assert.AreEqual(entity.FailureProbabilityReparation, inputParameters.FailureProbabilityReparation); + Assert.AreEqual(entity.IdenticalApertures, inputParameters.IdenticalApertures); + Assert.AreEqual(entity.LevelCrestStructureNotClosingMean, inputParameters.LevelCrestStructureNotClosing.Mean.Value); + Assert.AreEqual(entity.LevelCrestStructureNotClosingStandardDeviation, inputParameters.LevelCrestStructureNotClosing.StandardDeviation.Value); + Assert.AreEqual(entity.ProbabilityOpenStructureBeforeFlooding, inputParameters.ProbabilityOpenStructureBeforeFlooding); + Assert.IsFalse(calculation.HasOutput); + } + + [Test] + public void Read_EntityWithNullParameters_ReturnClosingStructuresCalculationWithInputParametersNaN() + { + // Setup + var entity = new ClosingStructuresCalculationEntity + { + StructureNormalOrientation = null, + ModelFactorSuperCriticalFlowMean = null, + AllowedLevelIncreaseStorageMean = null, + AllowedLevelIncreaseStorageStandardDeviation = null, + StorageStructureAreaMean = null, + StorageStructureAreaCoefficientOfVariation = null, + FlowWidthAtBottomProtectionMean = null, + FlowWidthAtBottomProtectionStandardDeviation = null, + CriticalOvertoppingDischargeMean = null, + CriticalOvertoppingDischargeCoefficientOfVariation = null, + WidthFlowAperturesMean = null, + WidthFlowAperturesStandardDeviation = null, + StormDurationMean = null, + BreakWaterHeight = null, + InsideWaterLevelMean = null, + InsideWaterLevelStandardDeviation = null, + DeviationWaveDirection = null, + DrainCoefficientMean = null, + FactorStormDurationOpenStructure = null, + ThresholdHeightOpenWeirMean = null, + ThresholdHeightOpenWeirStandardDeviation = null, + AreaFlowAperturesMean = null, + AreaFlowAperturesStandardDeviation = null, + LevelCrestStructureNotClosingMean = null, + LevelCrestStructureNotClosingStandardDeviation = null, + IdenticalApertures = 1 + }; + var collector = new ReadConversionCollector(); + + // Call + StructuresCalculation calculation = entity.Read(collector); + + // Assert + ClosingStructuresInput inputParameters = calculation.InputParameters; + Assert.IsNaN(inputParameters.StructureNormalOrientation); + Assert.IsNaN(inputParameters.ModelFactorSuperCriticalFlow.Mean); + Assert.IsNaN(inputParameters.AllowedLevelIncreaseStorage.Mean); + Assert.IsNaN(inputParameters.AllowedLevelIncreaseStorage.StandardDeviation); + Assert.IsNaN(inputParameters.StorageStructureArea.Mean); + Assert.IsNaN(inputParameters.StorageStructureArea.CoefficientOfVariation); + Assert.IsNaN(inputParameters.FlowWidthAtBottomProtection.Mean); + Assert.IsNaN(inputParameters.FlowWidthAtBottomProtection.StandardDeviation); + Assert.IsNaN(inputParameters.CriticalOvertoppingDischarge.Mean); + Assert.IsNaN(inputParameters.CriticalOvertoppingDischarge.CoefficientOfVariation); + Assert.IsNaN(inputParameters.WidthFlowApertures.Mean); + Assert.IsNaN(inputParameters.WidthFlowApertures.StandardDeviation); + Assert.IsNaN(inputParameters.StormDuration.Mean); + Assert.IsNaN(inputParameters.BreakWater.Height); + + Assert.IsNaN(inputParameters.InsideWaterLevel.Mean); + Assert.IsNaN(inputParameters.InsideWaterLevel.StandardDeviation); + Assert.IsNaN(inputParameters.DeviationWaveDirection); + Assert.IsNaN(inputParameters.DrainCoefficient.Mean); + Assert.IsNaN(inputParameters.FactorStormDurationOpenStructure); + Assert.IsNaN(inputParameters.ThresholdHeightOpenWeir.Mean); + Assert.IsNaN(inputParameters.ThresholdHeightOpenWeir.StandardDeviation); + Assert.IsNaN(inputParameters.AreaFlowApertures.Mean); + Assert.IsNaN(inputParameters.AreaFlowApertures.StandardDeviation); + Assert.IsNaN(inputParameters.LevelCrestStructureNotClosing.Mean); + Assert.IsNaN(inputParameters.LevelCrestStructureNotClosing.StandardDeviation); + } + + [Test] + public void Read_EntityWithStructureEntity_ReturnCalculationWithStructure() + { + // Setup + ClosingStructure structure = new TestClosingStructure(); + var structureEntity = new ClosingStructureEntity(); + var entity = new ClosingStructuresCalculationEntity + { + ClosingStructureEntity = structureEntity, + IdenticalApertures = 1 + }; + var collector = new ReadConversionCollector(); + collector.Read(structureEntity, structure); + + // Call + StructuresCalculation calculation = entity.Read(collector); + + // Assert + Assert.AreSame(structure, calculation.InputParameters.Structure); + } + + [Test] + public void Read_EntityWithHydraulicLocationEntity_ReturnCalculationWithHydraulicBoundaryLocation() + { + // Setup + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "A", 2, 3); + var hydraulicLocationEntity = new HydraulicLocationEntity(); + var entity = new ClosingStructuresCalculationEntity + { + HydraulicLocationEntity = hydraulicLocationEntity, + IdenticalApertures = 1 + }; + + var collector = new ReadConversionCollector(); + collector.Read(hydraulicLocationEntity, hydraulicBoundaryLocation); + + // Call + StructuresCalculation calculation = entity.Read(collector); + + // Assert + Assert.AreSame(hydraulicBoundaryLocation, calculation.InputParameters.HydraulicBoundaryLocation); + } + + [Test] + public void Read_EntityWithForeshoreProfileEntity_ReturnCalculationWithForeshoreProfile() + { + // Setup + var profile = new TestForeshoreProfile(); + var profileEntity = new ForeshoreProfileEntity(); + var entity = new ClosingStructuresCalculationEntity + { + ForeshoreProfileEntity = profileEntity, + IdenticalApertures = 1 + }; + + var collector = new ReadConversionCollector(); + collector.Read(profileEntity, profile); + + // Call + StructuresCalculation calculation = entity.Read(collector); + + // Assert + Assert.AreSame(profile, calculation.InputParameters.ForeshoreProfile); + } + + [Test] + public void Read_ValidEntityWithOutputEntity_ReturnCalculationWithOutput() + { + // Setup + var entity = new ClosingStructuresCalculationEntity + { + ClosingStructuresOutputEntities = + { + new ClosingStructuresOutputEntity() + }, + IdenticalApertures = 1 + }; + + var collector = new ReadConversionCollector(); + + // Call + StructuresCalculation calculation = entity.Read(collector); + + // Assert + StructuresOutput calculationOutput = calculation.Output; + Assert.IsNaN(calculationOutput.Reliability); + Assert.IsFalse(calculationOutput.HasGeneralResult); + } + + [Test] + public void Read_CalculationEntityAlreadyRead_ReturnReadCalculation() + { + // Setup + var entity = new ClosingStructuresCalculationEntity + { + ClosingStructuresOutputEntities = + { + new ClosingStructuresOutputEntity() + } + }; + + var calculation = new StructuresCalculation(); + + var collector = new ReadConversionCollector(); + collector.Read(entity, calculation); + + // Call + StructuresCalculation returnedCalculation = entity.Read(collector); + + // Assert + Assert.AreSame(calculation, returnedCalculation); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/ClosingStructures/ClosingStructuresFailureMechanismMetaEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/ClosingStructures/ClosingStructuresFailureMechanismMetaEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/ClosingStructures/ClosingStructuresFailureMechanismMetaEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,60 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.ClosingStructures.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.ClosingStructures; + +namespace Riskeer.Storage.Core.Test.Read.ClosingStructures +{ + [TestFixture] + public class ClosingStructuresFailureMechanismMetaEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => ((ClosingStructuresFailureMechanismMetaEntity) null).Read(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_Always_ReturnGeneralClosingStructuresInput() + { + // Setup + var entity = new ClosingStructuresFailureMechanismMetaEntity + { + N2A = new Random(39).Next(1, 40) + }; + + // Call + GeneralClosingStructuresInput generalInput = entity.Read(); + + // Assert + Assert.AreEqual(entity.N2A, generalInput.N2A); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/ClosingStructures/ClosingStructuresSectionResultEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/ClosingStructures/ClosingStructuresSectionResultEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/ClosingStructures/ClosingStructuresSectionResultEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,168 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.ClosingStructures.Data; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Read.ClosingStructures; + +namespace Riskeer.Storage.Core.Test.Read.ClosingStructures +{ + [TestFixture] + public class ClosingStructuresSectionResultEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((ClosingStructuresSectionResultEntity) null).Read( + new ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), + new ReadConversionCollector()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_SectionResultNull_ThrowsArgumentNullException() + { + // Setup + var entity = new ClosingStructuresSectionResultEntity(); + + // Call + TestDelegate call = () => entity.Read(null, new ReadConversionCollector()); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("sectionResult", paramName); + } + + [Test] + public void Read_CollectorNull_ThrowsArgumentNullException() + { + // Setup + var entity = new ClosingStructuresSectionResultEntity(); + + // Call + TestDelegate call = () => entity.Read(new ClosingStructuresFailureMechanismSectionResult( + FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void Read_ParameterValues_SectionResultWithParameterValues() + { + // Setup + var random = new Random(21); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResult = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + double tailorMadeAssessmentProbability = random.NextDouble(); + bool useManualAssembly = random.NextBoolean(); + double manualAssemblyProbability = random.NextDouble(); + + var collector = new ReadConversionCollector(); + + var failureMechanismSectionEntity = new FailureMechanismSectionEntity(); + collector.Read(failureMechanismSectionEntity, FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + var entity = new ClosingStructuresSectionResultEntity + { + FailureMechanismSectionEntity = failureMechanismSectionEntity, + SimpleAssessmentResult = Convert.ToByte(simpleAssessmentResult), + DetailedAssessmentResult = Convert.ToByte(detailedAssessmentResult), + TailorMadeAssessmentResult = Convert.ToByte(tailorMadeAssessmentResult), + TailorMadeAssessmentProbability = tailorMadeAssessmentProbability, + UseManualAssembly = Convert.ToByte(useManualAssembly), + ManualAssemblyProbability = manualAssemblyProbability + }; + var sectionResult = new ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult, collector); + + // Assert + Assert.AreEqual(simpleAssessmentResult, sectionResult.SimpleAssessmentResult); + Assert.AreEqual(detailedAssessmentResult, sectionResult.DetailedAssessmentResult); + Assert.AreEqual(tailorMadeAssessmentResult, sectionResult.TailorMadeAssessmentResult); + Assert.AreEqual(tailorMadeAssessmentProbability, sectionResult.TailorMadeAssessmentProbability, 1e-6); + Assert.AreEqual(useManualAssembly, sectionResult.UseManualAssembly); + Assert.AreEqual(manualAssemblyProbability, sectionResult.ManualAssemblyProbability, 1e-6); + Assert.IsNull(sectionResult.Calculation); + } + + [Test] + public void Read_EntityWithNullValues_SectionResultWithNaNValues() + { + // Setup + var collector = new ReadConversionCollector(); + + var failureMechanismSectionEntity = new FailureMechanismSectionEntity(); + collector.Read(failureMechanismSectionEntity, FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + var entity = new ClosingStructuresSectionResultEntity + { + FailureMechanismSectionEntity = failureMechanismSectionEntity + }; + var sectionResult = new ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult, collector); + + // Assert + Assert.IsNaN(sectionResult.TailorMadeAssessmentProbability); + Assert.IsNaN(sectionResult.ManualAssemblyProbability); + Assert.IsNull(sectionResult.Calculation); + } + + [Test] + public void Read_CalculationEntitySet_ReturnClosingStructuresSectionResultWithCalculation() + { + // Setup + var calculation = new StructuresCalculation(); + + var calculationEntity = new ClosingStructuresCalculationEntity(); + + var collector = new ReadConversionCollector(); + collector.Read(calculationEntity, calculation); + + var entity = new ClosingStructuresSectionResultEntity + { + ClosingStructuresCalculationEntity = calculationEntity + }; + var sectionResult = new ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult, collector); + + // Assert + Assert.AreSame(calculation, sectionResult.Calculation); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/DuneErosion/DuneErosionFailureMechanismMetaEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/DuneErosion/DuneErosionFailureMechanismMetaEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/DuneErosion/DuneErosionFailureMechanismMetaEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,80 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.DuneErosion.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.DuneErosion; + +namespace Riskeer.Storage.Core.Test.Read.DuneErosion +{ + [TestFixture] + public class DuneErosionFailureMechanismMetaEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Setup + var generalInput = new GeneralDuneErosionInput(); + + // Call + TestDelegate test = () => ((DuneErosionFailureMechanismMetaEntity) null).Read(generalInput); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_InputNull_ThrowsArgumentNullException() + { + // Setup + var entity = new DuneErosionFailureMechanismMetaEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("input", paramName); + } + + [Test] + public void Read_ValidInput_UpdateDuneErosionGeneralInput() + { + // Setup + var inputToUpdate = new GeneralDuneErosionInput(); + var entity = new DuneErosionFailureMechanismMetaEntity + { + N = new Random(31).NextDouble(1, 20) + }; + + // Call + entity.Read(inputToUpdate); + + // Assert + Assert.AreEqual(entity.N, inputToUpdate.N, inputToUpdate.N.GetAccuracy()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/DuneErosion/DuneErosionSectionResultEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/DuneErosion/DuneErosionSectionResultEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/DuneErosion/DuneErosionSectionResultEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,108 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.AssemblyTool.Data; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.DuneErosion.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.DuneErosion; + +namespace Riskeer.Storage.Core.Test.Read.DuneErosion +{ + [TestFixture] + public class DuneErosionSectionResultEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((DuneErosionSectionResultEntity) null).Read( + new DuneErosionFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection())); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_SectionResultNull_ThrowsArgumentNullException() + { + // Setup + var entity = new DuneErosionSectionResultEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("sectionResult", paramName); + } + + [Test] + public void Read_ParameterValues_SectionResultWithParameterValues() + { + // Setup + var random = new Random(21); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResultForFactorizedSignalingNorm = random.NextEnumValue(); + var detailedAssessmentResultForSignalingNorm = random.NextEnumValue(); + var detailedAssessmentResultForMechanismSpecificLowerLimitNorm = random.NextEnumValue(); + var detailedAssessmentResultForLowerLimitNorm = random.NextEnumValue(); + var detailedAssessmentResultForFactorizedLowerLimitNorm = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + bool useManualAssembly = random.NextBoolean(); + var manualAssemblyCategoryGroup = random.NextEnumValue(); + + var entity = new DuneErosionSectionResultEntity + { + FailureMechanismSectionEntity = new FailureMechanismSectionEntity(), + SimpleAssessmentResult = Convert.ToByte(simpleAssessmentResult), + DetailedAssessmentResultForFactorizedSignalingNorm = Convert.ToByte(detailedAssessmentResultForFactorizedSignalingNorm), + DetailedAssessmentResultForSignalingNorm = Convert.ToByte(detailedAssessmentResultForSignalingNorm), + DetailedAssessmentResultForMechanismSpecificLowerLimitNorm = Convert.ToByte(detailedAssessmentResultForMechanismSpecificLowerLimitNorm), + DetailedAssessmentResultForLowerLimitNorm = Convert.ToByte(detailedAssessmentResultForLowerLimitNorm), + DetailedAssessmentResultForFactorizedLowerLimitNorm = Convert.ToByte(detailedAssessmentResultForFactorizedLowerLimitNorm), + TailorMadeAssessmentResult = Convert.ToByte(tailorMadeAssessmentResult), + UseManualAssembly = Convert.ToByte(useManualAssembly), + ManualAssemblyCategoryGroup = Convert.ToByte(manualAssemblyCategoryGroup) + }; + var sectionResult = new DuneErosionFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult); + + // Assert + Assert.AreEqual(simpleAssessmentResult, sectionResult.SimpleAssessmentResult); + Assert.AreEqual(detailedAssessmentResultForFactorizedSignalingNorm, sectionResult.DetailedAssessmentResultForFactorizedSignalingNorm); + Assert.AreEqual(detailedAssessmentResultForSignalingNorm, sectionResult.DetailedAssessmentResultForSignalingNorm); + Assert.AreEqual(detailedAssessmentResultForMechanismSpecificLowerLimitNorm, sectionResult.DetailedAssessmentResultForMechanismSpecificLowerLimitNorm); + Assert.AreEqual(detailedAssessmentResultForLowerLimitNorm, sectionResult.DetailedAssessmentResultForLowerLimitNorm); + Assert.AreEqual(detailedAssessmentResultForFactorizedLowerLimitNorm, sectionResult.DetailedAssessmentResultForFactorizedLowerLimitNorm); + Assert.AreEqual(tailorMadeAssessmentResult, sectionResult.TailorMadeAssessmentResult); + Assert.AreEqual(useManualAssembly, sectionResult.UseManualAssembly); + Assert.AreEqual(manualAssemblyCategoryGroup, sectionResult.ManualAssemblyCategoryGroup); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/DuneErosion/DuneLocationCalculationCollectionEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/DuneErosion/DuneLocationCalculationCollectionEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/DuneErosion/DuneLocationCalculationCollectionEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,139 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.DuneErosion.Data; +using Ringtoets.DuneErosion.Data.TestUtil; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Read.DuneErosion; + +namespace Riskeer.Storage.Core.Test.Read.DuneErosion +{ + [TestFixture] + public class DuneLocationCalculationCollectionEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => + ((DuneLocationCalculationCollectionEntity) null).Read(Enumerable.Empty(), + new ReadConversionCollector()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_CalculationsNull_ThrowsArgumentNullException() + { + // Setup + var entity = new DuneLocationCalculationCollectionEntity(); + + // Call + TestDelegate call = () => entity.Read(null, new ReadConversionCollector()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("calculations", exception.ParamName); + } + + [Test] + public void Read_CollectorNull_ThrowsArgumentNullException() + { + // Setup + var entity = new DuneLocationCalculationCollectionEntity(); + + // Call + TestDelegate call = () => entity.Read(Enumerable.Empty(), + null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("collector", exception.ParamName); + } + + [Test] + public void Read_EntityWithValidValues_SetsCalculationsWithExpectedValues() + { + // Setup + DuneLocationEntity duneLocationEntityOne = CreateDuneLocationEntity(); + var calculationEntityWithoutOutput = new DuneLocationCalculationEntity + { + DuneLocationEntity = duneLocationEntityOne + }; + + DuneLocationEntity duneLocationEntityTwo = CreateDuneLocationEntity(); + var calculationEntityWithOutput = new DuneLocationCalculationEntity + { + DuneLocationEntity = duneLocationEntityTwo, + DuneLocationCalculationOutputEntities = + { + new DuneLocationCalculationOutputEntity() + } + }; + + var collectionEntity = new DuneLocationCalculationCollectionEntity + { + DuneLocationCalculationEntities = + { + calculationEntityWithoutOutput, + calculationEntityWithOutput + } + }; + + var duneLocationOne = new TestDuneLocation("1"); + var duneLocationTwo = new TestDuneLocation("2"); + var collector = new ReadConversionCollector(); + collector.Read(duneLocationEntityOne, duneLocationOne); + collector.Read(duneLocationEntityTwo, duneLocationTwo); + + var calculationOne = new DuneLocationCalculation(duneLocationOne); + var calculationTwo = new DuneLocationCalculation(duneLocationTwo); + + // Call + collectionEntity.Read(new[] + { + calculationOne, + calculationTwo + }, collector); + + // Assert + Assert.IsNull(calculationOne.Output); + Assert.IsNotNull(calculationTwo.Output); + } + + private static DuneLocationEntity CreateDuneLocationEntity() + { + return new DuneLocationEntity + { + LocationId = 1, + Name = "Dune Location", + LocationX = 1, + LocationY = 2 + }; + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/DuneErosion/DuneLocationCalculationEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/DuneErosion/DuneLocationCalculationEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/DuneErosion/DuneLocationCalculationEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,130 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.DuneErosion.Data; +using Ringtoets.DuneErosion.Data.TestUtil; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.DuneErosion; + +namespace Riskeer.Storage.Core.Test.Read.DuneErosion +{ + [TestFixture] + public class DuneLocationCalculationEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Setup + var calculation = new DuneLocationCalculation(new TestDuneLocation()); + + // Call + TestDelegate call = () => ((DuneLocationCalculationEntity) null).Read(calculation); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_CalculationNull_ThrowsArgumentNullException() + { + // Setup + var entity = new DuneLocationCalculationEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("calculation", exception.ParamName); + } + + [Test] + public void Read_CalculationEntityWithOutput_SetsDuneLocationCalculationWithoutOutput() + { + // Setup + var calculation = new DuneLocationCalculation(new TestDuneLocation()); + + var entity = new DuneLocationCalculationEntity(); + + // Call + entity.Read(calculation); + + // Assert + Assert.IsNull(calculation.Output); + } + + [Test] + public void Read_CalculationEntityWithOutput_SetsDuneLocationCalculationWithOutput() + { + // Setup + var calculation = new DuneLocationCalculation(new TestDuneLocation()); + + var random = new Random(21); + double waterLevel = random.NextDouble(); + double waveHeight = random.NextDouble(); + double wavePeriod = random.NextDouble(); + double targetProbability = random.NextDouble(); + double targetReliability = random.NextDouble(); + double calculatedProbability = random.NextDouble(); + double calculatedReliability = random.NextDouble(); + var convergence = random.NextEnumValue(); + + var entity = new DuneLocationCalculationEntity + { + DuneLocationCalculationOutputEntities = + { + new DuneLocationCalculationOutputEntity + { + WaterLevel = waterLevel, + WaveHeight = waveHeight, + WavePeriod = wavePeriod, + TargetProbability = targetProbability, + TargetReliability = targetReliability, + CalculatedProbability = calculatedProbability, + CalculatedReliability = calculatedReliability, + CalculationConvergence = Convert.ToByte(convergence) + } + } + }; + + // Call + entity.Read(calculation); + + // Assert + DuneLocationCalculationOutput output = calculation.Output; + Assert.IsNotNull(output); + Assert.AreEqual(waterLevel, output.WaterLevel, output.WaterLevel.GetAccuracy()); + Assert.AreEqual(waveHeight, output.WaveHeight, output.WaveHeight.GetAccuracy()); + Assert.AreEqual(wavePeriod, output.WavePeriod, output.WavePeriod.GetAccuracy()); + Assert.AreEqual(targetProbability, output.TargetProbability); + Assert.AreEqual(targetReliability, output.TargetReliability, output.TargetReliability.GetAccuracy()); + Assert.AreEqual(calculatedProbability, output.CalculatedProbability); + Assert.AreEqual(calculatedReliability, output.CalculatedReliability, output.CalculatedReliability.GetAccuracy()); + Assert.AreEqual(convergence, output.CalculationConvergence); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/DuneErosion/DuneLocationCalculationOutputEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/DuneErosion/DuneLocationCalculationOutputEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/DuneErosion/DuneLocationCalculationOutputEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,117 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.DuneErosion.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.DuneErosion; + +namespace Riskeer.Storage.Core.Test.Read.DuneErosion +{ + [TestFixture] + public class DuneLocationCalculationOutputEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((DuneLocationCalculationOutputEntity) null).Read(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_ValidParameters_ReturnsDuneLocationOutput() + { + // Setup + var random = new Random(22); + double waterLevel = random.NextDouble(); + double waveHeight = random.NextDouble(); + double wavePeriod = random.NextDouble(); + double targetProbability = random.NextDouble(); + double targetReliability = random.NextDouble(); + double calculatedProbability = random.NextDouble(); + double calculatedReliability = random.NextDouble(); + var convergence = random.NextEnumValue(); + var entity = new DuneLocationCalculationOutputEntity + { + WaterLevel = waterLevel, + WaveHeight = waveHeight, + WavePeriod = wavePeriod, + TargetProbability = targetProbability, + TargetReliability = targetReliability, + CalculatedProbability = calculatedProbability, + CalculatedReliability = calculatedReliability, + CalculationConvergence = Convert.ToByte(convergence) + }; + + // Call + DuneLocationCalculationOutput output = entity.Read(); + + // Assert + Assert.AreEqual(waterLevel, output.WaterLevel, output.WaterLevel.GetAccuracy()); + Assert.AreEqual(waveHeight, output.WaveHeight, output.WaveHeight.GetAccuracy()); + Assert.AreEqual(wavePeriod, output.WavePeriod, output.WavePeriod.GetAccuracy()); + Assert.AreEqual(targetProbability, output.TargetProbability); + Assert.AreEqual(targetReliability, output.TargetReliability, output.TargetReliability.GetAccuracy()); + Assert.AreEqual(calculatedProbability, output.CalculatedProbability); + Assert.AreEqual(calculatedReliability, output.CalculatedReliability, output.CalculatedReliability.GetAccuracy()); + Assert.AreEqual(convergence, output.CalculationConvergence); + } + + [Test] + public void Read_NullParameters_ReturnsDuneLocationOutputWithNaN() + { + // Setup + var convergence = new Random(36).NextEnumValue(); + var entity = new DuneLocationCalculationOutputEntity + { + WaterLevel = null, + WaveHeight = null, + WavePeriod = null, + TargetProbability = null, + TargetReliability = null, + CalculatedProbability = null, + CalculatedReliability = null, + CalculationConvergence = Convert.ToByte(convergence) + }; + + // Call + DuneLocationCalculationOutput output = entity.Read(); + + // Assert + Assert.IsNaN(output.WaterLevel); + Assert.IsNaN(output.WaveHeight); + Assert.IsNaN(output.WavePeriod); + Assert.IsNaN(output.TargetProbability); + Assert.IsNaN(output.TargetReliability); + Assert.IsNaN(output.CalculatedProbability); + Assert.IsNaN(output.CalculatedReliability); + Assert.AreEqual(convergence, output.CalculationConvergence); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/DuneErosion/DuneLocationEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/DuneErosion/DuneLocationEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/DuneErosion/DuneLocationEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,162 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.DuneErosion.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Read.DuneErosion; + +namespace Riskeer.Storage.Core.Test.Read.DuneErosion +{ + [TestFixture] + public class DuneLocationEntityReadExtensionsTest + { + [Test] + public void Read_EntityIsNull_ThrowArgumentNullException() + { + // Call + TestDelegate call = () => ((DuneLocationEntity) null).Read(new ReadConversionCollector()); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Read_CollectorIsNull_ThrowArgumentNullException() + { + // Setup + var entity = new DuneLocationEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void Read_WithValidData_ReturnsDuneLocationWithPropertiesSetAndEntityRegistered() + { + // Setup + const string testName = "testName"; + var random = new Random(21); + long locationId = random.Next(0, 400); + double x = random.NextDouble(); + double y = random.NextDouble(); + int coastalAreaId = random.Next(); + double offset = random.NextDouble(); + double orientation = random.NextDouble(); + double d50 = random.NextDouble(); + var entity = new DuneLocationEntity + { + LocationId = locationId, + Name = testName, + LocationX = x, + LocationY = y, + CoastalAreaId = coastalAreaId, + Offset = offset, + Orientation = orientation, + D50 = d50 + }; + + var collector = new ReadConversionCollector(); + + // Call + DuneLocation location = entity.Read(collector); + + // Assert + Assert.IsNotNull(location); + Assert.AreEqual(locationId, location.Id); + Assert.AreEqual(testName, location.Name); + Assert.AreEqual(x, location.Location.X, 1e-6); + Assert.AreEqual(y, location.Location.Y, 1e-6); + Assert.AreEqual(coastalAreaId, location.CoastalAreaId); + Assert.AreEqual(offset, location.Offset, location.Offset.GetAccuracy()); + Assert.AreEqual(orientation, location.Orientation, location.Orientation.GetAccuracy()); + Assert.AreEqual(d50, location.D50, location.D50.GetAccuracy()); + + Assert.IsTrue(collector.Contains(entity)); + } + + [Test] + public void Read_WithNullData_ReturnsDuneLocationWithNaNPropertiesSet() + { + // Setup + const string testName = "testName"; + var random = new Random(22); + long locationId = random.Next(0, 400); + int coastalAreaId = random.Next(); + var entity = new DuneLocationEntity + { + LocationId = locationId, + Name = testName, + LocationX = null, + LocationY = null, + CoastalAreaId = coastalAreaId, + Offset = null, + Orientation = null, + D50 = null + }; + + var collector = new ReadConversionCollector(); + + // Call + DuneLocation location = entity.Read(collector); + + // Assert + Assert.IsNotNull(location); + Assert.AreEqual(locationId, location.Id); + Assert.AreEqual(testName, location.Name); + Assert.IsNaN(location.Location.X); + Assert.IsNaN(location.Location.Y); + Assert.AreEqual(coastalAreaId, location.CoastalAreaId); + Assert.IsNaN(location.Offset); + Assert.IsNaN(location.Orientation); + Assert.IsNaN(location.D50); + + Assert.IsTrue(collector.Contains(entity)); + } + + [Test] + public void Read_SameDuneLocationEntityTwice_ReturnSameDuneLocation() + { + // Setup + var entity = new DuneLocationEntity + { + Name = "A" + }; + + var collector = new ReadConversionCollector(); + + // Call + DuneLocation location1 = entity.Read(collector); + DuneLocation location2 = entity.Read(collector); + + // Assert + Assert.AreSame(location1, location2); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/FailureMechanismEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/FailureMechanismEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/FailureMechanismEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,3164 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base; +using Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.ClosingStructures.Data; +using Ringtoets.Common.Data; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.DuneErosion.Data; +using Ringtoets.DuneErosion.Data.TestUtil; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.GrassCoverErosionOutwards.Data; +using Ringtoets.HeightStructures.Data; +using Ringtoets.Integration.Data.StandAlone; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.MacroStabilityInwards.Data.SoilProfile; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Data.SoilProfile; +using Ringtoets.StabilityPointStructures.Data; +using Ringtoets.StabilityStoneCover.Data; +using Ringtoets.Storage.Core.TestUtil; +using Ringtoets.Storage.Core.TestUtil.Hydraulics; +using Ringtoets.Storage.Core.TestUtil.MacroStabilityInwards; +using Ringtoets.WaveImpactAsphaltCover.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Read +{ + [TestFixture] + public class FailureMechanismEntityReadExtensionsTest + { + [Test] + [TestCase(true)] + [TestCase(false)] + public void ReadAsStandAloneFailureMechanism_WithoutSectionsSet_ReturnsNewStandAloneFailureMechanism(bool isRelevant) + { + // Setup + var entity = new FailureMechanismEntity + { + IsRelevant = Convert.ToByte(isRelevant), + InputComments = "Some input text", + OutputComments = "Some output text", + NotRelevantComments = "Really not relevant" + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new TestFailureMechanism(); + + // Call + entity.ReadCommonFailureMechanismProperties(failureMechanism, collector); + + // Assert + CollectionAssert.IsEmpty(failureMechanism.Sections); + Assert.AreEqual(isRelevant, failureMechanism.IsRelevant); + Assert.AreEqual(entity.InputComments, failureMechanism.InputComments.Body); + Assert.AreEqual(entity.OutputComments, failureMechanism.OutputComments.Body); + Assert.AreEqual(entity.NotRelevantComments, failureMechanism.NotRelevantComments.Body); + CollectionAssert.IsEmpty(failureMechanism.Sections); + Assert.IsNull(failureMechanism.FailureMechanismSectionSourcePath); + } + + [Test] + public void ReadAsStandAloneFailureMechanism_WithSectionsSet_ReturnsNewStandAloneFailureMechanismWithFailureMechanismSections() + { + // Setup + const string filePath = "failureMechanismSections/File/Path"; + var entity = new FailureMechanismEntity + { + FailureMechanismSectionCollectionSourcePath = filePath, + FailureMechanismSectionEntities = + { + CreateSimpleFailureMechanismSectionEntity() + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new TestFailureMechanism(); + + // Call + entity.ReadCommonFailureMechanismProperties(failureMechanism, collector); + + // Assert + Assert.AreEqual(entity.FailureMechanismSectionEntities.Count, failureMechanism.Sections.Count()); + Assert.AreEqual(filePath, failureMechanism.FailureMechanismSectionSourcePath); + } + + private static FailureMechanismSectionEntity CreateSimpleFailureMechanismSectionEntity() + { + var dummyPoints = new[] + { + new Point2D(0, 0) + }; + string dummyPointXml = new Point2DCollectionXmlSerializer().ToXml(dummyPoints); + var failureMechanismSectionEntity = new FailureMechanismSectionEntity + { + Name = "section", + FailureMechanismSectionPointXml = dummyPointXml + }; + return failureMechanismSectionEntity; + } + + #region Dune Erosion + + [Test] + public void ReadAsDuneErosionFailureMechanism_WithMeta_ReturnFailureMechanismWithGeneralInputSet() + { + // Setup + const int generalInputN = 3; + + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + DuneErosionFailureMechanismMetaEntities = + { + new DuneErosionFailureMechanismMetaEntity + { + N = generalInputN, + DuneLocationCalculationCollectionEntity = new DuneLocationCalculationCollectionEntity(), + DuneLocationCalculationCollectionEntity1 = new DuneLocationCalculationCollectionEntity(), + DuneLocationCalculationCollectionEntity2 = new DuneLocationCalculationCollectionEntity(), + DuneLocationCalculationCollectionEntity3 = new DuneLocationCalculationCollectionEntity(), + DuneLocationCalculationCollectionEntity4 = new DuneLocationCalculationCollectionEntity() + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new DuneErosionFailureMechanism(); + + // Call + entity.ReadAsDuneErosionFailureMechanism(failureMechanism, collector); + + // Assert + Assert.AreEqual(generalInputN, failureMechanism.GeneralInput.N, failureMechanism.GeneralInput.N.GetAccuracy()); + } + + [Test] + public void ReadAsDuneErosionFailureMechanism_WithSectionsSet_ReturnsNewDuneErosionFailureMechanismWithFailureMechanismSectionsAdded() + { + // Setup + const string filePath = "failureMechanismSections/File/Path"; + + FailureMechanismSectionEntity failureMechanismSectionEntity = CreateSimpleFailureMechanismSectionEntity(); + var duneErosionSectionResultEntity = new DuneErosionSectionResultEntity + { + FailureMechanismSectionEntity = failureMechanismSectionEntity + }; + failureMechanismSectionEntity.DuneErosionSectionResultEntities.Add(duneErosionSectionResultEntity); + var entity = new FailureMechanismEntity + { + FailureMechanismSectionCollectionSourcePath = filePath, + FailureMechanismSectionEntities = + { + failureMechanismSectionEntity + }, + DuneErosionFailureMechanismMetaEntities = + { + new DuneErosionFailureMechanismMetaEntity + { + N = 1, + DuneLocationCalculationCollectionEntity = new DuneLocationCalculationCollectionEntity(), + DuneLocationCalculationCollectionEntity1 = new DuneLocationCalculationCollectionEntity(), + DuneLocationCalculationCollectionEntity2 = new DuneLocationCalculationCollectionEntity(), + DuneLocationCalculationCollectionEntity3 = new DuneLocationCalculationCollectionEntity(), + DuneLocationCalculationCollectionEntity4 = new DuneLocationCalculationCollectionEntity() + } + }, + CalculationGroupEntity = new CalculationGroupEntity() + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new DuneErosionFailureMechanism(); + + // Call + entity.ReadAsDuneErosionFailureMechanism(failureMechanism, collector); + + // Assert + Assert.AreEqual(entity.FailureMechanismSectionEntities.Count, failureMechanism.Sections.Count()); + Assert.AreEqual(entity.FailureMechanismSectionCollectionSourcePath, + failureMechanism.FailureMechanismSectionSourcePath); + } + + [Test] + public void ReadAsDuneErosionFailureMechanism_WitDuneLocations_ReturnsNewDuneErosionFailureMechanismWithLocationsSet() + { + // Setup + const string locationAName = "DuneLocation A"; + const string locationBName = "DuneLocation B"; + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + DuneErosionFailureMechanismMetaEntities = + { + new DuneErosionFailureMechanismMetaEntity + { + N = 1, + DuneLocationCalculationCollectionEntity = new DuneLocationCalculationCollectionEntity(), + DuneLocationCalculationCollectionEntity1 = new DuneLocationCalculationCollectionEntity(), + DuneLocationCalculationCollectionEntity2 = new DuneLocationCalculationCollectionEntity(), + DuneLocationCalculationCollectionEntity3 = new DuneLocationCalculationCollectionEntity(), + DuneLocationCalculationCollectionEntity4 = new DuneLocationCalculationCollectionEntity() + } + }, + DuneLocationEntities = + { + new DuneLocationEntity + { + Order = 1, + Name = locationBName + }, + new DuneLocationEntity + { + Order = 0, + Name = locationAName + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new DuneErosionFailureMechanism(); + + // Call + entity.ReadAsDuneErosionFailureMechanism(failureMechanism, collector); + + // Assert + IObservableEnumerable duneLocations = failureMechanism.DuneLocations; + Assert.AreEqual(2, duneLocations.Count()); + + Assert.AreEqual(locationAName, duneLocations.ElementAt(0).Name); + Assert.AreEqual(locationBName, duneLocations.ElementAt(1).Name); + } + + [Test] + public void ReadAsDuneErosionFailureMechanism_WithDuneLocationCalculations_ReturnsNewDuneErosionFailureMechanismWithLocationsAndCalculationsSet() + { + // Setup + var duneLocationEntity = new DuneLocationEntity + { + Order = 1, + Name = "Dune" + }; + var duneErosionFailureMechanismMetaEntity = new DuneErosionFailureMechanismMetaEntity + { + N = 1, + DuneLocationCalculationCollectionEntity = CreateDuneLocationCollectionCalculationEntity(duneLocationEntity, 1), + DuneLocationCalculationCollectionEntity1 = CreateDuneLocationCollectionCalculationEntity(duneLocationEntity, 2), + DuneLocationCalculationCollectionEntity2 = CreateDuneLocationCollectionCalculationEntity(duneLocationEntity, 3), + DuneLocationCalculationCollectionEntity3 = CreateDuneLocationCollectionCalculationEntity(duneLocationEntity, 4), + DuneLocationCalculationCollectionEntity4 = CreateDuneLocationCollectionCalculationEntity(duneLocationEntity, 5) + }; + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + DuneErosionFailureMechanismMetaEntities = + { + duneErosionFailureMechanismMetaEntity + }, + DuneLocationEntities = + { + duneLocationEntity + } + }; + + var duneLocation = new TestDuneLocation(); + var collector = new ReadConversionCollector(); + collector.Read(duneLocationEntity, duneLocation); + + var failureMechanism = new DuneErosionFailureMechanism(); + + // Call + entity.ReadAsDuneErosionFailureMechanism(failureMechanism, collector); + + // Assert + AssertDuneLocationCalculation(duneErosionFailureMechanismMetaEntity.DuneLocationCalculationCollectionEntity + .DuneLocationCalculationEntities + .Single(), + duneLocation, + failureMechanism.CalculationsForFactorizedLowerLimitNorm.Single()); + + AssertDuneLocationCalculation(duneErosionFailureMechanismMetaEntity.DuneLocationCalculationCollectionEntity1 + .DuneLocationCalculationEntities + .Single(), + duneLocation, + failureMechanism.CalculationsForLowerLimitNorm.Single()); + + AssertDuneLocationCalculation(duneErosionFailureMechanismMetaEntity.DuneLocationCalculationCollectionEntity2 + .DuneLocationCalculationEntities + .Single(), + duneLocation, + failureMechanism.CalculationsForMechanismSpecificLowerLimitNorm.Single()); + + AssertDuneLocationCalculation(duneErosionFailureMechanismMetaEntity.DuneLocationCalculationCollectionEntity3 + .DuneLocationCalculationEntities + .Single(), + duneLocation, + failureMechanism.CalculationsForMechanismSpecificSignalingNorm.Single()); + + AssertDuneLocationCalculation(duneErosionFailureMechanismMetaEntity.DuneLocationCalculationCollectionEntity4 + .DuneLocationCalculationEntities + .Single(), + duneLocation, + failureMechanism.CalculationsForMechanismSpecificFactorizedSignalingNorm.Single()); + } + + private static DuneLocationCalculationCollectionEntity CreateDuneLocationCollectionCalculationEntity(DuneLocationEntity duneLocationEntity, + int seed) + { + var random = new Random(seed); + var duneLocationCalculationEntity = new DuneLocationCalculationEntity + { + DuneLocationEntity = duneLocationEntity + }; + + if (random.NextBoolean()) + { + duneLocationCalculationEntity.DuneLocationCalculationOutputEntities.Add(new DuneLocationCalculationOutputEntity()); + } + + return new DuneLocationCalculationCollectionEntity + { + DuneLocationCalculationEntities = + { + duneLocationCalculationEntity + } + }; + } + + private static void AssertDuneLocationCalculation(DuneLocationCalculationEntity expectedCalculationEntity, + DuneLocation expectedDuneLocation, + DuneLocationCalculation actualCalculation) + { + Assert.AreSame(expectedDuneLocation, actualCalculation.DuneLocation); + + DuneLocationCalculationOutputEntity expectedOutput = expectedCalculationEntity.DuneLocationCalculationOutputEntities.SingleOrDefault(); + if (expectedOutput != null) + { + Assert.IsNotNull(actualCalculation.Output); + } + else + { + Assert.IsNull(actualCalculation.Output); + } + } + + #endregion + + #region Piping + + [Test] + public void ReadAsPipingFailureMechanism_EntityNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => ((FailureMechanismEntity) null).ReadAsPipingFailureMechanism(failureMechanism, + collector); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", parameter); + } + + [Test] + public void ReadAsPipingFailureMechanism_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var entity = new FailureMechanismEntity(); + + // Call + TestDelegate test = () => entity.ReadAsPipingFailureMechanism(null, new ReadConversionCollector()); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("failureMechanism", parameter); + } + + [Test] + public void ReadAsPipingFailureMechanism_CollectorNull_ThrowsArgumentNullException() + { + // Setup + var entity = new FailureMechanismEntity(); + + // Call + TestDelegate test = () => entity.ReadAsPipingFailureMechanism(new PipingFailureMechanism(), null); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("collector", parameter); + } + + [Test] + public void ReadAsPipingFailureMechanism_WithProperties_SetsPipingFailureMechanismWithProperties() + { + // Setup + var random = new Random(31); + bool isRelevant = random.NextBoolean(); + var entity = new FailureMechanismEntity + { + IsRelevant = Convert.ToByte(isRelevant), + InputComments = "Some input text", + OutputComments = "Some output text", + NotRelevantComments = "Really not relevant", + CalculationGroupEntity = new CalculationGroupEntity(), + PipingFailureMechanismMetaEntities = new[] + { + new PipingFailureMechanismMetaEntity + { + A = random.NextDouble(), + WaterVolumetricWeight = random.NextDouble() + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new PipingFailureMechanism(); + + // Call + entity.ReadAsPipingFailureMechanism(failureMechanism, collector); + + // Assert + Assert.IsNotNull(failureMechanism); + Assert.AreEqual(isRelevant, failureMechanism.IsRelevant); + Assert.AreEqual(entity.InputComments, failureMechanism.InputComments.Body); + Assert.AreEqual(entity.OutputComments, failureMechanism.OutputComments.Body); + Assert.AreEqual(entity.NotRelevantComments, failureMechanism.NotRelevantComments.Body); + CollectionAssert.IsEmpty(failureMechanism.StochasticSoilModels); + CollectionAssert.IsEmpty(failureMechanism.SurfaceLines); + CollectionAssert.IsEmpty(failureMechanism.Sections); + + PipingFailureMechanismMetaEntity pipingFailureMechanismMetaEntity = entity.PipingFailureMechanismMetaEntities.Single(); + Assert.AreEqual(pipingFailureMechanismMetaEntity.A, failureMechanism.PipingProbabilityAssessmentInput.A); + Assert.AreEqual(pipingFailureMechanismMetaEntity.WaterVolumetricWeight, failureMechanism.GeneralInput.WaterVolumetricWeight, + failureMechanism.GeneralInput.WaterVolumetricWeight.GetAccuracy()); + + Assert.IsNull(pipingFailureMechanismMetaEntity.StochasticSoilModelCollectionSourcePath); + Assert.IsNull(pipingFailureMechanismMetaEntity.SurfaceLineCollectionSourcePath); + } + + [Test] + public void ReadAsPipingFailureMechanism_WithoutStochasticSoilModelsWithSourcePath_SetsFailureMechanismStochasticSoilModelsSourcePath() + { + // Setup + const string sourcePath = "some/Path"; + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + PipingFailureMechanismMetaEntities = + { + new PipingFailureMechanismMetaEntity + { + StochasticSoilModelCollectionSourcePath = sourcePath + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new PipingFailureMechanism(); + + // Call + entity.ReadAsPipingFailureMechanism(failureMechanism, collector); + + // Assert + PipingStochasticSoilModelCollection stochasticSoilModels = failureMechanism.StochasticSoilModels; + Assert.AreEqual(sourcePath, stochasticSoilModels.SourcePath); + CollectionAssert.IsEmpty(stochasticSoilModels); + } + + [Test] + public void ReadAsPipingFailureMechanism_WithStochasticSoilModelsSet_SetsPipingFailureMechanismWithStochasticSoilModels() + { + // Setup + var random = new Random(21); + var geometry = new[] + { + new Point2D(random.NextDouble(), random.NextDouble()) + }; + string segmentPointsXml = new Point2DCollectionXmlSerializer().ToXml(geometry); + const string sourcePath = "some/Path"; + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + StochasticSoilModelEntities = + { + new StochasticSoilModelEntity + { + StochasticSoilModelSegmentPointXml = segmentPointsXml, + PipingStochasticSoilProfileEntities = + { + PipingStochasticSoilProfileEntityTestFactory.CreateStochasticSoilProfileEntity() + }, + Name = "A", + Order = 1 + }, + new StochasticSoilModelEntity + { + StochasticSoilModelSegmentPointXml = segmentPointsXml, + PipingStochasticSoilProfileEntities = + { + PipingStochasticSoilProfileEntityTestFactory.CreateStochasticSoilProfileEntity() + }, + Name = "B", + Order = 0 + } + }, + PipingFailureMechanismMetaEntities = + { + new PipingFailureMechanismMetaEntity + { + StochasticSoilModelCollectionSourcePath = sourcePath + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new PipingFailureMechanism(); + + // Call + entity.ReadAsPipingFailureMechanism(failureMechanism, collector); + + // Assert + Assert.AreEqual(entity.StochasticSoilModelEntities.Count, failureMechanism.StochasticSoilModels.Count); + Assert.AreEqual(sourcePath, failureMechanism.StochasticSoilModels.SourcePath); + CollectionAssert.AreEqual(new[] + { + "B", + "A" + }, failureMechanism.StochasticSoilModels.Select(s => s.Name)); + } + + [Test] + public void ReadAsPipingFailureMechanism_WithoutSurfaceLinesWithSourcePath_SetsFailureMechanismSurfaceLinesSourcePath() + { + // Setup + const string sourcePath = "some/path"; + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + PipingFailureMechanismMetaEntities = + { + new PipingFailureMechanismMetaEntity + { + SurfaceLineCollectionSourcePath = sourcePath + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new PipingFailureMechanism(); + + // Call + entity.ReadAsPipingFailureMechanism(failureMechanism, collector); + + // Assert + PipingSurfaceLineCollection surfaceLines = failureMechanism.SurfaceLines; + Assert.AreEqual(sourcePath, surfaceLines.SourcePath); + CollectionAssert.IsEmpty(surfaceLines); + } + + [Test] + public void ReadAsPipingFailureMechanism_WithSurfaceLines_SetsPipingFailureMechanismSurfaceLines() + { + // Setup + string emptyPointsXml = new Point3DCollectionXmlSerializer().ToXml(new Point3D[0]); + const string sourcePath = "some/path"; + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + SurfaceLineEntities = + { + new SurfaceLineEntity + { + PointsXml = emptyPointsXml, + Name = "1", + Order = 1 + }, + new SurfaceLineEntity + { + PointsXml = emptyPointsXml, + Name = "2", + Order = 0 + } + }, + PipingFailureMechanismMetaEntities = + { + new PipingFailureMechanismMetaEntity + { + SurfaceLineCollectionSourcePath = sourcePath + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new PipingFailureMechanism(); + + // Call + entity.ReadAsPipingFailureMechanism(failureMechanism, collector); + + // Assert + Assert.AreEqual(entity.SurfaceLineEntities.Count, failureMechanism.SurfaceLines.Count); + Assert.AreEqual(sourcePath, failureMechanism.SurfaceLines.SourcePath); + CollectionAssert.AreEqual(new[] + { + "2", + "1" + }, failureMechanism.SurfaceLines.Select(sl => sl.Name)); + } + + [Test] + public void ReadAsPipingFailureMechanism_WithSectionsSet_SetsPipingFailureMechanismWithFailureMechanismSections() + { + // Setup + const string filePath = "failureMechanismSections/File/Path"; + + FailureMechanismSectionEntity failureMechanismSectionEntity = CreateSimpleFailureMechanismSectionEntity(); + var pipingSectionResultEntity = new PipingSectionResultEntity + { + FailureMechanismSectionEntity = failureMechanismSectionEntity + }; + failureMechanismSectionEntity.PipingSectionResultEntities.Add(pipingSectionResultEntity); + var entity = new FailureMechanismEntity + { + FailureMechanismSectionCollectionSourcePath = filePath, + CalculationGroupEntity = new CalculationGroupEntity(), + FailureMechanismSectionEntities = + { + failureMechanismSectionEntity + }, + PipingFailureMechanismMetaEntities = + { + new PipingFailureMechanismMetaEntity() + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new PipingFailureMechanism(); + + // Call + entity.ReadAsPipingFailureMechanism(failureMechanism, collector); + + // Assert + Assert.AreEqual(entity.FailureMechanismSectionEntities.Count, + failureMechanism.Sections.Count()); + Assert.AreEqual(entity.FailureMechanismSectionCollectionSourcePath, + failureMechanism.FailureMechanismSectionSourcePath); + } + + [Test] + public void ReadAsPipingFailureMechanism_WithCalculationGroup_SetsPipingFailureMechanismCalculationGroup() + { + // Setup + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity + { + Name = "Berekeningen", + Order = 0, + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Name = "Child1", + Order = 0 + }, + new CalculationGroupEntity + { + Name = "Child2", + Order = 1 + } + } + }, + PipingFailureMechanismMetaEntities = + { + new PipingFailureMechanismMetaEntity() + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new PipingFailureMechanism(); + + // Call + entity.ReadAsPipingFailureMechanism(failureMechanism, collector); + + // Assert + Assert.AreEqual(entity.CalculationGroupEntity.CalculationGroupEntity1.Count, + failureMechanism.CalculationsGroup.Children.Count); + + ICalculationBase child1 = failureMechanism.CalculationsGroup.Children[0]; + Assert.AreEqual("Child1", child1.Name); + + ICalculationBase child2 = failureMechanism.CalculationsGroup.Children[1]; + Assert.AreEqual("Child2", child2.Name); + } + + #endregion + + #region MacroStabilityInwards + + [Test] + public void ReadAsMacroStabilityInwardsFailureMechanism_EntityNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => ((FailureMechanismEntity) null).ReadAsMacroStabilityInwardsFailureMechanism( + failureMechanism, + collector); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", parameter); + } + + [Test] + public void ReadAsMacroStabilityInwardsFailureMechanism_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var entity = new FailureMechanismEntity(); + + // Call + TestDelegate test = () => entity.ReadAsMacroStabilityInwardsFailureMechanism( + null, new ReadConversionCollector()); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("failureMechanism", parameter); + } + + [Test] + public void ReadAsMacroStabilityInwardsFailureMechanism_CollectorNull_ThrowsArgumentNullException() + { + // Setup + var entity = new FailureMechanismEntity(); + + // Call + TestDelegate test = () => entity.ReadAsMacroStabilityInwardsFailureMechanism( + new MacroStabilityInwardsFailureMechanism(), null); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("collector", parameter); + } + + [Test] + public void ReadAsMacroStabilityInwardsFailureMechanism_WithPropertiesSet_SetsMacroStabilityInwardsFailureMechanismProperties() + { + // Setup + var random = new Random(31); + bool isRelevant = random.NextBoolean(); + var entity = new FailureMechanismEntity + { + IsRelevant = Convert.ToByte(isRelevant), + InputComments = "Some input text", + OutputComments = "Some output text", + NotRelevantComments = "Really not relevant", + CalculationGroupEntity = new CalculationGroupEntity(), + MacroStabilityInwardsFailureMechanismMetaEntities = new[] + { + new MacroStabilityInwardsFailureMechanismMetaEntity + { + A = random.NextDouble() + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + // Call + entity.ReadAsMacroStabilityInwardsFailureMechanism(failureMechanism, collector); + + // Assert + Assert.IsNotNull(failureMechanism); + Assert.AreEqual(isRelevant, failureMechanism.IsRelevant); + Assert.AreEqual(entity.InputComments, failureMechanism.InputComments.Body); + Assert.AreEqual(entity.OutputComments, failureMechanism.OutputComments.Body); + Assert.AreEqual(entity.NotRelevantComments, failureMechanism.NotRelevantComments.Body); + CollectionAssert.IsEmpty(failureMechanism.StochasticSoilModels); + CollectionAssert.IsEmpty(failureMechanism.SurfaceLines); + CollectionAssert.IsEmpty(failureMechanism.Sections); + + MacroStabilityInwardsFailureMechanismMetaEntity metaEntity = entity.MacroStabilityInwardsFailureMechanismMetaEntities.Single(); + Assert.AreEqual(metaEntity.A, failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput.A); + + Assert.IsNull(metaEntity.StochasticSoilModelCollectionSourcePath); + Assert.IsNull(metaEntity.SurfaceLineCollectionSourcePath); + } + + [Test] + public void ReadAsMacroStabilityInwardsFailureMechanism_WithNullPropertiesSet_SetsMacroStabilityInwardsFailureMechanismPropertiesToNaN() + { + // Setup + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + MacroStabilityInwardsFailureMechanismMetaEntities = new[] + { + new MacroStabilityInwardsFailureMechanismMetaEntity() + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + // Call + entity.ReadAsMacroStabilityInwardsFailureMechanism(failureMechanism, collector); + + // Assert + Assert.IsNotNull(failureMechanism); + + MacroStabilityInwardsFailureMechanismMetaEntity metaEntity = entity.MacroStabilityInwardsFailureMechanismMetaEntities.First(); + Assert.AreEqual(metaEntity.A, failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput.A); + } + + [Test] + public void ReadAsMacroStabilityInwardsFailureMechanism_WithoutStochasticSoilModelsWithSourcePath_FailureMechanismWithStochasticSoilModelsSourcePathSet() + { + // Setup + const string sourcePath = "some/Path"; + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + MacroStabilityInwardsFailureMechanismMetaEntities = + { + new MacroStabilityInwardsFailureMechanismMetaEntity + { + StochasticSoilModelCollectionSourcePath = sourcePath + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + // Call + entity.ReadAsMacroStabilityInwardsFailureMechanism(failureMechanism, collector); + + // Assert + MacroStabilityInwardsStochasticSoilModelCollection stochasticSoilModels = failureMechanism.StochasticSoilModels; + Assert.AreEqual(sourcePath, stochasticSoilModels.SourcePath); + CollectionAssert.IsEmpty(stochasticSoilModels); + } + + [Test] + public void ReadAsMacroStabilityInwardsFailureMechanism_WithStochasticSoilModelsSet_MacroStabilityInwardsFailureMechanismWithStochasticSoilModelsSet() + { + // Setup + var random = new Random(21); + string segmentPointsXml = new Point2DCollectionXmlSerializer().ToXml(new[] + { + new Point2D(random.NextDouble(), random.NextDouble()) + }); + + const string sourcePath = "some/Path"; + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + StochasticSoilModelEntities = + { + new StochasticSoilModelEntity + { + StochasticSoilModelSegmentPointXml = segmentPointsXml, + MacroStabilityInwardsStochasticSoilProfileEntities = + { + MacroStabilityInwardsStochasticSoilProfileEntityTestFactory.CreateStochasticSoilProfileEntity() + }, + Name = "A", + Order = 1 + }, + new StochasticSoilModelEntity + { + StochasticSoilModelSegmentPointXml = segmentPointsXml, + MacroStabilityInwardsStochasticSoilProfileEntities = + { + MacroStabilityInwardsStochasticSoilProfileEntityTestFactory.CreateStochasticSoilProfileEntity() + }, + Name = "B", + Order = 0 + } + }, + MacroStabilityInwardsFailureMechanismMetaEntities = + { + new MacroStabilityInwardsFailureMechanismMetaEntity + { + StochasticSoilModelCollectionSourcePath = sourcePath + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + // Call + entity.ReadAsMacroStabilityInwardsFailureMechanism(failureMechanism, collector); + + // Assert + Assert.AreEqual(entity.StochasticSoilModelEntities.Count, failureMechanism.StochasticSoilModels.Count); + Assert.AreEqual(sourcePath, failureMechanism.StochasticSoilModels.SourcePath); + CollectionAssert.AreEqual(new[] + { + "B", + "A" + }, failureMechanism.StochasticSoilModels.Select(s => s.Name)); + } + + [Test] + public void ReadAsMacroStabilityInwardsFailureMechanism_WithoutSurfaceLinesWithSourcePath_FailureMechanismWithSurfaceLinesSourcePathSet() + { + // Setup + const string sourcePath = "some/path"; + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + MacroStabilityInwardsFailureMechanismMetaEntities = + { + new MacroStabilityInwardsFailureMechanismMetaEntity + { + SurfaceLineCollectionSourcePath = sourcePath + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + // Call + entity.ReadAsMacroStabilityInwardsFailureMechanism(failureMechanism, collector); + + // Assert + MacroStabilityInwardsSurfaceLineCollection surfaceLines = failureMechanism.SurfaceLines; + Assert.AreEqual(sourcePath, surfaceLines.SourcePath); + CollectionAssert.IsEmpty(surfaceLines); + } + + [Test] + public void ReadAsMacroStabilityInwardsFailureMechanism_WithSurfaceLines_MacroStabilityInwardsFailureMechanismWithSurfaceLinesSet() + { + // Setup + string emptyPointsXml = new Point3DCollectionXmlSerializer().ToXml(new Point3D[0]); + const string sourcePath = "some/path"; + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + SurfaceLineEntities = + { + new SurfaceLineEntity + { + PointsXml = emptyPointsXml, + Name = "1", + Order = 1 + }, + new SurfaceLineEntity + { + PointsXml = emptyPointsXml, + Name = "2", + Order = 0 + } + }, + MacroStabilityInwardsFailureMechanismMetaEntities = + { + new MacroStabilityInwardsFailureMechanismMetaEntity + { + SurfaceLineCollectionSourcePath = sourcePath + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + // Call + entity.ReadAsMacroStabilityInwardsFailureMechanism(failureMechanism, collector); + + // Assert + Assert.AreEqual(entity.SurfaceLineEntities.Count, failureMechanism.SurfaceLines.Count); + Assert.AreEqual(sourcePath, failureMechanism.SurfaceLines.SourcePath); + CollectionAssert.AreEqual(new[] + { + "2", + "1" + }, failureMechanism.SurfaceLines.Select(sl => sl.Name)); + } + + [Test] + public void ReadAsMacroStabilityInwardsFailureMechanism_WithSectionsSet_MacroStabilityInwardsFailureMechanismWithFailureMechanismSectionsSet() + { + // Setup + const string filePath = "failureMechanismSections/File/Path"; + + FailureMechanismSectionEntity failureMechanismSectionEntity = CreateSimpleFailureMechanismSectionEntity(); + failureMechanismSectionEntity.MacroStabilityInwardsSectionResultEntities.Add(new MacroStabilityInwardsSectionResultEntity + { + FailureMechanismSectionEntity = failureMechanismSectionEntity + }); + var entity = new FailureMechanismEntity + { + FailureMechanismSectionCollectionSourcePath = filePath, + CalculationGroupEntity = new CalculationGroupEntity(), + FailureMechanismSectionEntities = + { + failureMechanismSectionEntity + }, + MacroStabilityInwardsFailureMechanismMetaEntities = + { + new MacroStabilityInwardsFailureMechanismMetaEntity() + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + // Call + entity.ReadAsMacroStabilityInwardsFailureMechanism(failureMechanism, collector); + + // Assert + Assert.AreEqual(entity.FailureMechanismSectionEntities.Count, + failureMechanism.Sections.Count()); + Assert.AreEqual(entity.FailureMechanismSectionCollectionSourcePath, + failureMechanism.FailureMechanismSectionSourcePath); + } + + [Test] + public void ReadAsMacroStabilityInwardsFailureMechanism_WithCalculationsAndGroups_ReturnFailureMechanismWithCalculationAndGroups() + { + var entity = new FailureMechanismEntity + { + MacroStabilityInwardsFailureMechanismMetaEntities = + { + new MacroStabilityInwardsFailureMechanismMetaEntity() + }, + CalculationGroupEntity = new CalculationGroupEntity + { + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Name = "A", + Order = 1 + } + }, + MacroStabilityInwardsCalculationEntities = + { + new MacroStabilityInwardsCalculationEntity + { + Name = "B", + TangentLineNumber = 1, + Order = 0, + LeftGridNrOfHorizontalPoints = 5, + LeftGridNrOfVerticalPoints = 5, + RightGridNrOfHorizontalPoints = 5, + RightGridNrOfVerticalPoints = 5 + } + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + // Call + entity.ReadAsMacroStabilityInwardsFailureMechanism(failureMechanism, collector); + + // Assert + Assert.AreEqual(2, failureMechanism.CalculationsGroup.Children.Count); + + ICalculationBase expectedCalculation = failureMechanism.CalculationsGroup.Children[0]; + Assert.AreEqual("B", expectedCalculation.Name); + Assert.IsInstanceOf(expectedCalculation); + + ICalculationBase expectedCalculationGroup = failureMechanism.CalculationsGroup.Children[1]; + Assert.AreEqual("A", expectedCalculationGroup.Name); + Assert.IsInstanceOf(expectedCalculationGroup); + } + + #endregion + + #region MacroStabilityOutwards + + [Test] + public void ReadAsMacroStabilityOutwardsFailureMechanism_EntityNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => ((FailureMechanismEntity) null).ReadAsMacroStabilityOutwardsFailureMechanism( + failureMechanism, + collector); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", parameter); + } + + [Test] + public void ReadAsMacroStabilityOutwardsFailureMechanism_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var entity = new FailureMechanismEntity(); + + // Call + TestDelegate test = () => entity.ReadAsMacroStabilityOutwardsFailureMechanism( + null, new ReadConversionCollector()); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("failureMechanism", parameter); + } + + [Test] + public void ReadAsMacroStabilityOutwardsFailureMechanism_CollectorNull_ThrowsArgumentNullException() + { + // Setup + var entity = new FailureMechanismEntity(); + + // Call + TestDelegate test = () => entity.ReadAsMacroStabilityOutwardsFailureMechanism( + new MacroStabilityOutwardsFailureMechanism(), null); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("collector", parameter); + } + + [Test] + public void ReadAsMacroStabilityOutwardsFailureMechanism_WithPropertiesSet_SetsMacroStabilityOutwardsFailureMechanismProperties() + { + // Setup + var random = new Random(31); + bool isRelevant = random.NextBoolean(); + var entity = new FailureMechanismEntity + { + IsRelevant = Convert.ToByte(isRelevant), + InputComments = "Some input text", + OutputComments = "Some output text", + NotRelevantComments = "Really not relevant", + CalculationGroupEntity = new CalculationGroupEntity(), + MacroStabilityOutwardsFailureMechanismMetaEntities = new[] + { + new MacroStabilityOutwardsFailureMechanismMetaEntity + { + A = random.NextDouble() + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); + + // Call + entity.ReadAsMacroStabilityOutwardsFailureMechanism(failureMechanism, collector); + + // Assert + Assert.IsNotNull(failureMechanism); + Assert.AreEqual(isRelevant, failureMechanism.IsRelevant); + Assert.AreEqual(entity.InputComments, failureMechanism.InputComments.Body); + Assert.AreEqual(entity.OutputComments, failureMechanism.OutputComments.Body); + Assert.AreEqual(entity.NotRelevantComments, failureMechanism.NotRelevantComments.Body); + CollectionAssert.IsEmpty(failureMechanism.Sections); + + MacroStabilityOutwardsFailureMechanismMetaEntity metaEntity = entity.MacroStabilityOutwardsFailureMechanismMetaEntities.Single(); + Assert.AreEqual(metaEntity.A, failureMechanism.MacroStabilityOutwardsProbabilityAssessmentInput.A); + } + + [Test] + public void ReadAsMacroStabilityOutwardsFailureMechanism_WithSectionsSet_MacroStabilityOutwardsFailureMechanismWithFailureMechanismSectionsSet() + { + // Setup + const string filePath = "failureMechanismSections/File/Path"; + FailureMechanismSectionEntity failureMechanismSectionEntity = CreateSimpleFailureMechanismSectionEntity(); + failureMechanismSectionEntity.MacroStabilityOutwardsSectionResultEntities.Add(new MacroStabilityOutwardsSectionResultEntity + { + FailureMechanismSectionEntity = failureMechanismSectionEntity + }); + var entity = new FailureMechanismEntity + { + FailureMechanismSectionCollectionSourcePath = filePath, + CalculationGroupEntity = new CalculationGroupEntity(), + FailureMechanismSectionEntities = + { + failureMechanismSectionEntity + }, + MacroStabilityOutwardsFailureMechanismMetaEntities = + { + new MacroStabilityOutwardsFailureMechanismMetaEntity() + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); + + // Call + entity.ReadAsMacroStabilityOutwardsFailureMechanism(failureMechanism, collector); + + // Assert + Assert.AreEqual(entity.FailureMechanismSectionEntities.Count, + failureMechanism.Sections.Count()); + Assert.AreEqual(entity.FailureMechanismSectionCollectionSourcePath, failureMechanism.FailureMechanismSectionSourcePath); + } + + #endregion + + #region Grass Cover Erosion Inwards + + [Test] + [TestCase(true)] + [TestCase(false)] + public void ReadAsGrassCoverErosionInwardsFailureMechanism_WithCollector_ReturnsNewGrassCoverErosionInwardsFailureMechanismWithPropertiesSet(bool isRelevant) + { + // Setup + var entity = new FailureMechanismEntity + { + IsRelevant = Convert.ToByte(isRelevant), + InputComments = "Some input text", + OutputComments = "Some output text", + NotRelevantComments = "Really not relevant", + GrassCoverErosionInwardsFailureMechanismMetaEntities = + { + new GrassCoverErosionInwardsFailureMechanismMetaEntity + { + N = new Random(39).NextRoundedDouble(1.0, 20.0) + } + }, + CalculationGroupEntity = new CalculationGroupEntity() + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + // Call + entity.ReadAsGrassCoverErosionInwardsFailureMechanism(failureMechanism, collector); + + // Assert + Assert.IsNotNull(failureMechanism); + Assert.AreEqual(isRelevant, failureMechanism.IsRelevant); + Assert.AreEqual(entity.InputComments, failureMechanism.InputComments.Body); + Assert.AreEqual(entity.OutputComments, failureMechanism.OutputComments.Body); + Assert.AreEqual(entity.NotRelevantComments, failureMechanism.NotRelevantComments.Body); + CollectionAssert.IsEmpty(failureMechanism.Sections); + + RoundedDouble actualN = failureMechanism.GeneralInput.N; + Assert.AreEqual(entity.GrassCoverErosionInwardsFailureMechanismMetaEntities.Single().N, actualN, actualN.GetAccuracy()); + + Assert.IsNull(failureMechanism.DikeProfiles.SourcePath); + } + + [Test] + public void ReadAsGrassCoverErosionInwardsFailureMechanism_WithDikeProfilesSet_ReturnsGrassCoverErosionInwardsFailureMechanismWithDikeProfilesAdded() + { + // Setup + string emptyDikeGeometryXml = new RoughnessPointCollectionXmlSerializer().ToXml(new RoughnessPoint[0]); + string emptyForeshoreBinaryXml = new Point2DCollectionXmlSerializer().ToXml(new Point2D[0]); + const string sourcePath = "some/path/to/my/dikeprofiles"; + var entity = new FailureMechanismEntity + { + GrassCoverErosionInwardsFailureMechanismMetaEntities = + { + new GrassCoverErosionInwardsFailureMechanismMetaEntity + { + N = 3, + DikeProfileCollectionSourcePath = sourcePath + } + }, + DikeProfileEntities = + { + new DikeProfileEntity + { + Id = "idA", + DikeGeometryXml = emptyDikeGeometryXml, + ForeshoreXml = emptyForeshoreBinaryXml + }, + new DikeProfileEntity + { + Id = "idB", + DikeGeometryXml = emptyDikeGeometryXml, + ForeshoreXml = emptyForeshoreBinaryXml + } + }, + CalculationGroupEntity = new CalculationGroupEntity() + }; + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var collector = new ReadConversionCollector(); + + // Call + entity.ReadAsGrassCoverErosionInwardsFailureMechanism(failureMechanism, collector); + + // Assert + Assert.AreEqual(2, failureMechanism.DikeProfiles.Count); + Assert.AreEqual(sourcePath, failureMechanism.DikeProfiles.SourcePath); + } + + [Test] + public void ReadAsGrassCoverErosionInwardsFailureMechanism_WithSectionsSet_ReturnsNewGrassCoverErosionInwardsFailureMechanismWithFailureMechanismSectionsAdded() + { + // Setup + const string filePath = "failureMechanismSections/File/Path"; + + FailureMechanismSectionEntity failureMechanismSectionEntity = CreateSimpleFailureMechanismSectionEntity(); + var grassCoverErosionInwardsSectionResultEntity = new GrassCoverErosionInwardsSectionResultEntity + { + FailureMechanismSectionEntity = failureMechanismSectionEntity + }; + failureMechanismSectionEntity.GrassCoverErosionInwardsSectionResultEntities.Add(grassCoverErosionInwardsSectionResultEntity); + var entity = new FailureMechanismEntity + { + FailureMechanismSectionCollectionSourcePath = filePath, + FailureMechanismSectionEntities = + { + failureMechanismSectionEntity + }, + GrassCoverErosionInwardsFailureMechanismMetaEntities = + { + new GrassCoverErosionInwardsFailureMechanismMetaEntity + { + N = 1 + } + }, + CalculationGroupEntity = new CalculationGroupEntity() + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + // Call + entity.ReadAsGrassCoverErosionInwardsFailureMechanism(failureMechanism, collector); + + // Assert + Assert.AreEqual(entity.FailureMechanismSectionEntities.Count, failureMechanism.Sections.Count()); + Assert.AreEqual(entity.FailureMechanismSectionCollectionSourcePath, failureMechanism.FailureMechanismSectionSourcePath); + } + + [Test] + public void ReadAsGrassCoverErosionInwardsFailureMechanism_WithCalculationGroup_ReturnsNewGrassCoverErosionInwardsFailureMechanismWithCalculationGroupSet() + { + // Setup + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity + { + Name = "Berekeningen", + Order = 0, + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Name = "Child1", + Order = 0 + }, + new CalculationGroupEntity + { + Name = "Child2", + Order = 1 + } + } + }, + GrassCoverErosionInwardsFailureMechanismMetaEntities = + { + new GrassCoverErosionInwardsFailureMechanismMetaEntity + { + N = 1 + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + // Call + entity.ReadAsGrassCoverErosionInwardsFailureMechanism(failureMechanism, collector); + + // Assert + Assert.AreEqual(2, failureMechanism.CalculationsGroup.Children.Count); + + ICalculationBase child1 = failureMechanism.CalculationsGroup.Children[0]; + Assert.AreEqual("Child1", child1.Name); + + ICalculationBase child2 = failureMechanism.CalculationsGroup.Children[1]; + Assert.AreEqual("Child2", child2.Name); + } + + #endregion + + #region Grass Cover Erosion Outwards + + [Test] + [TestCase(true)] + [TestCase(false)] + public void ReadAsGrassCoverErosionOutwardsFailureMechanism_WithCollector_ReturnsNewGrassCoverErosionOutwardsFailureMechanismWithPropertiesSet(bool isRelevant) + { + // Setup + var entity = new FailureMechanismEntity + { + IsRelevant = Convert.ToByte(isRelevant), + InputComments = "Some input text", + OutputComments = "Some output text", + NotRelevantComments = "Really not relevant", + GrassCoverErosionOutwardsFailureMechanismMetaEntities = + { + new GrassCoverErosionOutwardsFailureMechanismMetaEntity + { + N = new Random(39).NextRoundedDouble(1.0, 20.0), + HydraulicLocationCalculationCollectionEntity = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity1 = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity2 = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity3 = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity4 = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity5 = new HydraulicLocationCalculationCollectionEntity() + } + }, + CalculationGroupEntity = new CalculationGroupEntity() + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + + // Call + entity.ReadAsGrassCoverErosionOutwardsFailureMechanism(failureMechanism, collector); + + // Assert + Assert.IsNotNull(failureMechanism); + Assert.AreEqual(isRelevant, failureMechanism.IsRelevant); + Assert.AreEqual(entity.InputComments, failureMechanism.InputComments.Body); + Assert.AreEqual(entity.OutputComments, failureMechanism.OutputComments.Body); + Assert.AreEqual(entity.NotRelevantComments, failureMechanism.NotRelevantComments.Body); + CollectionAssert.IsEmpty(failureMechanism.Sections); + + RoundedDouble actualN = failureMechanism.GeneralInput.N; + Assert.AreEqual(entity.GrassCoverErosionOutwardsFailureMechanismMetaEntities.Single().N, actualN, actualN.GetAccuracy()); + Assert.IsNull(failureMechanism.ForeshoreProfiles.SourcePath); + } + + [Test] + public void ReadAsGrassCoverErosionOutwardsFailureMechanism_WithoutForeshoreProfilesWithSourcePath_ReturnsFailureMechanismWithSourcePathSet() + { + // Setup + const string fileLocation = "some/path/to/foreshoreProfiles"; + + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + GrassCoverErosionOutwardsFailureMechanismMetaEntities = + { + new GrassCoverErosionOutwardsFailureMechanismMetaEntity + { + ForeshoreProfileCollectionSourcePath = fileLocation, + N = 1, + HydraulicLocationCalculationCollectionEntity = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity1 = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity2 = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity3 = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity4 = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity5 = new HydraulicLocationCalculationCollectionEntity() + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + + // Call + entity.ReadAsGrassCoverErosionOutwardsFailureMechanism(failureMechanism, collector); + + // Assert + ForeshoreProfileCollection foreshoreProfiles = failureMechanism.ForeshoreProfiles; + Assert.AreEqual(fileLocation, foreshoreProfiles.SourcePath); + CollectionAssert.IsEmpty(foreshoreProfiles); + } + + [Test] + public void ReadAsGrassCoverErosionOutwardsFailureMechanism_WithHydraulicBoundaryLocationCalculations_ReturnsFailureMechanismWithHydraulicBoundaryLocationCalculations() + { + // Setup + HydraulicLocationEntity hydraulicLocationEntity = HydraulicLocationEntityTestFactory.CreateHydraulicLocationEntity(); + var metaEntity = new GrassCoverErosionOutwardsFailureMechanismMetaEntity + { + N = 1, + HydraulicLocationCalculationCollectionEntity = CreateHydraulicLocationCollectionCalculationEntity(hydraulicLocationEntity, 1), + HydraulicLocationCalculationCollectionEntity1 = CreateHydraulicLocationCollectionCalculationEntity(hydraulicLocationEntity, 2), + HydraulicLocationCalculationCollectionEntity2 = CreateHydraulicLocationCollectionCalculationEntity(hydraulicLocationEntity, 3), + HydraulicLocationCalculationCollectionEntity3 = CreateHydraulicLocationCollectionCalculationEntity(hydraulicLocationEntity, 4), + HydraulicLocationCalculationCollectionEntity4 = CreateHydraulicLocationCollectionCalculationEntity(hydraulicLocationEntity, 5), + HydraulicLocationCalculationCollectionEntity5 = CreateHydraulicLocationCollectionCalculationEntity(hydraulicLocationEntity, 6) + }; + + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + GrassCoverErosionOutwardsFailureMechanismMetaEntities = + { + metaEntity + } + }; + + var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + var collector = new ReadConversionCollector(); + collector.Read(hydraulicLocationEntity, hydraulicBoundaryLocation); + + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + failureMechanism.SetHydraulicBoundaryLocationCalculations(new[] + { + hydraulicBoundaryLocation + }); + + // Call + entity.ReadAsGrassCoverErosionOutwardsFailureMechanism(failureMechanism, collector); + + // Assert + HydraulicBoundaryLocationCalculation calculation = failureMechanism.WaterLevelCalculationsForMechanismSpecificFactorizedSignalingNorm + .Single(); + HydraulicLocationCalculationEntity hydraulicLocationCalculationEntity = metaEntity.HydraulicLocationCalculationCollectionEntity5 + .HydraulicLocationCalculationEntities + .Single(); + AssertHydraulicBoundaryLocationCalculation(hydraulicLocationCalculationEntity, hydraulicBoundaryLocation, calculation); + + calculation = failureMechanism.WaterLevelCalculationsForMechanismSpecificSignalingNorm + .Single(); + hydraulicLocationCalculationEntity = metaEntity.HydraulicLocationCalculationCollectionEntity4 + .HydraulicLocationCalculationEntities + .Single(); + AssertHydraulicBoundaryLocationCalculation(hydraulicLocationCalculationEntity, hydraulicBoundaryLocation, calculation); + + calculation = failureMechanism.WaterLevelCalculationsForMechanismSpecificLowerLimitNorm + .Single(); + hydraulicLocationCalculationEntity = metaEntity.HydraulicLocationCalculationCollectionEntity3 + .HydraulicLocationCalculationEntities + .Single(); + AssertHydraulicBoundaryLocationCalculation(hydraulicLocationCalculationEntity, hydraulicBoundaryLocation, calculation); + + calculation = failureMechanism.WaveHeightCalculationsForMechanismSpecificFactorizedSignalingNorm + .Single(); + hydraulicLocationCalculationEntity = metaEntity.HydraulicLocationCalculationCollectionEntity2 + .HydraulicLocationCalculationEntities + .Single(); + AssertHydraulicBoundaryLocationCalculation(hydraulicLocationCalculationEntity, hydraulicBoundaryLocation, calculation); + + calculation = failureMechanism.WaveHeightCalculationsForMechanismSpecificSignalingNorm + .Single(); + hydraulicLocationCalculationEntity = metaEntity.HydraulicLocationCalculationCollectionEntity1 + .HydraulicLocationCalculationEntities + .Single(); + AssertHydraulicBoundaryLocationCalculation(hydraulicLocationCalculationEntity, hydraulicBoundaryLocation, calculation); + + calculation = failureMechanism.WaveHeightCalculationsForMechanismSpecificLowerLimitNorm + .Single(); + hydraulicLocationCalculationEntity = metaEntity.HydraulicLocationCalculationCollectionEntity + .HydraulicLocationCalculationEntities + .Single(); + AssertHydraulicBoundaryLocationCalculation(hydraulicLocationCalculationEntity, hydraulicBoundaryLocation, calculation); + } + + [Test] + public void ReadAsGrassCoverErosionOutwardsFailureMechanism_WithForeshoreProfilesAndSourcePath_ReturnsFailureMechanismWithForeshoreProfilesAndSourcePathSet() + { + // Setup + const string fileLocation = "some/path/to/foreshoreProfiles"; + + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + ForeshoreProfileEntities = + { + new ForeshoreProfileEntity + { + Id = "Child1", + GeometryXml = new Point2DCollectionXmlSerializer().ToXml(Enumerable.Empty()), + Order = 1 + }, + new ForeshoreProfileEntity + { + Id = "Child2", + GeometryXml = new Point2DCollectionXmlSerializer().ToXml(Enumerable.Empty()), + Order = 0 + } + }, + GrassCoverErosionOutwardsFailureMechanismMetaEntities = + { + new GrassCoverErosionOutwardsFailureMechanismMetaEntity + { + ForeshoreProfileCollectionSourcePath = fileLocation, + N = 1, + HydraulicLocationCalculationCollectionEntity = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity1 = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity2 = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity3 = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity4 = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity5 = new HydraulicLocationCalculationCollectionEntity() + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + + // Call + entity.ReadAsGrassCoverErosionOutwardsFailureMechanism(failureMechanism, collector); + + // Assert + ForeshoreProfileCollection foreshoreProfiles = failureMechanism.ForeshoreProfiles; + Assert.AreEqual(2, foreshoreProfiles.Count); + Assert.AreEqual(fileLocation, foreshoreProfiles.SourcePath); + + ForeshoreProfile child1 = foreshoreProfiles[0]; + Assert.AreEqual("Child2", child1.Id); + + ForeshoreProfile child2 = foreshoreProfiles[1]; + Assert.AreEqual("Child1", child2.Id); + } + + [Test] + public void ReadAsGrassCoverErosionOutwardsFailureMechanism_WithSectionsSet_ReturnsNewGrassCoverErosionOutwardsFailureMechanismWithFailureMechanismSectionsAdded() + { + // Setup + const string filePath = "failureMechanismSections/File/Path"; + + FailureMechanismSectionEntity failureMechanismSectionEntity = CreateSimpleFailureMechanismSectionEntity(); + var grassCoverErosionOutwardsSectionResultEntity = new GrassCoverErosionOutwardsSectionResultEntity + { + FailureMechanismSectionEntity = failureMechanismSectionEntity + }; + failureMechanismSectionEntity.GrassCoverErosionOutwardsSectionResultEntities.Add(grassCoverErosionOutwardsSectionResultEntity); + var entity = new FailureMechanismEntity + { + FailureMechanismSectionCollectionSourcePath = filePath, + FailureMechanismSectionEntities = + { + failureMechanismSectionEntity + }, + GrassCoverErosionOutwardsFailureMechanismMetaEntities = + { + new GrassCoverErosionOutwardsFailureMechanismMetaEntity + { + N = 1, + HydraulicLocationCalculationCollectionEntity = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity1 = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity2 = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity3 = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity4 = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity5 = new HydraulicLocationCalculationCollectionEntity() + } + }, + CalculationGroupEntity = new CalculationGroupEntity() + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + + // Call + entity.ReadAsGrassCoverErosionOutwardsFailureMechanism(failureMechanism, collector); + + // Assert + Assert.AreEqual(entity.FailureMechanismSectionEntities.Count, failureMechanism.Sections.Count()); + Assert.AreEqual(entity.FailureMechanismSectionCollectionSourcePath, failureMechanism.FailureMechanismSectionSourcePath); + } + + [Test] + public void ReadAsGrassCoverErosionOutwardsFailureMechanism_WithWaveConditionsCalculationGroup_ReturnsNewGrassCoverErosionOutwardsFailureMechanismWithCalculationGroupSet() + { + // Setup + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity + { + Name = "Berekeningen", + Order = 0, + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Name = "Child1", + Order = 0 + }, + new CalculationGroupEntity + { + Name = "Child2", + Order = 1 + } + } + }, + GrassCoverErosionOutwardsFailureMechanismMetaEntities = + { + new GrassCoverErosionOutwardsFailureMechanismMetaEntity + { + N = 1, + HydraulicLocationCalculationCollectionEntity = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity1 = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity2 = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity3 = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity4 = new HydraulicLocationCalculationCollectionEntity(), + HydraulicLocationCalculationCollectionEntity5 = new HydraulicLocationCalculationCollectionEntity() + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + + // Call + entity.ReadAsGrassCoverErosionOutwardsFailureMechanism(failureMechanism, collector); + + // Assert + Assert.AreEqual(2, failureMechanism.WaveConditionsCalculationGroup.Children.Count); + + ICalculationBase child1 = failureMechanism.WaveConditionsCalculationGroup.Children[0]; + Assert.AreEqual("Child1", child1.Name); + + ICalculationBase child2 = failureMechanism.WaveConditionsCalculationGroup.Children[1]; + Assert.AreEqual("Child2", child2.Name); + } + + private static HydraulicLocationCalculationCollectionEntity CreateHydraulicLocationCollectionCalculationEntity(HydraulicLocationEntity hydraulicLocationEntity, + int seed) + { + var random = new Random(seed); + return new HydraulicLocationCalculationCollectionEntity + { + HydraulicLocationCalculationEntities = + { + new HydraulicLocationCalculationEntity + { + HydraulicLocationEntity = hydraulicLocationEntity, + ShouldIllustrationPointsBeCalculated = Convert.ToByte(random.NextBoolean()) + } + } + }; + } + + private static void AssertHydraulicBoundaryLocationCalculation(HydraulicLocationCalculationEntity expectedEntity, + HydraulicBoundaryLocation expectedHydraulicBoundaryLocation, + HydraulicBoundaryLocationCalculation actualCalculation) + { + Assert.AreSame(expectedHydraulicBoundaryLocation, actualCalculation.HydraulicBoundaryLocation); + Assert.AreEqual(Convert.ToBoolean(expectedEntity.ShouldIllustrationPointsBeCalculated), + actualCalculation.InputParameters.ShouldIllustrationPointsBeCalculated); + Assert.IsNull(actualCalculation.Output); + } + + #endregion + + #region Stability Stone Cover + + [Test] + [TestCase(true)] + [TestCase(false)] + public void ReadAsStabilityStoneCoverFailureMechanism_WithCollector_ReturnsNewStabilityStoneCoverFailureMechanismWithPropertiesSet(bool isRelevant) + { + // Setup + var entity = new FailureMechanismEntity + { + IsRelevant = Convert.ToByte(isRelevant), + InputComments = "Some input text", + OutputComments = "Some output text", + NotRelevantComments = "Really not relevant", + CalculationGroupEntity = new CalculationGroupEntity(), + StabilityStoneCoverFailureMechanismMetaEntities = + { + new StabilityStoneCoverFailureMechanismMetaEntity + { + N = new Random(39).NextRoundedDouble(1.0, 20.0) + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new StabilityStoneCoverFailureMechanism(); + + // Call + entity.ReadAsStabilityStoneCoverFailureMechanism(failureMechanism, collector); + + // Assert + Assert.IsNotNull(failureMechanism); + Assert.AreEqual(isRelevant, failureMechanism.IsRelevant); + Assert.AreEqual(entity.InputComments, failureMechanism.InputComments.Body); + Assert.AreEqual(entity.OutputComments, failureMechanism.OutputComments.Body); + Assert.AreEqual(entity.NotRelevantComments, failureMechanism.NotRelevantComments.Body); + CollectionAssert.IsEmpty(failureMechanism.Sections); + + RoundedDouble actualN = failureMechanism.GeneralInput.N; + Assert.AreEqual(entity.StabilityStoneCoverFailureMechanismMetaEntities.Single().N, actualN, actualN.GetAccuracy()); + + Assert.IsNull(failureMechanism.ForeshoreProfiles.SourcePath); + } + + [Test] + public void ReadAsStabilityStoneCoverFailureMechanism_WithWaveConditionsCalculationGroup_ReturnsNewStabilityStoneCoverFailureMechanismWithCalculationGroupSet() + { + // Setup + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity + { + Name = "Berekeningen", + Order = 0, + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Name = "Child1", + Order = 1 + }, + new CalculationGroupEntity + { + Name = "Child2", + Order = 0 + } + } + }, + StabilityStoneCoverFailureMechanismMetaEntities = + { + new StabilityStoneCoverFailureMechanismMetaEntity + { + N = 4.2 + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new StabilityStoneCoverFailureMechanism(); + + // Call + entity.ReadAsStabilityStoneCoverFailureMechanism(failureMechanism, collector); + + // Assert + Assert.AreEqual(2, failureMechanism.WaveConditionsCalculationGroup.Children.Count); + + ICalculationBase child1 = failureMechanism.WaveConditionsCalculationGroup.Children[0]; + Assert.AreEqual("Child2", child1.Name); + + ICalculationBase child2 = failureMechanism.WaveConditionsCalculationGroup.Children[1]; + Assert.AreEqual("Child1", child2.Name); + } + + [Test] + public void ReadAsStabilityStoneCoverFailureMechanism_WithoutForeshoreProfilesWithSourcePath_ReturnsFailureMechanismWithSourcePathSet() + { + // Setup + const string fileLocation = "some/path/to/foreshoreProfiles"; + + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + StabilityStoneCoverFailureMechanismMetaEntities = + { + new StabilityStoneCoverFailureMechanismMetaEntity + { + ForeshoreProfileCollectionSourcePath = fileLocation, + N = 1.2 + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new StabilityStoneCoverFailureMechanism(); + + // Call + entity.ReadAsStabilityStoneCoverFailureMechanism(failureMechanism, collector); + + // Assert + ForeshoreProfileCollection foreshoreProfiles = failureMechanism.ForeshoreProfiles; + Assert.AreEqual(fileLocation, foreshoreProfiles.SourcePath); + CollectionAssert.IsEmpty(foreshoreProfiles); + } + + [Test] + public void ReadAsStabilityStoneCoverFailureMechanism_WithForeshoreProfilesAndSourcePath_ReturnsFailureMechanismWithForeshoreProfilesAndSourcePathSet() + { + // Setup + const string fileLocation = "some/path/to/foreshoreProfiles"; + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + ForeshoreProfileEntities = + { + new ForeshoreProfileEntity + { + Id = "Child1", + GeometryXml = new Point2DCollectionXmlSerializer().ToXml(Enumerable.Empty()), + Order = 1 + }, + new ForeshoreProfileEntity + { + Id = "Child2", + GeometryXml = new Point2DCollectionXmlSerializer().ToXml(Enumerable.Empty()), + Order = 0 + } + }, + StabilityStoneCoverFailureMechanismMetaEntities = + { + new StabilityStoneCoverFailureMechanismMetaEntity + { + ForeshoreProfileCollectionSourcePath = fileLocation, + N = 8.123 + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new StabilityStoneCoverFailureMechanism(); + + // Call + entity.ReadAsStabilityStoneCoverFailureMechanism(failureMechanism, collector); + + // Assert + ForeshoreProfileCollection foreshoreProfiles = failureMechanism.ForeshoreProfiles; + Assert.AreEqual(2, foreshoreProfiles.Count); + Assert.AreEqual(fileLocation, foreshoreProfiles.SourcePath); + + ForeshoreProfile child1 = foreshoreProfiles[0]; + Assert.AreEqual("Child2", child1.Id); + + ForeshoreProfile child2 = foreshoreProfiles[1]; + Assert.AreEqual("Child1", child2.Id); + } + + [Test] + public void ReadAsStabilityStoneCoverFailureMechanism_WithSectionsSet_StabilityStoneCoverFailureMechanismWithFailureMechanismSectionsSet() + { + // Setup + const string filePath = "failureMechanismSections/FilePath"; + + FailureMechanismSectionEntity failureMechanismSectionEntity = CreateSimpleFailureMechanismSectionEntity(); + failureMechanismSectionEntity.StabilityStoneCoverSectionResultEntities.Add(new StabilityStoneCoverSectionResultEntity + { + FailureMechanismSectionEntity = failureMechanismSectionEntity + }); + var entity = new FailureMechanismEntity + { + FailureMechanismSectionCollectionSourcePath = filePath, + CalculationGroupEntity = new CalculationGroupEntity(), + FailureMechanismSectionEntities = + { + failureMechanismSectionEntity + }, + StabilityStoneCoverFailureMechanismMetaEntities = + { + new StabilityStoneCoverFailureMechanismMetaEntity + { + N = 2 + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new StabilityStoneCoverFailureMechanism(); + + // Call + entity.ReadAsStabilityStoneCoverFailureMechanism(failureMechanism, collector); + + // Assert + Assert.AreEqual(entity.FailureMechanismSectionEntities.Count, + failureMechanism.Sections.Count()); + Assert.AreEqual(entity.FailureMechanismSectionCollectionSourcePath, + failureMechanism.FailureMechanismSectionSourcePath); + } + + #endregion + + #region Wave Impact Asphalt Cover + + [Test] + [TestCase(true)] + [TestCase(false)] + public void ReadAsWaveImpactAsphaltCoverFailureMechanism_WithCollector_ReturnsNewWaveImpactAsphaltCoverFailureMechanismWithPropertiesSet(bool isRelevant) + { + // Setup + var entity = new FailureMechanismEntity + { + IsRelevant = Convert.ToByte(isRelevant), + InputComments = "Some input text", + OutputComments = "Some output text", + NotRelevantComments = "Really not relevant", + CalculationGroupEntity = new CalculationGroupEntity(), + WaveImpactAsphaltCoverFailureMechanismMetaEntities = + { + new WaveImpactAsphaltCoverFailureMechanismMetaEntity + { + DeltaL = new Random(39).NextRoundedDouble(1.0, 2000.0) + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + + // Call + entity.ReadAsWaveImpactAsphaltCoverFailureMechanism(failureMechanism, collector); + + // Assert + Assert.IsNotNull(failureMechanism); + Assert.AreEqual(isRelevant, failureMechanism.IsRelevant); + Assert.AreEqual(entity.InputComments, failureMechanism.InputComments.Body); + Assert.AreEqual(entity.OutputComments, failureMechanism.OutputComments.Body); + Assert.AreEqual(entity.NotRelevantComments, failureMechanism.NotRelevantComments.Body); + CollectionAssert.IsEmpty(failureMechanism.Sections); + + RoundedDouble actualDeltaL = failureMechanism.GeneralWaveImpactAsphaltCoverInput.DeltaL; + Assert.AreEqual(entity.WaveImpactAsphaltCoverFailureMechanismMetaEntities.Single().DeltaL, actualDeltaL, actualDeltaL.GetAccuracy()); + + Assert.IsNull(failureMechanism.ForeshoreProfiles.SourcePath); + } + + [Test] + public void ReadAsWaveImpactAsphaltCoverFailureMechanism_WithWaveConditionsCalculationGroup_ReturnsNewWaveImpactAsphaltCoverFailureMechanismWithCalculationGroupSet() + { + // Setup + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity + { + Name = "Berekeningen", + Order = 0, + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Name = "Child1", + Order = 1 + }, + new CalculationGroupEntity + { + Name = "Child2", + Order = 0 + } + } + }, + WaveImpactAsphaltCoverFailureMechanismMetaEntities = + { + new WaveImpactAsphaltCoverFailureMechanismMetaEntity + { + DeltaL = new Random(39).NextRoundedDouble(1.0, 2000.0) + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + + // Call + entity.ReadAsWaveImpactAsphaltCoverFailureMechanism(failureMechanism, collector); + + // Assert + Assert.AreEqual(2, failureMechanism.WaveConditionsCalculationGroup.Children.Count); + + ICalculationBase child1 = failureMechanism.WaveConditionsCalculationGroup.Children[0]; + Assert.AreEqual("Child2", child1.Name); + + ICalculationBase child2 = failureMechanism.WaveConditionsCalculationGroup.Children[1]; + Assert.AreEqual("Child1", child2.Name); + } + + [Test] + public void ReadAsWaveImpactAsphaltCoverFailureMechanism_WithoutForeshoreProfilesWithSourcePath_ReturnsFailureMechanismWithSourcePathSet() + { + // Setup + const string fileLocation = "some/path/to/foreshoreProfiles"; + + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + WaveImpactAsphaltCoverFailureMechanismMetaEntities = + { + new WaveImpactAsphaltCoverFailureMechanismMetaEntity + { + ForeshoreProfileCollectionSourcePath = fileLocation, + DeltaL = new Random(39).NextRoundedDouble(1.0, 2000.0) + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + + // Call + entity.ReadAsWaveImpactAsphaltCoverFailureMechanism(failureMechanism, collector); + + // Assert + ForeshoreProfileCollection foreshoreProfiles = failureMechanism.ForeshoreProfiles; + Assert.AreEqual(fileLocation, foreshoreProfiles.SourcePath); + CollectionAssert.IsEmpty(foreshoreProfiles); + } + + [Test] + public void ReadAsWaveImpactAsphaltCoverFailureMechanism_WithForeshoreProfilesAndSourcePath_ReturnsFailureMechanismWithForeshoreProfilesAndSourcePathSet() + { + // Setup + const string fileLocation = "some/path/to/foreshoreProfiles"; + + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + ForeshoreProfileEntities = + { + new ForeshoreProfileEntity + { + Id = "Child1", + GeometryXml = new Point2DCollectionXmlSerializer().ToXml(Enumerable.Empty()), + Order = 1 + }, + new ForeshoreProfileEntity + { + Id = "Child2", + GeometryXml = new Point2DCollectionXmlSerializer().ToXml(Enumerable.Empty()), + Order = 0 + } + }, + WaveImpactAsphaltCoverFailureMechanismMetaEntities = + { + new WaveImpactAsphaltCoverFailureMechanismMetaEntity + { + ForeshoreProfileCollectionSourcePath = fileLocation, + DeltaL = new Random(39).NextRoundedDouble(1.0, 2000.0) + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + + // Call + entity.ReadAsWaveImpactAsphaltCoverFailureMechanism(failureMechanism, collector); + + // Assert + ForeshoreProfileCollection foreshoreProfiles = failureMechanism.ForeshoreProfiles; + Assert.AreEqual(2, foreshoreProfiles.Count); + Assert.AreEqual(fileLocation, foreshoreProfiles.SourcePath); + + ForeshoreProfile child1 = foreshoreProfiles[0]; + Assert.AreEqual("Child2", child1.Id); + + ForeshoreProfile child2 = foreshoreProfiles[1]; + Assert.AreEqual("Child1", child2.Id); + } + + [Test] + public void ReadAsWaveImpactAsphaltCoverFailureMechanism_WithSectionsSet_WaveImpactAsphaltCoverFailureMechanismWithFailureMechanismSectionsSet() + { + // Setup + const string filePath = "failureMechanismSections/FilePath"; + + FailureMechanismSectionEntity failureMechanismSectionEntity = CreateSimpleFailureMechanismSectionEntity(); + failureMechanismSectionEntity.WaveImpactAsphaltCoverSectionResultEntities.Add(new WaveImpactAsphaltCoverSectionResultEntity + { + FailureMechanismSectionEntity = failureMechanismSectionEntity + }); + var entity = new FailureMechanismEntity + { + FailureMechanismSectionCollectionSourcePath = filePath, + CalculationGroupEntity = new CalculationGroupEntity(), + FailureMechanismSectionEntities = + { + failureMechanismSectionEntity + }, + WaveImpactAsphaltCoverFailureMechanismMetaEntities = + { + new WaveImpactAsphaltCoverFailureMechanismMetaEntity + { + DeltaL = new Random(39).NextRoundedDouble(1.0, 2000.0) + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + + // Call + entity.ReadAsWaveImpactAsphaltCoverFailureMechanism(failureMechanism, collector); + + // Assert + Assert.AreEqual(entity.FailureMechanismSectionEntities.Count, + failureMechanism.Sections.Count()); + Assert.AreEqual(entity.FailureMechanismSectionCollectionSourcePath, + failureMechanism.FailureMechanismSectionSourcePath); + } + + #endregion + + #region Height Structures + + [Test] + [TestCase(true)] + [TestCase(false)] + public void ReadAsHeightStructuresFailureMechanism_WithCollector_ReturnsNewHeightStructuresFailureMechanismWithPropertiesSet(bool isRelevant) + { + // Setup + var entity = new FailureMechanismEntity + { + IsRelevant = Convert.ToByte(isRelevant), + InputComments = "Some input text", + OutputComments = "Some output text", + NotRelevantComments = "Really not relevant", + CalculationGroupEntity = new CalculationGroupEntity(), + HeightStructuresFailureMechanismMetaEntities = + { + new HeightStructuresFailureMechanismMetaEntity + { + N = new Random(39).NextRoundedDouble(1.0, 20.0) + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new HeightStructuresFailureMechanism(); + + // Call + entity.ReadAsHeightStructuresFailureMechanism(failureMechanism, collector); + + // Assert + Assert.IsNotNull(failureMechanism); + Assert.AreEqual(isRelevant, failureMechanism.IsRelevant); + Assert.AreEqual(entity.InputComments, failureMechanism.InputComments.Body); + Assert.AreEqual(entity.OutputComments, failureMechanism.OutputComments.Body); + Assert.AreEqual(entity.NotRelevantComments, failureMechanism.NotRelevantComments.Body); + CollectionAssert.IsEmpty(failureMechanism.Sections); + + RoundedDouble actualN = failureMechanism.GeneralInput.N; + Assert.AreEqual(entity.HeightStructuresFailureMechanismMetaEntities.Single().N, actualN, actualN.GetAccuracy()); + + Assert.IsNull(failureMechanism.ForeshoreProfiles.SourcePath); + } + + [Test] + public void ReadAsHeightStructuresFailureMechanism_WithoutForeshoreProfilesWithSourcePath_ReturnsFailureMechanismWithSourcePathSet() + { + // Setup + const string fileLocation = "some/path/to/foreshoreProfiles"; + + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + HeightStructuresFailureMechanismMetaEntities = + { + new HeightStructuresFailureMechanismMetaEntity + { + ForeshoreProfileCollectionSourcePath = fileLocation, + N = 1 + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new HeightStructuresFailureMechanism(); + + // Call + entity.ReadAsHeightStructuresFailureMechanism(failureMechanism, collector); + + // Assert + ForeshoreProfileCollection foreshoreProfiles = failureMechanism.ForeshoreProfiles; + Assert.AreEqual(fileLocation, foreshoreProfiles.SourcePath); + CollectionAssert.IsEmpty(foreshoreProfiles); + } + + [Test] + public void ReadAsHeightStructuresFailureMechanism_WithForeshoreProfilesAndSourcePath_ReturnFailureMechanismWithForeshoreProfilesAndSourcePathSet() + { + // Setup + const int generalInputN = 7; + const string fileLocation = "some/location/to/foreshoreProfiles"; + + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + ForeshoreProfileEntities = + { + new ForeshoreProfileEntity + { + Id = "Child1", + GeometryXml = new Point2DCollectionXmlSerializer().ToXml(Enumerable.Empty()), + Order = 1 + }, + new ForeshoreProfileEntity + { + Id = "Child2", + GeometryXml = new Point2DCollectionXmlSerializer().ToXml(Enumerable.Empty()), + Order = 0 + } + }, + HeightStructuresFailureMechanismMetaEntities = + { + new HeightStructuresFailureMechanismMetaEntity + { + N = generalInputN, + ForeshoreProfileCollectionSourcePath = fileLocation + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new HeightStructuresFailureMechanism(); + + // Call + entity.ReadAsHeightStructuresFailureMechanism(failureMechanism, collector); + + // Assert + ForeshoreProfileCollection foreshoreProfiles = failureMechanism.ForeshoreProfiles; + Assert.AreEqual(2, foreshoreProfiles.Count); + Assert.AreEqual(fileLocation, foreshoreProfiles.SourcePath); + + ForeshoreProfile child1 = foreshoreProfiles[0]; + Assert.AreEqual("Child2", child1.Id); + + ForeshoreProfile child2 = foreshoreProfiles[1]; + Assert.AreEqual("Child1", child2.Id); + + RoundedDouble actualN = failureMechanism.GeneralInput.N; + Assert.AreEqual(entity.HeightStructuresFailureMechanismMetaEntities.Single().N, actualN, actualN.GetAccuracy()); + } + + [Test] + public void ReadAsHeightStructuresFailureMechanism_WithoutHeightStructuresWithSourcePath_ReturnsFailureMechanismWithSourcePathSet() + { + // Setup + const string path = "path/to/closingStructues"; + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + HeightStructuresFailureMechanismMetaEntities = + { + new HeightStructuresFailureMechanismMetaEntity + { + N = 7, + HeightStructureCollectionSourcePath = path + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new HeightStructuresFailureMechanism(); + + // Call + entity.ReadAsHeightStructuresFailureMechanism(failureMechanism, collector); + + // Assert + StructureCollection heightStructures = + failureMechanism.HeightStructures; + Assert.AreEqual(0, heightStructures.Count); + Assert.AreEqual(path, heightStructures.SourcePath); + } + + [Test] + public void ReadAsHeightStructuresFailureMechanism_WithHeightStructures_ReturnFailureMechanismWithHeightStructuresSet() + { + // Setup + const string sourcePath = "Some path"; + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + HeightStructureEntities = + { + new HeightStructureEntity + { + Order = 2, + Name = "Child1", + Id = "a" + }, + new HeightStructureEntity + { + Order = 1, + Name = "Child2", + Id = "b" + } + }, + HeightStructuresFailureMechanismMetaEntities = + { + new HeightStructuresFailureMechanismMetaEntity + { + N = 7, + HeightStructureCollectionSourcePath = sourcePath + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new HeightStructuresFailureMechanism(); + + // Call + entity.ReadAsHeightStructuresFailureMechanism(failureMechanism, collector); + + // Assert + Assert.AreEqual(2, failureMechanism.HeightStructures.Count); + + HeightStructure child1 = failureMechanism.HeightStructures[0]; + Assert.AreEqual("Child2", child1.Name); + + HeightStructure child2 = failureMechanism.HeightStructures[1]; + Assert.AreEqual("Child1", child2.Name); + + Assert.AreEqual(sourcePath, failureMechanism.HeightStructures.SourcePath); + } + + [Test] + public void ReadAsHeightStructuresFailureMechanism_WithoutStructuresWithPath_ReturnFailureMechanismWithSourcePathSet() + { + // Setup + const string sourcePath = "Some path"; + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + HeightStructuresFailureMechanismMetaEntities = + { + new HeightStructuresFailureMechanismMetaEntity + { + N = 7, + HeightStructureCollectionSourcePath = sourcePath + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new HeightStructuresFailureMechanism(); + + // Call + entity.ReadAsHeightStructuresFailureMechanism(failureMechanism, collector); + + // Assert + Assert.AreEqual(sourcePath, failureMechanism.HeightStructures.SourcePath); + CollectionAssert.IsEmpty(failureMechanism.HeightStructures); + } + + [Test] + public void ReadAsHeightStructuresFailureMechanism_WithSectionsSet_HeightStructuresFailureMechanismWithFailureMechanismSectionsSet() + { + // Setup + const string filePath = "failureMechanismSections/FilePath"; + + FailureMechanismSectionEntity failureMechanismSectionEntity = CreateSimpleFailureMechanismSectionEntity(); + failureMechanismSectionEntity.HeightStructuresSectionResultEntities.Add(new HeightStructuresSectionResultEntity + { + FailureMechanismSectionEntity = failureMechanismSectionEntity + }); + var entity = new FailureMechanismEntity + { + FailureMechanismSectionCollectionSourcePath = filePath, + CalculationGroupEntity = new CalculationGroupEntity(), + FailureMechanismSectionEntities = + { + failureMechanismSectionEntity + }, + HeightStructuresFailureMechanismMetaEntities = + { + new HeightStructuresFailureMechanismMetaEntity + { + N = 2 + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new HeightStructuresFailureMechanism(); + + // Call + entity.ReadAsHeightStructuresFailureMechanism(failureMechanism, collector); + + // Assert + Assert.AreEqual(entity.FailureMechanismSectionEntities.Count, + failureMechanism.Sections.Count()); + Assert.AreEqual(entity.FailureMechanismSectionCollectionSourcePath, + failureMechanism.FailureMechanismSectionSourcePath); + } + + #endregion + + #region Closing Structures + + [Test] + [TestCase(true)] + [TestCase(false)] + public void ReadAsClosingStructuresFailureMechanism_WithCollector_ReturnsNewClosingStructuresFailureMechanismWithPropertiesSet(bool isRelevant) + { + // Setup + var entity = new FailureMechanismEntity + { + IsRelevant = Convert.ToByte(isRelevant), + InputComments = "Some input text", + OutputComments = "Some output text", + NotRelevantComments = "Really not relevant", + CalculationGroupEntity = new CalculationGroupEntity(), + ClosingStructuresFailureMechanismMetaEntities = + { + new ClosingStructuresFailureMechanismMetaEntity() + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new ClosingStructuresFailureMechanism(); + + // Call + entity.ReadAsClosingStructuresFailureMechanism(failureMechanism, collector); + + // Assert + Assert.IsNotNull(failureMechanism); + Assert.AreEqual(isRelevant, failureMechanism.IsRelevant); + Assert.AreEqual(entity.InputComments, failureMechanism.InputComments.Body); + Assert.AreEqual(entity.OutputComments, failureMechanism.OutputComments.Body); + Assert.AreEqual(entity.NotRelevantComments, failureMechanism.NotRelevantComments.Body); + CollectionAssert.IsEmpty(failureMechanism.Sections); + + Assert.IsNull(failureMechanism.ForeshoreProfiles.SourcePath); + } + + [Test] + public void ReadAsClosingStructuresFailureMechanism_WithoutForeshoreProfilesWithSourcePath_ReturnsFailureMechanismWithSourcePathSet() + { + // Setup + const string fileLocation = "some/path/to/foreshoreProfiles"; + + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + ClosingStructuresFailureMechanismMetaEntities = + { + new ClosingStructuresFailureMechanismMetaEntity + { + ForeshoreProfileCollectionSourcePath = fileLocation, + N2A = 1 + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new ClosingStructuresFailureMechanism(); + + // Call + entity.ReadAsClosingStructuresFailureMechanism(failureMechanism, collector); + + // Assert + ForeshoreProfileCollection foreshoreProfiles = failureMechanism.ForeshoreProfiles; + Assert.AreEqual(fileLocation, foreshoreProfiles.SourcePath); + CollectionAssert.IsEmpty(foreshoreProfiles); + } + + [Test] + public void ReadAsClosingStructuresFailureMechanism_WithForeshoreProfiles_ReturnFailureMechanismWithForeshoreProfilesSet() + { + // Setup + const int generalInputN2A = 3; + const string fileLocation = "some/location/to/foreshoreprofiles"; + + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + ForeshoreProfileEntities = + { + new ForeshoreProfileEntity + { + Id = "Child1", + GeometryXml = new Point2DCollectionXmlSerializer().ToXml(Enumerable.Empty()), + Order = 1 + }, + new ForeshoreProfileEntity + { + Id = "Child2", + GeometryXml = new Point2DCollectionXmlSerializer().ToXml(Enumerable.Empty()), + Order = 0 + } + }, + ClosingStructuresFailureMechanismMetaEntities = + { + new ClosingStructuresFailureMechanismMetaEntity + { + N2A = generalInputN2A, + ForeshoreProfileCollectionSourcePath = fileLocation + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new ClosingStructuresFailureMechanism(); + + // Call + entity.ReadAsClosingStructuresFailureMechanism(failureMechanism, collector); + + // Assert + ForeshoreProfileCollection foreshoreProfiles = failureMechanism.ForeshoreProfiles; + Assert.AreEqual(2, foreshoreProfiles.Count); + Assert.AreEqual(fileLocation, foreshoreProfiles.SourcePath); + + ForeshoreProfile child1 = foreshoreProfiles[0]; + Assert.AreEqual("Child2", child1.Id); + + ForeshoreProfile child2 = foreshoreProfiles[1]; + Assert.AreEqual("Child1", child2.Id); + + Assert.AreEqual(generalInputN2A, failureMechanism.GeneralInput.N2A); + } + + [Test] + public void ReadAsClosingStructuresFailureMechanism_WithoutClosingStructuresWithSourcePath_ReturnsFailureMechanismWithSourcePathSet() + { + // Setup + const string path = "path/to/closingStructues"; + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + ClosingStructuresFailureMechanismMetaEntities = + { + new ClosingStructuresFailureMechanismMetaEntity + { + ClosingStructureCollectionSourcePath = path + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new ClosingStructuresFailureMechanism(); + + // Call + entity.ReadAsClosingStructuresFailureMechanism(failureMechanism, collector); + + // Assert + StructureCollection closingStructures = + failureMechanism.ClosingStructures; + Assert.AreEqual(0, closingStructures.Count); + Assert.AreEqual(path, closingStructures.SourcePath); + } + + [Test] + public void ReadAsClosingStructuresFailureMechanism_WithClosingStructures_ReturnFailureMechanismWithClosingStructuresSet() + { + // Setup + const string sourcePath = "some/path"; + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + ClosingStructureEntities = + { + new ClosingStructureEntity + { + Order = 2, + Name = "Child1", + Id = "a" + }, + new ClosingStructureEntity + { + Order = 1, + Name = "Child2", + Id = "b" + } + }, + ClosingStructuresFailureMechanismMetaEntities = + { + new ClosingStructuresFailureMechanismMetaEntity + { + ClosingStructureCollectionSourcePath = sourcePath + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new ClosingStructuresFailureMechanism(); + + // Call + entity.ReadAsClosingStructuresFailureMechanism(failureMechanism, collector); + + // Assert + StructureCollection closingStructures = failureMechanism.ClosingStructures; + Assert.AreEqual(2, closingStructures.Count); + Assert.AreEqual(sourcePath, closingStructures.SourcePath); + + ClosingStructure child1 = closingStructures[0]; + Assert.AreEqual("Child2", child1.Name); + + ClosingStructure child2 = closingStructures[1]; + Assert.AreEqual("Child1", child2.Name); + } + + [Test] + public void ReadAsClosingStructuresFailureMechanism_WithCalculationsAndGroups_ReturnFailureMechanismWithCalculationsAndGroups() + { + // Setup + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity + { + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Name = "A", + Order = 1 + } + }, + ClosingStructuresCalculationEntities = + { + new ClosingStructuresCalculationEntity + { + Name = "B", + Order = 0, + IdenticalApertures = 1 + } + } + }, + ClosingStructuresFailureMechanismMetaEntities = + { + new ClosingStructuresFailureMechanismMetaEntity() + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new ClosingStructuresFailureMechanism(); + + // Call + entity.ReadAsClosingStructuresFailureMechanism(failureMechanism, collector); + + // Assert + Assert.AreEqual(2, failureMechanism.CalculationsGroup.Children.Count); + + ICalculationBase expectedCalculation = failureMechanism.CalculationsGroup.Children[0]; + Assert.AreEqual("B", expectedCalculation.Name); + Assert.IsInstanceOf>(expectedCalculation); + + ICalculationBase expectedCalculationGroup = failureMechanism.CalculationsGroup.Children[1]; + Assert.AreEqual("A", expectedCalculationGroup.Name); + Assert.IsInstanceOf(expectedCalculationGroup); + } + + [Test] + public void ReadAsClosingStructuresFailureMechanism_WithSectionsSet_ClosingStructuresFailureMechanismWithFailureMechanismSectionsSet() + { + // Setup + const string filePath = "failureMechanismSections/FilePath"; + + FailureMechanismSectionEntity failureMechanismSectionEntity = CreateSimpleFailureMechanismSectionEntity(); + failureMechanismSectionEntity.ClosingStructuresSectionResultEntities.Add(new ClosingStructuresSectionResultEntity + { + FailureMechanismSectionEntity = failureMechanismSectionEntity + }); + var entity = new FailureMechanismEntity + { + FailureMechanismSectionCollectionSourcePath = filePath, + CalculationGroupEntity = new CalculationGroupEntity(), + FailureMechanismSectionEntities = + { + failureMechanismSectionEntity + }, + ClosingStructuresFailureMechanismMetaEntities = + { + new ClosingStructuresFailureMechanismMetaEntity() + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new ClosingStructuresFailureMechanism(); + + // Call + entity.ReadAsClosingStructuresFailureMechanism(failureMechanism, collector); + + // Assert + Assert.AreEqual(entity.FailureMechanismSectionEntities.Count, + failureMechanism.Sections.Count()); + Assert.AreEqual(entity.FailureMechanismSectionCollectionSourcePath, + failureMechanism.FailureMechanismSectionSourcePath); + } + + #endregion + + #region Stability Point Structures + + [Test] + [TestCase(true)] + [TestCase(false)] + public void ReadAsStabilityPointStructuresFailureMechanism_WithCollector_ReturnsNewStabilityPointStructuresFailureMechanismWithPropertiesSet(bool isRelevant) + { + // Setup + var entity = new FailureMechanismEntity + { + IsRelevant = Convert.ToByte(isRelevant), + InputComments = "Some input text", + OutputComments = "Some output text", + NotRelevantComments = "Really not relevant", + CalculationGroupEntity = new CalculationGroupEntity(), + StabilityPointStructuresFailureMechanismMetaEntities = + { + new StabilityPointStructuresFailureMechanismMetaEntity + { + N = new Random(39).NextRoundedDouble(1.0, 20.0) + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + // Call + entity.ReadAsStabilityPointStructuresFailureMechanism(failureMechanism, collector); + + // Assert + Assert.IsNotNull(failureMechanism); + Assert.AreEqual(isRelevant, failureMechanism.IsRelevant); + Assert.AreEqual(entity.InputComments, failureMechanism.InputComments.Body); + Assert.AreEqual(entity.OutputComments, failureMechanism.OutputComments.Body); + Assert.AreEqual(entity.NotRelevantComments, failureMechanism.NotRelevantComments.Body); + CollectionAssert.IsEmpty(failureMechanism.Sections); + + RoundedDouble actualN = failureMechanism.GeneralInput.N; + Assert.AreEqual(entity.StabilityPointStructuresFailureMechanismMetaEntities.Single().N, actualN, actualN.GetAccuracy()); + Assert.IsNull(failureMechanism.ForeshoreProfiles.SourcePath); + } + + [Test] + public void ReadAsStabilityPointStructuresFailureMechanism_WithoutForeshoreProfilesWithSourcePath_ReturnsFailureMechanismWithSourcePathSet() + { + // Setup + const string fileLocation = "some/path/to/foreshoreProfiles"; + + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + StabilityPointStructuresFailureMechanismMetaEntities = + { + new StabilityPointStructuresFailureMechanismMetaEntity + { + ForeshoreProfileCollectionSourcePath = fileLocation, + N = 1 + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + // Call + entity.ReadAsStabilityPointStructuresFailureMechanism(failureMechanism, collector); + + // Assert + ForeshoreProfileCollection foreshoreProfiles = failureMechanism.ForeshoreProfiles; + Assert.AreEqual(fileLocation, foreshoreProfiles.SourcePath); + CollectionAssert.IsEmpty(foreshoreProfiles); + } + + [Test] + public void ReadAsStabilityPointStructuresFailureMechanism_WithForeshoreProfiles_ReturnFailureMechanismWithForeshoreProfilesSet() + { + // Setup + const double generalInputN = 5.0; + const string fileLocation = "some/location/to/foreshoreprofiles"; + + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + ForeshoreProfileEntities = + { + new ForeshoreProfileEntity + { + Id = "Child1", + GeometryXml = new Point2DCollectionXmlSerializer().ToXml(Enumerable.Empty()), + Order = 1 + }, + new ForeshoreProfileEntity + { + Id = "Child2", + GeometryXml = new Point2DCollectionXmlSerializer().ToXml(Enumerable.Empty()), + Order = 0 + } + }, + StabilityPointStructuresFailureMechanismMetaEntities = + { + new StabilityPointStructuresFailureMechanismMetaEntity + { + N = generalInputN, + ForeshoreProfileCollectionSourcePath = fileLocation + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + // Call + entity.ReadAsStabilityPointStructuresFailureMechanism(failureMechanism, collector); + + // Assert + ForeshoreProfileCollection foreshoreProfiles = failureMechanism.ForeshoreProfiles; + Assert.AreEqual(2, foreshoreProfiles.Count); + Assert.AreEqual(fileLocation, foreshoreProfiles.SourcePath); + + ForeshoreProfile child1 = foreshoreProfiles[0]; + Assert.AreEqual("Child2", child1.Id); + + ForeshoreProfile child2 = foreshoreProfiles[1]; + Assert.AreEqual("Child1", child2.Id); + + Assert.AreEqual(generalInputN, failureMechanism.GeneralInput.N, failureMechanism.GeneralInput.N); + } + + [Test] + public void ReadAsStabilityPointStructuresFailureMechanism_WithoutStabilityPointStructuresWithSourcePath_ReturnsFailureMechanismWithSourcePathSet() + { + // Setup + const string path = "path/to/stabilityPointStructues"; + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + StabilityPointStructuresFailureMechanismMetaEntities = + { + new StabilityPointStructuresFailureMechanismMetaEntity + { + N = 7, + StabilityPointStructureCollectionSourcePath = path + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + // Call + entity.ReadAsStabilityPointStructuresFailureMechanism(failureMechanism, collector); + + // Assert + StructureCollection stabilityPointStructures = + failureMechanism.StabilityPointStructures; + Assert.AreEqual(0, stabilityPointStructures.Count); + Assert.AreEqual(path, stabilityPointStructures.SourcePath); + } + + [Test] + public void ReadAsStabilityPointStructuresFailureMechanism_WithStabilityPointStructures_ReturnFailureMechanismWithStabilityPointStructuresSet() + { + // Setup + const string path = "path/to/stabilityPointStructures"; + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity(), + StabilityPointStructureEntities = + { + new StabilityPointStructureEntity + { + Order = 2, + Name = "Child1", + Id = "a" + }, + new StabilityPointStructureEntity + { + Order = 1, + Name = "Child2", + Id = "b" + } + }, + StabilityPointStructuresFailureMechanismMetaEntities = + { + new StabilityPointStructuresFailureMechanismMetaEntity + { + N = 7, + StabilityPointStructureCollectionSourcePath = path + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + // Call + entity.ReadAsStabilityPointStructuresFailureMechanism(failureMechanism, collector); + + // Assert + StructureCollection stabilityPointStructures = + failureMechanism.StabilityPointStructures; + Assert.AreEqual(2, stabilityPointStructures.Count); + Assert.AreEqual(path, stabilityPointStructures.SourcePath); + + StabilityPointStructure child1 = stabilityPointStructures[0]; + Assert.AreEqual("Child2", child1.Name); + + StabilityPointStructure child2 = stabilityPointStructures[1]; + Assert.AreEqual("Child1", child2.Name); + } + + [Test] + public void ReadAsStabilityPointStructuresFailureMechanism_WithCalculationsAndGroups_ReturnFailureMechanismWithCalculationsAndGroups() + { + // Setup + var entity = new FailureMechanismEntity + { + CalculationGroupEntity = new CalculationGroupEntity + { + CalculationGroupEntity1 = + { + new CalculationGroupEntity + { + Name = "A", + Order = 1 + } + }, + StabilityPointStructuresCalculationEntities = + { + new StabilityPointStructuresCalculationEntity + { + Name = "B", + Order = 0 + } + } + }, + StabilityPointStructuresFailureMechanismMetaEntities = + { + new StabilityPointStructuresFailureMechanismMetaEntity + { + N = 2 + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + // Call + entity.ReadAsStabilityPointStructuresFailureMechanism(failureMechanism, collector); + + // Assert + Assert.AreEqual(2, failureMechanism.CalculationsGroup.Children.Count); + + ICalculationBase expectedCalculation = failureMechanism.CalculationsGroup.Children[0]; + Assert.AreEqual("B", expectedCalculation.Name); + Assert.IsInstanceOf>(expectedCalculation); + + ICalculationBase expectedCalculationGroup = failureMechanism.CalculationsGroup.Children[1]; + Assert.AreEqual("A", expectedCalculationGroup.Name); + Assert.IsInstanceOf(expectedCalculationGroup); + } + + [Test] + public void ReadAsStabilityPointStructuresFailureMechanism_WithSectionsSet_StabilityPointStructuresFailureMechanismWithFailureMechanismSectionsSet() + { + // Setup + const string filePath = "failureMechanismSections/FilePath"; + + FailureMechanismSectionEntity failureMechanismSectionEntity = CreateSimpleFailureMechanismSectionEntity(); + failureMechanismSectionEntity.StabilityPointStructuresSectionResultEntities.Add(new StabilityPointStructuresSectionResultEntity + { + FailureMechanismSectionEntity = failureMechanismSectionEntity + }); + var entity = new FailureMechanismEntity + { + FailureMechanismSectionCollectionSourcePath = filePath, + CalculationGroupEntity = new CalculationGroupEntity(), + FailureMechanismSectionEntities = + { + failureMechanismSectionEntity + }, + StabilityPointStructuresFailureMechanismMetaEntities = + { + new StabilityPointStructuresFailureMechanismMetaEntity + { + N = 2 + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + // Call + entity.ReadAsStabilityPointStructuresFailureMechanism(failureMechanism, collector); + + // Assert + Assert.AreEqual(entity.FailureMechanismSectionEntities.Count, + failureMechanism.Sections.Count()); + Assert.AreEqual(entity.FailureMechanismSectionCollectionSourcePath, + failureMechanism.FailureMechanismSectionSourcePath); + } + + #endregion + + #region PipingStructure + + [Test] + public void ReadAsPipingStructureFailureMechanism_EntityNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new PipingStructureFailureMechanism(); + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => ((FailureMechanismEntity) null).ReadAsPipingStructureFailureMechanism( + failureMechanism, + collector); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", parameter); + } + + [Test] + public void ReadAsPipingStructureFailureMechanism_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var entity = new FailureMechanismEntity(); + + // Call + TestDelegate test = () => entity.ReadAsPipingStructureFailureMechanism( + null, new ReadConversionCollector()); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("failureMechanism", parameter); + } + + [Test] + public void ReadAsPipingStructureFailureMechanism_CollectorNull_ThrowsArgumentNullException() + { + // Setup + var entity = new FailureMechanismEntity(); + + // Call + TestDelegate test = () => entity.ReadAsPipingStructureFailureMechanism( + new PipingStructureFailureMechanism(), null); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("collector", parameter); + } + + [Test] + public void ReadAsPipingStructureFailureMechanism_WithPropertiesSet_SetsPipingStructureFailureMechanismProperties() + { + // Setup + var random = new Random(31); + bool isRelevant = random.NextBoolean(); + var entity = new FailureMechanismEntity + { + IsRelevant = Convert.ToByte(isRelevant), + InputComments = "Some input text", + OutputComments = "Some output text", + NotRelevantComments = "Really not relevant", + CalculationGroupEntity = new CalculationGroupEntity(), + PipingStructureFailureMechanismMetaEntities = new[] + { + new PipingStructureFailureMechanismMetaEntity + { + N = random.NextRoundedDouble(1.0, 20.0) + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new PipingStructureFailureMechanism(); + + // Call + entity.ReadAsPipingStructureFailureMechanism(failureMechanism, collector); + + // Assert + Assert.IsNotNull(failureMechanism); + Assert.AreEqual(isRelevant, failureMechanism.IsRelevant); + Assert.AreEqual(entity.InputComments, failureMechanism.InputComments.Body); + Assert.AreEqual(entity.OutputComments, failureMechanism.OutputComments.Body); + Assert.AreEqual(entity.NotRelevantComments, failureMechanism.NotRelevantComments.Body); + CollectionAssert.IsEmpty(failureMechanism.Sections); + + PipingStructureFailureMechanismMetaEntity metaEntity = entity.PipingStructureFailureMechanismMetaEntities.Single(); + Assert.AreEqual(metaEntity.N, failureMechanism.N, failureMechanism.N.GetAccuracy()); + } + + [Test] + public void ReadAsPipingStructureFailureMechanism_WithSectionsSet_PipingStructureFailureMechanismWithFailureMechanismSectionsSet() + { + // Setup + const string filePath = "failureMechanismSections/FilePath"; + + FailureMechanismSectionEntity failureMechanismSectionEntity = CreateSimpleFailureMechanismSectionEntity(); + failureMechanismSectionEntity.PipingStructureSectionResultEntities.Add(new PipingStructureSectionResultEntity + { + FailureMechanismSectionEntity = failureMechanismSectionEntity + }); + var entity = new FailureMechanismEntity + { + FailureMechanismSectionCollectionSourcePath = filePath, + CalculationGroupEntity = new CalculationGroupEntity(), + FailureMechanismSectionEntities = + { + failureMechanismSectionEntity + }, + PipingStructureFailureMechanismMetaEntities = + { + new PipingStructureFailureMechanismMetaEntity + { + N = 1.0 + } + } + }; + var collector = new ReadConversionCollector(); + var failureMechanism = new PipingStructureFailureMechanism(); + + // Call + entity.ReadAsPipingStructureFailureMechanism(failureMechanism, collector); + + // Assert + Assert.AreEqual(entity.FailureMechanismSectionEntities.Count, + failureMechanism.Sections.Count()); + Assert.AreEqual(entity.FailureMechanismSectionCollectionSourcePath, + failureMechanism.FailureMechanismSectionSourcePath); + } + + #endregion + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/FailureMechanismSectionEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/FailureMechanismSectionEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/FailureMechanismSectionEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,94 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.Common.Data.FailureMechanism; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Read +{ + [TestFixture] + public class FailureMechanismSectionEntityReadExtensionsTest + { + [Test] + public void Read_CollectorNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => new FailureMechanismSectionEntity().Read(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + [TestCase("")] + [TestCase(null)] + public void Read_FailureMechanismSectionPointXmlNullOrEmpty_ThrowsArgumentException(string xml) + { + // Setup + var entity = new FailureMechanismSectionEntity + { + FailureMechanismSectionPointXml = xml + }; + + // Call + TestDelegate test = () => entity.Read(new ReadConversionCollector()); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("xml", paramName); + } + + [Test] + public void Read_WithCollector_NewPointAndEntityRegistered() + { + // Setup + const string name = "testName"; + var points = new[] + { + new Point2D(0, 0) + }; + string pointXml = new Point2DCollectionXmlSerializer().ToXml(points); + var entity = new FailureMechanismSectionEntity + { + Name = name, + FailureMechanismSectionPointXml = pointXml + }; + + var collector = new ReadConversionCollector(); + + // Call + FailureMechanismSection section = entity.Read(collector); + + // Assert + Assert.IsNotNull(section); + Assert.AreEqual(name, section.Name); + Assert.AreEqual(section, collector.Get(entity)); + + Assert.IsTrue(collector.Contains(entity)); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/ForeshoreProfileReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/ForeshoreProfileReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/ForeshoreProfileReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,167 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.TestUtil; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Read +{ + [TestFixture] + public class ForeshoreProfileReadExtensionsTest + { + [Test] + public void Read_CollectorNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => new ForeshoreProfileEntity().Read(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void Read_EntityNotReadBefore_EntityRegistered() + { + // Setup + var collector = new ReadConversionCollector(); + + var entity = new ForeshoreProfileEntity + { + Id = "id", + GeometryXml = new Point2DCollectionXmlSerializer().ToXml(new Point2D[0]) + }; + + // Precondition + Assert.IsFalse(collector.Contains(entity)); + + // Call + entity.Read(collector); + + // Assert + Assert.IsTrue(collector.Contains(entity)); + } + + [Test] + [TestCase("")] + [TestCase(null)] + public void Read_GeometryXmlNullOrEmpty_ThrowsArgumentException(string xml) + { + // Setup + var entity = new ForeshoreProfileEntity + { + GeometryXml = xml + }; + + // Call + TestDelegate test = () => entity.Read(new ReadConversionCollector()); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("xml", paramName); + } + + [Test] + public void Read_EmptyGeometryBreakWaterTypeAndNullableValuesAreNull_ForeshoreProfileWithoutBreakWaterNaNValues() + { + // Setup + const string name = "testName"; + const string id = "testId"; + string pointXml = new Point2DCollectionXmlSerializer().ToXml(Enumerable.Empty()); + var entity = new ForeshoreProfileEntity + { + Id = id, + Name = name, + GeometryXml = pointXml + }; + + var readConversionCollector = new ReadConversionCollector(); + + // Call + ForeshoreProfile foreshoreProfile = entity.Read(readConversionCollector); + + // Assert + Assert.IsNotNull(foreshoreProfile); + Assert.AreEqual(id, foreshoreProfile.Id); + Assert.AreEqual(name, foreshoreProfile.Name); + Assert.IsNaN(foreshoreProfile.Orientation); + Assert.IsNaN(foreshoreProfile.X0); + Assert.IsNull(foreshoreProfile.BreakWater); + Assert.IsFalse(foreshoreProfile.HasBreakWater); + CollectionAssert.IsEmpty(foreshoreProfile.Geometry); + } + + [Test] + public void Read_WithGeometryAndBreakWaterTypeAndValues_CompleteForeshoreProfile() + { + // Setup + const string name = "testName"; + const string id = "testId"; + var random = new Random(21); + int order = random.Next(); + double orientation = random.NextDouble(); + double x0 = random.NextDouble(); + double height = random.NextDouble(); + const BreakWaterType breakWaterType = BreakWaterType.Wall; + + var points = new[] + { + new Point2D(0, 0) + }; + string pointXml = new Point2DCollectionXmlSerializer().ToXml(points); + var entity = new ForeshoreProfileEntity + { + Order = order, + Id = id, + Name = name, + Orientation = orientation, + X0 = x0, + BreakWaterType = Convert.ToByte(breakWaterType), + BreakWaterHeight = height, + GeometryXml = pointXml + }; + + var readConversionCollector = new ReadConversionCollector(); + + // Call + ForeshoreProfile foreshoreProfile = entity.Read(readConversionCollector); + + // Assert + Assert.IsNotNull(foreshoreProfile); + Assert.AreEqual(name, foreshoreProfile.Name); + Assert.AreEqual(order, entity.Order); + Assert.AreEqual(id, foreshoreProfile.Id); + Assert.AreEqual(name, entity.Name); + Assert.AreEqual(orientation, foreshoreProfile.Orientation, foreshoreProfile.Orientation.GetAccuracy()); + Assert.AreEqual(x0, entity.X0); + Assert.AreEqual(breakWaterType, foreshoreProfile.BreakWater.Type); + Assert.IsTrue(foreshoreProfile.HasBreakWater); + CollectionAssert.AreEqual(points, foreshoreProfile.Geometry); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionInwards/DikeProfileEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionInwards/DikeProfileEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionInwards/DikeProfileEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,248 @@ +// Copyright (C) Stichting Deltares 2018. 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; +using Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.TestUtil; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Read.GrassCoverErosionInwards; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Read.GrassCoverErosionInwards +{ + [TestFixture] + public class DikeProfileEntityReadExtensionsTest + { + private const string validRoughnessPointXml = "" + + ""; + + [Test] + public void Read_ReadConversionCollectorNull_ThrowArgumentNullException() + { + // Setup + var entity = new DikeProfileEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void Read_EntityNotReadBefore_EntityRegistered() + { + // Setup + var collector = new ReadConversionCollector(); + + var entity = new DikeProfileEntity + { + Id = "id", + ForeshoreXml = new Point2DCollectionXmlSerializer().ToXml(new Point2D[0]), + DikeGeometryXml = new RoughnessPointCollectionXmlSerializer().ToXml(new RoughnessPoint[0]) + }; + + // Precondition + Assert.IsFalse(collector.Contains(entity)); + + // Call + entity.Read(collector); + + // Assert + Assert.IsTrue(collector.Contains(entity)); + } + + [Test] + [TestCase("")] + [TestCase(null)] + public void Read_DikeGeometryXmlNullOrEmpty_ThrowsArgumentException(string xml) + { + // Setup + var profile = new DikeProfileEntity + { + DikeGeometryXml = xml, + ForeshoreXml = validRoughnessPointXml + }; + + // Call + TestDelegate test = () => profile.Read(new ReadConversionCollector()); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("xml", paramName); + } + + [Test] + [TestCase("")] + [TestCase(null)] + public void Read_ForeshoreXmlNullOrEmpty_ThrowsArgumentException(string xml) + { + // Setup + var profile = new DikeProfileEntity + { + DikeGeometryXml = validRoughnessPointXml, + ForeshoreXml = xml + }; + + // Call + TestDelegate test = () => profile.Read(new ReadConversionCollector()); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("xml", paramName); + } + + [Test] + public void Read_DikeProfileEntityWithBreakWaterPropertiesNull_ReturnDikeProfileWithoutBreakWater() + { + // Setup + var foreshorePoints = new[] + { + new Point2D(-9.9, 8.8), + new Point2D(-7.7, 5.5) + }; + var roughnessPoints = new[] + { + new RoughnessPoint(new Point2D(-7.7, 5.5), 1.0), + new RoughnessPoint(new Point2D(5.5, 6.6), 0.5) + }; + var entity = new DikeProfileEntity + { + Id = "saved", + Name = "Just saved", + Orientation = 45.67, + BreakWaterHeight = null, + BreakWaterType = null, + ForeshoreXml = new Point2DCollectionXmlSerializer().ToXml(foreshorePoints), + DikeGeometryXml = new RoughnessPointCollectionXmlSerializer().ToXml(roughnessPoints), + DikeHeight = 1.2, + X = 3.4, + Y = 5.6, + X0 = -7.8 + }; + + var collector = new ReadConversionCollector(); + + // Call + DikeProfile dikeProfile = entity.Read(collector); + + // Assert + Assert.AreEqual(entity.Id, dikeProfile.Id); + Assert.AreEqual(entity.Name, dikeProfile.Name); + Assert.AreEqual(entity.Orientation, dikeProfile.Orientation.Value); + CollectionAssert.AreEqual(foreshorePoints, dikeProfile.ForeshoreGeometry); + CollectionAssert.AreEqual(roughnessPoints, dikeProfile.DikeGeometry, new RoughnessPointComparer()); + Assert.AreEqual(entity.X, dikeProfile.WorldReferencePoint.X); + Assert.AreEqual(entity.Y, dikeProfile.WorldReferencePoint.Y); + Assert.AreEqual(entity.X0, dikeProfile.X0); + + Assert.IsFalse(dikeProfile.HasBreakWater); + } + + [Test] + [TestCase(BreakWaterType.Caisson, 1.1)] + [TestCase(BreakWaterType.Dam, -22.2)] + [TestCase(BreakWaterType.Wall, 45.67)] + public void Read_DikeProfileEntityWithBreakWater_ReturnDikeProfileWithBreakWater(BreakWaterType type, double height) + { + // Setup + var foreshorePoints = new Point2D[0]; + var roughnessPoints = new[] + { + new RoughnessPoint(new Point2D(1.1, 2.2), 1.0), + new RoughnessPoint(new Point2D(3.3, 4.4), 0.6), + new RoughnessPoint(new Point2D(5.5, 6.6), 1.0), + new RoughnessPoint(new Point2D(7.7, 8.8), 0.5) + }; + var entity = new DikeProfileEntity + { + Id = "with_breakwater", + Name = "I have a Breakwater!", + Orientation = 360.0, + BreakWaterHeight = height, + BreakWaterType = Convert.ToByte(type), + ForeshoreXml = new Point2DCollectionXmlSerializer().ToXml(foreshorePoints), + DikeGeometryXml = new RoughnessPointCollectionXmlSerializer().ToXml(roughnessPoints), + DikeHeight = 4.5, + X = 93.0, + Y = 945.6, + X0 = 9.34 + }; + + var collector = new ReadConversionCollector(); + + // Call + DikeProfile dikeProfile = entity.Read(collector); + + // Assert + Assert.AreEqual(entity.Id, dikeProfile.Id); + Assert.AreEqual(entity.Name, dikeProfile.Name); + Assert.AreEqual(entity.Orientation, dikeProfile.Orientation.Value); + CollectionAssert.AreEqual(foreshorePoints, dikeProfile.ForeshoreGeometry); + CollectionAssert.AreEqual(roughnessPoints, dikeProfile.DikeGeometry, new RoughnessPointComparer()); + Assert.AreEqual(entity.X, dikeProfile.WorldReferencePoint.X); + Assert.AreEqual(entity.Y, dikeProfile.WorldReferencePoint.Y); + Assert.AreEqual(entity.X0, dikeProfile.X0); + + Assert.AreEqual(height, dikeProfile.BreakWater.Height.Value); + Assert.AreEqual(type, dikeProfile.BreakWater.Type); + + Assert.IsTrue(collector.Contains(entity)); + } + + [Test] + public void Read_AlreadyReadDikeProfileEntity_ReturnDikeProfile() + { + // Setup + var registeredEntity = new DikeProfileEntity(); + DikeProfile registeredProfile = DikeProfileTestFactory.CreateDikeProfile(); + var collector = new ReadConversionCollector(); + collector.Read(registeredEntity, registeredProfile); + + // Call + DikeProfile returnedProfile = registeredEntity.Read(collector); + + // Assert + Assert.AreSame(registeredProfile, returnedProfile); + } + + private class RoughnessPointComparer : IComparer + { + public int Compare(object x, object y) + { + var p1 = (RoughnessPoint) x; + var p2 = (RoughnessPoint) y; + if (p1.Point.Equals(p2.Point) && p1.Roughness.Equals(p2.Roughness)) + { + return 0; + } + + return 1; + } + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionInwards/GrassCoverErosionInwardsCalculationEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionInwards/GrassCoverErosionInwardsCalculationEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionInwards/GrassCoverErosionInwardsCalculationEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,308 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.Storage.Core.TestUtil.Hydraulics; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Read.GrassCoverErosionInwards; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Read.GrassCoverErosionInwards +{ + [TestFixture] + public class GrassCoverErosionInwardsCalculationEntityReadExtensionsTest + { + [Test] + public void Read_ReadConversionCollectorNull_ThrowArgumentNullException() + { + // Setup + var entity = new GrassCoverErosionInwardsCalculationEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void Read_ValidEntity_ReturnCalculation() + { + // Setup + var random = new Random(14); + var breakWaterType = random.NextEnumValue(); + var dikeHeightCalculationType = random.NextEnumValue(); + var overtoppingRateCalculationType = random.NextEnumValue(); + var entity = new GrassCoverErosionInwardsCalculationEntity + { + Name = "sodhfksn", + Comments = "s;ohfgwjo5p09u", + HydraulicLocationEntity = null, + DikeProfileEntity = null, + Orientation = 5.6, + CriticalFlowRateMean = 3.4, + CriticalFlowRateStandardDeviation = 1.2, + UseForeshore = Convert.ToByte(random.NextBoolean()), + DikeHeight = 2.3, + UseBreakWater = Convert.ToByte(random.NextBoolean()), + BreakWaterType = Convert.ToByte(breakWaterType), + BreakWaterHeight = 5.7, + DikeHeightCalculationType = Convert.ToByte(dikeHeightCalculationType), + OvertoppingRateCalculationType = Convert.ToByte(overtoppingRateCalculationType), + ShouldOvertoppingOutputIllustrationPointsBeCalculated = Convert.ToByte(random.NextBoolean()), + ShouldDikeHeightIllustrationPointsBeCalculated = Convert.ToByte(random.NextBoolean()), + ShouldOvertoppingRateIllustrationPointsBeCalculated = Convert.ToByte(random.NextBoolean()) + }; + + var collector = new ReadConversionCollector(); + + // Call + GrassCoverErosionInwardsCalculation calculation = entity.Read(collector); + + // Assert + Assert.AreEqual(entity.Name, calculation.Name); + Assert.AreEqual(entity.Comments, calculation.Comments.Body); + + GrassCoverErosionInwardsInput input = calculation.InputParameters; + Assert.AreEqual(entity.Orientation, input.Orientation.Value); + Assert.AreEqual(entity.CriticalFlowRateMean, input.CriticalFlowRate.Mean.Value); + Assert.AreEqual(entity.CriticalFlowRateStandardDeviation, input.CriticalFlowRate.StandardDeviation.Value); + AssertBoolean(entity.UseForeshore, input.UseForeshore); + Assert.AreEqual(entity.DikeHeight, input.DikeHeight.Value); + AssertBoolean(entity.UseBreakWater, input.UseBreakWater); + Assert.AreEqual(breakWaterType, input.BreakWater.Type); + Assert.AreEqual(entity.BreakWaterHeight, input.BreakWater.Height.Value); + Assert.AreEqual(dikeHeightCalculationType, input.DikeHeightCalculationType); + Assert.AreEqual(overtoppingRateCalculationType, input.OvertoppingRateCalculationType); + AssertBoolean(entity.ShouldOvertoppingOutputIllustrationPointsBeCalculated, + input.ShouldOvertoppingOutputIllustrationPointsBeCalculated); + AssertBoolean(entity.ShouldDikeHeightIllustrationPointsBeCalculated, + input.ShouldDikeHeightIllustrationPointsBeCalculated); + AssertBoolean(entity.ShouldOvertoppingRateIllustrationPointsBeCalculated, + input.ShouldOvertoppingRateIllustrationPointsBeCalculated); + + Assert.IsNull(input.DikeProfile); + Assert.IsNull(input.HydraulicBoundaryLocation); + Assert.IsFalse(calculation.HasOutput); + } + + [Test] + public void Read_EntityNotReadBefore_RegisterEntity() + { + // Setup + var entity = new GrassCoverErosionInwardsCalculationEntity(); + + var collector = new ReadConversionCollector(); + + // Precondition + Assert.IsFalse(collector.Contains(entity)); + + // Call + GrassCoverErosionInwardsCalculation calculation = entity.Read(collector); + + // Assert + Assert.IsTrue(collector.Contains(entity)); + Assert.AreSame(calculation, collector.Get(entity)); + } + + [Test] + public void Read_EntityWithNullValues_ReturnCalculationWithNaNOrNull() + { + // Setup + var entity = new GrassCoverErosionInwardsCalculationEntity + { + Name = null, + Comments = null, + Orientation = null, + CriticalFlowRateMean = null, + CriticalFlowRateStandardDeviation = null, + DikeHeight = null, + BreakWaterHeight = null + }; + + var collector = new ReadConversionCollector(); + + // Call + GrassCoverErosionInwardsCalculation calculation = entity.Read(collector); + + // Assert + Assert.IsNull(calculation.Name); + Assert.IsNull(calculation.Comments.Body); + + GrassCoverErosionInwardsInput input = calculation.InputParameters; + Assert.IsNaN(input.Orientation); + Assert.IsNaN(input.CriticalFlowRate.Mean); + Assert.IsNaN(input.CriticalFlowRate.StandardDeviation); + Assert.IsNaN(input.DikeHeight); + Assert.IsNaN(input.BreakWater.Height.Value); + + Assert.IsNull(input.DikeProfile); + Assert.IsNull(input.HydraulicBoundaryLocation); + Assert.IsFalse(calculation.HasOutput); + } + + [Test] + public void Read_ValidEntityWithAlreadyReadDikeProfileEntity_ReturnCalculationWithReadDikeProfile() + { + // Setup + DikeProfile dikeProfile = DikeProfileTestFactory.CreateDikeProfile(); + var dikeProfileEntity = new DikeProfileEntity(); + var entity = new GrassCoverErosionInwardsCalculationEntity + { + DikeProfileEntity = dikeProfileEntity + }; + + var collector = new ReadConversionCollector(); + collector.Read(dikeProfileEntity, dikeProfile); + + // Call + GrassCoverErosionInwardsCalculation calculation = entity.Read(collector); + + // Assert + Assert.AreSame(dikeProfile, calculation.InputParameters.DikeProfile); + } + + [Test] + public void Read_ValidEntityWithUnreadDikeProfileEntity_ReturnCalculationWithNewDikeProfile() + { + // Setup + var dikeProfileEntity = new DikeProfileEntity + { + Id = "a", + DikeGeometryXml = new RoughnessPointCollectionXmlSerializer().ToXml(new RoughnessPoint[0]), + ForeshoreXml = new Point2DCollectionXmlSerializer().ToXml(new Point2D[0]) + }; + var entity = new GrassCoverErosionInwardsCalculationEntity + { + DikeProfileEntity = dikeProfileEntity + }; + + var collector = new ReadConversionCollector(); + + // Call + GrassCoverErosionInwardsCalculation calculation = entity.Read(collector); + + // Assert + Assert.IsNotNull(calculation.InputParameters.DikeProfile); + Assert.IsTrue(collector.Contains(dikeProfileEntity)); + } + + [Test] + public void Read_ValidEntityWithAlreadyReadHydraulicLocationEntity_ReturnCalculationWithReadHydraulicBoundaryLocation() + { + // Setup + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "A", 0, 0); + var hydraulicLocationEntity = new HydraulicLocationEntity(); + var entity = new GrassCoverErosionInwardsCalculationEntity + { + HydraulicLocationEntity = hydraulicLocationEntity + }; + + var collector = new ReadConversionCollector(); + collector.Read(hydraulicLocationEntity, hydraulicBoundaryLocation); + + // Call + GrassCoverErosionInwardsCalculation calculation = entity.Read(collector); + + // Assert + Assert.AreSame(hydraulicBoundaryLocation, calculation.InputParameters.HydraulicBoundaryLocation); + } + + [Test] + public void Read_ValidEntityWithUnreadHydraulicLocationEntity_ReturnCalculationWithNewHydraulicBoundaryLocation() + { + // Setup + HydraulicLocationEntity hydraulicLocationEntity = HydraulicLocationEntityTestFactory.CreateHydraulicLocationEntity(); + var entity = new GrassCoverErosionInwardsCalculationEntity + { + HydraulicLocationEntity = hydraulicLocationEntity + }; + + var collector = new ReadConversionCollector(); + + // Call + GrassCoverErosionInwardsCalculation calculation = entity.Read(collector); + + // Assert + Assert.IsNotNull(calculation.InputParameters.HydraulicBoundaryLocation); + Assert.IsTrue(collector.Contains(hydraulicLocationEntity)); + } + + [Test] + public void Read_ValidEntityWithOutputEntity_ReturnCalculationWithOutput() + { + // Setup + var entity = new GrassCoverErosionInwardsCalculationEntity + { + GrassCoverErosionInwardsOutputEntities = + { + new GrassCoverErosionInwardsOutputEntity() + } + }; + + var collector = new ReadConversionCollector(); + + // Call + GrassCoverErosionInwardsCalculation calculation = entity.Read(collector); + + // Assert + Assert.IsTrue(calculation.HasOutput); + } + + [Test] + public void Read_CalculationEntityAlreadyRead_ReturnReadCalculation() + { + // Setup + var entity = new GrassCoverErosionInwardsCalculationEntity + { + GrassCoverErosionInwardsOutputEntities = + { + new GrassCoverErosionInwardsOutputEntity() + } + }; + + var calculation = new GrassCoverErosionInwardsCalculation(); + + var collector = new ReadConversionCollector(); + collector.Read(entity, calculation); + + // Call + GrassCoverErosionInwardsCalculation returnedCalculation = entity.Read(collector); + + // Assert + Assert.AreSame(calculation, returnedCalculation); + } + + private static void AssertBoolean(byte expectedByte, bool actual) + { + Assert.AreEqual(Convert.ToBoolean(expectedByte), actual); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionInwards/GrassCoverErosionInwardsDikeHeightOutputEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionInwards/GrassCoverErosionInwardsDikeHeightOutputEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionInwards/GrassCoverErosionInwardsDikeHeightOutputEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,133 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.Storage.Core.TestUtil.IllustrationPoints; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.GrassCoverErosionInwards; + +namespace Riskeer.Storage.Core.Test.Read.GrassCoverErosionInwards +{ + [TestFixture] + public class GrassCoverErosionInwardsDikeHeightOutputEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowArgumentNullException() + { + // Call + TestDelegate test = () => ((GrassCoverErosionInwardsDikeHeightOutputEntity) null).Read(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_ValidParameters_ReturnsDikeHeightOutput() + { + // Setup + var random = new Random(22); + double dikeHeight = random.NextDouble(); + double targetProbability = random.NextDouble(); + double targetReliability = random.NextDouble(); + double calculatedProbability = random.NextDouble(); + double calculatedReliability = random.NextDouble(); + var convergence = random.NextEnumValue(); + var entity = new GrassCoverErosionInwardsDikeHeightOutputEntity + { + DikeHeight = dikeHeight, + TargetProbability = targetProbability, + TargetReliability = targetReliability, + CalculatedProbability = calculatedProbability, + CalculatedReliability = calculatedReliability, + CalculationConvergence = Convert.ToByte(convergence) + }; + + // Call + DikeHeightOutput output = entity.Read(); + + // Assert + Assert.AreEqual(dikeHeight, output.DikeHeight, output.DikeHeight.GetAccuracy()); + Assert.AreEqual(targetProbability, output.TargetProbability); + Assert.AreEqual(targetReliability, output.TargetReliability, output.TargetReliability.GetAccuracy()); + Assert.AreEqual(calculatedProbability, output.CalculatedProbability); + Assert.AreEqual(calculatedReliability, output.CalculatedReliability, output.CalculatedReliability.GetAccuracy()); + Assert.AreEqual(convergence, output.CalculationConvergence); + Assert.IsNull(output.GeneralResult); + } + + [Test] + public void Read_NullParameters_ReturnsDikeHeightOutputWithNaN() + { + // Setup + var random = new Random(22); + var convergence = random.NextEnumValue(); + var entity = new GrassCoverErosionInwardsDikeHeightOutputEntity + { + CalculationConvergence = Convert.ToByte(convergence) + }; + + // Call + DikeHeightOutput output = entity.Read(); + + // Assert + Assert.IsNaN(output.DikeHeight); + 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_WithGeneralResultEntity_ReturnsDikeHeightOutputWithGeneralResult() + { + // Setup + var random = new Random(22); + + var generalResultEntity = new GeneralResultFaultTreeIllustrationPointEntity + { + GoverningWindDirectionName = "SSE", + GoverningWindDirectionAngle = random.NextDouble() + }; + + var convergence = random.NextEnumValue(); + var entity = new GrassCoverErosionInwardsDikeHeightOutputEntity + { + CalculationConvergence = Convert.ToByte(convergence), + GeneralResultFaultTreeIllustrationPointEntity = generalResultEntity + }; + + // Call + DikeHeightOutput output = entity.Read(); + + // Assert + GeneralResultEntityTestHelper.AssertGeneralResultPropertyValues(output.GeneralResult, + generalResultEntity); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionInwards/GrassCoverErosionInwardsFailureMechanismMetaEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionInwards/GrassCoverErosionInwardsFailureMechanismMetaEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionInwards/GrassCoverErosionInwardsFailureMechanismMetaEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,80 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.GrassCoverErosionInwards.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.GrassCoverErosionInwards; + +namespace Riskeer.Storage.Core.Test.Read.GrassCoverErosionInwards +{ + [TestFixture] + public class GrassCoverErosionInwardsFailureMechanismMetaEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Setup + var generalInput = new GeneralGrassCoverErosionInwardsInput(); + + // Call + TestDelegate test = () => ((GrassCoverErosionInwardsFailureMechanismMetaEntity) null).Read(generalInput); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_GeneralInputNull_ThrowArgumentNullException() + { + // Setup + var entity = new GrassCoverErosionInwardsFailureMechanismMetaEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("input", paramName); + } + + [Test] + public void Read_ValidEntity_ReturnGeneralGrassCoverErosionInwardsInput() + { + // Setup + var inputToUpdate = new GeneralGrassCoverErosionInwardsInput(); + var entity = new GrassCoverErosionInwardsFailureMechanismMetaEntity + { + N = new Random(21).NextRoundedDouble(1.0, 20.0) + }; + + // Call + entity.Read(inputToUpdate); + + // Assert + Assert.AreEqual(entity.N, inputToUpdate.N, inputToUpdate.N.GetAccuracy()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionInwards/GrassCoverErosionInwardsOutputEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionInwards/GrassCoverErosionInwardsOutputEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionInwards/GrassCoverErosionInwardsOutputEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,159 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.Storage.Core.TestUtil.IllustrationPoints; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.GrassCoverErosionInwards; + +namespace Riskeer.Storage.Core.Test.Read.GrassCoverErosionInwards +{ + [TestFixture] + public class GrassCoverErosionInwardsOutputEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((GrassCoverErosionInwardsOutputEntity) null).Read(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_ValidEntity_ReturnGrassCoverErosionInwardsOutput() + { + // Setup + var entity = new GrassCoverErosionInwardsOutputEntity + { + WaveHeight = 1.1, + IsOvertoppingDominant = Convert.ToByte(false), + Reliability = 0.2 + }; + + // Call + GrassCoverErosionInwardsOutput output = entity.Read(); + + // Assert + OvertoppingOutput overtoppingOutput = output.OvertoppingOutput; + + Assert.AreEqual(entity.WaveHeight, overtoppingOutput.WaveHeight.Value); + Assert.IsFalse(overtoppingOutput.IsOvertoppingDominant); + Assert.IsNull(output.DikeHeightOutput); + Assert.IsNull(output.OvertoppingRateOutput); + Assert.AreEqual(entity.Reliability, overtoppingOutput.Reliability); + } + + [Test] + public void Read_ValidEntityWithNullValues_ReturnGrassCoverErosionInwardsOutput() + { + // Setup + var entity = new GrassCoverErosionInwardsOutputEntity + { + WaveHeight = null, + IsOvertoppingDominant = Convert.ToByte(true), + Reliability = null, + GeneralResultFaultTreeIllustrationPointEntity = null + }; + + // Call + GrassCoverErosionInwardsOutput output = entity.Read(); + + // Assert + OvertoppingOutput overtoppingOutput = output.OvertoppingOutput; + + Assert.IsNaN(overtoppingOutput.WaveHeight); + Assert.IsTrue(overtoppingOutput.IsOvertoppingDominant); + Assert.IsNull(output.DikeHeightOutput); + Assert.IsNull(output.OvertoppingRateOutput); + Assert.IsNaN(overtoppingOutput.Reliability); + Assert.IsNull(overtoppingOutput.GeneralResult); + } + + [Test] + public void Read_ValidEntityWithGeneralResultEntity_ReturnsGrassCoverErosionInwardsOutputWithGeneralResult() + { + // Setup + var generalResultEntity = new GeneralResultFaultTreeIllustrationPointEntity + { + GoverningWindDirectionAngle = 10, + GoverningWindDirectionName = "SSE" + }; + var entity = new GrassCoverErosionInwardsOutputEntity + { + WaveHeight = null, + IsOvertoppingDominant = Convert.ToByte(true), + Reliability = null, + GeneralResultFaultTreeIllustrationPointEntity = generalResultEntity + }; + + // Call + GrassCoverErosionInwardsOutput output = entity.Read(); + + // Assert + OvertoppingOutput overtoppingOutput = output.OvertoppingOutput; + GeneralResultEntityTestHelper.AssertGeneralResultPropertyValues(overtoppingOutput.GeneralResult, + generalResultEntity); + } + + [Test] + public void Read_ValidEntityWithDikeHeightOutputEntity_ReturnGrassCoverErosionInwardsOutputWithDikeHeightOutput() + { + // Setup + var entity = new GrassCoverErosionInwardsOutputEntity + { + GrassCoverErosionInwardsDikeHeightOutputEntities = + { + new GrassCoverErosionInwardsDikeHeightOutputEntity() + } + }; + + // Call + GrassCoverErosionInwardsOutput output = entity.Read(); + + // Assert + Assert.IsNotNull(output.DikeHeightOutput); + } + + [Test] + public void Read_ValidEntityWithOvertoppingRateOutputEntity_ReturnGrassCoverErosionInwardsOutputWithOvertoppingRateOutput() + { + // Setup + var entity = new GrassCoverErosionInwardsOutputEntity + { + GrassCoverErosionInwardsOvertoppingRateOutputEntities = + { + new GrassCoverErosionInwardsOvertoppingRateOutputEntity() + } + }; + + // Call + GrassCoverErosionInwardsOutput output = entity.Read(); + + // Assert + Assert.IsNotNull(output.OvertoppingRateOutput); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionInwards/GrassCoverErosionInwardsOvertoppingRateOutputEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionInwards/GrassCoverErosionInwardsOvertoppingRateOutputEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionInwards/GrassCoverErosionInwardsOvertoppingRateOutputEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,134 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.Storage.Core.TestUtil.IllustrationPoints; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.GrassCoverErosionInwards; + +namespace Riskeer.Storage.Core.Test.Read.GrassCoverErosionInwards +{ + [TestFixture] + public class GrassCoverErosionInwardsOvertoppingRateOutputEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowArgumentNullException() + { + // Call + TestDelegate test = () => ((GrassCoverErosionInwardsOvertoppingRateOutputEntity) null).Read(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_ValidParameters_ReturnsOvertoppingRateOutput() + { + // Setup + var random = new Random(22); + double overtoppingRate = random.NextDouble(); + double targetProbability = random.NextDouble(); + double targetReliability = random.NextDouble(); + double calculatedProbability = random.NextDouble(); + double calculatedReliability = random.NextDouble(); + var convergence = random.NextEnumValue(); + var entity = new GrassCoverErosionInwardsOvertoppingRateOutputEntity + { + OvertoppingRate = overtoppingRate, + TargetProbability = targetProbability, + TargetReliability = targetReliability, + CalculatedProbability = calculatedProbability, + CalculatedReliability = calculatedReliability, + CalculationConvergence = Convert.ToByte(convergence) + }; + + // Call + OvertoppingRateOutput output = entity.Read(); + + // Assert + Assert.AreEqual(overtoppingRate, output.OvertoppingRate, output.OvertoppingRate.GetAccuracy()); + Assert.AreEqual(targetProbability, output.TargetProbability); + Assert.AreEqual(targetReliability, output.TargetReliability, output.TargetReliability.GetAccuracy()); + Assert.AreEqual(calculatedProbability, output.CalculatedProbability); + Assert.AreEqual(calculatedReliability, output.CalculatedReliability, output.CalculatedReliability.GetAccuracy()); + Assert.AreEqual(convergence, output.CalculationConvergence); + + Assert.IsNull(output.GeneralResult); + } + + [Test] + public void Read_NullParameters_ReturnsOvertoppingRateOutputWithNaN() + { + // Setup + var random = new Random(22); + var convergence = random.NextEnumValue(); + var entity = new GrassCoverErosionInwardsOvertoppingRateOutputEntity + { + CalculationConvergence = Convert.ToByte(convergence) + }; + + // Call + OvertoppingRateOutput output = entity.Read(); + + // Assert + Assert.IsNaN(output.OvertoppingRate); + 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_ValidEntityWithGeneralResultEntity_ReturnsOvertoppingRateOutputWithGeneralResult() + { + // Setup + var random = new Random(22); + var generalResultEntity = new GeneralResultFaultTreeIllustrationPointEntity + { + GoverningWindDirectionName = "SSE", + GoverningWindDirectionAngle = random.NextDouble() + }; + + var convergence = random.NextEnumValue(); + var entity = new GrassCoverErosionInwardsOvertoppingRateOutputEntity + { + CalculationConvergence = Convert.ToByte(convergence), + GeneralResultFaultTreeIllustrationPointEntity = generalResultEntity + }; + + // Call + OvertoppingRateOutput output = entity.Read(); + + // Assert + GeneralResultEntityTestHelper.AssertGeneralResultPropertyValues(output.GeneralResult, + generalResultEntity); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionInwards/GrassCoverErosionInwardsSectionResultEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionInwards/GrassCoverErosionInwardsSectionResultEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionInwards/GrassCoverErosionInwardsSectionResultEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,170 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.GrassCoverErosionInwards.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Read.GrassCoverErosionInwards; + +namespace Riskeer.Storage.Core.Test.Read.GrassCoverErosionInwards +{ + [TestFixture] + public class GrassCoverErosionInwardsSectionResultEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((GrassCoverErosionInwardsSectionResultEntity) null).Read( + new GrassCoverErosionInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), + new ReadConversionCollector()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_SectionResultNull_ThrowsArgumentNullException() + { + // Setup + var entity = new GrassCoverErosionInwardsSectionResultEntity(); + + // Call + TestDelegate call = () => entity.Read(null, new ReadConversionCollector()); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("sectionResult", paramName); + } + + [Test] + public void Read_CollectorNull_ThrowsArgumentNullException() + { + // Setup + var entity = new GrassCoverErosionInwardsSectionResultEntity(); + + // Call + TestDelegate call = () => entity.Read(new GrassCoverErosionInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void Read_ParameterValues_SectionResultWithParameterValues() + { + // Setup + var random = new Random(21); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResult = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + double tailorMadeAssessmentProbability = random.NextDouble(); + bool useManualAssembly = random.NextBoolean(); + double manualAssemblyProbability = random.NextDouble(); + + var collector = new ReadConversionCollector(); + + var failureMechanismSectionEntity = new FailureMechanismSectionEntity(); + collector.Read(failureMechanismSectionEntity, FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + var entity = new GrassCoverErosionInwardsSectionResultEntity + { + FailureMechanismSectionEntity = failureMechanismSectionEntity, + SimpleAssessmentResult = Convert.ToByte(simpleAssessmentResult), + DetailedAssessmentResult = Convert.ToByte(detailedAssessmentResult), + TailorMadeAssessmentResult = Convert.ToByte(tailorMadeAssessmentResult), + TailorMadeAssessmentProbability = tailorMadeAssessmentProbability, + UseManualAssembly = Convert.ToByte(useManualAssembly), + ManualAssemblyProbability = manualAssemblyProbability + }; + var sectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult, collector); + + // Assert + Assert.AreEqual(simpleAssessmentResult, sectionResult.SimpleAssessmentResult); + Assert.AreEqual(detailedAssessmentResult, sectionResult.DetailedAssessmentResult); + Assert.AreEqual(tailorMadeAssessmentResult, sectionResult.TailorMadeAssessmentResult); + Assert.AreEqual(tailorMadeAssessmentProbability, sectionResult.TailorMadeAssessmentProbability, 1e-6); + Assert.AreEqual(useManualAssembly, sectionResult.UseManualAssembly); + Assert.AreEqual(manualAssemblyProbability, sectionResult.ManualAssemblyProbability, 1e-6); + Assert.IsNull(sectionResult.Calculation); + } + + [Test] + public void Read_EntityWithNullValues_SectionResultWithNaNValues() + { + // Setup + var collector = new ReadConversionCollector(); + + var failureMechanismSectionEntity = new FailureMechanismSectionEntity(); + collector.Read(failureMechanismSectionEntity, FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + var entity = new GrassCoverErosionInwardsSectionResultEntity + { + FailureMechanismSectionEntity = failureMechanismSectionEntity + }; + var sectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult, collector); + + // Assert + Assert.IsNaN(sectionResult.TailorMadeAssessmentProbability); + Assert.IsNaN(sectionResult.ManualAssemblyProbability); + Assert.IsNull(sectionResult.Calculation); + } + + [Test] + public void Read_CalculationEntitySet_ReturnGrassCoverErosionInwardsSectionResultWithCalculation() + { + // Setup + var calculation = new GrassCoverErosionInwardsCalculation(); + + var failureMechanismSectionEntity = new FailureMechanismSectionEntity(); + var calculationEntity = new GrassCoverErosionInwardsCalculationEntity(); + + var collector = new ReadConversionCollector(); + collector.Read(failureMechanismSectionEntity, FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + collector.Read(calculationEntity, calculation); + + var entity = new GrassCoverErosionInwardsSectionResultEntity + { + FailureMechanismSectionEntity = failureMechanismSectionEntity, + GrassCoverErosionInwardsCalculationEntity = calculationEntity + }; + var sectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult, collector); + + // Assert + Assert.AreSame(calculation, sectionResult.Calculation); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionOutwards/GrassCoverErosionOutwardsFailureMechanismMetaEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionOutwards/GrassCoverErosionOutwardsFailureMechanismMetaEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionOutwards/GrassCoverErosionOutwardsFailureMechanismMetaEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,80 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.GrassCoverErosionOutwards.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.GrassCoverErosionOutwards; + +namespace Riskeer.Storage.Core.Test.Read.GrassCoverErosionOutwards +{ + [TestFixture] + public class GrassCoverErosionOutwardsFailureMechanismMetaEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Setup + var input = new GeneralGrassCoverErosionOutwardsInput(); + + // Call + TestDelegate test = () => ((GrassCoverErosionOutwardsFailureMechanismMetaEntity) null).Read(input); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_GeneralInputNull_ThrowArgumentNullException() + { + // Setup + var entity = new GrassCoverErosionOutwardsFailureMechanismMetaEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("input", paramName); + } + + [Test] + public void Read_ValidEntity_ReturnGeneralGrassCoverErosionOutwardsInput() + { + // Setup + var inputToUpdate = new GeneralGrassCoverErosionOutwardsInput(); + var entity = new GrassCoverErosionOutwardsFailureMechanismMetaEntity + { + N = new Random(21).NextRoundedDouble(1.0, 20.0) + }; + + // Call + entity.Read(inputToUpdate); + + // Assert + Assert.AreEqual(entity.N, inputToUpdate.N, inputToUpdate.N.GetAccuracy()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionOutwards/GrassCoverErosionOutwardsSectionResultEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionOutwards/GrassCoverErosionOutwardsSectionResultEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionOutwards/GrassCoverErosionOutwardsSectionResultEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,108 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.AssemblyTool.Data; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.GrassCoverErosionOutwards.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.GrassCoverErosionOutwards; + +namespace Riskeer.Storage.Core.Test.Read.GrassCoverErosionOutwards +{ + [TestFixture] + public class GrassCoverErosionOutwardsSectionResultEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((GrassCoverErosionOutwardsSectionResultEntity) null).Read( + new GrassCoverErosionOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection())); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_SectionResultNull_ThrowsArgumentNullException() + { + // Setup + var entity = new GrassCoverErosionOutwardsSectionResultEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("sectionResult", paramName); + } + + [Test] + public void Read_ParameterValues_SectionResultWithParameterValues() + { + // Setup + var random = new Random(21); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResultForFactorizedSignalingNorm = random.NextEnumValue(); + var detailedAssessmentResultForSignalingNorm = random.NextEnumValue(); + var detailedAssessmentResultForMechanismSpecificLowerLimitNorm = random.NextEnumValue(); + var detailedAssessmentResultForLowerLimitNorm = random.NextEnumValue(); + var detailedAssessmentResultForFactorizedLowerLimitNorm = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + bool useManualAssembly = random.NextBoolean(); + var manualAssemblyCategoryGroup = random.NextEnumValue(); + + var entity = new GrassCoverErosionOutwardsSectionResultEntity + { + FailureMechanismSectionEntity = new FailureMechanismSectionEntity(), + SimpleAssessmentResult = Convert.ToByte(simpleAssessmentResult), + DetailedAssessmentResultForFactorizedSignalingNorm = Convert.ToByte(detailedAssessmentResultForFactorizedSignalingNorm), + DetailedAssessmentResultForSignalingNorm = Convert.ToByte(detailedAssessmentResultForSignalingNorm), + DetailedAssessmentResultForMechanismSpecificLowerLimitNorm = Convert.ToByte(detailedAssessmentResultForMechanismSpecificLowerLimitNorm), + DetailedAssessmentResultForLowerLimitNorm = Convert.ToByte(detailedAssessmentResultForLowerLimitNorm), + DetailedAssessmentResultForFactorizedLowerLimitNorm = Convert.ToByte(detailedAssessmentResultForFactorizedLowerLimitNorm), + TailorMadeAssessmentResult = Convert.ToByte(tailorMadeAssessmentResult), + UseManualAssembly = Convert.ToByte(useManualAssembly), + ManualAssemblyCategoryGroup = Convert.ToByte(manualAssemblyCategoryGroup) + }; + var sectionResult = new GrassCoverErosionOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult); + + // Assert + Assert.AreEqual(simpleAssessmentResult, sectionResult.SimpleAssessmentResult); + Assert.AreEqual(detailedAssessmentResultForFactorizedSignalingNorm, sectionResult.DetailedAssessmentResultForFactorizedSignalingNorm); + Assert.AreEqual(detailedAssessmentResultForSignalingNorm, sectionResult.DetailedAssessmentResultForSignalingNorm); + Assert.AreEqual(detailedAssessmentResultForMechanismSpecificLowerLimitNorm, sectionResult.DetailedAssessmentResultForMechanismSpecificLowerLimitNorm); + Assert.AreEqual(detailedAssessmentResultForLowerLimitNorm, sectionResult.DetailedAssessmentResultForLowerLimitNorm); + Assert.AreEqual(detailedAssessmentResultForFactorizedLowerLimitNorm, sectionResult.DetailedAssessmentResultForFactorizedLowerLimitNorm); + Assert.AreEqual(tailorMadeAssessmentResult, sectionResult.TailorMadeAssessmentResult); + Assert.AreEqual(useManualAssembly, sectionResult.UseManualAssembly); + Assert.AreEqual(manualAssemblyCategoryGroup, sectionResult.ManualAssemblyCategoryGroup); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionOutwards/GrassCoverErosionOutwardsWaveConditionsCalculationEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionOutwards/GrassCoverErosionOutwardsWaveConditionsCalculationEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionOutwards/GrassCoverErosionOutwardsWaveConditionsCalculationEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,275 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.GrassCoverErosionOutwards.Data; +using Ringtoets.Revetment.Data; +using Ringtoets.Storage.Core.TestUtil.Hydraulics; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Read.GrassCoverErosionOutwards; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Read.GrassCoverErosionOutwards +{ + [TestFixture] + public class GrassCoverErosionOutwardsWaveConditionsCalculationEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((GrassCoverErosionOutwardsWaveConditionsCalculationEntity) null).Read(new ReadConversionCollector()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_CollectorIsNull_ThrowArgumentNullException() + { + // Setup + var entity = new GrassCoverErosionOutwardsWaveConditionsCalculationEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void Read_ValidEntity_ReturnCalculation() + { + // Setup + const string name = "Calculation Name"; + const string comments = "Calculation Comment"; + + var random = new Random(21); + double orientation = random.NextDouble(); + bool useBreakWater = random.NextBoolean(); + var breakWaterType = random.NextEnumValue(); + double breakWaterHeight = random.NextDouble(); + bool useForeshore = random.NextBoolean(); + const double lowerBoundaryRevetment = 3.58; + const double upperBoundaryRevetment = 6.10; + const double lowerBoundaryWaterLevels = 3.40; + const double upperBoundaryWaterLevels = 5.88; + var stepSize = random.NextEnumValue(); + var categoryType = random.NextEnumValue(); + + var entity = new GrassCoverErosionOutwardsWaveConditionsCalculationEntity + { + Name = name, + Comments = comments, + UseBreakWater = Convert.ToByte(useBreakWater), + BreakWaterType = Convert.ToByte(breakWaterType), + BreakWaterHeight = breakWaterHeight, + UseForeshore = Convert.ToByte(useForeshore), + Orientation = orientation, + UpperBoundaryRevetment = upperBoundaryRevetment, + LowerBoundaryRevetment = lowerBoundaryRevetment, + UpperBoundaryWaterLevels = upperBoundaryWaterLevels, + LowerBoundaryWaterLevels = lowerBoundaryWaterLevels, + StepSize = Convert.ToByte(stepSize), + CategoryType = Convert.ToByte(categoryType) + }; + + var collector = new ReadConversionCollector(); + + // Call + GrassCoverErosionOutwardsWaveConditionsCalculation calculation = entity.Read(collector); + + // Assert + Assert.AreEqual(name, calculation.Name); + Assert.AreEqual(comments, calculation.Comments.Body); + + FailureMechanismCategoryWaveConditionsInput calculationInput = calculation.InputParameters; + Assert.AreEqual(useBreakWater, calculationInput.UseBreakWater); + Assert.AreEqual(breakWaterType, calculationInput.BreakWater.Type); + AssertRoundedDouble(breakWaterHeight, calculationInput.BreakWater.Height); + Assert.AreEqual(useForeshore, calculationInput.UseForeshore); + AssertRoundedDouble(orientation, calculationInput.Orientation); + AssertRoundedDouble(upperBoundaryRevetment, calculationInput.UpperBoundaryRevetment); + AssertRoundedDouble(lowerBoundaryRevetment, calculationInput.LowerBoundaryRevetment); + AssertRoundedDouble(upperBoundaryWaterLevels, calculationInput.UpperBoundaryWaterLevels); + AssertRoundedDouble(lowerBoundaryWaterLevels, calculationInput.LowerBoundaryWaterLevels); + Assert.AreEqual(stepSize, calculationInput.StepSize); + Assert.AreEqual(categoryType, calculationInput.CategoryType); + + Assert.IsNull(calculationInput.HydraulicBoundaryLocation); + Assert.IsNull(calculationInput.ForeshoreProfile); + Assert.IsNull(calculation.Output); + } + + [Test] + public void Read_EntityWithNullValues_ReturnCalculationWithNaNValues() + { + // Setup + var entity = new GrassCoverErosionOutwardsWaveConditionsCalculationEntity(); + var collector = new ReadConversionCollector(); + + // Call + GrassCoverErosionOutwardsWaveConditionsCalculation calculation = entity.Read(collector); + + // Assert + Assert.IsNull(calculation.Name); + Assert.IsNull(calculation.Comments.Body); + + FailureMechanismCategoryWaveConditionsInput calculationInput = calculation.InputParameters; + Assert.IsNaN(calculationInput.BreakWater.Height); + Assert.IsNaN(calculationInput.Orientation); + Assert.IsNaN(calculationInput.UpperBoundaryRevetment); + Assert.IsNaN(calculationInput.LowerBoundaryRevetment); + Assert.IsNaN(calculationInput.UpperBoundaryWaterLevels); + Assert.IsNaN(calculationInput.LowerBoundaryWaterLevels); + + Assert.IsNull(calculationInput.HydraulicBoundaryLocation); + Assert.IsNull(calculationInput.ForeshoreProfile); + Assert.IsNull(calculation.Output); + } + + [Test] + public void Read_EntityWithForeshoreProfileInCollector_CalculationHasAlreadyReadForeshoreProfile() + { + // Setup + var foreshoreProfile = new TestForeshoreProfile(); + var foreshoreProfileEntity = new ForeshoreProfileEntity + { + GeometryXml = new Point2DCollectionXmlSerializer().ToXml(Enumerable.Empty()) + }; + var entity = new GrassCoverErosionOutwardsWaveConditionsCalculationEntity + { + ForeshoreProfileEntity = foreshoreProfileEntity + }; + + var collector = new ReadConversionCollector(); + collector.Read(foreshoreProfileEntity, foreshoreProfile); + + // Call + GrassCoverErosionOutwardsWaveConditionsCalculation calculation = entity.Read(collector); + + // Assert + Assert.AreSame(foreshoreProfile, calculation.InputParameters.ForeshoreProfile); + } + + [Test] + public void Read_EntityWithForeshoreProfileNotYetInCollector_CalculationWithCreatedForeshoreProfileAndRegisteredNewEntities() + { + // Setup + const string id = "profile"; + var foreshoreProfileEntity = new ForeshoreProfileEntity + { + Id = id, + GeometryXml = new Point2DCollectionXmlSerializer().ToXml(Enumerable.Empty()) + }; + + var entity = new GrassCoverErosionOutwardsWaveConditionsCalculationEntity + { + ForeshoreProfileEntity = foreshoreProfileEntity + }; + + var collector = new ReadConversionCollector(); + + // Call + GrassCoverErosionOutwardsWaveConditionsCalculation calculation = entity.Read(collector); + + // Assert + Assert.IsTrue(collector.Contains(foreshoreProfileEntity)); + CollectionAssert.AreEqual(id, calculation.InputParameters.ForeshoreProfile.Id); + } + + [Test] + public void Read_EntityWithHydraulicBoundaryLocationInCollector_CalculationHasAlreadyReadHydraulicBoundaryLocation() + { + // Setup + var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + HydraulicLocationEntity hydraulicLocationEntity = HydraulicLocationEntityTestFactory.CreateHydraulicLocationEntity(); + var entity = new GrassCoverErosionOutwardsWaveConditionsCalculationEntity + { + HydraulicLocationEntity = hydraulicLocationEntity + }; + + var collector = new ReadConversionCollector(); + collector.Read(hydraulicLocationEntity, hydraulicBoundaryLocation); + + // Call + GrassCoverErosionOutwardsWaveConditionsCalculation calculation = entity.Read(collector); + + // Assert + Assert.AreSame(hydraulicBoundaryLocation, calculation.InputParameters.HydraulicBoundaryLocation); + } + + [Test] + public void Read_EntityWithCalculationOutputEntity_CalculationWithOutput() + { + // Setup + const double outputALevel = 0; + const double outputBLevel = 1; + var entity = new GrassCoverErosionOutwardsWaveConditionsCalculationEntity + { + GrassCoverErosionOutwardsWaveConditionsOutputEntities = + { + new GrassCoverErosionOutwardsWaveConditionsOutputEntity + { + WaterLevel = outputBLevel, + Order = 1, + CalculationConvergence = Convert.ToByte(CalculationConvergence.NotCalculated) + }, + new GrassCoverErosionOutwardsWaveConditionsOutputEntity + { + WaterLevel = outputALevel, + Order = 0, + CalculationConvergence = Convert.ToByte(CalculationConvergence.NotCalculated) + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + GrassCoverErosionOutwardsWaveConditionsCalculation calculation = entity.Read(collector); + + // Assert + Assert.IsNotNull(calculation.Output); + double accuracy = calculation.Output.Items.First().WaterLevel.GetAccuracy(); + Assert.AreEqual(2, calculation.Output.Items.Count()); + Assert.AreEqual(outputALevel, calculation.Output.Items.ElementAt(0).WaterLevel, accuracy); + Assert.AreEqual(outputBLevel, calculation.Output.Items.ElementAt(1).WaterLevel, accuracy); + } + + private static void AssertRoundedDouble(double expectedValue, RoundedDouble actualValue) + { + Assert.AreEqual(expectedValue, actualValue, actualValue.GetAccuracy()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionOutwards/GrassCoverErosionOutwardsWaveConditionsOutputEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionOutwards/GrassCoverErosionOutwardsWaveConditionsOutputEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverErosionOutwards/GrassCoverErosionOutwardsWaveConditionsOutputEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,122 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Revetment.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.GrassCoverErosionOutwards; + +namespace Riskeer.Storage.Core.Test.Read.GrassCoverErosionOutwards +{ + [TestFixture] + public class GrassCoverErosionOutwardsWaveConditionsOutputEntityReadExtensionsTest + { + [Test] + public void Read_ValidEntity_ReturnOutputWithValues() + { + // Setup + var random = new Random(12); + var entity = new GrassCoverErosionOutwardsWaveConditionsOutputEntity + { + WaterLevel = random.NextDouble(), + WaveHeight = random.NextDouble(), + WavePeakPeriod = random.NextDouble(), + WaveAngle = random.NextDouble(), + WaveDirection = random.NextDouble(), + TargetProbability = random.NextDouble(), + TargetReliability = random.NextDouble(), + CalculatedProbability = random.NextDouble(), + CalculatedReliability = random.NextDouble(), + CalculationConvergence = Convert.ToByte(CalculationConvergence.CalculatedConverged) + }; + + // Call + WaveConditionsOutput output = entity.Read(); + + // Assert + Assert.IsNotNull(entity.WaterLevel); + Assert.AreEqual(entity.WaterLevel.Value, output.WaterLevel, output.WaterLevel.GetAccuracy()); + + Assert.IsNotNull(entity.WaveHeight); + Assert.AreEqual(entity.WaveHeight.Value, output.WaveHeight, output.WaveHeight.GetAccuracy()); + + Assert.IsNotNull(entity.WavePeakPeriod); + Assert.AreEqual(entity.WavePeakPeriod.Value, output.WavePeakPeriod, output.WavePeakPeriod.GetAccuracy()); + + Assert.IsNotNull(entity.WaveAngle); + Assert.AreEqual(entity.WaveAngle.Value, output.WaveAngle, output.WaveAngle.GetAccuracy()); + + Assert.IsNotNull(entity.WaveDirection); + Assert.AreEqual(entity.WaveDirection.Value, output.WaveDirection, output.WaveDirection.GetAccuracy()); + + Assert.IsNotNull(entity.TargetProbability); + Assert.AreEqual(entity.TargetProbability.Value, output.TargetProbability); + + Assert.IsNotNull(entity.TargetReliability); + Assert.AreEqual(entity.TargetReliability.Value, output.TargetReliability, output.TargetReliability.GetAccuracy()); + + Assert.IsNotNull(entity.CalculatedProbability); + Assert.AreEqual(entity.CalculatedProbability.Value, output.CalculatedProbability); + + Assert.IsNotNull(entity.CalculatedReliability); + Assert.AreEqual(entity.CalculatedReliability.Value, output.CalculatedReliability, output.CalculatedReliability.GetAccuracy()); + + Assert.IsNotNull(entity.CalculationConvergence); + Assert.AreEqual(CalculationConvergence.CalculatedConverged, output.CalculationConvergence); + } + + [Test] + public void Read_ValidEntityWithNullParameterValues_ReturnOutputWithNaNValues() + { + // Setup + var entity = new GrassCoverErosionOutwardsWaveConditionsOutputEntity + { + CalculationConvergence = Convert.ToByte(CalculationConvergence.NotCalculated), + WaterLevel = null, + WaveHeight = null, + WavePeakPeriod = null, + WaveAngle = null, + WaveDirection = null, + TargetProbability = null, + TargetReliability = null, + CalculatedProbability = null, + CalculatedReliability = null + }; + + // Call + WaveConditionsOutput output = entity.Read(); + + // Assert + Assert.IsNaN(output.WaterLevel); + Assert.IsNaN(output.WaveHeight); + Assert.IsNaN(output.WavePeakPeriod); + Assert.IsNaN(output.WaveAngle); + Assert.IsNaN(output.WaveDirection); + Assert.IsNaN(output.TargetProbability); + Assert.IsNaN(output.TargetReliability); + Assert.IsNaN(output.CalculatedProbability); + Assert.IsNaN(output.CalculatedReliability); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverSlipOffInwardsSectionResultEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverSlipOffInwardsSectionResultEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverSlipOffInwardsSectionResultEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,96 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.Integration.Data.StandAlone.SectionResults; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; + +namespace Riskeer.Storage.Core.Test.Read +{ + [TestFixture] + public class GrassCoverSlipOffInwardsSectionResultEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Setup + var sectionResult = new GrassCoverSlipOffInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + TestDelegate call = () => ((GrassCoverSlipOffInwardsSectionResultEntity) null).Read(sectionResult); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_SectionResultNull_ThrowsArgumentNullException() + { + // Setup + var entity = new GrassCoverSlipOffInwardsSectionResultEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("sectionResult", paramName); + } + + [Test] + public void Read_ParameterValues_SetsSectionResultWithParameterValues() + { + // Setup + var random = new Random(31); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResult = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + bool useManualAssembly = random.NextBoolean(); + var manualAssemblyCategoryGroup = random.NextEnumValue(); + + var entity = new GrassCoverSlipOffInwardsSectionResultEntity + { + SimpleAssessmentResult = Convert.ToByte(simpleAssessmentResult), + DetailedAssessmentResult = Convert.ToByte(detailedAssessmentResult), + TailorMadeAssessmentResult = Convert.ToByte(tailorMadeAssessmentResult), + UseManualAssembly = Convert.ToByte(useManualAssembly), + ManualAssemblyCategoryGroup = Convert.ToByte(manualAssemblyCategoryGroup) + }; + var sectionResult = new GrassCoverSlipOffInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult); + + // Assert + Assert.AreEqual(simpleAssessmentResult, sectionResult.SimpleAssessmentResult); + Assert.AreEqual(detailedAssessmentResult, sectionResult.DetailedAssessmentResult); + Assert.AreEqual(tailorMadeAssessmentResult, sectionResult.TailorMadeAssessmentResult); + Assert.AreEqual(useManualAssembly, sectionResult.UseManualAssembly); + Assert.AreEqual(manualAssemblyCategoryGroup, sectionResult.ManualAssemblyCategoryGroup); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverSlipOffOutwardsSectionResultEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverSlipOffOutwardsSectionResultEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/GrassCoverSlipOffOutwardsSectionResultEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,96 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.Integration.Data.StandAlone.SectionResults; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; + +namespace Riskeer.Storage.Core.Test.Read +{ + [TestFixture] + public class GrassCoverSlipOffOutwardsSectionResultEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Setup + var sectionResult = new GrassCoverSlipOffOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + TestDelegate call = () => ((GrassCoverSlipOffOutwardsSectionResultEntity) null).Read(sectionResult); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_SectionResultNull_ThrowsArgumentNullException() + { + // Setup + var entity = new GrassCoverSlipOffOutwardsSectionResultEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("sectionResult", paramName); + } + + [Test] + public void Read_ParameterValues_SetsSectionResultWithParameterValues() + { + // Setup + var random = new Random(31); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResult = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + bool useManualAssembly = random.NextBoolean(); + var manualAssemblyCategoryGroup = random.NextEnumValue(); + + var entity = new GrassCoverSlipOffOutwardsSectionResultEntity + { + SimpleAssessmentResult = Convert.ToByte(simpleAssessmentResult), + DetailedAssessmentResult = Convert.ToByte(detailedAssessmentResult), + TailorMadeAssessmentResult = Convert.ToByte(tailorMadeAssessmentResult), + UseManualAssembly = Convert.ToByte(useManualAssembly), + ManualAssemblyCategoryGroup = Convert.ToByte(manualAssemblyCategoryGroup) + }; + var sectionResult = new GrassCoverSlipOffOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult); + + // Assert + Assert.AreEqual(simpleAssessmentResult, sectionResult.SimpleAssessmentResult); + Assert.AreEqual(detailedAssessmentResult, sectionResult.DetailedAssessmentResult); + Assert.AreEqual(tailorMadeAssessmentResult, sectionResult.TailorMadeAssessmentResult); + Assert.AreEqual(useManualAssembly, sectionResult.UseManualAssembly); + Assert.AreEqual(manualAssemblyCategoryGroup, sectionResult.ManualAssemblyCategoryGroup); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/HeightStructures/HeightStructureEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/HeightStructures/HeightStructureEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/HeightStructures/HeightStructureEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,192 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.HeightStructures.Data; +using Ringtoets.HeightStructures.Data.TestUtil; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Read.HeightStructures; + +namespace Riskeer.Storage.Core.Test.Read.HeightStructures +{ + [TestFixture] + public class HeightStructureEntityReadExtensionsTest + { + [Test] + public void Read_ReadConversionCollectorNull_ThrowArgumentNullException() + { + // Setup + var entity = new HeightStructureEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void Read_EntityNotReadBefore_RegisterEntity() + { + // Setup + var entity = new HeightStructureEntity + { + Name = "name", + Id = "id" + }; + + var collector = new ReadConversionCollector(); + + // Precondition + Assert.IsFalse(collector.Contains(entity)); + + // Call + HeightStructure calculation = entity.Read(collector); + + // Assert + Assert.IsTrue(collector.Contains(entity)); + Assert.AreSame(calculation, collector.Get(entity)); + } + + [Test] + public void Read_ValidEntity_ReturnHeightStructure() + { + // Setup + var entity = new HeightStructureEntity + { + Name = "A", + Id = "B", + X = 1.1, + Y = 2.2, + StructureNormalOrientation = 3.3, + LevelCrestStructureMean = 4.4, + LevelCrestStructureStandardDeviation = 5.5, + FlowWidthAtBottomProtectionMean = 6.6, + FlowWidthAtBottomProtectionStandardDeviation = 7.7, + CriticalOvertoppingDischargeMean = 8.8, + CriticalOvertoppingDischargeCoefficientOfVariation = 9.9, + WidthFlowAperturesMean = 10.10, + WidthFlowAperturesStandardDeviation = 11.11, + FailureProbabilityStructureWithErosion = 12.12, + StorageStructureAreaMean = 13.13, + StorageStructureAreaCoefficientOfVariation = 14.14, + AllowedLevelIncreaseStorageMean = 15.15, + AllowedLevelIncreaseStorageStandardDeviation = 16.16 + }; + + var collector = new ReadConversionCollector(); + + // Call + HeightStructure structure = entity.Read(collector); + + // Assert + Assert.AreEqual(entity.Name, structure.Name); + Assert.AreEqual(entity.Id, structure.Id); + Assert.AreEqual(entity.X, structure.Location.X); + Assert.AreEqual(entity.Y, structure.Location.Y); + Assert.AreEqual(entity.StructureNormalOrientation, structure.StructureNormalOrientation.Value); + + Assert.AreEqual(entity.LevelCrestStructureMean, structure.LevelCrestStructure.Mean.Value); + Assert.AreEqual(entity.LevelCrestStructureStandardDeviation, structure.LevelCrestStructure.StandardDeviation.Value); + Assert.AreEqual(entity.FlowWidthAtBottomProtectionMean, structure.FlowWidthAtBottomProtection.Mean.Value); + Assert.AreEqual(entity.FlowWidthAtBottomProtectionStandardDeviation, structure.FlowWidthAtBottomProtection.StandardDeviation.Value); + Assert.AreEqual(entity.CriticalOvertoppingDischargeMean, structure.CriticalOvertoppingDischarge.Mean.Value); + Assert.AreEqual(entity.CriticalOvertoppingDischargeCoefficientOfVariation, structure.CriticalOvertoppingDischarge.CoefficientOfVariation.Value); + Assert.AreEqual(entity.WidthFlowAperturesMean, structure.WidthFlowApertures.Mean.Value); + Assert.AreEqual(entity.WidthFlowAperturesStandardDeviation, structure.WidthFlowApertures.StandardDeviation.Value); + Assert.AreEqual(entity.FailureProbabilityStructureWithErosion, structure.FailureProbabilityStructureWithErosion); + Assert.AreEqual(entity.StorageStructureAreaMean, structure.StorageStructureArea.Mean.Value); + Assert.AreEqual(entity.StorageStructureAreaCoefficientOfVariation, structure.StorageStructureArea.CoefficientOfVariation.Value); + Assert.AreEqual(entity.AllowedLevelIncreaseStorageMean, structure.AllowedLevelIncreaseStorage.Mean.Value); + Assert.AreEqual(entity.AllowedLevelIncreaseStorageStandardDeviation, structure.AllowedLevelIncreaseStorage.StandardDeviation.Value); + } + + [Test] + public void Read_NullValues_ReturnHeightStructureWithNaN() + { + // Setup + var entity = new HeightStructureEntity + { + Name = "A", + Id = "B", + X = null, + Y = null, + StructureNormalOrientation = null, + LevelCrestStructureMean = null, + LevelCrestStructureStandardDeviation = null, + FlowWidthAtBottomProtectionMean = null, + FlowWidthAtBottomProtectionStandardDeviation = null, + CriticalOvertoppingDischargeMean = null, + CriticalOvertoppingDischargeCoefficientOfVariation = null, + WidthFlowAperturesMean = null, + WidthFlowAperturesStandardDeviation = null, + FailureProbabilityStructureWithErosion = null, + StorageStructureAreaMean = null, + StorageStructureAreaCoefficientOfVariation = null, + AllowedLevelIncreaseStorageMean = null, + AllowedLevelIncreaseStorageStandardDeviation = null + }; + + var collector = new ReadConversionCollector(); + + // Call + HeightStructure structure = entity.Read(collector); + + // Assert + Assert.IsNaN(structure.Location.X); + Assert.IsNaN(structure.Location.Y); + Assert.IsNaN(structure.StructureNormalOrientation); + + Assert.IsNaN(structure.LevelCrestStructure.Mean.Value); + Assert.IsNaN(structure.LevelCrestStructure.StandardDeviation.Value); + Assert.IsNaN(structure.FlowWidthAtBottomProtection.Mean.Value); + Assert.IsNaN(structure.FlowWidthAtBottomProtection.StandardDeviation.Value); + Assert.IsNaN(structure.CriticalOvertoppingDischarge.Mean.Value); + Assert.IsNaN(structure.CriticalOvertoppingDischarge.CoefficientOfVariation.Value); + Assert.IsNaN(structure.WidthFlowApertures.Mean.Value); + Assert.IsNaN(structure.WidthFlowApertures.StandardDeviation.Value); + Assert.IsNaN(structure.FailureProbabilityStructureWithErosion); + Assert.IsNaN(structure.StorageStructureArea.Mean.Value); + Assert.IsNaN(structure.StorageStructureArea.CoefficientOfVariation.Value); + Assert.IsNaN(structure.AllowedLevelIncreaseStorage.Mean.Value); + Assert.IsNaN(structure.AllowedLevelIncreaseStorage.StandardDeviation.Value); + } + + [Test] + public void Read_EntityRegistered_ReturnRegisteredStructure() + { + // Setup + var entity = new HeightStructureEntity(); + HeightStructure registeredStructure = new TestHeightStructure(); + var collector = new ReadConversionCollector(); + collector.Read(entity, registeredStructure); + + // Call + HeightStructure readStructure = entity.Read(collector); + + // Assert + Assert.AreSame(registeredStructure, readStructure); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/HeightStructures/HeightStructuresCalculationEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/HeightStructures/HeightStructuresCalculationEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/HeightStructures/HeightStructuresCalculationEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,238 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.HeightStructures.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Read.HeightStructures; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.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] + public void Read_EntityNotReadBefore_RegisterEntity() + { + // Setup + var entity = new HeightStructuresCalculationEntity(); + + var collector = new ReadConversionCollector(); + + // Precondition + Assert.IsFalse(collector.Contains(entity)); + + // Call + StructuresCalculation calculation = entity.Read(collector); + + // Assert + Assert.IsTrue(collector.Contains(entity)); + Assert.AreSame(calculation, collector.Get(entity)); + } + + [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 = random.NextDouble(0, 360), + ModelFactorSuperCriticalFlowMean = random.NextDouble(-9999.9999, 9999.9999), + AllowedLevelIncreaseStorageMean = random.NextDouble(1e-6, 9999.9999), + AllowedLevelIncreaseStorageStandardDeviation = random.NextDouble(1e-6, 9999.9999), + FlowWidthAtBottomProtectionMean = random.NextDouble(1e-6, 9999.9999), + FlowWidthAtBottomProtectionStandardDeviation = random.NextDouble(1e-6, 9999.9999), + CriticalOvertoppingDischargeMean = random.NextDouble(1e-6, 9999.9999), + CriticalOvertoppingDischargeCoefficientOfVariation = random.NextDouble(1e-6, 9999.9999), + FailureProbabilityStructureWithErosion = random.NextDouble(), + WidthFlowAperturesMean = random.NextDouble(1e-6, 9999.9999), + WidthFlowAperturesStandardDeviation = random.NextDouble(1e-6, 9999.9999), + StormDurationMean = random.NextDouble(1e-6, 9999.9999), + LevelCrestStructureMean = random.NextDouble(1e-6, 9999.9999), + LevelCrestStructureStandardDeviation = random.NextDouble(1e-6, 9999.9999), + DeviationWaveDirection = random.NextDouble(-360, 360) + }; + + var collector = new ReadConversionCollector(); + + // Call + StructuresCalculation calculation = entity.Read(collector); + + // Assert + Assert.AreEqual(name, calculation.Name); + Assert.AreEqual(comments, calculation.Comments.Body); + + 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.WidthFlowAperturesStandardDeviation, input.WidthFlowApertures.StandardDeviation); + AssertRoundedDouble(entity.StormDurationMean, input.StormDuration.Mean); + AssertRoundedDouble(entity.LevelCrestStructureMean, input.LevelCrestStructure.Mean); + AssertRoundedDouble(entity.LevelCrestStructureStandardDeviation, input.LevelCrestStructure.StandardDeviation); + AssertRoundedDouble(entity.DeviationWaveDirection, input.DeviationWaveDirection); + + CollectionAssert.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 Point2DCollectionXmlSerializer().ToXml(points); + var foreshoreEntity = new ForeshoreProfileEntity + { + Id = "id", + BreakWaterHeight = breakWaterHeight, + BreakWaterType = Convert.ToByte(type), + GeometryXml = pointXml + }; + + var entity = new HeightStructuresCalculationEntity + { + UseForeshore = Convert.ToByte(flagUsage), + UseBreakWater = Convert.ToByte(!flagUsage), + ForeshoreProfileEntity = foreshoreEntity, + BreakWaterType = Convert.ToByte(type), + BreakWaterHeight = breakWaterHeight + }; + + 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(breakWaterHeight, input.BreakWater.Height, input.BreakWater.Height.GetAccuracy()); + CollectionAssert.AreEqual(points, input.ForeshoreProfile.Geometry); + Assert.IsNotNull(input.ForeshoreProfile); + } + + [Test] + public void Read_ValidEntityWithOutputEntity_ReturnCalculationWithOutput() + { + // Setup + var entity = new HeightStructuresCalculationEntity + { + HeightStructuresOutputEntities = + { + new HeightStructuresOutputEntity() + } + }; + + var collector = new ReadConversionCollector(); + + // Call + StructuresCalculation calculation = entity.Read(collector); + + // Assert + StructuresOutput calculationOutput = calculation.Output; + Assert.IsNaN(calculationOutput.Reliability); + Assert.IsFalse(calculationOutput.HasGeneralResult); + } + + [Test] + public void Read_CalculationEntityAlreadyRead_ReturnReadCalculation() + { + // Setup + var entity = new HeightStructuresCalculationEntity + { + HeightStructuresOutputEntities = + { + new HeightStructuresOutputEntity() + } + }; + + var calculation = new StructuresCalculation(); + + var collector = new ReadConversionCollector(); + collector.Read(entity, calculation); + + // Call + StructuresCalculation returnedCalculation = entity.Read(collector); + + // Assert + Assert.AreSame(calculation, returnedCalculation); + } + + private static void AssertRoundedDouble(double? entityValue, RoundedDouble roundedDouble) + { + Assert.AreEqual((RoundedDouble) entityValue.ToNullAsNaN(), roundedDouble, roundedDouble.GetAccuracy()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/HeightStructures/HeightStructuresFailureMechanismMetaEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/HeightStructures/HeightStructuresFailureMechanismMetaEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/HeightStructures/HeightStructuresFailureMechanismMetaEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,62 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.HeightStructures.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.HeightStructures; + +namespace Riskeer.Storage.Core.Test.Read.HeightStructures +{ + [TestFixture] + public class HeightStructuresFailureMechanismMetaEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => ((HeightStructuresFailureMechanismMetaEntity) null).Read(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_Always_ReturnGeneralHeightStructuresInput() + { + // Setup + var entity = new HeightStructuresFailureMechanismMetaEntity + { + N = new Random(39).NextRoundedDouble(1.0, 20.0) + }; + + // Call + GeneralHeightStructuresInput generalInput = entity.Read(); + + // Assert + Assert.AreEqual(entity.N, generalInput.N, generalInput.N.GetAccuracy()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/HeightStructures/HeightStructuresSectionResultEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/HeightStructures/HeightStructuresSectionResultEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/HeightStructures/HeightStructuresSectionResultEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,169 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.HeightStructures.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Read.HeightStructures; + +namespace Riskeer.Storage.Core.Test.Read.HeightStructures +{ + [TestFixture] + public class HeightStructuresSectionResultEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((HeightStructuresSectionResultEntity) null).Read( + new HeightStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), + new ReadConversionCollector()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_SectionResultNull_ThrowsArgumentNullException() + { + // Setup + var entity = new HeightStructuresSectionResultEntity(); + + // Call + TestDelegate call = () => entity.Read(null, new ReadConversionCollector()); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("sectionResult", paramName); + } + + [Test] + public void Read_CollectorNull_ThrowsArgumentNullException() + { + // Setup + var entity = new HeightStructuresSectionResultEntity(); + + // Call + TestDelegate call = () => entity.Read(new HeightStructuresFailureMechanismSectionResult( + FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void Read_ParameterValues_SectionResultWithParameterValues() + { + // Setup + var random = new Random(21); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResult = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + double tailorMadeAssessmentProbability = random.NextDouble(); + bool useManualAssembly = random.NextBoolean(); + double manualAssemblyProbability = random.NextDouble(); + + var collector = new ReadConversionCollector(); + + var failureMechanismSectionEntity = new FailureMechanismSectionEntity(); + collector.Read(failureMechanismSectionEntity, FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + var entity = new HeightStructuresSectionResultEntity + { + FailureMechanismSectionEntity = failureMechanismSectionEntity, + SimpleAssessmentResult = Convert.ToByte(simpleAssessmentResult), + DetailedAssessmentResult = Convert.ToByte(detailedAssessmentResult), + TailorMadeAssessmentResult = Convert.ToByte(tailorMadeAssessmentResult), + TailorMadeAssessmentProbability = tailorMadeAssessmentProbability, + UseManualAssembly = Convert.ToByte(useManualAssembly), + ManualAssemblyProbability = manualAssemblyProbability + }; + var sectionResult = new HeightStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult, collector); + + // Assert + Assert.AreEqual(simpleAssessmentResult, sectionResult.SimpleAssessmentResult); + Assert.AreEqual(simpleAssessmentResult, sectionResult.SimpleAssessmentResult); + Assert.AreEqual(detailedAssessmentResult, sectionResult.DetailedAssessmentResult); + Assert.AreEqual(tailorMadeAssessmentResult, sectionResult.TailorMadeAssessmentResult); + Assert.AreEqual(tailorMadeAssessmentProbability, sectionResult.TailorMadeAssessmentProbability, 1e-6); + Assert.AreEqual(useManualAssembly, sectionResult.UseManualAssembly); + Assert.AreEqual(manualAssemblyProbability, sectionResult.ManualAssemblyProbability, 1e-6); + Assert.IsNull(sectionResult.Calculation); + } + + [Test] + public void Read_EntityWithNullValues_SectionResultWithExpectedValuesValues() + { + // Setup + var collector = new ReadConversionCollector(); + + var failureMechanismSectionEntity = new FailureMechanismSectionEntity(); + collector.Read(failureMechanismSectionEntity, FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + var entity = new HeightStructuresSectionResultEntity + { + FailureMechanismSectionEntity = failureMechanismSectionEntity + }; + var sectionResult = new HeightStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult, collector); + + // Assert + Assert.IsNaN(sectionResult.TailorMadeAssessmentProbability); + Assert.IsNaN(sectionResult.ManualAssemblyProbability); + Assert.IsNull(sectionResult.Calculation); + } + + [Test] + public void Read_CalculationEntitySet_ReturnHeightStructuresSectionResultWithCalculation() + { + // Setup + var calculation = new StructuresCalculation(); + + var calculationEntity = new HeightStructuresCalculationEntity(); + + var collector = new ReadConversionCollector(); + collector.Read(calculationEntity, calculation); + + var entity = new HeightStructuresSectionResultEntity + { + HeightStructuresCalculationEntity = calculationEntity + }; + var sectionResult = new HeightStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult, collector); + + // Assert + Assert.AreSame(calculation, sectionResult.Calculation); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/HydraulicBoundaryDatabaseEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/HydraulicBoundaryDatabaseEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/HydraulicBoundaryDatabaseEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,101 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; + +namespace Riskeer.Storage.Core.Test.Read +{ + [TestFixture] + public class HydraulicBoundaryDatabaseEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((HydraulicBoundaryDatabaseEntity) null).Read(new HydraulicBoundaryDatabase()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_HydraulicBoundaryDatabaseNull_ThrowsArgumentNullException() + { + // Setup + var entity = new HydraulicBoundaryDatabaseEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("hydraulicBoundaryDatabase", exception.ParamName); + } + + [Test] + public void Read_WithValidEntity_UpdatesHydraulicBoundaryDatabase() + { + // Setup + var random = new Random(21); + var entity = new HydraulicBoundaryDatabaseEntity + { + FilePath = "hydraulicBoundaryDatabaseFilePath", + Version = "hydraulicBoundaryDatabaseVersion", + HydraulicLocationConfigurationSettingsFilePath = "hlcdFilePath", + HydraulicLocationConfigurationSettingsScenarioName = "ScenarioName", + HydraulicLocationConfigurationSettingsYear = random.Next(), + HydraulicLocationConfigurationSettingsScope = "Scope", + HydraulicLocationConfigurationSettingsSeaLevel = "SeaLevel", + HydraulicLocationConfigurationSettingsRiverDischarge = "RiverDischarge", + HydraulicLocationConfigurationSettingsLakeLevel = "LakeLevel", + HydraulicLocationConfigurationSettingsWindDirection = "WindDirection", + HydraulicLocationConfigurationSettingsWindSpeed = "WindSpeed", + HydraulicLocationConfigurationSettingsComment = "Comment" + }; + + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); + + // Call + entity.Read(hydraulicBoundaryDatabase); + + // Assert + Assert.AreEqual(entity.FilePath, hydraulicBoundaryDatabase.FilePath); + Assert.AreEqual(entity.Version, hydraulicBoundaryDatabase.Version); + + HydraulicLocationConfigurationSettings settings = hydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings; + Assert.AreEqual(entity.HydraulicLocationConfigurationSettingsFilePath, settings.FilePath); + Assert.AreEqual(entity.HydraulicLocationConfigurationSettingsScenarioName, settings.ScenarioName); + Assert.AreEqual(entity.HydraulicLocationConfigurationSettingsYear, settings.Year); + Assert.AreEqual(entity.HydraulicLocationConfigurationSettingsScope, settings.Scope); + Assert.AreEqual(entity.HydraulicLocationConfigurationSettingsSeaLevel, settings.SeaLevel); + Assert.AreEqual(entity.HydraulicLocationConfigurationSettingsRiverDischarge, settings.RiverDischarge); + Assert.AreEqual(entity.HydraulicLocationConfigurationSettingsLakeLevel, settings.LakeLevel); + Assert.AreEqual(entity.HydraulicLocationConfigurationSettingsWindDirection, settings.WindDirection); + Assert.AreEqual(entity.HydraulicLocationConfigurationSettingsWindSpeed, settings.WindSpeed); + Assert.AreEqual(entity.HydraulicLocationConfigurationSettingsComment, settings.Comment); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/HydraulicLocationCalculationCollectionEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/HydraulicLocationCalculationCollectionEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/HydraulicLocationCalculationCollectionEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,138 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Storage.Core.TestUtil.Hydraulics; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; + +namespace Riskeer.Storage.Core.Test.Read +{ + [TestFixture] + public class HydraulicLocationCalculationCollectionEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => + ((HydraulicLocationCalculationCollectionEntity) null).Read(Enumerable.Empty(), + new ReadConversionCollector()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_CalculationsNull_ThrowsArgumentNullException() + { + // Setup + var entity = new HydraulicLocationCalculationCollectionEntity(); + + // Call + TestDelegate call = () => entity.Read(null, new ReadConversionCollector()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("calculations", exception.ParamName); + } + + [Test] + public void Read_CollectorNull_ThrowsArgumentNullException() + { + // Setup + var entity = new HydraulicLocationCalculationCollectionEntity(); + + // Call + TestDelegate call = () => entity.Read(Enumerable.Empty(), + null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("collector", exception.ParamName); + } + + [Test] + public void Read_EntityWithValidValues_SetsCalculationsWithExpectedValues() + { + // Setup + var random = new Random(21); + + HydraulicLocationEntity hydraulicLocationEntityOne = HydraulicLocationEntityTestFactory.CreateHydraulicLocationEntity(); + var calculationEntityWithoutOutput = new HydraulicLocationCalculationEntity + { + HydraulicLocationEntity = hydraulicLocationEntityOne, + ShouldIllustrationPointsBeCalculated = Convert.ToByte(random.NextBoolean()) + }; + + HydraulicLocationEntity hydraulicLocationEntityTwo = HydraulicLocationEntityTestFactory.CreateHydraulicLocationEntity(); + var calculationEntityWithOutput = new HydraulicLocationCalculationEntity + { + HydraulicLocationEntity = hydraulicLocationEntityTwo, + ShouldIllustrationPointsBeCalculated = Convert.ToByte(random.NextBoolean()), + HydraulicLocationOutputEntities = + { + new HydraulicLocationOutputEntity() + } + }; + + var collectionEntity = new HydraulicLocationCalculationCollectionEntity + { + HydraulicLocationCalculationEntities = + { + calculationEntityWithoutOutput, + calculationEntityWithOutput + } + }; + + var hydraulicBoundaryLocationOne = new TestHydraulicBoundaryLocation("1"); + var hydraulicBoundaryLocationTwo = new TestHydraulicBoundaryLocation("2"); + var collector = new ReadConversionCollector(); + collector.Read(hydraulicLocationEntityOne, hydraulicBoundaryLocationOne); + collector.Read(hydraulicLocationEntityTwo, hydraulicBoundaryLocationTwo); + + var calculationOne = new HydraulicBoundaryLocationCalculation(hydraulicBoundaryLocationOne); + var calculationTwo = new HydraulicBoundaryLocationCalculation(hydraulicBoundaryLocationTwo); + + // Call + collectionEntity.Read(new[] + { + calculationOne, + calculationTwo + }, collector); + + // Assert + Assert.AreEqual(Convert.ToBoolean(calculationEntityWithoutOutput.ShouldIllustrationPointsBeCalculated), + calculationOne.InputParameters.ShouldIllustrationPointsBeCalculated); + Assert.IsNull(calculationOne.Output); + + Assert.AreEqual(Convert.ToBoolean(calculationEntityWithOutput.ShouldIllustrationPointsBeCalculated), + calculationTwo.InputParameters.ShouldIllustrationPointsBeCalculated); + Assert.IsNotNull(calculationTwo.Output); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/HydraulicLocationCalculationEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/HydraulicLocationCalculationEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/HydraulicLocationCalculationEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,214 @@ +// Copyright (C) Stichting Deltares 2018. 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 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; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; + +namespace Riskeer.Storage.Core.Test.Read +{ + [TestFixture] + public class HydraulicLocationCalculationEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Setup + var calculation = new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation()); + + // Call + TestDelegate call = () => ((HydraulicLocationCalculationEntity) null).Read(calculation); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_HydraulicBoundaryLocationCalculationNull_ThrowsArgumentNullException() + { + // Setup + var entity = new HydraulicLocationCalculationEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("calculation", exception.ParamName); + } + + [Test] + public void Read_CalculationWithoutOutput_HydraulicBoundaryLocationCalculationWithExpectedValues() + { + // Setup + HydraulicLocationCalculationEntity entity = CreateCalculationEntity(21); + + var calculation = new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation()); + + // Call + entity.Read(calculation); + + // Assert + AssertHydraulicBoundaryLocationCalculation(entity, calculation); + } + + [Test] + public void Read_CalculationWithOutputWithoutIllustrationPoints_HydraulicBoundaryLocationCalculationWithExpectedValues() + { + // Setup + HydraulicLocationCalculationEntity entity = CreateCalculationEntityWithOutputEntity(21); + + var calculation = new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation()); + + // Call + entity.Read(calculation); + + // Assert + AssertHydraulicBoundaryLocationCalculation(entity, calculation); + } + + [Test] + public void Read_CalculationWithOutputAndIllustrationPoints_HydraulicBoundaryLocationCalculationWithExpectedValues() + { + // Setup + HydraulicLocationCalculationEntity entity = CreateCalculationEntityWithOutputAndGeneralResultEntity(21); + + var calculation = new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation()); + + // Call + entity.Read(calculation); + + // Assert + AssertHydraulicBoundaryLocationCalculation(entity, calculation); + } + + private static HydraulicLocationCalculationEntity CreateCalculationEntity(int seed) + { + var random = new Random(seed); + + return new HydraulicLocationCalculationEntity + { + ShouldIllustrationPointsBeCalculated = Convert.ToByte(random.NextBoolean()) + }; + } + + private static HydraulicLocationOutputEntity CreateHydraulicOutputEntity(int seed) + { + var random = new Random(seed); + var hydraulicLocationOutputEntity = new HydraulicLocationOutputEntity + { + Result = random.NextDouble(), + TargetProbability = random.NextDouble(), + TargetReliability = random.NextDouble(), + CalculatedProbability = random.NextDouble(), + CalculatedReliability = random.NextDouble(), + CalculationConvergence = Convert.ToByte(CalculationConvergence.NotCalculated) + }; + return hydraulicLocationOutputEntity; + } + + private static HydraulicLocationCalculationEntity CreateCalculationEntityWithOutputEntity(int seed) + { + HydraulicLocationCalculationEntity calculationEntity = CreateCalculationEntity(seed); + calculationEntity.HydraulicLocationOutputEntities.Add(CreateHydraulicOutputEntity(seed)); + + return calculationEntity; + } + + private static HydraulicLocationCalculationEntity CreateCalculationEntityWithOutputAndGeneralResultEntity(int seed) + { + var random = new Random(seed); + var generalResultEntity = new GeneralResultSubMechanismIllustrationPointEntity + { + GoverningWindDirectionName = "A wind direction", + GoverningWindDirectionAngle = random.NextDouble() + }; + + HydraulicLocationOutputEntity hydraulicLocationOutputEntity = CreateHydraulicOutputEntity(seed); + hydraulicLocationOutputEntity.GeneralResultSubMechanismIllustrationPointEntity = generalResultEntity; + + HydraulicLocationCalculationEntity calculationEntity = CreateCalculationEntity(seed); + calculationEntity.HydraulicLocationOutputEntities.Add(hydraulicLocationOutputEntity); + + return calculationEntity; + } + + private static void AssertHydraulicBoundaryLocationCalculation(HydraulicLocationCalculationEntity expected, + HydraulicBoundaryLocationCalculation actual) + { + Assert.AreEqual(Convert.ToBoolean(expected.ShouldIllustrationPointsBeCalculated), + actual.InputParameters.ShouldIllustrationPointsBeCalculated); + + AssertHydraulicBoundaryLocationCalculationOutput(expected.HydraulicLocationOutputEntities.SingleOrDefault(), + actual.Output); + } + + private static void AssertHydraulicBoundaryLocationCalculationOutput(HydraulicLocationOutputEntity expected, HydraulicBoundaryLocationCalculationOutput actual) + { + if (expected == null) + { + Assert.IsNull(actual); + return; + } + + Assert.IsNotNull(expected.Result); + Assert.AreEqual((RoundedDouble) expected.Result, actual.Result, actual.Result.GetAccuracy()); + Assert.IsNotNull(expected.TargetReliability); + Assert.AreEqual((RoundedDouble) expected.TargetReliability, actual.TargetReliability, actual.TargetReliability.GetAccuracy()); + Assert.IsNotNull(expected.TargetProbability); + Assert.AreEqual(expected.TargetProbability, actual.TargetProbability); + Assert.IsNotNull(expected.CalculatedReliability); + Assert.AreEqual((RoundedDouble) expected.CalculatedReliability, actual.CalculatedReliability, actual.CalculatedReliability.GetAccuracy()); + Assert.IsNotNull(expected.CalculatedProbability); + Assert.AreEqual(expected.CalculatedProbability, actual.CalculatedProbability); + Assert.AreEqual((CalculationConvergence) expected.CalculationConvergence, actual.CalculationConvergence); + + AssertGeneralResult(expected.GeneralResultSubMechanismIllustrationPointEntity, actual.GeneralResult); + } + + private static void AssertGeneralResult(GeneralResultSubMechanismIllustrationPointEntity expected, + GeneralResult illustrationPoint) + { + if (expected == null) + { + Assert.IsNull(illustrationPoint); + return; + } + + WindDirection actualGoverningWindDirection = illustrationPoint.GoverningWindDirection; + Assert.AreEqual(expected.GoverningWindDirectionName, actualGoverningWindDirection.Name); + Assert.AreEqual(expected.GoverningWindDirectionAngle, actualGoverningWindDirection.Angle, + actualGoverningWindDirection.Angle.GetAccuracy()); + + Assert.AreEqual(expected.TopLevelSubMechanismIllustrationPointEntities.Count, + illustrationPoint.TopLevelIllustrationPoints.Count()); + Assert.AreEqual(expected.StochastEntities.Count, illustrationPoint.Stochasts.Count()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/HydraulicLocationEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/HydraulicLocationEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/HydraulicLocationEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,109 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; + +namespace Riskeer.Storage.Core.Test.Read +{ + [TestFixture] + public class HydraulicLocationEntityReadExtensionsTest + { + [Test] + public void Read_EntityIsNull_ThrowArgumentNullException() + { + // Call + TestDelegate call = () => ((HydraulicLocationEntity) null).Read(new ReadConversionCollector()); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Read_CollectorIsNull_ThrowArgumentNullException() + { + // Setup + var entity = new HydraulicLocationEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void Read_WithCollectorAndEntitiesWithoutOutput_ReturnsHydraulicBoundaryLocationWithPropertiesSetAndEntityRegistered() + { + // Setup + var random = new Random(21); + long testId = random.Next(0, 400); + const string testName = "testName"; + double x = random.NextDouble(); + double y = random.NextDouble(); + + var entity = new HydraulicLocationEntity + { + LocationId = testId, + Name = testName, + LocationX = x, + LocationY = y + }; + + var collector = new ReadConversionCollector(); + + // Call + HydraulicBoundaryLocation location = entity.Read(collector); + + // Assert + Assert.IsNotNull(location); + Assert.AreEqual(testId, location.Id); + Assert.AreEqual(testName, location.Name); + Assert.AreEqual(x, location.Location.X, 1e-6); + Assert.AreEqual(y, location.Location.Y, 1e-6); + Assert.IsTrue(collector.Contains(entity)); + } + + [Test] + public void Read_SameHydraulicLocationEntityTwice_ReturnSameHydraulicBoundaryLocation() + { + // Setup + var entity = new HydraulicLocationEntity + { + Name = "A" + }; + + var collector = new ReadConversionCollector(); + + // Call + HydraulicBoundaryLocation location1 = entity.Read(collector); + HydraulicBoundaryLocation location2 = entity.Read(collector); + + // Assert + Assert.AreSame(location1, location2); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/HydraulicLocationOutputEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/HydraulicLocationOutputEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/HydraulicLocationOutputEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,226 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.TestUtil; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; + +namespace Riskeer.Storage.Core.Test.Read +{ + [TestFixture] + public class HydraulicLocationOutputEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((HydraulicLocationOutputEntity) null).Read(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_ValidParameters_ReturnsHydraulicBoundaryLocationCalculationOutput() + { + // 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 convergence = random.NextEnumValue(); + var entity = new HydraulicLocationOutputEntity + { + Result = result, + TargetProbability = targetProbability, + TargetReliability = targetReliability, + CalculatedProbability = calculatedProbability, + CalculatedReliability = calculatedReliability, + CalculationConvergence = Convert.ToByte(convergence) + }; + + // Call + HydraulicBoundaryLocationCalculationOutput output = entity.Read(); + + // Assert + Assert.AreEqual(result, output.Result, output.Result.GetAccuracy()); + Assert.AreEqual(targetProbability, output.TargetProbability); + Assert.AreEqual(targetReliability, output.TargetReliability, output.TargetReliability.GetAccuracy()); + Assert.AreEqual(calculatedProbability, output.CalculatedProbability); + Assert.AreEqual(calculatedReliability, output.CalculatedReliability, output.CalculatedReliability.GetAccuracy()); + Assert.AreEqual(convergence, output.CalculationConvergence); + Assert.IsNull(output.GeneralResult); + } + + [Test] + public void Read_NaNParameters_ReturnsHydraulicBoundaryLocationCalculationOutputWithNaN() + { + // Setup + var random = new Random(21); + var convergence = random.NextEnumValue(); + + var entity = new HydraulicLocationOutputEntity + { + Result = double.NaN, + TargetProbability = double.NaN, + TargetReliability = double.NaN, + CalculatedProbability = double.NaN, + CalculatedReliability = double.NaN, + CalculationConvergence = Convert.ToByte(convergence) + }; + + // Call + HydraulicBoundaryLocationCalculationOutput 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_ReturnsHydraulicBoundaryLocationCalculationOutputWithGeneralResult() + { + // 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 HydraulicLocationOutputEntity + { + Result = double.NaN, + TargetProbability = double.NaN, + TargetReliability = double.NaN, + CalculatedProbability = double.NaN, + CalculatedReliability = double.NaN, + CalculationConvergence = Convert.ToByte(random.NextEnumValue()), + GeneralResultSubMechanismIllustrationPointEntity = new GeneralResultSubMechanismIllustrationPointEntity + { + GoverningWindDirectionName = "SSE", + GoverningWindDirectionAngle = random.NextDouble(), + StochastEntities = stochastEntities, + TopLevelSubMechanismIllustrationPointEntities = topLevelIllustrationPointEntities + } + }; + + // Call + HydraulicBoundaryLocationCalculationOutput 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: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/IllustrationPoints/FaultTreeIllustrationPointEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/IllustrationPoints/FaultTreeIllustrationPointEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/IllustrationPoints/FaultTreeIllustrationPointEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,293 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.TestUtil; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.IllustrationPoints; + +namespace Riskeer.Storage.Core.Test.Read.IllustrationPoints +{ + [TestFixture] + public class FaultTreeIllustrationPointEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((FaultTreeIllustrationPointEntity) null).Read(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_ValidEntityWithStochasts_ReturnsIllustrationPointNode() + { + // Setup + var random = new Random(21); + + var combinationType = random.NextEnumValue(); + var entity = new FaultTreeIllustrationPointEntity + { + Name = "FaultTreeIllustrationPointEntity", + Beta = random.NextDouble(), + CombinationType = Convert.ToByte(combinationType), + StochastEntities = + { + new StochastEntity + { + Alpha = random.NextDouble(), + Duration = random.NextDouble(), + Name = "StochastEntity" + } + } + }; + + // Call + IllustrationPointNode node = entity.Read(); + + // Assert + var illustrationPoint = node.Data as FaultTreeIllustrationPoint; + Assert.IsNotNull(illustrationPoint); + Assert.AreEqual(entity.Name, illustrationPoint.Name); + Assert.AreEqual(entity.Beta, illustrationPoint.Beta, illustrationPoint.Beta.GetAccuracy()); + Assert.AreEqual(combinationType, illustrationPoint.CombinationType); + + AssertStochasts(entity.StochastEntities.ToArray(), illustrationPoint.Stochasts.ToArray()); + + CollectionAssert.IsEmpty(node.Children); + } + + [Test] + public void Read_ValidEntityWithIllustrationPoints_ReturnsIllustrationPointNode() + { + // Setup + var random = new Random(21); + var entity = new FaultTreeIllustrationPointEntity + { + Name = "FaultTreeIllustrationPointEntity", + Beta = random.NextDouble(), + CombinationType = Convert.ToByte(random.NextEnumValue()), + SubMechanismIllustrationPointEntities = + { + new SubMechanismIllustrationPointEntity + { + Name = "SubMechanismIllustrationPointEntity", + Beta = random.NextDouble(), + Order = 10 + } + }, + FaultTreeIllustrationPointEntity1 = + { + new FaultTreeIllustrationPointEntity + { + Name = "FaultTreeIllustrationPointEntity", + Beta = random.NextDouble(), + CombinationType = Convert.ToByte(random.NextEnumValue()), + Order = 5 + } + } + }; + + // Call + IllustrationPointNode node = entity.Read(); + + // Assert + var illustrationPoint = node.Data as FaultTreeIllustrationPoint; + Assert.IsNotNull(illustrationPoint); + Assert.AreEqual(entity.Name, illustrationPoint.Name); + Assert.AreEqual(entity.Beta, illustrationPoint.Beta, illustrationPoint.Beta.GetAccuracy()); + Assert.AreEqual((CombinationType) entity.CombinationType, illustrationPoint.CombinationType); + + IllustrationPointNode[] children = node.Children.ToArray(); + Assert.AreEqual(2, children.Length); + + AssertFaultTreeIllustrationPointNode(entity.FaultTreeIllustrationPointEntity1.First(), children[0]); + AssertSubMechanismIllustrationPointNode(entity.SubMechanismIllustrationPointEntities.First(), children[1]); + } + + [Test] + public void Read_ValidEntityWithNestedIllustrationPoints_ReturnsIllustrationPointNodeWithNesting() + { + // Setup + var random = new Random(21); + var entity = new FaultTreeIllustrationPointEntity + { + Name = "FaultTreeIllustrationPointEntity", + Beta = random.NextDouble(), + CombinationType = Convert.ToByte(random.NextEnumValue()), + SubMechanismIllustrationPointEntities = + { + new SubMechanismIllustrationPointEntity + { + Name = "SubMechanismIllustrationPointEntity", + Beta = random.NextDouble(), + Order = 0 + } + }, + FaultTreeIllustrationPointEntity1 = + { + new FaultTreeIllustrationPointEntity + { + Name = "FaultTreeIllustrationPointEntityChild", + Beta = random.NextDouble(), + CombinationType = Convert.ToByte(random.NextEnumValue()), + Order = 1, + FaultTreeIllustrationPointEntity1 = + { + new FaultTreeIllustrationPointEntity + { + Name = "FaultTreeIllustrationPointEntityChildsChild", + Beta = random.NextDouble(), + CombinationType = Convert.ToByte(random.NextEnumValue()), + Order = 0 + }, + new FaultTreeIllustrationPointEntity + { + Name = "FaultTreeIllustrationPointEntityChildsSecondChild", + Beta = random.NextDouble(), + CombinationType = Convert.ToByte(random.NextEnumValue()), + Order = 1 + } + } + } + } + }; + + // Call + IllustrationPointNode node = entity.Read(); + + // Assert + var illustrationPoint = node.Data as FaultTreeIllustrationPoint; + Assert.IsNotNull(illustrationPoint); + Assert.AreEqual(entity.Name, illustrationPoint.Name); + Assert.AreEqual(entity.Beta, illustrationPoint.Beta, illustrationPoint.Beta.GetAccuracy()); + Assert.AreEqual((CombinationType) entity.CombinationType, illustrationPoint.CombinationType); + + IllustrationPointNode[] children = node.Children.ToArray(); + Assert.AreEqual(2, children.Length); + + AssertIllustrationPointNodes(entity.FaultTreeIllustrationPointEntity1, children); + AssertIllustrationPointNodes(entity.SubMechanismIllustrationPointEntities, children); + } + + private static void AssertIllustrationPointNodes(ICollection entities, + IEnumerable nodes) + { + FaultTreeIllustrationPointEntity[] entitiesArray = entities.OrderBy(ip => ip.Order).ToArray(); + IllustrationPointNode[] faultTreeNodes = nodes.Where(n => n.Data.GetType() == typeof(FaultTreeIllustrationPoint)).ToArray(); + + Assert.AreEqual(entitiesArray.Length, faultTreeNodes.Length); + + for (var i = 0; i < entitiesArray.Length; i++) + { + FaultTreeIllustrationPointEntity entity = entitiesArray[i]; + IllustrationPointNode node = faultTreeNodes[i]; + + AssertFaultTreeIllustrationPointNode(entity, node); + } + } + + private static void AssertIllustrationPointNodes(ICollection entities, + IEnumerable nodes) + { + SubMechanismIllustrationPointEntity[] entitiesArray = entities.OrderBy(ip => ip.Order).ToArray(); + IllustrationPointNode[] subMechanismNodes = nodes.Where(n => n.Data.GetType() == typeof(SubMechanismIllustrationPoint)).ToArray(); + + Assert.AreEqual(entitiesArray.Length, subMechanismNodes.Length); + + for (var i = 0; i < entitiesArray.Length; i++) + { + SubMechanismIllustrationPointEntity entity = entitiesArray[i]; + IllustrationPointNode node = subMechanismNodes[i]; + + AssertSubMechanismIllustrationPointNode(entity, node); + } + } + + private static void AssertFaultTreeIllustrationPointNode(FaultTreeIllustrationPointEntity entity, + IllustrationPointNode node) + { + var illustrationPoint = node.Data as FaultTreeIllustrationPoint; + Assert.IsNotNull(illustrationPoint); + Assert.AreEqual(entity.Name, illustrationPoint.Name); + Assert.AreEqual(entity.Beta, illustrationPoint.Beta, illustrationPoint.Beta.GetAccuracy()); + Assert.AreEqual((CombinationType) entity.CombinationType, illustrationPoint.CombinationType); + AssertStochasts(entity.StochastEntities.ToArray(), illustrationPoint.Stochasts.ToArray()); + + AssertIllustrationPointNodes(entity.FaultTreeIllustrationPointEntity1, node.Children); + AssertIllustrationPointNodes(entity.SubMechanismIllustrationPointEntities, node.Children); + } + + private static void AssertSubMechanismIllustrationPointNode(SubMechanismIllustrationPointEntity entity, + IllustrationPointNode node) + { + var illustrationPoint = node.Data as SubMechanismIllustrationPoint; + Assert.IsNotNull(illustrationPoint); + Assert.AreEqual(entity.Name, illustrationPoint.Name); + Assert.AreEqual(entity.Beta, illustrationPoint.Beta, illustrationPoint.Beta.GetAccuracy()); + AssertStochasts(entity.SubMechanismIllustrationPointStochastEntities.ToArray(), illustrationPoint.Stochasts.ToArray()); + + CollectionAssert.IsEmpty(illustrationPoint.Stochasts); + CollectionAssert.IsEmpty(illustrationPoint.IllustrationPointResults); + CollectionAssert.IsEmpty(node.Children); + } + + private static void AssertStochasts(SubMechanismIllustrationPointStochastEntity[] stochastEntities, + SubMechanismIllustrationPointStochast[] stochasts) + { + Assert.AreEqual(stochastEntities.Length, stochasts.Length); + + for (var i = 0; i < stochastEntities.Length; i++) + { + SubMechanismIllustrationPointStochastEntity stochastEntity = stochastEntities[i]; + SubMechanismIllustrationPointStochast stochast = stochasts[i]; + + Assert.AreEqual(stochastEntity.Name, stochast.Name); + Assert.AreEqual(stochastEntity.Alpha, stochast.Alpha, stochast.Alpha.GetAccuracy()); + Assert.AreEqual(stochastEntity.Duration, stochast.Duration, stochast.Duration.GetAccuracy()); + Assert.AreEqual(stochastEntity.Realization, stochast.Realization, stochast.Realization.GetAccuracy()); + } + } + + private static void AssertStochasts(StochastEntity[] stochastEntities, Stochast[] stochasts) + { + Assert.AreEqual(stochastEntities.Length, stochasts.Length); + + for (var i = 0; i < stochastEntities.Length; i++) + { + StochastEntity stochastEntity = stochastEntities[i]; + Stochast stochast = stochasts[i]; + + Assert.AreEqual(stochastEntity.Name, stochast.Name); + Assert.AreEqual(stochastEntity.Alpha, stochast.Alpha, stochast.Alpha.GetAccuracy()); + Assert.AreEqual(stochastEntity.Duration, stochast.Duration, stochast.Duration.GetAccuracy()); + } + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/IllustrationPoints/GeneralResultFaultTreeIllustrationPointEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/IllustrationPoints/GeneralResultFaultTreeIllustrationPointEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/IllustrationPoints/GeneralResultFaultTreeIllustrationPointEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,203 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.TestUtil; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.IllustrationPoints; + +namespace Riskeer.Storage.Core.Test.Read.IllustrationPoints +{ + [TestFixture] + public class GeneralResultFaultTreeIllustrationPointEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((GeneralResultFaultTreeIllustrationPointEntity) null).Read(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_ValidEntity_ReturnsGeneralResult() + { + // Setup + var entity = new GeneralResultFaultTreeIllustrationPointEntity + { + GoverningWindDirectionName = "SSE", + GoverningWindDirectionAngle = new Random(213).NextDouble() + }; + + // Call + GeneralResult generalResult = entity.Read(); + + // Assert + AssertWindDirection(entity, generalResult.GoverningWindDirection); + CollectionAssert.IsEmpty(generalResult.Stochasts); + CollectionAssert.IsEmpty(generalResult.TopLevelIllustrationPoints); + } + + [Test] + public void Read_ValidEntityWithStochasts_ReturnsGeneralResultFaultTreeIllustrationPoint() + { + // Setup + var random = new Random(21); + + var entity = new GeneralResultFaultTreeIllustrationPointEntity + { + GoverningWindDirectionName = "SSE", + GoverningWindDirectionAngle = random.NextDouble(), + StochastEntities = new[] + { + new StochastEntity + { + Name = "stochastEntityOne", + Duration = random.NextDouble(), + Alpha = random.NextDouble(), + Order = 0 + }, + new StochastEntity + { + Name = "stochastEntityTwo", + Duration = random.NextDouble(), + Alpha = random.NextDouble(), + Order = 1 + } + } + }; + + // Call + GeneralResult generalResult = entity.Read(); + + // Assert + AssertWindDirection(entity, generalResult.GoverningWindDirection); + AssertStochasts(entity.StochastEntities.ToArray(), generalResult.Stochasts.ToArray()); + } + + [Test] + public void Read_ValidEntityWithIllustrationPoints_ReturnsGeneralResultFaultTreeIllustrationPoint() + { + // Setup + var random = new Random(210); + + var topLevelFaultTreeIllustrationPointEntities = new[] + { + new TopLevelFaultTreeIllustrationPointEntity + { + WindDirectionName = "WindDirectionOne", + WindDirectionAngle = random.NextDouble(), + ClosingSituation = "ClosingSituationOne", + FaultTreeIllustrationPointEntity = new FaultTreeIllustrationPointEntity + { + Beta = random.NextDouble(), + CombinationType = Convert.ToByte(random.NextEnumValue()), + Name = "IllustrationPointOne" + }, + Order = 0 + }, + new TopLevelFaultTreeIllustrationPointEntity + { + WindDirectionName = "WindDirectionTwo", + WindDirectionAngle = random.NextDouble(), + ClosingSituation = "ClosingSituationTwo", + FaultTreeIllustrationPointEntity = new FaultTreeIllustrationPointEntity + { + Beta = random.NextDouble(), + CombinationType = Convert.ToByte(random.NextEnumValue()), + Name = "IllustrationPointTwo" + }, + Order = 1 + } + }; + + var entity = new GeneralResultFaultTreeIllustrationPointEntity + { + GoverningWindDirectionName = "SSE", + GoverningWindDirectionAngle = random.NextDouble(), + TopLevelFaultTreeIllustrationPointEntities = topLevelFaultTreeIllustrationPointEntities + }; + + // Call + GeneralResult generalResult = entity.Read(); + + // Assert + AssertWindDirection(entity, generalResult.GoverningWindDirection); + AssertIllustrationPoints(entity.TopLevelFaultTreeIllustrationPointEntities.ToArray(), + generalResult.TopLevelIllustrationPoints.ToArray()); + } + + private static void AssertWindDirection(IGeneralResultEntity entity, WindDirection windDirection) + { + Assert.AreEqual(entity.GoverningWindDirectionName, windDirection.Name); + Assert.AreEqual(entity.GoverningWindDirectionAngle, windDirection.Angle, + windDirection.Angle.GetAccuracy()); + } + + private static void AssertStochasts(StochastEntity[] entities, Stochast[] stochasts) + { + Assert.AreEqual(entities.Length, stochasts.Length); + for (var i = 0; i < entities.Length; i++) + { + AssertStochast(entities[i], stochasts[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 AssertIllustrationPoints( + TopLevelFaultTreeIllustrationPointEntity[] entities, + TopLevelFaultTreeIllustrationPoint[] illustrationPoints) + { + Assert.AreEqual(entities.Length, illustrationPoints.Length); + for (var i = 0; i < entities.Length; i++) + { + AssertTopLevelFaultTreeIllustrationPoint(entities[i], illustrationPoints[i]); + } + } + + private static void AssertTopLevelFaultTreeIllustrationPoint( + TopLevelFaultTreeIllustrationPointEntity illustrationPointEntity, + TopLevelFaultTreeIllustrationPoint illustrationPoint) + { + Assert.AreEqual(illustrationPointEntity.ClosingSituation, illustrationPoint.ClosingSituation); + + WindDirection actualWindDirection = illustrationPoint.WindDirection; + Assert.AreEqual(illustrationPointEntity.WindDirectionName, actualWindDirection.Name); + Assert.AreEqual(illustrationPointEntity.WindDirectionAngle, actualWindDirection.Angle, actualWindDirection.Angle); + + Assert.IsNotNull(illustrationPoint.FaultTreeNodeRoot); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/IllustrationPoints/GeneralResultSubMechanismIllustrationPointEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/IllustrationPoints/GeneralResultSubMechanismIllustrationPointEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/IllustrationPoints/GeneralResultSubMechanismIllustrationPointEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,200 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.TestUtil; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.IllustrationPoints; + +namespace Riskeer.Storage.Core.Test.Read.IllustrationPoints +{ + [TestFixture] + public class GeneralResultSubMechanismIllustrationPointEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((GeneralResultSubMechanismIllustrationPointEntity) null).Read(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_ValidEntityWithoutStochastsAndIllustrationPoints_ReturnsGeneralResultSubMechanismIllustrationPoint() + { + // Setup + var entity = new GeneralResultSubMechanismIllustrationPointEntity + { + GoverningWindDirectionName = "SSE", + GoverningWindDirectionAngle = new Random(21).NextDouble() + }; + + // Call + GeneralResult generalResult = entity.Read(); + + // Assert + AssertWindDirection(entity, generalResult.GoverningWindDirection); + CollectionAssert.IsEmpty(generalResult.Stochasts); + CollectionAssert.IsEmpty(generalResult.TopLevelIllustrationPoints); + } + + [Test] + public void Read_ValidEntityWithStochasts_ReturnsGeneralResultSubMechanismIllustrationPoint() + { + // Setup + var random = new Random(21); + + var entity = new GeneralResultSubMechanismIllustrationPointEntity + { + GoverningWindDirectionName = "SSE", + GoverningWindDirectionAngle = random.NextDouble(), + StochastEntities = new[] + { + new StochastEntity + { + Name = "stochastEntityOne", + Duration = random.NextDouble(), + Alpha = random.NextDouble(), + Order = 0 + }, + new StochastEntity + { + Name = "stochastEntityTwo", + Duration = random.NextDouble(), + Alpha = random.NextDouble(), + Order = 1 + } + } + }; + + // Call + GeneralResult generalResult = entity.Read(); + + // Assert + AssertWindDirection(entity, generalResult.GoverningWindDirection); + AssertStochasts(entity.StochastEntities.ToArray(), generalResult.Stochasts.ToArray()); + } + + [Test] + public void Read_ValidEntityWithIllustrationPoints_ReturnsGeneralResultSubMechanismIllustrationPoint() + { + // Setup + var random = new Random(210); + + var topLevelSubMechanismIllustrationPointEntities = new[] + { + new TopLevelSubMechanismIllustrationPointEntity + { + WindDirectionName = "WindDirectionOne", + WindDirectionAngle = random.NextDouble(), + ClosingSituation = "ClosingSituationOne", + SubMechanismIllustrationPointEntity = new SubMechanismIllustrationPointEntity + { + Beta = random.NextDouble(), + Name = "IllustrationPointOne" + }, + Order = 0 + }, + new TopLevelSubMechanismIllustrationPointEntity + { + WindDirectionName = "WindDirectionTwo", + WindDirectionAngle = random.NextDouble(), + ClosingSituation = "ClosingSituationTwo", + SubMechanismIllustrationPointEntity = new SubMechanismIllustrationPointEntity + { + Beta = random.NextDouble(), + Name = "IllustrationPointTwo" + }, + Order = 1 + } + }; + + var entity = new GeneralResultSubMechanismIllustrationPointEntity + { + GoverningWindDirectionName = "SSE", + GoverningWindDirectionAngle = random.NextDouble(), + TopLevelSubMechanismIllustrationPointEntities = topLevelSubMechanismIllustrationPointEntities + }; + + // Call + GeneralResult generalResult = entity.Read(); + + // Assert + AssertWindDirection(entity, generalResult.GoverningWindDirection); + AssertTopLevelSubMechanismIllustrationPoints(entity.TopLevelSubMechanismIllustrationPointEntities.ToArray(), + generalResult.TopLevelIllustrationPoints.ToArray()); + } + + private static void AssertTopLevelSubMechanismIllustrationPoints( + TopLevelSubMechanismIllustrationPointEntity[] entities, + TopLevelSubMechanismIllustrationPoint[] illustrationPoints) + { + Assert.AreEqual(entities.Length, illustrationPoints.Length); + for (var i = 0; i < entities.Length; i++) + { + AssertTopLevelSubMechanismIllustrationPoint(entities[i], illustrationPoints[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(StochastEntity[] entities, Stochast[] stochasts) + { + Assert.AreEqual(entities.Length, stochasts.Length); + for (var i = 0; i < entities.Length; i++) + { + AssertStochast(entities[i], stochasts[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: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/IllustrationPoints/IllustrationPointResultEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/IllustrationPoints/IllustrationPointResultEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/IllustrationPoints/IllustrationPointResultEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,64 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.TestUtil; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.IllustrationPoints; + +namespace Riskeer.Storage.Core.Test.Read.IllustrationPoints +{ + [TestFixture] + public class IllustrationPointResultEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((IllustrationPointResultEntity) null).Read(); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Read_ValidEntity_ReturnIllustrationPointResult() + { + // Setup + var random = new Random(123); + var entity = new IllustrationPointResultEntity + { + Description = "Description", + Value = random.NextDouble() + }; + + // Call + IllustrationPointResult illustrationPointResult = entity.Read(); + + // Assert + Assert.AreEqual(entity.Description, illustrationPointResult.Description); + Assert.AreEqual(entity.Value, illustrationPointResult.Value, illustrationPointResult.Value.GetAccuracy()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/IllustrationPoints/StochastEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/IllustrationPoints/StochastEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/IllustrationPoints/StochastEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,66 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.TestUtil; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.IllustrationPoints; + +namespace Riskeer.Storage.Core.Test.Read.IllustrationPoints +{ + [TestFixture] + public class StochastEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((StochastEntity) null).Read(); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Read_ValidEntity_ReturnStochast() + { + // Setup + var random = new Random(123); + var entity = new StochastEntity + { + Name = "Description", + Alpha = random.NextDouble(), + Duration = random.NextDouble() + }; + + // Call + Stochast illustrationPointResult = entity.Read(); + + // Assert + Assert.AreEqual(entity.Name, illustrationPointResult.Name); + Assert.AreEqual(entity.Alpha, illustrationPointResult.Alpha, illustrationPointResult.Alpha.GetAccuracy()); + Assert.AreEqual(entity.Duration, illustrationPointResult.Duration, illustrationPointResult.Duration.GetAccuracy()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/IllustrationPoints/SubMechanismIllustrationPointEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/IllustrationPoints/SubMechanismIllustrationPointEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/IllustrationPoints/SubMechanismIllustrationPointEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,181 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.TestUtil; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.IllustrationPoints; + +namespace Riskeer.Storage.Core.Test.Read.IllustrationPoints +{ + [TestFixture] + public class SubMechanismIllustrationPointEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((SubMechanismIllustrationPointEntity) null).Read(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_ValidEntityWithoutStochastsAndIllustrationPointResults_ReturnsSubMechanismIllustrationPoint() + { + // Setup + var random = new Random(21); + var entity = new SubMechanismIllustrationPointEntity + { + Name = "Name", + Beta = random.NextDouble() + }; + + // Call + SubMechanismIllustrationPoint illustrationPoint = entity.Read(); + + // Assert + AssertCommonProperties(entity, illustrationPoint); + + CollectionAssert.IsEmpty(illustrationPoint.IllustrationPointResults); + CollectionAssert.IsEmpty(illustrationPoint.Stochasts); + } + + [Test] + public void Read_ValidEntityWithIllustrationPointResults_ReturnsSubMechanismIllustrationPointWithResults() + { + // Setup + var random = new Random(21); + + var illustrationPointResultEntityOne = new IllustrationPointResultEntity + { + Description = "Description", + Value = random.NextDouble(), + Order = 0 + }; + var illustrationPointResultEntityTwo = new IllustrationPointResultEntity + { + Description = "Description_Two", + Value = random.NextDouble(), + Order = 1 + }; + + var entity = new SubMechanismIllustrationPointEntity + { + Name = "Name", + Beta = random.NextDouble(), + IllustrationPointResultEntities = new[] + { + illustrationPointResultEntityTwo, + illustrationPointResultEntityOne + } + }; + + // Call + SubMechanismIllustrationPoint illustrationPoint = entity.Read(); + + // Assert + AssertCommonProperties(entity, illustrationPoint); + + IllustrationPointResult[] illustrationPointResults = illustrationPoint.IllustrationPointResults.ToArray(); + Assert.AreEqual(2, illustrationPointResults.Length); + AssertReadIllustrationPointResult(illustrationPointResultEntityOne, illustrationPointResults[0]); + AssertReadIllustrationPointResult(illustrationPointResultEntityTwo, illustrationPointResults[1]); + } + + [Test] + public void Read_ValidEntityWithStochasts_ReturnsSubMechanismIllustrationPointWithStochasts() + { + // Setup + var random = new Random(21); + + var stochastEntityOne = new SubMechanismIllustrationPointStochastEntity + { + Name = "Stochast", + Alpha = random.NextDouble(), + Duration = random.NextDouble(), + Realization = random.NextDouble(), + Order = 0 + }; + var stochastEntityTwo = new SubMechanismIllustrationPointStochastEntity + { + Name = "Stochast_Two", + Alpha = random.NextDouble(), + Duration = random.NextDouble(), + Realization = random.NextDouble(), + Order = 1 + }; + + const string illustrationPointName = "Name"; + double beta = random.NextDouble(); + var entity = new SubMechanismIllustrationPointEntity + { + Name = illustrationPointName, + Beta = beta, + SubMechanismIllustrationPointStochastEntities = new[] + { + stochastEntityTwo, + stochastEntityOne + } + }; + + // Call + SubMechanismIllustrationPoint illustrationPoint = entity.Read(); + + // Assert + AssertCommonProperties(entity, illustrationPoint); + + SubMechanismIllustrationPointStochast[] stochasts = illustrationPoint.Stochasts.ToArray(); + Assert.AreEqual(2, stochasts.Length); + AssertReadStochast(stochastEntityOne, stochasts[0]); + AssertReadStochast(stochastEntityTwo, stochasts[1]); + } + + private static void AssertCommonProperties(SubMechanismIllustrationPointEntity expectedEntity, + SubMechanismIllustrationPoint illustrationPoint) + { + Assert.AreEqual(expectedEntity.Name, illustrationPoint.Name); + Assert.AreEqual(expectedEntity.Beta, illustrationPoint.Beta, illustrationPoint.Beta.GetAccuracy()); + } + + private static void AssertReadIllustrationPointResult(IllustrationPointResultEntity illustrationPointResultEntity, + IllustrationPointResult readIllustrationPointResult) + { + Assert.AreEqual(illustrationPointResultEntity.Description, readIllustrationPointResult.Description); + Assert.AreEqual(illustrationPointResultEntity.Value, readIllustrationPointResult.Value, + readIllustrationPointResult.Value.GetAccuracy()); + } + + private static void AssertReadStochast(SubMechanismIllustrationPointStochastEntity stochastEntity, + SubMechanismIllustrationPointStochast 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()); + Assert.AreEqual(stochastEntity.Realization, readStochast.Realization, readStochast.Realization.GetAccuracy()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/IllustrationPoints/SubMechanismIllustrationPointStochastEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/IllustrationPoints/SubMechanismIllustrationPointStochastEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/IllustrationPoints/SubMechanismIllustrationPointStochastEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,68 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.TestUtil; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.IllustrationPoints; + +namespace Riskeer.Storage.Core.Test.Read.IllustrationPoints +{ + [TestFixture] + public class SubMechanismIllustrationPointStochastEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((SubMechanismIllustrationPointStochastEntity) null).Read(); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Read_ValidEntity_ReturnRealizedStochast() + { + // Setup + var random = new Random(123); + var entity = new SubMechanismIllustrationPointStochastEntity + { + Name = "Description", + Alpha = random.NextDouble(), + Duration = random.NextDouble(), + Realization = random.NextDouble() + }; + + // Call + SubMechanismIllustrationPointStochast illustrationPointResult = entity.Read(); + + // Assert + Assert.AreEqual(entity.Name, illustrationPointResult.Name); + Assert.AreEqual(entity.Alpha, illustrationPointResult.Alpha, illustrationPointResult.Alpha.GetAccuracy()); + Assert.AreEqual(entity.Duration, illustrationPointResult.Duration, illustrationPointResult.Duration.GetAccuracy()); + Assert.AreEqual(entity.Realization, illustrationPointResult.Realization, illustrationPointResult.Realization.GetAccuracy()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/IllustrationPoints/TopLevelFaultTreeIllustrationPointEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/IllustrationPoints/TopLevelFaultTreeIllustrationPointEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/IllustrationPoints/TopLevelFaultTreeIllustrationPointEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,90 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.TestUtil; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.IllustrationPoints; + +namespace Riskeer.Storage.Core.Test.Read.IllustrationPoints +{ + [TestFixture] + public class TopLevelFaultTreeIllustrationPointEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((TopLevelFaultTreeIllustrationPointEntity) null).Read(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_ValidEntity_ReturnsTopLevelFaultTreeIllustrationPoint() + { + // Setup + var random = new Random(21); + + var combinationType = random.NextEnumValue(); + var illustrationPointEntity = new FaultTreeIllustrationPointEntity + { + Name = "Illustration point name", + Beta = random.NextDouble(), + CombinationType = Convert.ToByte(combinationType) + }; + + var entity = new TopLevelFaultTreeIllustrationPointEntity + { + ClosingSituation = "closingSituation", + WindDirectionName = "WindDirectionName", + WindDirectionAngle = random.NextDouble(), + FaultTreeIllustrationPointEntity = illustrationPointEntity + }; + + // Call + TopLevelFaultTreeIllustrationPoint topLevelIllustrationPoint = entity.Read(); + + // Assert + Assert.AreEqual(entity.ClosingSituation, topLevelIllustrationPoint.ClosingSituation); + + WindDirection actualWindDirection = topLevelIllustrationPoint.WindDirection; + Assert.AreEqual(entity.WindDirectionName, actualWindDirection.Name); + Assert.AreEqual(entity.WindDirectionAngle, actualWindDirection.Angle, + actualWindDirection.Angle.GetAccuracy()); + + IllustrationPointNode rootNode = topLevelIllustrationPoint.FaultTreeNodeRoot; + var illustrationPoint = rootNode.Data as FaultTreeIllustrationPoint; + Assert.IsNotNull(illustrationPoint); + Assert.AreEqual(illustrationPointEntity.Beta, illustrationPoint.Beta, illustrationPoint.Beta.GetAccuracy()); + Assert.AreEqual(illustrationPointEntity.Name, illustrationPoint.Name); + Assert.AreEqual(combinationType, illustrationPoint.CombinationType); + + CollectionAssert.IsEmpty(illustrationPoint.Stochasts); + CollectionAssert.IsEmpty(rootNode.Children); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/IllustrationPoints/TopLevelSubMechanismIllustrationPointReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/IllustrationPoints/TopLevelSubMechanismIllustrationPointReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/IllustrationPoints/TopLevelSubMechanismIllustrationPointReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,84 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.TestUtil; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.IllustrationPoints; + +namespace Riskeer.Storage.Core.Test.Read.IllustrationPoints +{ + [TestFixture] + public class TopLevelSubMechanismIllustrationPointReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((TopLevelSubMechanismIllustrationPointEntity) null).Read(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_ValidEntity_ReturnsTopLevelSubMechanismIllustrationPoint() + { + // Setup + var random = new Random(21); + + var subMechanismIllustrationPointEntity = new SubMechanismIllustrationPointEntity + { + Name = "Illustration point name", + Beta = random.NextDouble() + }; + + var entity = new TopLevelSubMechanismIllustrationPointEntity + { + ClosingSituation = "closingSituation", + WindDirectionName = "WindDirectionName", + WindDirectionAngle = random.NextDouble(), + SubMechanismIllustrationPointEntity = subMechanismIllustrationPointEntity + }; + + // Call + TopLevelSubMechanismIllustrationPoint topLevelSubMechanismIllustrationPoint = entity.Read(); + + // Assert + Assert.AreEqual(entity.ClosingSituation, topLevelSubMechanismIllustrationPoint.ClosingSituation); + + WindDirection actualWindDirection = topLevelSubMechanismIllustrationPoint.WindDirection; + Assert.AreEqual(entity.WindDirectionName, actualWindDirection.Name); + Assert.AreEqual(entity.WindDirectionAngle, actualWindDirection.Angle, + actualWindDirection.Angle.GetAccuracy()); + + SubMechanismIllustrationPoint actualIllustrationPoint = topLevelSubMechanismIllustrationPoint.SubMechanismIllustrationPoint; + Assert.AreEqual(subMechanismIllustrationPointEntity.Name, actualIllustrationPoint.Name); + Assert.AreEqual(subMechanismIllustrationPointEntity.Beta, actualIllustrationPoint.Beta, + actualIllustrationPoint.Beta.GetAccuracy()); + CollectionAssert.IsEmpty(actualIllustrationPoint.Stochasts); + CollectionAssert.IsEmpty(actualIllustrationPoint.IllustrationPointResults); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsCalculationEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsCalculationEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsCalculationEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,281 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Data; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.MacroStabilityInwards.Data.SoilProfile; +using Ringtoets.MacroStabilityInwards.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Data.TestUtil.SoilProfile; +using Ringtoets.MacroStabilityInwards.Primitives; +using Ringtoets.Storage.Core.TestUtil.MacroStabilityInwards; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Read.MacroStabilityInwards; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Read.MacroStabilityInwards +{ + [TestFixture] + public class MacroStabilityInwardsCalculationEntityReadExtensionsTest + { + [Test] + public void Read_CollectorNull_ThrowsArgumentNullException() + { + // Setup + MacroStabilityInwardsCalculationEntity entity = CreateValidCalculationEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("collector", exception.ParamName); + } + + [Test] + public void Read_EntityWithValidValues_ReturnsCalculationScenarioWithExpectedValues() + { + // Setup + var random = new Random(21); + var entity = new MacroStabilityInwardsCalculationEntity + { + Name = "Calculation name", + Comment = "Comment here", + AssessmentLevel = random.NextDouble(), + UseAssessmentLevelManualInput = Convert.ToByte(random.NextBoolean()), + ScenarioContribution = random.NextDouble(), + RelevantForScenario = Convert.ToByte(random.NextBoolean()), + SlipPlaneMinimumDepth = random.NextDouble(), + SlipPlaneMinimumLength = random.NextDouble(), + MaximumSliceWidth = random.NextDouble(), + MoveGrid = Convert.ToByte(random.NextBoolean()), + DikeSoilScenario = Convert.ToByte(random.NextEnumValue()), + WaterLevelRiverAverage = random.NextDouble(), + DrainageConstructionPresent = Convert.ToByte(random.NextBoolean()), + DrainageConstructionCoordinateX = random.NextDouble(), + DrainageConstructionCoordinateZ = random.NextDouble(), + MinimumLevelPhreaticLineAtDikeTopRiver = random.NextDouble(), + MinimumLevelPhreaticLineAtDikeTopPolder = random.NextDouble(), + LocationInputExtremeWaterLevelPolder = random.NextDouble(), + LocationInputExtremeUseDefaultOffsets = Convert.ToByte(random.NextBoolean()), + LocationInputExtremePhreaticLineOffsetBelowDikeTopAtRiver = random.NextDouble(), + LocationInputExtremePhreaticLineOffsetBelowDikeTopAtPolder = random.NextDouble(), + LocationInputExtremePhreaticLineOffsetBelowShoulderBaseInside = random.NextDouble(), + LocationInputExtremePhreaticLineOffsetDikeToeAtPolder = random.NextDouble(), + LocationInputExtremePenetrationLength = random.NextDouble(), + LocationInputDailyWaterLevelPolder = random.NextDouble(), + LocationInputDailyUseDefaultOffsets = Convert.ToByte(random.NextBoolean()), + LocationInputDailyPhreaticLineOffsetBelowDikeTopAtRiver = random.NextDouble(), + LocationInputDailyPhreaticLineOffsetBelowDikeTopAtPolder = random.NextDouble(), + LocationInputDailyPhreaticLineOffsetBelowShoulderBaseInside = random.NextDouble(), + LocationInputDailyPhreaticLineOffsetDikeToeAtPolder = random.NextDouble(), + AdjustPhreaticLine3And4ForUplift = Convert.ToByte(random.NextBoolean()), + LeakageLengthOutwardsPhreaticLine4 = random.NextDouble(), + LeakageLengthInwardsPhreaticLine4 = random.NextDouble(), + LeakageLengthOutwardsPhreaticLine3 = random.NextDouble(), + LeakageLengthInwardsPhreaticLine3 = random.NextDouble(), + PiezometricHeadPhreaticLine2Outwards = random.NextDouble(), + PiezometricHeadPhreaticLine2Inwards = random.NextDouble(), + GridDeterminationType = Convert.ToByte(random.NextEnumValue()), + TangentLineDeterminationType = Convert.ToByte(random.NextEnumValue()), + TangentLineZTop = random.NextDouble(2.0, 3.0), + TangentLineZBottom = random.NextDouble(0.0, 1.0), + TangentLineNumber = random.Next(1, 50), + LeftGridXLeft = random.NextDouble(0.0, 1.0), + LeftGridXRight = random.NextDouble(2.0, 3.0), + LeftGridNrOfHorizontalPoints = random.Next(1, 100), + LeftGridZTop = random.NextDouble(2.0, 3.0), + LeftGridZBottom = random.NextDouble(0.0, 1.0), + LeftGridNrOfVerticalPoints = random.Next(1, 100), + RightGridXLeft = random.NextDouble(0.0, 1.0), + RightGridXRight = random.NextDouble(2.0, 3.0), + RightGridNrOfHorizontalPoints = random.Next(1, 100), + RightGridZTop = random.NextDouble(2.0, 3.0), + RightGridZBottom = random.NextDouble(0.0, 1.0), + RightGridNrOfVerticalPoints = random.Next(1, 100), + CreateZones = Convert.ToByte(random.NextBoolean()), + ZoningBoundariesDeterminationType = Convert.ToByte(random.NextEnumValue()), + ZoneBoundaryLeft = random.NextDouble(), + ZoneBoundaryRight = random.NextDouble() + }; + + var collector = new ReadConversionCollector(); + + // Call + MacroStabilityInwardsCalculationScenario calculation = entity.Read(collector); + + // Assert + Assert.IsNull(calculation.Output); + Assert.AreEqual(entity.Name, calculation.Name); + Assert.AreEqual(entity.Comment, calculation.Comments.Body); + + MacroStabilityInwardsInput inputParameters = calculation.InputParameters; + Assert.IsNull(inputParameters.StochasticSoilModel); + Assert.IsNull(inputParameters.StochasticSoilProfile); + Assert.IsNull(inputParameters.SurfaceLine); + + MacroStabilityInwardsCalculationEntityTestHelper.AssertCalculationScenarioPropertyValues(calculation, entity); + } + + [Test] + public void Read_EntityWithNullValues_ReturnsCalculationScenarioWithNaNValues() + { + // Setup + MacroStabilityInwardsCalculationEntity entity = CreateValidCalculationEntity(); + var collector = new ReadConversionCollector(); + + // Call + MacroStabilityInwardsCalculationScenario calculation = entity.Read(collector); + + // Assert + Assert.IsNull(calculation.Output); + Assert.IsNull(calculation.Comments.Body); + + MacroStabilityInwardsInput inputParameters = calculation.InputParameters; + Assert.IsNull(inputParameters.StochasticSoilModel); + Assert.IsNull(inputParameters.StochasticSoilProfile); + Assert.IsNull(inputParameters.SurfaceLine); + + MacroStabilityInwardsCalculationEntityTestHelper.AssertCalculationScenarioPropertyValues(calculation, entity); + } + + [Test] + public void Read_EntityWithHydraulicBoundaryLocationEntity_ReturnsCalculationScenarioWithInputObjectWithLocationSet() + { + // Setup + var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + var hydraulicLocationEntity = new HydraulicLocationEntity(); + + var collector = new ReadConversionCollector(); + collector.Read(hydraulicLocationEntity, hydraulicBoundaryLocation); + + MacroStabilityInwardsCalculationEntity entity = CreateValidCalculationEntity(); + entity.HydraulicLocationEntity = hydraulicLocationEntity; + + // Call + MacroStabilityInwardsCalculationScenario calculation = entity.Read(collector); + + // Assert + Assert.AreSame(hydraulicBoundaryLocation, calculation.InputParameters.HydraulicBoundaryLocation); + } + + [Test] + public void Read_EntityWithSurfaceLineEntity_ReturnsCalculationScenarioWithInputObjectWithSurfaceLineSet() + { + // Setup + var surfaceLine = new MacroStabilityInwardsSurfaceLine(string.Empty); + var surfaceLineEntity = new SurfaceLineEntity(); + + var collector = new ReadConversionCollector(); + collector.Read(surfaceLineEntity, surfaceLine); + + MacroStabilityInwardsCalculationEntity entity = CreateValidCalculationEntity(); + entity.SurfaceLineEntity = surfaceLineEntity; + + // Call + MacroStabilityInwardsCalculationScenario calculation = entity.Read(collector); + + // Assert + Assert.AreSame(surfaceLine, calculation.InputParameters.SurfaceLine); + } + + [Test] + public void Read_EntityWithStochasticSoilModel_ReturnCalculationScenarioWithInputObjectWithStochasticSoilModelPropertiesSet() + { + // Setup + var random = new Random(21); + MacroStabilityInwardsStochasticSoilModel stochasticSoilModel = + MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel(); + var stochasticSoilModelEntity = new StochasticSoilModelEntity(); + + var stochasticSoilProfile = new MacroStabilityInwardsStochasticSoilProfile(random.NextDouble(), + MacroStabilityInwardsSoilProfile1DTestFactory.CreateMacroStabilityInwardsSoilProfile1D()); + var stochasticSoilProfileEntity = new MacroStabilityInwardsStochasticSoilProfileEntity + { + StochasticSoilModelEntity = stochasticSoilModelEntity + }; + + var collector = new ReadConversionCollector(); + collector.Read(stochasticSoilModelEntity, stochasticSoilModel); + collector.Read(stochasticSoilProfileEntity, stochasticSoilProfile); + + MacroStabilityInwardsCalculationEntity entity = CreateValidCalculationEntity(); + entity.MacroStabilityInwardsStochasticSoilProfileEntity = stochasticSoilProfileEntity; + + // Call + MacroStabilityInwardsCalculationScenario calculation = entity.Read(collector); + + // Assert + MacroStabilityInwardsInput inputParameters = calculation.InputParameters; + Assert.AreSame(stochasticSoilModel, inputParameters.StochasticSoilModel); + Assert.AreSame(stochasticSoilProfile, inputParameters.StochasticSoilProfile); + } + + [Test] + public void Read_EntityWithOutput_ReturnsCalculationScenarioWithOutput() + { + // Setup + var random = new Random(31); + var tangentLines = new RoundedDouble[0]; + var slices = new MacroStabilityInwardsSlice[0]; + + var calculationOutputEntity = new MacroStabilityInwardsCalculationOutputEntity + { + SlipPlaneTangentLinesXml = new TangentLineCollectionXmlSerializer().ToXml(tangentLines), + SlidingCurveSliceXML = new MacroStabilityInwardsSliceCollectionXmlSerializer().ToXml(slices), + SlipPlaneLeftGridNrOfHorizontalPoints = random.Next(1, 100), + SlipPlaneLeftGridNrOfVerticalPoints = random.Next(1, 100), + SlipPlaneRightGridNrOfHorizontalPoints = random.Next(1, 100), + SlipPlaneRightGridNrOfVerticalPoints = random.Next(1, 100) + }; + + MacroStabilityInwardsCalculationEntity entity = CreateValidCalculationEntity(); + entity.MacroStabilityInwardsCalculationOutputEntities.Add(calculationOutputEntity); + + var collector = new ReadConversionCollector(); + + // Call + MacroStabilityInwardsCalculationScenario calculation = entity.Read(collector); + + // Assert + MacroStabilityInwardsOutput output = calculation.Output; + Assert.IsNotNull(output); + MacroStabilityInwardsCalculationOutputEntityTestHelper.AssertOutputPropertyValues(output, calculationOutputEntity); + } + + private static MacroStabilityInwardsCalculationEntity CreateValidCalculationEntity() + { + var random = new Random(21); + return new MacroStabilityInwardsCalculationEntity + { + TangentLineNumber = 1, + LeftGridNrOfHorizontalPoints = random.Next(1, 100), + LeftGridNrOfVerticalPoints = random.Next(1, 100), + RightGridNrOfHorizontalPoints = random.Next(1, 100), + RightGridNrOfVerticalPoints = random.Next(1, 100) + }; + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsCalculationOutputEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsCalculationOutputEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsCalculationOutputEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,168 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Data; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.MacroStabilityInwards.Data.TestUtil; +using Ringtoets.Storage.Core.TestUtil.MacroStabilityInwards; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.MacroStabilityInwards; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Read.MacroStabilityInwards +{ + [TestFixture] + public class MacroStabilityInwardsCalculationOutputEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((MacroStabilityInwardsCalculationOutputEntity) null).Read(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_EntityWithValues_ReturnExpectedOutput() + { + // Setup + var random = new Random(21); + IEnumerable slices = new[] + { + MacroStabilityInwardsSliceTestFactory.CreateSlice() + }; + IEnumerable tangentLines = new[] + { + new RoundedDouble(2, random.NextDouble()) + }; + + var entity = new MacroStabilityInwardsCalculationOutputEntity + { + FactorOfStability = random.NextDouble(), + ZValue = random.NextDouble(), + ForbiddenZonesXEntryMin = random.NextDouble(), + ForbiddenZonesXEntryMax = random.NextDouble(), + SlidingCurveSliceXML = new MacroStabilityInwardsSliceCollectionXmlSerializer().ToXml(slices), + SlidingCurveNonIteratedHorizontalForce = random.NextDouble(), + SlidingCurveIteratedHorizontalForce = random.NextDouble(), + SlidingCurveLeftSlidingCircleCenterX = random.NextDouble(), + SlidingCurveLeftSlidingCircleCenterY = random.NextDouble(), + SlidingCurveLeftSlidingCircleRadius = random.NextDouble(), + SlidingCurveLeftSlidingCircleIsActive = Convert.ToByte(random.NextBoolean()), + SlidingCurveLeftSlidingCircleNonIteratedForce = random.NextDouble(), + SlidingCurveLeftSlidingCircleIteratedForce = random.NextDouble(), + SlidingCurveLeftSlidingCircleDrivingMoment = random.NextDouble(), + SlidingCurveLeftSlidingCircleResistingMoment = random.NextDouble(), + SlidingCurveRightSlidingCircleCenterX = random.NextDouble(), + SlidingCurveRightSlidingCircleCenterY = random.NextDouble(), + SlidingCurveRightSlidingCircleRadius = random.NextDouble(), + SlidingCurveRightSlidingCircleIsActive = Convert.ToByte(random.NextBoolean()), + SlidingCurveRightSlidingCircleNonIteratedForce = random.NextDouble(), + SlidingCurveRightSlidingCircleIteratedForce = random.NextDouble(), + SlidingCurveRightSlidingCircleDrivingMoment = random.NextDouble(), + SlidingCurveRightSlidingCircleResistingMoment = random.NextDouble(), + SlipPlaneTangentLinesXml = new TangentLineCollectionXmlSerializer().ToXml(tangentLines), + SlipPlaneLeftGridXLeft = random.NextDouble(0.0, 1.0), + SlipPlaneLeftGridXRight = random.NextDouble(2.0, 3.0), + SlipPlaneLeftGridNrOfHorizontalPoints = random.Next(1, 100), + SlipPlaneLeftGridZTop = random.NextDouble(2.0, 3.0), + SlipPlaneLeftGridZBottom = random.NextDouble(0.0, 1.0), + SlipPlaneLeftGridNrOfVerticalPoints = random.Next(1, 100), + SlipPlaneRightGridXLeft = random.NextDouble(0.0, 1.0), + SlipPlaneRightGridXRight = random.NextDouble(2.0, 3.0), + SlipPlaneRightGridNrOfHorizontalPoints = random.Next(1, 100), + SlipPlaneRightGridZTop = random.NextDouble(2.0, 3.0), + SlipPlaneRightGridZBottom = random.NextDouble(0.0, 1.0), + SlipPlaneRightGridNrOfVerticalPoints = random.Next(1, 100) + }; + + // Call + MacroStabilityInwardsOutput output = entity.Read(); + + // Assert + MacroStabilityInwardsCalculationOutputEntityTestHelper.AssertOutputPropertyValues(output, entity); + } + + [Test] + public void Read_EntityWithNullValues_ReturnExpectedOutputWithNaNValues() + { + // Setup + MacroStabilityInwardsCalculationOutputEntity entity = CreateValidCalculationOutputEntity(); + + // Call + MacroStabilityInwardsOutput output = entity.Read(); + + // Assert + MacroStabilityInwardsCalculationOutputEntityTestHelper.AssertOutputPropertyValues(output, entity); + } + + [Test] + public void Read_SlipPlaneTangentLineXMLEmpty_ThrowsArgumentException() + { + // Setup + MacroStabilityInwardsCalculationOutputEntity entity = CreateValidCalculationOutputEntity(); + entity.SlipPlaneTangentLinesXml = string.Empty; + + // Call + TestDelegate call = () => entity.Read(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("xml", exception.ParamName); + } + + [Test] + public void Read_SlidingCurveSliceXMLEmpty_ThrowsArgumentException() + { + // Setup + MacroStabilityInwardsCalculationOutputEntity entity = CreateValidCalculationOutputEntity(); + entity.SlidingCurveSliceXML = string.Empty; + + // Call + TestDelegate call = () => entity.Read(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("xml", exception.ParamName); + } + + private static MacroStabilityInwardsCalculationOutputEntity CreateValidCalculationOutputEntity() + { + var random = new Random(31); + return new MacroStabilityInwardsCalculationOutputEntity + { + SlidingCurveSliceXML = new MacroStabilityInwardsSliceCollectionXmlSerializer().ToXml(new MacroStabilityInwardsSlice[0]), + SlipPlaneTangentLinesXml = new TangentLineCollectionXmlSerializer().ToXml(new RoundedDouble[0]), + SlipPlaneLeftGridNrOfHorizontalPoints = random.Next(1, 100), + SlipPlaneLeftGridNrOfVerticalPoints = random.Next(1, 100), + SlipPlaneRightGridNrOfHorizontalPoints = random.Next(1, 100), + SlipPlaneRightGridNrOfVerticalPoints = random.Next(1, 100) + }; + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsFailureMechanismMetaEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsFailureMechanismMetaEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsFailureMechanismMetaEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,78 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.MacroStabilityInwards.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.MacroStabilityInwards; + +namespace Riskeer.Storage.Core.Test.Read.MacroStabilityInwards +{ + [TestFixture] + public class MacroStabilityInwardsFailureMechanismMetaEntityReadExtensionsTest + { + [Test] + public void ReadProbabilityAssessmentInput_EntityNull_ThrowsArgumentNullException() + { + // Setup + var input = new MacroStabilityInwardsProbabilityAssessmentInput(); + + // Call + TestDelegate test = () => ((MacroStabilityInwardsFailureMechanismMetaEntity) null).ReadProbabilityAssessmentInput(input); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void ReadProbabilityAssessmentInput_ProbabilityAssessmentInputNull_ThrowsArgumentNullException() + { + // Setup + var entity = new MacroStabilityInwardsFailureMechanismMetaEntity(); + + // Call + TestDelegate test = () => entity.ReadProbabilityAssessmentInput(null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("probabilityAssessmentInput", exception.ParamName); + } + + [Test] + public void ReadProbabilityAssessmentInput_ValidParameters_SetMacroStabilityInwardsProbabilityAssessmentInputProperties() + { + // Setup + var inputToUpdate = new MacroStabilityInwardsProbabilityAssessmentInput(); + var entity = new MacroStabilityInwardsFailureMechanismMetaEntity + { + A = new Random(31).NextDouble() + }; + + // Call + entity.ReadProbabilityAssessmentInput(inputToUpdate); + + // Assert + Assert.AreEqual(entity.A, inputToUpdate.A); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsPreconsolidationStressEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsPreconsolidationStressEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsPreconsolidationStressEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,101 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Data; +using NUnit.Framework; +using Ringtoets.Common.Data.Probabilistics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Data.SoilProfile; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.MacroStabilityInwards; + +namespace Riskeer.Storage.Core.Test.Read.MacroStabilityInwards +{ + [TestFixture] + public class MacroStabilityInwardsPreconsolidationStressEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => ((MacroStabilityInwardsPreconsolidationStressEntity) null).Read(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_WithValues_ReturnsExpectedMacroStabilityInwardsPreconsolidationStress() + { + // Setup + var random = new Random(31); + var entity = new MacroStabilityInwardsPreconsolidationStressEntity + { + CoordinateX = random.NextDouble(), + CoordinateZ = random.NextDouble(), + PreconsolidationStressMean = random.NextDouble(), + PreconsolidationStressCoefficientOfVariation = random.NextDouble() + }; + + // Call + MacroStabilityInwardsPreconsolidationStress stress = entity.Read(); + + // Assert + Assert.IsNotNull(stress); + Assert.AreEqual(entity.CoordinateX, stress.Location.X); + Assert.AreEqual(entity.CoordinateZ, stress.Location.Y); + + VariationCoefficientLogNormalDistribution preconsolidationStressDistribution = stress.Stress; + AssertAreEqual(entity.PreconsolidationStressMean, preconsolidationStressDistribution.Mean); + AssertAreEqual(entity.PreconsolidationStressCoefficientOfVariation, preconsolidationStressDistribution.CoefficientOfVariation); + } + + [Test] + public void Read_WithNullValues_ReturnsExpectedMacroStabilityInwardsPreconsolidationStress() + { + // Setup + var random = new Random(31); + var entity = new MacroStabilityInwardsPreconsolidationStressEntity + { + CoordinateX = random.NextDouble(), + CoordinateZ = random.NextDouble() + }; + + // Call + MacroStabilityInwardsPreconsolidationStress stress = entity.Read(); + + // Assert + Assert.IsNotNull(stress); + + VariationCoefficientLogNormalDistribution preconsolidationStressDistribution = stress.Stress; + Assert.IsNaN(preconsolidationStressDistribution.Mean); + Assert.IsNaN(preconsolidationStressDistribution.CoefficientOfVariation); + } + + private static void AssertAreEqual(double? expectedValue, RoundedDouble actualValue) + { + Assert.IsTrue(expectedValue.HasValue); + Assert.AreEqual(expectedValue.Value, actualValue, actualValue.GetAccuracy()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsSectionResultEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsSectionResultEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsSectionResultEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,114 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.MacroStabilityInwards.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.MacroStabilityInwards; + +namespace Riskeer.Storage.Core.Test.Read.MacroStabilityInwards +{ + [TestFixture] + public class MacroStabilityInwardsSectionResultEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Setup + var sectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + TestDelegate test = () => ((MacroStabilityInwardsSectionResultEntity) null).Read(sectionResult); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_SectionResultNull_ThrowsArgumentNullException() + { + // Setup + var entity = new MacroStabilityInwardsSectionResultEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("sectionResult", paramName); + } + + [Test] + public void Read_ParameterValues_SetsSectionResultWithParameterValues() + { + // Setup + var random = new Random(31); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResult = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + double tailorMadeAssessmentProbability = random.NextDouble(); + bool useManualAssembly = random.NextBoolean(); + double manualAssemblyProbability = random.NextDouble(); + + var entity = new MacroStabilityInwardsSectionResultEntity + { + SimpleAssessmentResult = Convert.ToByte(simpleAssessmentResult), + DetailedAssessmentResult = Convert.ToByte(detailedAssessmentResult), + TailorMadeAssessmentResult = Convert.ToByte(tailorMadeAssessmentResult), + TailorMadeAssessmentProbability = tailorMadeAssessmentProbability, + UseManualAssembly = Convert.ToByte(useManualAssembly), + ManualAssemblyProbability = manualAssemblyProbability + }; + var sectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult); + + // Assert + Assert.AreEqual(simpleAssessmentResult, sectionResult.SimpleAssessmentResult); + Assert.AreEqual(detailedAssessmentResult, sectionResult.DetailedAssessmentResult); + Assert.AreEqual(tailorMadeAssessmentResult, sectionResult.TailorMadeAssessmentResult); + Assert.AreEqual(tailorMadeAssessmentProbability, sectionResult.TailorMadeAssessmentProbability, 1e-6); + Assert.AreEqual(useManualAssembly, sectionResult.UseManualAssembly); + Assert.AreEqual(manualAssemblyProbability, sectionResult.ManualAssemblyProbability, 1e-6); + } + + [Test] + public void Read_EntityWithNullValues_SetsSectionResultWithNaNValues() + { + // Setup + var entity = new MacroStabilityInwardsSectionResultEntity(); + var sectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult); + + // Assert + Assert.IsNaN(sectionResult.TailorMadeAssessmentProbability); + Assert.IsNaN(sectionResult.ManualAssemblyProbability); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsSoilLayerOneDEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsSoilLayerOneDEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsSoilLayerOneDEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,191 @@ +// Copyright (C) Stichting Deltares 2018. 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.Drawing; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Data.SoilProfile; +using Ringtoets.MacroStabilityInwards.Primitives; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.MacroStabilityInwards; + +namespace Riskeer.Storage.Core.Test.Read.MacroStabilityInwards +{ + [TestFixture] + public class MacroStabilityInwardsSoilLayerOneDEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => ((MacroStabilityInwardsSoilLayerOneDEntity) null).Read(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_WithValues_ReturnsMacroStabilityInwardsSoilLayer1DWithDoubleParameterValues() + { + // Setup + var random = new Random(31); + double top = random.NextDouble(); + Color color = Color.FromKnownColor(random.NextEnumValue()); + bool isAquifer = random.NextBoolean(); + const double abovePhreaticLevelMean = 0.3; + const double abovePhreaticLevelCoefficientOfVariation = 0.2; + const double abovePhreaticLevelShift = 0.1; + const double belowPhreaticLevelMean = 0.6; + const double belowPhreaticLevelCoefficientOfVariation = 0.5; + const double belowPhreaticLevelShift = 0.4; + double cohesionMean = random.NextDouble(); + double cohesionCoefficientOfVariation = random.NextDouble(); + double frictionAngleMean = random.NextDouble(); + double frictionAngleCoefficientOfVariation = random.NextDouble(); + double shearStrengthRatioMean = random.NextDouble(); + double shearStrengthRatioCoefficientOfVariation = random.NextDouble(); + double strengthIncreaseExponentMean = random.NextDouble(); + double strengthIncreaseExponentCoefficientOfVariation = random.NextDouble(); + double popMean = random.NextDouble(); + double popCoefficientOfVariation = random.NextDouble(); + + var entity = new MacroStabilityInwardsSoilLayerOneDEntity + { + Top = top, + IsAquifer = Convert.ToByte(isAquifer), + Color = color.ToInt64(), + MaterialName = random.Next().ToString(), + AbovePhreaticLevelMean = abovePhreaticLevelMean, + AbovePhreaticLevelCoefficientOfVariation = abovePhreaticLevelCoefficientOfVariation, + AbovePhreaticLevelShift = abovePhreaticLevelShift, + BelowPhreaticLevelMean = belowPhreaticLevelMean, + BelowPhreaticLevelCoefficientOfVariation = belowPhreaticLevelCoefficientOfVariation, + BelowPhreaticLevelShift = belowPhreaticLevelShift, + CohesionMean = cohesionMean, + CohesionCoefficientOfVariation = cohesionCoefficientOfVariation, + FrictionAngleMean = frictionAngleMean, + FrictionAngleCoefficientOfVariation = frictionAngleCoefficientOfVariation, + ShearStrengthRatioMean = shearStrengthRatioMean, + ShearStrengthRatioCoefficientOfVariation = shearStrengthRatioCoefficientOfVariation, + StrengthIncreaseExponentMean = strengthIncreaseExponentMean, + StrengthIncreaseExponentCoefficientOfVariation = strengthIncreaseExponentCoefficientOfVariation, + PopMean = popMean, + PopCoefficientOfVariation = popCoefficientOfVariation + }; + + // Call + MacroStabilityInwardsSoilLayer1D layer = entity.Read(); + + // Assert + Assert.IsNotNull(layer); + Assert.AreEqual(top, layer.Top); + MacroStabilityInwardsSoilLayerData data = layer.Data; + Assert.AreEqual(isAquifer, data.IsAquifer); + Assert.IsNotNull(color); + Assert.AreEqual(color.ToArgb(), data.Color.ToArgb()); + Assert.AreEqual(entity.MaterialName, data.MaterialName); + + Assert.AreEqual(abovePhreaticLevelMean, data.AbovePhreaticLevel.Mean, + data.AbovePhreaticLevel.GetAccuracy()); + Assert.AreEqual(abovePhreaticLevelCoefficientOfVariation, data.AbovePhreaticLevel.CoefficientOfVariation, + data.AbovePhreaticLevel.GetAccuracy()); + Assert.AreEqual(abovePhreaticLevelShift, data.AbovePhreaticLevel.Shift, + data.AbovePhreaticLevel.GetAccuracy()); + + Assert.AreEqual(belowPhreaticLevelMean, data.BelowPhreaticLevel.Mean, + data.BelowPhreaticLevel.GetAccuracy()); + Assert.AreEqual(belowPhreaticLevelCoefficientOfVariation, data.BelowPhreaticLevel.CoefficientOfVariation, + data.BelowPhreaticLevel.GetAccuracy()); + Assert.AreEqual(belowPhreaticLevelShift, data.BelowPhreaticLevel.Shift, + data.BelowPhreaticLevel.GetAccuracy()); + + Assert.AreEqual(cohesionMean, data.Cohesion.Mean, + data.Cohesion.GetAccuracy()); + Assert.AreEqual(cohesionCoefficientOfVariation, data.Cohesion.CoefficientOfVariation, + data.Cohesion.GetAccuracy()); + + Assert.AreEqual(frictionAngleMean, data.FrictionAngle.Mean, + data.FrictionAngle.GetAccuracy()); + Assert.AreEqual(frictionAngleCoefficientOfVariation, data.FrictionAngle.CoefficientOfVariation, + data.FrictionAngle.GetAccuracy()); + + Assert.AreEqual(shearStrengthRatioMean, data.ShearStrengthRatio.Mean, + data.ShearStrengthRatio.GetAccuracy()); + Assert.AreEqual(shearStrengthRatioCoefficientOfVariation, data.ShearStrengthRatio.CoefficientOfVariation, + data.ShearStrengthRatio.GetAccuracy()); + + Assert.AreEqual(strengthIncreaseExponentMean, data.StrengthIncreaseExponent.Mean, + data.StrengthIncreaseExponent.GetAccuracy()); + Assert.AreEqual(strengthIncreaseExponentCoefficientOfVariation, data.StrengthIncreaseExponent.CoefficientOfVariation, + data.StrengthIncreaseExponent.GetAccuracy()); + + Assert.AreEqual(popMean, data.Pop.Mean, data.Pop.GetAccuracy()); + Assert.AreEqual(popCoefficientOfVariation, data.Pop.CoefficientOfVariation, + data.Pop.GetAccuracy()); + } + + [Test] + public void Read_WithNullValues_ReturnsMacroStabilityInwardsSoilLayer1DWithNaNValues() + { + // Setup + var entity = new MacroStabilityInwardsSoilLayerOneDEntity + { + MaterialName = nameof(MacroStabilityInwardsSoilLayerOneDEntity) + }; + + // Call + MacroStabilityInwardsSoilLayer1D layer = entity.Read(); + + // Assert + Assert.IsNotNull(layer); + MacroStabilityInwardsSoilLayerData data = layer.Data; + Assert.AreEqual(entity.MaterialName, data.MaterialName); + + Assert.IsNaN(layer.Top); + + Assert.IsNaN(data.AbovePhreaticLevel.Mean); + Assert.IsNaN(data.AbovePhreaticLevel.CoefficientOfVariation); + Assert.IsNaN(data.AbovePhreaticLevel.Shift); + + Assert.IsNaN(data.BelowPhreaticLevel.Mean); + Assert.IsNaN(data.BelowPhreaticLevel.CoefficientOfVariation); + Assert.IsNaN(data.BelowPhreaticLevel.Shift); + + Assert.IsNaN(data.Cohesion.Mean); + Assert.IsNaN(data.Cohesion.CoefficientOfVariation); + + Assert.IsNaN(data.FrictionAngle.Mean); + Assert.IsNaN(data.FrictionAngle.CoefficientOfVariation); + + Assert.IsNaN(data.ShearStrengthRatio.Mean); + Assert.IsNaN(data.ShearStrengthRatio.CoefficientOfVariation); + + Assert.IsNaN(data.StrengthIncreaseExponent.Mean); + Assert.IsNaN(data.StrengthIncreaseExponent.CoefficientOfVariation); + + Assert.IsNaN(data.Pop.Mean); + Assert.IsNaN(data.Pop.CoefficientOfVariation); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsSoilLayerTwoDEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsSoilLayerTwoDEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsSoilLayerTwoDEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,212 @@ +// Copyright (C) Stichting Deltares 2018. 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.Drawing; +using System.Linq; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Primitives; +using Ringtoets.MacroStabilityInwards.Primitives.TestUtil; +using Ringtoets.Storage.Core.TestUtil.MacroStabilityInwards; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.MacroStabilityInwards; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Read.MacroStabilityInwards +{ + [TestFixture] + public class MacroStabilityInwardsSoilLayerTwoDEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => ((MacroStabilityInwardsSoilLayerTwoDEntity) null).Read(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_WithValues_ReturnsMacroStabilityInwardsSoilLayer2DWithDoubleParameterValues() + { + // Setup + MacroStabilityInwardsSoilLayerTwoDEntity entity = CreateMacroStabilityInwardsSoilLayerTwoDEntity(); + + // Call + MacroStabilityInwardsSoilLayer2D layer = entity.Read(); + + // Assert + AssertMacroStabilityInwardsSoilLayer2D(entity, layer); + } + + [Test] + public void Read_WithNestedLayers_ReturnsMacroStabilityInwardsSoilLayer2DWithNestedLayers() + { + // Setup + MacroStabilityInwardsSoilLayerTwoDEntity entity = MacroStabilityInwardsSoilLayerTwoDEntityTestFactory.CreateMacroStabilityInwardsSoilLayerTwoDEntity(); + + entity.MacroStabilityInwardsSoilLayerTwoDEntity1.Add(CreateMacroStabilityInwardsSoilLayerTwoDEntity()); + entity.MacroStabilityInwardsSoilLayerTwoDEntity1.Add(CreateMacroStabilityInwardsSoilLayerTwoDEntity()); + entity.MacroStabilityInwardsSoilLayerTwoDEntity1.Add(CreateMacroStabilityInwardsSoilLayerTwoDEntity()); + + // Call + MacroStabilityInwardsSoilLayer2D layer = entity.Read(); + + // Assert + Assert.IsNotNull(layer); + Assert.AreEqual(entity.MacroStabilityInwardsSoilLayerTwoDEntity1.Count, + layer.NestedLayers.Count()); + + for (var i = 0; i < entity.MacroStabilityInwardsSoilLayerTwoDEntity1.Count; i++) + { + AssertMacroStabilityInwardsSoilLayer2D(entity.MacroStabilityInwardsSoilLayerTwoDEntity1.ElementAt(i), + layer.NestedLayers.ElementAt(i)); + } + } + + [Test] + public void Read_WithNullValues_ReturnsMacroStabilityInwardsSoilLayer2DWithNaNValues() + { + // Setup + var entity = new MacroStabilityInwardsSoilLayerTwoDEntity + { + MaterialName = nameof(MacroStabilityInwardsSoilLayerTwoDEntity), + OuterRingXml = new Point2DCollectionXmlSerializer().ToXml(RingTestFactory.CreateRandomRing().Points) + }; + + // Call + MacroStabilityInwardsSoilLayer2D layer = entity.Read(); + + // Assert + Assert.IsNotNull(layer); + MacroStabilityInwardsSoilLayerData data = layer.Data; + Assert.AreEqual(entity.MaterialName, data.MaterialName); + + Assert.IsNaN(data.AbovePhreaticLevel.Mean); + Assert.IsNaN(data.AbovePhreaticLevel.CoefficientOfVariation); + Assert.IsNaN(data.AbovePhreaticLevel.Shift); + + Assert.IsNaN(data.BelowPhreaticLevel.Mean); + Assert.IsNaN(data.BelowPhreaticLevel.CoefficientOfVariation); + Assert.IsNaN(data.BelowPhreaticLevel.Shift); + + Assert.IsNaN(data.Cohesion.Mean); + Assert.IsNaN(data.Cohesion.CoefficientOfVariation); + + Assert.IsNaN(data.FrictionAngle.Mean); + Assert.IsNaN(data.FrictionAngle.CoefficientOfVariation); + + Assert.IsNaN(data.ShearStrengthRatio.Mean); + Assert.IsNaN(data.ShearStrengthRatio.CoefficientOfVariation); + + Assert.IsNaN(data.StrengthIncreaseExponent.Mean); + Assert.IsNaN(data.StrengthIncreaseExponent.CoefficientOfVariation); + + Assert.IsNaN(data.Pop.Mean); + Assert.IsNaN(data.Pop.CoefficientOfVariation); + } + + private static void AssertMacroStabilityInwardsSoilLayer2D(MacroStabilityInwardsSoilLayerTwoDEntity entity, + MacroStabilityInwardsSoilLayer2D layer) + { + Assert.IsNotNull(layer); + MacroStabilityInwardsSoilLayerData data = layer.Data; + Assert.AreEqual(Convert.ToBoolean(entity.IsAquifer), data.IsAquifer); + Assert.AreEqual(entity.Color, data.Color.ToInt64()); + Assert.AreEqual(entity.MaterialName, data.MaterialName); + + Assert.AreEqual(entity.AbovePhreaticLevelMean ?? double.NaN, data.AbovePhreaticLevel.Mean, + data.AbovePhreaticLevel.GetAccuracy()); + Assert.AreEqual(entity.AbovePhreaticLevelCoefficientOfVariation ?? double.NaN, data.AbovePhreaticLevel.CoefficientOfVariation, + data.AbovePhreaticLevel.GetAccuracy()); + Assert.AreEqual(entity.AbovePhreaticLevelShift ?? double.NaN, data.AbovePhreaticLevel.Shift, + data.AbovePhreaticLevel.GetAccuracy()); + + Assert.AreEqual(entity.BelowPhreaticLevelMean ?? double.NaN, data.BelowPhreaticLevel.Mean, + data.BelowPhreaticLevel.GetAccuracy()); + Assert.AreEqual(entity.BelowPhreaticLevelCoefficientOfVariation ?? double.NaN, data.BelowPhreaticLevel.CoefficientOfVariation, + data.BelowPhreaticLevel.GetAccuracy()); + Assert.AreEqual(entity.BelowPhreaticLevelShift ?? double.NaN, data.BelowPhreaticLevel.Shift, + data.BelowPhreaticLevel.GetAccuracy()); + + Assert.AreEqual(entity.CohesionMean ?? double.NaN, data.Cohesion.Mean, + data.Cohesion.GetAccuracy()); + Assert.AreEqual(entity.CohesionCoefficientOfVariation ?? double.NaN, data.Cohesion.CoefficientOfVariation, + data.Cohesion.GetAccuracy()); + + Assert.AreEqual(entity.FrictionAngleMean ?? double.NaN, data.FrictionAngle.Mean, + data.FrictionAngle.GetAccuracy()); + Assert.AreEqual(entity.FrictionAngleCoefficientOfVariation ?? double.NaN, data.FrictionAngle.CoefficientOfVariation, + data.FrictionAngle.GetAccuracy()); + + Assert.AreEqual(entity.ShearStrengthRatioMean ?? double.NaN, data.ShearStrengthRatio.Mean, + data.ShearStrengthRatio.GetAccuracy()); + Assert.AreEqual(entity.ShearStrengthRatioCoefficientOfVariation ?? double.NaN, data.ShearStrengthRatio.CoefficientOfVariation, + data.ShearStrengthRatio.GetAccuracy()); + + Assert.AreEqual(entity.StrengthIncreaseExponentMean ?? double.NaN, data.StrengthIncreaseExponent.Mean, + data.StrengthIncreaseExponent.GetAccuracy()); + Assert.AreEqual(entity.StrengthIncreaseExponentCoefficientOfVariation ?? double.NaN, data.StrengthIncreaseExponent.CoefficientOfVariation, + data.StrengthIncreaseExponent.GetAccuracy()); + + Assert.AreEqual(entity.PopMean ?? double.NaN, data.Pop.Mean, data.Pop.GetAccuracy()); + Assert.AreEqual(entity.PopCoefficientOfVariation ?? double.NaN, data.Pop.CoefficientOfVariation, + data.Pop.GetAccuracy()); + + CollectionAssert.AreEqual(new Point2DCollectionXmlSerializer().FromXml(entity.OuterRingXml), + layer.OuterRing.Points); + CollectionAssert.IsEmpty(layer.NestedLayers); + } + + private static MacroStabilityInwardsSoilLayerTwoDEntity CreateMacroStabilityInwardsSoilLayerTwoDEntity() + { + var random = new Random(31); + var entity = new MacroStabilityInwardsSoilLayerTwoDEntity + { + IsAquifer = Convert.ToByte(random.NextBoolean()), + Color = Color.FromKnownColor(random.NextEnumValue()).ToInt64(), + MaterialName = random.Next().ToString(), + AbovePhreaticLevelMean = random.NextDouble(2.0, 3.0), + AbovePhreaticLevelCoefficientOfVariation = random.NextDouble(), + AbovePhreaticLevelShift = random.NextDouble(0.0, 1.0), + BelowPhreaticLevelMean = random.NextDouble(2.0, 3.0), + BelowPhreaticLevelCoefficientOfVariation = random.NextDouble(), + BelowPhreaticLevelShift = random.NextDouble(0.0, 1.0), + CohesionMean = random.NextDouble(), + CohesionCoefficientOfVariation = random.NextDouble(), + FrictionAngleMean = random.NextDouble(), + FrictionAngleCoefficientOfVariation = random.NextDouble(), + ShearStrengthRatioMean = random.NextDouble(), + ShearStrengthRatioCoefficientOfVariation = random.NextDouble(), + StrengthIncreaseExponentMean = random.NextDouble(), + StrengthIncreaseExponentCoefficientOfVariation = random.NextDouble(), + PopMean = random.NextDouble(), + PopCoefficientOfVariation = random.NextDouble(), + OuterRingXml = new Point2DCollectionXmlSerializer().ToXml(RingTestFactory.CreateRandomRing().Points) + }; + return entity; + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsSoilProfileOneDEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsSoilProfileOneDEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsSoilProfileOneDEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,166 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.MacroStabilityInwards.Data.SoilProfile; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Read.MacroStabilityInwards; + +namespace Riskeer.Storage.Core.Test.Read.MacroStabilityInwards +{ + [TestFixture] + public class MacroStabilityInwardsSoilProfileOneDEntityReadExtensionsTest + { + [Test] + public void Read_CollectorNull_ThrowsArgumentNullException() + { + // Setup + var entity = new MacroStabilityInwardsSoilProfileOneDEntity(); + + // Call + TestDelegate test = () => entity.Read(null); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("collector", parameter); + } + + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => ((MacroStabilityInwardsSoilProfileOneDEntity) null).Read(collector); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", parameter); + } + + [Test] + public void Read_WithCollector_ReturnsNewSoilProfileWithPropertiesSet() + { + // Setup + var random = new Random(31); + double bottom = random.NextDouble(); + var entity = new MacroStabilityInwardsSoilProfileOneDEntity + { + Name = nameof(MacroStabilityInwardsSoilProfileOneDEntity), + Bottom = bottom, + MacroStabilityInwardsSoilLayerOneDEntities = + { + new MacroStabilityInwardsSoilLayerOneDEntity + { + Top = bottom + 0.5, + MaterialName = "A", + Order = 1 + }, + new MacroStabilityInwardsSoilLayerOneDEntity + { + Top = bottom + 1.2, + MaterialName = "B", + Order = 0 + } + } + }; + var collector = new ReadConversionCollector(); + + // Call + MacroStabilityInwardsSoilProfile1D profile = entity.Read(collector); + + // Assert + Assert.IsNotNull(profile); + Assert.AreEqual(entity.Name, profile.Name); + Assert.AreEqual(bottom, profile.Bottom); + CollectionAssert.AreEqual(new[] + { + "B", + "A" + }, profile.Layers.Select(l => l.Data.MaterialName)); + } + + [Test] + public void Read_WithNullValues_ReturnsSoilProfileWithNaNValues() + { + // Setup + var entity = new MacroStabilityInwardsSoilProfileOneDEntity + { + Name = nameof(MacroStabilityInwardsSoilProfileOneDEntity), + Bottom = null, + MacroStabilityInwardsSoilLayerOneDEntities = + { + new MacroStabilityInwardsSoilLayerOneDEntity + { + MaterialName = nameof(MacroStabilityInwardsSoilLayerOneDEntity) + } + } + }; + var collector = new ReadConversionCollector(); + + // Call + MacroStabilityInwardsSoilProfile1D profile = entity.Read(collector); + + // Assert + Assert.IsNotNull(profile); + Assert.AreEqual(entity.Name, profile.Name); + Assert.IsNaN(profile.Bottom); + Assert.AreEqual(entity.MacroStabilityInwardsSoilLayerOneDEntities.Count, profile.Layers.Count()); + + MacroStabilityInwardsSoilLayer1D layer = profile.Layers.ElementAt(0); + Assert.AreEqual(entity.MacroStabilityInwardsSoilLayerOneDEntities.First().MaterialName, layer.Data.MaterialName); + } + + [Test] + public void GivenReadObject_WhenReadCalledOnSameEntity_ThenSameObjectInstanceReturned() + { + // Given + const string testName = "testName"; + var random = new Random(31); + double bottom = random.NextDouble(); + var entity = new MacroStabilityInwardsSoilProfileOneDEntity + { + Name = testName, + Bottom = bottom, + MacroStabilityInwardsSoilLayerOneDEntities = + { + new MacroStabilityInwardsSoilLayerOneDEntity + { + Top = bottom + 0.5 + } + } + }; + var collector = new ReadConversionCollector(); + + MacroStabilityInwardsSoilProfile1D profile = entity.Read(collector); + + // When + MacroStabilityInwardsSoilProfile1D secondProfile = entity.Read(collector); + + // Then + Assert.AreSame(profile, secondProfile); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsSoilProfileTwoDEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsSoilProfileTwoDEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsSoilProfileTwoDEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,179 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using Core.Common.Util.Extensions; +using NUnit.Framework; +using Ringtoets.Common.Data.Probabilistics; +using Ringtoets.MacroStabilityInwards.Data.SoilProfile; +using Ringtoets.MacroStabilityInwards.Primitives; +using Ringtoets.MacroStabilityInwards.Primitives.TestUtil; +using Ringtoets.Storage.Core.TestUtil.MacroStabilityInwards; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Read.MacroStabilityInwards; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Read.MacroStabilityInwards +{ + [TestFixture] + public class MacroStabilityInwardsSoilProfileTwoDEntityReadExtensionsTest + { + [Test] + public void Read_CollectorNull_ThrowsArgumentNullException() + { + // Setup + var entity = new MacroStabilityInwardsSoilProfileTwoDEntity(); + + // Call + TestDelegate test = () => entity.Read(null); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("collector", parameter); + } + + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => ((MacroStabilityInwardsSoilProfileTwoDEntity) null).Read(collector); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", parameter); + } + + [Test] + public void Read_WithCollector_ReturnsSoilProfileWithPropertiesSet() + { + // Setup + Ring outerRingA = RingTestFactory.CreateRandomRing(32); + Ring outerRingB = RingTestFactory.CreateRandomRing(33); + + var random = new Random(31); + var preconsolidationStressEntity = new MacroStabilityInwardsPreconsolidationStressEntity + { + CoordinateX = random.NextDouble(), + CoordinateZ = random.NextDouble(), + PreconsolidationStressMean = random.NextDouble(), + PreconsolidationStressCoefficientOfVariation = random.NextDouble(), + Order = 1 + }; + + var point2DXmlSerializer = new Point2DCollectionXmlSerializer(); + var entity = new MacroStabilityInwardsSoilProfileTwoDEntity + { + Name = nameof(MacroStabilityInwardsSoilProfileTwoDEntity), + MacroStabilityInwardsSoilLayerTwoDEntities = + { + new MacroStabilityInwardsSoilLayerTwoDEntity + { + MaterialName = "A", + OuterRingXml = point2DXmlSerializer.ToXml(outerRingA.Points), + Order = 1 + }, + new MacroStabilityInwardsSoilLayerTwoDEntity + { + MaterialName = "B", + OuterRingXml = point2DXmlSerializer.ToXml(outerRingB.Points), + Order = 0 + } + }, + MacroStabilityInwardsPreconsolidationStressEntities = + { + preconsolidationStressEntity, + new MacroStabilityInwardsPreconsolidationStressEntity + { + Order = 0 + } + } + }; + var collector = new ReadConversionCollector(); + + // Call + MacroStabilityInwardsSoilProfile2D profile = entity.Read(collector); + + // Assert + Assert.IsNotNull(profile); + Assert.AreEqual(entity.Name, profile.Name); + CollectionAssert.AreEqual(new[] + { + "B", + "A" + }, profile.Layers.Select(l => l.Data.MaterialName)); + + CollectionAssert.AreEqual(new[] + { + outerRingB, + outerRingA + }, profile.Layers.Select(l => l.OuterRing)); + + profile.Layers.Select(l => l.NestedLayers).ForEachElementDo(CollectionAssert.IsEmpty); + + CollectionAssert.AreEqual(new[] + { + new MacroStabilityInwardsPreconsolidationStress(new Point2D(0, 0), + new VariationCoefficientLogNormalDistribution + { + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN + }), + new MacroStabilityInwardsPreconsolidationStress(new Point2D(preconsolidationStressEntity.CoordinateX, + preconsolidationStressEntity.CoordinateZ), + new VariationCoefficientLogNormalDistribution + { + Mean = (RoundedDouble) preconsolidationStressEntity.PreconsolidationStressMean.ToNullAsNaN(), + CoefficientOfVariation = (RoundedDouble) preconsolidationStressEntity.PreconsolidationStressCoefficientOfVariation.ToNullAsNaN() + }) + }, profile.PreconsolidationStresses); + } + + [Test] + public void GivenReadObject_WhenReadCalledOnSameEntity_ThenSameObjectInstanceReturned() + { + // Given + var entity = new MacroStabilityInwardsSoilProfileTwoDEntity + { + Name = "testName", + MacroStabilityInwardsSoilLayerTwoDEntities = + { + MacroStabilityInwardsSoilLayerTwoDEntityTestFactory.CreateMacroStabilityInwardsSoilLayerTwoDEntity() + } + }; + var collector = new ReadConversionCollector(); + + MacroStabilityInwardsSoilProfile2D profile = entity.Read(collector); + + // When + MacroStabilityInwardsSoilProfile2D secondProfile = entity.Read(collector); + + // Then + Assert.AreSame(profile, secondProfile); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsStochasticSoilProfileEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsStochasticSoilProfileEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityInwards/MacroStabilityInwardsStochasticSoilProfileEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,227 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.MacroStabilityInwards.Data.SoilProfile; +using Ringtoets.MacroStabilityInwards.Primitives; +using Ringtoets.Storage.Core.TestUtil.MacroStabilityInwards; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Read.MacroStabilityInwards; + +namespace Riskeer.Storage.Core.Test.Read.MacroStabilityInwards +{ + [TestFixture] + public class MacroStabilityInwardsStochasticSoilProfileEntityReadExtensionsTest + { + [Test] + public void Read_CollectorNull_ThrowsArgumentNullException() + { + // Setup + var entity = new MacroStabilityInwardsStochasticSoilProfileEntity(); + + // Call + TestDelegate test = () => entity.Read(null); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("collector", parameter); + } + + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => ((MacroStabilityInwardsStochasticSoilProfileEntity) null).Read(collector); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", parameter); + } + + [Test] + public void Read_WithCollectorAnd1dProfile_ReturnsStochasticSoilProfileWithPropertiesSet() + { + // Setup + var random = new Random(21); + var entity = new MacroStabilityInwardsStochasticSoilProfileEntity + { + Probability = random.NextDouble(), + MacroStabilityInwardsSoilProfileOneDEntity = new MacroStabilityInwardsSoilProfileOneDEntity + { + Name = "SoilProfile", + MacroStabilityInwardsSoilLayerOneDEntities = + { + new MacroStabilityInwardsSoilLayerOneDEntity() + } + } + }; + var collector = new ReadConversionCollector(); + + // Call + MacroStabilityInwardsStochasticSoilProfile stochasticSoilProfile = entity.Read(collector); + + // Assert + Assert.IsNotNull(stochasticSoilProfile); + Assert.AreEqual(entity.Probability, stochasticSoilProfile.Probability, 1e-6); + + IMacroStabilityInwardsSoilProfile profile = stochasticSoilProfile.SoilProfile; + Assert.IsInstanceOf(profile); + Assert.AreEqual(entity.MacroStabilityInwardsSoilProfileOneDEntity.Name, profile.Name); + } + + [Test] + public void Read_WithCollectorAnd2dProfile_ReturnsStochasticSoilProfileWithPropertiesSet() + { + // Setup + var random = new Random(21); + var entity = new MacroStabilityInwardsStochasticSoilProfileEntity + { + Probability = random.NextDouble(), + MacroStabilityInwardsSoilProfileTwoDEntity = new MacroStabilityInwardsSoilProfileTwoDEntity + { + Name = "SoilProfile", + MacroStabilityInwardsSoilLayerTwoDEntities = + { + MacroStabilityInwardsSoilLayerTwoDEntityTestFactory.CreateMacroStabilityInwardsSoilLayerTwoDEntity() + } + } + }; + var collector = new ReadConversionCollector(); + + // Call + MacroStabilityInwardsStochasticSoilProfile stochasticSoilProfile = entity.Read(collector); + + // Assert + Assert.IsNotNull(stochasticSoilProfile); + Assert.AreEqual(entity.Probability, stochasticSoilProfile.Probability, 1e-6); + + IMacroStabilityInwardsSoilProfile profile = stochasticSoilProfile.SoilProfile; + Assert.IsInstanceOf(profile); + Assert.AreEqual(entity.MacroStabilityInwardsSoilProfileTwoDEntity.Name, profile.Name); + } + + [Test] + public void Read_DifferentStochasticSoilProfileEntitiesWithSame1dProfile_ReturnsStochasticSoilProfilesWithSameSoilProfile() + { + // Setup + var random = new Random(21); + double probability = random.NextDouble(); + var soilProfileOneDEntity = new MacroStabilityInwardsSoilProfileOneDEntity + { + Name = "SoilProfile", + MacroStabilityInwardsSoilLayerOneDEntities = + { + new MacroStabilityInwardsSoilLayerOneDEntity() + } + }; + + var firstEntity = new MacroStabilityInwardsStochasticSoilProfileEntity + { + Probability = probability, + MacroStabilityInwardsSoilProfileOneDEntity = soilProfileOneDEntity + }; + var secondEntity = new MacroStabilityInwardsStochasticSoilProfileEntity + { + Probability = 1 - probability, + MacroStabilityInwardsSoilProfileOneDEntity = soilProfileOneDEntity + }; + var collector = new ReadConversionCollector(); + + MacroStabilityInwardsStochasticSoilProfile firstStochasticSoilProfile = firstEntity.Read(collector); + + // Call + MacroStabilityInwardsStochasticSoilProfile secondStochasticSoilProfile = secondEntity.Read(collector); + + // Assert + Assert.AreNotSame(firstStochasticSoilProfile, secondStochasticSoilProfile); + Assert.AreSame(firstStochasticSoilProfile.SoilProfile, secondStochasticSoilProfile.SoilProfile); + } + + [Test] + public void Read_DifferentStochasticSoilProfileEntitiesWithSame2dProfile_ReturnsStochasticSoilProfilesWithSameSoilProfile() + { + // Setup + var random = new Random(21); + double probability = random.NextDouble(); + var soilProfileTwoDEntity = new MacroStabilityInwardsSoilProfileTwoDEntity + { + Name = "SoilProfile", + MacroStabilityInwardsSoilLayerTwoDEntities = + { + MacroStabilityInwardsSoilLayerTwoDEntityTestFactory.CreateMacroStabilityInwardsSoilLayerTwoDEntity() + } + }; + + var firstEntity = new MacroStabilityInwardsStochasticSoilProfileEntity + { + Probability = probability, + MacroStabilityInwardsSoilProfileTwoDEntity = soilProfileTwoDEntity + }; + var secondEntity = new MacroStabilityInwardsStochasticSoilProfileEntity + { + Probability = 1 - probability, + MacroStabilityInwardsSoilProfileTwoDEntity = soilProfileTwoDEntity + }; + var collector = new ReadConversionCollector(); + + MacroStabilityInwardsStochasticSoilProfile firstStochasticSoilProfile = firstEntity.Read(collector); + + // Call + MacroStabilityInwardsStochasticSoilProfile secondStochasticSoilProfile = secondEntity.Read(collector); + + // Assert + Assert.AreNotSame(firstStochasticSoilProfile, secondStochasticSoilProfile); + Assert.AreSame(firstStochasticSoilProfile.SoilProfile, secondStochasticSoilProfile.SoilProfile); + } + + [Test] + public void GivenReadObject_WhenReadCalledOnSameEntity_ThenSameObjectInstanceReturned() + { + // Given + var entity = new MacroStabilityInwardsStochasticSoilProfileEntity + { + MacroStabilityInwardsSoilProfileOneDEntity = new MacroStabilityInwardsSoilProfileOneDEntity + { + Name = "StochasticSoilProfile", + MacroStabilityInwardsSoilLayerOneDEntities = + { + new MacroStabilityInwardsSoilLayerOneDEntity() + } + } + }; + + var collector = new ReadConversionCollector(); + + MacroStabilityInwardsStochasticSoilProfile stochasticSoilProfile1 = entity.Read(collector); + + // When + MacroStabilityInwardsStochasticSoilProfile stochasticSoilProfile2 = entity.Read(collector); + + // Then + Assert.AreSame(stochasticSoilProfile1, stochasticSoilProfile2); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityOutwards/MacroStabilityOutwardsFailureMechanismMetaEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityOutwards/MacroStabilityOutwardsFailureMechanismMetaEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityOutwards/MacroStabilityOutwardsFailureMechanismMetaEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,78 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.Integration.Data.StandAlone.Input; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.MacroStabilityOutwards; + +namespace Riskeer.Storage.Core.Test.Read.MacroStabilityOutwards +{ + [TestFixture] + public class MacroStabilityOutwardsFailureMechanismMetaEntityReadExtensionsTest + { + [Test] + public void ReadProbabilityAssessmentInput_EntityNull_ThrowsArgumentNullException() + { + // Setup + var input = new MacroStabilityOutwardsProbabilityAssessmentInput(); + + // Call + TestDelegate test = () => ((MacroStabilityOutwardsFailureMechanismMetaEntity) null).ReadProbabilityAssessmentInput(input); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void ReadProbabilityAssessmentInput_ProbabilityAssessmentInputNull_ThrowsArgumentNullException() + { + // Setup + var entity = new MacroStabilityOutwardsFailureMechanismMetaEntity(); + + // Call + TestDelegate test = () => entity.ReadProbabilityAssessmentInput(null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("probabilityAssessmentInput", exception.ParamName); + } + + [Test] + public void ReadProbabilityAssessmentInput_ValidParameters_SetMacroStabilityOutwardsProbabilityAssessmentInputProperties() + { + // Setup + var inputToUpdate = new MacroStabilityOutwardsProbabilityAssessmentInput(); + var entity = new MacroStabilityOutwardsFailureMechanismMetaEntity + { + A = new Random(31).NextDouble() + }; + + // Call + entity.ReadProbabilityAssessmentInput(inputToUpdate); + + // Assert + Assert.AreEqual(entity.A, inputToUpdate.A); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityOutwards/MacroStabilityOutwardsSectionResultEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityOutwards/MacroStabilityOutwardsSectionResultEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MacroStabilityOutwards/MacroStabilityOutwardsSectionResultEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,115 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.Integration.Data.StandAlone.SectionResults; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.MacroStabilityOutwards; + +namespace Riskeer.Storage.Core.Test.Read.MacroStabilityOutwards +{ + [TestFixture] + public class MacroStabilityOutwardsSectionResultEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Setup + var sectionResult = new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + TestDelegate call = () => ((MacroStabilityOutwardsSectionResultEntity) null).Read(sectionResult); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_SectionResultNull_ThrowsArgumentNullException() + { + // Setup + var entity = new MacroStabilityOutwardsSectionResultEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("sectionResult", paramName); + } + + [Test] + public void Read_ParameterValues_SetsSectionResultWithParameterValues() + { + // Setup + var random = new Random(31); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResult = random.NextEnumValue(); + double detailedAssessmentProbability = random.NextDouble(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + double tailorMadeAssessmentProbability = random.NextDouble(); + bool useManualAssembly = random.NextBoolean(); + var manualAssemblyCategoryGroup = random.NextEnumValue(); + + var entity = new MacroStabilityOutwardsSectionResultEntity + { + SimpleAssessmentResult = Convert.ToByte(simpleAssessmentResult), + DetailedAssessmentResult = Convert.ToByte(detailedAssessmentResult), + DetailedAssessmentProbability = detailedAssessmentProbability, + TailorMadeAssessmentResult = Convert.ToByte(tailorMadeAssessmentResult), + TailorMadeAssessmentProbability = tailorMadeAssessmentProbability, + UseManualAssembly = Convert.ToByte(useManualAssembly), + ManualAssemblyCategoryGroup = Convert.ToByte(manualAssemblyCategoryGroup) + }; + var sectionResult = new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult); + + // Assert + Assert.AreEqual(simpleAssessmentResult, sectionResult.SimpleAssessmentResult); + Assert.AreEqual(detailedAssessmentResult, sectionResult.DetailedAssessmentResult); + Assert.AreEqual(tailorMadeAssessmentResult, sectionResult.TailorMadeAssessmentResult); + Assert.AreEqual(useManualAssembly, sectionResult.UseManualAssembly); + Assert.AreEqual(manualAssemblyCategoryGroup, sectionResult.ManualAssemblyCategoryGroup); + } + + [Test] + public void Read_EntityWithNullValues_SetsSectionResultWithNaNValues() + { + // Setup + var entity = new MacroStabilityOutwardsSectionResultEntity(); + var sectionResult = new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult); + + // Assert + Assert.IsNaN(sectionResult.DetailedAssessmentProbability); + Assert.IsNaN(sectionResult.TailorMadeAssessmentProbability); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MicrostabilitySectionResultEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MicrostabilitySectionResultEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/MicrostabilitySectionResultEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,96 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.Integration.Data.StandAlone.SectionResults; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; + +namespace Riskeer.Storage.Core.Test.Read +{ + [TestFixture] + public class MicrostabilitySectionResultEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Setup + var sectionResult = new MicrostabilityFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + TestDelegate call = () => ((MicrostabilitySectionResultEntity) null).Read(sectionResult); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_SectionResultNull_ThrowsArgumentNullException() + { + // Setup + var entity = new MicrostabilitySectionResultEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("sectionResult", paramName); + } + + [Test] + public void Read_ParameterValues_SetsSectionResultWithParameterValues() + { + // Setup + var random = new Random(31); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResult = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + bool useManualAssembly = random.NextBoolean(); + var manualAssemblyCategoryGroup = random.NextEnumValue(); + + var entity = new MicrostabilitySectionResultEntity + { + SimpleAssessmentResult = Convert.ToByte(simpleAssessmentResult), + DetailedAssessmentResult = Convert.ToByte(detailedAssessmentResult), + TailorMadeAssessmentResult = Convert.ToByte(tailorMadeAssessmentResult), + UseManualAssembly = Convert.ToByte(useManualAssembly), + ManualAssemblyCategoryGroup = Convert.ToByte(manualAssemblyCategoryGroup) + }; + var sectionResult = new MicrostabilityFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult); + + // Assert + Assert.AreEqual(simpleAssessmentResult, sectionResult.SimpleAssessmentResult); + Assert.AreEqual(detailedAssessmentResult, sectionResult.DetailedAssessmentResult); + Assert.AreEqual(tailorMadeAssessmentResult, sectionResult.TailorMadeAssessmentResult); + Assert.AreEqual(useManualAssembly, sectionResult.UseManualAssembly); + Assert.AreEqual(manualAssemblyCategoryGroup, sectionResult.ManualAssemblyCategoryGroup); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/PipingCalculationEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/PipingCalculationEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/PipingCalculationEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,376 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Data.SoilProfile; +using Ringtoets.Piping.Data.TestUtil; +using Ringtoets.Piping.Primitives; +using Ringtoets.Piping.Primitives.TestUtil; +using Ringtoets.Storage.Core.TestUtil.Hydraulics; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Read.Piping; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Read.Piping +{ + [TestFixture] + public class PipingCalculationEntityReadExtensionsTest + { + [Test] + public void Read_CollectorIsNull_ThrowArgumentNullException() + { + // Setup + var entity = new PipingCalculationEntity(); + + // Call + TestDelegate call = () => entity.Read(null, new GeneralPipingInput()); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + [TestCase(true, false, 0.98, "haha", "hihi", 0.0, 3.4, 5.8, 123)] + [TestCase(false, true, 0.0, null, null, double.NaN, double.NaN, double.NaN, 321)] + public void Read_ValidEntity_ReturnPipingCalculationScenario(bool isRelevant, bool useAssessmentLevelManualInput, double contribution, + string name, string comments, double entryPoint, double exitPoint, + double assessmentLevel, int seed) + { + // Setup + var random = new Random(seed); + + var entity = new PipingCalculationEntity + { + RelevantForScenario = Convert.ToByte(isRelevant), + ScenarioContribution = contribution.ToNaNAsNull(), + Name = name, + Comments = comments, + EntryPointL = entryPoint.ToNaNAsNull(), + ExitPointL = exitPoint.ToNaNAsNull(), + PhreaticLevelExitMean = GetRandomNullableDoubleInRange(random, -9999.99, 9999.99), + PhreaticLevelExitStandardDeviation = GetRandomNullableDoubleInRange(random, 0, 9999.99), + DampingFactorExitMean = GetRandomNullableDoubleInRange(random, 1e-6, 9999.99), + DampingFactorExitStandardDeviation = GetRandomNullableDoubleInRange(random, 0, 9999.99), + AssessmentLevel = assessmentLevel.ToNaNAsNull(), + UseAssessmentLevelManualInput = Convert.ToByte(useAssessmentLevelManualInput) + }; + + var collector = new ReadConversionCollector(); + var generalInputParameters = new GeneralPipingInput(); + + // Call + PipingCalculationScenario calculation = entity.Read(collector, generalInputParameters); + + // Assert + Assert.AreEqual(isRelevant, calculation.IsRelevant); + Assert.AreEqual(contribution, calculation.Contribution, 1e-6); + Assert.AreEqual(name, calculation.Name); + Assert.AreEqual(comments, calculation.Comments.Body); + + Assert.AreEqual(generalInputParameters.BeddingAngle, calculation.InputParameters.BeddingAngle); + Assert.AreEqual(generalInputParameters.CriticalHeaveGradient, calculation.InputParameters.CriticalHeaveGradient); + Assert.AreEqual(generalInputParameters.Gravity, calculation.InputParameters.Gravity); + Assert.AreEqual(generalInputParameters.MeanDiameter70, calculation.InputParameters.MeanDiameter70); + Assert.AreEqual(generalInputParameters.SandParticlesVolumicWeight.Value, calculation.InputParameters.SandParticlesVolumicWeight); + Assert.AreEqual(generalInputParameters.SellmeijerModelFactor, calculation.InputParameters.SellmeijerModelFactor); + Assert.AreEqual(generalInputParameters.SellmeijerReductionFactor, calculation.InputParameters.SellmeijerReductionFactor); + Assert.AreEqual(generalInputParameters.UpliftModelFactor, calculation.InputParameters.UpliftModelFactor); + Assert.AreEqual(generalInputParameters.WaterKinematicViscosity, calculation.InputParameters.WaterKinematicViscosity); + Assert.AreEqual(generalInputParameters.WaterVolumetricWeight.Value, calculation.InputParameters.WaterVolumetricWeight); + Assert.AreEqual(generalInputParameters.WhitesDragCoefficient, calculation.InputParameters.WhitesDragCoefficient); + + AssertRoundedDouble(entryPoint, calculation.InputParameters.EntryPointL); + AssertRoundedDouble(exitPoint, calculation.InputParameters.ExitPointL); + AssertRoundedDouble(entity.PhreaticLevelExitMean, calculation.InputParameters.PhreaticLevelExit.Mean); + AssertRoundedDouble(entity.PhreaticLevelExitStandardDeviation, calculation.InputParameters.PhreaticLevelExit.StandardDeviation); + AssertRoundedDouble(entity.DampingFactorExitMean, calculation.InputParameters.DampingFactorExit.Mean); + AssertRoundedDouble(entity.DampingFactorExitStandardDeviation, calculation.InputParameters.DampingFactorExit.StandardDeviation); + + Assert.AreEqual(useAssessmentLevelManualInput, calculation.InputParameters.UseAssessmentLevelManualInput); + Assert.AreEqual(entity.AssessmentLevel.ToNullAsNaN(), calculation.InputParameters.AssessmentLevel.Value); + + Assert.IsNull(calculation.InputParameters.SurfaceLine); + Assert.IsNull(calculation.InputParameters.HydraulicBoundaryLocation); + Assert.IsNull(calculation.InputParameters.StochasticSoilModel); + Assert.IsNull(calculation.InputParameters.StochasticSoilProfile); + Assert.IsNull(calculation.Output); + } + + [Test] + public void Read_EntityWithSurfaceLineInCollector_CalculationHasAlreadyReadSurfaceLine() + { + // Setup + var surfaceLine = new PipingSurfaceLine(string.Empty); + surfaceLine.SetGeometry(new[] + { + new Point3D(1, 2, 3), + new Point3D(4, 5, 6) + }); + var surfaceLineEntity = new SurfaceLineEntity(); + var entity = new PipingCalculationEntity + { + SurfaceLineEntity = surfaceLineEntity, + EntryPointL = 1, + ExitPointL = 2, + DampingFactorExitMean = 1 + }; + + var collector = new ReadConversionCollector(); + collector.Read(surfaceLineEntity, surfaceLine); + + // Call + PipingCalculationScenario calculation = entity.Read(collector, new GeneralPipingInput()); + + // Assert + Assert.AreSame(surfaceLine, calculation.InputParameters.SurfaceLine); + Assert.AreEqual(1, calculation.InputParameters.EntryPointL, 1e-6); + Assert.AreEqual(2, calculation.InputParameters.ExitPointL, 1e-6); + } + + [Test] + public void Read_EntityWithSurfaceLineNotYetInCollector_CalculationWithCreatedSurfaceLineAndRegisteredNewEntities() + { + // Setup + var points = new[] + { + new Point3D(1, 3, 4), + new Point3D(7, 10, 11) + }; + + var surfaceLineEntity = new SurfaceLineEntity + { + Name = "surface line", + PointsXml = new Point3DCollectionXmlSerializer().ToXml(points) + }; + + var entity = new PipingCalculationEntity + { + SurfaceLineEntity = surfaceLineEntity, + EntryPointL = 1, + ExitPointL = 2, + DampingFactorExitMean = 1 + }; + + var collector = new ReadConversionCollector(); + + // Call + PipingCalculationScenario calculation = entity.Read(collector, new GeneralPipingInput()); + + // Assert + Assert.IsTrue(collector.ContainsPipingSurfaceLine(surfaceLineEntity)); + CollectionAssert.AreEqual(points, calculation.InputParameters.SurfaceLine.Points); + } + + [Test] + public void Read_EntityWithHydraulicBoundaryLocationInCollector_CalculationHasAlreadyReadHydraulicBoundaryLocation() + { + // Setup + var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + var hydraulicLocationEntity = new HydraulicLocationEntity(); + var entity = new PipingCalculationEntity + { + HydraulicLocationEntity = hydraulicLocationEntity, + EntryPointL = 1, + ExitPointL = 2, + DampingFactorExitMean = 1, + AssessmentLevel = 5.81, + UseAssessmentLevelManualInput = Convert.ToByte(false) + }; + + var collector = new ReadConversionCollector(); + collector.Read(hydraulicLocationEntity, hydraulicBoundaryLocation); + + // Call + PipingCalculationScenario calculation = entity.Read(collector, new GeneralPipingInput()); + + // Assert + Assert.AreSame(hydraulicBoundaryLocation, calculation.InputParameters.HydraulicBoundaryLocation); + } + + [Test] + public void Read_EntityWithHydraulicBoundaryLocationNotYetInCollector_CalculationWithCreatedHydraulicBoundaryLocationAndRegisteredNewEntities() + { + // Setup + HydraulicLocationEntity hydraulicLocationEntity = HydraulicLocationEntityTestFactory.CreateHydraulicLocationEntity(); + var entity = new PipingCalculationEntity + { + HydraulicLocationEntity = hydraulicLocationEntity, + EntryPointL = 1, + ExitPointL = 2, + DampingFactorExitMean = 1, + UseAssessmentLevelManualInput = Convert.ToByte(false) + }; + + var collector = new ReadConversionCollector(); + + // Call + entity.Read(collector, new GeneralPipingInput()); + + // Assert + Assert.IsTrue(collector.Contains(hydraulicLocationEntity)); + } + + [Test] + public void Read_EntityWithStochasticSoilModelEntityInCollector_CalculationHasAlreadyReadStochasticSoilModel() + { + // Setup + PipingStochasticSoilModel stochasticSoilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel(); + var stochasticSoilModelEntity = new StochasticSoilModelEntity(); + + var stochasticSoilProfile = new PipingStochasticSoilProfile(1, PipingSoilProfileTestFactory.CreatePipingSoilProfile()); + var stochasticSoilProfileEntity = new PipingStochasticSoilProfileEntity + { + StochasticSoilModelEntity = stochasticSoilModelEntity + }; + + var entity = new PipingCalculationEntity + { + PipingStochasticSoilProfileEntity = stochasticSoilProfileEntity, + EntryPointL = 1, + ExitPointL = 2, + DampingFactorExitMean = 1 + }; + + var collector = new ReadConversionCollector(); + collector.Read(stochasticSoilProfileEntity, stochasticSoilProfile); + collector.Read(stochasticSoilModelEntity, stochasticSoilModel); + + // Call + PipingCalculationScenario calculation = entity.Read(collector, new GeneralPipingInput()); + + // Assert + Assert.AreSame(stochasticSoilProfile, calculation.InputParameters.StochasticSoilProfile); + Assert.AreSame(stochasticSoilModel, calculation.InputParameters.StochasticSoilModel); + } + + [Test] + public void Read_EntityWithStochasticSoilProfileEntityNotYetInCollector_CalculationWithCreatedStochasticSoilProfileAndRegisteredNewEntities() + { + // Setup + var stochasticSoilProfileEntity = new PipingStochasticSoilProfileEntity + { + PipingSoilProfileEntity = new PipingSoilProfileEntity + { + Name = "SoilProfile", + PipingSoilLayerEntities = + { + new PipingSoilLayerEntity() + } + } + }; + + var random = new Random(21); + var geometry = new[] + { + new Point2D(random.NextDouble(), random.NextDouble()) + }; + var stochasticSoilModelEntity = new StochasticSoilModelEntity + { + Name = "StochasticSoilModel", + StochasticSoilModelSegmentPointXml = new Point2DCollectionXmlSerializer().ToXml(geometry), + PipingStochasticSoilProfileEntities = + { + stochasticSoilProfileEntity + } + }; + stochasticSoilProfileEntity.StochasticSoilModelEntity = stochasticSoilModelEntity; + + var entity = new PipingCalculationEntity + { + PipingStochasticSoilProfileEntity = stochasticSoilProfileEntity, + EntryPointL = 1, + ExitPointL = 2, + DampingFactorExitMean = 1 + }; + + var collector = new ReadConversionCollector(); + + // Call + entity.Read(collector, new GeneralPipingInput()); + + // Assert + Assert.IsTrue(collector.Contains(stochasticSoilProfileEntity)); + Assert.IsTrue(collector.ContainsPipingStochasticSoilModel(stochasticSoilModelEntity)); + } + + [Test] + public void Read_EntityWithPipingCalculationOutputEntity_CalculationWithPipingOutput() + { + // Setup + var entity = new PipingCalculationEntity + { + EntryPointL = 1, + ExitPointL = 2, + DampingFactorExitMean = 1, + PipingCalculationOutputEntities = + { + new PipingCalculationOutputEntity() + } + }; + + var collector = new ReadConversionCollector(); + + // Call + PipingCalculationScenario calculation = entity.Read(collector, new GeneralPipingInput()); + + // Assert + PipingOutput output = calculation.Output; + Assert.IsNotNull(output); + + Assert.IsNaN(output.HeaveFactorOfSafety); + Assert.IsNaN(output.HeaveZValue); + Assert.IsNaN(output.SellmeijerFactorOfSafety); + Assert.IsNaN(output.SellmeijerZValue); + Assert.IsNaN(output.UpliftZValue); + Assert.IsNaN(output.UpliftFactorOfSafety); + Assert.IsNaN(output.UpliftEffectiveStress); + Assert.IsNaN(output.HeaveGradient); + Assert.IsNaN(output.SellmeijerCreepCoefficient); + Assert.IsNaN(output.SellmeijerCriticalFall); + Assert.IsNaN(output.SellmeijerReducedFall); + } + + private static void AssertRoundedDouble(double? expectedValue, RoundedDouble actualValue) + { + Assert.IsTrue(expectedValue.HasValue); + Assert.AreEqual(expectedValue.Value, actualValue, actualValue.GetAccuracy()); + } + + private static void AssertRoundedDouble(double expectedValue, RoundedDouble actualValue) + { + Assert.AreEqual(expectedValue, actualValue, actualValue.GetAccuracy()); + } + + private static double? GetRandomNullableDoubleInRange(Random random, double lowerLimit, double upperLimit) + { + double difference = upperLimit - lowerLimit; + return lowerLimit + random.NextDouble(0, difference); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/PipingCalculationOutputEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/PipingCalculationOutputEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/PipingCalculationOutputEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,116 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.Piping.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.Piping; + +namespace Riskeer.Storage.Core.Test.Read.Piping +{ + [TestFixture] + public class PipingCalculationOutputEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((PipingCalculationOutputEntity) null).Read(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_ValidEntity_ReturnPipingOutput() + { + // Setup + var entity = new PipingCalculationOutputEntity + { + HeaveFactorOfSafety = 9.8, + HeaveZValue = 7.6, + UpliftZValue = 5.4, + UpliftFactorOfSafety = 3.2, + SellmeijerZValue = 1.9, + SellmeijerFactorOfSafety = 8.7, + UpliftEffectiveStress = 15.2, + HeaveGradient = 12.2, + SellmeijerCreepCoefficient = 1.4, + SellmeijerCriticalFall = 6.2, + SellmeijerReducedFall = 8.1 + }; + + // Call + PipingOutput output = entity.Read(); + + // Assert + Assert.AreEqual(entity.HeaveFactorOfSafety, output.HeaveFactorOfSafety); + Assert.AreEqual(entity.HeaveZValue, output.HeaveZValue); + Assert.AreEqual(entity.SellmeijerFactorOfSafety, output.SellmeijerFactorOfSafety); + Assert.AreEqual(entity.SellmeijerZValue, output.SellmeijerZValue); + Assert.AreEqual(entity.UpliftZValue, output.UpliftZValue); + Assert.AreEqual(entity.UpliftFactorOfSafety, output.UpliftFactorOfSafety); + Assert.AreEqual(entity.UpliftEffectiveStress, output.UpliftEffectiveStress.Value); + Assert.AreEqual(entity.HeaveGradient, output.HeaveGradient.Value); + Assert.AreEqual(entity.SellmeijerCreepCoefficient, output.SellmeijerCreepCoefficient.Value); + Assert.AreEqual(entity.SellmeijerCriticalFall, output.SellmeijerCriticalFall.Value); + Assert.AreEqual(entity.SellmeijerReducedFall, output.SellmeijerReducedFall.Value); + } + + [Test] + public void Read_ValidEntityWithNullParameterValues_ReturnPipingOutput() + { + // Setup + var entity = new PipingCalculationOutputEntity + { + HeaveFactorOfSafety = null, + HeaveZValue = null, + UpliftZValue = null, + UpliftFactorOfSafety = null, + SellmeijerZValue = null, + SellmeijerFactorOfSafety = null, + UpliftEffectiveStress = null, + HeaveGradient = null, + SellmeijerCreepCoefficient = null, + SellmeijerCriticalFall = null, + SellmeijerReducedFall = null + }; + + // Call + PipingOutput output = entity.Read(); + + // Assert + Assert.IsNaN(output.HeaveFactorOfSafety); + Assert.IsNaN(output.HeaveZValue); + Assert.IsNaN(output.SellmeijerFactorOfSafety); + Assert.IsNaN(output.SellmeijerZValue); + Assert.IsNaN(output.UpliftZValue); + Assert.IsNaN(output.UpliftFactorOfSafety); + Assert.IsNaN(output.UpliftEffectiveStress); + Assert.IsNaN(output.HeaveGradient); + Assert.IsNaN(output.SellmeijerCreepCoefficient); + Assert.IsNaN(output.SellmeijerCriticalFall); + Assert.IsNaN(output.SellmeijerReducedFall); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/PipingFailureMechanismMetaEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/PipingFailureMechanismMetaEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/PipingFailureMechanismMetaEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,124 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Piping.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.Piping; + +namespace Riskeer.Storage.Core.Test.Read.Piping +{ + [TestFixture] + public class PipingFailureMechanismMetaEntityReadExtensionsTest + { + [Test] + public void ReadProbabilityAssessmentInput_EntityNull_ThrowsArgumentNullException() + { + // Setup + var input = new PipingProbabilityAssessmentInput(); + + // Call + TestDelegate test = () => ((PipingFailureMechanismMetaEntity) null).ReadProbabilityAssessmentInput(input); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void ReadProbabilityAssessmentInput_ProbabilityAssessmentInputNull_ThrowsArgumentNullException() + { + // Setup + var entity = new PipingFailureMechanismMetaEntity(); + + // Call + TestDelegate test = () => entity.ReadProbabilityAssessmentInput(null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("probabilityAssessmentInput", exception.ParamName); + } + + [Test] + public void ReadProbabilityAssessmentInput_ValidParameters_SetPipingProbabilityAssessmentInputProperties() + { + // Setup + var inputToUpdate = new PipingProbabilityAssessmentInput(); + var entity = new PipingFailureMechanismMetaEntity + { + A = new Random(31).NextDouble() + }; + + // Call + entity.ReadProbabilityAssessmentInput(inputToUpdate); + + // Assert + Assert.AreEqual(entity.A, inputToUpdate.A); + } + + [Test] + public void ReadGeneralPipingInput_EntityNull_ThrowsArgumentNullException() + { + // Setup + var input = new GeneralPipingInput(); + + // Call + TestDelegate test = () => ((PipingFailureMechanismMetaEntity) null).ReadGeneralPipingInput(input); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void ReadGeneralPipingInput_GeneralPipingInputNull_ThrowsArgumentNullException() + { + // Setup + var entity = new PipingFailureMechanismMetaEntity(); + + // Call + TestDelegate test = () => entity.ReadGeneralPipingInput(null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("generalPipingInput", exception.ParamName); + } + + [Test] + public void ReadGeneralPipingInput_ValidParameters_SetGeneralPipingInputWithProperties() + { + // Setup + var inputToUpdate = new GeneralPipingInput(); + var entity = new PipingFailureMechanismMetaEntity + { + WaterVolumetricWeight = new Random(31).NextDouble() + }; + + // Call + entity.ReadGeneralPipingInput(inputToUpdate); + + // Assert + Assert.AreEqual(entity.WaterVolumetricWeight, inputToUpdate.WaterVolumetricWeight, inputToUpdate.WaterVolumetricWeight.GetAccuracy()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/PipingSectionResultEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/PipingSectionResultEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/PipingSectionResultEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,113 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.Piping.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.Piping; + +namespace Riskeer.Storage.Core.Test.Read.Piping +{ + [TestFixture] + public class PipingSectionResultEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((PipingSectionResultEntity) null).Read( + new PipingFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection())); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_SectionResultNull_ThrowsArgumentNullException() + { + // Setup + var entity = new PipingSectionResultEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("sectionResult", paramName); + } + + [Test] + public void Read_ParameterValues_SectionResultWithParameterValues() + { + // Setup + var random = new Random(21); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResult = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + double tailorMadeAssessmentProbability = random.NextDouble(); + bool useManualAssembly = random.NextBoolean(); + double manualAssemblyProbability = random.NextDouble(); + + var entity = new PipingSectionResultEntity + { + SimpleAssessmentResult = Convert.ToByte(simpleAssessmentResult), + DetailedAssessmentResult = Convert.ToByte(detailedAssessmentResult), + TailorMadeAssessmentResult = Convert.ToByte(tailorMadeAssessmentResult), + TailorMadeAssessmentProbability = tailorMadeAssessmentProbability, + UseManualAssembly = Convert.ToByte(useManualAssembly), + ManualAssemblyProbability = manualAssemblyProbability + }; + + var sectionResult = new PipingFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult); + + // Assert + Assert.AreEqual(simpleAssessmentResult, sectionResult.SimpleAssessmentResult); + Assert.AreEqual(detailedAssessmentResult, sectionResult.DetailedAssessmentResult); + Assert.AreEqual(tailorMadeAssessmentResult, sectionResult.TailorMadeAssessmentResult); + Assert.AreEqual(tailorMadeAssessmentProbability, sectionResult.TailorMadeAssessmentProbability, 1e-6); + Assert.AreEqual(useManualAssembly, sectionResult.UseManualAssembly); + Assert.AreEqual(manualAssemblyProbability, sectionResult.ManualAssemblyProbability, 1e-6); + } + + [Test] + public void Read_EntityWithNullValues_SectionResultWithNaNValues() + { + // Setup + var entity = new PipingSectionResultEntity(); + var sectionResult = new PipingFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult); + + // Assert + Assert.IsNaN(sectionResult.TailorMadeAssessmentProbability); + Assert.IsNaN(sectionResult.ManualAssemblyProbability); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/PipingSoilLayerEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/PipingSoilLayerEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/PipingSoilLayerEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,135 @@ +// Copyright (C) Stichting Deltares 2018. 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.Drawing; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Piping.Primitives; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.Piping; + +namespace Riskeer.Storage.Core.Test.Read.Piping +{ + [TestFixture] + public class PipingSoilLayerEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => ((PipingSoilLayerEntity) null).Read(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_WithValues_ReturnsPipingSoilLayerWithDoubleParameterValues() + { + // Setup + var random = new Random(21); + double top = random.NextDouble(); + Color color = Color.FromKnownColor(random.NextEnumValue()); + const string materialName = "sand"; + + bool isAquifer = random.NextBoolean(); + double belowPhreaticLevelMean = random.NextDouble(1, double.MaxValue); + double belowPhreaticLevelDeviation = random.NextDouble(); + double belowPhreaticLevelShift = random.NextDouble(); + double diameterD70Mean = random.NextDouble(1, double.MaxValue); + double diameterD70CoefficientOfVariation = random.NextDouble(); + double permeabilityMean = random.NextDouble(1, double.MaxValue); + double permeabilityCoefficientOfVariation = random.NextDouble(); + + var entity = new PipingSoilLayerEntity + { + Top = top, + IsAquifer = Convert.ToByte(isAquifer), + Color = color.ToInt64(), + MaterialName = materialName, + BelowPhreaticLevelMean = belowPhreaticLevelMean, + BelowPhreaticLevelDeviation = belowPhreaticLevelDeviation, + BelowPhreaticLevelShift = belowPhreaticLevelShift, + DiameterD70Mean = diameterD70Mean, + DiameterD70CoefficientOfVariation = diameterD70CoefficientOfVariation, + PermeabilityMean = permeabilityMean, + PermeabilityCoefficientOfVariation = permeabilityCoefficientOfVariation + }; + + // Call + PipingSoilLayer layer = entity.Read(); + + // Assert + Assert.IsNotNull(layer); + Assert.AreEqual(top, layer.Top, 1e-6); + Assert.AreEqual(isAquifer, layer.IsAquifer); + Assert.IsNotNull(color); + Assert.AreEqual(color.ToArgb(), layer.Color.ToArgb()); + Assert.AreEqual(materialName, layer.MaterialName); + + Assert.AreEqual(belowPhreaticLevelMean, layer.BelowPhreaticLevel.Mean, + layer.BelowPhreaticLevel.GetAccuracy()); + Assert.AreEqual(belowPhreaticLevelDeviation, layer.BelowPhreaticLevel.StandardDeviation, + layer.BelowPhreaticLevel.GetAccuracy()); + Assert.AreEqual(belowPhreaticLevelShift, layer.BelowPhreaticLevel.Shift, + layer.BelowPhreaticLevel.GetAccuracy()); + + Assert.AreEqual(diameterD70Mean, layer.DiameterD70.Mean, + layer.DiameterD70.GetAccuracy()); + Assert.AreEqual(diameterD70CoefficientOfVariation, layer.DiameterD70.CoefficientOfVariation, + layer.DiameterD70.GetAccuracy()); + + Assert.AreEqual(permeabilityMean, layer.Permeability.Mean, + layer.Permeability.GetAccuracy()); + Assert.AreEqual(permeabilityCoefficientOfVariation, layer.Permeability.CoefficientOfVariation, + layer.Permeability.GetAccuracy()); + } + + [Test] + public void Read_WithNullValues_ReturnsPipingSoilLayerWithNaNValues() + { + // Setup + var entity = new PipingSoilLayerEntity + { + MaterialName = nameof(PipingSoilLayerEntity) + }; + + // Call + PipingSoilLayer layer = entity.Read(); + + // Assert + Assert.IsNotNull(layer); + Assert.AreEqual(entity.MaterialName, layer.MaterialName); + + Assert.IsNaN(layer.Top); + Assert.IsNaN(layer.BelowPhreaticLevel.Mean); + Assert.IsNaN(layer.BelowPhreaticLevel.StandardDeviation); + Assert.IsNaN(layer.BelowPhreaticLevel.Shift); + Assert.IsNaN(layer.DiameterD70.Mean); + Assert.IsNaN(layer.DiameterD70.CoefficientOfVariation); + Assert.IsNaN(layer.Permeability.Mean); + Assert.IsNaN(layer.Permeability.CoefficientOfVariation); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/PipingSoilProfileEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/PipingSoilProfileEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/PipingSoilProfileEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,168 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Piping.Primitives; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Read.Piping; + +namespace Riskeer.Storage.Core.Test.Read.Piping +{ + [TestFixture] + public class PipingSoilProfileEntityReadExtensionsTest + { + [Test] + public void Read_CollectorNull_ThrowsArgumentNullException() + { + // Setup + var entity = new PipingSoilProfileEntity(); + + // Call + TestDelegate test = () => entity.Read(null); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("collector", parameter); + } + + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => ((PipingSoilProfileEntity) null).Read(collector); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", parameter); + } + + [Test] + public void Read_WithCollector_ReturnsNewPipingSoilProfileWithPropertiesSet() + { + // Setup + var random = new Random(21); + double bottom = random.NextDouble(); + var sourceType = random.NextEnumValue(); + var entity = new PipingSoilProfileEntity + { + Name = "testName", + Bottom = bottom, + SourceType = Convert.ToByte(sourceType), + PipingSoilLayerEntities = + { + new PipingSoilLayerEntity + { + Top = bottom + 0.5, + MaterialName = "A", + Order = 1 + }, + new PipingSoilLayerEntity + { + Top = bottom + 1.2, + MaterialName = "B", + Order = 0 + } + } + }; + var collector = new ReadConversionCollector(); + + // Call + PipingSoilProfile profile = entity.Read(collector); + + // Assert + Assert.IsNotNull(profile); + Assert.AreEqual(entity.Name, profile.Name); + Assert.AreEqual(bottom, profile.Bottom, 1e-6); + Assert.AreEqual(sourceType, profile.SoilProfileSourceType); + CollectionAssert.AreEqual(new[] + { + "B", + "A" + }, profile.Layers.Select(l => l.MaterialName)); + } + + [Test] + public void Read_WithNullValues_ReturnsPipingSoilProfileWithNaNValues() + { + // Setup + var entity = new PipingSoilProfileEntity + { + Name = nameof(PipingSoilProfileEntity), + PipingSoilLayerEntities = + { + new PipingSoilLayerEntity + { + MaterialName = nameof(PipingSoilLayerEntity) + } + } + }; + var collector = new ReadConversionCollector(); + + // Call + PipingSoilProfile profile = entity.Read(collector); + + // Assert + Assert.IsNotNull(profile); + Assert.AreEqual(entity.Name, profile.Name); + Assert.IsNaN(profile.Bottom); + Assert.AreEqual(entity.PipingSoilLayerEntities.Count, profile.Layers.Count()); + + PipingSoilLayer layer = profile.Layers.ElementAt(0); + Assert.AreEqual(entity.PipingSoilLayerEntities.First().MaterialName, layer.MaterialName); + } + + [Test] + public void GivenReadObject_WhenReadCalledOnSameEntity_ThenSameObjectInstanceReturned() + { + // Given + var random = new Random(21); + var entity = new PipingSoilProfileEntity + { + Name = "testName", + Bottom = random.NextDouble(), + SourceType = Convert.ToByte(random.NextEnumValue()), + PipingSoilLayerEntities = + { + new PipingSoilLayerEntity + { + Top = random.NextDouble() + 1 + } + } + }; + var collector = new ReadConversionCollector(); + + PipingSoilProfile profile = entity.Read(collector); + + // When + PipingSoilProfile secondProfile = entity.Read(collector); + + // Then + Assert.AreSame(profile, secondProfile); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/PipingStochasticSoilProfileEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/PipingStochasticSoilProfileEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/Piping/PipingStochasticSoilProfileEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,158 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Piping.Data.SoilProfile; +using Ringtoets.Piping.Primitives; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Read.Piping; + +namespace Riskeer.Storage.Core.Test.Read.Piping +{ + [TestFixture] + public class PipingStochasticSoilProfileEntityReadExtensionsTest + { + [Test] + public void Read_CollectorNull_ThrowsArgumentNullException() + { + // Setup + var entity = new PipingStochasticSoilProfileEntity(); + + // Call + TestDelegate test = () => entity.Read(null); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("collector", parameter); + } + + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => ((PipingStochasticSoilProfileEntity) null).Read(collector); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", parameter); + } + + [Test] + public void Read_WithCollector_ReturnsNewStochasticSoilProfileWithPropertiesSet() + { + // Setup + var random = new Random(21); + var entity = new PipingStochasticSoilProfileEntity + { + Probability = random.NextDouble(), + PipingSoilProfileEntity = new PipingSoilProfileEntity + { + Name = "StochasticSoilProfile", + SourceType = Convert.ToByte(random.NextEnumValue()), + PipingSoilLayerEntities = + { + new PipingSoilLayerEntity() + } + } + }; + var collector = new ReadConversionCollector(); + + // Call + PipingStochasticSoilProfile profile = entity.Read(collector); + + // Assert + Assert.IsNotNull(profile); + Assert.AreEqual(entity.Probability, profile.Probability, 1e-6); + } + + [Test] + public void Read_DifferentStochasticSoilProfileEntitiesWithSameSoilProfileEntity_ReturnsStochasticSoilProfilesWithSamePipingSoilProfile() + { + // Setup + var random = new Random(21); + double probability = random.NextDouble(); + var soilProfileEntity = new PipingSoilProfileEntity + { + Name = "StochasticSoilProfile", + SourceType = Convert.ToByte(random.NextEnumValue()), + PipingSoilLayerEntities = + { + new PipingSoilLayerEntity() + } + }; + var firstEntity = new PipingStochasticSoilProfileEntity + { + Probability = probability, + PipingSoilProfileEntity = soilProfileEntity + }; + var secondEntity = new PipingStochasticSoilProfileEntity + { + Probability = 1 - probability, + PipingSoilProfileEntity = soilProfileEntity + }; + var collector = new ReadConversionCollector(); + + PipingStochasticSoilProfile firstProfile = firstEntity.Read(collector); + + // Call + PipingStochasticSoilProfile secondProfile = secondEntity.Read(collector); + + // Assert + Assert.AreNotSame(firstProfile, secondProfile); + Assert.AreSame(firstProfile.SoilProfile, secondProfile.SoilProfile); + } + + [Test] + public void GivenReadObject_WhenReadCalledOnSameEntity_ThenSameObjectInstanceReturned() + { + // Given + var random = new Random(9); + var entity = new PipingStochasticSoilProfileEntity + { + PipingSoilProfileEntity = new PipingSoilProfileEntity + { + Name = "StochasticSoilProfile", + SourceType = Convert.ToByte(random.NextEnumValue()), + PipingSoilLayerEntities = + { + new PipingSoilLayerEntity() + } + } + }; + + var collector = new ReadConversionCollector(); + + PipingStochasticSoilProfile profile1 = entity.Read(collector); + + // When + PipingStochasticSoilProfile profile2 = entity.Read(collector); + + // Then + Assert.AreSame(profile1, profile2); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/PipingStructure/PipingStructureSectionResultEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/PipingStructure/PipingStructureSectionResultEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/PipingStructure/PipingStructureSectionResultEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,96 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.Integration.Data.StandAlone.SectionResults; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.PipingStructure; + +namespace Riskeer.Storage.Core.Test.Read.PipingStructure +{ + [TestFixture] + public class PipingStructureSectionResultEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Setup + var sectionResult = new PipingStructureFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + TestDelegate test = () => ((PipingStructureSectionResultEntity) null).Read(sectionResult); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_SectionResultNull_ThrowsArgumentNullException() + { + // Setup + var entity = new PipingStructureSectionResultEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("sectionResult", paramName); + } + + [Test] + public void Read_ParameterValues_SetsSectionResultWithParameterValues() + { + // Setup + var random = new Random(31); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResult = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + var manualAssemblyCategoryGroup = random.NextEnumValue(); + bool useManualAssembly = random.NextBoolean(); + + var entity = new PipingStructureSectionResultEntity + { + SimpleAssessmentResult = Convert.ToByte(simpleAssessmentResult), + DetailedAssessmentResult = Convert.ToByte(detailedAssessmentResult), + TailorMadeAssessmentResult = Convert.ToByte(tailorMadeAssessmentResult), + UseManualAssembly = Convert.ToByte(useManualAssembly), + ManualAssemblyCategoryGroup = Convert.ToByte(manualAssemblyCategoryGroup) + }; + var sectionResult = new PipingStructureFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult); + + // Assert + Assert.AreEqual(simpleAssessmentResult, sectionResult.SimpleAssessmentResult); + Assert.AreEqual(detailedAssessmentResult, sectionResult.DetailedAssessmentResult); + Assert.AreEqual(tailorMadeAssessmentResult, sectionResult.TailorMadeAssessmentResult); + Assert.AreEqual(useManualAssembly, sectionResult.UseManualAssembly); + Assert.AreEqual(manualAssemblyCategoryGroup, sectionResult.ManualAssemblyCategoryGroup); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/ProjectEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/ProjectEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/ProjectEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,149 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Contribution; +using Ringtoets.Integration.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; + +namespace Riskeer.Storage.Core.Test.Read +{ + [TestFixture] + public class ProjectEntityReadExtensionsTest + { + [Test] + public void Read_WithoutCollector_ThrowsArgumentNullException() + { + // Setup + var entity = new ProjectEntity(); + + // Call + TestDelegate test = () => entity.Read(null); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("collector", parameter); + } + + [Test] + public void Read_WithCollector_ReturnsNewProjectWithPropertiesSet() + { + // Setup + const string testDescription = "testName"; + var entity = new ProjectEntity + { + Description = testDescription + }; + + // Call + RingtoetsProject project = entity.Read(new ReadConversionCollector()); + + // Assert + Assert.IsNotNull(project); + Assert.AreEqual(testDescription, project.Description); + } + + [Test] + public void Read_WithAssessmentSection_ReturnsNewProjectWithAssessmentSections() + { + // Setup + const double lowerLimitNorm = 0.0001; + const double signalingNorm = 0.00001; + + var entity = new ProjectEntity + { + Description = "testName", + AssessmentSectionEntities = + { + new AssessmentSectionEntity + { + SignalingNorm = signalingNorm, + LowerLimitNorm = lowerLimitNorm, + NormativeNormType = Convert.ToByte(NormType.Signaling), + Name = "A", + Order = 56, + Composition = Convert.ToByte(AssessmentSectionComposition.Dike), + BackgroundDataEntities = new[] + { + new BackgroundDataEntity + { + Name = "Background A", + Transparency = 0.0, + IsVisible = 1, + BackgroundDataType = 1, + BackgroundDataMetaEntities = new[] + { + new BackgroundDataMetaEntity + { + Key = BackgroundDataIdentifiers.IsConfigured, + Value = "0" + } + } + } + } + }, + new AssessmentSectionEntity + { + SignalingNorm = signalingNorm, + LowerLimitNorm = lowerLimitNorm, + NormativeNormType = Convert.ToByte(NormType.Signaling), + Name = "B", + Order = 0, + Composition = Convert.ToByte(AssessmentSectionComposition.Dike), + BackgroundDataEntities = new[] + { + new BackgroundDataEntity + { + Name = "Background B", + Transparency = 0.0, + IsVisible = 1, + BackgroundDataType = 2, + BackgroundDataMetaEntities = new[] + { + new BackgroundDataMetaEntity + { + Key = BackgroundDataIdentifiers.WellKnownTileSource, + Value = "1" + } + } + } + } + } + } + }; + + // Call + RingtoetsProject project = entity.Read(new ReadConversionCollector()); + + // Assert + Assert.AreEqual(2, project.AssessmentSections.Count); + CollectionAssert.AreEqual(new[] + { + "B", + "A" + }, project.AssessmentSections.Select(a => a.Name)); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/ReadConversionCollectorTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/ReadConversionCollectorTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/ReadConversionCollectorTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,626 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.ClosingStructures.Data; +using Ringtoets.ClosingStructures.Data.TestUtil; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.DuneErosion.Data; +using Ringtoets.DuneErosion.Data.TestUtil; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.HeightStructures.Data; +using Ringtoets.HeightStructures.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Data.SoilProfile; +using Ringtoets.MacroStabilityInwards.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Data.TestUtil.SoilProfile; +using Ringtoets.MacroStabilityInwards.Primitives; +using Ringtoets.Piping.Data.SoilProfile; +using Ringtoets.Piping.Data.TestUtil; +using Ringtoets.Piping.Primitives; +using Ringtoets.Piping.Primitives.TestUtil; +using Ringtoets.StabilityPointStructures.Data; +using Ringtoets.StabilityPointStructures.Data.TestUtil; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; + +namespace Riskeer.Storage.Core.Test.Read +{ + [TestFixture] + public class ReadConversionCollectorTest + { + /// + /// Test class to test the for the combination of + /// and . + /// + /// The data model. + /// The database entity. + private abstract class CollectorTest where TDataModel : class + where TEntity : class, new() + { + private readonly Action registerToCollector; + private readonly Func containsInCollector; + private readonly Func getFromCollector; + + /// + /// Creates a new instance of . + /// + /// The action to perform to register the entity + /// to the collector. + /// The action to perform to check whether the entity + /// is registered in the collector. + /// The action to perform to get the entity from + /// the collector. + /// Thrown when any input parameter is null. + /// + /// public CollectorTest() : base( + /// (c, e, m) => c.Read(e, m), + /// (c, e) => c.Contains(e), + /// (c, e) => c.Get(e)) {} + /// + /// + protected CollectorTest(Action registerToCollector, + Func containsInCollector, + Func getFromCollector) + { + if (registerToCollector == null) + { + throw new ArgumentNullException(nameof(registerToCollector)); + } + + if (containsInCollector == null) + { + throw new ArgumentNullException(nameof(containsInCollector)); + } + + if (getFromCollector == null) + { + throw new ArgumentNullException(nameof(getFromCollector)); + } + + this.registerToCollector = registerToCollector; + this.containsInCollector = containsInCollector; + this.getFromCollector = getFromCollector; + } + + [Test] + public void Contains_EntityNull_ThrowsArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => containsInCollector(collector, null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Contains_DataModelAdded_ReturnsTrue() + { + // Setup + var collector = new ReadConversionCollector(); + var entity = new TEntity(); + registerToCollector(collector, entity, CreateDataModel()); + + // Call + bool result = containsInCollector(collector, entity); + + // Assert + Assert.IsTrue(result); + } + + [Test] + public void Contains_EmptyReadConversionCollector_ReturnsFalse() + { + // Setup + var collector = new ReadConversionCollector(); + var entity = new TEntity(); + + // Call + bool result = containsInCollector(collector, entity); + + // Assert + Assert.IsFalse(result); + } + + [Test] + public void Contains_OtherEntityAdded_ReturnsFalse() + { + // Setup + var collector = new ReadConversionCollector(); + registerToCollector(collector, new TEntity(), CreateDataModel()); + + // Call + bool result = containsInCollector(collector, new TEntity()); + + // Assert + Assert.IsFalse(result); + } + + [Test] + public void Get_EntityNull_ThrowsArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => getFromCollector(collector, null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Get_DataModelAdded_ReturnsEntity() + { + // Setup + var collector = new ReadConversionCollector(); + TDataModel dataModel = CreateDataModel(); + var entity = new TEntity(); + registerToCollector(collector, entity, dataModel); + + // Call + TDataModel result = getFromCollector(collector, entity); + + // Assert + Assert.AreSame(dataModel, result); + } + + [Test] + public void Get_NoDataModelAdded_ThrowsInvalidOperationException() + { + // Setup + var collector = new ReadConversionCollector(); + var entity = new TEntity(); + + // Call + TestDelegate test = () => getFromCollector(collector, entity); + + // Assert + Assert.Throws(test); + } + + [Test] + public void Get_OtherDataModelAdded_ThrowsInvalidOperationException() + { + // Setup + var collector = new ReadConversionCollector(); + registerToCollector(collector, new TEntity(), CreateDataModel()); + + // Call + TestDelegate test = () => getFromCollector(collector, new TEntity()); + + // Assert + Assert.Throws(test); + } + + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => registerToCollector(collector, null, CreateDataModel()); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Read_DataModelNull_ThrowsArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => registerToCollector(collector, new TEntity(), null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + + /// + /// Creates a new instance of . + /// + /// An instance of . + protected abstract TDataModel CreateDataModel(); + } + + [TestFixture] + private class HydraulicBoundaryLocationCollectorTest : CollectorTest + { + public HydraulicBoundaryLocationCollectorTest() : base( + (c, e, m) => c.Read(e, m), + (c, e) => c.Contains(e), + (c, e) => c.Get(e)) {} + + protected override HydraulicBoundaryLocation CreateDataModel() + { + return new TestHydraulicBoundaryLocation(); + } + } + + #region DuneErosion + + [TestFixture] + private class DuneLocationCollectorTest : CollectorTest + { + public DuneLocationCollectorTest() : base( + (c, e, m) => c.Read(e, m), + (c, e) => c.Contains(e), + (c, e) => c.Get(e)) {} + + protected override DuneLocation CreateDataModel() + { + return new TestDuneLocation(); + } + } + + #endregion + + [TestFixture] + private class FailureMechanismSectionCollectorTest : CollectorTest + { + public FailureMechanismSectionCollectorTest() : base( + (c, e, m) => c.Read(e, m), + (c, e) => c.Contains(e), + (c, e) => c.Get(e)) {} + + protected override FailureMechanismSection CreateDataModel() + { + return FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + } + } + + [TestFixture] + private class DikeProfileCollectorTest : CollectorTest + { + public DikeProfileCollectorTest() : base( + (c, e, m) => c.Read(e, m), + (c, e) => c.Contains(e), + (c, e) => c.Get(e)) {} + + protected override DikeProfile CreateDataModel() + { + return DikeProfileTestFactory.CreateDikeProfile(); + } + } + + [TestFixture] + private class ForeshoreProfileCollectorTest : CollectorTest + { + public ForeshoreProfileCollectorTest() : base( + (c, e, m) => c.Read(e, m), + (c, e) => c.Contains(e), + (c, e) => c.Get(e)) {} + + protected override ForeshoreProfile CreateDataModel() + { + return new TestForeshoreProfile(); + } + } + + #region GrassCoverErosionInwards + + [TestFixture] + private class GrassCoverErosionInwardsCalculationCollectorTest : CollectorTest + { + public GrassCoverErosionInwardsCalculationCollectorTest() : base( + (c, e, m) => c.Read(e, m), + (c, e) => c.Contains(e), + (c, e) => c.Get(e)) {} + + protected override GrassCoverErosionInwardsCalculation CreateDataModel() + { + return new GrassCoverErosionInwardsCalculation(); + } + } + + #endregion + + #region HeightStructure + + [TestFixture] + private class HeightStructureCollectorTest : CollectorTest + { + public HeightStructureCollectorTest() : base( + (c, e, m) => c.Read(e, m), + (c, e) => c.Contains(e), + (c, e) => c.Get(e)) {} + + protected override HeightStructure CreateDataModel() + { + return new TestHeightStructure(); + } + } + + [TestFixture] + private class HeightStructureCalculationCollectorTest : CollectorTest, + HeightStructuresCalculationEntity> + { + public HeightStructureCalculationCollectorTest() : base( + (c, e, m) => c.Read(e, m), + (c, e) => c.Contains(e), + (c, e) => c.Get(e)) {} + + protected override StructuresCalculation CreateDataModel() + { + return new StructuresCalculation(); + } + } + + #endregion + + #region ClosingStructure + + [TestFixture] + private class ClosingStructureCollectorTest : CollectorTest + { + public ClosingStructureCollectorTest() : base( + (c, e, m) => c.Read(e, m), + (c, e) => c.Contains(e), + (c, e) => c.Get(e)) {} + + protected override ClosingStructure CreateDataModel() + { + return new TestClosingStructure(); + } + } + + [TestFixture] + private class ClosingStructureCalculationCollectorTest : CollectorTest, + ClosingStructuresCalculationEntity> + { + public ClosingStructureCalculationCollectorTest() : base( + (c, e, m) => c.Read(e, m), + (c, e) => c.Contains(e), + (c, e) => c.Get(e)) {} + + protected override StructuresCalculation CreateDataModel() + { + return new StructuresCalculation(); + } + } + + #endregion + + #region StabilityPointStructure + + [TestFixture] + private class StabilityPointStructureCollectorTest : CollectorTest + { + public StabilityPointStructureCollectorTest() : base( + (c, e, m) => c.Read(e, m), + (c, e) => c.Contains(e), + (c, e) => c.Get(e)) {} + + protected override StabilityPointStructure CreateDataModel() + { + return new TestStabilityPointStructure(); + } + } + + [TestFixture] + private class StabilityPointStructureCalculationCollectorTest : CollectorTest, + StabilityPointStructuresCalculationEntity> + { + public StabilityPointStructureCalculationCollectorTest() : base( + (c, e, m) => c.Read(e, m), + (c, e) => c.Contains(e), + (c, e) => c.Get(e)) {} + + protected override StructuresCalculation CreateDataModel() + { + return new StructuresCalculation(); + } + } + + #endregion + + #region Piping + + [TestFixture] + private class PipingSoilProfileCollectorTest : CollectorTest + { + public PipingSoilProfileCollectorTest() : base( + (c, e, m) => c.Read(e, m), + (c, e) => c.Contains(e), + (c, e) => c.Get(e)) {} + + protected override PipingSoilProfile CreateDataModel() + { + return PipingSoilProfileTestFactory.CreatePipingSoilProfile(); + } + } + + [TestFixture] + private class PipingStochasticSoilProfileCollectorTest : CollectorTest + { + public PipingStochasticSoilProfileCollectorTest() : base( + (c, e, m) => c.Read(e, m), + (c, e) => c.Contains(e), + (c, e) => c.Get(e)) {} + + protected override PipingStochasticSoilProfile CreateDataModel() + { + return new PipingStochasticSoilProfile(1, PipingSoilProfileTestFactory.CreatePipingSoilProfile()); + } + } + + [TestFixture] + private class PipingStochasticSoilModelCollectorTest : CollectorTest + { + public PipingStochasticSoilModelCollectorTest() : base( + (c, e, m) => c.Read(e, m), + (c, e) => c.ContainsPipingStochasticSoilModel(e), + (c, e) => c.GetPipingStochasticSoilModel(e)) {} + + protected override PipingStochasticSoilModel CreateDataModel() + { + return PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel(nameof(PipingStochasticSoilModel)); + } + } + + [TestFixture] + private class PipingSurfaceLineCollectorTest : CollectorTest + { + public PipingSurfaceLineCollectorTest() : base( + (c, e, m) => c.Read(e, m), + (c, e) => c.ContainsPipingSurfaceLine(e), + (c, e) => c.GetPipingSurfaceLine(e)) {} + + protected override PipingSurfaceLine CreateDataModel() + { + return new PipingSurfaceLine(nameof(PipingSurfaceLine)); + } + } + + #endregion + + #region MacroStabilityInwards + + [TestFixture] + private class MacroStabilityInwardsSoilProfileOneDCollectorTest : CollectorTest + { + public MacroStabilityInwardsSoilProfileOneDCollectorTest() : base( + (c, e, m) => c.Read(e, m), + (c, e) => c.Contains(e), + (c, e) => c.Get(e)) {} + + protected override MacroStabilityInwardsSoilProfile1D CreateDataModel() + { + return new MacroStabilityInwardsSoilProfile1D(nameof(MacroStabilityInwardsSoilProfile1D), 0.0, new[] + { + new MacroStabilityInwardsSoilLayer1D(0.0) + { + Data = + { + IsAquifer = true + } + } + }); + } + } + + [TestFixture] + private class MacroStabilityInwardsSoilProfileTwoDCollectorTest : CollectorTest + { + public MacroStabilityInwardsSoilProfileTwoDCollectorTest() : base( + (c, e, m) => c.Read(e, m), + (c, e) => c.Contains(e), + (c, e) => c.Get(e)) {} + + protected override MacroStabilityInwardsSoilProfile2D CreateDataModel() + { + return new MacroStabilityInwardsSoilProfile2D(nameof(MacroStabilityInwardsSoilProfile1D), + CreateLayers2D(), + Enumerable.Empty()); + } + + private static IEnumerable CreateLayers2D() + { + var outerRing = new Ring(new[] + { + new Point2D(3, 2), + new Point2D(3, 5) + }); + return new[] + { + new MacroStabilityInwardsSoilLayer2D(outerRing) + }; + } + } + + [TestFixture] + private class MacroStabilityInwardsStochasticSoilProfileCollectorTest : CollectorTest + { + public MacroStabilityInwardsStochasticSoilProfileCollectorTest() : base( + (c, e, m) => c.Read(e, m), + (c, e) => c.Contains(e), + (c, e) => c.Get(e)) {} + + protected override MacroStabilityInwardsStochasticSoilProfile CreateDataModel() + { + return new MacroStabilityInwardsStochasticSoilProfile(1, MacroStabilityInwardsSoilProfile1DTestFactory.CreateMacroStabilityInwardsSoilProfile1D()); + } + } + + [TestFixture] + private class MacroStabilityInwardsStochasticSoilModelCollectorTest : CollectorTest + { + public MacroStabilityInwardsStochasticSoilModelCollectorTest() : base( + (c, e, m) => c.Read(e, m), + (c, e) => c.ContainsMacroStabilityInwardsStochasticSoilModel(e), + (c, e) => c.GetMacroStabilityInwardsStochasticSoilModel(e)) {} + + protected override MacroStabilityInwardsStochasticSoilModel CreateDataModel() + { + return MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel(nameof(MacroStabilityInwardsStochasticSoilModel)); + } + } + + [TestFixture] + private class MacroStabilityInwardsSurfaceLineCollectorTest : CollectorTest + { + public MacroStabilityInwardsSurfaceLineCollectorTest() : base( + (c, e, m) => c.Read(e, m), + (c, e) => c.ContainsMacroStabilityInwardsSurfaceLine(e), + (c, e) => c.GetMacroStabilityInwardsSurfaceLine(e)) {} + + protected override MacroStabilityInwardsSurfaceLine CreateDataModel() + { + return new MacroStabilityInwardsSurfaceLine(nameof(MacroStabilityInwardsSurfaceLine)); + } + } + + #endregion + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StabilityPointStructures/StabilityPointStructureEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StabilityPointStructures/StabilityPointStructureEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StabilityPointStructures/StabilityPointStructureEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,306 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.StabilityPointStructures.Data; +using Ringtoets.StabilityPointStructures.Data.TestUtil; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Read.StabilityPointStructures; + +namespace Riskeer.Storage.Core.Test.Read.StabilityPointStructures +{ + [TestFixture] + public class StabilityPointStructureEntityReadExtensionsTest + { + [Test] + public void Read_ReadConversionCollectorNull_ThrowArgumentNullException() + { + // Setup + var entity = new StabilityPointStructureEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void Read_EntityNotReadBefore_RegisterEntity() + { + // Setup + var entity = new StabilityPointStructureEntity + { + Name = "name", + Id = "id" + }; + + var collector = new ReadConversionCollector(); + + // Precondition + Assert.IsFalse(collector.Contains(entity)); + + // Call + StabilityPointStructure calculation = entity.Read(collector); + + // Assert + Assert.IsTrue(collector.Contains(entity)); + Assert.AreSame(calculation, collector.Get(entity)); + } + + [Test] + public void Read_ValidEntity_ReturnStabilityPointStructure() + { + // Setup + var entity = new StabilityPointStructureEntity + { + Name = "A", + Id = "B", + X = 1.1, + Y = 2.2, + StructureNormalOrientation = 3.3, + StorageStructureAreaMean = 4.4, + StorageStructureAreaCoefficientOfVariation = 5.5, + AllowedLevelIncreaseStorageMean = 6.6, + AllowedLevelIncreaseStorageStandardDeviation = 7.7, + WidthFlowAperturesMean = 8.8, + WidthFlowAperturesStandardDeviation = 9.9, + InsideWaterLevelMean = 10.10, + InsideWaterLevelStandardDeviation = 11.11, + ThresholdHeightOpenWeirMean = 12.12, + ThresholdHeightOpenWeirStandardDeviation = 13.13, + CriticalOvertoppingDischargeMean = 14.14, + CriticalOvertoppingDischargeCoefficientOfVariation = 15.15, + FlowWidthAtBottomProtectionMean = 16.16, + FlowWidthAtBottomProtectionStandardDeviation = 17.17, + ConstructiveStrengthLinearLoadModelMean = 18.18, + ConstructiveStrengthLinearLoadModelCoefficientOfVariation = 19.19, + ConstructiveStrengthQuadraticLoadModelMean = 20.20, + ConstructiveStrengthQuadraticLoadModelCoefficientOfVariation = 21.21, + BankWidthMean = 22.22, + BankWidthStandardDeviation = 23.23, + InsideWaterLevelFailureConstructionMean = 24.24, + InsideWaterLevelFailureConstructionStandardDeviation = 25.25, + EvaluationLevel = 26.26, + LevelCrestStructureMean = 27.27, + LevelCrestStructureStandardDeviation = 28.28, + VerticalDistance = 29.29, + FailureProbabilityRepairClosure = 30.30, + FailureCollisionEnergyMean = 31.31, + FailureCollisionEnergyCoefficientOfVariation = 32.32, + ShipMassMean = 33.33, + ShipMassCoefficientOfVariation = 34.34, + ShipVelocityMean = 35.35, + ShipVelocityCoefficientOfVariation = 36.36, + LevellingCount = 37, + ProbabilityCollisionSecondaryStructure = 38.38, + FlowVelocityStructureClosableMean = 39.39, + StabilityLinearLoadModelMean = 41.41, + StabilityLinearLoadModelCoefficientOfVariation = 42.42, + StabilityQuadraticLoadModelMean = 43.43, + StabilityQuadraticLoadModelCoefficientOfVariation = 44.44, + AreaFlowAperturesMean = 45.45, + AreaFlowAperturesStandardDeviation = 46.46, + InflowModelType = Convert.ToByte(StabilityPointStructureInflowModelType.FloodedCulvert) + }; + + var collector = new ReadConversionCollector(); + + // Call + StabilityPointStructure structure = entity.Read(collector); + + // Assert + Assert.AreEqual(entity.Name, structure.Name); + Assert.AreEqual(entity.Id, structure.Id); + Assert.AreEqual(entity.X, structure.Location.X); + Assert.AreEqual(entity.Y, structure.Location.Y); + Assert.AreEqual(entity.StructureNormalOrientation, structure.StructureNormalOrientation.Value); + + Assert.AreEqual(entity.StorageStructureAreaMean, structure.StorageStructureArea.Mean.Value); + Assert.AreEqual(entity.StorageStructureAreaCoefficientOfVariation, structure.StorageStructureArea.CoefficientOfVariation.Value); + Assert.AreEqual(entity.AllowedLevelIncreaseStorageMean, structure.AllowedLevelIncreaseStorage.Mean.Value); + Assert.AreEqual(entity.AllowedLevelIncreaseStorageStandardDeviation, structure.AllowedLevelIncreaseStorage.StandardDeviation.Value); + Assert.AreEqual(entity.WidthFlowAperturesMean, structure.WidthFlowApertures.Mean.Value); + Assert.AreEqual(entity.WidthFlowAperturesStandardDeviation, structure.WidthFlowApertures.StandardDeviation.Value); + Assert.AreEqual(entity.InsideWaterLevelMean, structure.InsideWaterLevel.Mean.Value); + Assert.AreEqual(entity.InsideWaterLevelStandardDeviation, structure.InsideWaterLevel.StandardDeviation.Value); + Assert.AreEqual(entity.ThresholdHeightOpenWeirMean, structure.ThresholdHeightOpenWeir.Mean.Value); + Assert.AreEqual(entity.ThresholdHeightOpenWeirStandardDeviation, structure.ThresholdHeightOpenWeir.StandardDeviation.Value); + Assert.AreEqual(entity.CriticalOvertoppingDischargeMean, structure.CriticalOvertoppingDischarge.Mean.Value); + Assert.AreEqual(entity.CriticalOvertoppingDischargeCoefficientOfVariation, structure.CriticalOvertoppingDischarge.CoefficientOfVariation.Value); + Assert.AreEqual(entity.FlowWidthAtBottomProtectionMean, structure.FlowWidthAtBottomProtection.Mean.Value); + Assert.AreEqual(entity.FlowWidthAtBottomProtectionStandardDeviation, structure.FlowWidthAtBottomProtection.StandardDeviation.Value); + Assert.AreEqual(entity.ConstructiveStrengthLinearLoadModelMean, structure.ConstructiveStrengthLinearLoadModel.Mean.Value); + Assert.AreEqual(entity.ConstructiveStrengthLinearLoadModelCoefficientOfVariation, structure.ConstructiveStrengthLinearLoadModel.CoefficientOfVariation.Value); + Assert.AreEqual(entity.ConstructiveStrengthQuadraticLoadModelMean, structure.ConstructiveStrengthQuadraticLoadModel.Mean.Value); + Assert.AreEqual(entity.ConstructiveStrengthQuadraticLoadModelCoefficientOfVariation, structure.ConstructiveStrengthQuadraticLoadModel.CoefficientOfVariation.Value); + Assert.AreEqual(entity.BankWidthMean, structure.BankWidth.Mean.Value); + Assert.AreEqual(entity.BankWidthStandardDeviation, structure.BankWidth.StandardDeviation.Value); + Assert.AreEqual(entity.InsideWaterLevelFailureConstructionMean, structure.InsideWaterLevelFailureConstruction.Mean.Value); + Assert.AreEqual(entity.InsideWaterLevelFailureConstructionStandardDeviation, structure.InsideWaterLevelFailureConstruction.StandardDeviation.Value); + Assert.AreEqual(entity.EvaluationLevel, structure.EvaluationLevel.Value); + Assert.AreEqual(entity.LevelCrestStructureMean, structure.LevelCrestStructure.Mean.Value); + Assert.AreEqual(entity.LevelCrestStructureStandardDeviation, structure.LevelCrestStructure.StandardDeviation.Value); + Assert.AreEqual(entity.VerticalDistance, structure.VerticalDistance.Value); + Assert.AreEqual(entity.FailureProbabilityRepairClosure, structure.FailureProbabilityRepairClosure); + Assert.AreEqual(entity.FailureCollisionEnergyMean, structure.FailureCollisionEnergy.Mean.Value); + Assert.AreEqual(entity.FailureCollisionEnergyCoefficientOfVariation, structure.FailureCollisionEnergy.CoefficientOfVariation.Value); + Assert.AreEqual(entity.ShipMassMean, structure.ShipMass.Mean.Value); + Assert.AreEqual(entity.ShipMassCoefficientOfVariation, structure.ShipMass.CoefficientOfVariation.Value); + Assert.AreEqual(entity.ShipVelocityMean, structure.ShipVelocity.Mean.Value); + Assert.AreEqual(entity.ShipVelocityCoefficientOfVariation, structure.ShipVelocity.CoefficientOfVariation.Value); + Assert.AreEqual(entity.LevellingCount, structure.LevellingCount); + Assert.AreEqual(entity.ProbabilityCollisionSecondaryStructure, structure.ProbabilityCollisionSecondaryStructure); + Assert.AreEqual(entity.FlowVelocityStructureClosableMean, structure.FlowVelocityStructureClosable.Mean.Value); + Assert.AreEqual(entity.StabilityLinearLoadModelMean, structure.StabilityLinearLoadModel.Mean.Value); + Assert.AreEqual(entity.StabilityLinearLoadModelCoefficientOfVariation, structure.StabilityLinearLoadModel.CoefficientOfVariation.Value); + Assert.AreEqual(entity.StabilityQuadraticLoadModelMean, structure.StabilityQuadraticLoadModel.Mean.Value); + Assert.AreEqual(entity.StabilityQuadraticLoadModelCoefficientOfVariation, structure.StabilityQuadraticLoadModel.CoefficientOfVariation.Value); + Assert.AreEqual(entity.AreaFlowAperturesMean, structure.AreaFlowApertures.Mean.Value); + Assert.AreEqual(entity.AreaFlowAperturesStandardDeviation, structure.AreaFlowApertures.StandardDeviation.Value); + Assert.AreEqual((StabilityPointStructureInflowModelType) entity.InflowModelType, structure.InflowModelType); + } + + [Test] + public void Read_NullValues_ReturnStabilityPointStructureWithNaN() + { + // Setup + var entity = new StabilityPointStructureEntity + { + Name = "A", + Id = "B", + X = null, + Y = null, + StructureNormalOrientation = null, + StorageStructureAreaMean = null, + StorageStructureAreaCoefficientOfVariation = null, + AllowedLevelIncreaseStorageMean = null, + AllowedLevelIncreaseStorageStandardDeviation = null, + WidthFlowAperturesMean = null, + WidthFlowAperturesStandardDeviation = null, + InsideWaterLevelMean = null, + InsideWaterLevelStandardDeviation = null, + ThresholdHeightOpenWeirMean = null, + ThresholdHeightOpenWeirStandardDeviation = null, + CriticalOvertoppingDischargeMean = null, + CriticalOvertoppingDischargeCoefficientOfVariation = null, + FlowWidthAtBottomProtectionMean = null, + FlowWidthAtBottomProtectionStandardDeviation = null, + ConstructiveStrengthLinearLoadModelMean = null, + ConstructiveStrengthLinearLoadModelCoefficientOfVariation = null, + ConstructiveStrengthQuadraticLoadModelMean = null, + ConstructiveStrengthQuadraticLoadModelCoefficientOfVariation = null, + BankWidthMean = null, + BankWidthStandardDeviation = null, + InsideWaterLevelFailureConstructionMean = null, + InsideWaterLevelFailureConstructionStandardDeviation = null, + EvaluationLevel = null, + LevelCrestStructureMean = null, + LevelCrestStructureStandardDeviation = null, + VerticalDistance = null, + FailureProbabilityRepairClosure = null, + FailureCollisionEnergyMean = null, + FailureCollisionEnergyCoefficientOfVariation = null, + ShipMassMean = null, + ShipMassCoefficientOfVariation = null, + ShipVelocityMean = null, + ShipVelocityCoefficientOfVariation = null, + ProbabilityCollisionSecondaryStructure = null, + FlowVelocityStructureClosableMean = null, + StabilityLinearLoadModelMean = null, + StabilityLinearLoadModelCoefficientOfVariation = null, + AreaFlowAperturesMean = null, + AreaFlowAperturesStandardDeviation = null + }; + + var collector = new ReadConversionCollector(); + + // Call + StabilityPointStructure structure = entity.Read(collector); + + // Assert + Assert.IsNaN(structure.Location.X); + Assert.IsNaN(structure.Location.Y); + Assert.IsNaN(structure.StructureNormalOrientation); + + Assert.IsNaN(structure.StorageStructureArea.Mean); + Assert.IsNaN(structure.StorageStructureArea.CoefficientOfVariation); + Assert.IsNaN(structure.AllowedLevelIncreaseStorage.Mean); + Assert.IsNaN(structure.AllowedLevelIncreaseStorage.StandardDeviation); + Assert.IsNaN(structure.WidthFlowApertures.Mean); + Assert.IsNaN(structure.WidthFlowApertures.StandardDeviation); + Assert.IsNaN(structure.InsideWaterLevel.Mean); + Assert.IsNaN(structure.InsideWaterLevel.StandardDeviation); + Assert.IsNaN(structure.ThresholdHeightOpenWeir.Mean); + Assert.IsNaN(structure.ThresholdHeightOpenWeir.StandardDeviation); + Assert.IsNaN(structure.CriticalOvertoppingDischarge.Mean); + Assert.IsNaN(structure.CriticalOvertoppingDischarge.CoefficientOfVariation); + Assert.IsNaN(structure.FlowWidthAtBottomProtection.Mean); + Assert.IsNaN(structure.FlowWidthAtBottomProtection.StandardDeviation); + Assert.IsNaN(structure.ConstructiveStrengthLinearLoadModel.Mean); + Assert.IsNaN(structure.ConstructiveStrengthLinearLoadModel.CoefficientOfVariation); + Assert.IsNaN(structure.ConstructiveStrengthQuadraticLoadModel.Mean); + Assert.IsNaN(structure.ConstructiveStrengthQuadraticLoadModel.CoefficientOfVariation); + Assert.IsNaN(structure.BankWidth.Mean); + Assert.IsNaN(structure.BankWidth.StandardDeviation); + Assert.IsNaN(structure.InsideWaterLevelFailureConstruction.Mean); + Assert.IsNaN(structure.InsideWaterLevelFailureConstruction.StandardDeviation); + Assert.IsNaN(structure.EvaluationLevel); + Assert.IsNaN(structure.LevelCrestStructure.Mean); + Assert.IsNaN(structure.LevelCrestStructure.StandardDeviation); + Assert.IsNaN(structure.VerticalDistance); + Assert.IsNaN(structure.FailureProbabilityRepairClosure); + Assert.IsNaN(structure.FailureCollisionEnergy.Mean); + Assert.IsNaN(structure.FailureCollisionEnergy.CoefficientOfVariation); + Assert.IsNaN(structure.ShipMass.Mean); + Assert.IsNaN(structure.ShipMass.CoefficientOfVariation); + Assert.IsNaN(structure.ShipVelocity.Mean); + Assert.IsNaN(structure.ShipVelocity.CoefficientOfVariation); + Assert.IsNaN(structure.ProbabilityCollisionSecondaryStructure); + Assert.IsNaN(structure.FlowVelocityStructureClosable.Mean); + Assert.IsNaN(structure.StabilityLinearLoadModel.Mean); + Assert.IsNaN(structure.StabilityLinearLoadModel.CoefficientOfVariation); + Assert.IsNaN(structure.StabilityQuadraticLoadModel.Mean); + Assert.IsNaN(structure.StabilityQuadraticLoadModel.CoefficientOfVariation); + Assert.IsNaN(structure.AreaFlowApertures.Mean); + Assert.IsNaN(structure.AreaFlowApertures.StandardDeviation); + } + + [Test] + public void Read_EntityRegistered_ReturnRegisteredStructure() + { + // Setup + var entity = new StabilityPointStructureEntity(); + StabilityPointStructure registeredStructure = new TestStabilityPointStructure(); + var collector = new ReadConversionCollector(); + collector.Read(entity, registeredStructure); + + // Call + StabilityPointStructure readStructure = entity.Read(collector); + + // Assert + Assert.AreSame(registeredStructure, readStructure); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StabilityPointStructures/StabilityPointStructuresCalculationEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StabilityPointStructures/StabilityPointStructuresCalculationEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StabilityPointStructures/StabilityPointStructuresCalculationEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,422 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.StabilityPointStructures.Data; +using Ringtoets.StabilityPointStructures.Data.TestUtil; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Read.StabilityPointStructures; + +namespace Riskeer.Storage.Core.Test.Read.StabilityPointStructures +{ + [TestFixture] + public class StabilityPointStructuresCalculationEntityReadExtensionsTest + { + [Test] + public void Read_ReadConversionCollectorNull_ThrowArgumentNullException() + { + // Setup + var entity = new StabilityPointStructuresCalculationEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void Read_EntityNotReadBefore_RegisterEntity() + { + // Setup + var entity = new StabilityPointStructuresCalculationEntity(); + + var collector = new ReadConversionCollector(); + + // Precondition + Assert.IsFalse(collector.Contains(entity)); + + // Call + StructuresCalculation calculation = entity.Read(collector); + + // Assert + Assert.IsTrue(collector.Contains(entity)); + Assert.AreSame(calculation, collector.Get(entity)); + } + + [Test] + public void Read_ValidEntity_ReturnStabilityPointStructuresCalculation() + { + // Setup + var entity = new StabilityPointStructuresCalculationEntity + { + Name = "name", + Comments = "comments", + StructureNormalOrientation = 1.1, + AllowedLevelIncreaseStorageMean = 2.2, + AllowedLevelIncreaseStorageStandardDeviation = 3.3, + StorageStructureAreaMean = 4.4, + StorageStructureAreaCoefficientOfVariation = 5.5, + FlowWidthAtBottomProtectionMean = 6.6, + FlowWidthAtBottomProtectionStandardDeviation = 7.7, + CriticalOvertoppingDischargeMean = 8.8, + CriticalOvertoppingDischargeCoefficientOfVariation = 9.9, + FailureProbabilityStructureWithErosion = 0.10, + WidthFlowAperturesMean = 11.11, + WidthFlowAperturesStandardDeviation = 12.12, + StormDurationMean = 13.13, + UseBreakWater = Convert.ToByte(true), + BreakWaterType = Convert.ToByte(BreakWaterType.Wall), + BreakWaterHeight = 14.14, + UseForeshore = Convert.ToByte(true), + InsideWaterLevelMean = 15.15, + InsideWaterLevelStandardDeviation = 16.16, + ThresholdHeightOpenWeirMean = 17.17, + ThresholdHeightOpenWeirStandardDeviation = 18.18, + ConstructiveStrengthLinearLoadModelMean = 19.19, + ConstructiveStrengthLinearLoadModelCoefficientOfVariation = 20.20, + ConstructiveStrengthQuadraticLoadModelMean = 21.21, + ConstructiveStrengthQuadraticLoadModelCoefficientOfVariation = 22.22, + BankWidthMean = 23.23, + BankWidthStandardDeviation = 24.24, + InsideWaterLevelFailureConstructionMean = 25.25, + InsideWaterLevelFailureConstructionStandardDeviation = 26.26, + EvaluationLevel = 27.27, + LevelCrestStructureMean = 28.28, + LevelCrestStructureStandardDeviation = 29.29, + VerticalDistance = 30.30, + FailureProbabilityRepairClosure = 0.31, + FailureCollisionEnergyMean = 32.32, + FailureCollisionEnergyCoefficientOfVariation = 33.33, + ShipMassMean = 34.34, + ShipMassCoefficientOfVariation = 35.35, + ShipVelocityMean = 36.36, + ShipVelocityCoefficientOfVariation = 37.37, + LevellingCount = 38, + ProbabilityCollisionSecondaryStructure = 0.39, + FlowVelocityStructureClosableMean = 40.40, + StabilityLinearLoadModelMean = 41.41, + StabilityLinearLoadModelCoefficientOfVariation = 42.42, + StabilityQuadraticLoadModelMean = 43.43, + StabilityQuadraticLoadModelCoefficientOfVariation = 44.44, + AreaFlowAperturesMean = 45.45, + AreaFlowAperturesStandardDeviation = 46.46, + InflowModelType = Convert.ToByte(StabilityPointStructureInflowModelType.FloodedCulvert), + LoadSchematizationType = Convert.ToByte(LoadSchematizationType.Quadratic), + VolumicWeightWater = 47.47, + FactorStormDurationOpenStructure = 48.48, + DrainCoefficientMean = 49.49 + }; + var collector = new ReadConversionCollector(); + + // Call + StructuresCalculation calculation = entity.Read(collector); + + // Assert + Assert.AreEqual(entity.Name, calculation.Name); + Assert.AreEqual(entity.Comments, calculation.Comments.Body); + + StabilityPointStructuresInput inputParameters = calculation.InputParameters; + Assert.IsNull(inputParameters.ForeshoreProfile); + Assert.IsNull(inputParameters.Structure); + Assert.IsNull(inputParameters.HydraulicBoundaryLocation); + Assert.AreEqual(entity.StructureNormalOrientation, inputParameters.StructureNormalOrientation.Value); + Assert.AreEqual(entity.AllowedLevelIncreaseStorageMean, inputParameters.AllowedLevelIncreaseStorage.Mean.Value); + Assert.AreEqual(entity.AllowedLevelIncreaseStorageStandardDeviation, inputParameters.AllowedLevelIncreaseStorage.StandardDeviation.Value); + Assert.AreEqual(entity.StorageStructureAreaMean, inputParameters.StorageStructureArea.Mean.Value); + Assert.AreEqual(entity.StorageStructureAreaCoefficientOfVariation, inputParameters.StorageStructureArea.CoefficientOfVariation.Value); + Assert.AreEqual(entity.FlowWidthAtBottomProtectionMean, inputParameters.FlowWidthAtBottomProtection.Mean.Value); + Assert.AreEqual(entity.FlowWidthAtBottomProtectionStandardDeviation, inputParameters.FlowWidthAtBottomProtection.StandardDeviation.Value); + Assert.AreEqual(entity.CriticalOvertoppingDischargeMean, inputParameters.CriticalOvertoppingDischarge.Mean.Value); + Assert.AreEqual(entity.CriticalOvertoppingDischargeCoefficientOfVariation, inputParameters.CriticalOvertoppingDischarge.CoefficientOfVariation.Value); + Assert.AreEqual(entity.FailureProbabilityStructureWithErosion, inputParameters.FailureProbabilityStructureWithErosion); + Assert.AreEqual(entity.WidthFlowAperturesMean, inputParameters.WidthFlowApertures.Mean.Value); + Assert.AreEqual(entity.WidthFlowAperturesStandardDeviation, inputParameters.WidthFlowApertures.StandardDeviation.Value); + Assert.AreEqual(entity.StormDurationMean, inputParameters.StormDuration.Mean.Value); + Assert.AreEqual(Convert.ToBoolean(entity.UseBreakWater), inputParameters.UseBreakWater); + Assert.AreEqual((BreakWaterType) entity.BreakWaterType, inputParameters.BreakWater.Type); + Assert.AreEqual(entity.BreakWaterHeight, inputParameters.BreakWater.Height.Value); + Assert.AreEqual(Convert.ToBoolean(entity.UseForeshore), inputParameters.UseForeshore); + + Assert.AreEqual(entity.InsideWaterLevelMean, inputParameters.InsideWaterLevel.Mean.Value); + Assert.AreEqual(entity.InsideWaterLevelStandardDeviation, inputParameters.InsideWaterLevel.StandardDeviation.Value); + Assert.AreEqual(entity.ThresholdHeightOpenWeirMean, inputParameters.ThresholdHeightOpenWeir.Mean.Value); + Assert.AreEqual(entity.ThresholdHeightOpenWeirStandardDeviation, inputParameters.ThresholdHeightOpenWeir.StandardDeviation.Value); + Assert.AreEqual(entity.ConstructiveStrengthLinearLoadModelMean, inputParameters.ConstructiveStrengthLinearLoadModel.Mean.Value); + Assert.AreEqual(entity.ConstructiveStrengthLinearLoadModelCoefficientOfVariation, inputParameters.ConstructiveStrengthLinearLoadModel.CoefficientOfVariation.Value); + Assert.AreEqual(entity.ConstructiveStrengthQuadraticLoadModelMean, inputParameters.ConstructiveStrengthQuadraticLoadModel.Mean.Value); + Assert.AreEqual(entity.ConstructiveStrengthQuadraticLoadModelCoefficientOfVariation, inputParameters.ConstructiveStrengthQuadraticLoadModel.CoefficientOfVariation.Value); + Assert.AreEqual(entity.BankWidthMean, inputParameters.BankWidth.Mean.Value); + Assert.AreEqual(entity.BankWidthStandardDeviation, inputParameters.BankWidth.StandardDeviation.Value); + Assert.AreEqual(entity.InsideWaterLevelFailureConstructionMean, inputParameters.InsideWaterLevelFailureConstruction.Mean.Value); + Assert.AreEqual(entity.InsideWaterLevelFailureConstructionStandardDeviation, inputParameters.InsideWaterLevelFailureConstruction.StandardDeviation.Value); + Assert.AreEqual(entity.EvaluationLevel, inputParameters.EvaluationLevel.Value); + Assert.AreEqual(entity.LevelCrestStructureMean, inputParameters.LevelCrestStructure.Mean.Value); + Assert.AreEqual(entity.LevelCrestStructureStandardDeviation, inputParameters.LevelCrestStructure.StandardDeviation.Value); + Assert.AreEqual(entity.VerticalDistance, inputParameters.VerticalDistance.Value); + Assert.AreEqual(entity.FailureProbabilityRepairClosure, inputParameters.FailureProbabilityRepairClosure); + Assert.AreEqual(entity.FailureCollisionEnergyMean, inputParameters.FailureCollisionEnergy.Mean.Value); + Assert.AreEqual(entity.FailureCollisionEnergyCoefficientOfVariation, inputParameters.FailureCollisionEnergy.CoefficientOfVariation.Value); + Assert.AreEqual(entity.ShipMassMean, inputParameters.ShipMass.Mean.Value); + Assert.AreEqual(entity.ShipMassCoefficientOfVariation, inputParameters.ShipMass.CoefficientOfVariation.Value); + Assert.AreEqual(entity.ShipVelocityMean, inputParameters.ShipVelocity.Mean.Value); + Assert.AreEqual(entity.ShipVelocityCoefficientOfVariation, inputParameters.ShipVelocity.CoefficientOfVariation.Value); + Assert.AreEqual(entity.LevellingCount, inputParameters.LevellingCount); + Assert.AreEqual(entity.ProbabilityCollisionSecondaryStructure, inputParameters.ProbabilityCollisionSecondaryStructure); + Assert.AreEqual(entity.FlowVelocityStructureClosableMean, inputParameters.FlowVelocityStructureClosable.Mean.Value); + Assert.AreEqual(entity.StabilityLinearLoadModelMean, inputParameters.StabilityLinearLoadModel.Mean.Value); + Assert.AreEqual(entity.StabilityLinearLoadModelCoefficientOfVariation, inputParameters.StabilityLinearLoadModel.CoefficientOfVariation.Value); + Assert.AreEqual(entity.StabilityQuadraticLoadModelMean, inputParameters.StabilityQuadraticLoadModel.Mean.Value); + Assert.AreEqual(entity.StabilityQuadraticLoadModelCoefficientOfVariation, inputParameters.StabilityQuadraticLoadModel.CoefficientOfVariation.Value); + Assert.AreEqual(entity.AreaFlowAperturesMean, inputParameters.AreaFlowApertures.Mean.Value); + Assert.AreEqual(entity.AreaFlowAperturesStandardDeviation, inputParameters.AreaFlowApertures.StandardDeviation.Value); + Assert.AreEqual((StabilityPointStructureInflowModelType) entity.InflowModelType, inputParameters.InflowModelType); + Assert.AreEqual((LoadSchematizationType) entity.LoadSchematizationType, inputParameters.LoadSchematizationType); + Assert.AreEqual(entity.VolumicWeightWater, inputParameters.VolumicWeightWater.Value); + Assert.AreEqual(entity.FactorStormDurationOpenStructure, inputParameters.FactorStormDurationOpenStructure.Value); + Assert.AreEqual(entity.DrainCoefficientMean, inputParameters.DrainCoefficient.Mean.Value); + Assert.IsFalse(calculation.HasOutput); + } + + [Test] + public void Read_EntityWithNullParameters_ReturnStabilityPointStructuresCalculationWithInputParametersNaN() + { + // Setup + var entity = new StabilityPointStructuresCalculationEntity + { + StructureNormalOrientation = null, + AllowedLevelIncreaseStorageMean = null, + AllowedLevelIncreaseStorageStandardDeviation = null, + StorageStructureAreaMean = null, + StorageStructureAreaCoefficientOfVariation = null, + FlowWidthAtBottomProtectionMean = null, + FlowWidthAtBottomProtectionStandardDeviation = null, + CriticalOvertoppingDischargeMean = null, + CriticalOvertoppingDischargeCoefficientOfVariation = null, + WidthFlowAperturesMean = null, + WidthFlowAperturesStandardDeviation = null, + StormDurationMean = null, + BreakWaterHeight = null, + InsideWaterLevelMean = null, + InsideWaterLevelStandardDeviation = null, + ThresholdHeightOpenWeirMean = null, + ThresholdHeightOpenWeirStandardDeviation = null, + ConstructiveStrengthLinearLoadModelMean = null, + ConstructiveStrengthLinearLoadModelCoefficientOfVariation = null, + ConstructiveStrengthQuadraticLoadModelMean = null, + ConstructiveStrengthQuadraticLoadModelCoefficientOfVariation = null, + BankWidthMean = null, + BankWidthStandardDeviation = null, + InsideWaterLevelFailureConstructionMean = null, + InsideWaterLevelFailureConstructionStandardDeviation = null, + EvaluationLevel = null, + LevelCrestStructureMean = null, + LevelCrestStructureStandardDeviation = null, + VerticalDistance = null, + FailureCollisionEnergyMean = null, + FailureCollisionEnergyCoefficientOfVariation = null, + ShipMassMean = null, + ShipMassCoefficientOfVariation = null, + ShipVelocityMean = null, + ShipVelocityCoefficientOfVariation = null, + FlowVelocityStructureClosableMean = null, + StabilityLinearLoadModelMean = null, + StabilityLinearLoadModelCoefficientOfVariation = null, + StabilityQuadraticLoadModelMean = null, + StabilityQuadraticLoadModelCoefficientOfVariation = null, + AreaFlowAperturesMean = null, + AreaFlowAperturesStandardDeviation = null, + VolumicWeightWater = null, + FactorStormDurationOpenStructure = null, + DrainCoefficientMean = null + }; + var collector = new ReadConversionCollector(); + + // Call + StructuresCalculation calculation = entity.Read(collector); + + // Assert + StabilityPointStructuresInput inputParameters = calculation.InputParameters; + Assert.IsNaN(inputParameters.StructureNormalOrientation); + Assert.IsNaN(inputParameters.AllowedLevelIncreaseStorage.Mean); + Assert.IsNaN(inputParameters.AllowedLevelIncreaseStorage.StandardDeviation); + Assert.IsNaN(inputParameters.StorageStructureArea.Mean); + Assert.IsNaN(inputParameters.StorageStructureArea.CoefficientOfVariation); + Assert.IsNaN(inputParameters.FlowWidthAtBottomProtection.Mean); + Assert.IsNaN(inputParameters.FlowWidthAtBottomProtection.StandardDeviation); + Assert.IsNaN(inputParameters.CriticalOvertoppingDischarge.Mean); + Assert.IsNaN(inputParameters.CriticalOvertoppingDischarge.CoefficientOfVariation); + Assert.IsNaN(inputParameters.WidthFlowApertures.Mean); + Assert.IsNaN(inputParameters.WidthFlowApertures.StandardDeviation); + Assert.IsNaN(inputParameters.StormDuration.Mean); + Assert.IsNaN(inputParameters.BreakWater.Height); + + Assert.IsNaN(inputParameters.InsideWaterLevel.Mean); + Assert.IsNaN(inputParameters.InsideWaterLevel.StandardDeviation); + Assert.IsNaN(inputParameters.ThresholdHeightOpenWeir.Mean); + Assert.IsNaN(inputParameters.ThresholdHeightOpenWeir.StandardDeviation); + Assert.IsNaN(inputParameters.ConstructiveStrengthLinearLoadModel.Mean); + Assert.IsNaN(inputParameters.ConstructiveStrengthLinearLoadModel.CoefficientOfVariation); + Assert.IsNaN(inputParameters.ConstructiveStrengthQuadraticLoadModel.Mean); + Assert.IsNaN(inputParameters.ConstructiveStrengthQuadraticLoadModel.CoefficientOfVariation); + Assert.IsNaN(inputParameters.BankWidth.Mean); + Assert.IsNaN(inputParameters.BankWidth.StandardDeviation); + Assert.IsNaN(inputParameters.InsideWaterLevelFailureConstruction.Mean); + Assert.IsNaN(inputParameters.InsideWaterLevelFailureConstruction.StandardDeviation); + Assert.IsNaN(inputParameters.EvaluationLevel); + Assert.IsNaN(inputParameters.LevelCrestStructure.Mean); + Assert.IsNaN(inputParameters.LevelCrestStructure.StandardDeviation); + Assert.IsNaN(inputParameters.VerticalDistance); + Assert.IsNaN(inputParameters.FailureCollisionEnergy.Mean); + Assert.IsNaN(inputParameters.FailureCollisionEnergy.CoefficientOfVariation); + Assert.IsNaN(inputParameters.ShipMass.Mean); + Assert.IsNaN(inputParameters.ShipMass.CoefficientOfVariation); + Assert.IsNaN(inputParameters.ShipVelocity.Mean); + Assert.IsNaN(inputParameters.ShipVelocity.CoefficientOfVariation); + Assert.IsNaN(inputParameters.FlowVelocityStructureClosable.Mean); + Assert.IsNaN(inputParameters.StabilityLinearLoadModel.Mean); + Assert.IsNaN(inputParameters.StabilityLinearLoadModel.CoefficientOfVariation); + Assert.IsNaN(inputParameters.StabilityQuadraticLoadModel.Mean); + Assert.IsNaN(inputParameters.StabilityQuadraticLoadModel.CoefficientOfVariation); + Assert.IsNaN(inputParameters.AreaFlowApertures.Mean); + Assert.IsNaN(inputParameters.AreaFlowApertures.StandardDeviation); + Assert.IsNaN(inputParameters.VolumicWeightWater); + Assert.IsNaN(inputParameters.FactorStormDurationOpenStructure); + Assert.IsNaN(inputParameters.DrainCoefficient.Mean); + } + + [Test] + public void Read_EntityWithStructureEntity_ReturnCalculationWithStructure() + { + // Setup + StabilityPointStructure structure = new TestStabilityPointStructure(); + var structureEntity = new StabilityPointStructureEntity(); + var entity = new StabilityPointStructuresCalculationEntity + { + StabilityPointStructureEntity = structureEntity + }; + var collector = new ReadConversionCollector(); + collector.Read(structureEntity, structure); + + // Call + StructuresCalculation calculation = entity.Read(collector); + + // Assert + Assert.AreSame(structure, calculation.InputParameters.Structure); + } + + [Test] + public void Read_EntityWithHydraulicLocationEntity_ReturnCalculationWithHydraulicBoundaryLocation() + { + // Setup + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "A", 2, 3); + var hydraulicLocationEntity = new HydraulicLocationEntity(); + var entity = new StabilityPointStructuresCalculationEntity + { + HydraulicLocationEntity = hydraulicLocationEntity + }; + + var collector = new ReadConversionCollector(); + collector.Read(hydraulicLocationEntity, hydraulicBoundaryLocation); + + // Call + StructuresCalculation calculation = entity.Read(collector); + + // Assert + Assert.AreSame(hydraulicBoundaryLocation, calculation.InputParameters.HydraulicBoundaryLocation); + } + + [Test] + public void Read_EntityWithForeshoreProfileEntity_ReturnCalculationWithForeshoreProfile() + { + // Setup + var profile = new TestForeshoreProfile(); + var profileEntity = new ForeshoreProfileEntity(); + var entity = new StabilityPointStructuresCalculationEntity + { + ForeshoreProfileEntity = profileEntity + }; + + var collector = new ReadConversionCollector(); + collector.Read(profileEntity, profile); + + // Call + StructuresCalculation calculation = entity.Read(collector); + + // Assert + Assert.AreSame(profile, calculation.InputParameters.ForeshoreProfile); + } + + [Test] + public void Read_ValidEntityWithOutputEntity_ReturnCalculationWithOutput() + { + // Setup + var entity = new StabilityPointStructuresCalculationEntity + { + StabilityPointStructuresOutputEntities = + { + new StabilityPointStructuresOutputEntity() + } + }; + + var collector = new ReadConversionCollector(); + + // Call + StructuresCalculation calculation = entity.Read(collector); + + // Assert + StructuresOutput calculationOutput = calculation.Output; + Assert.IsNaN(calculationOutput.Reliability); + Assert.IsFalse(calculationOutput.HasGeneralResult); + } + + [Test] + public void Read_CalculationEntityAlreadyRead_ReturnReadCalculation() + { + // Setup + var entity = new StabilityPointStructuresCalculationEntity + { + StabilityPointStructuresOutputEntities = + { + new StabilityPointStructuresOutputEntity() + } + }; + + var calculation = new StructuresCalculation(); + + var collector = new ReadConversionCollector(); + collector.Read(entity, calculation); + + // Call + StructuresCalculation returnedCalculation = entity.Read(collector); + + // Assert + Assert.AreSame(calculation, returnedCalculation); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StabilityPointStructures/StabilityPointStructuresFailureMechanismMetaEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StabilityPointStructures/StabilityPointStructuresFailureMechanismMetaEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StabilityPointStructures/StabilityPointStructuresFailureMechanismMetaEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,62 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.StabilityPointStructures.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.StabilityPointStructures; + +namespace Riskeer.Storage.Core.Test.Read.StabilityPointStructures +{ + [TestFixture] + public class StabilityPointStructuresFailureMechanismMetaEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => ((StabilityPointStructuresFailureMechanismMetaEntity) null).Read(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_Always_ReturnGeneralStabilityPointStructuresInput() + { + // Setup + var entity = new StabilityPointStructuresFailureMechanismMetaEntity + { + N = new Random(39).NextRoundedDouble(1.0, 20.0) + }; + + // Call + GeneralStabilityPointStructuresInput generalInput = entity.Read(); + + // Assert + Assert.AreEqual(entity.N, generalInput.N, generalInput.N.GetAccuracy()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StabilityPointStructures/StabilityPointStructuresSectionResultEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StabilityPointStructures/StabilityPointStructuresSectionResultEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StabilityPointStructures/StabilityPointStructuresSectionResultEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,167 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.StabilityPointStructures.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Read.StabilityPointStructures; + +namespace Riskeer.Storage.Core.Test.Read.StabilityPointStructures +{ + [TestFixture] + public class StabilityPointStructuresSectionResultEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((StabilityPointStructuresSectionResultEntity) null).Read( + new StabilityPointStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), + new ReadConversionCollector()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_SectionResultNull_ThrowsArgumentNullException() + { + // Setup + var entity = new StabilityPointStructuresSectionResultEntity(); + + // Call + TestDelegate call = () => entity.Read(null, new ReadConversionCollector()); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("sectionResult", paramName); + } + + [Test] + public void Read_CollectorNull_ThrowsArgumentNullException() + { + // Setup + var entity = new StabilityPointStructuresSectionResultEntity(); + + // Call + TestDelegate call = () => entity.Read(new StabilityPointStructuresFailureMechanismSectionResult( + FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void Read_ParameterValues_SectionResultWithParameterValues() + { + // Setup + var random = new Random(21); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResult = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + double tailorMadeAssessmentProbability = random.NextDouble(); + bool useManualAssembly = random.NextBoolean(); + double manualAssemblyProbability = random.NextDouble(); + + var collector = new ReadConversionCollector(); + + var failureMechanismSectionEntity = new FailureMechanismSectionEntity(); + collector.Read(failureMechanismSectionEntity, FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + var entity = new StabilityPointStructuresSectionResultEntity + { + FailureMechanismSectionEntity = failureMechanismSectionEntity, + SimpleAssessmentResult = Convert.ToByte(simpleAssessmentResult), + DetailedAssessmentResult = Convert.ToByte(detailedAssessmentResult), + TailorMadeAssessmentResult = Convert.ToByte(tailorMadeAssessmentResult), + TailorMadeAssessmentProbability = tailorMadeAssessmentProbability, + UseManualAssembly = Convert.ToByte(useManualAssembly), + ManualAssemblyProbability = manualAssemblyProbability + }; + var sectionResult = new StabilityPointStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult, collector); + + // Assert + Assert.AreEqual(simpleAssessmentResult, sectionResult.SimpleAssessmentResult); + Assert.AreEqual(detailedAssessmentResult, sectionResult.DetailedAssessmentResult); + Assert.AreEqual(tailorMadeAssessmentResult, sectionResult.TailorMadeAssessmentResult); + Assert.AreEqual(tailorMadeAssessmentProbability, sectionResult.TailorMadeAssessmentProbability, 1e-6); + Assert.AreEqual(useManualAssembly, sectionResult.UseManualAssembly); + Assert.AreEqual(manualAssemblyProbability, sectionResult.ManualAssemblyProbability, 1e-6); + Assert.IsNull(sectionResult.Calculation); + } + + [Test] + public void Read_EntityWithNullValues_SectionResultWithNaNValues() + { + // Setup + var collector = new ReadConversionCollector(); + + var failureMechanismSectionEntity = new FailureMechanismSectionEntity(); + collector.Read(failureMechanismSectionEntity, FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + var entity = new StabilityPointStructuresSectionResultEntity + { + FailureMechanismSectionEntity = failureMechanismSectionEntity + }; + var sectionResult = new StabilityPointStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult, collector); + + // Assert + Assert.IsNaN(sectionResult.TailorMadeAssessmentProbability); + Assert.IsNaN(sectionResult.ManualAssemblyProbability); + Assert.IsNull(sectionResult.Calculation); + } + + [Test] + public void Read_CalculationEntitySet_ReturnStabilityPointStructuresSectionResultWithCalculation() + { + // Setup + var calculation = new StructuresCalculation(); + var calculationEntity = new StabilityPointStructuresCalculationEntity(); + + var collector = new ReadConversionCollector(); + collector.Read(calculationEntity, calculation); + + var entity = new StabilityPointStructuresSectionResultEntity + { + StabilityPointStructuresCalculationEntity = calculationEntity + }; + var sectionResult = new StabilityPointStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult, collector); + + // Assert + Assert.AreSame(calculation, sectionResult.Calculation); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StabilityStoneCover/StabilityStoneCoverFailureMechanismMetaEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StabilityStoneCover/StabilityStoneCoverFailureMechanismMetaEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StabilityStoneCover/StabilityStoneCoverFailureMechanismMetaEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,62 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.StabilityStoneCover.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.StabilityStoneCover; + +namespace Riskeer.Storage.Core.Test.Read.StabilityStoneCover +{ + [TestFixture] + public class StabilityStoneCoverFailureMechanismMetaEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => ((StabilityStoneCoverFailureMechanismMetaEntity) null).Read(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_Always_ReturnGeneralStabilityStoneCoverWaveConditionsInput() + { + // Setup + var entity = new StabilityStoneCoverFailureMechanismMetaEntity + { + N = new Random(39).NextRoundedDouble(1.0, 20.0) + }; + + // Call + GeneralStabilityStoneCoverWaveConditionsInput generalInput = entity.Read(); + + // Assert + Assert.AreEqual(entity.N, generalInput.N, generalInput.N.GetAccuracy()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StabilityStoneCover/StabilityStoneCoverSectionResultEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StabilityStoneCover/StabilityStoneCoverSectionResultEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StabilityStoneCover/StabilityStoneCoverSectionResultEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,109 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.AssemblyTool.Data; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.StabilityStoneCover.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.StabilityStoneCover; + +namespace Riskeer.Storage.Core.Test.Read.StabilityStoneCover +{ + [TestFixture] + public class StabilityStoneCoverSectionResultEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((StabilityStoneCoverSectionResultEntity) null).Read( + new StabilityStoneCoverFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection())); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_SectionResultNull_ThrowsArgumentNullException() + { + // Setup + var entity = new StabilityStoneCoverSectionResultEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("sectionResult", paramName); + } + + [Test] + public void Read_ParameterValues_SectionResultWithParameterValues() + { + // Setup + var random = new Random(21); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResultForFactorizedSignalingNorm = random.NextEnumValue(); + var detailedAssessmentResultForSignalingNorm = random.NextEnumValue(); + var detailedAssessmentResultForMechanismSpecificLowerLimitNorm = random.NextEnumValue(); + var detailedAssessmentResultForLowerLimitNorm = random.NextEnumValue(); + var detailedAssessmentResultForFactorizedLowerLimitNorm = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + bool useManualAssembly = random.NextBoolean(); + var manualAssemblyCategoryGroup = random.NextEnumValue(); + + var entity = new StabilityStoneCoverSectionResultEntity + { + FailureMechanismSectionEntity = new FailureMechanismSectionEntity(), + SimpleAssessmentResult = Convert.ToByte(simpleAssessmentResult), + DetailedAssessmentResultForFactorizedSignalingNorm = Convert.ToByte(detailedAssessmentResultForFactorizedSignalingNorm), + DetailedAssessmentResultForSignalingNorm = Convert.ToByte(detailedAssessmentResultForSignalingNorm), + DetailedAssessmentResultForMechanismSpecificLowerLimitNorm = Convert.ToByte(detailedAssessmentResultForMechanismSpecificLowerLimitNorm), + DetailedAssessmentResultForLowerLimitNorm = Convert.ToByte(detailedAssessmentResultForLowerLimitNorm), + DetailedAssessmentResultForFactorizedLowerLimitNorm = Convert.ToByte(detailedAssessmentResultForFactorizedLowerLimitNorm), + TailorMadeAssessmentResult = Convert.ToByte(tailorMadeAssessmentResult), + UseManualAssembly = Convert.ToByte(useManualAssembly), + ManualAssemblyCategoryGroup = Convert.ToByte(manualAssemblyCategoryGroup) + }; + + var sectionResult = new StabilityStoneCoverFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult); + + // Assert + Assert.AreEqual(simpleAssessmentResult, sectionResult.SimpleAssessmentResult); + Assert.AreEqual(detailedAssessmentResultForFactorizedSignalingNorm, sectionResult.DetailedAssessmentResultForFactorizedSignalingNorm); + Assert.AreEqual(detailedAssessmentResultForSignalingNorm, sectionResult.DetailedAssessmentResultForSignalingNorm); + Assert.AreEqual(detailedAssessmentResultForMechanismSpecificLowerLimitNorm, sectionResult.DetailedAssessmentResultForMechanismSpecificLowerLimitNorm); + Assert.AreEqual(detailedAssessmentResultForLowerLimitNorm, sectionResult.DetailedAssessmentResultForLowerLimitNorm); + Assert.AreEqual(detailedAssessmentResultForFactorizedLowerLimitNorm, sectionResult.DetailedAssessmentResultForFactorizedLowerLimitNorm); + Assert.AreEqual(tailorMadeAssessmentResult, sectionResult.TailorMadeAssessmentResult); + Assert.AreEqual(useManualAssembly, sectionResult.UseManualAssembly); + Assert.AreEqual(manualAssemblyCategoryGroup, sectionResult.ManualAssemblyCategoryGroup); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StabilityStoneCover/StabilityStoneCoverWaveConditionsCalculationEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StabilityStoneCover/StabilityStoneCoverWaveConditionsCalculationEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StabilityStoneCover/StabilityStoneCoverWaveConditionsCalculationEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,308 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Revetment.Data; +using Ringtoets.StabilityStoneCover.Data; +using Ringtoets.Storage.Core.TestUtil.Hydraulics; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Read.StabilityStoneCover; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Read.StabilityStoneCover +{ + [TestFixture] + public class StabilityStoneCoverWaveConditionsCalculationEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((StabilityStoneCoverWaveConditionsCalculationEntity) null).Read(new ReadConversionCollector()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_CollectorIsNull_ThrowArgumentNullException() + { + // Setup + var entity = new StabilityStoneCoverWaveConditionsCalculationEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void Read_ValidEntity_ReturnCalculation() + { + // Setup + const string name = "Calculation Name"; + const string comments = "Calculation Comment"; + + var random = new Random(21); + double orientation = random.NextDouble(); + bool useBreakWater = random.NextBoolean(); + var breakWaterType = random.NextEnumValue(); + double breakWaterHeight = random.NextDouble(); + bool useForeshore = random.NextBoolean(); + const double lowerBoundaryRevetment = 3.58; + const double upperBoundaryRevetment = 6.10; + const double lowerBoundaryWaterLevels = 3.40; + const double upperBoundaryWaterLevels = 5.88; + var stepSize = random.NextEnumValue(); + var categoryType = random.NextEnumValue(); + + var entity = new StabilityStoneCoverWaveConditionsCalculationEntity + { + Name = name, + Comments = comments, + UseBreakWater = Convert.ToByte(useBreakWater), + BreakWaterType = Convert.ToByte(breakWaterType), + BreakWaterHeight = breakWaterHeight, + UseForeshore = Convert.ToByte(useForeshore), + Orientation = orientation, + UpperBoundaryRevetment = upperBoundaryRevetment, + LowerBoundaryRevetment = lowerBoundaryRevetment, + UpperBoundaryWaterLevels = upperBoundaryWaterLevels, + LowerBoundaryWaterLevels = lowerBoundaryWaterLevels, + StepSize = Convert.ToByte(stepSize), + CategoryType = Convert.ToByte(categoryType) + }; + + var collector = new ReadConversionCollector(); + + // Call + StabilityStoneCoverWaveConditionsCalculation calculation = entity.Read(collector); + + // Assert + Assert.AreEqual(name, calculation.Name); + Assert.AreEqual(comments, calculation.Comments.Body); + + AssessmentSectionCategoryWaveConditionsInput calculationInput = calculation.InputParameters; + Assert.AreEqual(useBreakWater, calculationInput.UseBreakWater); + Assert.AreEqual(breakWaterType, calculationInput.BreakWater.Type); + AssertRoundedDouble(breakWaterHeight, calculationInput.BreakWater.Height); + Assert.AreEqual(useForeshore, calculationInput.UseForeshore); + AssertRoundedDouble(orientation, calculationInput.Orientation); + AssertRoundedDouble(upperBoundaryRevetment, calculationInput.UpperBoundaryRevetment); + AssertRoundedDouble(lowerBoundaryRevetment, calculationInput.LowerBoundaryRevetment); + AssertRoundedDouble(upperBoundaryWaterLevels, calculationInput.UpperBoundaryWaterLevels); + AssertRoundedDouble(lowerBoundaryWaterLevels, calculationInput.LowerBoundaryWaterLevels); + Assert.AreEqual(stepSize, calculationInput.StepSize); + Assert.AreEqual(categoryType, calculationInput.CategoryType); + + Assert.IsNull(calculationInput.HydraulicBoundaryLocation); + Assert.IsNull(calculationInput.ForeshoreProfile); + Assert.IsNull(calculation.Output); + } + + [Test] + public void Read_EntityWithNullValues_ReturnCalculationWithNaNValues() + { + // Setup + var entity = new StabilityStoneCoverWaveConditionsCalculationEntity(); + var collector = new ReadConversionCollector(); + + // Call + StabilityStoneCoverWaveConditionsCalculation calculation = entity.Read(collector); + + // Assert + Assert.IsNull(calculation.Name); + Assert.IsNull(calculation.Comments.Body); + + AssessmentSectionCategoryWaveConditionsInput calculationInput = calculation.InputParameters; + Assert.IsNaN(calculationInput.BreakWater.Height); + Assert.IsNaN(calculationInput.Orientation); + Assert.IsNaN(calculationInput.UpperBoundaryRevetment); + Assert.IsNaN(calculationInput.LowerBoundaryRevetment); + Assert.IsNaN(calculationInput.UpperBoundaryWaterLevels); + Assert.IsNaN(calculationInput.LowerBoundaryWaterLevels); + + Assert.IsNull(calculationInput.HydraulicBoundaryLocation); + Assert.IsNull(calculationInput.ForeshoreProfile); + Assert.IsNull(calculation.Output); + } + + [Test] + public void Read_EntityWithForeshoreProfileInCollector_CalculationHasAlreadyReadForeshoreProfile() + { + // Setup + var foreshoreProfile = new TestForeshoreProfile(); + var foreshoreProfileEntity = new ForeshoreProfileEntity + { + GeometryXml = new Point2DCollectionXmlSerializer().ToXml(Enumerable.Empty()) + }; + var entity = new StabilityStoneCoverWaveConditionsCalculationEntity + { + ForeshoreProfileEntity = foreshoreProfileEntity + }; + + var collector = new ReadConversionCollector(); + collector.Read(foreshoreProfileEntity, foreshoreProfile); + + // Call + StabilityStoneCoverWaveConditionsCalculation calculation = entity.Read(collector); + + // Assert + Assert.AreSame(foreshoreProfile, calculation.InputParameters.ForeshoreProfile); + } + + [Test] + public void Read_EntityWithForeshoreProfileNotYetInCollector_CalculationWithCreatedForeshoreProfileAndRegisteredNewEntities() + { + // Setup + const string id = "profile"; + var foreshoreProfileEntity = new ForeshoreProfileEntity + { + Id = id, + GeometryXml = new Point2DCollectionXmlSerializer().ToXml(Enumerable.Empty()) + }; + + var entity = new StabilityStoneCoverWaveConditionsCalculationEntity + { + ForeshoreProfileEntity = foreshoreProfileEntity + }; + + var collector = new ReadConversionCollector(); + + // Call + StabilityStoneCoverWaveConditionsCalculation calculation = entity.Read(collector); + + // Assert + Assert.IsTrue(collector.Contains(foreshoreProfileEntity)); + CollectionAssert.AreEqual(id, calculation.InputParameters.ForeshoreProfile.Id); + } + + [Test] + public void Read_EntityWithHydraulicBoundaryLocationInCollector_CalculationHasAlreadyReadHydraulicBoundaryLocation() + { + // Setup + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "A", 1.1, 2.2); + var hydraulicLocationEntity = new HydraulicLocationEntity(); + var entity = new StabilityStoneCoverWaveConditionsCalculationEntity + { + HydraulicLocationEntity = hydraulicLocationEntity + }; + + var collector = new ReadConversionCollector(); + collector.Read(hydraulicLocationEntity, hydraulicBoundaryLocation); + + // Call + StabilityStoneCoverWaveConditionsCalculation calculation = entity.Read(collector); + + // Assert + Assert.AreSame(hydraulicBoundaryLocation, calculation.InputParameters.HydraulicBoundaryLocation); + } + + [Test] + public void Read_EntityWithHydraulicBoundaryLocationNotYetInCollector_CalculationWithCreatedHydraulicBoundaryLocationAndRegisteredNewEntities() + { + // Setup + HydraulicLocationEntity hydraulicLocationEntity = HydraulicLocationEntityTestFactory.CreateHydraulicLocationEntity(); + var entity = new StabilityStoneCoverWaveConditionsCalculationEntity + { + HydraulicLocationEntity = hydraulicLocationEntity + }; + + var collector = new ReadConversionCollector(); + + // Call + entity.Read(collector); + + // Assert + Assert.IsTrue(collector.Contains(hydraulicLocationEntity)); + } + + [Test] + public void Read_EntityWithCalculationOutputEntity_CalculationWithOutput() + { + // Setup + const double outputALevel = 5.4; + const double outputBLevel = 2.3; + const double outputCLevel = 13.2; + var entity = new StabilityStoneCoverWaveConditionsCalculationEntity + { + StabilityStoneCoverWaveConditionsOutputEntities = + { + new StabilityStoneCoverWaveConditionsOutputEntity + { + CalculationConvergence = Convert.ToByte(CalculationConvergence.NotCalculated), + WaterLevel = outputBLevel, + Order = 1, + OutputType = Convert.ToByte(WaveConditionsOutputType.Columns) + }, + new StabilityStoneCoverWaveConditionsOutputEntity + { + CalculationConvergence = Convert.ToByte(CalculationConvergence.NotCalculated), + WaterLevel = outputCLevel, + Order = 2, + OutputType = Convert.ToByte(WaveConditionsOutputType.Blocks) + }, + new StabilityStoneCoverWaveConditionsOutputEntity + { + CalculationConvergence = Convert.ToByte(CalculationConvergence.NotCalculated), + WaterLevel = outputALevel, + Order = 0, + OutputType = Convert.ToByte(WaveConditionsOutputType.Columns) + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + StabilityStoneCoverWaveConditionsCalculation calculation = entity.Read(collector); + + // Assert + Assert.IsNotNull(calculation.Output); + double accuracy = calculation.Output.ColumnsOutput.ElementAt(0).WaterLevel.GetAccuracy(); + + Assert.AreEqual(2, calculation.Output.ColumnsOutput.Count()); + Assert.AreEqual(outputALevel, calculation.Output.ColumnsOutput.ElementAt(0).WaterLevel, accuracy); + Assert.AreEqual(outputBLevel, calculation.Output.ColumnsOutput.ElementAt(1).WaterLevel, accuracy); + + Assert.AreEqual(1, calculation.Output.BlocksOutput.Count()); + Assert.AreEqual(outputCLevel, calculation.Output.BlocksOutput.ElementAt(0).WaterLevel, accuracy); + } + + private static void AssertRoundedDouble(double expectedValue, RoundedDouble actualValue) + { + Assert.AreEqual(expectedValue, actualValue, actualValue.GetAccuracy()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StabilityStoneCover/StabilityStoneCoverWaveConditionsOutputEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StabilityStoneCover/StabilityStoneCoverWaveConditionsOutputEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StabilityStoneCover/StabilityStoneCoverWaveConditionsOutputEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,123 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Revetment.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.StabilityStoneCover; + +namespace Riskeer.Storage.Core.Test.Read.StabilityStoneCover +{ + [TestFixture] + public class StabilityStoneCoverWaveConditionsOutputEntityReadExtensionsTest + { + [Test] + public void Read_ValidEntity_ReturnOutputWithValues() + { + // Setup + var random = new Random(12); + var entity = new StabilityStoneCoverWaveConditionsOutputEntity + { + WaterLevel = random.NextDouble(), + WaveHeight = random.NextDouble(), + WavePeakPeriod = random.NextDouble(), + WaveAngle = random.NextDouble(), + WaveDirection = random.NextDouble(), + TargetProbability = random.NextDouble(), + TargetReliability = random.NextDouble(), + CalculatedProbability = random.NextDouble(), + CalculatedReliability = random.NextDouble(), + CalculationConvergence = Convert.ToByte(CalculationConvergence.CalculatedConverged) + }; + + // Call + WaveConditionsOutput output = entity.Read(); + + // Assert + Assert.IsNotNull(entity.WaterLevel); + Assert.AreEqual(entity.WaterLevel.Value, output.WaterLevel, output.WaterLevel.GetAccuracy()); + + Assert.IsNotNull(entity.WaveHeight); + Assert.AreEqual(entity.WaveHeight.Value, output.WaveHeight, output.WaveHeight.GetAccuracy()); + + Assert.IsNotNull(entity.WavePeakPeriod); + Assert.AreEqual(entity.WavePeakPeriod.Value, output.WavePeakPeriod, output.WavePeakPeriod.GetAccuracy()); + + Assert.IsNotNull(entity.WaveAngle); + Assert.AreEqual(entity.WaveAngle.Value, output.WaveAngle, output.WaveAngle.GetAccuracy()); + + Assert.IsNotNull(entity.WaveDirection); + Assert.AreEqual(entity.WaveDirection.Value, output.WaveDirection, output.WaveDirection.GetAccuracy()); + + Assert.IsNotNull(entity.TargetProbability); + Assert.AreEqual(entity.TargetProbability.Value, output.TargetProbability); + + Assert.IsNotNull(entity.TargetReliability); + Assert.AreEqual(entity.TargetReliability.Value, output.TargetReliability, output.TargetReliability.GetAccuracy()); + + Assert.IsNotNull(entity.CalculatedProbability); + Assert.AreEqual(entity.CalculatedProbability.Value, output.CalculatedProbability); + + Assert.IsNotNull(entity.CalculatedReliability); + Assert.AreEqual(entity.CalculatedReliability.Value, output.CalculatedReliability, output.CalculatedReliability.GetAccuracy()); + + Assert.IsNotNull(entity.CalculationConvergence); + Assert.AreEqual(CalculationConvergence.CalculatedConverged, output.CalculationConvergence); + } + + [Test] + public void Read_ValidEntityWithNullParameterValues_ReturnOutputWithNaNValues() + { + // Setup + var entity = new StabilityStoneCoverWaveConditionsOutputEntity + { + WaterLevel = null, + WaveHeight = null, + WavePeakPeriod = null, + WaveAngle = null, + WaveDirection = null, + TargetProbability = null, + TargetReliability = null, + CalculatedProbability = null, + CalculatedReliability = null, + CalculationConvergence = Convert.ToByte(CalculationConvergence.NotCalculated) + }; + + // Call + WaveConditionsOutput output = entity.Read(); + + // Assert + Assert.IsNaN(output.WaterLevel); + Assert.IsNaN(output.WaveHeight); + Assert.IsNaN(output.WavePeakPeriod); + Assert.IsNaN(output.WaveAngle); + Assert.IsNaN(output.WaveDirection); + Assert.IsNaN(output.TargetProbability); + Assert.IsNaN(output.TargetReliability); + Assert.IsNaN(output.CalculatedProbability); + Assert.IsNaN(output.CalculatedReliability); + Assert.AreEqual(CalculationConvergence.NotCalculated, output.CalculationConvergence); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StochasticSoilModelEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StochasticSoilModelEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StochasticSoilModelEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,313 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.MacroStabilityInwards.Data.SoilProfile; +using Ringtoets.Piping.Data.SoilProfile; +using Ringtoets.Storage.Core.TestUtil; +using Ringtoets.Storage.Core.TestUtil.MacroStabilityInwards; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Read +{ + [TestFixture] + public class StochasticSoilModelEntityReadExtensionsTest + { + [Test] + public void ReadAsPipingStochasticSoilModel_CollectorNull_ThrowsArgumentNullException() + { + // Setup + var entity = new StochasticSoilModelEntity(); + + // Call + TestDelegate test = () => entity.ReadAsPipingStochasticSoilModel(null); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("collector", parameter); + } + + [Test] + public void ReadAsPipingStochasticSoilModel_EntityNull_ThrowsArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => ((StochasticSoilModelEntity) null).ReadAsPipingStochasticSoilModel(collector); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", parameter); + } + + [Test] + public void ReadAsPipingStochasticSoilModel_StochasticSoilModelSegmentPointXmlEmpty_ThrowsArgumentException() + { + // Setup + var entity = new StochasticSoilModelEntity + { + Name = "Name", + StochasticSoilModelSegmentPointXml = string.Empty + }; + + // Call + TestDelegate test = () => entity.ReadAsPipingStochasticSoilModel(new ReadConversionCollector()); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("xml", paramName); + } + + [Test] + public void ReadAsPipingStochasticSoilModel_WithValidEntity_ReturnsNewStochasticSoilModelWithPropertiesSet() + { + // Setup + var random = new Random(21); + var geometry = new[] + { + new Point2D(random.NextDouble(), random.NextDouble()), + new Point2D(random.NextDouble(), random.NextDouble()) + }; + + var entity = new StochasticSoilModelEntity + { + Name = "StochasticSoilModel", + StochasticSoilModelSegmentPointXml = new Point2DCollectionXmlSerializer().ToXml(geometry), + PipingStochasticSoilProfileEntities = + { + new PipingStochasticSoilProfileEntity + { + PipingSoilProfileEntity = new PipingSoilProfileEntity + { + PipingSoilLayerEntities = + { + new PipingSoilLayerEntity() + }, + Name = "A" + }, + Order = 1 + }, + new PipingStochasticSoilProfileEntity + { + PipingSoilProfileEntity = new PipingSoilProfileEntity + { + PipingSoilLayerEntities = + { + new PipingSoilLayerEntity() + }, + Name = "B" + }, + Order = 0 + } + } + }; + var collector = new ReadConversionCollector(); + + // Call + PipingStochasticSoilModel model = entity.ReadAsPipingStochasticSoilModel(collector); + + // Assert + Assert.IsNotNull(model); + Assert.AreEqual(entity.Name, model.Name); + CollectionAssert.AreEqual(geometry, model.Geometry); + + Assert.AreEqual(entity.PipingStochasticSoilProfileEntities.Count, model.StochasticSoilProfiles.Count()); + CollectionAssert.AreEqual(new[] + { + "B", + "A" + }, model.StochasticSoilProfiles.Select(ssp => ssp.SoilProfile.Name)); + } + + [Test] + public void ReadAsPipingStochasticSoilModel_SameStochasticSoilModelEntityMultipleTimes_ReturnSameStochasticSoilModel() + { + // Setup + var random = new Random(21); + var geometry = new[] + { + new Point2D(random.NextDouble(), random.NextDouble()) + }; + var entity = new StochasticSoilModelEntity + { + Name = "StochasticSoilModel", + StochasticSoilModelSegmentPointXml = new Point2DCollectionXmlSerializer().ToXml(geometry), + PipingStochasticSoilProfileEntities = + { + PipingStochasticSoilProfileEntityTestFactory.CreateStochasticSoilProfileEntity() + } + }; + + var collector = new ReadConversionCollector(); + + // Call + PipingStochasticSoilModel soilModel1 = entity.ReadAsPipingStochasticSoilModel(collector); + PipingStochasticSoilModel soilModel2 = entity.ReadAsPipingStochasticSoilModel(collector); + + // Assert + Assert.AreSame(soilModel1, soilModel2); + } + + [Test] + public void ReadAsMacroStabilityInwardsStochasticSoilModel_CollectorNull_ThrowsArgumentNullException() + { + // Setup + var entity = new StochasticSoilModelEntity(); + + // Call + TestDelegate test = () => entity.ReadAsMacroStabilityInwardsStochasticSoilModel(null); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("collector", parameter); + } + + [Test] + public void ReadAsMacroStabilityInwardsStochasticSoilModel_EntityNull_ThrowsArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => ((StochasticSoilModelEntity) null).ReadAsMacroStabilityInwardsStochasticSoilModel(collector); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", parameter); + } + + [Test] + public void ReadAsMacroStabilityInwardsStochasticSoilModel_StochasticSoilModelSegmentPointXmlEmpty_ThrowsArgumentException() + { + // Setup + var entity = new StochasticSoilModelEntity + { + Name = "Name", + StochasticSoilModelSegmentPointXml = string.Empty + }; + + // Call + TestDelegate test = () => entity.ReadAsMacroStabilityInwardsStochasticSoilModel(new ReadConversionCollector()); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("xml", paramName); + } + + [Test] + public void ReadAsMacroStabilityInwardsStochasticSoilModel_WithValidEntity_ReturnsNewStochasticSoilModelWithPropertiesSet() + { + // Setup + var random = new Random(21); + var geometry = new[] + { + new Point2D(random.NextDouble(), random.NextDouble()), + new Point2D(random.NextDouble(), random.NextDouble()) + }; + + var entity = new StochasticSoilModelEntity + { + Name = "testName", + StochasticSoilModelSegmentPointXml = new Point2DCollectionXmlSerializer().ToXml(geometry), + MacroStabilityInwardsStochasticSoilProfileEntities = + { + new MacroStabilityInwardsStochasticSoilProfileEntity + { + MacroStabilityInwardsSoilProfileOneDEntity = new MacroStabilityInwardsSoilProfileOneDEntity + { + MacroStabilityInwardsSoilLayerOneDEntities = + { + new MacroStabilityInwardsSoilLayerOneDEntity() + }, + Name = "A" + }, + Order = 1 + }, + new MacroStabilityInwardsStochasticSoilProfileEntity + { + MacroStabilityInwardsSoilProfileTwoDEntity = new MacroStabilityInwardsSoilProfileTwoDEntity + { + MacroStabilityInwardsSoilLayerTwoDEntities = + { + MacroStabilityInwardsSoilLayerTwoDEntityTestFactory.CreateMacroStabilityInwardsSoilLayerTwoDEntity() + }, + Name = "B" + }, + Order = 0 + } + } + }; + var collector = new ReadConversionCollector(); + + // Call + MacroStabilityInwardsStochasticSoilModel model = entity.ReadAsMacroStabilityInwardsStochasticSoilModel(collector); + + // Assert + Assert.IsNotNull(model); + Assert.AreEqual(entity.Name, model.Name); + CollectionAssert.AreEqual(geometry, model.Geometry); + + Assert.AreEqual(entity.MacroStabilityInwardsStochasticSoilProfileEntities.Count, + model.StochasticSoilProfiles.Count()); + CollectionAssert.AreEqual(new[] + { + "B", + "A" + }, model.StochasticSoilProfiles.Select(ssp => ssp.SoilProfile.Name)); + } + + [Test] + public void ReadAsMacroStabilityInwardsStochasticSoilModel_SameStochasticSoilModelEntityMultipleTimes_ReturnSameStochasticSoilModel() + { + // Setup + var random = new Random(21); + string segmentPointsXml = new Point2DCollectionXmlSerializer().ToXml(new[] + { + new Point2D(random.NextDouble(), random.NextDouble()) + }); + + var entity = new StochasticSoilModelEntity + { + Name = "StochasticSoilModel", + StochasticSoilModelSegmentPointXml = segmentPointsXml, + MacroStabilityInwardsStochasticSoilProfileEntities = + { + MacroStabilityInwardsStochasticSoilProfileEntityTestFactory.CreateStochasticSoilProfileEntity() + } + }; + + var collector = new ReadConversionCollector(); + + // Call + MacroStabilityInwardsStochasticSoilModel soilModel1 = entity.ReadAsMacroStabilityInwardsStochasticSoilModel(collector); + MacroStabilityInwardsStochasticSoilModel soilModel2 = entity.ReadAsMacroStabilityInwardsStochasticSoilModel(collector); + + // Assert + Assert.AreSame(soilModel1, soilModel2); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StrengthStabilityLengthwiseConstructionSectionResultEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StrengthStabilityLengthwiseConstructionSectionResultEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StrengthStabilityLengthwiseConstructionSectionResultEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,93 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.Integration.Data.StandAlone.SectionResults; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; + +namespace Riskeer.Storage.Core.Test.Read +{ + [TestFixture] + public class StrengthStabilityLengthwiseConstructionSectionResultEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Setup + var sectionResult = new StrengthStabilityLengthwiseConstructionFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + TestDelegate call = () => ((StrengthStabilityLengthwiseConstructionSectionResultEntity) null).Read(sectionResult); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_SectionResultNull_ThrowsArgumentNullException() + { + // Setup + var entity = new StrengthStabilityLengthwiseConstructionSectionResultEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("sectionResult", paramName); + } + + [Test] + public void Read_ParameterValues_SetsSectionResultWithParameterValues() + { + // Setup + var random = new Random(31); + var simpleAssessmentResult = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + bool useManualAssembly = random.NextBoolean(); + var manualAssemblyCategoryGroup = random.NextEnumValue(); + + var entity = new StrengthStabilityLengthwiseConstructionSectionResultEntity + { + SimpleAssessmentResult = Convert.ToByte(simpleAssessmentResult), + TailorMadeAssessmentResult = Convert.ToByte(tailorMadeAssessmentResult), + UseManualAssembly = Convert.ToByte(useManualAssembly), + ManualAssemblyCategoryGroup = Convert.ToByte(manualAssemblyCategoryGroup) + }; + var sectionResult = new StrengthStabilityLengthwiseConstructionFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult); + + // Assert + Assert.AreEqual(simpleAssessmentResult, sectionResult.SimpleAssessmentResult); + Assert.AreEqual(tailorMadeAssessmentResult, sectionResult.TailorMadeAssessmentResult); + Assert.AreEqual(useManualAssembly, sectionResult.UseManualAssembly); + Assert.AreEqual(manualAssemblyCategoryGroup, sectionResult.ManualAssemblyCategoryGroup); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StructureCalculationEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StructureCalculationEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/StructureCalculationEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,240 @@ +// Copyright (C) Stichting Deltares 2018. 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 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; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; + +namespace Riskeer.Storage.Core.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.NextDouble(0, 360); + entity.AllowedLevelIncreaseStorageMean = random.NextDouble(1e-6, 9999.9999); + entity.AllowedLevelIncreaseStorageStandardDeviation = random.NextDouble(1e-6, 9999.9999); + entity.FlowWidthAtBottomProtectionMean = random.NextDouble(1e-6, 9999.9999); + entity.FlowWidthAtBottomProtectionStandardDeviation = random.NextDouble(1e-6, 9999.9999); + entity.CriticalOvertoppingDischargeMean = random.NextDouble(1e-6, 9999.9999); + entity.CriticalOvertoppingDischargeCoefficientOfVariation = random.NextDouble(1e-6, 9999.9999); + entity.FailureProbabilityStructureWithErosion = random.NextDouble(); + entity.WidthFlowAperturesMean = random.NextDouble(1e-6, 9999.9999); + entity.WidthFlowAperturesStandardDeviation = random.NextDouble(1e-6, 9999.9999); + entity.StormDurationMean = random.NextDouble(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.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); + + CollectionAssert.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.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.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 Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/SurfaceLineEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/SurfaceLineEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/SurfaceLineEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,738 @@ +// Copyright (C) Stichting Deltares 2018. 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.ComponentModel; +using System.Linq; +using Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.MacroStabilityInwards.Primitives; +using Ringtoets.Piping.Primitives; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Read +{ + [TestFixture] + public class SurfaceLineEntityReadExtensionsTest + { + [Test] + public void ReadAsPipingSurfaceLine_CollectorNull_ThrowArgumentNullException() + { + // Setup + var entity = new SurfaceLineEntity(); + + // Call + TestDelegate call = () => entity.ReadAsPipingSurfaceLine(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("collector", exception.ParamName); + } + + [Test] + public void ReadAsPipingSurfaceLine_EntityNull_ThrowArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate call = () => ((SurfaceLineEntity) null).ReadAsPipingSurfaceLine(collector); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void ReadAsPipingSurfaceLine_PointsXmlEmpty_ThrowsArgumentException() + { + var entity = new SurfaceLineEntity + { + Name = "surface line", + PointsXml = string.Empty + }; + + // Call + TestDelegate call = () => entity.ReadAsPipingSurfaceLine(new ReadConversionCollector()); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("xml", paramName); + } + + [Test] + public void ReadAsPipingSurfaceLine_SurfaceLineEntityWithoutGeometryPointXml_ReturnSurfaceLine() + { + // Setup + var collector = new ReadConversionCollector(); + var random = new Random(31); + + var entity = new SurfaceLineEntity + { + Name = "nice name!", + ReferenceLineIntersectionX = random.NextDouble(), + ReferenceLineIntersectionY = random.NextDouble(), + PointsXml = new Point3DCollectionXmlSerializer().ToXml(new Point3D[0]) + }; + + // Call + PipingSurfaceLine surfaceLine = entity.ReadAsPipingSurfaceLine(collector); + + // Assert + Assert.AreEqual(entity.Name, surfaceLine.Name); + Assert.AreEqual(entity.ReferenceLineIntersectionX, surfaceLine.ReferenceLineIntersectionWorldPoint.X); + Assert.AreEqual(entity.ReferenceLineIntersectionY, surfaceLine.ReferenceLineIntersectionWorldPoint.Y); + + CollectionAssert.IsEmpty(surfaceLine.Points); + + Assert.IsNull(surfaceLine.BottomDitchDikeSide); + Assert.IsNull(surfaceLine.BottomDitchPolderSide); + Assert.IsNull(surfaceLine.DikeToeAtPolder); + Assert.IsNull(surfaceLine.DikeToeAtRiver); + Assert.IsNull(surfaceLine.DitchDikeSide); + Assert.IsNull(surfaceLine.DitchPolderSide); + } + + [Test] + public void ReadAsPipingSurfaceLine_SurfaceLineEntityWithGeometryPointXmlButNoCharacteristicPoints_ReturnSurfaceLineWithGeometry() + { + // Setup + var collector = new ReadConversionCollector(); + var random = new Random(31); + + Point3D[] points = + { + CreatePoint3D(random), + CreatePoint3D(random), + CreatePoint3D(random) + }; + + var entity = new SurfaceLineEntity + { + Name = nameof(SurfaceLineEntity), + ReferenceLineIntersectionX = random.NextDouble(), + ReferenceLineIntersectionY = random.NextDouble(), + PointsXml = new Point3DCollectionXmlSerializer().ToXml(points) + }; + + // Call + PipingSurfaceLine surfaceLine = entity.ReadAsPipingSurfaceLine(collector); + + // Assert + Assert.AreEqual(entity.Name, surfaceLine.Name); + Assert.AreEqual(entity.ReferenceLineIntersectionX, surfaceLine.ReferenceLineIntersectionWorldPoint.X); + Assert.AreEqual(entity.ReferenceLineIntersectionY, surfaceLine.ReferenceLineIntersectionWorldPoint.Y); + + CollectionAssert.AreEqual(points, surfaceLine.Points); + + Assert.IsNull(surfaceLine.BottomDitchDikeSide); + Assert.IsNull(surfaceLine.BottomDitchPolderSide); + Assert.IsNull(surfaceLine.DikeToeAtPolder); + Assert.IsNull(surfaceLine.DikeToeAtRiver); + Assert.IsNull(surfaceLine.DitchDikeSide); + Assert.IsNull(surfaceLine.DitchPolderSide); + } + + [Test] + public void ReadAsPipingSurfaceLine_SurfaceLineEntityWithGeometryPointXmlAndCharacteristicPoints_ReturnFullSurfaceLine() + { + // Setup + var collector = new ReadConversionCollector(); + var random = new Random(31); + + Point3D[] points = + { + CreatePoint3D(random), + CreatePoint3D(random), + CreatePoint3D(random), + CreatePoint3D(random), + CreatePoint3D(random), + CreatePoint3D(random), + CreatePoint3D(random) + }; + + var entity = new SurfaceLineEntity + { + Name = "Better name.", + ReferenceLineIntersectionX = random.NextDouble(), + ReferenceLineIntersectionY = random.NextDouble(), + PointsXml = new Point3DCollectionXmlSerializer().ToXml(points), + PipingCharacteristicPointEntities = + { + CreatePipingCharacteristicPointEntity(points[1], PipingCharacteristicPointType.BottomDitchDikeSide), + CreatePipingCharacteristicPointEntity(points[2], PipingCharacteristicPointType.BottomDitchPolderSide), + CreatePipingCharacteristicPointEntity(points[3], PipingCharacteristicPointType.DikeToeAtPolder), + CreatePipingCharacteristicPointEntity(points[4], PipingCharacteristicPointType.DikeToeAtRiver), + CreatePipingCharacteristicPointEntity(points[5], PipingCharacteristicPointType.DitchDikeSide), + CreatePipingCharacteristicPointEntity(points[6], PipingCharacteristicPointType.DitchPolderSide) + } + }; + + // Call + PipingSurfaceLine surfaceLine = entity.ReadAsPipingSurfaceLine(collector); + + // Assert + Assert.AreEqual(entity.Name, surfaceLine.Name); + Assert.AreEqual(entity.ReferenceLineIntersectionX, surfaceLine.ReferenceLineIntersectionWorldPoint.X); + Assert.AreEqual(entity.ReferenceLineIntersectionY, surfaceLine.ReferenceLineIntersectionWorldPoint.Y); + + CollectionAssert.AreEqual(points, surfaceLine.Points); + + Assert.AreSame(surfaceLine.Points.ElementAt(1), surfaceLine.BottomDitchDikeSide); + Assert.AreSame(surfaceLine.Points.ElementAt(2), surfaceLine.BottomDitchPolderSide); + Assert.AreSame(surfaceLine.Points.ElementAt(3), surfaceLine.DikeToeAtPolder); + Assert.AreSame(surfaceLine.Points.ElementAt(4), surfaceLine.DikeToeAtRiver); + Assert.AreSame(surfaceLine.Points.ElementAt(5), surfaceLine.DitchDikeSide); + Assert.AreSame(surfaceLine.Points.ElementAt(6), surfaceLine.DitchPolderSide); + } + + [Test] + public void ReadAsPipingSurfaceLine_SurfaceLineEntityWithPointsAndAllCharacteristicPointsSetToSamePoint_ReturnsExpectedSurfaceLine() + { + // Setup + var collector = new ReadConversionCollector(); + var random = new Random(31); + + Point3D[] points = + { + CreatePoint3D(random), + CreatePoint3D(random) + }; + + var entity = new SurfaceLineEntity + { + Name = "Better name.", + ReferenceLineIntersectionX = random.NextDouble(), + ReferenceLineIntersectionY = random.NextDouble(), + PointsXml = new Point3DCollectionXmlSerializer().ToXml(points), + PipingCharacteristicPointEntities = + { + CreatePipingCharacteristicPointEntity(points[0], PipingCharacteristicPointType.BottomDitchDikeSide), + CreatePipingCharacteristicPointEntity(points[0], PipingCharacteristicPointType.BottomDitchPolderSide), + CreatePipingCharacteristicPointEntity(points[0], PipingCharacteristicPointType.DikeToeAtPolder), + CreatePipingCharacteristicPointEntity(points[0], PipingCharacteristicPointType.DikeToeAtRiver), + CreatePipingCharacteristicPointEntity(points[0], PipingCharacteristicPointType.DitchDikeSide), + CreatePipingCharacteristicPointEntity(points[0], PipingCharacteristicPointType.DitchPolderSide) + } + }; + + // Call + PipingSurfaceLine surfaceLine = entity.ReadAsPipingSurfaceLine(collector); + + // Assert + Assert.AreEqual(entity.Name, surfaceLine.Name); + Assert.AreEqual(entity.ReferenceLineIntersectionX, surfaceLine.ReferenceLineIntersectionWorldPoint.X); + Assert.AreEqual(entity.ReferenceLineIntersectionY, surfaceLine.ReferenceLineIntersectionWorldPoint.Y); + + Point3D[] geometry = surfaceLine.Points.ToArray(); + Assert.AreEqual(2, geometry.Length); + Point3D geometryPoint = geometry[0]; + + Assert.AreSame(geometryPoint, surfaceLine.BottomDitchDikeSide); + Assert.AreSame(geometryPoint, surfaceLine.BottomDitchPolderSide); + Assert.AreSame(geometryPoint, surfaceLine.DikeToeAtPolder); + Assert.AreSame(geometryPoint, surfaceLine.DikeToeAtRiver); + Assert.AreSame(geometryPoint, surfaceLine.DitchDikeSide); + Assert.AreSame(geometryPoint, surfaceLine.DitchPolderSide); + } + + [Test] + public void ReadAsPipingSurfaceLine_WithNullValues_ReturnsPipingSurfaceLineWithNaNValues() + { + // Setup + var collector = new ReadConversionCollector(); + var point3D = new Point3D(double.NaN, double.NaN, double.NaN); + var entity = new SurfaceLineEntity + { + Name = "name", + PointsXml = new Point3DCollectionXmlSerializer().ToXml(new[] + { + point3D + }), + PipingCharacteristicPointEntities = + { + CreatePipingCharacteristicPointEntity(point3D, PipingCharacteristicPointType.BottomDitchDikeSide), + CreatePipingCharacteristicPointEntity(point3D, PipingCharacteristicPointType.BottomDitchPolderSide), + CreatePipingCharacteristicPointEntity(point3D, PipingCharacteristicPointType.DikeToeAtPolder), + CreatePipingCharacteristicPointEntity(point3D, PipingCharacteristicPointType.DikeToeAtRiver), + CreatePipingCharacteristicPointEntity(point3D, PipingCharacteristicPointType.DitchDikeSide), + CreatePipingCharacteristicPointEntity(point3D, PipingCharacteristicPointType.DitchPolderSide) + } + }; + + // Call + PipingSurfaceLine surfaceLine = entity.ReadAsPipingSurfaceLine(collector); + + // Assert + Assert.AreEqual(entity.Name, surfaceLine.Name); + Assert.IsNaN(surfaceLine.ReferenceLineIntersectionWorldPoint.X); + Assert.IsNaN(surfaceLine.ReferenceLineIntersectionWorldPoint.Y); + + Point3D geometryPoint = surfaceLine.Points.Single(); + Assert.AreSame(geometryPoint, surfaceLine.BottomDitchDikeSide); + Assert.AreSame(geometryPoint, surfaceLine.BottomDitchPolderSide); + Assert.AreSame(geometryPoint, surfaceLine.DikeToeAtPolder); + Assert.AreSame(geometryPoint, surfaceLine.DikeToeAtRiver); + Assert.AreSame(geometryPoint, surfaceLine.DitchDikeSide); + Assert.AreSame(geometryPoint, surfaceLine.DitchPolderSide); + } + + [Test] + public void ReadAsPipingSurfaceLine_WithInvalidPipingCharacteristicPointType_ThrowsInvalidEnumArgumentException() + { + // Setup + var random = new Random(31); + + Point3D[] points = + { + CreatePoint3D(random) + }; + + const byte invalidCharacteristicPointType = 37; + var entity = new SurfaceLineEntity + { + Name = "Better name.", + ReferenceLineIntersectionX = random.NextDouble(), + ReferenceLineIntersectionY = random.NextDouble(), + PointsXml = new Point3DCollectionXmlSerializer().ToXml(points), + PipingCharacteristicPointEntities = + { + CreatePipingCharacteristicPointEntity(points[0], (PipingCharacteristicPointType) invalidCharacteristicPointType) + } + }; + + // Call + TestDelegate call = () => entity.ReadAsPipingSurfaceLine(new ReadConversionCollector()); + + // Assert + string exoectedMessage = $"The value of argument 'type' ({invalidCharacteristicPointType}) is invalid for Enum type '{nameof(PipingCharacteristicPointType)}'."; + string parameterName = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, exoectedMessage).ParamName; + Assert.AreEqual("type", parameterName); + } + + [Test] + public void ReadAsPipingSurfaceLine_SurfaceLineEntityReadMultipleTimes_ReturnSameSurfaceLine() + { + // Setup + var collector = new ReadConversionCollector(); + + var entity = new SurfaceLineEntity + { + Name = "surface line", + PointsXml = new Point3DCollectionXmlSerializer().ToXml(new Point3D[0]) + }; + + // Call + PipingSurfaceLine surfaceLine1 = entity.ReadAsPipingSurfaceLine(collector); + PipingSurfaceLine surfaceLine2 = entity.ReadAsPipingSurfaceLine(collector); + + // Assert + Assert.AreSame(surfaceLine1, surfaceLine2); + } + + [Test] + public void ReadAsMacroStabilityInwardsSurfaceLine_CollectorNull_ThrowArgumentNullException() + { + // Setup + var entity = new SurfaceLineEntity(); + + // Call + TestDelegate call = () => entity.ReadAsMacroStabilityInwardsSurfaceLine(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("collector", exception.ParamName); + } + + [Test] + public void ReadAsMacroStabilityInwardsSurfaceLine_EntityNull_ThrowArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate call = () => ((SurfaceLineEntity) null).ReadAsMacroStabilityInwardsSurfaceLine(collector); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void ReadAsMacroStabilityInwardsSurfaceLine_PointsXmlEmpty_ThrowsArgumentException() + { + var entity = new SurfaceLineEntity + { + Name = "surface line", + PointsXml = string.Empty + }; + + // Call + TestDelegate call = () => entity.ReadAsMacroStabilityInwardsSurfaceLine(new ReadConversionCollector()); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("xml", paramName); + } + + [Test] + public void ReadAsMacroStabilityInwardsSurfaceLine_SurfaceLineEntityWithoutGeometryPointXml_ReturnSurfaceLine() + { + // Setup + var collector = new ReadConversionCollector(); + var random = new Random(31); + + var entity = new SurfaceLineEntity + { + Name = "nice name!", + ReferenceLineIntersectionX = random.NextDouble(), + ReferenceLineIntersectionY = random.NextDouble(), + PointsXml = new Point3DCollectionXmlSerializer().ToXml(new Point3D[0]) + }; + + // Call + MacroStabilityInwardsSurfaceLine surfaceLine = entity.ReadAsMacroStabilityInwardsSurfaceLine(collector); + + // Assert + Assert.AreEqual(entity.Name, surfaceLine.Name); + Assert.AreEqual(entity.ReferenceLineIntersectionX, surfaceLine.ReferenceLineIntersectionWorldPoint.X); + Assert.AreEqual(entity.ReferenceLineIntersectionY, surfaceLine.ReferenceLineIntersectionWorldPoint.Y); + + CollectionAssert.IsEmpty(surfaceLine.Points); + + Assert.IsNull(surfaceLine.SurfaceLevelOutside); + Assert.IsNull(surfaceLine.DikeToeAtRiver); + Assert.IsNull(surfaceLine.DikeTopAtPolder); + Assert.IsNull(surfaceLine.DikeTopAtRiver); + Assert.IsNull(surfaceLine.ShoulderBaseInside); + Assert.IsNull(surfaceLine.ShoulderTopInside); + Assert.IsNull(surfaceLine.DikeToeAtPolder); + Assert.IsNull(surfaceLine.DitchDikeSide); + Assert.IsNull(surfaceLine.BottomDitchDikeSide); + Assert.IsNull(surfaceLine.BottomDitchPolderSide); + Assert.IsNull(surfaceLine.DitchPolderSide); + Assert.IsNull(surfaceLine.SurfaceLevelInside); + } + + [Test] + public void ReadAsMacroStabilityInwardsSurfaceLine_SurfaceLineEntityWithGeometryPointXmlButNoCharacteristicPoints_ReturnSurfaceLineWithGeometry() + { + // Setup + var collector = new ReadConversionCollector(); + var random = new Random(31); + + Point3D[] points = + { + CreatePoint3D(random), + CreatePoint3D(random), + CreatePoint3D(random) + }; + + var entity = new SurfaceLineEntity + { + Name = nameof(SurfaceLineEntity), + ReferenceLineIntersectionX = random.NextDouble(), + ReferenceLineIntersectionY = random.NextDouble(), + PointsXml = new Point3DCollectionXmlSerializer().ToXml(points) + }; + + // Call + MacroStabilityInwardsSurfaceLine surfaceLine = entity.ReadAsMacroStabilityInwardsSurfaceLine(collector); + + // Assert + Assert.AreEqual(entity.Name, surfaceLine.Name); + Assert.AreEqual(entity.ReferenceLineIntersectionX, surfaceLine.ReferenceLineIntersectionWorldPoint.X); + Assert.AreEqual(entity.ReferenceLineIntersectionY, surfaceLine.ReferenceLineIntersectionWorldPoint.Y); + + CollectionAssert.AreEqual(points, surfaceLine.Points); + + Assert.IsNull(surfaceLine.SurfaceLevelOutside); + Assert.IsNull(surfaceLine.DikeToeAtRiver); + Assert.IsNull(surfaceLine.DikeTopAtPolder); + Assert.IsNull(surfaceLine.DikeTopAtRiver); + Assert.IsNull(surfaceLine.ShoulderBaseInside); + Assert.IsNull(surfaceLine.ShoulderTopInside); + Assert.IsNull(surfaceLine.DikeToeAtPolder); + Assert.IsNull(surfaceLine.DitchDikeSide); + Assert.IsNull(surfaceLine.BottomDitchDikeSide); + Assert.IsNull(surfaceLine.BottomDitchPolderSide); + Assert.IsNull(surfaceLine.DitchPolderSide); + Assert.IsNull(surfaceLine.SurfaceLevelInside); + } + + [Test] + public void ReadAsMacroStabilityInwardsSurfaceLine_SurfaceLineEntityWithGeometryPointXmlAndCharacteristicPoints_ReturnFullSurfaceLine() + { + // Setup + var collector = new ReadConversionCollector(); + var random = new Random(31); + + Point3D[] points = Array.ConvertAll(new Point3D[12], p => CreatePoint3D(random)); + + var entity = new SurfaceLineEntity + { + Name = "Better name.", + ReferenceLineIntersectionX = random.NextDouble(), + ReferenceLineIntersectionY = random.NextDouble(), + PointsXml = new Point3DCollectionXmlSerializer().ToXml(points), + MacroStabilityInwardsCharacteristicPointEntities = + { + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.SurfaceLevelOutside), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[1], MacroStabilityInwardsCharacteristicPointType.DikeToeAtRiver), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[2], MacroStabilityInwardsCharacteristicPointType.DikeTopAtPolder), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[3], MacroStabilityInwardsCharacteristicPointType.DikeTopAtRiver), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[4], MacroStabilityInwardsCharacteristicPointType.ShoulderBaseInside), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[5], MacroStabilityInwardsCharacteristicPointType.ShoulderTopInside), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[6], MacroStabilityInwardsCharacteristicPointType.DikeToeAtPolder), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[7], MacroStabilityInwardsCharacteristicPointType.DitchDikeSide), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[8], MacroStabilityInwardsCharacteristicPointType.BottomDitchDikeSide), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[9], MacroStabilityInwardsCharacteristicPointType.BottomDitchPolderSide), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[10], MacroStabilityInwardsCharacteristicPointType.DitchPolderSide), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[11], MacroStabilityInwardsCharacteristicPointType.SurfaceLevelInside) + } + }; + + // Call + MacroStabilityInwardsSurfaceLine surfaceLine = entity.ReadAsMacroStabilityInwardsSurfaceLine(collector); + + // Assert + Assert.AreEqual(entity.Name, surfaceLine.Name); + Assert.AreEqual(entity.ReferenceLineIntersectionX, surfaceLine.ReferenceLineIntersectionWorldPoint.X); + Assert.AreEqual(entity.ReferenceLineIntersectionY, surfaceLine.ReferenceLineIntersectionWorldPoint.Y); + + CollectionAssert.AreEqual(points, surfaceLine.Points); + + Assert.AreSame(surfaceLine.Points.ElementAt(0), surfaceLine.SurfaceLevelOutside); + Assert.AreSame(surfaceLine.Points.ElementAt(1), surfaceLine.DikeToeAtRiver); + Assert.AreSame(surfaceLine.Points.ElementAt(2), surfaceLine.DikeTopAtPolder); + Assert.AreSame(surfaceLine.Points.ElementAt(3), surfaceLine.DikeTopAtRiver); + Assert.AreSame(surfaceLine.Points.ElementAt(4), surfaceLine.ShoulderBaseInside); + Assert.AreSame(surfaceLine.Points.ElementAt(5), surfaceLine.ShoulderTopInside); + Assert.AreSame(surfaceLine.Points.ElementAt(6), surfaceLine.DikeToeAtPolder); + Assert.AreSame(surfaceLine.Points.ElementAt(7), surfaceLine.DitchDikeSide); + Assert.AreSame(surfaceLine.Points.ElementAt(8), surfaceLine.BottomDitchDikeSide); + Assert.AreSame(surfaceLine.Points.ElementAt(9), surfaceLine.BottomDitchPolderSide); + Assert.AreSame(surfaceLine.Points.ElementAt(10), surfaceLine.DitchPolderSide); + Assert.AreSame(surfaceLine.Points.ElementAt(11), surfaceLine.SurfaceLevelInside); + } + + [Test] + public void ReadAsMacroStabilityInwardsSurfaceLine_SurfaceLineEntityWithPointsAndAllCharacteristicPointsSetToSamePoint_ReturnsExpectedSurfaceLine() + { + // Setup + var collector = new ReadConversionCollector(); + var random = new Random(31); + + Point3D[] points = + { + CreatePoint3D(random), + CreatePoint3D(random) + }; + + var entity = new SurfaceLineEntity + { + Name = "Better name.", + ReferenceLineIntersectionX = random.NextDouble(), + ReferenceLineIntersectionY = random.NextDouble(), + PointsXml = new Point3DCollectionXmlSerializer().ToXml(points), + MacroStabilityInwardsCharacteristicPointEntities = + { + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.SurfaceLevelOutside), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.DikeToeAtRiver), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.DikeTopAtPolder), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.DikeTopAtRiver), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.ShoulderBaseInside), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.ShoulderTopInside), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.DikeToeAtPolder), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.DitchDikeSide), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.BottomDitchDikeSide), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.BottomDitchPolderSide), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.DitchPolderSide), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.SurfaceLevelInside) + } + }; + + // Call + MacroStabilityInwardsSurfaceLine surfaceLine = entity.ReadAsMacroStabilityInwardsSurfaceLine(collector); + + // Assert + Assert.AreEqual(entity.Name, surfaceLine.Name); + Assert.AreEqual(entity.ReferenceLineIntersectionX, surfaceLine.ReferenceLineIntersectionWorldPoint.X); + Assert.AreEqual(entity.ReferenceLineIntersectionY, surfaceLine.ReferenceLineIntersectionWorldPoint.Y); + + Point3D[] geometry = surfaceLine.Points.ToArray(); + Assert.AreEqual(2, geometry.Length); + Point3D geometryPoint = geometry[0]; + + Assert.AreSame(geometryPoint, surfaceLine.SurfaceLevelOutside); + Assert.AreSame(geometryPoint, surfaceLine.DikeToeAtRiver); + Assert.AreSame(geometryPoint, surfaceLine.DikeTopAtPolder); + Assert.AreSame(geometryPoint, surfaceLine.DikeTopAtRiver); + Assert.AreSame(geometryPoint, surfaceLine.ShoulderBaseInside); + Assert.AreSame(geometryPoint, surfaceLine.ShoulderTopInside); + Assert.AreSame(geometryPoint, surfaceLine.DikeToeAtPolder); + Assert.AreSame(geometryPoint, surfaceLine.DitchDikeSide); + Assert.AreSame(geometryPoint, surfaceLine.BottomDitchDikeSide); + Assert.AreSame(geometryPoint, surfaceLine.BottomDitchPolderSide); + Assert.AreSame(geometryPoint, surfaceLine.DitchPolderSide); + Assert.AreSame(geometryPoint, surfaceLine.SurfaceLevelInside); + } + + [Test] + public void ReadAsMacroStabilityInwardsSurfaceLine_WithNullValues_ReturnsMacroStabilityInwardsSurfaceLineWithNaNValues() + { + // Setup + var collector = new ReadConversionCollector(); + var point3D = new Point3D(double.NaN, double.NaN, double.NaN); + var entity = new SurfaceLineEntity + { + Name = "name", + PointsXml = new Point3DCollectionXmlSerializer().ToXml(new[] + { + point3D + }), + MacroStabilityInwardsCharacteristicPointEntities = + { + CreateMacroStabilityInwardsCharacteristicPointEntity(point3D, MacroStabilityInwardsCharacteristicPointType.SurfaceLevelOutside), + CreateMacroStabilityInwardsCharacteristicPointEntity(point3D, MacroStabilityInwardsCharacteristicPointType.DikeToeAtRiver), + CreateMacroStabilityInwardsCharacteristicPointEntity(point3D, MacroStabilityInwardsCharacteristicPointType.DikeTopAtPolder), + CreateMacroStabilityInwardsCharacteristicPointEntity(point3D, MacroStabilityInwardsCharacteristicPointType.DikeTopAtRiver), + CreateMacroStabilityInwardsCharacteristicPointEntity(point3D, MacroStabilityInwardsCharacteristicPointType.ShoulderBaseInside), + CreateMacroStabilityInwardsCharacteristicPointEntity(point3D, MacroStabilityInwardsCharacteristicPointType.ShoulderTopInside), + CreateMacroStabilityInwardsCharacteristicPointEntity(point3D, MacroStabilityInwardsCharacteristicPointType.DikeToeAtPolder), + CreateMacroStabilityInwardsCharacteristicPointEntity(point3D, MacroStabilityInwardsCharacteristicPointType.DitchDikeSide), + CreateMacroStabilityInwardsCharacteristicPointEntity(point3D, MacroStabilityInwardsCharacteristicPointType.BottomDitchDikeSide), + CreateMacroStabilityInwardsCharacteristicPointEntity(point3D, MacroStabilityInwardsCharacteristicPointType.BottomDitchPolderSide), + CreateMacroStabilityInwardsCharacteristicPointEntity(point3D, MacroStabilityInwardsCharacteristicPointType.DitchPolderSide), + CreateMacroStabilityInwardsCharacteristicPointEntity(point3D, MacroStabilityInwardsCharacteristicPointType.SurfaceLevelInside) + } + }; + + // Call + MacroStabilityInwardsSurfaceLine surfaceLine = entity.ReadAsMacroStabilityInwardsSurfaceLine(collector); + + // Assert + Assert.AreEqual(entity.Name, surfaceLine.Name); + Assert.IsNaN(surfaceLine.ReferenceLineIntersectionWorldPoint.X); + Assert.IsNaN(surfaceLine.ReferenceLineIntersectionWorldPoint.Y); + + Point3D geometryPoint = surfaceLine.Points.Single(); + Assert.AreSame(geometryPoint, surfaceLine.SurfaceLevelOutside); + Assert.AreSame(geometryPoint, surfaceLine.DikeToeAtRiver); + Assert.AreSame(geometryPoint, surfaceLine.DikeTopAtPolder); + Assert.AreSame(geometryPoint, surfaceLine.DikeTopAtRiver); + Assert.AreSame(geometryPoint, surfaceLine.ShoulderBaseInside); + Assert.AreSame(geometryPoint, surfaceLine.ShoulderTopInside); + Assert.AreSame(geometryPoint, surfaceLine.DikeToeAtPolder); + Assert.AreSame(geometryPoint, surfaceLine.DitchDikeSide); + Assert.AreSame(geometryPoint, surfaceLine.BottomDitchDikeSide); + Assert.AreSame(geometryPoint, surfaceLine.BottomDitchPolderSide); + Assert.AreSame(geometryPoint, surfaceLine.DitchPolderSide); + Assert.AreSame(geometryPoint, surfaceLine.SurfaceLevelInside); + } + + [Test] + public void ReadAsMacroStabilityInwardsSurfaceLine_WithInvalidMacroStabilityCharacteristicPointType_ThrowsInvalidEnumArgumentException() + { + // Setup + var random = new Random(31); + + Point3D[] points = + { + CreatePoint3D(random) + }; + + const byte invalidCharacteristicPointType = 37; + var entity = new SurfaceLineEntity + { + Name = "Better name.", + ReferenceLineIntersectionX = random.NextDouble(), + ReferenceLineIntersectionY = random.NextDouble(), + PointsXml = new Point3DCollectionXmlSerializer().ToXml(points), + MacroStabilityInwardsCharacteristicPointEntities = + { + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], (MacroStabilityInwardsCharacteristicPointType) invalidCharacteristicPointType) + } + }; + + // Call + TestDelegate call = () => entity.ReadAsMacroStabilityInwardsSurfaceLine(new ReadConversionCollector()); + + // Assert + string exoectedMessage = $"The value of argument 'type' ({invalidCharacteristicPointType}) is invalid for Enum type '{nameof(MacroStabilityInwardsCharacteristicPointType)}'."; + string parameterName = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, exoectedMessage).ParamName; + Assert.AreEqual("type", parameterName); + } + + [Test] + public void ReadAsMacroStabilityInwardsSurfaceLine_SurfaceLineEntityReadMultipleTimes_ReturnSameSurfaceLine() + { + // Setup + var collector = new ReadConversionCollector(); + + var entity = new SurfaceLineEntity + { + Name = "surface line", + PointsXml = new Point3DCollectionXmlSerializer().ToXml(new Point3D[0]) + }; + + // Call + MacroStabilityInwardsSurfaceLine surfaceLine1 = entity.ReadAsMacroStabilityInwardsSurfaceLine(collector); + MacroStabilityInwardsSurfaceLine surfaceLine2 = entity.ReadAsMacroStabilityInwardsSurfaceLine(collector); + + // Assert + Assert.AreSame(surfaceLine1, surfaceLine2); + } + + private static Point3D CreatePoint3D(Random random) + { + return new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()); + } + + private static PipingCharacteristicPointEntity CreatePipingCharacteristicPointEntity(Point3D point, + PipingCharacteristicPointType type) + { + return new PipingCharacteristicPointEntity + { + Type = Convert.ToByte(type), + X = point.X, + Y = point.Y, + Z = point.Z + }; + } + + private static MacroStabilityInwardsCharacteristicPointEntity CreateMacroStabilityInwardsCharacteristicPointEntity( + Point3D point, + MacroStabilityInwardsCharacteristicPointType type) + { + return new MacroStabilityInwardsCharacteristicPointEntity + { + Type = Convert.ToByte(type), + X = point.X, + Y = point.Y, + Z = point.Z + }; + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/TechnicalInnovationSectionResultEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/TechnicalInnovationSectionResultEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/TechnicalInnovationSectionResultEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,93 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.Integration.Data.StandAlone.SectionResults; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; + +namespace Riskeer.Storage.Core.Test.Read +{ + [TestFixture] + public class TechnicalInnovationSectionResultEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Setup + var sectionResult = new TechnicalInnovationFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + TestDelegate call = () => ((TechnicalInnovationSectionResultEntity) null).Read(sectionResult); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_SectionResultNull_ThrowsArgumentNullException() + { + // Setup + var entity = new TechnicalInnovationSectionResultEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("sectionResult", paramName); + } + + [Test] + public void Read_ParameterValues_SetsSectionResultWithParameterValues() + { + // Setup + var random = new Random(31); + var simpleAssessmentResult = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + bool useManualAssembly = random.NextBoolean(); + var manualAssemblyCategoryGroup = random.NextEnumValue(); + + var entity = new TechnicalInnovationSectionResultEntity + { + SimpleAssessmentResult = Convert.ToByte(simpleAssessmentResult), + TailorMadeAssessmentResult = Convert.ToByte(tailorMadeAssessmentResult), + UseManualAssembly = Convert.ToByte(useManualAssembly), + ManualAssemblyCategoryGroup = Convert.ToByte(manualAssemblyCategoryGroup) + }; + var sectionResult = new TechnicalInnovationFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult); + + // Assert + Assert.AreEqual(simpleAssessmentResult, sectionResult.SimpleAssessmentResult); + Assert.AreEqual(tailorMadeAssessmentResult, sectionResult.TailorMadeAssessmentResult); + Assert.AreEqual(useManualAssembly, sectionResult.UseManualAssembly); + Assert.AreEqual(manualAssemblyCategoryGroup, sectionResult.ManualAssemblyCategoryGroup); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/WaterPressureAsphaltCoverSectionResultEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/WaterPressureAsphaltCoverSectionResultEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/WaterPressureAsphaltCoverSectionResultEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,93 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.Integration.Data.StandAlone.SectionResults; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; + +namespace Riskeer.Storage.Core.Test.Read +{ + [TestFixture] + public class WaterPressureAsphaltCoverSectionResultEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Setup + var sectionResult = new WaterPressureAsphaltCoverFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + TestDelegate call = () => ((WaterPressureAsphaltCoverSectionResultEntity) null).Read(sectionResult); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_SectionResultNull_ThrowsArgumentNullException() + { + // Setup + var entity = new WaterPressureAsphaltCoverSectionResultEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("sectionResult", paramName); + } + + [Test] + public void Read_ParameterValues_SetsSectionResultWithParameterValues() + { + // Setup + var random = new Random(31); + var simpleAssessmentResult = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + bool useManualAssembly = random.NextBoolean(); + var manualAssemblyCategoryGroup = random.NextEnumValue(); + + var entity = new WaterPressureAsphaltCoverSectionResultEntity + { + SimpleAssessmentResult = Convert.ToByte(simpleAssessmentResult), + TailorMadeAssessmentResult = Convert.ToByte(tailorMadeAssessmentResult), + UseManualAssembly = Convert.ToByte(useManualAssembly), + ManualAssemblyCategoryGroup = Convert.ToByte(manualAssemblyCategoryGroup) + }; + var sectionResult = new WaterPressureAsphaltCoverFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult); + + // Assert + Assert.AreEqual(simpleAssessmentResult, sectionResult.SimpleAssessmentResult); + Assert.AreEqual(tailorMadeAssessmentResult, sectionResult.TailorMadeAssessmentResult); + Assert.AreEqual(useManualAssembly, sectionResult.UseManualAssembly); + Assert.AreEqual(manualAssemblyCategoryGroup, sectionResult.ManualAssemblyCategoryGroup); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/WaveImpactAsphaltCover/WaveImpactAsphaltCoverFailureMechanismMetaEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/WaveImpactAsphaltCover/WaveImpactAsphaltCoverFailureMechanismMetaEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/WaveImpactAsphaltCover/WaveImpactAsphaltCoverFailureMechanismMetaEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,62 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.WaveImpactAsphaltCover.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.WaveImpactAsphaltCover; + +namespace Riskeer.Storage.Core.Test.Read.WaveImpactAsphaltCover +{ + [TestFixture] + public class WaveImpactAsphaltCoverFailureMechanismMetaEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => ((WaveImpactAsphaltCoverFailureMechanismMetaEntity) null).Read(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_Always_ReturnGeneralWaveImpactAsphaltCoverInput() + { + // Setup + var entity = new WaveImpactAsphaltCoverFailureMechanismMetaEntity + { + DeltaL = new Random(39).NextRoundedDouble(1.0, 2000.0) + }; + + // Call + GeneralWaveImpactAsphaltCoverInput generalInput = entity.Read(); + + // Assert + Assert.AreEqual(entity.DeltaL, generalInput.DeltaL, generalInput.DeltaL.GetAccuracy()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/WaveImpactAsphaltCover/WaveImpactAsphaltCoverSectionResultEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/WaveImpactAsphaltCover/WaveImpactAsphaltCoverSectionResultEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/WaveImpactAsphaltCover/WaveImpactAsphaltCoverSectionResultEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,109 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.AssemblyTool.Data; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Primitives; +using Ringtoets.WaveImpactAsphaltCover.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.WaveImpactAsphaltCover; + +namespace Riskeer.Storage.Core.Test.Read.WaveImpactAsphaltCover +{ + [TestFixture] + public class WaveImpactAsphaltCoverSectionResultEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((WaveImpactAsphaltCoverSectionResultEntity) null).Read( + new WaveImpactAsphaltCoverFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection())); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_SectionResultNull_ThrowsArgumentNullException() + { + // Setup + var entity = new WaveImpactAsphaltCoverSectionResultEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("sectionResult", paramName); + } + + [Test] + public void Read_ParameterValues_SectionResultWithParameterValues() + { + // Setup + var random = new Random(21); + var simpleAssessmentResult = random.NextEnumValue(); + var detailedAssessmentResultForFactorizedSignalingNorm = random.NextEnumValue(); + var detailedAssessmentResultForSignalingNorm = random.NextEnumValue(); + var detailedAssessmentResultForMechanismSpecificLowerLimitNorm = random.NextEnumValue(); + var detailedAssessmentResultForLowerLimitNorm = random.NextEnumValue(); + var detailedAssessmentResultForFactorizedLowerLimitNorm = random.NextEnumValue(); + var tailorMadeAssessmentResult = random.NextEnumValue(); + bool useManualAssembly = random.NextBoolean(); + var manualAssemblyCategoryGroup = random.NextEnumValue(); + + var entity = new WaveImpactAsphaltCoverSectionResultEntity + { + FailureMechanismSectionEntity = new FailureMechanismSectionEntity(), + SimpleAssessmentResult = Convert.ToByte(simpleAssessmentResult), + DetailedAssessmentResultForFactorizedSignalingNorm = Convert.ToByte(detailedAssessmentResultForFactorizedSignalingNorm), + DetailedAssessmentResultForSignalingNorm = Convert.ToByte(detailedAssessmentResultForSignalingNorm), + DetailedAssessmentResultForMechanismSpecificLowerLimitNorm = Convert.ToByte(detailedAssessmentResultForMechanismSpecificLowerLimitNorm), + DetailedAssessmentResultForLowerLimitNorm = Convert.ToByte(detailedAssessmentResultForLowerLimitNorm), + DetailedAssessmentResultForFactorizedLowerLimitNorm = Convert.ToByte(detailedAssessmentResultForFactorizedLowerLimitNorm), + TailorMadeAssessmentResult = Convert.ToByte(tailorMadeAssessmentResult), + UseManualAssembly = Convert.ToByte(useManualAssembly), + ManualAssemblyCategoryGroup = Convert.ToByte(manualAssemblyCategoryGroup) + }; + + var sectionResult = new WaveImpactAsphaltCoverFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + entity.Read(sectionResult); + + // Assert + Assert.AreEqual(simpleAssessmentResult, sectionResult.SimpleAssessmentResult); + Assert.AreEqual(detailedAssessmentResultForFactorizedSignalingNorm, sectionResult.DetailedAssessmentResultForFactorizedSignalingNorm); + Assert.AreEqual(detailedAssessmentResultForSignalingNorm, sectionResult.DetailedAssessmentResultForSignalingNorm); + Assert.AreEqual(detailedAssessmentResultForMechanismSpecificLowerLimitNorm, sectionResult.DetailedAssessmentResultForMechanismSpecificLowerLimitNorm); + Assert.AreEqual(detailedAssessmentResultForLowerLimitNorm, sectionResult.DetailedAssessmentResultForLowerLimitNorm); + Assert.AreEqual(detailedAssessmentResultForFactorizedLowerLimitNorm, sectionResult.DetailedAssessmentResultForFactorizedLowerLimitNorm); + Assert.AreEqual(tailorMadeAssessmentResult, sectionResult.TailorMadeAssessmentResult); + Assert.AreEqual(useManualAssembly, sectionResult.UseManualAssembly); + Assert.AreEqual(manualAssemblyCategoryGroup, sectionResult.ManualAssemblyCategoryGroup); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/WaveImpactAsphaltCover/WaveImpactAsphaltCoverWaveConditionsCalculationEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/WaveImpactAsphaltCover/WaveImpactAsphaltCoverWaveConditionsCalculationEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/WaveImpactAsphaltCover/WaveImpactAsphaltCoverWaveConditionsCalculationEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,294 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Revetment.Data; +using Ringtoets.Storage.Core.TestUtil.Hydraulics; +using Ringtoets.WaveImpactAsphaltCover.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Read.WaveImpactAsphaltCover; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Read.WaveImpactAsphaltCover +{ + [TestFixture] + public class WaveImpactAsphaltCoverWaveConditionsCalculationEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((WaveImpactAsphaltCoverWaveConditionsCalculationEntity) null).Read(new ReadConversionCollector()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_CollectorIsNull_ThrowArgumentNullException() + { + // Setup + var entity = new WaveImpactAsphaltCoverWaveConditionsCalculationEntity(); + + // Call + TestDelegate call = () => entity.Read(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void Read_ValidEntity_ReturnCalculation() + { + // Setup + const string name = "Calculation Name"; + const string comments = "Calculation Comment"; + + var random = new Random(21); + double orientation = random.NextDouble(); + bool useBreakWater = random.NextBoolean(); + var breakWaterType = random.NextEnumValue(); + double breakWaterHeight = random.NextDouble(); + bool useForeshore = random.NextBoolean(); + const double lowerBoundaryRevetment = 3.58; + const double upperBoundaryRevetment = 6.10; + const double lowerBoundaryWaterLevels = 3.40; + const double upperBoundaryWaterLevels = 5.88; + var stepSize = random.NextEnumValue(); + var categoryType = random.NextEnumValue(); + + var entity = new WaveImpactAsphaltCoverWaveConditionsCalculationEntity + { + Name = name, + Comments = comments, + UseBreakWater = Convert.ToByte(useBreakWater), + BreakWaterType = Convert.ToByte(breakWaterType), + BreakWaterHeight = breakWaterHeight, + UseForeshore = Convert.ToByte(useForeshore), + Orientation = orientation, + UpperBoundaryRevetment = upperBoundaryRevetment, + LowerBoundaryRevetment = lowerBoundaryRevetment, + UpperBoundaryWaterLevels = upperBoundaryWaterLevels, + LowerBoundaryWaterLevels = lowerBoundaryWaterLevels, + StepSize = Convert.ToByte(stepSize), + CategoryType = Convert.ToByte(categoryType) + }; + + var collector = new ReadConversionCollector(); + + // Call + WaveImpactAsphaltCoverWaveConditionsCalculation calculation = entity.Read(collector); + + // Assert + Assert.AreEqual(name, calculation.Name); + Assert.AreEqual(comments, calculation.Comments.Body); + + AssessmentSectionCategoryWaveConditionsInput calculationInput = calculation.InputParameters; + Assert.AreEqual(useBreakWater, calculationInput.UseBreakWater); + Assert.AreEqual(breakWaterType, calculationInput.BreakWater.Type); + AssertRoundedDouble(breakWaterHeight, calculationInput.BreakWater.Height); + Assert.AreEqual(useForeshore, calculationInput.UseForeshore); + AssertRoundedDouble(orientation, calculationInput.Orientation); + AssertRoundedDouble(upperBoundaryRevetment, calculationInput.UpperBoundaryRevetment); + AssertRoundedDouble(lowerBoundaryRevetment, calculationInput.LowerBoundaryRevetment); + AssertRoundedDouble(upperBoundaryWaterLevels, calculationInput.UpperBoundaryWaterLevels); + AssertRoundedDouble(lowerBoundaryWaterLevels, calculationInput.LowerBoundaryWaterLevels); + Assert.AreEqual(stepSize, calculationInput.StepSize); + Assert.AreEqual(categoryType, calculationInput.CategoryType); + + Assert.IsNull(calculationInput.HydraulicBoundaryLocation); + Assert.IsNull(calculationInput.ForeshoreProfile); + Assert.IsNull(calculation.Output); + } + + [Test] + public void Read_EntityWithNullValues_ReturnCalculationWithNaNValues() + { + // Setup + var entity = new WaveImpactAsphaltCoverWaveConditionsCalculationEntity(); + var collector = new ReadConversionCollector(); + + // Call + WaveImpactAsphaltCoverWaveConditionsCalculation calculation = entity.Read(collector); + + // Assert + Assert.IsNull(calculation.Name); + Assert.IsNull(calculation.Comments.Body); + + AssessmentSectionCategoryWaveConditionsInput calculationInput = calculation.InputParameters; + Assert.IsNaN(calculationInput.BreakWater.Height); + Assert.IsNaN(calculationInput.Orientation); + Assert.IsNaN(calculationInput.UpperBoundaryRevetment); + Assert.IsNaN(calculationInput.LowerBoundaryRevetment); + Assert.IsNaN(calculationInput.UpperBoundaryWaterLevels); + Assert.IsNaN(calculationInput.LowerBoundaryWaterLevels); + + Assert.IsNull(calculationInput.HydraulicBoundaryLocation); + Assert.IsNull(calculationInput.ForeshoreProfile); + Assert.IsNull(calculation.Output); + } + + [Test] + public void Read_EntityWithForeshoreProfileInCollector_CalculationHasAlreadyReadForeshoreProfile() + { + // Setup + var foreshoreProfile = new TestForeshoreProfile(); + var foreshoreProfileEntity = new ForeshoreProfileEntity + { + GeometryXml = new Point2DCollectionXmlSerializer().ToXml(Enumerable.Empty()) + }; + var entity = new WaveImpactAsphaltCoverWaveConditionsCalculationEntity + { + ForeshoreProfileEntity = foreshoreProfileEntity + }; + + var collector = new ReadConversionCollector(); + collector.Read(foreshoreProfileEntity, foreshoreProfile); + + // Call + WaveImpactAsphaltCoverWaveConditionsCalculation calculation = entity.Read(collector); + + // Assert + Assert.AreSame(foreshoreProfile, calculation.InputParameters.ForeshoreProfile); + } + + [Test] + public void Read_EntityWithForeshoreProfileNotYetInCollector_CalculationWithCreatedForeshoreProfileAndRegisteredNewEntities() + { + // Setup + const string id = "profile"; + var foreshoreProfileEntity = new ForeshoreProfileEntity + { + Id = id, + GeometryXml = new Point2DCollectionXmlSerializer().ToXml(Enumerable.Empty()) + }; + + var entity = new WaveImpactAsphaltCoverWaveConditionsCalculationEntity + { + ForeshoreProfileEntity = foreshoreProfileEntity + }; + + var collector = new ReadConversionCollector(); + + // Call + WaveImpactAsphaltCoverWaveConditionsCalculation calculation = entity.Read(collector); + + // Assert + Assert.IsTrue(collector.Contains(foreshoreProfileEntity)); + CollectionAssert.AreEqual(id, calculation.InputParameters.ForeshoreProfile.Id); + } + + [Test] + public void Read_EntityWithHydraulicBoundaryLocationInCollector_CalculationHasAlreadyReadHydraulicBoundaryLocation() + { + // Setup + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "A", 1.1, 2.2); + var hydraulicLocationEntity = new HydraulicLocationEntity(); + var entity = new WaveImpactAsphaltCoverWaveConditionsCalculationEntity + { + HydraulicLocationEntity = hydraulicLocationEntity + }; + + var collector = new ReadConversionCollector(); + collector.Read(hydraulicLocationEntity, hydraulicBoundaryLocation); + + // Call + WaveImpactAsphaltCoverWaveConditionsCalculation calculation = entity.Read(collector); + + // Assert + Assert.AreSame(hydraulicBoundaryLocation, calculation.InputParameters.HydraulicBoundaryLocation); + } + + [Test] + public void Read_EntityWithHydraulicBoundaryLocationNotYetInCollector_CalculationWithCreatedHydraulicBoundaryLocationAndRegisteredNewEntities() + { + // Setup + HydraulicLocationEntity hydraulicLocationEntity = HydraulicLocationEntityTestFactory.CreateHydraulicLocationEntity(); + var entity = new WaveImpactAsphaltCoverWaveConditionsCalculationEntity + { + HydraulicLocationEntity = hydraulicLocationEntity + }; + + var collector = new ReadConversionCollector(); + + // Call + entity.Read(collector); + + // Assert + Assert.IsTrue(collector.Contains(hydraulicLocationEntity)); + } + + [Test] + public void Read_EntityWithCalculationOutputEntity_CalculationWithOutput() + { + // Setup + const double outputALevel = 5.4; + const double outputBLevel = 2.3; + var entity = new WaveImpactAsphaltCoverWaveConditionsCalculationEntity + { + WaveImpactAsphaltCoverWaveConditionsOutputEntities = + { + new WaveImpactAsphaltCoverWaveConditionsOutputEntity + { + CalculationConvergence = Convert.ToByte(CalculationConvergence.NotCalculated), + WaterLevel = outputBLevel, + Order = 1 + }, + new WaveImpactAsphaltCoverWaveConditionsOutputEntity + { + CalculationConvergence = Convert.ToByte(CalculationConvergence.NotCalculated), + WaterLevel = outputALevel, + Order = 0 + } + } + }; + + var collector = new ReadConversionCollector(); + + // Call + WaveImpactAsphaltCoverWaveConditionsCalculation calculation = entity.Read(collector); + + // Assert + Assert.IsNotNull(calculation.Output); + Assert.AreEqual(2, calculation.Output.Items.Count()); + double accuracy = calculation.Output.Items.ElementAt(0).WaterLevel.GetAccuracy(); + Assert.AreEqual(outputALevel, calculation.Output.Items.ElementAt(0).WaterLevel, accuracy); + Assert.AreEqual(outputBLevel, calculation.Output.Items.ElementAt(1).WaterLevel, accuracy); + } + + private static void AssertRoundedDouble(double expectedValue, RoundedDouble actualValue) + { + Assert.AreEqual(expectedValue, actualValue, actualValue.GetAccuracy()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/WaveImpactAsphaltCover/WaveImpactAsphaltCoverWaveConditionsOutputEntityReadExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/WaveImpactAsphaltCover/WaveImpactAsphaltCoverWaveConditionsOutputEntityReadExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Read/WaveImpactAsphaltCover/WaveImpactAsphaltCoverWaveConditionsOutputEntityReadExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,122 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Revetment.Data; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.WaveImpactAsphaltCover; + +namespace Riskeer.Storage.Core.Test.Read.WaveImpactAsphaltCover +{ + [TestFixture] + public class WaveImpactAsphaltCoverWaveConditionsOutputEntityReadExtensionsTest + { + [Test] + public void Read_ValidEntity_ReturnOutputWithValues() + { + // Setup + var random = new Random(12); + var entity = new WaveImpactAsphaltCoverWaveConditionsOutputEntity + { + WaterLevel = random.NextDouble(), + WaveHeight = random.NextDouble(), + WavePeakPeriod = random.NextDouble(), + WaveAngle = random.NextDouble(), + WaveDirection = random.NextDouble(), + TargetProbability = random.NextDouble(), + TargetReliability = random.NextDouble(), + CalculatedProbability = random.NextDouble(), + CalculatedReliability = random.NextDouble(), + CalculationConvergence = Convert.ToByte(CalculationConvergence.CalculatedConverged) + }; + + // Call + WaveConditionsOutput output = entity.Read(); + + // Assert + Assert.IsNotNull(entity.WaterLevel); + Assert.AreEqual(entity.WaterLevel.Value, output.WaterLevel, output.WaterLevel.GetAccuracy()); + + Assert.IsNotNull(entity.WaveHeight); + Assert.AreEqual(entity.WaveHeight.Value, output.WaveHeight, output.WaveHeight.GetAccuracy()); + + Assert.IsNotNull(entity.WavePeakPeriod); + Assert.AreEqual(entity.WavePeakPeriod.Value, output.WavePeakPeriod, output.WavePeakPeriod.GetAccuracy()); + + Assert.IsNotNull(entity.WaveAngle); + Assert.AreEqual(entity.WaveAngle.Value, output.WaveAngle, output.WaveAngle.GetAccuracy()); + + Assert.IsNotNull(entity.WaveDirection); + Assert.AreEqual(entity.WaveDirection.Value, output.WaveDirection, output.WaveDirection.GetAccuracy()); + + Assert.IsNotNull(entity.TargetProbability); + Assert.AreEqual(entity.TargetProbability.Value, output.TargetProbability); + + Assert.IsNotNull(entity.TargetReliability); + Assert.AreEqual(entity.TargetReliability.Value, output.TargetReliability, output.TargetReliability.GetAccuracy()); + + Assert.IsNotNull(entity.CalculatedProbability); + Assert.AreEqual(entity.CalculatedProbability.Value, output.CalculatedProbability); + + Assert.IsNotNull(entity.CalculatedReliability); + Assert.AreEqual(entity.CalculatedReliability.Value, output.CalculatedReliability, output.CalculatedReliability.GetAccuracy()); + + Assert.IsNotNull(entity.CalculationConvergence); + Assert.AreEqual(CalculationConvergence.CalculatedConverged, output.CalculationConvergence); + } + + [Test] + public void Read_ValidEntityWithNullParameterValues_ReturnOutputWithNaNValues() + { + // Setup + var entity = new WaveImpactAsphaltCoverWaveConditionsOutputEntity + { + CalculationConvergence = Convert.ToByte(CalculationConvergence.NotCalculated), + WaterLevel = null, + WaveHeight = null, + WavePeakPeriod = null, + WaveAngle = null, + WaveDirection = null, + TargetProbability = null, + TargetReliability = null, + CalculatedProbability = null, + CalculatedReliability = null + }; + + // Call + WaveConditionsOutput output = entity.Read(); + + // Assert + Assert.IsNaN(output.WaterLevel); + Assert.IsNaN(output.WaveHeight); + Assert.IsNaN(output.WavePeakPeriod); + Assert.IsNaN(output.WaveAngle); + Assert.IsNaN(output.WaveDirection); + Assert.IsNaN(output.TargetProbability); + Assert.IsNaN(output.TargetReliability); + Assert.IsNaN(output.CalculatedProbability); + Assert.IsNaN(output.CalculatedReliability); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Riskeer.Storage.Core.Test.csproj =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Riskeer.Storage.Core.Test.csproj (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Riskeer.Storage.Core.Test.csproj (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,410 @@ + + + + {594C5C6D-5833-4E1C-9F30-13A202628EEF} + Riskeer.Storage.Core.Test + Riskeer.Storage.Core.Test + + + + + ..\..\..\..\packages\EntityFramework.6.1.3\lib\net40\EntityFramework.dll + True + + + ..\..\..\..\packages\Fluent.Ribbon.3.4.0\lib\net40\Fluent.dll + True + + + ..\..\..\..\packages\NUnit.3.8.1\lib\net40\nunit.framework.dll + True + + + + + ..\..\..\..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll + True + + + + + + ..\..\..\..\packages\System.Data.SQLite.Core.1.0.106.0\lib\net40\System.Data.SQLite.dll + True + + + ..\..\..\..\packages\System.Data.SQLite.EF6.1.0.106.0\lib\net40\System.Data.SQLite.EF6.dll + True + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {3bbfd65b-b277-4e50-ae6d-bd24c3434609} + Core.Common.Base + + + {30E4C2AE-719E-4D70-9FA9-668A9767FBFA} + Core.Common.Gui + + + {F49BD8B2-332A-4C91-A196-8CCE0A2C7D98} + Core.Common.Util + + + {D749EE4C-CE50-4C17-BF01-9A953028C126} + Core.Common.TestUtil + + + {420ED9C3-0C33-47EA-B893-121A9C0DB4F1} + Ringtoets.AssemblyTool.Data + + + {C6309704-D67B-434C-BC98-9F8910BC1D10} + Ringtoets.ClosingStructures.Data + + + {f5b43c29-6169-4e9a-859e-09090330b94e} + Ringtoets.ClosingStructures.Data.TestUtil + + + {78AA56F5-431D-465C-AC50-3173D7E90AC1} + Ringtoets.Common.Primitives + + + {6A074D65-A81C-4C1C-8E24-F36C916E4ED7} + Ringtoets.Common.Util + + + {D1068432-C172-4AA6-847B-D9DEB4C6DE26} + Ringtoets.DuneErosion.Data + + + {7BE6B522-02E3-4143-8508-C021A211DE54} + Ringtoets.DuneErosion.Data.TestUtil + + + {BF753DB5-973B-4ADF-B0F6-9437325C3466} + Ringtoets.GrassCoverErosionInwards.Data.TestUtil + + + {f67e8ae8-1ff0-4680-9817-99e025cd9ff6} + Ringtoets.HeightStructures.Data.TestUtil + + + {83d6b73e-91d5-46b0-9218-955da1f75f7c} + Ringtoets.MacroStabilityInwards.Data + + + {e9b39743-2dc9-4922-9e0f-6ba3e0e54189} + Ringtoets.MacroStabilityInwards.Primitives + + + {2b78cf04-4785-4f27-a6e5-45bddbb7bf04} + Ringtoets.MacroStabilityInwards.Data.TestUtil + + + {1DF4EE8D-0EF5-4FCC-A40E-CB8B82080FDF} + Ringtoets.MacroStabilityInwards.Primitives.TestUtil + + + {6F568E38-592A-4F99-A901-86B74C4F24D2} + Ringtoets.Piping.Primitives.TestUtil + + + {87c2c553-c0bc-40bf-b1ea-b83bff357f27} + Ringtoets.Revetment.Data + + + {3706200E-48C6-4B86-B48C-4E45C69ABE95} + Ringtoets.Revetment.Data.TestUtil + + + {3D4B9740-8348-4434-8D77-B611FC6EE57F} + Ringtoets.StabilityPointStructures.Data + + + {e9ac095b-8f10-41d2-9456-4a85e3ba91ad} + Ringtoets.StabilityPointStructures.Data.TestUtil + + + {567E0B69-5280-41CE-ADD6-443725A61C86} + Ringtoets.WaveImpactAsphaltCover.Data + + + {d4200f43-3f72-4f42-af0a-8ced416a38ec} + Ringtoets.Common.Data + + + {4843D6E5-066F-4795-94F5-1D53932DD03C} + Ringtoets.Common.Data.TestUtil + + + {90DE728E-48EF-4665-AB38-3D88E41D9F4D} + Ringtoets.GrassCoverErosionInwards.Data + + + {E7225477-577F-4A17-B7EC-6721158E1543} + Ringtoets.GrassCoverErosionOutwards.Data + + + {1c0017d8-35b5-4ca0-8fc7-a83f46dbdc99} + Ringtoets.HeightStructures.Data + + + {11f1f874-45af-43e4-8ae5-15a5c9593e28} + Ringtoets.Integration.Data + + + {CE994CC9-6F6A-48AC-B4BE-02C30A21F4DB} + Ringtoets.Piping.Data + + + {14C6F716-64E2-4BC4-A1EF-05865FCEFA4C} + Ringtoets.Piping.Primitives + + + {955E574D-67CE-4347-AA6B-7DF8A04ED754} + Ringtoets.Piping.Data.TestUtil + + + {b479e3af-7c34-488c-bb73-d324100d36c9} + Ringtoets.StabilityStoneCover.Data + + + {50963f12-448c-41ba-a62c-cdb0ab8d21e0} + Riskeer.Storage.Core + + + {03DBE353-99F7-47D6-B826-60D694FFB9AC} + Ringtoets.Storage.Core.TestUtil + + + + + Copying.licenseheader + + + Designer + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/RiskeerDatabaseCreatorTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/RiskeerDatabaseCreatorTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/RiskeerDatabaseCreatorTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,61 @@ +// Copyright (C) Stichting Deltares 2018. 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.IO; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Storage.Core.TestUtil; +using Riskeer.Storage.Core.Properties; + +namespace Riskeer.Storage.Core.Test +{ + [TestFixture] + [Explicit("Creates a new Riskeer.rtd file in the root of the Ringtoets.Storage.Core")] + public class RiskeerDatabaseCreatorTest + { + /// + /// Creates a new Riskeer.rtd file in the root of the , + /// which is used to auto-generate the database code. + /// + [Test] + public void RingtoetsDatabaseCreator_Explicit_CreatesRiskeerProjectDatabaseFile() + { + // Setup + string storageFile = GetPathToStorageFile(); + if (File.Exists(storageFile)) + { + TestDelegate precondition = () => File.Delete(storageFile); + Assert.DoesNotThrow(precondition, "Precondition failed: file could not be deleted: '{0}'", storageFile); + } + + // Call + SqLiteDatabaseHelper.CreateDatabaseFile(storageFile, Resources.DatabaseStructure); + + // Assert + Assert.IsTrue(File.Exists(storageFile)); + } + + private static string GetPathToStorageFile() + { + return Path.Combine(Path.GetDirectoryName(TestHelper.SolutionRoot), "Ringtoets", "Storage", "src", "Ringtoets.Storage.Core", "Riskeer.rtd"); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/RoundedDoubleConversionExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/RoundedDoubleConversionExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/RoundedDoubleConversionExtensionsTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,58 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Data; +using NUnit.Framework; + +namespace Riskeer.Storage.Core.Test +{ + [TestFixture] + public class RoundedDoubleConversionExtensionsTest + { + [Test] + public void ToNaNAsNull_ValueIsNaN_ReturnNull() + { + // Call + RoundedDouble? value = RoundedDouble.NaN.ToNaNAsNull(); + + // Assert + Assert.IsNull(value); + } + + [Test] + [TestCase(1.1)] + [TestCase(-2.2)] + [TestCase(double.MinValue)] + [TestCase(double.MaxValue)] + [TestCase(double.PositiveInfinity)] + [TestCase(double.NegativeInfinity)] + public void ToNaNAsNull_NotNaNValue_ReturnThatValue(double original) + { + // Call + var originalRoundedDouble = (RoundedDouble) original; + RoundedDouble? value = originalRoundedDouble.ToNaNAsNull(); + + // Assert + Assert.IsTrue(value.HasValue); + Assert.AreEqual(originalRoundedDouble, value.Value); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Serializers/DataCollectionSerializerTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Serializers/DataCollectionSerializerTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Serializers/DataCollectionSerializerTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,168 @@ +// Copyright (C) Stichting Deltares 2018. 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 System.Runtime.Serialization; +using NUnit.Framework; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Serializers +{ + [TestFixture] + public class DataCollectionSerializerTest + { + private const string invalidXml = "Invalid"; + + [Test] + public void ToXml_CollectionNull_ThrowsArgumentNullException() + { + // Setup + var serializer = new TestDataCollectionSerializer(); + + // Call + TestDelegate call = () => serializer.ToXml(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("elements", paramName); + } + + [Test] + public void ToXml_CollectionUnableToSerialize_ThrowsInvalidDataContractException() + { + // Setup + var serializer = new UnableToSerializeDataCollectionSerializer(); + var collection = new[] + { + new object() + }; + + // Call + TestDelegate call = () => serializer.ToXml(collection); + + // Assert + Assert.Throws(call); + } + + [Test] + public void GivenArray_WhenConvertingRoundTrip_ThenEqualArray() + { + // Given + var original = new[] + { + new TestSerializableObject() + }; + var serializer = new TestDataCollectionSerializer(); + + // When + string xml = serializer.ToXml(original); + TestSerializableObject[] roundtripResult = serializer.FromXml(xml); + + // Then + Assert.AreEqual(1, roundtripResult.Length); + Assert.IsInstanceOf(roundtripResult[0]); + } + + [Test] + public void GivenEmptyArray_WhenConvertingRoundTrip_ThenEqualEmptyArray() + { + // Given + var serializer = new TestDataCollectionSerializer(); + + // When + string xml = serializer.ToXml(Enumerable.Empty()); + TestSerializableObject[] roundtripResult = serializer.FromXml(xml); + + // Then + CollectionAssert.IsEmpty(roundtripResult); + } + + [Test] + public void FromXml_InvalidXml_ThrowsSerializationException() + { + // Setup + var serializer = new TestDataCollectionSerializer(); + + // Call + TestDelegate call = () => serializer.FromXml(invalidXml); + + // Assert + Assert.Throws(call); + } + + [Test] + [TestCase(null)] + [TestCase("")] + public void FromXml_XmlNullOrEmpty_ThrowArgumentException(string xml) + { + // Setup + var serializer = new TestDataCollectionSerializer(); + + // Call + TestDelegate call = () => serializer.FromXml(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("xml", paramName); + } + + [Serializable] + private class TestSerializableObject {} + + private class TestUnSerializableObject + { + public object ToObject() + { + return new object(); + } + } + + private class TestDataCollectionSerializer : DataCollectionSerializer + { + protected override TestSerializableObject[] ToSerializableData(IEnumerable objects) + { + return objects.ToArray(); + } + + protected override TestSerializableObject[] FromSerializableData(IEnumerable objectData) + { + return objectData.ToArray(); + } + } + + private class UnableToSerializeDataCollectionSerializer : DataCollectionSerializer + { + protected override TestUnSerializableObject[] ToSerializableData(IEnumerable objects) + { + return objects.Select(p => new TestUnSerializableObject()).ToArray(); + } + + protected override object[] FromSerializableData(IEnumerable objectData) + { + return objectData.Select(pd => pd.ToObject()).ToArray(); + } + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Serializers/MacroStabilityInwardsSliceCollectionXmlSerializerTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Serializers/MacroStabilityInwardsSliceCollectionXmlSerializerTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Serializers/MacroStabilityInwardsSliceCollectionXmlSerializerTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,156 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.Storage.Core.TestUtil.Serializers; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Serializers +{ + [TestFixture] + public class MacroStabilityInwardsSliceCollectionXmlSerializerTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Call + var serializer = new MacroStabilityInwardsSliceCollectionXmlSerializer(); + + // Assert + Assert.IsInstanceOf>(serializer); + SerializerTestHelper.AssertSerializedData(typeof(MacroStabilityInwardsSliceCollectionXmlSerializer.SerializableMacroStabilityInwardsSlice)); + } + + [Test] + public void GivenArrayOfMacroStabilityInwardsSlices_WhenConvertingRoundTrip_ThenEqualMacroStabilityInwardsSlices() + { + // Given + var random = new Random(31); + var original = new[] + { + new MacroStabilityInwardsSlice( + new Point2D(double.NaN, double.NaN), + new Point2D(double.NaN, double.NaN), + new Point2D(double.NaN, double.NaN), + new Point2D(double.NaN, double.NaN), + new MacroStabilityInwardsSlice.ConstructionProperties()), + new MacroStabilityInwardsSlice( + new Point2D(random.NextDouble(), random.NextDouble()), + new Point2D(random.NextDouble(), random.NextDouble()), + new Point2D(random.NextDouble(), random.NextDouble()), + new Point2D(random.NextDouble(), random.NextDouble()), + new MacroStabilityInwardsSlice.ConstructionProperties + { + Cohesion = random.NextDouble(), + FrictionAngle = random.NextDouble(), + CriticalPressure = random.NextDouble(), + OverConsolidationRatio = random.NextDouble(), + Pop = random.NextDouble(), + DegreeOfConsolidationPorePressureSoil = random.NextDouble(), + DegreeOfConsolidationPorePressureLoad = random.NextDouble(), + Dilatancy = random.NextDouble(), + ExternalLoad = random.NextDouble(), + HydrostaticPorePressure = random.NextDouble(), + LeftForce = random.NextDouble(), + LeftForceAngle = random.NextDouble(), + LeftForceY = random.NextDouble(), + RightForce = random.NextDouble(), + RightForceAngle = random.NextDouble(), + RightForceY = random.NextDouble(), + LoadStress = random.NextDouble(), + NormalStress = random.NextDouble(), + PorePressure = random.NextDouble(), + HorizontalPorePressure = random.NextDouble(), + VerticalPorePressure = random.NextDouble(), + PiezometricPorePressure = random.NextDouble(), + EffectiveStress = random.NextDouble(), + EffectiveStressDaily = random.NextDouble(), + ExcessPorePressure = random.NextDouble(), + ShearStress = random.NextDouble(), + SoilStress = random.NextDouble(), + TotalPorePressure = random.NextDouble(), + TotalStress = random.NextDouble(), + Weight = random.NextDouble() + }) + }; + var serializer = new MacroStabilityInwardsSliceCollectionXmlSerializer(); + + // When + string xml = serializer.ToXml(original); + MacroStabilityInwardsSlice[] roundtripResult = serializer.FromXml(xml); + + // Then + TestHelper.AssertCollectionsAreEqual(original, roundtripResult, new MacroStabilityInwardsSliceComparer()); + } + + private class MacroStabilityInwardsSliceComparer : IEqualityComparer + { + public bool Equals(MacroStabilityInwardsSlice x, MacroStabilityInwardsSlice y) + { + return x.TopLeftPoint.Equals(y.TopLeftPoint) + && x.TopRightPoint.Equals(y.TopRightPoint) + && x.BottomLeftPoint.Equals(y.BottomLeftPoint) + && x.BottomRightPoint.Equals(y.BottomRightPoint) + && x.Cohesion.Equals(y.Cohesion) + && x.FrictionAngle.Equals(y.FrictionAngle) + && x.CriticalPressure.Equals(y.CriticalPressure) + && x.OverConsolidationRatio.Equals(y.OverConsolidationRatio) + && x.Pop.Equals(y.Pop) + && x.DegreeOfConsolidationPorePressureSoil.Equals(y.DegreeOfConsolidationPorePressureSoil) + && x.DegreeOfConsolidationPorePressureLoad.Equals(y.DegreeOfConsolidationPorePressureLoad) + && x.Dilatancy.Equals(y.Dilatancy) + && x.ExternalLoad.Equals(y.ExternalLoad) + && x.HydrostaticPorePressure.Equals(y.HydrostaticPorePressure) + && x.LeftForce.Equals(y.LeftForce) + && x.LeftForceAngle.Equals(y.LeftForceAngle) + && x.LeftForceY.Equals(y.LeftForceY) + && x.RightForce.Equals(y.RightForce) + && x.RightForceAngle.Equals(y.RightForceAngle) + && x.RightForceY.Equals(y.RightForceY) + && x.LoadStress.Equals(y.LoadStress) + && x.NormalStress.Equals(y.NormalStress) + && x.PorePressure.Equals(y.PorePressure) + && x.HorizontalPorePressure.Equals(y.HorizontalPorePressure) + && x.VerticalPorePressure.Equals(y.VerticalPorePressure) + && x.PiezometricPorePressure.Equals(y.PiezometricPorePressure) + && x.EffectiveStress.Equals(y.EffectiveStress) + && x.EffectiveStressDaily.Equals(y.EffectiveStressDaily) + && x.ExcessPorePressure.Equals(y.ExcessPorePressure) + && x.ShearStress.Equals(y.ShearStress) + && x.SoilStress.Equals(y.SoilStress) + && x.TotalPorePressure.Equals(y.TotalPorePressure) + && x.TotalStress.Equals(y.TotalStress) + && x.Weight.Equals(y.Weight); + } + + public int GetHashCode(MacroStabilityInwardsSlice obj) + { + throw new NotImplementedException(); + } + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Serializers/Point2DCollectionXmlSerializerTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Serializers/Point2DCollectionXmlSerializerTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Serializers/Point2DCollectionXmlSerializerTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,69 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.Storage.Core.TestUtil.Serializers; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Serializers +{ + [TestFixture] + public class Point2DCollectionXmlSerializerTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Call + var serializer = new Point2DCollectionXmlSerializer(); + + // Assert + Assert.IsInstanceOf>(serializer); + SerializerTestHelper.AssertSerializedData(typeof(Point2DCollectionXmlSerializer.SerializablePoint2D)); + } + + [Test] + public void GivenArrayWithPoint2D_WhenConvertingRoundTrip_ThenEqualArrayOfPoints2D() + { + // Given + var original = new[] + { + new Point2D(-7.7, -6.6), + new Point2D(-5.5, -4.4), + new Point2D(-3.3, -2.2), + new Point2D(-1.1, 0.0), + new Point2D(1.1, 2.2), + new Point2D(3.3, 4.4), + new Point2D(5.5, 6.6), + new Point2D(7.7, 8.8), + new Point2D(9.9, 10.10) + }; + var serializer = new Point2DCollectionXmlSerializer(); + + // When + string xml = serializer.ToXml(original); + Point2D[] roundtripResult = serializer.FromXml(xml); + + // Then + CollectionAssert.AreEqual(original, roundtripResult); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Serializers/Point3DCollectionXmlSerializerTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Serializers/Point3DCollectionXmlSerializerTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Serializers/Point3DCollectionXmlSerializerTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,66 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.Storage.Core.TestUtil.Serializers; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Serializers +{ + [TestFixture] + public class Point3DCollectionXmlSerializerTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Call + var serializer = new Point3DCollectionXmlSerializer(); + + // Assert + Assert.IsInstanceOf>(serializer); + SerializerTestHelper.AssertSerializedData(typeof(Point3DCollectionXmlSerializer.SerializablePoint3D)); + } + + [Test] + public void GivenArrayWithPoint3D_WhenConvertingRoundTrip_ThenEqualArrayOfPoints3D() + { + // Given + var original = new[] + { + new Point3D(-6.6, -5.5, -4.4), + new Point3D(-3.3, -2.2, -1.1), + new Point3D(0.0, 1.1, 2.2), + new Point3D(3.3, 4.4, 5.5), + new Point3D(6.6, 7.7, 8.8), + new Point3D(9.9, 10.10, 11.11) + }; + var serializer = new Point3DCollectionXmlSerializer(); + + // When + string xml = serializer.ToXml(original); + Point3D[] roundtripResult = serializer.FromXml(xml); + + // Then + CollectionAssert.AreEqual(original, roundtripResult); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Serializers/RoughnessPointCollectionXmlSerializerTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Serializers/RoughnessPointCollectionXmlSerializerTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Serializers/RoughnessPointCollectionXmlSerializerTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,86 @@ +// Copyright (C) Stichting Deltares 2018. 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.Collections; +using Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Storage.Core.TestUtil.Serializers; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Serializers +{ + [TestFixture] + public class RoughnessPointCollectionXmlSerializerTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Call + var serializer = new RoughnessPointCollectionXmlSerializer(); + + // Assert + Assert.IsInstanceOf>(serializer); + SerializerTestHelper.AssertSerializedData(typeof(RoughnessPointCollectionXmlSerializer.SerializableRoughnessPoint)); + } + + [Test] + public void GivenArrayWithRoughnessPoint_WhenConvertingRoundTrip_ThenEqualArrayOfRoughnessPoint() + { + // Given + var original = new[] + { + new RoughnessPoint(new Point2D(-7.7, -6.6), 0.5), + new RoughnessPoint(new Point2D(-5.5, -4.4), 0.6), + new RoughnessPoint(new Point2D(-3.3, -2.2), 0.7), + new RoughnessPoint(new Point2D(-1.1, 0.0), 0.8), + new RoughnessPoint(new Point2D(1.1, 2.2), 0.9), + new RoughnessPoint(new Point2D(3.3, 4.4), 1.0), + new RoughnessPoint(new Point2D(5.5, 6.6), 0.9), + new RoughnessPoint(new Point2D(7.7, 8.8), 0.8), + new RoughnessPoint(new Point2D(9.9, 10.10), 0.7) + }; + var converter = new RoughnessPointCollectionXmlSerializer(); + + // When + string xml = converter.ToXml(original); + RoughnessPoint[] roundtripResult = converter.FromXml(xml); + + // Then + CollectionAssert.AreEqual(original, roundtripResult, new RoughnessPointComparer()); + } + + private class RoughnessPointComparer : IComparer + { + public int Compare(object x, object y) + { + var x1 = (RoughnessPoint) x; + var y1 = (RoughnessPoint) y; + if (x1.Point.Equals(y1.Point) && x1.Roughness.Equals(y1.Roughness)) + { + return 0; + } + + return 1; + } + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Serializers/TangentLineCollectionXmlSerializerTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Serializers/TangentLineCollectionXmlSerializerTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/Serializers/TangentLineCollectionXmlSerializerTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,65 @@ +// Copyright (C) Stichting Deltares 2018. 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 Core.Common.Base.Data; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Storage.Core.TestUtil.Serializers; +using Riskeer.Storage.Core.Serializers; + +namespace Riskeer.Storage.Core.Test.Serializers +{ + [TestFixture] + public class TangentLineCollectionXmlSerializerTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Call + var serializer = new TangentLineCollectionXmlSerializer(); + + // Assert + Assert.IsInstanceOf>(serializer); + SerializerTestHelper.AssertSerializedData(typeof(TangentLineCollectionXmlSerializer.SerializableTangentLine)); + } + + [Test] + public void GivenArrayOfTangentLines_WhenConvertingRoundTrip_ThenEqualTangentLines() + { + // Given + var random = new Random(31); + RoundedDouble[] original = + { + new RoundedDouble(2, double.NaN), + random.NextRoundedDouble() + }; + var serializer = new TangentLineCollectionXmlSerializer(); + + // When + string xml = serializer.ToXml(original); + RoundedDouble[] roundtripResult = serializer.FromXml(xml); + + // Then + CollectionAssert.AreEqual(original, roundtripResult); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/SqLiteEntityConnectionStringBuilderTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/SqLiteEntityConnectionStringBuilderTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/SqLiteEntityConnectionStringBuilderTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,89 @@ +// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework; + +namespace Riskeer.Storage.Core.Test +{ + [TestFixture] + public class SqLiteEntityConnectionStringBuilderTest + { + private const string pathToSqLiteFile = @"C:\SqLiteFile.sqlite"; + + [Test] + [TestCase(null)] + [TestCase("")] + [TestCase(" ")] + public void BuildSqLiteEntityConnectionString_InvalidPathToSqLiteFile_ThrowsArgumentNullException(string invalidPathToSqLiteFile) + { + // Call + TestDelegate test = () => SqLiteEntityConnectionStringBuilder.BuildSqLiteEntityConnectionString( + invalidPathToSqLiteFile); + + // Assert + Assert.Throws(test); + } + + [Test] + public void BuildSqLiteEntityConnectionString_ValidPathToSqLiteFile_ValidConnectionString() + { + // Call + string connectionString = SqLiteEntityConnectionStringBuilder.BuildSqLiteEntityConnectionString( + pathToSqLiteFile); + + // Assert + Assert.That(!string.IsNullOrEmpty(connectionString)); + StringAssert.Contains(string.Format("metadata=res://*/{0}.csdl|res://*/{0}.ssdl|res://*/{0}.msl;", + "DbContext.RiskeerEntities"), connectionString); + StringAssert.Contains("provider=System.Data.SQLite.EF6", connectionString); + StringAssert.Contains("failifmissing=True", connectionString); + StringAssert.Contains($"data source={pathToSqLiteFile}", connectionString); + StringAssert.Contains("read only=False", connectionString); + StringAssert.Contains("foreign keys=True", connectionString); + StringAssert.Contains("version=3", connectionString); + StringAssert.Contains("pooling=False", connectionString); + } + + [Test] + public void BuildSqLiteEntityConnectionString_ValidUncPathToSqLiteFile_ValidConnectionString() + { + // Setup + const string uncPathToSqlFile = @"\\server\share\file.sqlite"; + + // Call + string connectionString = SqLiteEntityConnectionStringBuilder.BuildSqLiteEntityConnectionString( + uncPathToSqlFile); + + // Assert + Assert.That(!string.IsNullOrEmpty(connectionString)); + StringAssert.Contains(string.Format("metadata=res://*/{0}.csdl|res://*/{0}.ssdl|res://*/{0}.msl;", + "DbContext.RiskeerEntities"), connectionString); + StringAssert.Contains("provider=System.Data.SQLite.EF6", connectionString); + StringAssert.Contains("failifmissing=True", connectionString); + StringAssert.Contains($@"data source=\\{uncPathToSqlFile}", connectionString); + StringAssert.Contains("read only=False", connectionString); + StringAssert.Contains("foreign keys=True", connectionString); + StringAssert.Contains("version=3", connectionString); + StringAssert.Contains("pooling=False", connectionString); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/StorageSqLiteTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/StorageSqLiteTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/StorageSqLiteTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,552 @@ +// Copyright (C) Stichting Deltares 2018. 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.Data; +using System.Data.SQLite; +using System.IO; +using Core.Common.Base.Data; +using Core.Common.Base.Storage; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Util; +using Ringtoets.Integration.Data; +using Ringtoets.Storage.Core.TestUtil; + +namespace Riskeer.Storage.Core.Test +{ + [TestFixture] + public class StorageSqLiteTest + { + private readonly string testPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Storage.Core, "DatabaseFiles"); + private readonly string workingDirectory = TestHelper.GetScratchPadPath(nameof(StorageSqLiteTest)); + private DirectoryDisposeHelper directoryDisposeHelper; + + [Test] + public void DefaultConstructor_ExpectedValues() + { + // Call + var storage = new StorageSqLite(); + + // Assert + Assert.IsInstanceOf(storage); + Assert.AreEqual("Ringtoetsproject (*.rtd)|*.rtd", storage.FileFilter); + } + + [Test] + [TestCase(null)] + [TestCase("")] + [TestCase(" ")] + public void LoadProject_InvalidPath_ThrowsArgumentException(string invalidPath) + { + // Call + TestDelegate test = () => new StorageSqLite().LoadProject(invalidPath); + + // Assert + var exception = Assert.Throws(test); + Assert.IsInstanceOf(exception); + Assert.AreEqual($"Fout bij het lezen van bestand '{invalidPath}': bestandspad mag niet leeg of ongedefinieerd zijn.", + exception.Message); + } + + [Test] + public void LoadProject_NonExistingPath_ThrowsStorageExceptionAndCouldNotConnectException() + { + // Setup + const string nonExistingPath = "fileDoesNotExist"; + + // Call + TestDelegate test = () => new StorageSqLite().LoadProject(nonExistingPath); + + // Assert + StorageException exception = Assert.Throws(test); + + Assert.AreEqual($@"Fout bij het lezen van bestand '{nonExistingPath}': het bestand bestaat niet.", + exception.Message); + } + + [Test] + public void LoadProject_RingtoetsFileWithoutSchema_ThrowsStorageExceptionAndStorageValidationException() + { + // Setup + const string validPath = "empty.rtd"; + string tempFile = Path.Combine(testPath, validPath); + + // Call + TestDelegate test = () => new StorageSqLite().LoadProject(tempFile); + + // Assert + StorageException exception = Assert.Throws(test); + Assert.AreEqual($@"Fout bij het lezen van bestand '{tempFile}': het bestand is geen geldig Ringtoets bestand.", + exception.Message); + } + + [Test] + public void LoadProject_RingtoetsFileWithTwoProjects_ThrowsStorageExceptionAndStorageValidationException() + { + // Setup + string tempRingtoetsFile = Path.Combine(workingDirectory, nameof(LoadProject_RingtoetsFileWithTwoProjects_ThrowsStorageExceptionAndStorageValidationException)); + + TestDelegate precondition = () => SqLiteDatabaseHelper.CreateCompleteDatabaseFileWithoutProjectData(tempRingtoetsFile); + Assert.DoesNotThrow(precondition, "Precondition failed: creating corrupt database file failed"); + + // Call + TestDelegate test = () => new StorageSqLite().LoadProject(tempRingtoetsFile); + + // Assert + string expectedMessage = $@"Fout bij het lezen van bestand '{tempRingtoetsFile}': het bestand is geen geldig Ringtoets bestand."; + + var exception = Assert.Throws(test); + Assert.IsInstanceOf(exception); + Assert.AreEqual(expectedMessage, exception.Message); + } + + [Test] + public void LoadProject_CorruptRingtoetsFileThatPassesValidation_ThrowsStorageExceptionWithFullStackTrace() + { + // Setup + string tempRingtoetsFile = Path.Combine(workingDirectory, nameof(LoadProject_CorruptRingtoetsFileThatPassesValidation_ThrowsStorageExceptionWithFullStackTrace)); + TestDelegate precondition = () => SqLiteDatabaseHelper.CreateCorruptDatabaseFile(tempRingtoetsFile); + Assert.DoesNotThrow(precondition, "Precondition failed: creating corrupt database file failed"); + + // Call + TestDelegate test = () => new StorageSqLite().LoadProject(tempRingtoetsFile); + + // Assert + var exception = Assert.Throws(test); + Assert.IsInstanceOf(exception); + Assert.AreEqual($@"Fout bij het lezen van bestand '{tempRingtoetsFile}': het bestand is geen geldig Ringtoets bestand.", + exception.Message); + + Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual("An error occurred while executing the command definition. See the inner exception for details.", + exception.InnerException.Message); + + Assert.IsInstanceOf(exception.InnerException.InnerException); + Assert.AreEqual($"SQL logic error{Environment.NewLine}" + + "no such table: AssessmentSectionEntity", exception.InnerException.InnerException.Message); + } + + [Test] + public void LoadProject_DatabaseWithoutVersionEntities_ThrowStorageValidationException() + { + // Setup + string tempRingtoetsFile = Path.Combine(workingDirectory, nameof(LoadProject_DatabaseWithoutVersionEntities_ThrowStorageValidationException)); + + TestDelegate precondition = () => SqLiteDatabaseHelper.CreateCompleteDatabaseFileEmpty(tempRingtoetsFile); + Assert.DoesNotThrow(precondition, "Precondition failed: creating corrupt database file failed"); + + // Call + TestDelegate test = () => new StorageSqLite().LoadProject(tempRingtoetsFile); + + // Assert + StorageException exception = Assert.Throws(test); + Assert.IsInstanceOf(exception); + Assert.AreEqual($@"Fout bij het lezen van bestand '{tempRingtoetsFile}': database moet één rij in de VersionEntity tabel hebben.", + exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + + [Test] + public void LoadProject_DatabaseWithMultipleVersionEntities_ThrowStorageValidationException() + { + // Setup + string tempRingtoetsFile = Path.Combine(workingDirectory, nameof(LoadProject_DatabaseWithMultipleVersionEntities_ThrowStorageValidationException)); + string currentDatabaseVersion = RingtoetsVersionHelper.GetCurrentDatabaseVersion(); + + TestDelegate precondition = () => + { + SqLiteDatabaseHelper.CreateCompleteDatabaseFileEmpty(tempRingtoetsFile); + SqLiteDatabaseHelper.AddVersionEntity(tempRingtoetsFile, currentDatabaseVersion); + SqLiteDatabaseHelper.AddVersionEntity(tempRingtoetsFile, currentDatabaseVersion); + }; + Assert.DoesNotThrow(precondition, "Precondition failed: creating corrupt database file failed"); + + // Call + TestDelegate test = () => new StorageSqLite().LoadProject(tempRingtoetsFile); + + // Assert + StorageException exception = Assert.Throws(test); + Assert.IsInstanceOf(exception); + Assert.AreEqual($@"Fout bij het lezen van bestand '{tempRingtoetsFile}': database moet één rij in de VersionEntity tabel hebben.", + exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + + [Test] + [TestCase(1)] + [TestCase(500)] + public void LoadProject_DatabaseFromFutureVersion_ThrowStorageValidationException(int additionalVersionNumber) + { + // Setup + string tempRingtoetsFile = Path.Combine(workingDirectory, $"{nameof(LoadProject_DatabaseFromFutureVersion_ThrowStorageValidationException)}_{Path.GetRandomFileName()}"); + string currentDatabaseVersion = RingtoetsVersionHelper.GetCurrentDatabaseVersion(); + string versionCode = additionalVersionNumber + currentDatabaseVersion; + + TestDelegate precondition = () => + { + SqLiteDatabaseHelper.CreateCompleteDatabaseFileEmpty(tempRingtoetsFile); + SqLiteDatabaseHelper.AddVersionEntity(tempRingtoetsFile, versionCode); + }; + Assert.DoesNotThrow(precondition, "Precondition failed: creating future database file failed"); + + // Call + TestDelegate test = () => new StorageSqLite().LoadProject(tempRingtoetsFile); + + // Assert + StorageException exception = Assert.Throws(test); + Assert.IsInstanceOf(exception); + Assert.AreEqual($@"Fout bij het lezen van bestand '{tempRingtoetsFile}': ringtoets " + + $"bestand versie '{versionCode}' is hoger dan de huidig ondersteunde versie " + + $"('{currentDatabaseVersion}'). Update Ringtoets naar een nieuwere versie.", + exception.Message); + } + + [Test] + [TestCase("0")] + [TestCase("-567")] + public void LoadProject_DatabaseWithInvalidVersionCode_ThrowStorageValidationException(string versionCode) + { + // Setup + string tempRingtoetsFile = Path.Combine(workingDirectory, $"{nameof(LoadProject_DatabaseWithInvalidVersionCode_ThrowStorageValidationException)}_{Path.GetRandomFileName()}"); + + TestDelegate precondition = () => + { + SqLiteDatabaseHelper.CreateCompleteDatabaseFileEmpty(tempRingtoetsFile); + SqLiteDatabaseHelper.AddVersionEntity(tempRingtoetsFile, versionCode); + }; + Assert.DoesNotThrow(precondition, "Precondition failed: creating future database file failed"); + + // Call + TestDelegate test = () => new StorageSqLite().LoadProject(tempRingtoetsFile); + + // Assert + StorageException exception = Assert.Throws(test); + Assert.IsInstanceOf(exception); + Assert.AreEqual($@"Fout bij het lezen van bestand '{tempRingtoetsFile}': ringtoets " + + $"bestand versie '{versionCode}' is niet valide. De versie van het Ringtoets projectbestand " + + "dient '16.4' of hoger te zijn.", exception.Message); + } + + [Test] + public void LoadProject_ValidDatabase_ReturnsProject() + { + // Setup + string tempRingtoetsFile = Path.Combine(workingDirectory, nameof(LoadProject_ValidDatabase_ReturnsProject)); + string projectName = Path.GetFileNameWithoutExtension(tempRingtoetsFile); + var storage = new StorageSqLite(); + var mockRepository = new MockRepository(); + var project = mockRepository.StrictMock(); + project.Description = ""; + + // Precondition + SqLiteDatabaseHelper.CreateValidRingtoetsDatabase(tempRingtoetsFile, project); + + // Call + IProject loadedProject = storage.LoadProject(tempRingtoetsFile); + + // Assert + Assert.IsInstanceOf(loadedProject); + Assert.AreEqual(projectName, loadedProject.Name); + Assert.AreEqual(project.Description, loadedProject.Description); + } + + [Test] + public void StageProject_ProjectIsNull_ThrowsArgumentNullException() + { + // Setup + var storage = new StorageSqLite(); + + // Call + TestDelegate test = () => storage.StageProject(null); + + // Assert + Assert.Throws(test); + } + + [Test] + [TestCase(null)] + [TestCase("")] + [TestCase(" ")] + public void SaveProjectAs_InvalidPath_ThrowsArgumentException(string invalidPath) + { + // Setup + var project = new RingtoetsProject(); + + var storage = new StorageSqLite(); + storage.StageProject(project); + + // Call + TestDelegate test = () => storage.SaveProjectAs(invalidPath); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual($"Fout bij het lezen van bestand '{invalidPath}': bestandspad mag niet " + + "leeg of ongedefinieerd zijn.", exception.Message); + } + + [Test] + public void SaveProjectAs_ValidPathToNonExistingFile_DoesNotThrowException() + { + // Setup + string tempRingtoetsFile = Path.Combine(workingDirectory, nameof(SaveProjectAs_ValidPathToNonExistingFile_DoesNotThrowException)); + var project = new RingtoetsProject(); + var storage = new StorageSqLite(); + storage.StageProject(project); + + // Precondition + Assert.IsFalse(File.Exists(tempRingtoetsFile)); + + // Call + TestDelegate test = () => storage.SaveProjectAs(tempRingtoetsFile); + + // Assert + Assert.DoesNotThrow(test); + } + + [Test] + public void SaveProjectAs_ValidPathToExistingFile_DoesNotThrowException() + { + // Setup + string tempRingtoetsFile = Path.Combine(workingDirectory, nameof(SaveProjectAs_ValidPathToExistingFile_DoesNotThrowException)); + var project = new RingtoetsProject(); + var storage = new StorageSqLite(); + storage.StageProject(project); + + using (File.Create(tempRingtoetsFile)) {} + + // Call + TestDelegate test = () => storage.SaveProjectAs(tempRingtoetsFile); + + // Assert + Assert.DoesNotThrow(test); + } + + [Test] + public void SaveProjectAs_ValidPathToLockedFile_ThrowsUpdateStorageException() + { + // Setup + string tempRingtoetsFile = Path.Combine(workingDirectory, nameof(SaveProjectAs_ValidPathToLockedFile_ThrowsUpdateStorageException)); + var project = new RingtoetsProject(); + var storage = new StorageSqLite(); + storage.StageProject(project); + + using (var fileDisposeHelper = new FileDisposeHelper(tempRingtoetsFile)) + { + try + { + fileDisposeHelper.LockFiles(); + + // Call + TestDelegate test = () => storage.SaveProjectAs(tempRingtoetsFile); + + // Assert + var exception = Assert.Throws(test); + + Assert.IsInstanceOf(exception); + Assert.IsInstanceOf(exception.InnerException); + Assert.IsInstanceOf(exception); + Assert.AreEqual($@"Kan geen tijdelijk bestand maken van het originele bestand ({tempRingtoetsFile}).", + exception.Message); + } + finally + { + CallGarbageCollector(); + } + } + } + + [Test] + public void SaveProjectAs_NoStagedProject_ThrowInvalidOperationException() + { + // Setup + string tempRingtoetsFile = TestHelper.GetScratchPadPath(nameof(SaveProjectAs_NoStagedProject_ThrowInvalidOperationException)); + var storage = new StorageSqLite(); + + // Precondition + Assert.IsFalse(storage.HasStagedProject); + + // Call + TestDelegate call = () => storage.SaveProjectAs(tempRingtoetsFile); + + // Assert + string message = Assert.Throws(call).Message; + Assert.AreEqual("Call 'StageProject(IProject)' first before calling this method.", message); + } + + [Test] + public void HasStagedProjectChanges_InvalidPath_ThrowsArgumentException() + { + // Setup + var storage = new StorageSqLite(); + storage.StageProject(new RingtoetsProject()); + + string path = Path.Combine(testPath, "ValidCharacteristics.csv"); + char[] invalidCharacters = Path.GetInvalidPathChars(); + string corruptPath = path.Replace('V', invalidCharacters[0]); + + // Call + TestDelegate call = () => storage.HasStagedProjectChanges(corruptPath); + + // Assert + Assert.Throws(call); + } + + [Test] + public void HasStagedProjectChanges_NoProjectStaged_ThrowInvalidOperationException() + { + // Setup + var storage = new StorageSqLite(); + + // Precondition + Assert.IsFalse(storage.HasStagedProject); + + // Call + TestDelegate call = () => storage.HasStagedProjectChanges(null); + + // Assert + string message = Assert.Throws(call).Message; + Assert.AreEqual("Call 'StageProject(IProject)' first before calling this method.", message); + } + + [Test] + public void HasStagedProjectChanges_NoPathGiven_ReturnsTrue() + { + // Setup + var storageSqLite = new StorageSqLite(); + storageSqLite.StageProject(new RingtoetsProject()); + + // Call + bool hasChanges = storageSqLite.HasStagedProjectChanges(null); + + // Assert + Assert.IsTrue(hasChanges); + } + + [Test] + public void HasStagedProjectChanges_ValidProjectLoaded_ReturnsFalse() + { + // Setup + var storageSqLite = new StorageSqLite(); + var storedProject = new RingtoetsProject(); + string tempRingtoetsFile = Path.Combine(workingDirectory, nameof(HasStagedProjectChanges_ValidProjectLoaded_ReturnsFalse)); + + SqLiteDatabaseHelper.CreateValidRingtoetsDatabase(tempRingtoetsFile, storedProject); + IProject loadedProject = storageSqLite.LoadProject(tempRingtoetsFile); + storageSqLite.StageProject(loadedProject); + + // Call + bool hasChanges = storageSqLite.HasStagedProjectChanges(tempRingtoetsFile); + + // Assert + Assert.IsFalse(hasChanges); + } + + [Test] + public void HasStagedProjectChanges_ValidProjectLoadedWithUnaffectedChange_ReturnsFalse() + { + // Setup + var storageSqLite = new StorageSqLite(); + var storedProject = new RingtoetsProject(); + const string changedName = "some name"; + string tempRingtoetsFile = Path.Combine(workingDirectory, nameof(HasStagedProjectChanges_ValidProjectLoadedWithUnaffectedChange_ReturnsFalse)); + + SqLiteDatabaseHelper.CreateValidRingtoetsDatabase(tempRingtoetsFile, storedProject); + IProject loadedProject = storageSqLite.LoadProject(tempRingtoetsFile); + storageSqLite.StageProject(loadedProject); + + // Call + loadedProject.Name = changedName; + bool hasChanges = storageSqLite.HasStagedProjectChanges(tempRingtoetsFile); + + // Assert + Assert.IsFalse(hasChanges); + } + + [Test] + public void HasStagedProjectChanges_ValidProjectLoadedWithAffectedChange_ReturnsTrue() + { + // Setup + var storageSqLite = new StorageSqLite(); + RingtoetsProject storedProject = RiskeerProjectTestHelper.GetFullTestProject(); + const string changedDescription = "some description"; + string tempRingtoetsFile = Path.Combine(workingDirectory, nameof(HasStagedProjectChanges_ValidProjectLoadedWithAffectedChange_ReturnsTrue)); + + SqLiteDatabaseHelper.CreateValidRingtoetsDatabase(tempRingtoetsFile, storedProject); + IProject loadedProject = storageSqLite.LoadProject(tempRingtoetsFile); + + loadedProject.Description = changedDescription; + storageSqLite.StageProject(loadedProject); + + // Call + bool hasChanges = storageSqLite.HasStagedProjectChanges(tempRingtoetsFile); + + // Assert + Assert.IsTrue(hasChanges); + } + + [Test] + public void HasStagedProjectChanges_SavedToEmptyDatabaseFile_ReturnsFalse() + { + // Setup + var mockRepository = new MockRepository(); + var project = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + var storage = new StorageSqLite(); + string tempRingtoetsFile = Path.Combine(workingDirectory, nameof(HasStagedProjectChanges_SavedToEmptyDatabaseFile_ReturnsFalse)); + + // Precondition, required to set the connection string + storage.StageProject(project); + TestDelegate precondition = () => storage.SaveProjectAs(tempRingtoetsFile); + Assert.DoesNotThrow(precondition, "Precondition failed: creating database file failed"); + + storage.StageProject(project); + + // Call + bool hasChanges = storage.HasStagedProjectChanges(tempRingtoetsFile); + + // Assert + Assert.IsFalse(hasChanges); + + mockRepository.VerifyAll(); + } + + [OneTimeSetUp] + public void SetUp() + { + directoryDisposeHelper = new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(StorageSqLiteTest)); + } + + [OneTimeTearDown] + public void TearDown() + { + CallGarbageCollector(); + directoryDisposeHelper.Dispose(); + } + + private static void CallGarbageCollector() + { + GC.Collect(); + GC.WaitForPendingFinalizers(); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/StorageSqliteCreatorTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/StorageSqliteCreatorTest.cs (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/StorageSqliteCreatorTest.cs (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,123 @@ +// Copyright (C) Stichting Deltares 2018. 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.IO; +using Core.Common.TestUtil; +using NUnit.Framework; + +namespace Riskeer.Storage.Core.Test +{ + [TestFixture] + public class StorageSqliteCreatorTest + { + [Test] + [TestCase(null)] + [TestCase("")] + [TestCase(" ")] + [TestCase("C:\\folder\\")] + public void CreateDatabaseStructure_InvalidFilePath_ThrowsArgumentException(string invalidPath) + { + // Call + TestDelegate call = () => StorageSqliteCreator.CreateDatabaseStructure(invalidPath); + + // Assert + Assert.Throws(call); + } + + [Test] + public void CreateDatabaseStructure_WithNonExistingPath_DoesNotThrowException() + { + // Setup + const string fileName = "DoesNotExist.sqlite"; + string fullPath = TestHelper.GetScratchPadPath(fileName); + + // Precondition + Assert.IsFalse(File.Exists(fullPath)); + + try + { + // Call + TestDelegate call = () => StorageSqliteCreator.CreateDatabaseStructure(fullPath); + + // Assert + Assert.DoesNotThrow(call); + + Assert.IsTrue(File.Exists(fullPath)); + } + finally + { + if (File.Exists(fullPath)) + { + File.Delete(fullPath); + } + } + } + + [Test] + public void CreateDatabaseStructure_WithNonExistingNetworkPath_DoesNotThrowException() + { + // Setup + const string fileName = "DoesNotExist.sqlite"; + string fullPath = TestHelper.GetScratchPadPath(fileName); + string uncPath = TestHelper.ToUncPath(fullPath); + + // Precondition + Assert.IsFalse(File.Exists(fullPath)); + + try + { + // Call + TestDelegate call = () => StorageSqliteCreator.CreateDatabaseStructure(uncPath); + + // Assert + Assert.DoesNotThrow(call); + + Assert.IsTrue(File.Exists(fullPath)); + } + finally + { + if (File.Exists(fullPath)) + { + File.Delete(fullPath); + } + } + } + + [Test] + public void CreateDatabaseStructure_ValidExistingFile_ThrowsStorageException() + { + string tempRingtoetsFile = TestHelper.GetScratchPadPath(nameof(CreateDatabaseStructure_ValidExistingFile_ThrowsStorageException)); + using (var disposeHelper = new FileDisposeHelper(tempRingtoetsFile)) + { + disposeHelper.LockFiles(); + + // Call + TestDelegate call = () => StorageSqliteCreator.CreateDatabaseStructure(tempRingtoetsFile); + + // Assert + var exception = Assert.Throws(call); + string expectedMessage = $@"File '{tempRingtoetsFile}' already exists."; + Assert.AreEqual(expectedMessage, exception.Message); + } + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/packages.config =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/packages.config (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/packages.config (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1,31 @@ + + + + + + + + + + \ No newline at end of file Index: Ringtoets/Storage/test/Riskeer.Storage.Core.Test/test-data/DatabaseFiles/empty.rtd =================================================================== diff -u --- Ringtoets/Storage/test/Riskeer.Storage.Core.Test/test-data/DatabaseFiles/empty.rtd (revision 0) +++ Ringtoets/Storage/test/Riskeer.Storage.Core.Test/test-data/DatabaseFiles/empty.rtd (revision 2d850ad8de01dd4896ada4999d18f787165ce644) @@ -0,0 +1 @@ \ No newline at end of file