diff --git a/application/CohortManager/src/Functions/Functions.sln b/application/CohortManager/src/Functions/Functions.sln index 1a4bf2ad62..77e7ceca29 100644 --- a/application/CohortManager/src/Functions/Functions.sln +++ b/application/CohortManager/src/Functions/Functions.sln @@ -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}" @@ -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 @@ -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 @@ -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 diff --git a/tests/UnitTests/ScreeningDataServicesTests/ValidationExceptionDataTests/GetValidationExceptionTests/GetValidationExceptionsTests.cs b/tests/UnitTests/ScreeningDataServicesTests/ValidationExceptionDataTests/GetValidationExceptionTests/GetValidationExceptionsTests.cs index 45da06af09..8d52d2658a 100644 --- a/tests/UnitTests/ScreeningDataServicesTests/ValidationExceptionDataTests/GetValidationExceptionTests/GetValidationExceptionsTests.cs +++ b/tests/UnitTests/ScreeningDataServicesTests/ValidationExceptionDataTests/GetValidationExceptionTests/GetValidationExceptionsTests.cs @@ -17,6 +17,8 @@ public class GetValidationExceptionsTests : DatabaseTestBaseSetup _exceptionList; private readonly Dictionary columnToClassPropertyMapping; private readonly Mock> _paginationServiceMock = new(); + private readonly HttpResponseData _mockHttpResponseData; + public GetValidationExceptionsTests() : base((conn, logger, transaction, command, response) => null) { @@ -40,6 +42,8 @@ public GetValidationExceptionsTests() : base((conn, logger, transaction, command SetupRequest(json); CreateHttpResponseMock(); SetupDataReader(_exceptionList, columnToClassPropertyMapping); + + _mockHttpResponseData = _request.Object.CreateResponse(); } [TestMethod] @@ -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()); + _httpParserHelperMock.Setup(s => s.GetQueryParameterAsInt(It.IsAny(), "exceptionId")) + .Returns(0); + + _httpParserHelperMock.Setup(s => s.GetQueryParameterAsInt(It.IsAny(), "lastId")) + .Returns(0); + + _httpParserHelperMock.Setup(s => s.GetQueryParameterAsBool( + It.IsAny(), + It.Is(key => key == "todayOnly"), + It.IsAny())) + .Returns(false); + + _httpParserHelperMock.Setup(s => s.GetQueryParameterAsInt(It.IsAny(), "orderByProperty")) + .Returns((int)ExceptionSort.DateCreated); + + _mockHttpResponseData.StatusCode = HttpStatusCode.NoContent; + + _createResponseMock.Setup(r => + r.CreateHttpResponse( + HttpStatusCode.NoContent, + It.IsAny(), + It.IsAny()) + ).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(), "exceptionId")) + .Returns(exceptionId); + + _httpParserHelperMock.Setup(s => s.GetQueryParameterAsInt(It.IsAny(), "lastId")) + .Returns(0); + + _httpParserHelperMock.Setup(s => s.GetQueryParameterAsBool( + It.IsAny(), + It.Is(key => key == "todayOnly"), + It.IsAny())) + .Returns(false); + + _httpParserHelperMock.Setup(s => s.GetQueryParameterAsInt(It.IsAny(), "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(), + It.IsAny()) + ).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); + } } diff --git a/tests/UnitTests/ScreeningDataServicesTests/ValidationExceptionDataTests/GetValidationExceptionTests/GetValidationExceptionsTests.csproj b/tests/UnitTests/ScreeningDataServicesTests/ValidationExceptionDataTests/GetValidationExceptionTests/GetValidationExceptionsTests.csproj index 5049932039..02f7688b3d 100644 --- a/tests/UnitTests/ScreeningDataServicesTests/ValidationExceptionDataTests/GetValidationExceptionTests/GetValidationExceptionsTests.csproj +++ b/tests/UnitTests/ScreeningDataServicesTests/ValidationExceptionDataTests/GetValidationExceptionTests/GetValidationExceptionsTests.csproj @@ -11,9 +11,9 @@ - - - + + +