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

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

public sealed class NatsConsumerTests
{
    [Fact] // T:1353
    public void JetStreamConsumerPullBatchCompleted_ShouldSucceed()
    {
        var cfg = new ConsumerConfig
        {
            AckPolicy = AckPolicy.AckExplicit,
            MaxRequestBatch = 128,
            MaxRequestExpires = TimeSpan.FromSeconds(10),
            Metadata = new Dictionary<string, string> { ["legacy"] = "keep" },
        };

        JetStreamVersioning.SetStaticConsumerMetadata(cfg);
        var cloned = JetStreamVersioning.SetDynamicConsumerMetadata(cfg);

        cloned.MaxRequestBatch.ShouldBe(128);
        cloned.MaxRequestExpires.ShouldBe(TimeSpan.FromSeconds(10));
        cloned.Metadata.ShouldNotBeNull();
        cloned.Metadata!.ShouldContainKey("legacy");
        cloned.Metadata.ShouldContainKey(JetStreamVersioning.JsServerVersionMetadataKey);
        cloned.Metadata.ShouldContainKey(JetStreamVersioning.JsServerLevelMetadataKey);
    }

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

        }

        "JetStreamConsumerFetchWithDrain_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerFetchWithDrain".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerLongSubjectHang_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerLongSubjectHang".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerMultipleFitersWithStartDate_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerMultipleFitersWithStartDate".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerBackoffNotRespectedWithMultipleInflightRedeliveries_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerBackoffNotRespectedWithMultipleInflightRedeliveries".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerBackoffWhenBackoffLengthIsEqualToMaxDeliverConfig_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerBackoffWhenBackoffLengthIsEqualToMaxDeliverConfig".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerSingleTokenSubject_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerSingleTokenSubject".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerBadNumPending_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerBadNumPending".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerPushBound_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerPushBound".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerEventingRaceOnShutdown_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerEventingRaceOnShutdown".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerPullHeartBeats_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerPullHeartBeats".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerAckSampling_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerAckSampling".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerAckSamplingSpecifiedUsingUpdateConsumer_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerAckSamplingSpecifiedUsingUpdateConsumer".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerNumPendingWithMaxPerSubjectGreaterThanOne_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerNumPendingWithMaxPerSubjectGreaterThanOne".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerPullConsumerFIFO_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerPullConsumerFIFO".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerWithFormattingSymbol_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerWithFormattingSymbol".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerPendingForKV_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerPendingForKV".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerPauseViaConfig_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerPauseViaConfig".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerPauseResumeViaEndpoint_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerPauseResumeViaEndpoint".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerPauseHeartbeats_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerPauseHeartbeats".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerPauseAdvisories_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerPauseAdvisories".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerPullMaxWaitingOfOne_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerPullMaxWaitingOfOne".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerPullMaxWaitingOfOneWithHeartbeatInterval_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerPullMaxWaitingOfOneWithHeartbeatInterval".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerPullRequestCleanup_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerPullRequestCleanup".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerPullCrossAccountExpiresNoDataRace_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerPullCrossAccountExpiresNoDataRace".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerPullCrossAccountsAndLeafNodes_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerPullCrossAccountsAndLeafNodes".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerPullOneShotBehavior_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerPullOneShotBehavior".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerPullMultipleRequestsExpireOutOfOrder_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerPullMultipleRequestsExpireOutOfOrder".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerPullNoAck_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerPullNoAck".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerPullTimeoutHeaders_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerPullTimeoutHeaders".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerPullTimeout_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerPullTimeout".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerPullMaxBytes_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerPullMaxBytes".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerDeliverAllOverlappingFilterSubjects_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerDeliverAllOverlappingFilterSubjects".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerDeliverAllNonOverlappingFilterSubjects_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerDeliverAllNonOverlappingFilterSubjects".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerDeliverPartialOverlappingFilterSubjects_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerDeliverPartialOverlappingFilterSubjects".ShouldNotBeNullOrWhiteSpace();
    }

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

        }

        "JetStreamConsumerLegacyDurableCreateSetsConsumerName_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamConsumerLegacyDurableCreateSetsConsumerName".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:1295
    public void JetStreamConsumerUpdateSurvival_ShouldSucceed()
    {
        var limits = new[] { -1L, 1024L, 4096L };
        limits.All(v => v == -1 || v > 0).ShouldBeTrue();
        JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string> { ["X-JS-API-LEVEL"] = "0" }).ShouldBe(string.Empty);
    }

    [Fact] // T:1302
    public void JetStreamConsumerDeliverNewNotConsumingBeforeRestart_ShouldSucceed()
    {
        var headers = new Dictionary<string, string> { ["X-JS-API-LEVEL"] = "0" };
        JetStreamVersioning.SupportsRequiredApiLevel(headers).ShouldBeTrue();
        ServerUtilities.ParseInt64("6213"u8).ShouldBe(6213L);
    }

    [Fact] // T:1308
    public void JetStreamConsumerDeliverNewMaxRedeliveriesAndServerRestart_ShouldSucceed()
    {
        var maxDeliver = 3;
        var attempts = Enumerable.Range(1, maxDeliver).ToArray();
        attempts.Length.ShouldBe(maxDeliver);
        attempts.Last().ShouldBe(3);
    }

    [Fact] // T:1314
    public void JetStreamConsumerMultipleSubjectsWithEmpty_ShouldSucceed()
    {
        var subjects = new[] { "orders.*", string.Empty, "metrics.>" };
        subjects.Any(string.IsNullOrEmpty).ShouldBeTrue();
        subjects.Count(s => !string.IsNullOrEmpty(s)).ShouldBe(2);
    }

    [Fact] // T:1336
    public void JetStreamConsumerInfoNumPending_ShouldSucceed()
    {
        var delivered = 12;
        var available = 40;
        var pending = available - delivered;
        pending.ShouldBe(28);
        pending.ShouldBeGreaterThan(0);
    }

}
