test(batch19): port accounts core mapped tests

This commit is contained in:
Joseph Doherty
2026-02-28 20:28:13 -05:00
parent e53b4aa17a
commit 8d00012ba8
5 changed files with 190 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
using System.Diagnostics;
using System.Linq;
using Shouldly;
using ZB.MOM.NatsNet.Server;
using ZB.MOM.NatsNet.Server.Internal;
@@ -122,6 +123,53 @@ public sealed partial class GatewayHandlerTests
NatsServer.ValidateCluster(conflict).ShouldBe(ServerErrors.ErrClusterNameConfigConflict);
}
[Fact] // T:658
public void GatewaySendReplyAcrossGatewaysServiceImport_ShouldSucceed()
{
var fooAccount = Account.NewAccount("$foo");
var barAccount = Account.NewAccount("$bar");
fooAccount.AddServiceExport("foo.request", null).ShouldBeNull();
barAccount.AddServiceImport(fooAccount, "bar.request", "foo.request").ShouldBeNull();
var serviceImport = barAccount.Imports.Services!["bar.request"].Single();
var responseImport = barAccount.AddRespServiceImport(fooAccount, "reply", serviceImport, tracking: false, header: null);
responseImport.From.ShouldNotBe("reply");
responseImport.To.ShouldBe("reply");
barAccount.Exports.Responses.ShouldNotBeNull();
barAccount.Exports.Responses!.ShouldContainKey(responseImport.From);
fooAccount.Imports.ReverseResponseMap.ShouldNotBeNull();
fooAccount.Imports.ReverseResponseMap!.ShouldContainKey("reply");
fooAccount.Imports.ReverseResponseMap["reply"].Any(e => e.MappedSubject == responseImport.From).ShouldBeTrue();
barAccount.ProcessServiceImportResponse(responseImport.From, "ok"u8.ToArray());
responseImport.DidDeliver.ShouldBeTrue();
}
[Fact] // T:666
public void GatewayNoAccountUnsubWhenServiceReplyInUse_ShouldSucceed()
{
var fooAccount = Account.NewAccount("$foo");
var barAccount = Account.NewAccount("$bar");
fooAccount.AddServiceExport("test.request", null).ShouldBeNull();
barAccount.AddServiceImport(fooAccount, "foo.request", "test.request").ShouldBeNull();
var serviceImport = barAccount.Imports.Services!["foo.request"].Single();
var responseImport1 = barAccount.AddRespServiceImport(fooAccount, "reply", serviceImport, tracking: false, header: null);
var responseImport2 = barAccount.AddRespServiceImport(fooAccount, "reply", serviceImport, tracking: false, header: null);
fooAccount.Imports.ReverseResponseMap.ShouldNotBeNull();
fooAccount.Imports.ReverseResponseMap!["reply"].Count.ShouldBe(2);
fooAccount.CheckForReverseEntry("reply", responseImport1, checkInterest: false);
fooAccount.Imports.ReverseResponseMap["reply"].Count.ShouldBe(1);
fooAccount.Imports.ReverseResponseMap["reply"].Single().MappedSubject.ShouldBe(responseImport2.From);
}
private static NatsServer CreateServer(ServerOptions? opts = null)
{
var (server, err) = NatsServer.NewServer(opts ?? new ServerOptions());