Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"Rules": [
{
"RuleName": "30.Postcode.NBO.NonFatal",
"Expression": "string.IsNullOrEmpty(participant.Postcode) OR ValidationHelper.ValidatePostcode(participant.Postcode)",
"Expression": "string.IsNullOrEmpty(participant.Postcode) OR ValidationHelper.ValidatePostcode(participant.Postcode) OR participant.Postcode == \"ZZZSECUR\"",
"Actions": {
"OnFailure": {
"Name": "OutputExpression",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,12 @@ public static bool ValidateNHSNumber(string nhsNumber)
public static bool ValidatePostcode(string postcode)
{
string validPostcodePattern = "^([A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})$";
string dummyPostcodePattern1 = "^ZZ99 ?[0-9][A-Z]{2}$";
string dummyPostcodePattern2 = "^ZZZSECUR$";
string dummyPostcodePattern = "^ZZ99 ?[0-9][A-Z]{2}$";

Match validPostcodeMatch = Regex.Match(postcode, validPostcodePattern, RegexOptions.IgnoreCase, TimeSpan.FromSeconds(2));
Match dummyPostcodeMatch1 = Regex.Match(postcode, dummyPostcodePattern1, RegexOptions.IgnoreCase, TimeSpan.FromSeconds(2));
Match dummyPostcodeMatch2 = Regex.Match(postcode, dummyPostcodePattern2, RegexOptions.IgnoreCase, TimeSpan.FromSeconds(2));
Match dummyPostcodeMatch = Regex.Match(postcode, dummyPostcodePattern, RegexOptions.IgnoreCase, TimeSpan.FromSeconds(2));

if (validPostcodeMatch.Success || dummyPostcodeMatch1.Success || dummyPostcodeMatch2.Success)
if (validPostcodeMatch.Success || dummyPostcodeMatch.Success)
Comment thread
sudipnhs marked this conversation as resolved.
return true;

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public async Task Run_DelRecord_DoNotRunCommonRules()
[DataRow("ZZ99 9FZ")]
[DataRow("ZZ999FZ")]
[DataRow("ZZ99 3WZ")]
[DataRow("ZZZSECUR")]
public async Task Run_ValidPostcode_ReturnNoContent(string postcode)
{
// Arrange
Expand Down
25 changes: 25 additions & 0 deletions tests/UnitTests/StaticTests/ValidationHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,29 @@ public void ValidatePastDate_InvalidPastDateAlwaysFuture_ReturnsFalse()

Assert.IsFalse(result);
}

[TestMethod]
[DataRow("B33 8TH")] // Valid postcode format
[DataRow("SW1A 1AA")] // Valid postcode format
[DataRow("SM1 1AA")] // Valid postcode format
[DataRow("ZZ99 3CZ")] // dummy postcode format
Comment thread
sudipnhs marked this conversation as resolved.
public void ValidatePostcode_ValidPostcode_ReturnsTrue(string postCode)
{
var result = ValidationHelper.ValidatePostcode(postCode);

Assert.IsTrue(result);
}

[TestMethod]
[DataRow("A1")]
[DataRow("ABCDE 123")]
[DataRow("123 ABC")]
[DataRow("W1A")]
[DataRow("SW1A1AAA")]
public void ValidatePostcode_InvalidPostcode_ReturnsFalse(string postCode)
{
var result = ValidationHelper.ValidatePostcode(postCode);

Assert.IsFalse(result);
}
}
Loading