Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/StructuresCalculationCreateExtensionsTest.cs =================================================================== diff -u -r183d1e7ed095ea4e8024068bc4ddfcf3ac6997d3 -rbce62ec6102f15b0dbb1328fd9d14063fd21c978 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/StructuresCalculationCreateExtensionsTest.cs (.../StructuresCalculationCreateExtensionsTest.cs) (revision 183d1e7ed095ea4e8024068bc4ddfcf3ac6997d3) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/StructuresCalculationCreateExtensionsTest.cs (.../StructuresCalculationCreateExtensionsTest.cs) (revision bce62ec6102f15b0dbb1328fd9d14063fd21c978) @@ -24,8 +24,11 @@ using Application.Ringtoets.Storage.DbContext; using Application.Ringtoets.Storage.TestUtil; using Core.Common.Base.Data; +using Core.Common.Base.Geometry; 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.Probability; using Ringtoets.Common.Data.Structures; @@ -38,14 +41,16 @@ [TestFixture] public class StructuresCalculationCreateExtensionsTest { + #region CreateForHeightStructures + [Test] - public void Create_PersistenceRegistryNull_ThrowArgumentNullException() + public void CreateForHeightStructures_PersistenceRegistryNull_ThrowArgumentNullException() { // Setup var calculation = new StructuresCalculation(); // Call - TestDelegate call = () => calculation.Create(null, 0); + TestDelegate call = () => calculation.CreateForHeightStructures(null, 0); // Assert string paramName = Assert.Throws(call).ParamName; @@ -55,7 +60,7 @@ [Test] [TestCase("I have no comments", null, 0, 827364)] [TestCase("I have a comment", "I am comment", 98, 231)] - public void Create_ValidCalculation_ReturnEntity(string name, string comments, int order, int randomSeed) + public void CreateForHeightStructures_ValidCalculation_ReturnEntity(string name, string comments, int order, int randomSeed) { // Setup var random = new Random(randomSeed); @@ -121,7 +126,7 @@ var registry = new PersistenceRegistry(); // Call - HeightStructuresCalculationEntity entity = calculation.Create(registry, order); + HeightStructuresCalculationEntity entity = calculation.CreateForHeightStructures(registry, order); // Assert Assert.AreEqual(0, entity.HeightStructuresCalculationEntityId); @@ -161,7 +166,7 @@ } [Test] - public void Create_NaNParameters_EntityWithNullFields() + public void CreateForHeightStructures_NaNParameters_EntityWithNullFields() { // Setup var calculation = new StructuresCalculation @@ -218,7 +223,7 @@ var registry = new PersistenceRegistry(); // Call - HeightStructuresCalculationEntity entity = calculation.Create(registry, 0); + HeightStructuresCalculationEntity entity = calculation.CreateForHeightStructures(registry, 0); // Assert Assert.IsNull(entity.StructureNormalOrientation); @@ -242,7 +247,7 @@ } [Test] - public void Create_StringPropertiesDoNotShareReference() + public void CreateForHeightStructures_StringPropertiesDoNotShareReference() { // Setup const string name = "A"; @@ -256,7 +261,7 @@ var registry = new PersistenceRegistry(); // Call - HeightStructuresCalculationEntity entity = calculation.Create(registry, 0); + HeightStructuresCalculationEntity entity = calculation.CreateForHeightStructures(registry, 0); // Assert Assert.AreNotSame(name, entity.Name, @@ -269,7 +274,7 @@ } [Test] - public void Create_CalculationWithAlreadySavedHydraulicBoundaryLocation_ReturnEntityWithHydraulicLocationEntity() + public void CreateForHeightStructures_CalculationWithAlreadySavedHydraulicBoundaryLocation_ReturnEntityWithHydraulicLocationEntity() { // Setup var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "A", 1, 1); @@ -286,14 +291,14 @@ registry.Register(hydraulicLocationEntity, hydraulicBoundaryLocation); // Call - HeightStructuresCalculationEntity entity = calculation.Create(registry, 0); + HeightStructuresCalculationEntity entity = calculation.CreateForHeightStructures(registry, 0); // Assert Assert.AreSame(hydraulicLocationEntity, entity.HydraulicLocationEntity); } [Test] - public void Create_CalculationWithAlreadySavedHeightStructure_ReturnEntityWithHeightStructureEntity() + public void CreateForHeightStructures_CalculationWithAlreadySavedHeightStructure_ReturnEntityWithHeightStructureEntity() { // Setup var heightStructure = new TestHeightStructure(); @@ -310,14 +315,14 @@ registry.Register(heightStructureEntity, heightStructure); // Call - HeightStructuresCalculationEntity entity = calculation.Create(registry, 0); + HeightStructuresCalculationEntity entity = calculation.CreateForHeightStructures(registry, 0); // Assert Assert.AreSame(heightStructureEntity, entity.HeightStructureEntity); } [Test] - public void Create_CalculationWithAlreadySavedForeshoreProfile_ReturnEntityWithForeshoreProfileEntity() + public void CreateForHeightStructures_CalculationWithAlreadySavedForeshoreProfile_ReturnEntityWithForeshoreProfileEntity() { // Setup var foreshoreProfile = new TestForeshoreProfile(); @@ -334,14 +339,14 @@ registry.Register(foreshoreProfileEntity, foreshoreProfile); // Call - HeightStructuresCalculationEntity entity = calculation.Create(registry, 0); + HeightStructuresCalculationEntity entity = calculation.CreateForHeightStructures(registry, 0); // Assert Assert.AreSame(foreshoreProfileEntity, entity.ForeshoreProfileEntity); } [Test] - public void Create_CalculationWithOutput_ReturnEntity() + public void CreateForHeightStructures_CalculationWithOutput_ReturnEntity() { // Setup var random = new Random(159); @@ -355,10 +360,351 @@ var registry = new PersistenceRegistry(); // Call - HeightStructuresCalculationEntity entity = calculation.Create(registry, 0); + HeightStructuresCalculationEntity entity = calculation.CreateForHeightStructures(registry, 0); // Assert Assert.AreEqual(1, entity.HeightStructuresOutputEntities.Count); } + + #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 = "B", + InputParameters = + { + StormDuration = + { + Mean = (RoundedDouble) random.NextDouble(), + }, + StructureNormalOrientation = (RoundedDouble) random.NextDouble(), + FailureProbabilityStructureWithErosion = (RoundedDouble) random.NextDouble(), + UseForeshore = random.NextBoolean(), + UseBreakWater = random.NextBoolean(), + BreakWater = + { + Type = BreakWaterType.Dam, + Height = (RoundedDouble) random.NextDouble() + }, + AllowedLevelIncreaseStorage = + { + Mean = (RoundedDouble) random.NextDouble(), + StandardDeviation = (RoundedDouble) random.NextDouble() + }, + StorageStructureArea = + { + Mean = (RoundedDouble) random.NextDouble(), + CoefficientOfVariation = (RoundedDouble) random.NextDouble() + }, + FlowWidthAtBottomProtection = + { + Mean = (RoundedDouble) random.NextDouble(), + StandardDeviation = (RoundedDouble) random.NextDouble() + }, + CriticalOvertoppingDischarge = + { + Mean = (RoundedDouble) random.NextDouble(), + CoefficientOfVariation = (RoundedDouble) random.NextDouble() + }, + ModelFactorSuperCriticalFlow = + { + Mean = (RoundedDouble) random.NextDouble() + }, + WidthFlowApertures = + { + Mean = (RoundedDouble) random.NextDouble(), + CoefficientOfVariation = (RoundedDouble) random.NextDouble() + }, + InflowModelType = ClosingStructureInflowModelType.VerticalWall, + InsideWaterLevel = + { + Mean = (RoundedDouble) random.NextDouble(), + StandardDeviation = (RoundedDouble) random.NextDouble() + }, + DeviationWaveDirection = (RoundedDouble) random.NextDouble(), + DrainCoefficient = + { + Mean = (RoundedDouble) random.NextDouble() + }, + FactorStormDurationOpenStructure = (RoundedDouble) random.NextDouble(), + ThresholdHeightOpenWeir = + { + Mean = (RoundedDouble) random.NextDouble(), + StandardDeviation = (RoundedDouble) random.NextDouble() + }, + AreaFlowApertures = + { + Mean = (RoundedDouble) random.NextDouble(), + StandardDeviation = (RoundedDouble) random.NextDouble() + }, + FailureProbabilityOpenStructure = (RoundedDouble) random.NextDouble(), + FailureProbabilityReparation = (RoundedDouble) random.NextDouble(), + IdenticalApertures = random.Next(), + LevelCrestStructureNotClosing = + { + Mean = (RoundedDouble) random.NextDouble(), + StandardDeviation = (RoundedDouble) random.NextDouble() + }, + ProbabilityOpenStructureBeforeFlooding = (RoundedDouble) random.NextDouble() + } + }; + + var registry = new PersistenceRegistry(); + + const int order = 67; + + // Call + ClosingStructuresCalculationEntity entity = calculation.CreateForClosingStructures(registry, order); + + // Assert + Assert.AreEqual(calculation.Name, entity.Name); + Assert.AreEqual(calculation.Comments, 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.CoefficientOfVariation.Value, entity.WidthFlowAperturesCoefficientOfVariation); + 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.FailureProbablityReparation); + 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(order, entity.Order); + } + + [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, + CoefficientOfVariation = 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.WidthFlowAperturesCoefficientOfVariation); + 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 alreadyRegisteredHydroLocation = new HydraulicBoundaryLocation(1, "A", 2, 3); + var calculation = new StructuresCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = alreadyRegisteredHydroLocation + } + }; + + var registry = new PersistenceRegistry(); + registry.Register(new HydraulicLocationEntity(), alreadyRegisteredHydroLocation); + + // Call + ClosingStructuresCalculationEntity entity = calculation.CreateForClosingStructures(registry, 0); + + // Assert + Assert.IsNotNull(entity.HydraulicLocationEntity); + } + + [Test] + public void CreateForClosingStructures_CalculationWithForeshoreProfile_ReturnEntityWithForeshoreProfileEntity() + { + // Setup + var alreadyRegisteredForeshoreProfile = new ForeshoreProfile(new Point2D(0, 0), + new Point2D[0], + null, + new ForeshoreProfile.ConstructionProperties()); + 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); + } + + #endregion } } \ No newline at end of file