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

namespace eSuite.API.UnitTests.Controllers.GlossariesManagerControllerUnitTests;

[TestFixture]
public class GetUnitTests : GlossariesManagerControllerTestBase
{
    [SetUp]
    public override async Task Setup()
    {
        await base.Setup();

        const long id = -1;
        const string email = "email@mail.test";
        const string displayName = "Testy McTester";

        AddAuthorisedUserToController(id, email, displayName);
    }

    [Test]
    public async Task Get_WhenCalled_ReturnsOKResultWithData()
    {
        //Arrange
        var generalIdRef = new GeneralIdRef
        {
            Guid = new Guid("f6bfa906-a4f6-41a0-bbad-06b77af8ac50")
        };

        var cancellationToken = CancellationToken.None;

        var glossaryItem = new GlossaryItem();
        _glossariesManagerMock.Setup(x => x.GetGlossaryItem(It.IsAny<AuditUserDetails>(), generalIdRef, cancellationToken)).ReturnsAsync(glossaryItem);

        //Act
        var actualResult = await _glossariesController.Get(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.EqualTo(glossaryItem));
    }
}