using System.Reflection;
using Microsoft.AspNetCore.Http;

namespace RpgRoller.Tests;

public sealed class BackendCoverageTests
{
    [Fact]
    public void GetRequiredSessionToken_ThrowsWhenTokenWasNotStored()
    {
        var extensionsType = typeof(Program).Assembly.GetType("RpgRoller.Api.SessionTokenHttpContextExtensions");
        Assert.NotNull(extensionsType);

        var method = extensionsType.GetMethod("GetRequiredSessionToken", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
        Assert.NotNull(method);

        var context = new DefaultHttpContext();
        var exception = Assert.Throws<TargetInvocationException>(() => method.Invoke(null, [context]));
        Assert.IsType<InvalidOperationException>(exception.InnerException);
    }
}