Skip to content

Commit 2deb975

Browse files
committed
test: Added Tests to ValidationHelper.cs
1 parent 1539848 commit 2deb975

3 files changed

Lines changed: 110 additions & 0 deletions

File tree

application/CohortManager/src/Functions/Functions.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpParserTests", "..\..\..
218218
EndProject
219219
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileNameParserTests", "..\..\..\..\tests\UnitTests\SharedTests\FileNameParserTests\FileNameParserTests.csproj", "{0A68E48A-8249-4A74-B5B7-5921017D07BD}"
220220
EndProject
221+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ValidationHelperTests", "..\..\..\..\tests\UnitTests\SharedTests\ValidationHelperTests\ValidationHelperTests.csproj", "{EDB57691-525A-4693-8562-A5E6F4D0A61F}"
222+
EndProject
221223
Global
222224
GlobalSection(SolutionConfigurationPlatforms) = preSolution
223225
Debug|Any CPU = Debug|Any CPU
@@ -604,6 +606,10 @@ Global
604606
{C86FDA63-AA51-4B5F-A69B-DEF0266E268F}.Debug|Any CPU.Build.0 = Debug|Any CPU
605607
{C86FDA63-AA51-4B5F-A69B-DEF0266E268F}.Release|Any CPU.ActiveCfg = Release|Any CPU
606608
{C86FDA63-AA51-4B5F-A69B-DEF0266E268F}.Release|Any CPU.Build.0 = Release|Any CPU
609+
{EDB57691-525A-4693-8562-A5E6F4D0A61F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
610+
{EDB57691-525A-4693-8562-A5E6F4D0A61F}.Debug|Any CPU.Build.0 = Debug|Any CPU
611+
{EDB57691-525A-4693-8562-A5E6F4D0A61F}.Release|Any CPU.ActiveCfg = Release|Any CPU
612+
{EDB57691-525A-4693-8562-A5E6F4D0A61F}.Release|Any CPU.Build.0 = Release|Any CPU
607613
EndGlobalSection
608614
GlobalSection(SolutionProperties) = preSolution
609615
HideSolutionNode = FALSE
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
namespace ValidationHelperTests;
2+
3+
using Common;
4+
5+
[TestClass]
6+
public class ValidationHelperTests
7+
{
8+
[TestMethod]
9+
[DataRow("20000101")] // yyyymmdd
10+
[DataRow("200001")] // yyyymm
11+
[DataRow("2000-01-01")] // yyyy-mm-dd
12+
[DataRow("01/01/2000 12:00:00")] // dd/mm/yyyy hh:mm:ss
13+
[DataRow("2000")] // yyyy
14+
public void ValidatePastDate_ValidInput_ReturnTrue(string date)
15+
{
16+
//No Arrange
17+
//Act
18+
var actual = ValidationHelper.ValidatePastDate(date);
19+
20+
//Assert
21+
bool expected = true;
22+
Assert.AreEqual(actual, expected);
23+
}
24+
25+
[TestMethod]
26+
[DataRow(null)] // null
27+
[DataRow("20300101")] // future date
28+
[DataRow("2000-01-32")] // date doesn't exist
29+
[DataRow("1/13/2000 12:00:00 01")] // d/mm/yyyy hh:mm:ss tt
30+
[DataRow("01/01/2000 25:00:00 01")] // dd/mm/yyyy hh:mm:ss tt
31+
[DataRow("-2000")] // negative year
32+
public void ValidatePastDate_InvalidInput_ReturnFalse(string date)
33+
{
34+
//No Arrange
35+
//Act
36+
var actual = ValidationHelper.ValidatePastDate(date);
37+
38+
//Assert
39+
bool expected = false;
40+
Assert.AreEqual(actual, expected);
41+
}
42+
43+
[TestMethod]
44+
[DataRow("8919361401")] // These are random valid NHS numbers created by https://data-gorilla.uk/en/healthcare/nhs-number/
45+
[DataRow("4539728490")] // This does not contain PII.
46+
[DataRow("1056154497")]
47+
[DataRow("1201484383")]
48+
[DataRow("8325769629")]
49+
public void ValidateNHSNumber_ValidInput_ReturnTrue(string nhsNumber)
50+
{
51+
//No Arrange
52+
//Act
53+
var actual = ValidationHelper.ValidateNHSNumber(nhsNumber);
54+
55+
//Assert
56+
bool expected = true;
57+
Assert.AreEqual(actual, expected);
58+
}
59+
60+
[TestMethod]
61+
[DataRow(null)]
62+
[DataRow("1234567890")]
63+
[DataRow("-1234567890")]
64+
[DataRow("1a2b3c4d5e")]
65+
[DataRow("123")]
66+
[DataRow("0000000000")]
67+
public void ValidateNHSNumber_InvalidInput_ReturnFalse(string nhsNumber)
68+
{
69+
//No Arrange
70+
//Act
71+
var actual = ValidationHelper.ValidateNHSNumber(nhsNumber);
72+
73+
//Assert
74+
bool expected = false;
75+
Assert.AreEqual(actual, expected);
76+
}
77+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
<IsTestProject>true</IsTestProject>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="coverlet.collector" Version="6.0.0" />
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
15+
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
16+
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<ProjectReference Include="../../../../application/CohortManager/src/Functions/Shared/Common/Common.csproj" />
21+
</ItemGroup>
22+
23+
<ItemGroup>
24+
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
25+
</ItemGroup>
26+
27+
</Project>

0 commit comments

Comments
 (0)