diff --git a/test/Altinn.Profile.Tests/Profile.Integrations/UserContactDetailsRetrieverTests.cs b/test/Altinn.Profile.Tests/Profile.Integrations/UserContactDetailsRetrieverTests.cs new file mode 100644 index 0000000..218e116 --- /dev/null +++ b/test/Altinn.Profile.Tests/Profile.Integrations/UserContactDetailsRetrieverTests.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Threading.Tasks; + +using Altinn.Profile.Core; +using Altinn.Profile.Integrations.Entities; +using Altinn.Profile.Integrations.Services; +using Altinn.Profile.Models; +using Altinn.Profile.UseCases; + +using Moq; + +using Xunit; + +namespace Altinn.Profile.Tests.Profile.Integrations; + +public class UserContactDetailsRetrieverTests +{ + private readonly Mock _mockRegisterService; + private readonly UserContactDetailsRetriever _retriever; + + public UserContactDetailsRetrieverTests() + { + _mockRegisterService = new Mock(); + _retriever = new UserContactDetailsRetriever(_mockRegisterService.Object); + } + + [Fact] + public async Task RetrieveAsync_ThrowsArgumentNullException_WhenLookupCriteriaIsNull() + { + // Act & Assert + await Assert.ThrowsAsync(() => _retriever.RetrieveAsync(null)); + } + + [Fact] + public async Task RetrieveAsync_ReturnsFalse_WhenNationalIdentityNumbersIsEmpty() + { + // Arrange + var lookupCriteria = new UserContactPointLookup { NationalIdentityNumbers = [] }; + + // Act + var result = await _retriever.RetrieveAsync(lookupCriteria); + + // Assert + Assert.False(result.IsSuccess); + } + + [Fact] + public async Task RetrieveAsync_ReturnsFalse_WhenNoContactDetailsFound() + { + // Arrange + var lookupCriteria = new UserContactPointLookup + { + NationalIdentityNumbers = new List { "08119043698" } + }; + + _mockRegisterService.Setup(s => s.GetUserContactAsync(lookupCriteria.NationalIdentityNumbers)).ReturnsAsync(false); + + // Act + var result = await _retriever.RetrieveAsync(lookupCriteria); + + // Assert + Assert.False(result.IsSuccess); + } +}