Index: Ringtoets/Common/src/Ringtoets.Common.IO/Configurations/Helpers/XElementExtensions.cs
===================================================================
diff -u -r8ebf5b222f3b052df95f6164ac488a5e7760cf68 -rdd18dca1346bd551789e19700faef78e48091771
--- Ringtoets/Common/src/Ringtoets.Common.IO/Configurations/Helpers/XElementExtensions.cs (.../XElementExtensions.cs) (revision 8ebf5b222f3b052df95f6164ac488a5e7760cf68)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/Configurations/Helpers/XElementExtensions.cs (.../XElementExtensions.cs) (revision dd18dca1346bd551789e19700faef78e48091771)
@@ -125,6 +125,7 @@
{
return null;
}
+
return new TConverter().ConvertFromInvariantString(stringValue);
}
@@ -152,6 +153,7 @@
{
return null;
}
+
return new TConverter().ConvertFrom(doubleValue);
}
@@ -169,6 +171,7 @@
{
throw new ArgumentNullException(nameof(parentElement));
}
+
if (stochastName == null)
{
throw new ArgumentNullException(nameof(stochastName));
@@ -194,6 +197,7 @@
{
throw new ArgumentNullException(nameof(parentElement));
}
+
if (descendantElementName == null)
{
throw new ArgumentNullException(nameof(descendantElementName));
@@ -207,6 +211,8 @@
///
/// The element containing values for stochast parameters.
/// The name of the stochast to find the parameter values for.
+ /// The configuration, or null when the
+ /// does not have stochast elements with the name .
/// Thrown when any parameter is null.
/// Thrown when the value for a parameter isn't in the correct format.
/// Thrown when the value for a parameter represents a number less
@@ -217,6 +223,7 @@
{
throw new ArgumentNullException(nameof(calculationElement));
}
+
if (stochastName == null)
{
throw new ArgumentNullException(nameof(stochastName));
@@ -233,13 +240,16 @@
VariationCoefficient = element.GetDoubleValueFromDescendantElement(ConfigurationSchemaIdentifiers.VariationCoefficientElement)
};
}
+
return null;
}
///
/// Gets a wave reduction configuration based on the values found in the .
///
/// The element containing values for wave reduction parameters.
+ /// The configuration, or null when the does not
+ /// have wave reduction elements.
/// Thrown when is null.
/// Thrown when the value for break water type isn't valid.
/// Thrown when the value for break water height, use foreshore profile or
@@ -259,13 +269,16 @@
UseForeshoreProfile = calculationElement.GetBoolValueFromDescendantElement(ConfigurationSchemaIdentifiers.UseForeshore)
};
}
+
return null;
}
///
/// Gets a scenario configuration based on the values found in the .
///
/// The element containing values for scenario parameters.
+ /// The configuration, or null when the does not
+ /// have scenario elements.
/// Thrown when is null.
/// Thrown when the value for contribution or is relevant
/// for scenario is not in the correct format to convert to a value.
@@ -287,7 +300,26 @@
Contribution = calculationElement.GetDoubleValueFromDescendantElement(ConfigurationSchemaIdentifiers.ScenarioContribution)
};
}
+
return null;
}
+
+ ///
+ /// Gets a hydraulic boundary location name based on the values found in the .
+ ///
+ /// The element containing values for scenario parameters.
+ /// Thrown when is null.
+ /// The hydraulic boundary location name, or null when the does not
+ /// have hydraulic boundary location elements.
+ public static string GetHydraulicBoundaryLocationName(this XElement calculationElement)
+ {
+ if (calculationElement == null)
+ {
+ throw new ArgumentNullException(nameof(calculationElement));
+ }
+
+ return calculationElement.GetStringValueFromDescendantElement(ConfigurationSchemaIdentifiers.HydraulicBoundaryLocationElementNew)
+ ?? calculationElement.GetStringValueFromDescendantElement(ConfigurationSchemaIdentifiers.HydraulicBoundaryLocationElementOld);
+ }
}
}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Configurations/Helpers/XElementExtensionsTest.cs
===================================================================
diff -u -r803d02ac855a1ac3ef4881e4557ae14209882411 -rdd18dca1346bd551789e19700faef78e48091771
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Configurations/Helpers/XElementExtensionsTest.cs (.../XElementExtensionsTest.cs) (revision 803d02ac855a1ac3ef4881e4557ae14209882411)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Configurations/Helpers/XElementExtensionsTest.cs (.../XElementExtensionsTest.cs) (revision dd18dca1346bd551789e19700faef78e48091771)
@@ -1199,6 +1199,49 @@
Assert.AreEqual(isRelevant, configuration.IsRelevant);
}
+ [Test]
+ public void GetHydraulicBoundaryLocationName_CalculationElementNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate call = () => ((XElement) null).GetHydraulicBoundaryLocationName();
+
+ // Assert
+ var exception = Assert.Throws(call);
+ Assert.AreEqual("calculationElement", exception.ParamName);
+ }
+
+ [Test]
+ [TestCase("hrlocatie")]
+ [TestCase("hblocatie")]
+ public void GetHydraulicBoundaryLocationName_WithHydraulicBoundaryLocation_ReturnHydraulicBoundaryLocationName(string tagName)
+ {
+ // Setup
+ const string locationName = "Location1";
+
+ var locationElement = new XElement(tagName, locationName);
+ var configurationElement = new XElement("scenario", locationElement);
+ var xElement = new XElement("root", configurationElement);
+
+ // Call
+ string configuration = xElement.GetHydraulicBoundaryLocationName();
+
+ // Assert
+ Assert.AreEqual(locationName, configuration);
+ }
+
+ [Test]
+ public void GetHydraulicBoundaryLocationName_OtherDescendantElement_ReturnsNull()
+ {
+ // Setup
+ var xElement = new XElement("root", new XElement("OtherDescendantElement"));
+
+ // Call
+ string configuration = xElement.GetHydraulicBoundaryLocationName();
+
+ // Assert
+ Assert.IsNull(configuration);
+ }
+
private class DoubleToBooleanConverter : TypeConverter
{
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
Index: Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Configurations/WaveConditionsCalculationConfigurationReader.cs
===================================================================
diff -u -r57ef881a6cda7c218d06759e0ac7d92f6d6bfab7 -rdd18dca1346bd551789e19700faef78e48091771
--- Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Configurations/WaveConditionsCalculationConfigurationReader.cs (.../WaveConditionsCalculationConfigurationReader.cs) (revision 57ef881a6cda7c218d06759e0ac7d92f6d6bfab7)
+++ Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Configurations/WaveConditionsCalculationConfigurationReader.cs (.../WaveConditionsCalculationConfigurationReader.cs) (revision dd18dca1346bd551789e19700faef78e48091771)
@@ -86,7 +86,7 @@
protected void ParseCalculationElementData(XElement calculationElement, T configuration)
{
- configuration.HydraulicBoundaryLocationName = GetHydraulicBoundaryLocationName(calculationElement);
+ configuration.HydraulicBoundaryLocationName = calculationElement.GetHydraulicBoundaryLocationName();
configuration.UpperBoundaryRevetment = calculationElement.GetDoubleValueFromDescendantElement(WaveConditionsCalculationConfigurationSchemaIdentifiers.UpperBoundaryRevetment);
configuration.LowerBoundaryRevetment = calculationElement.GetDoubleValueFromDescendantElement(WaveConditionsCalculationConfigurationSchemaIdentifiers.LowerBoundaryRevetment);
configuration.UpperBoundaryWaterLevels = calculationElement.GetDoubleValueFromDescendantElement(WaveConditionsCalculationConfigurationSchemaIdentifiers.UpperBoundaryWaterLevels);
@@ -96,11 +96,5 @@
configuration.Orientation = calculationElement.GetDoubleValueFromDescendantElement(ConfigurationSchemaIdentifiers.Orientation);
configuration.WaveReduction = calculationElement.GetWaveReductionParameters();
}
-
- private static string GetHydraulicBoundaryLocationName(XElement calculationElement)
- {
- return calculationElement.GetStringValueFromDescendantElement(ConfigurationSchemaIdentifiers.HydraulicBoundaryLocationElementNew)
- ?? calculationElement.GetStringValueFromDescendantElement(ConfigurationSchemaIdentifiers.HydraulicBoundaryLocationElementOld);
- }
}
}
\ No newline at end of file