Index: Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.IO/Model/Helpers/IdValidator.cs =================================================================== diff -u -r259f662afb80263cee647a25e6cadeeb654dc41d -r36b9c04c7edcc5527fde3c6f2134d14969ee8e4f --- Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.IO/Model/Helpers/IdValidator.cs (.../IdValidator.cs) (revision 259f662afb80263cee647a25e6cadeeb654dc41d) +++ Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.IO/Model/Helpers/IdValidator.cs (.../IdValidator.cs) (revision 36b9c04c7edcc5527fde3c6f2134d14969ee8e4f) @@ -19,28 +19,26 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System; using System.Text.RegularExpressions; namespace Ringtoets.AssemblyTool.IO.Model.Helpers { /// - /// Helper to validate if an id is suitable to use as an identifier. + /// Validator to validate the id of a serializable object. /// public static class IdValidator { /// - /// Validates if is a valid id to be used + /// Validates whether is a valid id to be used /// as an identifier in an xml context. /// /// The identifier to validate. - /// true if is valid, false if otherwise. - /// Thrown when is null. + /// true when is valid, false otherwise. public static bool Validate(string id) { - if (id == null) + if (string.IsNullOrWhiteSpace(id)) { - throw new ArgumentNullException(nameof(id)); + return false; } var regex = new Regex(@"^[A-Za-z\\_][A-Za-z\\_\d\-\.]+$"); Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/Helpers/IdValidatorTest.cs =================================================================== diff -u -r9506617567a9aa2e19952f96e1a7f04842d61f62 -r36b9c04c7edcc5527fde3c6f2134d14969ee8e4f --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/Helpers/IdValidatorTest.cs (.../IdValidatorTest.cs) (revision 9506617567a9aa2e19952f96e1a7f04842d61f62) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/Helpers/IdValidatorTest.cs (.../IdValidatorTest.cs) (revision 36b9c04c7edcc5527fde3c6f2134d14969ee8e4f) @@ -19,7 +19,6 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System; using NUnit.Framework; using Ringtoets.AssemblyTool.IO.Model.Helpers; @@ -29,17 +28,6 @@ public class IdValidatorTest { [Test] - public void Validate_IdNull_ThrowsArgumentNullException() - { - // Call - TestDelegate call = () => IdValidator.Validate(null); - - // Assert - var exception = Assert.Throws(call); - Assert.AreEqual("id", exception.ParamName); - } - - [Test] [TestCase("AValidId1-2.3")] [TestCase("_AValidId1-2.3")] [TestCase("aValidId1-2.3")] @@ -67,6 +55,7 @@ [TestCase("invalidId\r")] [TestCase("")] [TestCase(" ")] + [TestCase(null)] public void Validate_WithInvalidIds_ReturnsFalse(string invalidId) { // Call Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableAssemblyTest.cs =================================================================== diff -u -r2f2055ad087e60f1c66914d69df623279b14bd95 -r36b9c04c7edcc5527fde3c6f2134d14969ee8e4f --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableAssemblyTest.cs (.../SerializableAssemblyTest.cs) (revision 2f2055ad087e60f1c66914d69df623279b14bd95) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableAssemblyTest.cs (.../SerializableAssemblyTest.cs) (revision 36b9c04c7edcc5527fde3c6f2134d14969ee8e4f) @@ -76,32 +76,8 @@ } [Test] - public void Constructor_IdNull_ThrowsArgumentNullException() - { - // Setup - var random = new Random(39); - - // Call - TestDelegate call = () => new SerializableAssembly(null, - new Point2D(random.NextDouble(), random.NextDouble()), - new Point2D(random.NextDouble(), random.NextDouble()), - new SerializableAssessmentSection(), - new SerializableAssessmentProcess(), - new SerializableTotalAssemblyResult(), - Enumerable.Empty(), - Enumerable.Empty(), - Enumerable.Empty(), - Enumerable.Empty(), - Enumerable.Empty()); - - // Assert - var exception = Assert.Throws(call); - Assert.AreEqual("id", exception.ParamName); - } - - [Test] [TestCaseSource(typeof(InvalidIdTestHelper), nameof(InvalidIdTestHelper.InvalidIdCases))] - public void Constructor_InvalidId_ThrowsArgumentNullException(string invalidId) + public void Constructor_InvalidId_ThrowsArgumentException(string invalidId) { // Setup var random = new Random(39); Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableAssessmentProcessTest.cs =================================================================== diff -u -r2f2055ad087e60f1c66914d69df623279b14bd95 -r36b9c04c7edcc5527fde3c6f2134d14969ee8e4f --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableAssessmentProcessTest.cs (.../SerializableAssessmentProcessTest.cs) (revision 2f2055ad087e60f1c66914d69df623279b14bd95) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableAssessmentProcessTest.cs (.../SerializableAssessmentProcessTest.cs) (revision 36b9c04c7edcc5527fde3c6f2134d14969ee8e4f) @@ -58,20 +58,8 @@ } [Test] - public void Constructor_IdNull_ThrowsArgumentNullException() - { - // Call - TestDelegate call = () => new SerializableAssessmentProcess(null, - new SerializableAssessmentSection()); - - // Assert - var exception = Assert.Throws(call); - Assert.AreEqual("id", exception.ParamName); - } - - [Test] [TestCaseSource(typeof(InvalidIdTestHelper), nameof(InvalidIdTestHelper.InvalidIdCases))] - public void Constructor_InvalidId_ThrowsArgumentNullException(string invalidId) + public void Constructor_InvalidId_ThrowsArgumentException(string invalidId) { // Call TestDelegate call = () => new SerializableAssessmentProcess(invalidId, Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableAssessmentSectionTest.cs =================================================================== diff -u -r2f2055ad087e60f1c66914d69df623279b14bd95 -r36b9c04c7edcc5527fde3c6f2134d14969ee8e4f --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableAssessmentSectionTest.cs (.../SerializableAssessmentSectionTest.cs) (revision 2f2055ad087e60f1c66914d69df623279b14bd95) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableAssessmentSectionTest.cs (.../SerializableAssessmentSectionTest.cs) (revision 36b9c04c7edcc5527fde3c6f2134d14969ee8e4f) @@ -62,21 +62,8 @@ } [Test] - public void Constructor_IdNull_ThrowsArgumentNullException() - { - // Call - TestDelegate call = () => new SerializableAssessmentSection(null, - "name", - Enumerable.Empty()); - - // Assert - var exception = Assert.Throws(call); - Assert.AreEqual("id", exception.ParamName); - } - - [Test] [TestCaseSource(typeof(InvalidIdTestHelper), nameof(InvalidIdTestHelper.InvalidIdCases))] - public void Constructor_InvalidId_ThrowsArgumentNullException(string invalidId) + public void Constructor_InvalidId_ThrowsArgumentException(string invalidId) { // Setup var random = new Random(39); Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableCombinedFailureMechanismSectionAssemblyTest.cs =================================================================== diff -u -r2f2055ad087e60f1c66914d69df623279b14bd95 -r36b9c04c7edcc5527fde3c6f2134d14969ee8e4f --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableCombinedFailureMechanismSectionAssemblyTest.cs (.../SerializableCombinedFailureMechanismSectionAssemblyTest.cs) (revision 2f2055ad087e60f1c66914d69df623279b14bd95) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableCombinedFailureMechanismSectionAssemblyTest.cs (.../SerializableCombinedFailureMechanismSectionAssemblyTest.cs) (revision 36b9c04c7edcc5527fde3c6f2134d14969ee8e4f) @@ -63,23 +63,8 @@ } [Test] - public void Constructor_IdNull_ThrowsArgumentNullException() - { - // Call - TestDelegate call = () => new SerializableCombinedFailureMechanismSectionAssembly(null, - new SerializableTotalAssemblyResult(), - new SerializableFailureMechanismSection(), - new SerializableCombinedFailureMechanismSectionAssemblyResult[0], - new SerializableFailureMechanismSectionAssemblyResult()); - - // Assert - var exception = Assert.Throws(call); - Assert.AreEqual("id", exception.ParamName); - } - - [Test] [TestCaseSource(typeof(InvalidIdTestHelper), nameof(InvalidIdTestHelper.InvalidIdCases))] - public void Constructor_InvalidId_ThrowsArgumentNullException(string invalidId) + public void Constructor_InvalidId_ThrowsArgumentException(string invalidId) { // Call TestDelegate call = () => new SerializableCombinedFailureMechanismSectionAssembly(invalidId, Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableFailureMechanismSectionAssemblyTest.cs =================================================================== diff -u -r2f2055ad087e60f1c66914d69df623279b14bd95 -r36b9c04c7edcc5527fde3c6f2134d14969ee8e4f --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableFailureMechanismSectionAssemblyTest.cs (.../SerializableFailureMechanismSectionAssemblyTest.cs) (revision 2f2055ad087e60f1c66914d69df623279b14bd95) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableFailureMechanismSectionAssemblyTest.cs (.../SerializableFailureMechanismSectionAssemblyTest.cs) (revision 36b9c04c7edcc5527fde3c6f2134d14969ee8e4f) @@ -63,23 +63,8 @@ } [Test] - public void Constructor_IdNull_ThrowsArgumentNullException() - { - // Call - TestDelegate call = () => new SerializableFailureMechanismSectionAssembly(null, - new SerializableFailureMechanism(), - new SerializableFailureMechanismSection(), - new SerializableFailureMechanismSectionAssemblyResult[0], - new SerializableFailureMechanismSectionAssemblyResult()); - - // Assert - var exception = Assert.Throws(call); - Assert.AreEqual("id", exception.ParamName); - } - - [Test] [TestCaseSource(typeof(InvalidIdTestHelper), nameof(InvalidIdTestHelper.InvalidIdCases))] - public void Constructor_InvalidId_ThrowsArgumentNullException(string invalidId) + public void Constructor_InvalidId_ThrowsArgumentException(string invalidId) { // Setup var random = new Random(39); Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableFailureMechanismSectionCollectionTest.cs =================================================================== diff -u -r2f2055ad087e60f1c66914d69df623279b14bd95 -r36b9c04c7edcc5527fde3c6f2134d14969ee8e4f --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableFailureMechanismSectionCollectionTest.cs (.../SerializableFailureMechanismSectionCollectionTest.cs) (revision 2f2055ad087e60f1c66914d69df623279b14bd95) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableFailureMechanismSectionCollectionTest.cs (.../SerializableFailureMechanismSectionCollectionTest.cs) (revision 36b9c04c7edcc5527fde3c6f2134d14969ee8e4f) @@ -55,20 +55,8 @@ } [Test] - public void ConstructorWithFailureMechanism_IdNull_ThrowsArgumentNullException() - { - // Call - TestDelegate call = () => new SerializableFailureMechanismSectionCollection(null, - new SerializableFailureMechanism()); - - // Assert - var exception = Assert.Throws(call); - Assert.AreEqual("id", exception.ParamName); - } - - [Test] [TestCaseSource(typeof(InvalidIdTestHelper), nameof(InvalidIdTestHelper.InvalidIdCases))] - public void ConstructorWithFailureMechanism_InvalidId_ThrowsArgumentNullException(string invalidId) + public void ConstructorWithFailureMechanism_InvalidId_ThrowsArgumentException(string invalidId) { // Call TestDelegate call = () => new SerializableFailureMechanismSectionCollection(invalidId, @@ -115,20 +103,8 @@ } [Test] - public void ConstructorWithTotalAssemblyResult_IdNull_ThrowsArgumentNullException() - { - // Call - TestDelegate call = () => new SerializableFailureMechanismSectionCollection(null, - new SerializableTotalAssemblyResult()); - - // Assert - var exception = Assert.Throws(call); - Assert.AreEqual("id", exception.ParamName); - } - - [Test] [TestCaseSource(typeof(InvalidIdTestHelper), nameof(InvalidIdTestHelper.InvalidIdCases))] - public void ConstructorWithTotalAssemblyResult_InvalidId_ThrowsArgumentNullException(string invalidId) + public void ConstructorWithTotalAssemblyResult_InvalidId_ThrowsArgumentException(string invalidId) { // Call TestDelegate call = () => new SerializableFailureMechanismSectionCollection(invalidId, Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableFailureMechanismSectionTest.cs =================================================================== diff -u -r2f2055ad087e60f1c66914d69df623279b14bd95 -r36b9c04c7edcc5527fde3c6f2134d14969ee8e4f --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableFailureMechanismSectionTest.cs (.../SerializableFailureMechanismSectionTest.cs) (revision 2f2055ad087e60f1c66914d69df623279b14bd95) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableFailureMechanismSectionTest.cs (.../SerializableFailureMechanismSectionTest.cs) (revision 36b9c04c7edcc5527fde3c6f2134d14969ee8e4f) @@ -71,27 +71,8 @@ } [Test] - public void Constructor_IdNull_ThrowsArgumentNullException() - { - // Setup - var random = new Random(39); - - // Call - TestDelegate call = () => new SerializableFailureMechanismSection(null, - new SerializableFailureMechanismSectionCollection(), - random.NextDouble(), - random.NextDouble(), - Enumerable.Empty(), - random.NextEnumValue()); - - // Assert - var exception = Assert.Throws(call); - Assert.AreEqual("id", exception.ParamName); - } - - [Test] [TestCaseSource(typeof(InvalidIdTestHelper), nameof(InvalidIdTestHelper.InvalidIdCases))] - public void Constructor_InvalidId_ThrowsArgumentNullException(string invalidId) + public void Constructor_InvalidId_ThrowsArgumentException(string invalidId) { // Setup var random = new Random(39); Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableFailureMechanismTest.cs =================================================================== diff -u -r2f2055ad087e60f1c66914d69df623279b14bd95 -r36b9c04c7edcc5527fde3c6f2134d14969ee8e4f --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableFailureMechanismTest.cs (.../SerializableFailureMechanismTest.cs) (revision 2f2055ad087e60f1c66914d69df623279b14bd95) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableFailureMechanismTest.cs (.../SerializableFailureMechanismTest.cs) (revision 36b9c04c7edcc5527fde3c6f2134d14969ee8e4f) @@ -65,26 +65,8 @@ } [Test] - public void Constructor_IdNull_ThrowsArgumentNullException() - { - // Setup - var random = new Random(39); - - // Call - TestDelegate call = () => new SerializableFailureMechanism(null, - new SerializableTotalAssemblyResult(), - random.NextEnumValue(), - random.NextEnumValue(), - new SerializableFailureMechanismAssemblyResult()); - - // Assert - var exception = Assert.Throws(call); - Assert.AreEqual("id", exception.ParamName); - } - - [Test] [TestCaseSource(typeof(InvalidIdTestHelper), nameof(InvalidIdTestHelper.InvalidIdCases))] - public void Constructor_InvalidId_ThrowsArgumentNullException(string invalidId) + public void Constructor_InvalidId_ThrowsArgumentException(string invalidId) { // Setup var random = new Random(39); Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableTotalAssemblyResultTest.cs =================================================================== diff -u -r2f2055ad087e60f1c66914d69df623279b14bd95 -r36b9c04c7edcc5527fde3c6f2134d14969ee8e4f --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableTotalAssemblyResultTest.cs (.../SerializableTotalAssemblyResultTest.cs) (revision 2f2055ad087e60f1c66914d69df623279b14bd95) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableTotalAssemblyResultTest.cs (.../SerializableTotalAssemblyResultTest.cs) (revision 36b9c04c7edcc5527fde3c6f2134d14969ee8e4f) @@ -61,23 +61,8 @@ } [Test] - public void Constructor_IdNull_ThrowsArgumentNullException() - { - // Call - TestDelegate call = () => new SerializableTotalAssemblyResult(null, - new SerializableAssessmentProcess(), - new SerializableFailureMechanismAssemblyResult(), - new SerializableFailureMechanismAssemblyResult(), - new SerializableAssessmentSectionAssemblyResult()); - - // Assert - var exception = Assert.Throws(call); - Assert.AreEqual("id", exception.ParamName); - } - - [Test] [TestCaseSource(typeof(InvalidIdTestHelper), nameof(InvalidIdTestHelper.InvalidIdCases))] - public void Constructor_InvalidId_ThrowsArgumentNullException(string invalidId) + public void Constructor_InvalidId_ThrowsArgumentException(string invalidId) { // Call TestDelegate call = () => new SerializableTotalAssemblyResult(invalidId, Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.TestUtil.Test/InvalidIdTestHelperTest.cs =================================================================== diff -u -r46c6e661ed805f0fe44e3a70e865415cf57f0cf6 -r36b9c04c7edcc5527fde3c6f2134d14969ee8e4f --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.TestUtil.Test/InvalidIdTestHelperTest.cs (.../InvalidIdTestHelperTest.cs) (revision 46c6e661ed805f0fe44e3a70e865415cf57f0cf6) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.TestUtil.Test/InvalidIdTestHelperTest.cs (.../InvalidIdTestHelperTest.cs) (revision 36b9c04c7edcc5527fde3c6f2134d14969ee8e4f) @@ -35,20 +35,16 @@ IEnumerable testCases = InvalidIdTestHelper.InvalidIdCases.ToArray(); // Assert - var expectedCases = new[] - { - new TestCaseData(""), - new TestCaseData(" "), - new TestCaseData("1nvalidId"), - new TestCaseData("invalidId#") - }; - int nrOfExpectedCases = expectedCases.Length; - Assert.AreEqual(nrOfExpectedCases, testCases.Count()); - for (var i = 0; i < nrOfExpectedCases; i++) + CollectionAssert.AreEqual(new[] { - Assert.AreEqual(expectedCases[i].Arguments[0], testCases.ElementAt(i).Arguments[0]); - } + null, + "", + " ", + "1nvalidId", + "invalidId#", + "invalid\rId#" + }, testCases.Select(tc => tc.Arguments[0])); } } } \ No newline at end of file Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.TestUtil/InvalidIdTestHelper.cs =================================================================== diff -u -r46c6e661ed805f0fe44e3a70e865415cf57f0cf6 -r36b9c04c7edcc5527fde3c6f2134d14969ee8e4f --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.TestUtil/InvalidIdTestHelper.cs (.../InvalidIdTestHelper.cs) (revision 46c6e661ed805f0fe44e3a70e865415cf57f0cf6) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.TestUtil/InvalidIdTestHelper.cs (.../InvalidIdTestHelper.cs) (revision 36b9c04c7edcc5527fde3c6f2134d14969ee8e4f) @@ -36,10 +36,12 @@ { get { + yield return new TestCaseData(null); yield return new TestCaseData(""); yield return new TestCaseData(" "); yield return new TestCaseData("1nvalidId"); yield return new TestCaseData("invalidId#"); + yield return new TestCaseData("invalid\rId"); } } }