Skip to content

Commit 40bb9b3

Browse files
feat: DTOSS-8078-Update GetValidationExceptions tests (#840)
* feat: DTOSS-8078-Update GetValidationExceptions tests * feat: 8078-removing old guid references
1 parent 4f30c28 commit 40bb9b3

3 files changed

Lines changed: 102 additions & 9 deletions

File tree

application/CohortManager/src/Functions/Functions.sln

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExceptionHandlerTests", "..
136136
EndProject
137137
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CheckDemographicTests", "..\..\..\..\tests\UnitTests\SharedTests\CheckDemographicTests\CheckDemographicTests.csproj", "{2476768B-4A21-4348-8EA3-A95EC27DE464}"
138138
EndProject
139-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GetValidationExceptionTests", "..\..\..\..\tests\UnitTests\ScreeningDataServicesTests\ValidationExceptionDataTests\GetValidationExceptionTests\GetValidationExceptionsTests.csproj", "{8B96E54E-5391-4B61-97D5-B31FC7963BEA}"
140-
EndProject
141139
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ValidationExceptionDataTests", "..\..\..\..\tests\UnitTests\ScreeningDataServicesTests\ValidationExceptionDataTests\ValidationExceptionDataTests\ValidationExceptionDataTests.csproj", "{A54E1897-B755-4D15-8575-6589E17ECADE}"
142140
EndProject
143141
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataServices.Client", "Shared\DataServices.Client\DataServices.Client.csproj", "{420B8566-2CE2-4B89-A0E4-D86C6AB24722}"
@@ -226,6 +224,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileNameParserTests", "..\.
226224
EndProject
227225
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddCohortDistributionDataTests", "..\..\..\..\tests\UnitTests\CohortDistributionTests\AddCohortDistributionDataTests\AddCohortDistributionDataTests.csproj", "{5D5C7C1C-37FE-4671-8BA2-138447049EE3}"
228226
EndProject
227+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GetValidationExceptionsTests", "..\..\..\..\tests\UnitTests\ScreeningDataServicesTests\ValidationExceptionDataTests\GetValidationExceptionTests\GetValidationExceptionsTests.csproj", "{8E769A0D-F808-48F7-9E36-6F8BDC204C80}"
228+
EndProject
229229
Global
230230
GlobalSection(SolutionConfigurationPlatforms) = preSolution
231231
Debug|Any CPU = Debug|Any CPU
@@ -428,10 +428,6 @@ Global
428428
{073470C0-3CFE-4C53-AA24-B3E75CB1BFE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
429429
{073470C0-3CFE-4C53-AA24-B3E75CB1BFE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
430430
{073470C0-3CFE-4C53-AA24-B3E75CB1BFE3}.Release|Any CPU.Build.0 = Release|Any CPU
431-
{8B96E54E-5391-4B61-97D5-B31FC7963BEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
432-
{8B96E54E-5391-4B61-97D5-B31FC7963BEA}.Debug|Any CPU.Build.0 = Debug|Any CPU
433-
{8B96E54E-5391-4B61-97D5-B31FC7963BEA}.Release|Any CPU.ActiveCfg = Release|Any CPU
434-
{8B96E54E-5391-4B61-97D5-B31FC7963BEA}.Release|Any CPU.Build.0 = Release|Any CPU
435431
{A54E1897-B755-4D15-8575-6589E17ECADE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
436432
{A54E1897-B755-4D15-8575-6589E17ECADE}.Debug|Any CPU.Build.0 = Debug|Any CPU
437433
{A54E1897-B755-4D15-8575-6589E17ECADE}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -628,6 +624,10 @@ Global
628624
{5D5C7C1C-37FE-4671-8BA2-138447049EE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
629625
{5D5C7C1C-37FE-4671-8BA2-138447049EE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
630626
{5D5C7C1C-37FE-4671-8BA2-138447049EE3}.Release|Any CPU.Build.0 = Release|Any CPU
627+
{8E769A0D-F808-48F7-9E36-6F8BDC204C80}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
628+
{8E769A0D-F808-48F7-9E36-6F8BDC204C80}.Debug|Any CPU.Build.0 = Debug|Any CPU
629+
{8E769A0D-F808-48F7-9E36-6F8BDC204C80}.Release|Any CPU.ActiveCfg = Release|Any CPU
630+
{8E769A0D-F808-48F7-9E36-6F8BDC204C80}.Release|Any CPU.Build.0 = Release|Any CPU
631631
EndGlobalSection
632632
GlobalSection(SolutionProperties) = preSolution
633633
HideSolutionNode = FALSE

tests/UnitTests/ScreeningDataServicesTests/ValidationExceptionDataTests/GetValidationExceptionTests/GetValidationExceptionsTests.cs

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public class GetValidationExceptionsTests : DatabaseTestBaseSetup<GetValidationE
1717
private readonly List<ValidationException> _exceptionList;
1818
private readonly Dictionary<string, string> columnToClassPropertyMapping;
1919
private readonly Mock<PaginationService<ValidationException>> _paginationServiceMock = new();
20+
private readonly HttpResponseData _mockHttpResponseData;
21+
2022

2123
public GetValidationExceptionsTests() : base((conn, logger, transaction, command, response) => null)
2224
{
@@ -40,6 +42,8 @@ public GetValidationExceptionsTests() : base((conn, logger, transaction, command
4042
SetupRequest(json);
4143
CreateHttpResponseMock();
4244
SetupDataReader(_exceptionList, columnToClassPropertyMapping);
45+
46+
_mockHttpResponseData = _request.Object.CreateResponse();
4347
}
4448

4549
[TestMethod]
@@ -94,4 +98,93 @@ public async Task Run_ExceptionIdIsOutOfRange_ReturnsNoContent()
9498
Assert.AreEqual(HttpStatusCode.NoContent, result.StatusCode);
9599
_validationDataMock.Verify(v => v.GetExceptionById(exceptionId), Times.Once);
96100
}
101+
[TestMethod]
102+
public async Task Run_NoExceptionsFound_ReturnsNoContent()
103+
{
104+
// Arrange
105+
var exceptionId = 0;
106+
107+
108+
_validationDataMock.Setup(s => s.GetAllExceptions(false, ExceptionSort.DateCreated))
109+
.ReturnsAsync(new List<ValidationException>());
110+
_httpParserHelperMock.Setup(s => s.GetQueryParameterAsInt(It.IsAny<HttpRequestData>(), "exceptionId"))
111+
.Returns(0);
112+
113+
_httpParserHelperMock.Setup(s => s.GetQueryParameterAsInt(It.IsAny<HttpRequestData>(), "lastId"))
114+
.Returns(0);
115+
116+
_httpParserHelperMock.Setup(s => s.GetQueryParameterAsBool(
117+
It.IsAny<HttpRequestData>(),
118+
It.Is<string>(key => key == "todayOnly"),
119+
It.IsAny<bool>()))
120+
.Returns(false);
121+
122+
_httpParserHelperMock.Setup(s => s.GetQueryParameterAsInt(It.IsAny<HttpRequestData>(), "orderByProperty"))
123+
.Returns((int)ExceptionSort.DateCreated);
124+
125+
_mockHttpResponseData.StatusCode = HttpStatusCode.NoContent;
126+
127+
_createResponseMock.Setup(r =>
128+
r.CreateHttpResponse(
129+
HttpStatusCode.NoContent,
130+
It.IsAny<HttpRequestData>(),
131+
It.IsAny<string>())
132+
).Returns(_mockHttpResponseData);
133+
134+
SetupRequestWithQueryParams([]);
135+
136+
// Act
137+
var result = await _service.Run(_request.Object);
138+
139+
// Assert
140+
Assert.IsNotNull(result);
141+
Assert.AreEqual(HttpStatusCode.NoContent, result.StatusCode);
142+
_validationDataMock.Verify(v => v.GetAllExceptions(false, ExceptionSort.DateCreated), Times.Once);
143+
}
144+
145+
[TestMethod]
146+
public async Task Run_ThrowsException_ReturnsInternalServerError()
147+
{
148+
// Arrange
149+
var exceptionId = 0;
150+
151+
// Simulate exception thrown from GetAllExceptions
152+
_validationDataMock.Setup(s => s.GetAllExceptions(false, ExceptionSort.DateCreated))
153+
.ThrowsAsync(new Exception("Simulated failure"));
154+
155+
_httpParserHelperMock.Setup(s => s.GetQueryParameterAsInt(It.IsAny<HttpRequestData>(), "exceptionId"))
156+
.Returns(exceptionId);
157+
158+
_httpParserHelperMock.Setup(s => s.GetQueryParameterAsInt(It.IsAny<HttpRequestData>(), "lastId"))
159+
.Returns(0);
160+
161+
_httpParserHelperMock.Setup(s => s.GetQueryParameterAsBool(
162+
It.IsAny<HttpRequestData>(),
163+
It.Is<string>(key => key == "todayOnly"),
164+
It.IsAny<bool>()))
165+
.Returns(false);
166+
167+
_httpParserHelperMock.Setup(s => s.GetQueryParameterAsInt(It.IsAny<HttpRequestData>(), "orderByProperty"))
168+
.Returns((int)ExceptionSort.DateCreated);
169+
170+
// Setup the mock response with expected error status code
171+
_mockHttpResponseData.StatusCode = HttpStatusCode.InternalServerError;
172+
173+
_createResponseMock.Setup(r =>
174+
r.CreateHttpResponse(
175+
HttpStatusCode.InternalServerError,
176+
It.IsAny<HttpRequestData>(),
177+
It.IsAny<string>())
178+
).Returns(_mockHttpResponseData);
179+
180+
SetupRequestWithQueryParams([]);
181+
182+
// Act
183+
var result = await _service.Run(_request.Object);
184+
185+
// Assert
186+
Assert.IsNotNull(result);
187+
Assert.AreEqual(HttpStatusCode.InternalServerError, result.StatusCode);
188+
_validationDataMock.Verify(v => v.GetAllExceptions(false, ExceptionSort.DateCreated), Times.Once);
189+
}
97190
}

tests/UnitTests/ScreeningDataServicesTests/ValidationExceptionDataTests/GetValidationExceptionTests/GetValidationExceptionsTests.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
<ItemGroup>
1212
<PackageReference Include="coverlet.collector" Version="6.0.0" />
1313
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
14-
<PackageReference Include="Moq" Version="4.20.70" />
15-
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
16-
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
14+
<PackageReference Include="Moq" Version="4.20.72" />
15+
<PackageReference Include="MSTest.TestAdapter" Version="3.8.3" />
16+
<PackageReference Include="MSTest.TestFramework" Version="3.8.3" />
1717
</ItemGroup>
1818

1919
<ItemGroup>

0 commit comments

Comments
 (0)