Index: Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.IO/Model/Helpers/IdValidator.cs
===================================================================
diff -u
--- Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.IO/Model/Helpers/IdValidator.cs (revision 0)
+++ Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.IO/Model/Helpers/IdValidator.cs (revision 259f662afb80263cee647a25e6cadeeb654dc41d)
@@ -0,0 +1,50 @@
+// Copyright (C) Stichting Deltares 2017. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets 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.Text.RegularExpressions;
+
+namespace Ringtoets.AssemblyTool.IO.Model.Helpers
+{
+ ///
+ /// Helper to validate if an id is suitable to use as an identifier.
+ ///
+ public static class IdValidator
+ {
+ ///
+ /// Validates if 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.
+ public static bool Validate(string id)
+ {
+ if (id == null)
+ {
+ throw new ArgumentNullException(nameof(id));
+ }
+
+ var regex = new Regex(@"^[A-Za-z\\_][A-Za-z\\_\d\-\.]+$");
+ return regex.IsMatch(id);
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.IO/Ringtoets.AssemblyTool.IO.csproj
===================================================================
diff -u -rd3b53b68914f5cead6eaf7b008168b29b2bd5754 -r259f662afb80263cee647a25e6cadeeb654dc41d
--- Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.IO/Ringtoets.AssemblyTool.IO.csproj (.../Ringtoets.AssemblyTool.IO.csproj) (revision d3b53b68914f5cead6eaf7b008168b29b2bd5754)
+++ Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.IO/Ringtoets.AssemblyTool.IO.csproj (.../Ringtoets.AssemblyTool.IO.csproj) (revision 259f662afb80263cee647a25e6cadeeb654dc41d)
@@ -33,6 +33,7 @@
+
Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/Helpers/IdValidatorTest.cs
===================================================================
diff -u
--- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/Helpers/IdValidatorTest.cs (revision 0)
+++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/Helpers/IdValidatorTest.cs (revision 259f662afb80263cee647a25e6cadeeb654dc41d)
@@ -0,0 +1,79 @@
+// Copyright (C) Stichting Deltares 2017. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets 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 NUnit.Framework;
+using Ringtoets.AssemblyTool.IO.Model.Helpers;
+
+namespace Ringtoets.AssemblyTool.IO.Test.Model.Helpers
+{
+ [TestFixture]
+ public class IdValidatorTest
+ {
+ [Test]
+ public void Validate_IdNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate call = () => IdValidator.Validate(null);
+
+ // Assert
+ var exception = Assert.Throws(call);
+ Assert.AreEqual("input", exception.ParamName);
+ }
+
+ [Test]
+ [TestCase("AValidId1-2.3")]
+ [TestCase("_AValidId1-2.3")]
+ [TestCase("aValidId1-2.3")]
+ public void Validate_WithValidIds_ReturnsTrue(string validId)
+ {
+ // Call
+ bool result = IdValidator.Validate(validId);
+
+ // Assert
+ Assert.IsTrue(result);
+ }
+
+ [Test]
+ [TestCase("-invalidId1-2.3")]
+ [TestCase("1nvalidId1-2.3")]
+ [TestCase(".invalidId1-2.3")]
+ [TestCase("invalidId#")]
+ [TestCase("invalid#Id")]
+ [TestCase("#invalidId")]
+ [TestCase("i nvalidId")]
+ [TestCase(" invalidId")]
+ [TestCase("invalidId ")]
+ [TestCase("i\rnvalidId")]
+ [TestCase("\rinvalidId")]
+ [TestCase("invalidId\r")]
+ [TestCase("")]
+ [TestCase(" ")]
+ public void Validate_WithInvalidIds_ReturnsFalse(string invalidId)
+ {
+ // Call
+ bool result = IdValidator.Validate(invalidId);
+
+ // Assert
+ Assert.IsFalse(result);
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Ringtoets.AssemblyTool.IO.Test.csproj
===================================================================
diff -u -r1ea93714d7063df84c6ecf043209ef821ca54a70 -r259f662afb80263cee647a25e6cadeeb654dc41d
--- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Ringtoets.AssemblyTool.IO.Test.csproj (.../Ringtoets.AssemblyTool.IO.Test.csproj) (revision 1ea93714d7063df84c6ecf043209ef821ca54a70)
+++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Ringtoets.AssemblyTool.IO.Test.csproj (.../Ringtoets.AssemblyTool.IO.Test.csproj) (revision 259f662afb80263cee647a25e6cadeeb654dc41d)
@@ -31,6 +31,7 @@
+