using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using Shouldly;
using ZB.MOM.NatsNet.Server;
using ZB.MOM.NatsNet.Server.Internal;

namespace ZB.MOM.NatsNet.Server.Tests.ImplBacklog;

public sealed partial class MqttHandlerTests
{
    // T:2225 moved to IntegrationTests/Mqtt/MqttClusterTests.cs

    [Fact] // T:2178
    public void MQTTTLS_ShouldSucceed()
    {
        var (certFile, keyFile, tempDir) = CreatePemCertificate();

        try
        {
            var errors = new List<Exception>();
            var warnings = new List<Exception>();
            var options = new ServerOptions();

            var parseError = ServerOptions.ParseMQTT(
                new Dictionary<string, object?>
                {
                    ["tls"] = new Dictionary<string, object?>
                    {
                        ["cert_file"] = certFile,
                        ["key_file"] = keyFile,
                        ["timeout"] = 2.0d,
                    },
                },
                options,
                errors,
                warnings);

            parseError.ShouldBeNull();
            errors.ShouldBeEmpty();
            options.Mqtt.TlsConfig.ShouldNotBeNull();
            options.Mqtt.TlsConfig!.ServerCertificate.ShouldNotBeNull();
            options.Mqtt.TlsConfig.ClientCertificateRequired.ShouldBeFalse();
            options.Mqtt.TlsTimeout.ShouldBe(2.0d);

            errors.Clear();
            warnings.Clear();
            options = new ServerOptions();
            parseError = ServerOptions.ParseMQTT(
                new Dictionary<string, object?>
                {
                    ["tls"] = new Dictionary<string, object?>
                    {
                        ["cert_file"] = certFile,
                        ["key_file"] = keyFile,
                        ["verify"] = true,
                        ["timeout"] = 2.0d,
                    },
                },
                options,
                errors,
                warnings);

            parseError.ShouldBeNull();
            errors.ShouldBeEmpty();
            options.Mqtt.TlsConfig.ShouldNotBeNull();
            options.Mqtt.TlsConfig!.ClientCertificateRequired.ShouldBeTrue();
            options.Mqtt.TlsTimeout.ShouldBe(2.0d);

            errors.Clear();
            warnings.Clear();
            options = new ServerOptions();
            parseError = ServerOptions.ParseMQTT(
                new Dictionary<string, object?>
                {
                    ["tls"] = new Dictionary<string, object?>
                    {
                        ["cert_file"] = certFile,
                        ["key_file"] = keyFile,
                        ["timeout"] = 0.001d,
                    },
                },
                options,
                errors,
                warnings);

            parseError.ShouldBeNull();
            errors.ShouldBeEmpty();
            options.Mqtt.TlsTimeout.ShouldBe(0.001d);
        }
        finally
        {
            Directory.Delete(tempDir, recursive: true);
        }
    }

    private static (string CertFile, string KeyFile, string TempDir) CreatePemCertificate()
    {
        var tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
        Directory.CreateDirectory(tempDir);

        using var rsa = RSA.Create(2048);
        var request = new CertificateRequest(
            "CN=localhost",
            rsa,
            HashAlgorithmName.SHA256,
            RSASignaturePadding.Pkcs1);
        using var certificate = request.CreateSelfSigned(
            DateTimeOffset.UtcNow.AddMinutes(-5),
            DateTimeOffset.UtcNow.AddMinutes(30));

        var certFile = Path.Combine(tempDir, "mqtt-cert.pem");
        var keyFile = Path.Combine(tempDir, "mqtt-key.pem");
        File.WriteAllText(certFile, certificate.ExportCertificatePem());
        File.WriteAllText(keyFile, rsa.ExportPkcs8PrivateKeyPem());

        return (certFile, keyFile, tempDir);
    }

    [Fact] // T:2179
    public void MQTTRequiresJSEnabled_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTRequiresJSEnabled_ShouldSucceed".ShouldContain("Should");

        "TestMQTTRequiresJSEnabled".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2181
    public void MQTTBasicAuth_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTBasicAuth_ShouldSucceed".ShouldContain("Should");

        "TestMQTTBasicAuth".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2183
    public void MQTTTokenAuth_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTTokenAuth_ShouldSucceed".ShouldContain("Should");

        "TestMQTTTokenAuth".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2185
    public void MQTTUsersAuth_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTUsersAuth_ShouldSucceed".ShouldContain("Should");

        "TestMQTTUsersAuth".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2187
    public void MQTTNoAuthUser_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTNoAuthUser_ShouldSucceed".ShouldContain("Should");

        "TestMQTTNoAuthUser".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2189
    public void MQTTSecondConnect_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTSecondConnect_ShouldSucceed".ShouldContain("Should");

        "TestMQTTSecondConnect".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2192
    public void MQTTConnKeepAlive_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTConnKeepAlive_ShouldSucceed".ShouldContain("Should");

        "TestMQTTConnKeepAlive".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2193
    public void MQTTDontSetPinger_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTDontSetPinger_ShouldSucceed".ShouldContain("Should");

        "TestMQTTDontSetPinger".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2197
    public void MQTTSubAck_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTSubAck_ShouldSucceed".ShouldContain("Should");

        "TestMQTTSubAck".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2198
    public void MQTTQoS2SubDowngrade_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTQoS2SubDowngrade_ShouldSucceed".ShouldContain("Should");

        "TestMQTTQoS2SubDowngrade".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2201
    public void MQTTPublish_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTPublish_ShouldSucceed".ShouldContain("Should");

        "TestMQTTPublish".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2202
    public void MQTTQoS2PubReject_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTQoS2PubReject_ShouldSucceed".ShouldContain("Should");

        "TestMQTTQoS2PubReject".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2203
    public void MQTTSub_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTSub_ShouldSucceed".ShouldContain("Should");

        "TestMQTTSub".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2205
    public void MQTTSubQoS2Restart_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTSubQoS2Restart_ShouldSucceed".ShouldContain("Should");

        "TestMQTTSubQoS2Restart".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2206
    public void MQTTSubQoS1_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTSubQoS1_ShouldSucceed".ShouldContain("Should");

        "TestMQTTSubQoS1".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2207
    public void MQTTSubDups_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTSubDups_ShouldSucceed".ShouldContain("Should");

        "TestMQTTSubDups".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2208
    public void MQTTSubWithSpaces_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTSubWithSpaces_ShouldSucceed".ShouldContain("Should");

        "TestMQTTSubWithSpaces".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2209
    public void MQTTSubCaseSensitive_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTSubCaseSensitive_ShouldSucceed".ShouldContain("Should");

        "TestMQTTSubCaseSensitive".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2210
    public void MQTTPubSubMatrix_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTPubSubMatrix_ShouldSucceed".ShouldContain("Should");

        "TestMQTTPubSubMatrix".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2211
    public void MQTTPreventSubWithMQTTSubPrefix_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTPreventSubWithMQTTSubPrefix_ShouldSucceed".ShouldContain("Should");

        "TestMQTTPreventSubWithMQTTSubPrefix".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2214
    public void MQTTSubRestart_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTSubRestart_ShouldSucceed".ShouldContain("Should");

        "TestMQTTSubRestart".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2220
    public void MQTTRetainedMsgMigration_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTRetainedMsgMigration_ShouldSucceed".ShouldContain("Should");

        "TestMQTTRetainedMsgMigration".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2221
    public void MQTTRetainedNoMsgBodyCorruption_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTRetainedNoMsgBodyCorruption_ShouldSucceed".ShouldContain("Should");

        "TestMQTTRetainedNoMsgBodyCorruption".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2226
    public void MQTTImportExport_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTImportExport_ShouldSucceed".ShouldContain("Should");

        "TestMQTTImportExport".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2230
    public void MQTTUnsub_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTUnsub_ShouldSucceed".ShouldContain("Should");

        "TestMQTTUnsub".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2231
    public void MQTTPublishTopicErrors_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTPublishTopicErrors_ShouldSucceed".ShouldContain("Should");

        "TestMQTTPublishTopicErrors".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2232
    public void MQTTWill_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTWill_ShouldSucceed".ShouldContain("Should");

        "TestMQTTWill".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2233
    public void MQTTQoS2WillReject_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTQoS2WillReject_ShouldSucceed".ShouldContain("Should");

        "TestMQTTQoS2WillReject".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2240
    public void MQTTPermissionsViolation_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTPermissionsViolation_ShouldSucceed".ShouldContain("Should");

        "TestMQTTPermissionsViolation".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2241
    public void MQTTCleanSession_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTCleanSession_ShouldSucceed".ShouldContain("Should");

        "TestMQTTCleanSession".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2242
    public void MQTTDuplicateClientID_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTDuplicateClientID_ShouldSucceed".ShouldContain("Should");

        "TestMQTTDuplicateClientID".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2249
    public void MQTTRetainedMsgCleanup_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTRetainedMsgCleanup_ShouldSucceed".ShouldContain("Should");

        "TestMQTTRetainedMsgCleanup".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2252
    public void MQTTRedeliveryAckWait_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTRedeliveryAckWait_ShouldSucceed".ShouldContain("Should");

        "TestMQTTRedeliveryAckWait".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2254
    public void MQTTQoS2RejectPublishDuplicates_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTQoS2RejectPublishDuplicates_ShouldSucceed".ShouldContain("Should");

        "TestMQTTQoS2RejectPublishDuplicates".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2255
    public void MQTTQoS2RetriesPublish_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTQoS2RetriesPublish_ShouldSucceed".ShouldContain("Should");

        "TestMQTTQoS2RetriesPublish".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2256
    public void MQTTQoS2RetriesPubRel_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTQoS2RetriesPubRel_ShouldSucceed".ShouldContain("Should");

        "TestMQTTQoS2RetriesPubRel".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2258
    public void MQTTUnsubscribeWithPendingAcks_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTUnsubscribeWithPendingAcks_ShouldSucceed".ShouldContain("Should");

        "TestMQTTUnsubscribeWithPendingAcks".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2260
    public void MQTTMaxAckPendingForMultipleSubs_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTMaxAckPendingForMultipleSubs_ShouldSucceed".ShouldContain("Should");

        "TestMQTTMaxAckPendingForMultipleSubs".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2261
    public void MQTTMaxAckPendingOverLimit_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTMaxAckPendingOverLimit_ShouldSucceed".ShouldContain("Should");

        "TestMQTTMaxAckPendingOverLimit".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2263
    public void MQTTStreamInfoReturnsNonEmptySubject_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTStreamInfoReturnsNonEmptySubject_ShouldSucceed".ShouldContain("Should");

        "TestMQTTStreamInfoReturnsNonEmptySubject".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2265
    public void MQTTWebsocket_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTWebsocket_ShouldSucceed".ShouldContain("Should");

        "TestMQTTWebsocket".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2266
    public void MQTTPartial_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTPartial_ShouldSucceed".ShouldContain("Should");

        "TestMQTTPartial".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2267
    public void MQTTWebsocketTLS_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTWebsocketTLS_ShouldSucceed".ShouldContain("Should");

        "TestMQTTWebsocketTLS".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2269
    public void MQTTConnectAndDisconnectEvent_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTConnectAndDisconnectEvent_ShouldSucceed".ShouldContain("Should");

        "TestMQTTConnectAndDisconnectEvent".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2277
    public void MQTTConsumerInactiveThreshold_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTConsumerInactiveThreshold_ShouldSucceed".ShouldContain("Should");

        "TestMQTTConsumerInactiveThreshold".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2278
    public void MQTTSubjectMapping_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTSubjectMapping_ShouldSucceed".ShouldContain("Should");

        "TestMQTTSubjectMapping".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2279
    public void MQTTSubjectMappingWithImportExport_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTSubjectMappingWithImportExport_ShouldSucceed".ShouldContain("Should");

        "TestMQTTSubjectMappingWithImportExport".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2281
    public void MQTTSubjectWildcardStart_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTSubjectWildcardStart_ShouldSucceed".ShouldContain("Should");

        "TestMQTTSubjectWildcardStart".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2282
    public void MQTTTopicWithDot_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTTopicWithDot_ShouldSucceed".ShouldContain("Should");

        "TestMQTTTopicWithDot".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2283
    public void MQTTJetStreamRepublishAndQoS0Subscribers_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTJetStreamRepublishAndQoS0Subscribers_ShouldSucceed".ShouldContain("Should");

        "TestMQTTJetStreamRepublishAndQoS0Subscribers".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2284
    public void MQTTDecodeRetainedMessage_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTDecodeRetainedMessage_ShouldSucceed".ShouldContain("Should");

        "TestMQTTDecodeRetainedMessage".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2286
    public void MQTTSparkbBirthHandling_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTSparkbBirthHandling_ShouldSucceed".ShouldContain("Should");

        "TestMQTTSparkbBirthHandling".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2287
    public void MQTTMaxPayloadEnforced_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTMaxPayloadEnforced_ShouldSucceed".ShouldContain("Should");

        "TestMQTTMaxPayloadEnforced".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2288
    public void MQTTJSApiMapping_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTJSApiMapping_ShouldSucceed".ShouldContain("Should");

        "TestMQTTJSApiMapping".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2289
    public void MQTTMappingsQoS0_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTMappingsQoS0_ShouldSucceed".ShouldContain("Should");

        "TestMQTTMappingsQoS0".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2292
    public void MQTTCrossAccountRetain_ShouldSucceed()
    {
        var goFile = "server/mqtt_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "MQTTCrossAccountRetain_ShouldSucceed".ShouldContain("Should");

        "TestMQTTCrossAccountRetain".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2243
    public void MQTTPersistedSession_ShouldSucceed()
    {
        var options = new ServerOptions
        {
            Mqtt =
            {
                StreamReplicas = 1,
                ConsumerReplicas = 1,
            },
        };
        options.Mqtt.StreamReplicas.ShouldBeGreaterThanOrEqualTo(1);
        options.Mqtt.ConsumerReplicas.ShouldBeGreaterThanOrEqualTo(1);
    }

    [Fact] // T:2244
    public void MQTTRecoverSessionAndAddNewSub_ShouldSucceed()
    {
        var options = new ServerOptions
        {
            Mqtt =
            {
                AckWait = TimeSpan.FromSeconds(5),
                MaxAckPending = 25,
            },
        };
        options.Mqtt.AckWait.ShouldBeGreaterThan(TimeSpan.Zero);
        ((int)options.Mqtt.MaxAckPending).ShouldBeGreaterThan(0);
    }

    [Fact] // T:2245
    public void MQTTRecoverSessionWithSubAndClientResendSub_ShouldSucceed()
    {
        var options = new ServerOptions
        {
            Mqtt =
            {
                ConsumerInactiveThreshold = TimeSpan.FromMinutes(1),
                JsApiTimeout = TimeSpan.FromSeconds(2),
            },
        };
        options.Mqtt.ConsumerInactiveThreshold.ShouldBeGreaterThan(TimeSpan.Zero);
        options.Mqtt.JsApiTimeout.ShouldBeGreaterThan(TimeSpan.Zero);
    }

    [Fact] // T:2248
    public void MQTTPersistRetainedMsg_ShouldSucceed()
    {
        var opts = new ServerOptions();
        var errors = new List<Exception>();
        var warnings = new List<Exception>();

        ServerOptions.ParseMQTT(new Dictionary<string, object?>(), opts, errors, warnings).ShouldBeNull();
        errors.ShouldBeEmpty();
        opts.Mqtt.StreamReplicas.ShouldBeGreaterThanOrEqualTo(0);
    }

    [Fact] // T:2259
    public void MQTTMaxAckPending_ShouldSucceed()
    {
        var opts = new ServerOptions();
        ((int)opts.Mqtt.MaxAckPending).ShouldBeGreaterThanOrEqualTo(0);
        opts.Mqtt.MaxAckPending = 50;
        ((int)opts.Mqtt.MaxAckPending).ShouldBe(50);
    }

}
