diff --git a/src/Altinn.Notifications.Core/Integrations/IRegisterClient.cs b/src/Altinn.Notifications.Core/Integrations/IRegisterClient.cs index 2ddd0c32..a13b686f 100644 --- a/src/Altinn.Notifications.Core/Integrations/IRegisterClient.cs +++ b/src/Altinn.Notifications.Core/Integrations/IRegisterClient.cs @@ -27,5 +27,5 @@ public interface IRegisterClient /// A task that represents the asynchronous operation. /// The task result contains a list of representing the details of the specified individuals and organizations. /// - Task> GetPartyDetails(List organizationNumbers, List socialSecurityNumbers); + Task> GetPartyDetails(List? organizationNumbers, List? socialSecurityNumbers); } diff --git a/src/Altinn.Notifications.Core/Services/Interfaces/IKeywordsService.cs b/src/Altinn.Notifications.Core/Services/Interfaces/IKeywordsService.cs index a6846c92..43fc7452 100644 --- a/src/Altinn.Notifications.Core/Services/Interfaces/IKeywordsService.cs +++ b/src/Altinn.Notifications.Core/Services/Interfaces/IKeywordsService.cs @@ -24,14 +24,14 @@ public interface IKeywordsService /// /// Replaces placeholder keywords in a collection of with actual values. /// - /// The collection of to process. + /// The collection of to process. /// A task that represents the asynchronous operation. The task result contains the collection of with the placeholder keywords replaced by actual values. - Task> ReplaceKeywordsAsync(IEnumerable smsRecipients); + Task> ReplaceKeywordsAsync(IEnumerable recipients); /// /// Replaces placeholder keywords in a collection of with actual values. /// - /// The collection of to process. + /// The collection of to process. /// A task that represents the asynchronous operation. The task result contains the collection of with the placeholder keywords replaced by actual values. - Task> ReplaceKeywordsAsync(IEnumerable emailRecipients); + Task> ReplaceKeywordsAsync(IEnumerable recipients); } diff --git a/src/Altinn.Notifications.Core/Services/KeywordsService.cs b/src/Altinn.Notifications.Core/Services/KeywordsService.cs index 0bfa3ac1..ceba6f49 100644 --- a/src/Altinn.Notifications.Core/Services/KeywordsService.cs +++ b/src/Altinn.Notifications.Core/Services/KeywordsService.cs @@ -33,17 +33,17 @@ public bool ContainsRecipientNumberPlaceholder(string? value) => !string.IsNullOrWhiteSpace(value) && value.Contains(_recipientNumberPlaceholder); /// - public async Task> ReplaceKeywordsAsync(IEnumerable smsRecipients) + public async Task> ReplaceKeywordsAsync(IEnumerable recipients) { - ArgumentNullException.ThrowIfNull(smsRecipients); + ArgumentNullException.ThrowIfNull(recipients); - var organizationNumbers = smsRecipients + var organizationNumbers = recipients .Where(e => !string.IsNullOrWhiteSpace(e.CustomizedBody)) .Where(e => !string.IsNullOrWhiteSpace(e.OrganizationNumber)) .Select(e => e.OrganizationNumber!) .ToList(); - var nationalIdentityNumbers = smsRecipients + var nationalIdentityNumbers = recipients .Where(e => !string.IsNullOrWhiteSpace(e.CustomizedBody)) .Where(e => !string.IsNullOrWhiteSpace(e.NationalIdentityNumber)) .Select(e => e.NationalIdentityNumber!) @@ -51,27 +51,27 @@ public async Task> ReplaceKeywordsAsync(IEnumerable - public async Task> ReplaceKeywordsAsync(IEnumerable emailRecipients) + public async Task> ReplaceKeywordsAsync(IEnumerable recipients) { - ArgumentNullException.ThrowIfNull(emailRecipients); + ArgumentNullException.ThrowIfNull(recipients); - var organizationNumbers = emailRecipients + var organizationNumbers = recipients .Where(e => !string.IsNullOrWhiteSpace(e.OrganizationNumber)) .Where(e => !string.IsNullOrWhiteSpace(e.CustomizedBody) || !string.IsNullOrWhiteSpace(e.CustomizedSubject)) .Select(e => e.OrganizationNumber!) .ToList(); - var nationalIdentityNumbers = emailRecipients + var nationalIdentityNumbers = recipients .Where(e => !string.IsNullOrWhiteSpace(e.NationalIdentityNumber)) .Where(e => !string.IsNullOrWhiteSpace(e.CustomizedBody) || !string.IsNullOrWhiteSpace(e.CustomizedSubject)) .Select(e => e.NationalIdentityNumber!) @@ -79,7 +79,7 @@ public async Task> ReplaceKeywordsAsync(IEnumerable< var (personDetails, organizationDetails) = await FetchPartyDetailsAsync(organizationNumbers, nationalIdentityNumbers); - foreach (var emailRecipient in emailRecipients) + foreach (var emailRecipient in recipients) { emailRecipient.CustomizedBody = ReplacePlaceholders(emailRecipient.CustomizedBody, emailRecipient.OrganizationNumber, emailRecipient.NationalIdentityNumber, organizationDetails, personDetails); @@ -88,7 +88,7 @@ public async Task> ReplaceKeywordsAsync(IEnumerable< ReplacePlaceholders(emailRecipient.CustomizedSubject, emailRecipient.OrganizationNumber, emailRecipient.NationalIdentityNumber, organizationDetails, personDetails); } - return emailRecipients; + return recipients; } /// @@ -102,7 +102,7 @@ public async Task> ReplaceKeywordsAsync(IEnumerable< List organizationNumbers, List nationalIdentityNumbers) { - var partyDetails = await _registerClient.GetPartyDetails(nationalIdentityNumbers, organizationNumbers); + var partyDetails = await _registerClient.GetPartyDetails(organizationNumbers, nationalIdentityNumbers); var organizationDetails = partyDetails .Where(e => !string.IsNullOrWhiteSpace(e.OrganizationNumber) && organizationNumbers.Contains(e.OrganizationNumber)) diff --git a/src/Altinn.Notifications.Integrations/Altinn.Notifications.Integrations.csproj b/src/Altinn.Notifications.Integrations/Altinn.Notifications.Integrations.csproj index 3c3af855..164bf48f 100644 --- a/src/Altinn.Notifications.Integrations/Altinn.Notifications.Integrations.csproj +++ b/src/Altinn.Notifications.Integrations/Altinn.Notifications.Integrations.csproj @@ -10,8 +10,9 @@ + - + diff --git a/src/Altinn.Notifications.Integrations/Extensions/ServiceCollectionExtensions.cs b/src/Altinn.Notifications.Integrations/Extensions/ServiceCollectionExtensions.cs index d80cd6e3..be9312aa 100644 --- a/src/Altinn.Notifications.Integrations/Extensions/ServiceCollectionExtensions.cs +++ b/src/Altinn.Notifications.Integrations/Extensions/ServiceCollectionExtensions.cs @@ -1,5 +1,6 @@ using Altinn.ApiClients.Maskinporten.Extensions; using Altinn.ApiClients.Maskinporten.Services; +using Altinn.Common.AccessTokenClient.Services; using Altinn.Common.PEP.Clients; using Altinn.Common.PEP.Implementation; using Altinn.Common.PEP.Interfaces; @@ -70,6 +71,7 @@ public static void AddAuthorizationService(this IServiceCollection services, ICo services.Configure(config.GetSection("PlatformSettings")); services.AddHttpClient(); services.AddSingleton(); + services.AddTransient(); services.AddSingleton(); services.AddMaskinportenHttpClient( @@ -77,7 +79,7 @@ public static void AddAuthorizationService(this IServiceCollection services, ICo } /// - /// Adds kafka health checks + /// Adds Kafka health checks /// /// service collection. /// the configuration collection diff --git a/src/Altinn.Notifications.Integrations/Register/RegisterClient.cs b/src/Altinn.Notifications.Integrations/Register/RegisterClient.cs index 07dd4ab2..494ee0a8 100644 --- a/src/Altinn.Notifications.Integrations/Register/RegisterClient.cs +++ b/src/Altinn.Notifications.Integrations/Register/RegisterClient.cs @@ -1,6 +1,7 @@ using System.Text; using System.Text.Json; +using Altinn.Common.AccessTokenClient.Services; using Altinn.Notifications.Core.Integrations; using Altinn.Notifications.Core.Models.ContactPoints; using Altinn.Notifications.Core.Models.Parties; @@ -13,7 +14,7 @@ namespace Altinn.Notifications.Integrations.Register; /// -/// Implementation of the to retrieve information for organizations and individuals. +/// A client implementation of for retrieving information about organizations and individuals. /// public class RegisterClient : IRegisterClient { @@ -22,15 +23,21 @@ public class RegisterClient : IRegisterClient private readonly string _contactPointLookupEndpoint = "organizations/contactpoint/lookup"; private readonly string _nameComponentsLookupEndpoint = "parties/nameslookup"; + private readonly IAccessTokenGenerator _accessTokenGenerator; + /// /// Initializes a new instance of the class. /// /// The HTTP client used to make requests to the register service. /// The platform settings containing the API endpoints. - public RegisterClient(HttpClient client, IOptions settings) + /// The access token generator. + public RegisterClient(HttpClient client, IOptions settings, IAccessTokenGenerator accessTokenGenerator) { _client = client; _client.BaseAddress = new Uri(settings.Value.ApiRegisterEndpoint); + + _accessTokenGenerator = accessTokenGenerator; + _jsonSerializerOptions = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; } @@ -62,17 +69,25 @@ public async Task> GetOrganizationContactPoints( } /// - public async Task> GetPartyDetails(List organizationNumbers, List socialSecurityNumbers) + public async Task> GetPartyDetails(List? organizationNumbers, List? socialSecurityNumbers) { if ((organizationNumbers?.Count ?? 0) == 0 && (socialSecurityNumbers?.Count ?? 0) == 0) { return []; } - var partyDetailsLookupBatch = new PartyDetailsLookupBatch(organizationNumbers, socialSecurityNumbers); - var content = CreateJsonContent(partyDetailsLookupBatch); + HttpRequestMessage requestMessage = new(HttpMethod.Post, _nameComponentsLookupEndpoint) + { + Content = CreateJsonContent(new PartyDetailsLookupBatch(organizationNumbers, socialSecurityNumbers)) + }; + + var accessToken = _accessTokenGenerator.GenerateAccessToken("platform", "notifications"); + if (!string.IsNullOrEmpty(accessToken)) + { + requestMessage.Headers.Add("PlatformAccessToken", accessToken); + } - var response = await _client.PostAsync(_nameComponentsLookupEndpoint, content); + var response = await _client.SendAsync(requestMessage, CancellationToken.None); if (!response.IsSuccessStatusCode) { @@ -80,9 +95,9 @@ public async Task> GetPartyDetails(List organizationN } var responseContent = await response.Content.ReadAsStringAsync(); - var partyDetailsList = JsonSerializer.Deserialize(responseContent, _jsonSerializerOptions)?.PartyDetailsList; - return partyDetailsList ?? []; + var deserializeResponse = JsonSerializer.Deserialize(responseContent, _jsonSerializerOptions); + return deserializeResponse?.PartyDetailsList ?? []; } /// diff --git a/test/Altinn.Notifications.IntegrationTests/Register/RegisterClientTests.cs b/test/Altinn.Notifications.IntegrationTests/Register/RegisterClientTests.cs index 9a366397..0bd83a3a 100644 --- a/test/Altinn.Notifications.IntegrationTests/Register/RegisterClientTests.cs +++ b/test/Altinn.Notifications.IntegrationTests/Register/RegisterClientTests.cs @@ -1,7 +1,9 @@ using System.Net; using System.Net.Http.Json; +using System.Text; using System.Text.Json; +using Altinn.Common.AccessTokenClient.Services; using Altinn.Notifications.Core.Models.ContactPoints; using Altinn.Notifications.Core.Models.Parties; using Altinn.Notifications.Core.Shared; @@ -11,6 +13,8 @@ using Microsoft.Extensions.Options; +using Moq; + using Xunit; namespace Altinn.Notifications.IntegrationTests.Register; @@ -26,35 +30,42 @@ public class RegisterClientTests public RegisterClientTests() { - var registerHttpMessageHandler = new DelegatingHandlerStub(async (request, token) => - { - if (request!.RequestUri!.AbsolutePath.EndsWith("contactpoint/lookup")) - { - OrgContactPointLookup? lookup = JsonSerializer.Deserialize(await request!.Content!.ReadAsStringAsync(token), _serializerOptions); - return await GetResponse(lookup!); - } - else if (request!.RequestUri!.AbsolutePath.EndsWith("nameslookup")) - { - PartyDetailsLookupBatch? lookup = JsonSerializer.Deserialize(await request!.Content!.ReadAsStringAsync(token), _serializerOptions); - return await GetPartyDetailsResponse(lookup!); - } + _registerClient = CreateRegisterClient(); + } - return new HttpResponseMessage(HttpStatusCode.NotFound); - }); + [Fact] + public async Task GetOrganizationContactPoints_WithEmptyOrganizationNumbers_ReturnsEmpty() + { + // Arrange + List organizationNumbers = []; - PlatformSettings settings = new() - { - ApiRegisterEndpoint = "https://dummy.endpoint/register/api/v1/" - }; + // Act + var result = await _registerClient.GetOrganizationContactPoints(organizationNumbers); - _registerClient = new RegisterClient(new HttpClient(registerHttpMessageHandler), Options.Create(settings)); + // Assert + Assert.Empty(result); + Assert.NotNull(result); } [Fact] - public async Task GetOrganizationContactPoints_WithEmptyList_ReturnsEmpty() + public async Task GetOrganizationContactPoints_WithNullResponseContent_ReturnsEmpty() { + // Arrange + var registerClient = CreateRegisterClient(new DelegatingHandlerStub((request, token) => + { + if (request!.RequestUri!.AbsolutePath.EndsWith("contactpoint/lookup")) + { + return Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) + { + Content = new StringContent("null", Encoding.UTF8, "application/json") + }); + } + + return Task.FromResult(new HttpResponseMessage(HttpStatusCode.NotFound)); + })); + // Act - List actual = await _registerClient.GetOrganizationContactPoints(["empty-list"]); + List actual = await registerClient.GetOrganizationContactPoints(["test-org"]); // Assert Assert.Empty(actual); @@ -68,7 +79,7 @@ public async Task GetOrganizationContactPoints_WithPopulatedList_ReturnsExpected // Assert Assert.Equal(2, actual.Count); - Assert.Contains("910011154", actual.Select(cp => cp.OrganizationNumber)); + Assert.Contains("910011154", actual.Select(e => e.OrganizationNumber)); } [Fact] @@ -77,22 +88,38 @@ public async Task GetOrganizationContactPoints_WithUnavailableEndpoint_ThrowsExc // Act var exception = await Assert.ThrowsAsync(async () => await _registerClient.GetOrganizationContactPoints(["unavailable"])); + // Assert Assert.StartsWith("503 - Service Unavailable", exception.Message); Assert.Equal(HttpStatusCode.ServiceUnavailable, exception.Response?.StatusCode); } [Fact] - public async Task GetOrganizationContactPoints_WithEmptyOrganizationNumbers_ReturnsEmpty() + public async Task GetPartyDetails_WithEmptyJSONArrayResponse_ReturnsEmpty() { // Arrange - List organizationNumbers = []; + var registerClient = CreateRegisterClient(new DelegatingHandlerStub((request, token) => + { + if (request!.RequestUri!.AbsolutePath.EndsWith("nameslookup")) + { + var responseContent = new PartyDetailsLookupResult + { + PartyDetailsList = [] + }; + + return Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) + { + Content = new StringContent(JsonSerializer.Serialize(responseContent), Encoding.UTF8, "application/json") + }); + } + + return Task.FromResult(new HttpResponseMessage(HttpStatusCode.NotFound)); + })); // Act - var result = await _registerClient.GetOrganizationContactPoints(organizationNumbers); + List actual = await registerClient.GetPartyDetails(["test-org"], ["test-ssn"]); // Assert - Assert.Empty(result); - Assert.NotNull(result); + Assert.Empty(actual); } [Fact] @@ -105,15 +132,78 @@ public async Task GetPartyDetails_WithEmptyList_ReturnsEmpty() Assert.Empty(actual); } + [Fact] + public async Task GetPartyDetails_WithEmptyOrganizationNumbersAndNullSocialSecurityNumbers_ReturnsEmpty() + { + // Act + List actual = await _registerClient.GetPartyDetails([], null); + + // Assert + Assert.Empty(actual); + } + + [Fact] + public async Task GetPartyDetails_WithNullDeserializedResponse_ReturnsEmpty() + { + // Arrange + var registerClient = CreateRegisterClient(new DelegatingHandlerStub((request, token) => + { + if (request!.RequestUri!.AbsolutePath.EndsWith("nameslookup")) + { + return Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) + { + Content = new StringContent("{}", Encoding.UTF8, "application/json") + }); + } + + return Task.FromResult(new HttpResponseMessage(HttpStatusCode.NotFound)); + })); + + // Act + List actual = await registerClient.GetPartyDetails(["test-org"], ["test-ssn"]); + + // Assert + Assert.Empty(actual); + } + + [Fact] + public async Task GetPartyDetails_WithNullOrganizationNumbersAndEmptySocialSecurityNumbers_ReturnsEmpty() + { + // Act + List actual = await _registerClient.GetPartyDetails(null, []); + + // Assert + Assert.Empty(actual); + } + [Fact] public async Task GetPartyDetails_WithPopulatedList_ReturnsExpectedData() { + // Arrange + var organizationNumbers = new List { "populated-list" }; + var socialSecurityNumbers = new List { "populated-list" }; + // Act - List actual = await _registerClient.GetPartyDetails(["populated-list"], ["populated-list"]); + List actual = await _registerClient.GetPartyDetails(organizationNumbers, socialSecurityNumbers); // Assert - Assert.Equal(2, actual.Count); - Assert.Contains("313600947", actual.Select(pd => pd.OrganizationNumber)); + Assert.Equal(4, actual.Count); + + var firstOrganization = actual.FirstOrDefault(e => e.OrganizationNumber == "313600947"); + Assert.NotNull(firstOrganization); + Assert.Equal("Test Organization 1", firstOrganization.Name); + + var secondOrganization = actual.FirstOrDefault(e => e.OrganizationNumber == "315058384"); + Assert.NotNull(secondOrganization); + Assert.Equal("Test Organization 2", secondOrganization.Name); + + var firstPerson = actual.FirstOrDefault(e => e.NationalIdentityNumber == "07837399275"); + Assert.NotNull(firstPerson); + Assert.Equal("Test Person 1", firstPerson.Name); + + var secondPerson = actual.FirstOrDefault(e => e.NationalIdentityNumber == "04917199103"); + Assert.NotNull(secondPerson); + Assert.Equal("Test Person 2", secondPerson.Name); } [Fact] @@ -122,10 +212,71 @@ public async Task GetPartyDetails_WithUnavailableEndpoint_ThrowsException() // Act var exception = await Assert.ThrowsAsync(async () => await _registerClient.GetPartyDetails(["unavailable"], ["unavailable"])); + // Assert Assert.StartsWith("503 - Service Unavailable", exception.Message); Assert.Equal(HttpStatusCode.ServiceUnavailable, exception.Response?.StatusCode); } + [Fact] + public async Task GetPartyDetails_WithValidAccessToken_AddsHeader() + { + // Arrange + var registerClient = CreateRegisterClient(new DelegatingHandlerStub((request, token) => + { + if (request!.RequestUri!.AbsolutePath.EndsWith("nameslookup")) + { + var response = new HttpResponseMessage(HttpStatusCode.OK) + { + Content = new StringContent(JsonSerializer.Serialize(new PartyDetailsLookupResult { PartyDetailsList = [] }), Encoding.UTF8, "application/json") + }; + + // Assert that the PlatformAccessToken header is present + Assert.True(request.Headers.Contains("PlatformAccessToken")); + Assert.Equal("valid-token", request.Headers.GetValues("PlatformAccessToken").First()); + + return Task.FromResult(response); + } + + return Task.FromResult(new HttpResponseMessage(HttpStatusCode.NotFound)); + })); + + // Act + List actual = await registerClient.GetPartyDetails(["test-org"], ["test-ssn"]); + + // Assert + Assert.NotNull(actual); + Assert.Empty(actual); + } + + private RegisterClient CreateRegisterClient(DelegatingHandler? handler = null, string accessToken = "valid-token") + { + var registerHttpMessageHandler = handler ?? new DelegatingHandlerStub(async (request, token) => + { + if (request!.RequestUri!.AbsolutePath.EndsWith("contactpoint/lookup")) + { + OrgContactPointLookup? lookup = JsonSerializer.Deserialize(await request!.Content!.ReadAsStringAsync(token), _serializerOptions); + return await GetResponse(lookup!); + } + else if (request!.RequestUri!.AbsolutePath.EndsWith("nameslookup")) + { + PartyDetailsLookupBatch? lookup = JsonSerializer.Deserialize(await request!.Content!.ReadAsStringAsync(token), _serializerOptions); + return await GetPartyDetailsResponse(lookup!); + } + + return new HttpResponseMessage(HttpStatusCode.NotFound); + }); + + PlatformSettings settings = new() + { + ApiRegisterEndpoint = "https://dummy.endpoint/register/api/v1/" + }; + + Mock accessTokenGenerator = new(); + accessTokenGenerator.Setup(e => e.GenerateAccessToken(It.IsAny(), It.IsAny())).Returns(accessToken); + + return new RegisterClient(new HttpClient(registerHttpMessageHandler), Options.Create(settings), accessTokenGenerator.Object); + } + private Task CreateMockResponse(object? contentData, HttpStatusCode statusCode) { JsonContent? content = (contentData != null) ? JsonContent.Create(contentData, options: _serializerOptions) : null; @@ -137,6 +288,70 @@ private Task CreateMockResponse(object? contentData, HttpSt }); } + private Task GetPartyDetailsResponse(PartyDetailsLookupBatch lookup) + { + var contentData = new PartyDetailsLookupResult { PartyDetailsList = [] }; + + if (lookup == null) + { + return CreateMockResponse(contentData, HttpStatusCode.BadRequest); + } + + HttpStatusCode statusCode = HttpStatusCode.OK; + + if (lookup.PartyDetailsLookupRequestList == null) + { + return CreateMockResponse(contentData, statusCode); + } + + foreach (var lookupRequest in lookup.PartyDetailsLookupRequestList) + { + if (!string.IsNullOrWhiteSpace(lookupRequest.OrganizationNumber)) + { + switch (lookupRequest.OrganizationNumber) + { + case "empty-list": + break; + + case "populated-list": + contentData.PartyDetailsList.AddRange( + [ + new() { OrganizationNumber = "313600947", Name = "Test Organization 1" }, + new() { OrganizationNumber = "315058384", Name = "Test Organization 2" } + ]); + break; + + case "unavailable": + statusCode = HttpStatusCode.ServiceUnavailable; + break; + } + } + + if (!string.IsNullOrWhiteSpace(lookupRequest.SocialSecurityNumber)) + { + switch (lookupRequest.SocialSecurityNumber) + { + case "empty-list": + break; + + case "populated-list": + contentData.PartyDetailsList.AddRange( + [ + new() { NationalIdentityNumber = "07837399275", Name = "Test Person 1" }, + new() { NationalIdentityNumber = "04917199103", Name = "Test Person 2" } + ]); + break; + + case "unavailable": + statusCode = HttpStatusCode.ServiceUnavailable; + break; + } + } + } + + return CreateMockResponse(contentData, statusCode); + } + private Task GetResponse(OrgContactPointLookup lookup) { object? contentData = null; @@ -166,67 +381,4 @@ private Task GetResponse(OrgContactPointLookup lookup) return CreateMockResponse(contentData, statusCode); } - - private Task GetPartyDetailsResponse(PartyDetailsLookupBatch lookup) - { - object? contentData = null; - HttpStatusCode statusCode = HttpStatusCode.OK; - - var firstRequest = lookup.PartyDetailsLookupRequestList?.FirstOrDefault(); - if (firstRequest == null) - { - return CreateMockResponse(contentData, statusCode); - } - - if (!string.IsNullOrWhiteSpace(firstRequest.OrganizationNumber)) - { - switch (firstRequest.OrganizationNumber) - { - case "empty-list": - contentData = new PartyDetailsLookupResult() { PartyDetailsList = [] }; - break; - - case "populated-list": - contentData = new PartyDetailsLookupResult - { - PartyDetailsList = - [ - new() { OrganizationNumber = "313600947", Name = "Test Organization 1" }, - new() { OrganizationNumber = "315058384", Name = "Test Organization 2" } - ] - }; - break; - - case "unavailable": - statusCode = HttpStatusCode.ServiceUnavailable; - break; - } - } - else if (!string.IsNullOrWhiteSpace(firstRequest.SocialSecurityNumber)) - { - switch (firstRequest.SocialSecurityNumber) - { - case "empty-list": - contentData = new PartyDetailsLookupResult() { PartyDetailsList = [] }; - break; - - case "populated-list": - contentData = new PartyDetailsLookupResult - { - PartyDetailsList = - [ - new() { NationalIdentityNumber = "07837399275", Name = "Test Person 1" }, - new() { NationalIdentityNumber = "04917199103", Name = "Test Person 2" } - ] - }; - break; - - case "unavailable": - statusCode = HttpStatusCode.ServiceUnavailable; - break; - } - } - - return CreateMockResponse(contentData, statusCode); - } }