diff --git a/application/CohortManager/src/Functions/DemographicServices/RetrievePDSDemographic/IPdsProcessor.cs b/application/CohortManager/src/Functions/DemographicServices/RetrievePDSDemographic/IPdsProcessor.cs new file mode 100644 index 0000000000..a257c6476e --- /dev/null +++ b/application/CohortManager/src/Functions/DemographicServices/RetrievePDSDemographic/IPdsProcessor.cs @@ -0,0 +1,10 @@ +namespace NHS.CohortManager.DemographicServices; + +using Model; + +public interface IPdsProcessor +{ + Task ProcessPdsNotFoundResponse(HttpResponseMessage pdsResponse, string nhsNumber); + Task ProcessRecord(Participant participant); + Task UpsertDemographicRecordFromPDS(ParticipantDemographic participantDemographic); +} \ No newline at end of file diff --git a/application/CohortManager/src/Functions/DemographicServices/RetrievePDSDemographic/PdsProcessor.cs b/application/CohortManager/src/Functions/DemographicServices/RetrievePDSDemographic/PdsProcessor.cs new file mode 100644 index 0000000000..73ccb6bdeb --- /dev/null +++ b/application/CohortManager/src/Functions/DemographicServices/RetrievePDSDemographic/PdsProcessor.cs @@ -0,0 +1,124 @@ +namespace NHS.CohortManager.DemographicServices; + +using System.Collections.Concurrent; +using System.Net.Http.Json; +using Common; +using DataServices.Client; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Model; + +public class PdsProcessor : IPdsProcessor +{ + private readonly ILogger _logger; + + private readonly IDataServiceClient _participantDemographicClient; + private readonly ICreateBasicParticipantData _createBasicParticipantData; + private readonly RetrievePDSDemographicConfig _config; + private readonly IAddBatchToQueue _addBatchToQueue; + + + public PdsProcessor( + ILogger logger, + ICreateBasicParticipantData createBasicParticipantData, + IDataServiceClient participantDemographicClient, + IAddBatchToQueue addBatchToQueue, + IOptions retrievePDSDemographicConfig) + { + _logger = logger; + _participantDemographicClient = participantDemographicClient; + _createBasicParticipantData = createBasicParticipantData; + _addBatchToQueue = addBatchToQueue; + _config = retrievePDSDemographicConfig.Value; + } + + /// + /// processes pds error responses. Sends a record to distribute participant via service bus + /// + /// + /// + /// + public async Task ProcessPdsNotFoundResponse(HttpResponseMessage pdsResponse, string nhsNumber) + { + var errorResponse = await pdsResponse!.Content.ReadFromJsonAsync(); + // we now create a record as an update record and send to the manage participant function. Reason for removal for date should be today and the reason for remove of ORR + if (errorResponse!.issue!.FirstOrDefault()!.details!.coding!.FirstOrDefault()!.code == PdsConstants.InvalidatedResourceCode) + { + var pdsDemographic = new PdsDemographic() + { + NhsNumber = nhsNumber, + PrimaryCareProvider = null, + ReasonForRemoval = PdsConstants.OrrRemovalReason, + RemovalEffectiveFromDate = DateTime.UtcNow.Date.ToString("yyyyMMdd") + }; + var participant = new Participant(pdsDemographic); + participant.RecordType = Actions.Removed; + //sends record for an update + await ProcessRecord(participant); + return; + } + _logger.LogError("the PDS function has returned a 404 error. function now stopping processing"); + } + + /// + /// sends a participant record to the distribute service bus topic + /// + /// + /// + public async Task ProcessRecord(Participant participant) + { + var updateRecord = new ConcurrentQueue(); + participant.RecordType = Actions.Removed; + + var basicParticipantCsvRecord = new BasicParticipantCsvRecord + { + BasicParticipantData = _createBasicParticipantData.BasicParticipantData(participant), + FileName = PdsConstants.DefaultFileName, + Participant = participant + }; + + updateRecord.Enqueue(basicParticipantCsvRecord); + + _logger.LogInformation("Sending record to the update queue."); + await _addBatchToQueue.ProcessBatch(updateRecord, _config.ParticipantManagementTopic); + } + + /// + /// adds or updates a demographic record depending on if an record already exists in the database + /// + /// + /// + public async Task UpsertDemographicRecordFromPDS(ParticipantDemographic participantDemographic) + { + ParticipantDemographic oldParticipantDemographic = await _participantDemographicClient.GetSingleByFilter(i => i.NhsNumber == participantDemographic.NhsNumber); + + if (oldParticipantDemographic == null) + { + _logger.LogInformation("Participant Demographic record not found, attemping to add Participant Demographic."); + bool addSuccess = await _participantDemographicClient.Add(participantDemographic); + + if (addSuccess) + { + _logger.LogInformation("Successfully added Participant Demographic."); + return true; + } + + _logger.LogError("Failed to add Participant Demographic."); + return false; + } + + _logger.LogInformation("Participant Demographic record found, attempting to update Participant Demographic."); + participantDemographic.ParticipantId = oldParticipantDemographic.ParticipantId; + bool updateSuccess = await _participantDemographicClient.Update(participantDemographic); + + if (updateSuccess) + { + _logger.LogInformation("Successfully updated Participant Demographic."); + return true; + } + + _logger.LogError("Failed to update Participant Demographic."); + return false; + } + +} \ No newline at end of file diff --git a/application/CohortManager/src/Functions/DemographicServices/RetrievePDSDemographic/Program.cs b/application/CohortManager/src/Functions/DemographicServices/RetrievePDSDemographic/Program.cs index 3aec6ea56d..093684c5c6 100644 --- a/application/CohortManager/src/Functions/DemographicServices/RetrievePDSDemographic/Program.cs +++ b/application/CohortManager/src/Functions/DemographicServices/RetrievePDSDemographic/Program.cs @@ -19,6 +19,7 @@ services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); // Register health checks services.AddBasicHealthCheck("RetrievePdsDemographic"); diff --git a/application/CohortManager/src/Functions/DemographicServices/RetrievePDSDemographic/RetrievePDSDemographic.cs b/application/CohortManager/src/Functions/DemographicServices/RetrievePDSDemographic/RetrievePDSDemographic.cs index f6b6ac16a9..7ffefed1b9 100644 --- a/application/CohortManager/src/Functions/DemographicServices/RetrievePDSDemographic/RetrievePDSDemographic.cs +++ b/application/CohortManager/src/Functions/DemographicServices/RetrievePDSDemographic/RetrievePDSDemographic.cs @@ -12,8 +12,6 @@ namespace NHS.CohortManager.DemographicServices; using Microsoft.Extensions.Options; using System.Threading.Tasks; using Model; -using System.Net.Http.Json; -using System.Collections.Concurrent; public class RetrievePdsDemographic { @@ -22,10 +20,8 @@ public class RetrievePdsDemographic private readonly IHttpClientFunction _httpClientFunction; private readonly RetrievePDSDemographicConfig _config; private readonly IFhirPatientDemographicMapper _fhirPatientDemographicMapper; - private readonly IDataServiceClient _participantDemographicClient; private readonly IBearerTokenService _bearerTokenService; - private readonly ICreateBasicParticipantData _createBasicParticipantData; - private readonly IAddBatchToQueue _addBatchToQueue; + private readonly IPdsProcessor _pdsProcessor; private const string PdsParticipantUrlFormat = "{0}/{1}"; @@ -35,10 +31,8 @@ public RetrievePdsDemographic( IHttpClientFunction httpClientFunction, IFhirPatientDemographicMapper fhirPatientDemographicMapper, IOptions retrievePDSDemographicConfig, - IDataServiceClient participantDemographicClient, - ICreateBasicParticipantData createBasicParticipantData, - IAddBatchToQueue addBatchToQueue, - IBearerTokenService bearerTokenService + IBearerTokenService bearerTokenService, + IPdsProcessor pdsProcessor ) { _logger = logger; @@ -46,10 +40,8 @@ IBearerTokenService bearerTokenService _httpClientFunction = httpClientFunction; _fhirPatientDemographicMapper = fhirPatientDemographicMapper; _config = retrievePDSDemographicConfig.Value; - _participantDemographicClient = participantDemographicClient; - _createBasicParticipantData = createBasicParticipantData; _bearerTokenService = bearerTokenService; - _addBatchToQueue = addBatchToQueue; + _pdsProcessor = pdsProcessor; } // TODO: Need to send an exception to the EXCEPTION_MANAGEMENT table whenever this function returns a non OK status. @@ -82,14 +74,14 @@ public async Task Run([HttpTrigger(AuthorizationLevel.Anonymou if (response.StatusCode == HttpStatusCode.NotFound || pdsDemographic.ConfidentialityCode == "R") { - await ProcessPdsNotFoundResponse(response, nhsNumber); + await _pdsProcessor.ProcessPdsNotFoundResponse(response, nhsNumber); return _createResponse.CreateHttpResponse(HttpStatusCode.NotFound, req, "PDS returned a 404 please database for details"); } response.EnsureSuccessStatusCode(); var participantDemographic = pdsDemographic.ToParticipantDemographic(); - var upsertResult = await UpsertDemographicRecordFromPDS(participantDemographic); + var upsertResult = await _pdsProcessor.UpsertDemographicRecordFromPDS(participantDemographic); return upsertResult ? _createResponse.CreateHttpResponse(HttpStatusCode.OK, req, JsonSerializer.Serialize(participantDemographic)) : @@ -101,79 +93,4 @@ public async Task Run([HttpTrigger(AuthorizationLevel.Anonymou return _createResponse.CreateHttpResponse(HttpStatusCode.InternalServerError, req); } } - - private async Task ProcessPdsNotFoundResponse(HttpResponseMessage pdsResponse, string nhsNumber) - { - var errorResponse = await pdsResponse!.Content.ReadFromJsonAsync(); - // we now create a record as an update record and send to the manage participant function. Reason for removal for date should be today and the reason for remove of ORR - if (errorResponse!.issue!.FirstOrDefault()!.details!.coding!.FirstOrDefault()!.code == PdsConstants.InvalidatedResourceCode) - { - var pdsDemographic = new PdsDemographic() - { - NhsNumber = nhsNumber, - PrimaryCareProvider = null, - ReasonForRemoval = PdsConstants.OrrRemovalReason, - RemovalEffectiveFromDate = DateTime.UtcNow.Date.ToString("yyyyMMdd") - }; - var participant = new Participant(pdsDemographic); - participant.RecordType = Actions.Removed; - //sends record for an update - await ProcessRecord(participant); - return; - } - _logger.LogError("the PDS function has returned a 404 error. function now stopping processing"); - } - - - private async Task ProcessRecord(Participant participant) - { - var updateRecord = new ConcurrentQueue(); - participant.RecordType = participant.RecordType = Actions.Removed; - - var basicParticipantCsvRecord = new BasicParticipantCsvRecord - { - BasicParticipantData = _createBasicParticipantData.BasicParticipantData(participant), - FileName = PdsConstants.DefaultFileName, - Participant = participant - }; - - updateRecord.Enqueue(basicParticipantCsvRecord); - - _logger.LogInformation("Sending record to the update queue."); - await _addBatchToQueue.ProcessBatch(updateRecord, _config.ParticipantManagementTopic); - } - - - private async Task UpsertDemographicRecordFromPDS(ParticipantDemographic participantDemographic) - { - ParticipantDemographic oldParticipantDemographic = await _participantDemographicClient.GetSingleByFilter(i => i.NhsNumber == participantDemographic.NhsNumber); - - if (oldParticipantDemographic == null) - { - _logger.LogInformation("Participant Demographic record not found, attemping to add Participant Demographic."); - bool addSuccess = await _participantDemographicClient.Add(participantDemographic); - - if (addSuccess) - { - _logger.LogInformation("Successfully added Participant Demographic."); - return true; - } - - _logger.LogError("Failed to add Participant Demographic."); - return false; - } - - _logger.LogInformation("Participant Demographic record found, attempting to update Participant Demographic."); - participantDemographic.ParticipantId = oldParticipantDemographic.ParticipantId; - bool updateSuccess = await _participantDemographicClient.Update(participantDemographic); - - if (updateSuccess) - { - _logger.LogInformation("Successfully updated Participant Demographic."); - return true; - } - - _logger.LogError("Failed to update Participant Demographic."); - return false; - } } diff --git a/application/CohortManager/src/Functions/Functions.sln b/application/CohortManager/src/Functions/Functions.sln index 8891d8edd4..701c5f0fd8 100644 --- a/application/CohortManager/src/Functions/Functions.sln +++ b/application/CohortManager/src/Functions/Functions.sln @@ -229,6 +229,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JWTTokenServiceTests", "..\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AuthClientCredentialsTests", "..\..\..\..\tests\UnitTests\AuthClientCredentialsTests\AuthClientCredentialsTests.csproj", "{59CBDBE5-29BE-F38C-80E6-40843F2F8AF6}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "PdsProcesserTests", "PdsProcesserTests", "{5555D2A1-8C8F-5B64-9F84-08EFE0FC7CD8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PdsProcessorTests", "..\..\..\..\tests\PdsProcessorTests\PdsProcessorTests.csproj", "{FC22C311-57DD-B069-4041-AD2AC8F80B5D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1367,6 +1371,18 @@ Global {59CBDBE5-29BE-F38C-80E6-40843F2F8AF6}.Release|x64.Build.0 = Release|Any CPU {59CBDBE5-29BE-F38C-80E6-40843F2F8AF6}.Release|x86.ActiveCfg = Release|Any CPU {59CBDBE5-29BE-F38C-80E6-40843F2F8AF6}.Release|x86.Build.0 = Release|Any CPU + {FC22C311-57DD-B069-4041-AD2AC8F80B5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FC22C311-57DD-B069-4041-AD2AC8F80B5D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FC22C311-57DD-B069-4041-AD2AC8F80B5D}.Debug|x64.ActiveCfg = Debug|Any CPU + {FC22C311-57DD-B069-4041-AD2AC8F80B5D}.Debug|x64.Build.0 = Debug|Any CPU + {FC22C311-57DD-B069-4041-AD2AC8F80B5D}.Debug|x86.ActiveCfg = Debug|Any CPU + {FC22C311-57DD-B069-4041-AD2AC8F80B5D}.Debug|x86.Build.0 = Debug|Any CPU + {FC22C311-57DD-B069-4041-AD2AC8F80B5D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FC22C311-57DD-B069-4041-AD2AC8F80B5D}.Release|Any CPU.Build.0 = Release|Any CPU + {FC22C311-57DD-B069-4041-AD2AC8F80B5D}.Release|x64.ActiveCfg = Release|Any CPU + {FC22C311-57DD-B069-4041-AD2AC8F80B5D}.Release|x64.Build.0 = Release|Any CPU + {FC22C311-57DD-B069-4041-AD2AC8F80B5D}.Release|x86.ActiveCfg = Release|Any CPU + {FC22C311-57DD-B069-4041-AD2AC8F80B5D}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1428,5 +1444,6 @@ Global {52C72C2E-9A76-4ECF-A210-C3F7C584C193} = {19500E0D-AAAB-6F02-E24F-82619ACA2290} {4BD680A2-1ACB-7D6B-B2FD-8EBE9AEB5050} = {E8E33C5F-F9FB-3ACA-2B58-298ED48517C1} {59CBDBE5-29BE-F38C-80E6-40843F2F8AF6} = {E8E33C5F-F9FB-3ACA-2B58-298ED48517C1} + {FC22C311-57DD-B069-4041-AD2AC8F80B5D} = {5555D2A1-8C8F-5B64-9F84-08EFE0FC7CD8} EndGlobalSection EndGlobal diff --git a/tests/PdsProcessorTests/PdsProcessorTests.cs b/tests/PdsProcessorTests/PdsProcessorTests.cs new file mode 100644 index 0000000000..92bf4dec9e --- /dev/null +++ b/tests/PdsProcessorTests/PdsProcessorTests.cs @@ -0,0 +1,264 @@ +namespace NHS.CohortManager.Tests.PdsProcessorTests; + +using System.Text.Json; +using Common; +using DataServices.Client; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Model; +using Moq; +using NHS.CohortManager.DemographicServices; + +[TestClass] +public class PdsProcessorTests +{ + private readonly Mock> _mockLogger = new(); + private readonly Mock _mockCreateBasicParticipantData = new(); + private readonly Mock> _dataServiceClient = new(); + private readonly Mock _addBatchToQueue = new(); + private readonly Mock> _retrievePDSDemographicConfig = new(); + string nhsNumber = "1111110662"; + + private readonly PdsProcessor _pdsProcessor; + public PdsProcessorTests() + { + var testConfig = new RetrievePDSDemographicConfig + { + RetrievePdsParticipantURL = "", + DemographicDataServiceURL = "", + Audience = "", + KId = "", + AuthTokenURL = "", + ParticipantManagementTopic = "some-fake-topic", + ServiceBusConnectionString = "", + UseFakePDSServices = false + }; + + + _mockCreateBasicParticipantData.Setup(x => x.BasicParticipantData(It.IsAny())) + .Returns(new BasicParticipantData()); + + _retrievePDSDemographicConfig.Setup(x => x.Value).Returns(testConfig); + + _dataServiceClient.Setup(x => x.Update(It.IsAny())).ReturnsAsync(true); + _dataServiceClient.Setup(x => x.Add(It.IsAny())).ReturnsAsync(true); + _pdsProcessor = new PdsProcessor(_mockLogger.Object, _mockCreateBasicParticipantData.Object, _dataServiceClient.Object, _addBatchToQueue.Object, _retrievePDSDemographicConfig.Object); + + } + + [TestMethod] + public async Task ProcessPdsNotFoundResponse_ProcessesResponse_SendsForDistribution() + { + var errorResponse = new PdsErrorResponse() + { + issue = new List() + { + new PdsIssue() + { + code = "", + details = new PdsErrorDetails() + { + coding = new List() + { + new PdsCoding() + { + code = "INVALIDATED_RESOURCE" + } + } + } + } + } + }; + + HttpResponseMessage httpResponseMessage = new HttpResponseMessage(); + httpResponseMessage.Content = new StringContent(JsonSerializer.Serialize(errorResponse)); + + await _pdsProcessor.ProcessPdsNotFoundResponse(httpResponseMessage, nhsNumber); + + _mockLogger.Verify(x => x.Log(It.Is(l => l == LogLevel.Information), + It.IsAny(), + It.Is((v, t) => v.ToString().Contains($"Sending record to the update queue.")), + It.IsAny(), + It.IsAny>()), + Times.Once); + + _mockLogger.Verify(x => x.Log(It.Is(l => l == LogLevel.Error), + It.IsAny(), + It.Is((v, t) => v.ToString().Contains($"the PDS function has returned a 404 error. function now stopping processing")), + It.IsAny(), + It.IsAny>()), + Times.Never); + } + + [TestMethod] + public async Task ProcessPdsNotFoundResponse_WithNonInvalidatedResource_LogsError() + { + var errorResponse = new PdsErrorResponse() + { + issue = new List() + { + new PdsIssue() + { + code = "", + details = new PdsErrorDetails() + { + coding = new List() + { + new PdsCoding() + { + code = "" + } + } + } + } + } + }; + + HttpResponseMessage httpResponseMessage = new HttpResponseMessage(); + httpResponseMessage.Content = new StringContent(JsonSerializer.Serialize(errorResponse)); + + await _pdsProcessor.ProcessPdsNotFoundResponse(httpResponseMessage, nhsNumber); + + _mockLogger.Verify(x => x.Log(It.Is(l => l == LogLevel.Information), + It.IsAny(), + It.Is((v, t) => v.ToString().Contains($"Sending record to the update queue.")), + It.IsAny(), + It.IsAny>()), + Times.Never); + + _mockLogger.Verify(x => x.Log(It.Is(l => l == LogLevel.Error), + It.IsAny(), + It.Is((v, t) => v.ToString().Contains($"the PDS function has returned a 404 error. function now stopping processing")), + It.IsAny(), + It.IsAny>()), + Times.Once); + } + + + [TestMethod] + public async Task UpsertDemographicRecordFromPDS_WithExistingRecord_ReturnsTrue() + { + _dataServiceClient.Setup(x => x.GetSingleByFilter(It.IsAny>>())).ReturnsAsync(new ParticipantDemographic() + { + NhsNumber = 1111110662 + }); + + var res = await _pdsProcessor.UpsertDemographicRecordFromPDS(new ParticipantDemographic()); + + _mockLogger.Verify(x => x.Log(It.Is(l => l == LogLevel.Information), + It.IsAny(), + It.Is((v, t) => v.ToString().Contains("Successfully updated Participant Demographic.")), + It.IsAny(), + It.IsAny>()), + Times.Once); + + _mockLogger.Verify(x => x.Log(It.Is(l => l == LogLevel.Information), + It.IsAny(), + It.Is((v, t) => v.ToString().Contains("Participant Demographic record found, attempting to update Participant Demographic.")), + It.IsAny(), + It.IsAny>()), + Times.Once); + + Assert.IsTrue(res); + } + + + [TestMethod] + public async Task UpsertDemographicRecordFromPDS_WithNewRecord_ReturnsTrue() + { + var res = await _pdsProcessor.UpsertDemographicRecordFromPDS(new ParticipantDemographic()); + + _mockLogger.Verify(x => x.Log(It.Is(l => l == LogLevel.Information), + It.IsAny(), + It.Is((v, t) => v.ToString().Contains("Successfully updated Participant Demographic.")), + It.IsAny(), + It.IsAny>()), + Times.Never); + + _mockLogger.Verify(x => x.Log(It.Is(l => l == LogLevel.Information), + It.IsAny(), + It.Is((v, t) => v.ToString().Contains("Participant Demographic record found, attempting to update Participant Demographic.")), + It.IsAny(), + It.IsAny>()), + Times.Never); + + _mockLogger.Verify(x => x.Log(It.Is(l => l == LogLevel.Information), + It.IsAny(), + It.Is((v, t) => v.ToString().Contains("Successfully added Participant Demographic.")), + It.IsAny(), + It.IsAny>()), + Times.Once); + + + Assert.IsTrue(res); + } + + [TestMethod] + public async Task UpsertDemographicRecordFromPDS_FailsToAddNewRecord_ReturnsFalse() + { + _dataServiceClient.Setup(x => x.Add(It.IsAny())).ReturnsAsync(false); + var res = await _pdsProcessor.UpsertDemographicRecordFromPDS(new ParticipantDemographic()); + + _mockLogger.Verify(x => x.Log(It.Is(l => l == LogLevel.Information), + It.IsAny(), + It.Is((v, t) => v.ToString().Contains("Successfully updated Participant Demographic.")), + It.IsAny(), + It.IsAny>()), + Times.Never); + + _mockLogger.Verify(x => x.Log(It.Is(l => l == LogLevel.Information), + It.IsAny(), + It.Is((v, t) => v.ToString().Contains("Participant Demographic record found, attempting to update Participant Demographic.")), + It.IsAny(), + It.IsAny>()), + Times.Never); + + _mockLogger.Verify(x => x.Log(It.Is(l => l == LogLevel.Information), + It.IsAny(), + It.Is((v, t) => v.ToString().Contains("Successfully added Participant Demographic.")), + It.IsAny(), + It.IsAny>()), + Times.Never); + + Assert.IsFalse(res); + } + + [TestMethod] + public async Task UpsertDemographicRecordFromPDS_UpdateRecordFails_ReturnsFalse() + { + _dataServiceClient.Setup(x => x.GetSingleByFilter(It.IsAny>>())).ReturnsAsync(new ParticipantDemographic() + { + NhsNumber = 1111110662 + }); + _dataServiceClient.Setup(x => x.Update(It.IsAny())).ReturnsAsync(false); + + + var res = await _pdsProcessor.UpsertDemographicRecordFromPDS(new ParticipantDemographic()); + + _mockLogger.Verify(x => x.Log(It.Is(l => l == LogLevel.Information), + It.IsAny(), + It.Is((v, t) => v.ToString().Contains("Successfully updated Participant Demographic.")), + It.IsAny(), + It.IsAny>()), + Times.Never); + + _mockLogger.Verify(x => x.Log(It.Is(l => l == LogLevel.Information), + It.IsAny(), + It.Is((v, t) => v.ToString().Contains("Participant Demographic record found, attempting to update Participant Demographic.")), + It.IsAny(), + It.IsAny>()), + Times.Once); + + _mockLogger.Verify(x => x.Log(It.Is(l => l == LogLevel.Error), + It.IsAny(), + It.Is((v, t) => v.ToString().Contains("Failed to update Participant Demographic.")), + It.IsAny(), + It.IsAny>()), + Times.Once); + + + Assert.IsFalse(res); + } + + +} \ No newline at end of file diff --git a/tests/PdsProcessorTests/PdsProcessorTests.csproj b/tests/PdsProcessorTests/PdsProcessorTests.csproj new file mode 100644 index 0000000000..e35c6763c2 --- /dev/null +++ b/tests/PdsProcessorTests/PdsProcessorTests.csproj @@ -0,0 +1,29 @@ + + + + {F2D368CE-F338-42E1-8083-7052F9DAA3F7} + net8.0 + enable + enable + + false + true + + + + + + + + + + + + + + + + + + + diff --git a/tests/UnitTests/DemographicServicesTests/RetrievePDSDemographicTests/RetrievePDSDemographicTests.cs b/tests/UnitTests/DemographicServicesTests/RetrievePDSDemographicTests/RetrievePDSDemographicTests.cs index c6338a692f..59796cc211 100644 --- a/tests/UnitTests/DemographicServicesTests/RetrievePDSDemographicTests/RetrievePDSDemographicTests.cs +++ b/tests/UnitTests/DemographicServicesTests/RetrievePDSDemographicTests/RetrievePDSDemographicTests.cs @@ -20,12 +20,12 @@ public class RetrievePdsDemographicTests : DatabaseTestBaseSetup _mockHttpClientFunction = new(); private static readonly Mock> _mockConfig = new(); private static readonly Mock _mockFhirPatientDemographicMapper = new(); - private static readonly Mock> _mockParticipantDemographicClient = new(); - private static readonly Mock _mockCreateBasicParticipantService = new(); - private static readonly Mock _mockAddBatchToQueue = new(); - private static Mock _bearerTokenService = new(); + private static Mock _httpClientFunction = new(); + + private static readonly Mock _mockPdsProcessor = new(); + private const string _validNhsNumber = "3112728165"; private const long _validNhsNumberLong = 3112728165; @@ -34,13 +34,11 @@ public RetrievePdsDemographicTests() : base((conn, logger, transaction, command, new RetrievePdsDemographic( logger, response, - _mockHttpClientFunction.Object, + _httpClientFunction.Object, _mockFhirPatientDemographicMapper.Object, _mockConfig.Object, - _mockParticipantDemographicClient.Object, - _mockCreateBasicParticipantService.Object, - _mockAddBatchToQueue.Object, - _bearerTokenService.Object + _bearerTokenService.Object, + _mockPdsProcessor.Object )) { CreateHttpResponseMock();