using e_suite.Database.Core.Tables.Domain;
using e_suite.Modules.RoleManager.UnitTests.Helpers;
using e_suite.Utilities.Pagination;
using eSuite.Core.Miscellaneous;
using NUnit.Framework;

namespace e_suite.Modules.RoleManager.UnitTests;

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

    [Test]
    public async Task GetRoles_WhenCalled_ReturnsExpectedResult()
    {
        //Arrange
        var paging = new Paging();

        var domain = new Domain
        {
            Guid = new Guid("07dd1c69-dfe7-4add-8514-a624d5c744a5"),
            Name = "Testing domain"
        };
        DomainRepository.Domains.Add(domain);

        var role = new Role
        {
            Guid = new Guid("7f986bbb-d873-42a1-aca2-7f6df6d0f26c"),
            Domain = domain,
            DomainId = domain.Id,
            Name = "Administrator",
            IsAdministrator = true,
            IsSuperUser = false
        };
        RoleManagerRepository.Roles.Add(role);

        var domainGeneralIdRef = new GeneralIdRef
        {
            Guid = domain.Guid
        };
        
        //Act
        var result = await RoleManager.GetRoles(paging, domainGeneralIdRef, CancellationToken.None);

        //Assert
        Assert.That(result, Is.Not.Null);
        Assert.That(result.Count, Is.EqualTo(1));
        Assert.That(result.Data.Count(), Is.EqualTo(1));

        var firstRole = result.Data.First();
        Assert.That(firstRole.Guid, Is.EqualTo(role.Guid));
        Assert.That(firstRole.Id, Is.EqualTo(role.Id));
        Assert.That(firstRole.Name, Is.EqualTo(role.Name));
    }
}