Skip to content

Commit

Permalink
Implement two unit tests to validate the functionality of the user co…
Browse files Browse the repository at this point in the history
…ntact details retrieval use case.
  • Loading branch information
Ahmed-Ghanam committed Oct 8, 2024
1 parent 3723e74 commit 643d984
Showing 1 changed file with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<IPersonService> _mockRegisterService;
private readonly UserContactDetailsRetriever _retriever;

public UserContactDetailsRetrieverTests()
{
_mockRegisterService = new Mock<IPersonService>();
_retriever = new UserContactDetailsRetriever(_mockRegisterService.Object);
}

[Fact]
public async Task RetrieveAsync_ThrowsArgumentNullException_WhenLookupCriteriaIsNull()
{
// Act & Assert
await Assert.ThrowsAsync<ArgumentNullException>(() => _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<string> { "08119043698" }
};

_mockRegisterService.Setup(s => s.GetUserContactAsync(lookupCriteria.NationalIdentityNumbers)).ReturnsAsync(false);

// Act
var result = await _retriever.RetrieveAsync(lookupCriteria);

// Assert
Assert.False(result.IsSuccess);
}
}

0 comments on commit 643d984

Please sign in to comment.