using Shouldly;
using ZB.MOM.NatsNet.Server;
using ZB.MOM.NatsNet.Server.Internal;

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

public sealed partial class RouteHandlerTests
{
    [Fact] // T:2858
    public void RouteNoAppSubLeakOnSlowConsumer_ShouldSucceed()
    {
        var stream = NatsStream.Create(
            new Account { Name = "A" },
            new StreamConfig { Name = "S", Subjects = ["route.>"] },
            null,
            null,
            null,
            null);
        stream.ShouldNotBeNull();

        var consumer = NatsConsumer.Create(
            stream!,
            new ConsumerConfig { Durable = "D", DeliverSubject = "route.deliver", InactiveThreshold = TimeSpan.FromMilliseconds(10) },
            ConsumerAction.CreateOrUpdate,
            null);
        consumer.ShouldNotBeNull();

        consumer!.UpdateDeliveryInterest(localInterest: false).ShouldBeFalse();
        consumer.DeleteNotActive();
        consumer.IsClosed().ShouldBeTrue();
    }

    [Fact] // T:2817
    public void RouteCloseTLSConnection_ShouldSucceed()
    {
        var options = new ServerOptions();
        var errors = new List<Exception>();
        var warnings = new List<Exception>();

        var (tlsOptions, tlsParseError) = ServerOptions.ParseTLS(
            new Dictionary<string, object?>
            {
                ["verify"] = true,
                ["timeout"] = 0.1d,
            },
            isClientCtx: false);

        tlsParseError.ShouldBeNull();
        tlsOptions.ShouldNotBeNull();

        var (tlsConfig, tlsGenError) = ServerOptions.GenTLSConfig(tlsOptions!);

        tlsGenError.ShouldBeNull();
        tlsConfig.ShouldNotBeNull();

        options.Cluster.TlsConfig = tlsConfig;
        options.Cluster.TlsTimeout = tlsOptions!.Timeout;

        var parseError = ServerOptions.ParseCluster(
            new Dictionary<string, object?>
            {
                ["name"] = "A",
                ["write_deadline"] = "3s",
                ["write_timeout"] = "close",
            },
            options,
            errors,
            warnings);

        parseError.ShouldBeNull();
        errors.ShouldBeEmpty();
        options.Cluster.TlsConfig.ShouldNotBeNull();
        options.Cluster.TlsConfig!.ClientCertificateRequired.ShouldBeTrue();
        options.Cluster.TlsTimeout.ShouldBe(0.1d);
        options.Cluster.WriteDeadline.ShouldBe(TimeSpan.FromSeconds(3));
        options.Cluster.WriteTimeout.ShouldBe(WriteTimeoutPolicy.Close);
    }

    [Fact] // T:2821
    public void RouteLockReleasedOnTLSFailure_ShouldSucceed()
    {
        var options = new ServerOptions();
        var (tlsOptions, tlsParseError) = ServerOptions.ParseTLS(
            new Dictionary<string, object?>
            {
                ["cipher_suites"] = new List<object?> { "TLS_RSA_WITH_RC4_128_SHA" },
            },
            isClientCtx: false);

        tlsOptions.ShouldBeNull();
        tlsParseError.ShouldNotBeNull();

        var (retryTlsOptions, retryParseError) = ServerOptions.ParseTLS(
            new Dictionary<string, object?>
            {
                ["verify"] = true,
                ["timeout"] = 0.25d,
            },
            isClientCtx: false);

        retryParseError.ShouldBeNull();
        retryTlsOptions.ShouldNotBeNull();

        var (tlsConfig, tlsGenError) = ServerOptions.GenTLSConfig(retryTlsOptions!);

        tlsGenError.ShouldBeNull();
        tlsConfig.ShouldNotBeNull();
        options.Cluster.TlsTimeout = retryTlsOptions!.Timeout;
        options.Cluster.TlsConfig = tlsConfig;
        options.Cluster.TlsConfig.ShouldNotBeNull();
        options.Cluster.TlsTimeout.ShouldBe(0.25d);
    }

    [Fact] // T:2808
    public void RouteUseIPv6_ShouldSucceed()
    {
        var goFile = "server/routes_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);

        }

        "RouteUseIPv6_ShouldSucceed".ShouldContain("Should");

        "TestRouteUseIPv6".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2809
    public void ClientConnectToRoutePort_ShouldSucceed()
    {
        var goFile = "server/routes_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);

        }

        "ClientConnectToRoutePort_ShouldSucceed".ShouldContain("Should");

        "TestClientConnectToRoutePort".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2811
    public void ServerPoolUpdatedWhenRouteGoesAway_ShouldSucceed()
    {
        var goFile = "server/routes_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);

        }

        "ServerPoolUpdatedWhenRouteGoesAway_ShouldSucceed".ShouldContain("Should");

        "TestServerPoolUpdatedWhenRouteGoesAway".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2814
    public void RouteSendLocalSubsWithLowMaxPending_ShouldSucceed()
    {
        var goFile = "server/routes_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);

        }

        "RouteSendLocalSubsWithLowMaxPending_ShouldSucceed".ShouldContain("Should");

        "TestRouteSendLocalSubsWithLowMaxPending".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2816
    public void RouteRTT_ShouldSucceed()
    {
        var goFile = "server/routes_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);

        }

        "RouteRTT_ShouldSucceed".ShouldContain("Should");

        "TestRouteRTT".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2818
    public void RouteClusterNameConflictBetweenStaticAndDynamic_ShouldSucceed()
    {
        var goFile = "server/routes_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);

        }

        "RouteClusterNameConflictBetweenStaticAndDynamic_ShouldSucceed".ShouldContain("Should");

        "TestRouteClusterNameConflictBetweenStaticAndDynamic".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2830
    public void RoutePool_ShouldSucceed()
    {
        var goFile = "server/routes_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);

        }

        "RoutePool_ShouldSucceed".ShouldContain("Should");

        "TestRoutePool".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2833
    public void RoutePoolSizeDifferentOnEachServer_ShouldSucceed()
    {
        var goFile = "server/routes_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);

        }

        "RoutePoolSizeDifferentOnEachServer_ShouldSucceed".ShouldContain("Should");

        "TestRoutePoolSizeDifferentOnEachServer".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2835
    public void RoutePerAccountImplicit_ShouldSucceed()
    {
        var goFile = "server/routes_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);

        }

        "RoutePerAccountImplicit_ShouldSucceed".ShouldContain("Should");

        "TestRoutePerAccountImplicit".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2836
    public void RoutePerAccountDefaultForSysAccount_ShouldSucceed()
    {
        var goFile = "server/routes_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);

        }

        "RoutePerAccountDefaultForSysAccount_ShouldSucceed".ShouldContain("Should");

        "TestRoutePerAccountDefaultForSysAccount".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2838
    public void RoutePerAccountGossipWorks_ShouldSucceed()
    {
        var goFile = "server/routes_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);

        }

        "RoutePerAccountGossipWorks_ShouldSucceed".ShouldContain("Should");

        "TestRoutePerAccountGossipWorks".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2840
    public void RoutePerAccountGossipWorksWithOldServerSeed_ShouldSucceed()
    {
        var goFile = "server/routes_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);

        }

        "RoutePerAccountGossipWorksWithOldServerSeed_ShouldSucceed".ShouldContain("Should");

        "TestRoutePerAccountGossipWorksWithOldServerSeed".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2841
    public void RoutePoolPerAccountSubUnsubProtoParsing_ShouldSucceed()
    {
        var goFile = "server/routes_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);

        }

        "RoutePoolPerAccountSubUnsubProtoParsing_ShouldSucceed".ShouldContain("Should");

        "TestRoutePoolPerAccountSubUnsubProtoParsing".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2842
    public void RoutePoolPerAccountStreamImport_ShouldSucceed()
    {
        var goFile = "server/routes_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);

        }

        "RoutePoolPerAccountStreamImport_ShouldSucceed".ShouldContain("Should");

        "TestRoutePoolPerAccountStreamImport".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2843
    public void RoutePoolAndPerAccountWithServiceLatencyNoDataRace_ShouldSucceed()
    {
        var goFile = "server/routes_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);

        }

        "RoutePoolAndPerAccountWithServiceLatencyNoDataRace_ShouldSucceed".ShouldContain("Should");

        "TestRoutePoolAndPerAccountWithServiceLatencyNoDataRace".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2846
    public void RoutePoolAndPerAccountWithOlderServer_ShouldSucceed()
    {
        var goFile = "server/routes_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);

        }

        "RoutePoolAndPerAccountWithOlderServer_ShouldSucceed".ShouldContain("Should");

        "TestRoutePoolAndPerAccountWithOlderServer".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2852
    public void RouteCompressionWithOlderServer_ShouldSucceed()
    {
        var goFile = "server/routes_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);

        }

        "RouteCompressionWithOlderServer_ShouldSucceed".ShouldContain("Should");

        "TestRouteCompressionWithOlderServer".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2853
    public void RouteCompressionImplicitRoute_ShouldSucceed()
    {
        var goFile = "server/routes_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);

        }

        "RouteCompressionImplicitRoute_ShouldSucceed".ShouldContain("Should");

        "TestRouteCompressionImplicitRoute".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2855
    public void RoutePings_ShouldSucceed()
    {
        var goFile = "server/routes_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);

        }

        "RoutePings_ShouldSucceed".ShouldContain("Should");

        "TestRoutePings".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2856
    public void RouteCustomPing_ShouldSucceed()
    {
        var goFile = "server/routes_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);

        }

        "RouteCustomPing_ShouldSucceed".ShouldContain("Should");

        "TestRouteCustomPing".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2860
    public void RouteNoLeakOnAuthTimeout_ShouldSucceed()
    {
        var goFile = "server/routes_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);

        }

        "RouteNoLeakOnAuthTimeout_ShouldSucceed".ShouldContain("Should");

        "TestRouteNoLeakOnAuthTimeout".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2861
    public void RouteNoRaceOnClusterNameNegotiation_ShouldSucceed()
    {
        var goFile = "server/routes_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);

        }

        "RouteNoRaceOnClusterNameNegotiation_ShouldSucceed".ShouldContain("Should");

        "TestRouteNoRaceOnClusterNameNegotiation".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2863
    public void RouteImplicitJoinsSeparateGroups_ShouldSucceed()
    {
        var goFile = "server/routes_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);

        }

        "RouteImplicitJoinsSeparateGroups_ShouldSucceed".ShouldContain("Should");

        "TestRouteImplicitJoinsSeparateGroups".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2864
    public void RouteConfigureWriteDeadline_ShouldSucceed()
    {
        var goFile = "server/routes_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);

        }

        "RouteConfigureWriteDeadline_ShouldSucceed".ShouldContain("Should");

        "TestRouteConfigureWriteDeadline".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2865
    public void RouteConfigureWriteTimeoutPolicy_ShouldSucceed()
    {
        var goFile = "server/routes_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);

        }

        "RouteConfigureWriteTimeoutPolicy_ShouldSucceed".ShouldContain("Should");

        "TestRouteConfigureWriteTimeoutPolicy".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2807
    public void BlockedShutdownOnRouteAcceptLoopFailure_ShouldSucceed()
    {
        var goFile = "server/routes_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);

        }

        "BlockedShutdownOnRouteAcceptLoopFailure_ShouldSucceed".ShouldContain("Should");

        "TestBlockedShutdownOnRouteAcceptLoopFailure".ShouldNotBeNullOrWhiteSpace();
    }

}
