Index: DamClients/DamUI/trunk/src/Dam/Tests/DamEngineIo/FillXmlInputFromDamUiTests.cs
===================================================================
diff -u -r2630 -r2645
--- DamClients/DamUI/trunk/src/Dam/Tests/DamEngineIo/FillXmlInputFromDamUiTests.cs (.../FillXmlInputFromDamUiTests.cs) (revision 2630)
+++ DamClients/DamUI/trunk/src/Dam/Tests/DamEngineIo/FillXmlInputFromDamUiTests.cs (.../FillXmlInputFromDamUiTests.cs) (revision 2645)
@@ -609,13 +609,13 @@
public void RaiseExceptionWhenRiverLevelIsMissing()
{
// Given DataSet with undefined RiverLevel
- DamProjectData expectedDamProjectData = CreateExampleDamProjectData();
- var scenario = expectedDamProjectData.WaterBoard.Dikes[0].Locations[0].Scenarios[0];
+ DamProjectData damProjectData = CreateExampleDamProjectData();
+ var scenario = damProjectData.WaterBoard.Dikes[0].Locations[0].Scenarios[0];
scenario.RiverLevel = null;
// When Writing Xml, Then Raise Exception With Clear Message
- var expectedMessage = "Location 'Location 1', scenario '1' has no river level" + Environment.NewLine + "Parameter name: value";
- Assert.That(() => FillXmlInputFromDamUi.CreateInput(expectedDamProjectData), Throws.TypeOf(typeof(ArgumentNullException)).With.Message.EqualTo(expectedMessage));
+ var expectedMessage = "Location 'Location 1', scenario '1' has no river level" + Environment.NewLine + "Parameter name: RiverLevel";
+ Assert.That(() => FillXmlInputFromDamUi.CreateInput(damProjectData), Throws.TypeOf(typeof(ArgumentNullException)).With.Message.EqualTo(expectedMessage));
}
[Test]
@@ -627,23 +627,35 @@
public void RaiseExceptionWhenRiverLevelLowIsMissingForStabilityOutside(FailureMechanismSystemType failureMechanismSystemType, string expectedMessage)
{
// Given DataSet with undefined RiverLevelLow
- DamProjectData expectedDamProjectData = CreateExampleDamProjectData();
- var scenario = expectedDamProjectData.WaterBoard.Dikes[0].Locations[0].Scenarios[0];
+ DamProjectData damProjectData = CreateExampleDamProjectData();
+ var scenario = damProjectData.WaterBoard.Dikes[0].Locations[0].Scenarios[0];
scenario.RiverLevelLow = null;
- var currentSpecification = expectedDamProjectData.DamProjectCalculationSpecification.CurrentSpecification;
+ var currentSpecification = damProjectData.DamProjectCalculationSpecification.CurrentSpecification;
currentSpecification.FailureMechanismSystemType = failureMechanismSystemType;
// When Writing Xml, Then Raise Exception With Clear Message in case of Stability Outside
if (expectedMessage != string.Empty)
{
- Assert.That(() => FillXmlInputFromDamUi.CreateInput(expectedDamProjectData), Throws.TypeOf(typeof(ArgumentNullException)).With.Message.Contains(expectedMessage));
+ Assert.That(() => FillXmlInputFromDamUi.CreateInput(damProjectData), Throws.TypeOf(typeof(ArgumentNullException)).With.Message.Contains(expectedMessage));
}
else
{
- Assert.That(() => FillXmlInputFromDamUi.CreateInput(expectedDamProjectData), Throws.Nothing);
+ Assert.That(() => FillXmlInputFromDamUi.CreateInput(damProjectData), Throws.Nothing);
}
}
+ [Test]
+ public void RaiseExceptionWhenWaterBoardIsNotDefined()
+ {
+ // Given DataSet with undefine waterboard
+ DamProjectData damProjectData = new DamProjectData();
+ damProjectData.WaterBoard = null;
+
+ // When Writing Xml, Then Raise Exception With Clear Message in case of Stability Outside
+ var expectedMessage = "No dike defined in this project" + Environment.NewLine + "Parameter name: WaterBoard";
+ Assert.That(() => FillXmlInputFromDamUi.CreateInput(damProjectData), Throws.TypeOf(typeof(ArgumentNullException)).With.Message.EqualTo(expectedMessage));
+ }
+
}
}
Index: DamClients/DamUI/trunk/src/Dam/Tests/CsvParserTest.cs
===================================================================
diff -u -r875 -r2645
--- DamClients/DamUI/trunk/src/Dam/Tests/CsvParserTest.cs (.../branches/CalcualtionIncluded/src/Dam/Tests/CsvParserTest.cs) (revision 875)
+++ DamClients/DamUI/trunk/src/Dam/Tests/CsvParserTest.cs (.../trunk/src/Dam/Tests/CsvParserTest.cs) (revision 2645)
@@ -1,3 +1,24 @@
+// Copyright (C) Stichting Deltares 2018. All rights reserved.
+//
+// This file is part of the application DAM - UI.
+//
+// DAM - UI 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 System.Text.RegularExpressions;
@@ -27,24 +48,24 @@
}
[Test]
- [ExpectedException(typeof(ArgumentException))]
public void ThrowsArgumentExceptionWhenHeaderStringIsNullByCallingParseHeader()
{
- CsvParser.ParseHeader(null, null);
+ var expectedMessage = "The header in the import file is not valid";
+ Assert.That(() => CsvParser.ParseHeader(null, new Regex("")), Throws.TypeOf(typeof(ArgumentException)).With.Message.EqualTo(expectedMessage));
}
[Test]
- [ExpectedException(typeof(ArgumentNullException))]
public void ThrowsArgumentExceptionSplitterIsNull()
{
- CsvParser.ParseHeader("test;test", null);
+ var expectedMessage = "The given pattern to split the data values of the CSV files is not valid" + Environment.NewLine + "Parameter name: splitter";
+ Assert.That(() => CsvParser.ParseHeader("test;test", null), Throws.TypeOf(typeof(ArgumentNullException)).With.Message.EqualTo(expectedMessage));
}
[Test]
- [ExpectedException(typeof(ArgumentException))]
public void ThrowsWhenSplitPatternIsEmpty()
{
- CsvParser.ParseHeader("test", new Regex(""));
+ var expectedMessage = "The given pattern to split the data values of the CSV files is not valid";
+ Assert.That(() => CsvParser.ParseHeader("test", new Regex("")), Throws.TypeOf(typeof(ArgumentException)).With.Message.EqualTo(expectedMessage));
}
//[Test]
Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/ThrowHelper.cs
===================================================================
diff -u -r2630 -r2645
--- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/ThrowHelper.cs (.../ThrowHelper.cs) (revision 2630)
+++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/ThrowHelper.cs (.../ThrowHelper.cs) (revision 2645)
@@ -37,7 +37,7 @@
{
CsvFileNotFound,
CsvFileNotValid,
- CsvHeaderEmptyOrNull,
+ CsvHeaderNullOrEmpty,
CsvHeaderNotValid,
CsvObjectMaterializerNotValid,
CsvSplitterPatternNotValid,
@@ -166,16 +166,16 @@
return StringResources.GetString(resourceNames.ToString());
}
- internal static void ThrowIfArgumentNull(object value, StringResourceNames resourceNamesName)
+ internal static void ThrowIfArgumentNull(object value, string parameter, StringResourceNames resourceNamesName)
{
if (value == null)
- throw new ArgumentNullException(StringResources.GetString(GetResourceString(resourceNamesName)));
+ throw new ArgumentNullException(parameter, GetResourceString(resourceNamesName));
}
- internal static void ThrowIfArgumentNull(object value, string message)
+ internal static void ThrowIfArgumentNull(object value, string parameter, string message)
{
if (value == null)
- throw new ArgumentNullException(nameof(value), message);
+ throw new ArgumentNullException(parameter, message);
}
internal static void ThrowIfStringArgumentNullOrEmpty(string value, StringResourceNames resourceNamesName)
Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/CsvParser.cs
===================================================================
diff -u -r2089 -r2645
--- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/CsvParser.cs (.../CsvParser.cs) (revision 2089)
+++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/CsvParser.cs (.../CsvParser.cs) (revision 2645)
@@ -38,8 +38,8 @@
/// An array of strings containing the header names
public static string[] ParseHeader(string header, Regex splitter)
{
- ThrowHelper.ThrowIfStringArgumentNullOrEmpty(header, StringResourceNames.CsvHeaderEmptyOrNull);
- ThrowHelper.ThrowIfArgumentNull(splitter, StringResourceNames.CsvSplitterPatternNotValid);
+ ThrowHelper.ThrowIfStringArgumentNullOrEmpty(header, StringResourceNames.CsvHeaderNullOrEmpty);
+ ThrowHelper.ThrowIfArgumentNull(splitter, "splitter", StringResourceNames.CsvSplitterPatternNotValid);
ThrowHelper.ThrowIfStringArgumentNullOrEmpty(splitter.ToString(), StringResourceNames.CsvSplitterPatternNotValid);
return splitter.Split(header);
@@ -146,7 +146,7 @@
ThrowHelper.ThrowIfStringArgumentNullOrEmpty(fileName, StringResourceNames.CsvFileNotValid);
ThrowHelper.ThrowIfFileNotExist(fileName, StringResourceNames.CsvFileNotFound);
ThrowHelper.ThrowIfStringArgumentNullOrEmpty(splitPattern, StringResourceNames.CsvSplitterPatternNotValid);
- ThrowHelper.ThrowIfArgumentNull(materializer, StringResourceNames.CsvObjectMaterializerNotValid);
+ ThrowHelper.ThrowIfArgumentNull(materializer, nameof(materializer), StringResourceNames.CsvObjectMaterializerNotValid);
ThrowHelper.ThrowWhenConditionIsTrue(
materializer,
StringResourceNames.CsvObjectMaterializerNotValid,
Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/DamEngineIo/FillXmlInputFromDamUi.cs
===================================================================
diff -u -r2630 -r2645
--- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/DamEngineIo/FillXmlInputFromDamUi.cs (.../FillXmlInputFromDamUi.cs) (revision 2630)
+++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/DamEngineIo/FillXmlInputFromDamUi.cs (.../FillXmlInputFromDamUi.cs) (revision 2645)
@@ -389,33 +389,33 @@
private static void ValidateDamProjectData(DamProjectData damProjectData)
{
- ThrowHelper.ThrowIfArgumentNull(damProjectData.WaterBoard, StringResourceNames.NoDikeDefined);
+ ThrowHelper.ThrowIfArgumentNull(damProjectData.WaterBoard, nameof(damProjectData.WaterBoard), StringResourceNames.NoDikeDefined);
if (damProjectData.WaterBoard.Dikes == null || damProjectData.WaterBoard.Dikes.Count != 1)
{
throw new ArgumentException(Resources.DikeShouldContainExactly1Dike);
}
var dike = damProjectData.WaterBoard.Dikes[0];
- ThrowHelper.ThrowIfArgumentNull(dike.Locations, StringResourceNames.NoLocationsDefined);
+ ThrowHelper.ThrowIfArgumentNull(dike.Locations, nameof(dike.Locations), StringResourceNames.NoLocationsDefined);
// Following situation should never occur in the UI. Tested because of the check on RiverLevelLow in the code below
- ThrowHelper.ThrowIfArgumentNull(damProjectData.DamProjectCalculationSpecification.CurrentSpecification, StringResourceNames.NoCalculationTypeSpecified);
+ var currentSpecification = damProjectData.DamProjectCalculationSpecification.CurrentSpecification;
+ ThrowHelper.ThrowIfArgumentNull(currentSpecification, nameof(currentSpecification), StringResourceNames.NoCalculationTypeSpecified);
foreach (Location location in dike.Locations)
{
- ThrowHelper.ThrowIfArgumentNull(location.Scenarios, StringResourceNames.NoScenariosDefinedInLocation);
+ ThrowHelper.ThrowIfArgumentNull(location.Scenarios, nameof(location.Scenarios), StringResourceNames.NoScenariosDefinedInLocation);
foreach (var scenario in location.Scenarios)
{
string errorMessage = string.Format(Resources.NoRiverLevel, location.Name, scenario.LocationScenarioID);
- ThrowHelper.ThrowIfArgumentNull(scenario.RiverLevel, errorMessage);
+ ThrowHelper.ThrowIfArgumentNull(scenario.RiverLevel, nameof(scenario.RiverLevel), errorMessage);
// In code above is tested that CurrentSpecification exists
- if (damProjectData.DamProjectCalculationSpecification.CurrentSpecification.FailureMechanismSystemType ==
- FailureMechanismSystemType.StabilityOutside)
+ if (currentSpecification.FailureMechanismSystemType == FailureMechanismSystemType.StabilityOutside)
{
errorMessage = string.Format(Resources.NoRiverLevelLow, location.Name, scenario.LocationScenarioID);
- ThrowHelper.ThrowIfArgumentNull(scenario.RiverLevelLow, errorMessage);
+ ThrowHelper.ThrowIfArgumentNull(scenario.RiverLevelLow, nameof(scenario.RiverLevelLow), errorMessage);
}
}
}
- ThrowHelper.ThrowIfArgumentNull(dike.SurfaceLines2, StringResourceNames.NoSurfaceLines);
+ ThrowHelper.ThrowIfArgumentNull(dike.SurfaceLines2, nameof(dike.SurfaceLines2), StringResourceNames.NoSurfaceLines);
foreach (var surfaceLine in dike.SurfaceLines2)
{
if ((surfaceLine.CharacteristicPoints == null) || (surfaceLine.CharacteristicPoints.Count < 1))
@@ -427,9 +427,9 @@
throw new ArgumentException(string.Format(Resources.SurfaceLineHasNoPoints, surfaceLine.Name));
}
}
- ThrowHelper.ThrowIfArgumentNull(dike.SoilList, StringResourceNames.NoSoilsDefinedInProject);
- ThrowHelper.ThrowIfArgumentNull(dike.SoilList.Soils, StringResourceNames.NoSoilsDefinedInProject);
- ThrowHelper.ThrowIfArgumentNull(dike.SoilProfiles, StringResourceNames.NoSoilprofiles1DDefinedInProject);
+ ThrowHelper.ThrowIfArgumentNull(dike.SoilList, nameof(dike.SoilList), StringResourceNames.NoSoilsDefinedInProject);
+ ThrowHelper.ThrowIfArgumentNull(dike.SoilList.Soils, nameof(dike.SoilList.Soils), StringResourceNames.NoSoilsDefinedInProject);
+ ThrowHelper.ThrowIfArgumentNull(dike.SoilProfiles, nameof(dike.SoilProfiles), StringResourceNames.NoSoilprofiles1DDefinedInProject);
// Check for invalid Id names
foreach (var location in dike.Locations)
{