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
12 changes: 6 additions & 6 deletions application/CohortManager/src/Functions/Functions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExceptionHandlerTests", "..
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CheckDemographicTests", "..\..\..\..\tests\UnitTests\SharedTests\CheckDemographicTests\CheckDemographicTests.csproj", "{2476768B-4A21-4348-8EA3-A95EC27DE464}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GetValidationExceptionTests", "..\..\..\..\tests\UnitTests\ScreeningDataServicesTests\ValidationExceptionDataTests\GetValidationExceptionTests\GetValidationExceptionsTests.csproj", "{8B96E54E-5391-4B61-97D5-B31FC7963BEA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ValidationExceptionDataTests", "..\..\..\..\tests\UnitTests\ScreeningDataServicesTests\ValidationExceptionDataTests\ValidationExceptionDataTests\ValidationExceptionDataTests.csproj", "{A54E1897-B755-4D15-8575-6589E17ECADE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataServices.Client", "Shared\DataServices.Client\DataServices.Client.csproj", "{420B8566-2CE2-4B89-A0E4-D86C6AB24722}"
Expand Down Expand Up @@ -226,6 +224,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileNameParserTests", "..\.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddCohortDistributionDataTests", "..\..\..\..\tests\UnitTests\CohortDistributionTests\AddCohortDistributionDataTests\AddCohortDistributionDataTests.csproj", "{5D5C7C1C-37FE-4671-8BA2-138447049EE3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GetValidationExceptionsTests", "..\..\..\..\tests\UnitTests\ScreeningDataServicesTests\ValidationExceptionDataTests\GetValidationExceptionTests\GetValidationExceptionsTests.csproj", "{8E769A0D-F808-48F7-9E36-6F8BDC204C80}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -428,10 +428,6 @@ Global
{073470C0-3CFE-4C53-AA24-B3E75CB1BFE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{073470C0-3CFE-4C53-AA24-B3E75CB1BFE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{073470C0-3CFE-4C53-AA24-B3E75CB1BFE3}.Release|Any CPU.Build.0 = Release|Any CPU
{8B96E54E-5391-4B61-97D5-B31FC7963BEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8B96E54E-5391-4B61-97D5-B31FC7963BEA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8B96E54E-5391-4B61-97D5-B31FC7963BEA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8B96E54E-5391-4B61-97D5-B31FC7963BEA}.Release|Any CPU.Build.0 = Release|Any CPU
{A54E1897-B755-4D15-8575-6589E17ECADE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A54E1897-B755-4D15-8575-6589E17ECADE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A54E1897-B755-4D15-8575-6589E17ECADE}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -628,6 +624,10 @@ Global
{5D5C7C1C-37FE-4671-8BA2-138447049EE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5D5C7C1C-37FE-4671-8BA2-138447049EE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5D5C7C1C-37FE-4671-8BA2-138447049EE3}.Release|Any CPU.Build.0 = Release|Any CPU
{8E769A0D-F808-48F7-9E36-6F8BDC204C80}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8E769A0D-F808-48F7-9E36-6F8BDC204C80}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E769A0D-F808-48F7-9E36-6F8BDC204C80}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E769A0D-F808-48F7-9E36-6F8BDC204C80}.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
Expand Up @@ -17,6 +17,8 @@ public class GetValidationExceptionsTests : DatabaseTestBaseSetup<GetValidationE
private readonly List<ValidationException> _exceptionList;
private readonly Dictionary<string, string> columnToClassPropertyMapping;
private readonly Mock<PaginationService<ValidationException>> _paginationServiceMock = new();
private readonly HttpResponseData _mockHttpResponseData;


public GetValidationExceptionsTests() : base((conn, logger, transaction, command, response) => null)
{
Expand All @@ -40,6 +42,8 @@ public GetValidationExceptionsTests() : base((conn, logger, transaction, command
SetupRequest(json);
CreateHttpResponseMock();
SetupDataReader(_exceptionList, columnToClassPropertyMapping);

_mockHttpResponseData = _request.Object.CreateResponse();
}

[TestMethod]
Expand Down Expand Up @@ -94,4 +98,93 @@ public async Task Run_ExceptionIdIsOutOfRange_ReturnsNoContent()
Assert.AreEqual(HttpStatusCode.NoContent, result.StatusCode);
_validationDataMock.Verify(v => v.GetExceptionById(exceptionId), Times.Once);
}
[TestMethod]
public async Task Run_NoExceptionsFound_ReturnsNoContent()
{
// Arrange
var exceptionId = 0;


_validationDataMock.Setup(s => s.GetAllExceptions(false, ExceptionSort.DateCreated))
.ReturnsAsync(new List<ValidationException>());
_httpParserHelperMock.Setup(s => s.GetQueryParameterAsInt(It.IsAny<HttpRequestData>(), "exceptionId"))
.Returns(0);

_httpParserHelperMock.Setup(s => s.GetQueryParameterAsInt(It.IsAny<HttpRequestData>(), "lastId"))
.Returns(0);

_httpParserHelperMock.Setup(s => s.GetQueryParameterAsBool(
It.IsAny<HttpRequestData>(),
It.Is<string>(key => key == "todayOnly"),
It.IsAny<bool>()))
.Returns(false);

_httpParserHelperMock.Setup(s => s.GetQueryParameterAsInt(It.IsAny<HttpRequestData>(), "orderByProperty"))
.Returns((int)ExceptionSort.DateCreated);

_mockHttpResponseData.StatusCode = HttpStatusCode.NoContent;

_createResponseMock.Setup(r =>
r.CreateHttpResponse(
HttpStatusCode.NoContent,
It.IsAny<HttpRequestData>(),
It.IsAny<string>())
).Returns(_mockHttpResponseData);

SetupRequestWithQueryParams([]);

// Act
var result = await _service.Run(_request.Object);

// Assert
Assert.IsNotNull(result);
Assert.AreEqual(HttpStatusCode.NoContent, result.StatusCode);
_validationDataMock.Verify(v => v.GetAllExceptions(false, ExceptionSort.DateCreated), Times.Once);
}

[TestMethod]
public async Task Run_ThrowsException_ReturnsInternalServerError()
{
// Arrange
var exceptionId = 0;

// Simulate exception thrown from GetAllExceptions
_validationDataMock.Setup(s => s.GetAllExceptions(false, ExceptionSort.DateCreated))
.ThrowsAsync(new Exception("Simulated failure"));

_httpParserHelperMock.Setup(s => s.GetQueryParameterAsInt(It.IsAny<HttpRequestData>(), "exceptionId"))
.Returns(exceptionId);

_httpParserHelperMock.Setup(s => s.GetQueryParameterAsInt(It.IsAny<HttpRequestData>(), "lastId"))
.Returns(0);

_httpParserHelperMock.Setup(s => s.GetQueryParameterAsBool(
It.IsAny<HttpRequestData>(),
It.Is<string>(key => key == "todayOnly"),
It.IsAny<bool>()))
.Returns(false);

_httpParserHelperMock.Setup(s => s.GetQueryParameterAsInt(It.IsAny<HttpRequestData>(), "orderByProperty"))
.Returns((int)ExceptionSort.DateCreated);

// Setup the mock response with expected error status code
_mockHttpResponseData.StatusCode = HttpStatusCode.InternalServerError;

_createResponseMock.Setup(r =>
r.CreateHttpResponse(
HttpStatusCode.InternalServerError,
It.IsAny<HttpRequestData>(),
It.IsAny<string>())
).Returns(_mockHttpResponseData);

SetupRequestWithQueryParams([]);

// Act
var result = await _service.Run(_request.Object);

// Assert
Assert.IsNotNull(result);
Assert.AreEqual(HttpStatusCode.InternalServerError, result.StatusCode);
_validationDataMock.Verify(v => v.GetAllExceptions(false, ExceptionSort.DateCreated), Times.Once);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="MSTest.TestAdapter" Version="3.8.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.8.3" />
</ItemGroup>

<ItemGroup>
Expand Down