using Microsoft.AspNetCore.Http;
using Moq;
using NUnit.Framework;

namespace eSuite.API.UnitTests.SingleSignOn.CookieManager;

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

    [Test]
    public async Task DeleteLinkCookie_WhenCalledAndCookiePresent_RemovesCookieFromResponse()
    {
        //Arrange
        var cookies = new FakeResponseCookies();

        cookies.Append("eSuiteProfileLinkCookie", "Guid", new CookieOptions
        {
        });

        var httpResponseMock = new Mock<HttpResponse>();
        httpResponseMock.SetupGet(x => x.Cookies).Returns(cookies);

        //Act
        await _cookieManager.DeleteLinkCookie(httpResponseMock.Object);

        //Assert
        Assert.That(cookies.CookieDictionary.ContainsKey("eSuiteProfileLinkCookie"), Is.False);
    }

    [Test]
    public async Task DeleteLinkCookie_WhenCalledAndCookieNotPresent_DoesNothingGraceFully()
    {
        //Arrange
        var cookies = new FakeResponseCookies();

        var httpResponseMock = new Mock<HttpResponse>();
        httpResponseMock.SetupGet(x => x.Cookies).Returns(cookies);

        //Act
        await _cookieManager.DeleteLinkCookie(httpResponseMock.Object);

        //Assert
        Assert.That(cookies.CookieDictionary.ContainsKey("eSuiteProfileLinkCookie"), Is.False);
    }
}