using e_suite.API.Common.exceptions;
using e_suite.Database.Core.Models;
using Microsoft.AspNetCore.Mvc;
using Moq;
using NUnit.Framework;

namespace eSuite.API.UnitTests.Controllers.UserManagerControllerUnitTests;

[TestFixture]
public class CurrentEmailUserActionUrlUnitTests : UserManagerControllerTestBase
{
    [SetUp]
    public override async Task Setup()
    {
        await base.Setup();
    }

    [Test]
    public void CurrentEmailUserActionUrl_UserIsNull_ThrowsArgumentNullException()
    {
        //Arrange
        string email = null!;
        var emailUserActionType = EmailUserActionType.ConfirmEmailAddress;

        _userManagerMock
            .Setup(x => x.GetCurrentEmailActionUrl(It.IsAny<string>(), It.IsAny<EmailUserActionType>(),
                It.IsAny<CancellationToken>())).Throws<NotFoundException>();

        //Assert
        Assert.ThrowsAsync<NotFoundException>(async () =>
        {
            //Act
            var actualResult = await _userManagerController.CurrentEmailUserActionUrl(email, emailUserActionType, CancellationToken.None);
        });
    }

    [Test]
    public async Task CurrentEmailUserActionUrl_Found_ReturnsUrl()
    {
        //Arrange
        const string email = "test@test.test";
        const EmailUserActionType emailUserActionType = EmailUserActionType.ConfirmEmailAddress;
        
        const string okResult = "OKResult";

        _userManagerMock
            .Setup(x => x.GetCurrentEmailActionUrl(email, emailUserActionType,
                It.IsAny<CancellationToken>())).ReturnsAsync(okResult);

        //Act
        var actualResult = await _userManagerController.CurrentEmailUserActionUrl(email, emailUserActionType, CancellationToken.None);

        //Assert
        Assert.That(actualResult, Is.TypeOf(typeof(OkObjectResult)));
        Assert.That(((OkObjectResult)actualResult).Value, Is.EqualTo(okResult));
    }
}