Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/StabilityStoneCover/StabilityStoneCoverWaveConditionsCalculationCreateExtensions.cs
===================================================================
diff -u -rac96d7c315129af851634ed5a4a6800b59ede718 -r307c64f9b0db863143e745bb8df2188ab570a8dc
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/StabilityStoneCover/StabilityStoneCoverWaveConditionsCalculationCreateExtensions.cs (.../StabilityStoneCoverWaveConditionsCalculationCreateExtensions.cs) (revision ac96d7c315129af851634ed5a4a6800b59ede718)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/StabilityStoneCover/StabilityStoneCoverWaveConditionsCalculationCreateExtensions.cs (.../StabilityStoneCoverWaveConditionsCalculationCreateExtensions.cs) (revision 307c64f9b0db863143e745bb8df2188ab570a8dc)
@@ -41,10 +41,15 @@
/// The object keeping track of create operations.
/// The index at which resides within its parent.
/// A new .
- /// Thrown when is null.
+ /// Thrown when any parameter is null.
internal static StabilityStoneCoverWaveConditionsCalculationEntity Create(this StabilityStoneCoverWaveConditionsCalculation calculation,
PersistenceRegistry registry, int order)
{
+ if (calculation == null)
+ {
+ throw new ArgumentNullException(nameof(calculation));
+ }
+
if (registry == null)
{
throw new ArgumentNullException(nameof(registry));
@@ -57,33 +62,36 @@
Comments = calculation.Comments.Body.DeepClone()
};
- SetInputParameters(entity, calculation, registry);
+ SetInputParameters(entity, calculation.InputParameters, registry);
SetOutputEntities(entity, calculation);
return entity;
}
- private static void SetInputParameters(StabilityStoneCoverWaveConditionsCalculationEntity entity, StabilityStoneCoverWaveConditionsCalculation calculation, PersistenceRegistry registry)
+ private static void SetInputParameters(StabilityStoneCoverWaveConditionsCalculationEntity entity,
+ AssessmentSectionCategoryWaveConditionsInput calculationInput,
+ PersistenceRegistry registry)
{
- if (calculation.InputParameters.HydraulicBoundaryLocation != null)
+ if (calculationInput.HydraulicBoundaryLocation != null)
{
- entity.HydraulicLocationEntity = calculation.InputParameters.HydraulicBoundaryLocation.Create(registry, 0);
+ entity.HydraulicLocationEntity = calculationInput.HydraulicBoundaryLocation.Create(registry, 0);
}
- if (calculation.InputParameters.ForeshoreProfile != null)
+ if (calculationInput.ForeshoreProfile != null)
{
- entity.ForeshoreProfileEntity = calculation.InputParameters.ForeshoreProfile.Create(registry, 0);
+ entity.ForeshoreProfileEntity = calculationInput.ForeshoreProfile.Create(registry, 0);
}
- entity.Orientation = calculation.InputParameters.Orientation;
- entity.UseBreakWater = Convert.ToByte(calculation.InputParameters.UseBreakWater);
- entity.BreakWaterType = (byte) calculation.InputParameters.BreakWater.Type;
- entity.BreakWaterHeight = calculation.InputParameters.BreakWater.Height;
- entity.UseForeshore = Convert.ToByte(calculation.InputParameters.UseForeshore);
- entity.UpperBoundaryRevetment = calculation.InputParameters.UpperBoundaryRevetment;
- entity.LowerBoundaryRevetment = calculation.InputParameters.LowerBoundaryRevetment;
- entity.UpperBoundaryWaterLevels = calculation.InputParameters.UpperBoundaryWaterLevels;
- entity.LowerBoundaryWaterLevels = calculation.InputParameters.LowerBoundaryWaterLevels;
- entity.StepSize = Convert.ToByte(calculation.InputParameters.StepSize);
+ entity.Orientation = calculationInput.Orientation.ToNaNAsNull();
+ entity.UseBreakWater = Convert.ToByte(calculationInput.UseBreakWater);
+ entity.BreakWaterType = Convert.ToByte(calculationInput.BreakWater.Type);
+ entity.BreakWaterHeight = calculationInput.BreakWater.Height.ToNaNAsNull();
+ entity.UseForeshore = Convert.ToByte(calculationInput.UseForeshore);
+ entity.UpperBoundaryRevetment = calculationInput.UpperBoundaryRevetment.ToNaNAsNull();
+ entity.LowerBoundaryRevetment = calculationInput.LowerBoundaryRevetment.ToNaNAsNull();
+ entity.UpperBoundaryWaterLevels = calculationInput.UpperBoundaryWaterLevels.ToNaNAsNull();
+ entity.LowerBoundaryWaterLevels = calculationInput.LowerBoundaryWaterLevels.ToNaNAsNull();
+ entity.StepSize = Convert.ToByte(calculationInput.StepSize);
+ entity.CategoryType = Convert.ToByte(calculationInput.CategoryType);
}
private static void SetOutputEntities(StabilityStoneCoverWaveConditionsCalculationEntity entity, StabilityStoneCoverWaveConditionsCalculation calculation)
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/StabilityStoneCover/StabilityStoneCoverWaveConditionsCalculationCreateExtensionsTest.cs
===================================================================
diff -u -ra096cb901099c85dbaafa2dba6c69288464c248e -r307c64f9b0db863143e745bb8df2188ab570a8dc
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/StabilityStoneCover/StabilityStoneCoverWaveConditionsCalculationCreateExtensionsTest.cs (.../StabilityStoneCoverWaveConditionsCalculationCreateExtensionsTest.cs) (revision a096cb901099c85dbaafa2dba6c69288464c248e)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/StabilityStoneCover/StabilityStoneCoverWaveConditionsCalculationCreateExtensionsTest.cs (.../StabilityStoneCoverWaveConditionsCalculationCreateExtensionsTest.cs) (revision 307c64f9b0db863143e745bb8df2188ab570a8dc)
@@ -20,13 +20,14 @@
// All rights reserved.
using System;
-using System.Collections.Generic;
using System.Linq;
using Application.Ringtoets.Storage.Create;
using Application.Ringtoets.Storage.Create.StabilityStoneCover;
using Application.Ringtoets.Storage.DbContext;
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;
@@ -39,6 +40,17 @@
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_PersistenceRegistryIsNull_ThrowArgumentNullException()
{
// Setup
@@ -53,33 +65,25 @@
}
[Test]
- [TestCaseSource(nameof(ValidWaveConditionsInputs))]
- public void Create_CalculationWithPropertiesSet_ReturnCalculationEntity(
- double orientation, bool useBreakWater, double lowerBoundaryRevetment,
- double upperBoundaryRevetment, double lowerBoundaryWaterLevels,
- double upperBoundaryWaterLevels, WaveConditionsInputStepSize stepSize)
+ public void Create_CalculationWithPropertiesSet_ReturnCalculationEntity()
{
// Setup
- const string name = "Name";
- const string comments = "comments";
- const int order = 1234;
+ var random = new Random(21);
+ int order = random.Next();
var calculation = new StabilityStoneCoverWaveConditionsCalculation
{
- Name = name,
- Comments =
- {
- Body = comments
- },
InputParameters =
{
- Orientation = (RoundedDouble) orientation,
- UseBreakWater = useBreakWater,
- UpperBoundaryRevetment = (RoundedDouble) upperBoundaryRevetment,
- LowerBoundaryRevetment = (RoundedDouble) lowerBoundaryRevetment,
- UpperBoundaryWaterLevels = (RoundedDouble) upperBoundaryWaterLevels,
- LowerBoundaryWaterLevels = (RoundedDouble) lowerBoundaryWaterLevels,
- StepSize = stepSize
+ 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()
}
};
@@ -89,28 +93,59 @@
StabilityStoneCoverWaveConditionsCalculationEntity entity = calculation.Create(registry, order);
// Assert
- Assert.AreEqual(name, entity.Name);
- Assert.AreEqual(comments, entity.Comments);
-
- WaveConditionsInput input = calculation.InputParameters;
- Assert.AreEqual(input.Orientation.Value, entity.Orientation);
- Assert.AreEqual(Convert.ToByte(useBreakWater), entity.UseBreakWater);
- Assert.AreEqual(Convert.ToByte(false), entity.UseForeshore);
+ 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.AreEqual(0, entity.StabilityStoneCoverWaveConditionsCalculationEntityId);
Assert.IsNull(entity.CalculationGroupEntity);
- Assert.AreEqual(0, entity.StabilityStoneCoverWaveConditionsOutputEntities.Count);
- Assert.IsNull(entity.ForeshoreProfileEntityId);
- Assert.IsNull(entity.HydraulicLocationEntityId);
+ 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
@@ -131,13 +166,8 @@
StabilityStoneCoverWaveConditionsCalculationEntity 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(comments, entity.Comments,
- "To create stable binary representations/fingerprints, it's really important that strings are not shared.");
- Assert.AreEqual(comments, entity.Comments);
+ TestHelper.AssertAreEqualButNotSame(calculation.Name, entity.Name);
+ TestHelper.AssertAreEqualButNotSame(calculation.Comments.Body, entity.Comments);
}
[Test]
@@ -211,24 +241,5 @@
1
}, entity.StabilityStoneCoverWaveConditionsOutputEntities.Select(oe => oe.Order));
}
-
- private static IEnumerable ValidWaveConditionsInputs()
- {
- yield return new TestCaseData(1.0, true, 3.58, 6.10, 3.40, 5.88, WaveConditionsInputStepSize.Half).SetName("ValuesSetBWTrueStepSizeHalf");
- yield return new TestCaseData(1.0, true, 3.58, 6.10, 3.40, 5.88, WaveConditionsInputStepSize.One).SetName("ValuesSetBWTrueStepSizeOne");
- yield return new TestCaseData(1.0, true, 3.58, 6.10, 3.40, 5.88, WaveConditionsInputStepSize.Two).SetName("ValuesSetBWTrueStepSizeTwo");
-
- yield return new TestCaseData(1.0, false, 3.58, 6.10, 3.40, 5.88, WaveConditionsInputStepSize.Half).SetName("ValuesSetBWFalseStepSizeHalf");
- yield return new TestCaseData(1.0, false, 3.58, 6.10, 3.40, 5.88, WaveConditionsInputStepSize.One).SetName("ValuesSetBWFalseStepSizeOne");
- yield return new TestCaseData(1.0, false, 3.58, 6.10, 3.40, 5.88, WaveConditionsInputStepSize.Two).SetName("ValuesSetBWFalseStepSizeTwo");
-
- yield return new TestCaseData(double.NaN, true, double.NaN, double.NaN, double.NaN, double.NaN, WaveConditionsInputStepSize.Half).SetName("NaNValuesBWTrueStepSizeHalf");
- yield return new TestCaseData(double.NaN, true, double.NaN, double.NaN, double.NaN, double.NaN, WaveConditionsInputStepSize.One).SetName("NaNValuesBWTrueStepSizeOne");
- yield return new TestCaseData(double.NaN, true, double.NaN, double.NaN, double.NaN, double.NaN, WaveConditionsInputStepSize.Two).SetName("NaNValuesBWTrueStepSizeTwo");
-
- yield return new TestCaseData(double.NaN, false, double.NaN, double.NaN, double.NaN, double.NaN, WaveConditionsInputStepSize.Half).SetName("NaNValuesBWFalseStepSizeHalf");
- yield return new TestCaseData(double.NaN, false, double.NaN, double.NaN, double.NaN, double.NaN, WaveConditionsInputStepSize.One).SetName("NaNValuesBWFalseStepSizeOne");
- yield return new TestCaseData(double.NaN, false, double.NaN, double.NaN, double.NaN, double.NaN, WaveConditionsInputStepSize.Two).SetName("NaNValuesBWFalseStepSizeTwo");
- }
}
}
\ No newline at end of file