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

namespace eSuite.API.UnitTests.Controllers.SequenceManagerControllerUnitTests;

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

    [Test]
    public void GetSequence_SequenceNotFound_ReturnsNotFoundResult()
    {
        //Arrange
        var generalIdRef = new GeneralIdRef();

        _sequenceManagerMock.Setup(x => x.GetSequence(It.IsAny<GeneralIdRef>(), It.IsAny<CancellationToken>()))
            .Throws(new NotFoundException());

        //Assert
        Assert.ThrowsAsync<NotFoundException>(async () =>
        {
            //Act
            var actualResult = await _sequenceController.GetSequence(generalIdRef.Id, generalIdRef.Guid);
        });
    }


    [Test]
    public async Task GetSequence_SequenceFound_ReturnsOk()
    {
        //Arrange
        var generalIdRef = new GeneralIdRef();

        var expectedResult = new Sequence();

        _sequenceManagerMock.Setup(x => x.GetSequence(It.IsAny<GeneralIdRef>(), It.IsAny<CancellationToken>())).ReturnsAsync(expectedResult);

        //Act
        var actualResult = await _sequenceController.GetSequence(generalIdRef.Id, generalIdRef.Guid);

        //Assert
        var objectResult = actualResult as OkObjectResult;

        Assert.That(objectResult?.StatusCode, Is.EqualTo(200));
        Assert.That(objectResult?.Value, Is.EqualTo(expectedResult));
    }
}