Skip to content
Closed
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
6 changes: 6 additions & 0 deletions application/CohortManager/src/Functions/Functions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpParserTests", "..\..\..
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileNameParserTests", "..\..\..\..\tests\UnitTests\SharedTests\FileNameParserTests\FileNameParserTests.csproj", "{0A68E48A-8249-4A74-B5B7-5921017D07BD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ValidationHelperTests", "..\..\..\..\tests\UnitTests\SharedTests\ValidationHelperTests\ValidationHelperTests.csproj", "{EDB57691-525A-4693-8562-A5E6F4D0A61F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -610,6 +612,10 @@ Global
{C86FDA63-AA51-4B5F-A69B-DEF0266E268F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C86FDA63-AA51-4B5F-A69B-DEF0266E268F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C86FDA63-AA51-4B5F-A69B-DEF0266E268F}.Release|Any CPU.Build.0 = Release|Any CPU
{EDB57691-525A-4693-8562-A5E6F4D0A61F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EDB57691-525A-4693-8562-A5E6F4D0A61F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EDB57691-525A-4693-8562-A5E6F4D0A61F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EDB57691-525A-4693-8562-A5E6F4D0A61F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
namespace NHS.CohortManager.Tests.Shared;


using Common;

[TestClass]
public class ValidationHelperTests
{
[TestMethod]
[DataRow("20000101")] // yyyymmdd
[DataRow("200001")] // yyyymm
[DataRow("2000-01-01")] // yyyy-mm-dd
[DataRow("01/01/2000 12:00:00")] // dd/mm/yyyy hh:mm:ss
[DataRow("2000")] // yyyy
public void ValidatePastDate_ValidInput_ReturnTrue(string date)
{
//No Arrange
//Act
var actual = ValidationHelper.ValidatePastDate(date);

//Assert
bool expected = true;
Assert.AreEqual(actual, expected);
}

[TestMethod]
[DataRow(null)] // null
[DataRow("20300101")] // future date
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we calculate a future date rather than hardcoding? this will start failing in 2030

[DataRow("2000-01-32")] // date doesn't exist
[DataRow("1/13/2000 12:00:00 01")] // d/mm/yyyy hh:mm:ss tt
[DataRow("01/01/2000 25:00:00 01")] // dd/mm/yyyy hh:mm:ss tt
[DataRow("-2000")] // negative year
public void ValidatePastDate_InvalidInput_ReturnFalse(string date)
{
//No Arrange
//Act
var actual = ValidationHelper.ValidatePastDate(date);

//Assert
bool expected = false;
Assert.AreEqual(actual, expected);
}

[TestMethod]
[DataRow("8919361401")] // These are random valid NHS numbers created by https://data-gorilla.uk/en/healthcare/nhs-number/
[DataRow("4539728490")] // This does not contain PII.
[DataRow("1056154497")]
[DataRow("1201484383")]
[DataRow("8325769629")]
public void ValidateNHSNumber_ValidInput_ReturnTrue(string nhsNumber)
{
//No Arrange
//Act
var actual = ValidationHelper.ValidateNHSNumber(nhsNumber);

//Assert
bool expected = true;
Assert.AreEqual(actual, expected);
}

[TestMethod]
[DataRow(null)]
[DataRow("1234567890")]
[DataRow("-1234567890")]
[DataRow("1a2b3c4d5e")]
[DataRow("123")]
[DataRow("0000000000")]
public void ValidateNHSNumber_InvalidInput_ReturnFalse(string nhsNumber)
{
//No Arrange
//Act
var actual = ValidationHelper.ValidateNHSNumber(nhsNumber);

//Assert
bool expected = false;
Assert.AreEqual(actual, expected);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="../../../../application/CohortManager/src/Functions/Shared/Common/Common.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>

</Project>