-
Notifications
You must be signed in to change notification settings - Fork 2
test: Added unit tests to MappingUtilities.cs #810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c5f3208
test: Added tests to MappingUtilities.cs
Joseph2910 49d8d45
test: Added more coverage
Joseph2910 d8bd57f
chore: Remove erroneous import
Joseph2910 60c186d
Merge branch 'main' into DTOSS-7884-Add-Mapping-Utilities-Tests
Joseph2910 b8f1226
test: updated tests
Joseph2910 2b5a355
chore: Remove null
Joseph2910 0a607c3
chore: Remove comma
Joseph2910 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
tests/UnitTests/SharedTests/MappingUtilitiesTests/MappingUtilitiesTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| using NHS.CohortManager.Shared.Utilities; | ||
|
|
||
| namespace MappingUtilitiesTests; | ||
|
Joseph2910 marked this conversation as resolved.
|
||
|
|
||
| [TestClass] | ||
| public class MappingUtilitiesTests | ||
| { | ||
| private static readonly DateTime expectedResultDT = new DateTime(2000, 01, 01); | ||
|
|
||
| [TestMethod] | ||
| [DataRow("2000/01/01")] | ||
| public void ParseNullableDateTime_ValidInput_ReturnDate(string date) | ||
| { | ||
| //No Arrange | ||
| //Act | ||
| var actual = MappingUtilities.ParseNullableDateTime(date); | ||
|
|
||
| //Assert | ||
| Assert.AreEqual(actual, expectedResultDT); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [DataRow("2000/0/0")] //Invalid date | ||
| [DataRow(null)] //Null input | ||
| public void ParseNullableDateTime_InvalidInput_ReturnNull(string date) | ||
| { | ||
| //No Arrange | ||
| //Act | ||
| var actual = MappingUtilities.ParseNullableDateTime(date); | ||
|
|
||
| //Assert | ||
| Assert.IsNull(actual); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [DataRow("0",(short)0)] | ||
| [DataRow("1",(short)1)] | ||
| [DataRow("N",(short)0)] | ||
| [DataRow("Y",(short)1)] | ||
| public void ParseStringFlag_ValidInput_ReturnDate(string flag, short expectedResult) | ||
| { | ||
| //No Arrange | ||
| //Act | ||
| short actual = MappingUtilities.ParseStringFlag(flag); | ||
|
|
||
| //Assert | ||
| Assert.AreEqual(actual, expectedResult); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [DataRow("W")] | ||
| [DataRow(null)] | ||
| public void ParseStringFlag_InvalidInput_ReturnArguementError(string flag) | ||
| { | ||
| //No Arrange or Act | ||
| //Assert | ||
| var exception = Assert.ThrowsException<ArgumentException>(() => MappingUtilities.ParseStringFlag(flag)); | ||
| Assert.AreEqual("Invalid input", exception.Message); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [DataRow("01/01/2000")] // dd/mm/yyyy | ||
| [DataRow("20000101")] // yyyymmdd | ||
| [DataRow("1/1/2000")] // d/m/yyyy | ||
| [DataRow("2000")] //yyyy | ||
| [DataRow("200001")] //yyyymm | ||
| public void ParseDates_ValidInput_ReturnDate(string date) | ||
| { | ||
| //No Arrange | ||
| //Act | ||
| var actual = MappingUtilities.ParseDates(date); | ||
|
|
||
| //Assert | ||
| Assert.AreEqual(actual, expectedResultDT); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [DataRow("00/00/2000")] // dd/mm/yyyy | ||
| [DataRow("20000000")] // yyyymmdd | ||
| [DataRow("0/0/2000")] // d/m/yyyy | ||
| [DataRow(null)] | ||
| [DataRow("")] | ||
| public void ParseDates_InvalidInput_ReturnNull(string date) | ||
| { | ||
| //No Arrange | ||
| //Act | ||
| var actual = MappingUtilities.ParseDates(date); | ||
|
|
||
| //Assert | ||
| Assert.IsNull(actual); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void FormatDateTime_ValidInput_ReturnDate() | ||
| { | ||
| //Arrange | ||
| string expectedResult = "2000-01-01"; | ||
|
|
||
| //Act | ||
| var actual = MappingUtilities.FormatDateTime(expectedResultDT); | ||
|
|
||
| //Assert | ||
| Assert.AreEqual(actual, expectedResult); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void FormatDateTime_InvalidInput_ReturnNull() | ||
| { | ||
| //No Arrange | ||
| //Act | ||
| var actual = MappingUtilities.FormatDateTime(null); | ||
|
|
||
| //Assert | ||
| Assert.IsNull(actual); | ||
| } | ||
| } | ||
27 changes: 27 additions & 0 deletions
27
tests/UnitTests/SharedTests/MappingUtilitiesTests/MappingUtilitiesTests.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/Utilities/Utilities.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.