feat(batch18): implement group-b server core helpers
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Reflection;
|
||||
using Shouldly;
|
||||
using ZB.MOM.NatsNet.Server;
|
||||
using ZB.MOM.NatsNet.Server.Internal;
|
||||
@@ -6,6 +7,43 @@ namespace ZB.MOM.NatsNet.Server.Tests.ImplBacklog;
|
||||
|
||||
public sealed class NatsServerTests
|
||||
{
|
||||
[Fact]
|
||||
public void String_WhenCalled_ReturnsServerNameAndMatchesToString()
|
||||
{
|
||||
var options = new ServerOptions { ServerName = "batch18-node" };
|
||||
var (server, err) = NatsServer.NewServer(options);
|
||||
err.ShouldBeNull();
|
||||
server.ShouldNotBeNull();
|
||||
|
||||
var stringMethod = server!.GetType()
|
||||
.GetMethod("String", BindingFlags.Instance | BindingFlags.Public);
|
||||
stringMethod.ShouldNotBeNull();
|
||||
|
||||
var value = stringMethod!.Invoke(server, null).ShouldBeOfType<string>();
|
||||
value.ShouldBe("batch18-node");
|
||||
server.ToString().ShouldBe(value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FetchAccount_WhenResolverClaimsAreInvalid_ReturnsValidationError()
|
||||
{
|
||||
var (server, err) = NatsServer.NewServer(new ServerOptions());
|
||||
err.ShouldBeNull();
|
||||
server.ShouldNotBeNull();
|
||||
|
||||
var resolver = new MemoryAccountResolver();
|
||||
resolver.StoreAsync("A", "invalid-jwt").GetAwaiter().GetResult();
|
||||
SetField(server!, "_accResolver", resolver);
|
||||
|
||||
var fetchAccountMethod = server.GetType()
|
||||
.GetMethod("FetchAccount", BindingFlags.Instance | BindingFlags.Public);
|
||||
fetchAccountMethod.ShouldNotBeNull();
|
||||
|
||||
var result = ((Account? Account, Exception? Error))fetchAccountMethod!.Invoke(server, ["A"])!;
|
||||
result.Account.ShouldBeNull();
|
||||
result.Error.ShouldBe(ServerErrors.ErrAccountValidation);
|
||||
}
|
||||
|
||||
[Fact] // T:2886
|
||||
public void CustomRouterAuthentication_ShouldSucceed()
|
||||
{
|
||||
@@ -518,4 +556,10 @@ public sealed class NatsServerTests
|
||||
"TestServerShutdownDuringStart".ShouldNotBeNullOrWhiteSpace();
|
||||
}
|
||||
|
||||
private static void SetField(object target, string name, object? value)
|
||||
{
|
||||
target.GetType()
|
||||
.GetField(name, BindingFlags.Instance | BindingFlags.NonPublic)!
|
||||
.SetValue(target, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,29 @@ namespace ZB.MOM.NatsNet.Server.Tests.ImplBacklog;
|
||||
|
||||
public sealed partial class RouteHandlerTests
|
||||
{
|
||||
[Fact]
|
||||
public void NumRemotesInternal_WhenRoutesExist_ReturnsCount()
|
||||
{
|
||||
var (server, err) = NatsServer.NewServer(new ServerOptions());
|
||||
err.ShouldBeNull();
|
||||
server.ShouldNotBeNull();
|
||||
|
||||
var routesField = typeof(NatsServer).GetField("_routes", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
|
||||
routesField.ShouldNotBeNull();
|
||||
routesField!.SetValue(
|
||||
server,
|
||||
new Dictionary<string, List<ClientConnection>>
|
||||
{
|
||||
["one"] = [],
|
||||
["two"] = [],
|
||||
});
|
||||
|
||||
var method = typeof(NatsServer).GetMethod("NumRemotesInternal", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
|
||||
method.ShouldNotBeNull();
|
||||
var count = (int)method!.Invoke(server, null)!;
|
||||
count.ShouldBe(2);
|
||||
}
|
||||
|
||||
[Fact] // T:2854
|
||||
public void RouteCompressionAuto_ShouldSucceed()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user