Index: Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.IO/Model/SerializableAssessmentSection.cs =================================================================== diff -u -ra30b67748bed77736f62b6b3c30c82649bb9cf4e -rf567b2b8e99d56ee71cdb33116f85c0c918cc59e --- Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.IO/Model/SerializableAssessmentSection.cs (.../SerializableAssessmentSection.cs) (revision a30b67748bed77736f62b6b3c30c82649bb9cf4e) +++ Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.IO/Model/SerializableAssessmentSection.cs (.../SerializableAssessmentSection.cs) (revision f567b2b8e99d56ee71cdb33116f85c0c918cc59e) @@ -24,6 +24,7 @@ using System.Xml.Serialization; using Core.Common.Base.Geometry; using Ringtoets.AssemblyTool.IO.Model.DataTypes; +using Ringtoets.AssemblyTool.IO.Model.Helpers; using Ringtoets.AssemblyTool.IO.Properties; namespace Ringtoets.AssemblyTool.IO.Model @@ -48,20 +49,19 @@ /// The unique ID of the assessment section. /// The name of the assessment section. /// The geometry of the reference line. + /// Thrown when any parameter is null. /// Thrown when: - /// - /// contains no elements; - /// is null or empty. - /// - /// - /// Thrown when or is null. + /// + /// contains no elements. + /// is invalid. + /// public SerializableAssessmentSection(string id, string name, IEnumerable geometry) : this() { - if (string.IsNullOrEmpty(id)) + if (!IdValidator.Validate(id)) { - throw new ArgumentException($@"'{nameof(id)}' must have a value."); + throw new ArgumentException($@"'{nameof(id)}' must have a value and consist only of alphanumerical characters, '-', '_' or '.'."); } if (name == null) Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableAssessmentSectionTest.cs =================================================================== diff -u -ra30b67748bed77736f62b6b3c30c82649bb9cf4e -rf567b2b8e99d56ee71cdb33116f85c0c918cc59e --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableAssessmentSectionTest.cs (.../SerializableAssessmentSectionTest.cs) (revision a30b67748bed77736f62b6b3c30c82649bb9cf4e) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableAssessmentSectionTest.cs (.../SerializableAssessmentSectionTest.cs) (revision f567b2b8e99d56ee71cdb33116f85c0c918cc59e) @@ -62,17 +62,34 @@ } [Test] - [TestCase(null)] + 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] + [TestCase(" ")] [TestCase("")] - public void Constructor_IdInvalid_ThrowsArgumentException(string id) + [TestCase(" InvalidId")] + public void Constructor_InvalidId_ThrowsArgumentNullException(string invalidId) { + // Setup + var random = new Random(39); + // Call - TestDelegate call = () => new SerializableAssessmentSection(id, - string.Empty, + TestDelegate call = () => new SerializableAssessmentSection(invalidId, + "name", Enumerable.Empty()); // Assert - const string expectedMessage = "'id' must have a value."; + const string expectedMessage = "'id' must have a value and consist only of alphanumerical characters, '-', '_' or '.'."; TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); } @@ -107,7 +124,7 @@ { // Setup const string name = "section name"; - const string id = "section id"; + const string id = "sectionId"; var random = new Random(39); var geometry = new[]