using NATS.Server.WebSocket;
using Shouldly;

namespace NATS.Server.Tests.WebSocket;

public class WsConstantsTests
{
    [Fact]
    public void OpCodes_MatchRfc6455()
    {
        WsConstants.TextMessage.ShouldBe(1);
        WsConstants.BinaryMessage.ShouldBe(2);
        WsConstants.CloseMessage.ShouldBe(8);
        WsConstants.PingMessage.ShouldBe(9);
        WsConstants.PongMessage.ShouldBe(10);
    }

    [Fact]
    public void FrameBits_MatchRfc6455()
    {
        WsConstants.FinalBit.ShouldBe((byte)0x80);
        WsConstants.Rsv1Bit.ShouldBe((byte)0x40);
        WsConstants.MaskBit.ShouldBe((byte)0x80);
    }

    [Fact]
    public void CloseStatusCodes_MatchRfc6455()
    {
        WsConstants.CloseStatusNormalClosure.ShouldBe(1000);
        WsConstants.CloseStatusGoingAway.ShouldBe(1001);
        WsConstants.CloseStatusProtocolError.ShouldBe(1002);
        WsConstants.CloseStatusPolicyViolation.ShouldBe(1008);
        WsConstants.CloseStatusMessageTooBig.ShouldBe(1009);
    }

    [Theory]
    [InlineData(WsConstants.CloseMessage)]
    [InlineData(WsConstants.PingMessage)]
    [InlineData(WsConstants.PongMessage)]
    public void IsControlFrame_True(int opcode)
    {
        WsConstants.IsControlFrame(opcode).ShouldBeTrue();
    }

    [Theory]
    [InlineData(WsConstants.TextMessage)]
    [InlineData(WsConstants.BinaryMessage)]
    [InlineData(0)]
    public void IsControlFrame_False(int opcode)
    {
        WsConstants.IsControlFrame(opcode).ShouldBeFalse();
    }
}
