using e_suite.API.Common.models;
using e_suite.Utilities.Pagination;
using eSuite.Core.Miscellaneous;
using Microsoft.AspNetCore.Mvc;
using Moq;
using NUnit.Framework;

namespace eSuite.API.UnitTests.Controllers.RoleControllerUnitTests;

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

    [Test]
    public async Task GetRoleUsers_WhenCalled_ReturnsPagedData()
    {
        //Arrange
        var domains = new List<RoleUser>
        {
            new()
            {
                Guid = new Guid("914d36c6-0572-4e48-9c85-639b4d1cd8c8"),
                Id = 6574,
                DisplayName = "TestyMcTester"
            }
        };

        var paginatedData = new PaginatedData<RoleUser>
        {
            Count = domains.Count,
            Data = domains,
            Page = 1,
            PageSize = 10
        };

        var cancellationToken = CancellationToken.None;

        var paging = new Paging();

        var generalIdRef = new GeneralIdRef();

        _roleManagerMock.Setup(x => x.GetRoleUsers(paging, generalIdRef, cancellationToken)).ReturnsAsync(paginatedData);

        //Act
        var actualResult = await _roleController.GetRoleUsers(paging, generalIdRef, cancellationToken);

        //Assert
        Assert.That(actualResult.GetType(), Is.EqualTo(typeof(OkObjectResult)));
        var objectResult = actualResult as OkObjectResult;

        Assert.That(objectResult?.StatusCode, Is.EqualTo(200));
        Assert.That(objectResult?.Value, Is.Not.Null);
        Assert.That(objectResult!.Value!.GetType, Is.EqualTo(typeof(PaginatedData<RoleUser>)));
    }
}