Skip to content

Commit 24d4146

Browse files
TD-4624 assign the error string to a variable and reference it
1 parent 800094e commit 24d4146

File tree

3 files changed

+27
-38
lines changed

3 files changed

+27
-38
lines changed

DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/Delegates/EditDelegateControllerTests.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,7 @@ public void Index_post_returns_view_with_model_error_with_invalid_prn()
175175
result.As<ViewResult>().Model.Should().BeOfType<EditDelegateViewModel>();
176176
AssertModelStateErrorIsExpected(
177177
result,
178-
"Invalid professional registration number format. " +
179-
"Valid formats include: 7 digits (e.g., 1234567), 1–2 letters followed by 6 digits (e.g., AB123456), " +
180-
"4–8 digits, an optional 'P' plus 5–6 digits, 'C' or 'P' plus 6 digits, " +
181-
"an optional letter plus 5–6 digits, 'L' plus 4–6 digits, " +
182-
"or 2 digits followed by a hyphen and 4–5 alphanumeric characters (e.g., 12-AB123)."
183-
178+
ErrorMessagesTestHelper.InvalidFormatError
184179
);
185180
A.CallTo(() => userService.GetDelegateById(A<int>._)).MustNotHaveHappened();
186181
}

DigitalLearningSolutions.Web.Tests/Helpers/ProfessionalRegistrationNumberHelperTests.cs

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
namespace DigitalLearningSolutions.Web.Tests.Helpers
22
{
3-
using System.Linq;
43
using DigitalLearningSolutions.Web.Helpers;
4+
using DigitalLearningSolutions.Web.Tests.TestHelpers;
55
using FluentAssertions;
66
using FluentAssertions.Execution;
77
using Microsoft.AspNetCore.Mvc.ModelBinding;
88
using NUnit.Framework;
9+
using System.Linq;
910

1011
public class ProfessionalRegistrationNumberHelperTests
1112
{
@@ -104,37 +105,13 @@ public void ValidateProfessionalRegistrationNumber_sets_error_when_hasPrn_is_not
104105
}
105106
}
106107

107-
[TestCase(null, "Enter a professional registration number")]
108-
[TestCase("", "Enter a professional registration number")]
109-
[TestCase("1234", "Professional registration number must be between 5 and 20 characters")]
110-
[TestCase("1234", "Professional registration number must be between 5 and 20 characters")]
111-
[TestCase(
112-
"01234_",
113-
"Invalid professional registration number format. " +
114-
"Valid formats include: 7 digits (e.g., 1234567), 1–2 letters followed by 6 digits (e.g., AB123456), " +
115-
"4–8 digits, an optional 'P' plus 5–6 digits, 'C' or 'P' plus 6 digits, " +
116-
"an optional letter plus 5–6 digits, 'L' plus 4–6 digits, " +
117-
"or 2 digits followed by a hyphen and 4–5 alphanumeric characters (e.g., 12-AB123)."
118-
119-
)]
120-
[TestCase(
121-
"01234 ",
122-
"Invalid professional registration number format. " +
123-
"Valid formats include: 7 digits (e.g., 1234567), 1–2 letters followed by 6 digits (e.g., AB123456), " +
124-
"4–8 digits, an optional 'P' plus 5–6 digits, 'C' or 'P' plus 6 digits, " +
125-
"an optional letter plus 5–6 digits, 'L' plus 4–6 digits, " +
126-
"or 2 digits followed by a hyphen and 4–5 alphanumeric characters (e.g., 12-AB123)."
127-
128-
)]
129-
[TestCase(
130-
"01234$",
131-
"Invalid professional registration number format. " +
132-
"Valid formats include: 7 digits (e.g., 1234567), 1–2 letters followed by 6 digits (e.g., AB123456), " +
133-
"4–8 digits, an optional 'P' plus 5–6 digits, 'C' or 'P' plus 6 digits, " +
134-
"an optional letter plus 5–6 digits, 'L' plus 4–6 digits, " +
135-
"or 2 digits followed by a hyphen and 4–5 alphanumeric characters (e.g., 12-AB123)."
136-
137-
)]
108+
[TestCase(null, ErrorMessagesTestHelper.MissingNumberError)]
109+
[TestCase("", ErrorMessagesTestHelper.MissingNumberError)]
110+
[TestCase("1234", ErrorMessagesTestHelper.LengthError)]
111+
[TestCase("1234", ErrorMessagesTestHelper.LengthError)]
112+
[TestCase("01234_", ErrorMessagesTestHelper.InvalidFormatError)]
113+
[TestCase("01234 ", ErrorMessagesTestHelper.InvalidFormatError)]
114+
[TestCase("01234$", ErrorMessagesTestHelper.InvalidFormatError)]
138115
public void ValidateProfessionalRegistrationNumber_sets_error_when_prn_is_invalid(
139116
string prn,
140117
string expectedError
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+

2+
namespace DigitalLearningSolutions.Web.Tests.TestHelpers
3+
{
4+
public static class ErrorMessagesTestHelper
5+
{
6+
public const string InvalidFormatError =
7+
"Invalid professional registration number format. " +
8+
"Valid formats include: 7 digits (e.g., 1234567), 1–2 letters followed by 6 digits (e.g., AB123456), " +
9+
"4–8 digits, an optional 'P' plus 5–6 digits, 'C' or 'P' plus 6 digits, " +
10+
"an optional letter plus 5–6 digits, 'L' plus 4–6 digits, " +
11+
"or 2 digits followed by a hyphen and 4–5 alphanumeric characters (e.g., 12-AB123).";
12+
13+
public const string MissingNumberError = "Enter a professional registration number";
14+
public const string LengthError = "Professional registration number must be between 5 and 20 characters";
15+
16+
}
17+
}

0 commit comments

Comments
 (0)