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

namespace eSuite.API.UnitTests.SingleSignOn.CookieManager;

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

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

        cookies.Append("eSuiteSsoProvider", "12345", new CookieOptions
        {
        });

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

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

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

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

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

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

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