using e_suite.API.Common.exceptions;
using eSuite.Core.Miscellaneous;
using NUnit.Framework;
using UserManager.UnitTests.Helpers;

namespace UserManager.UnitTests.UserManager;

[TestFixture]
public class GetUserAsyncUnitTests : UserManagerTestBase<object>
{
    [SetUp]
    public override async Task Setup()
    {
        await base.Setup();
    }

    [Test]
    public void GetUserAsync_WhenUserDoesNotExist_ReturnsNotFoundError()
    {
        // Arrange
        var userId = new GeneralIdRef { Id = 1000000 };

        // Assert
        Assert.ThrowsAsync<NotFoundException>(async () =>
        {
            // Act
            var result = await UserManager.GetUserAsync(userId, default);
        });
    }

    [Test]
    public async Task GetUserAsync_WhenUserExists_ReturnsUser()
    {
        // Arrange
        var userId = new GeneralIdRef { Id = -1 };

        // Act
        var result = await UserManager.GetUserAsync(userId, default);

        // Assert
        Assert.That(result, Is.Not.Null);
        Assert.That(result!.Guid, Is.EqualTo(new Guid("{EA6A2EB2-ADBF-47A1-8FA6-EF363D0750DC}")));
        Assert.That(result!.FirstName, Is.EqualTo("Audit"));
        Assert.That(result!.LastName, Is.EqualTo("Tester"));
        Assert.That(result!.MiddleNames, Is.EqualTo(""));
        Assert.That(result!.DisplayName, Is.EqualTo("Audit Tester"));
        Assert.That(result!.Email, Is.EqualTo("audit@test.test"));
        Assert.That(result!.Created, Is.EqualTo(new DateTimeOffset(2023, 7, 24, 13, 45, 24, TimeSpan.Zero)));
        Assert.That(result!.LastUpdated, Is.EqualTo(new DateTimeOffset(2023, 7, 24, 13, 45, 25, TimeSpan.Zero)));
        Assert.That(result!.Domain.Id, Is.EqualTo(1));
        Assert.That(result!.Domain.Guid, Is.EqualTo(new Guid("E5B6C043-C2EB-46CC-9387-E5F45420C93F")));
        Assert.That(result!.DomainName, Is.EqualTo("Default Test domain"));
        Assert.That(result!.EmailConfirmed, Is.True);
    }
}