using Shouldly; using ZB.MOM.NatsNet.Server; namespace ZB.MOM.NatsNet.Server.Tests.JetStream; public sealed class NatsStreamConsumersTests { [Fact] public void NewCMsg_ReturnToPool_ClearsValues() { var msg = NatsStream.NewCMsg("orders.created", 22); msg.Subject.ShouldBe("orders.created"); msg.Seq.ShouldBe(22UL); msg.ReturnToPool(); msg.Subject.ShouldBe(string.Empty); msg.Seq.ShouldBe(0UL); } [Fact] public void NewJSPubMsg_WithHeaderAndData_ReturnsSizedMessage() { var pub = NatsStream.NewJSPubMsg("inbox.x", "orders", "reply", [1, 2], [3, 4, 5], null, 12); pub.Subject.ShouldBe("inbox.x"); pub.Size().ShouldBeGreaterThan(0); } [Fact] public void JsOutQ_SendThenUnregister_RejectsFutureSends() { var outq = new JsOutQ(); var first = outq.SendMsg("inbox.1", [1, 2, 3]); first.Error.ShouldBeNull(); first.Len.ShouldBeGreaterThan(0); outq.Unregister(); var second = outq.SendMsg("inbox.2", [4]); second.Error.ShouldNotBeNull(); } [Fact] public void AccName_AndNameLocked_ReturnConfiguredValues() { var stream = CreateStream(); stream.AccName().ShouldBe("A"); stream.NameLocked().ShouldBe("S"); } [Fact] public void SetupSendCapabilities_AndResetConsumers_DoNotThrow() { var stream = CreateStream(); Should.NotThrow(stream.SetupSendCapabilities); Should.NotThrow(stream.ResetAndWaitOnConsumers); } private static NatsStream CreateStream() { var account = new Account { Name = "A" }; var config = new StreamConfig { Name = "S", Storage = StorageType.MemoryStorage, }; return new NatsStream(account, config, DateTime.UtcNow); } }