refactor: rename ScadaLink → ZB.MOM.WW.ScadaBridge (code + projects + namespaces)
Solution + 23 src projects + 26 test projects renamed; folders, csproj, namespaces, and ScadaLinkDbContext/ScadaBridgeDbContext class updated. ActorSystem "scadalink" → "scadabridge", Akka seed-node URLs migrated. SQL roles/logins, LDAP domains, CLI command name, and CLI config dir (~/.scadalink → ~/.scadabridge) also renamed. Build green; 5 Host.Tests fail awaiting SQL login rename in next commit. Pre-existing StaleTagMonitor timing flakes unchanged. Rename script committed at tools/rename-to-scadabridge.sh.
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Messages.Management;
|
||||
using ZB.MOM.WW.ScadaBridge.ManagementService;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.ManagementService.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for <see cref="ManagementEndpoints"/> request-body parsing
|
||||
/// (findings ManagementService-006 / -013).
|
||||
/// </summary>
|
||||
public class ManagementEndpointsTests
|
||||
{
|
||||
[Fact]
|
||||
public void ParseCommand_WithExplicitPayload_DeserializesIntoCommandType()
|
||||
{
|
||||
var json = """{ "command": "CreateSite", "payload": { "name": "Site1", "siteIdentifier": "SITE1", "description": "Desc" } }""";
|
||||
|
||||
var result = ManagementEndpoints.ParseCommand(json);
|
||||
|
||||
Assert.True(result.Success);
|
||||
var command = Assert.IsType<CreateSiteCommand>(result.Command);
|
||||
Assert.Equal("Site1", command.Name);
|
||||
Assert.Equal("SITE1", command.SiteIdentifier);
|
||||
Assert.Equal("Desc", command.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseCommand_WithMissingPayload_DeserializesParameterlessCommand()
|
||||
{
|
||||
// No "payload" field at all -- the fallback must not allocate a throwaway
|
||||
// JsonDocument and must still produce a valid parameterless command.
|
||||
var json = """{ "command": "ListTemplates" }""";
|
||||
|
||||
var result = ManagementEndpoints.ParseCommand(json);
|
||||
|
||||
Assert.True(result.Success);
|
||||
Assert.IsType<ListTemplatesCommand>(result.Command);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseCommand_WithInvalidJson_ReturnsFailure()
|
||||
{
|
||||
var result = ManagementEndpoints.ParseCommand("{ not json");
|
||||
|
||||
Assert.False(result.Success);
|
||||
Assert.Equal("BAD_REQUEST", result.ErrorCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseCommand_WithMissingCommandField_ReturnsFailure()
|
||||
{
|
||||
var result = ManagementEndpoints.ParseCommand("""{ "payload": {} }""");
|
||||
|
||||
Assert.False(result.Success);
|
||||
Assert.Equal("BAD_REQUEST", result.ErrorCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseCommand_WithUnknownCommand_ReturnsFailure()
|
||||
{
|
||||
var result = ManagementEndpoints.ParseCommand("""{ "command": "NoSuchCommand" }""");
|
||||
|
||||
Assert.False(result.Success);
|
||||
Assert.Equal("BAD_REQUEST", result.ErrorCode);
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// Command-timeout configuration (finding ManagementService-010)
|
||||
//
|
||||
// ManagementServiceOptions.CommandTimeout must actually drive the Ask
|
||||
// timeout instead of a hard-coded 30s constant.
|
||||
// ========================================================================
|
||||
|
||||
[Fact]
|
||||
public void ResolveAskTimeout_UsesConfiguredCommandTimeout()
|
||||
{
|
||||
var options = new ManagementServiceOptions { CommandTimeout = TimeSpan.FromSeconds(75) };
|
||||
|
||||
var timeout = ManagementEndpoints.ResolveAskTimeout(options);
|
||||
|
||||
Assert.Equal(TimeSpan.FromSeconds(75), timeout);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolveAskTimeout_WithNullOptions_FallsBackToDefault()
|
||||
{
|
||||
var timeout = ManagementEndpoints.ResolveAskTimeout(null);
|
||||
|
||||
Assert.Equal(TimeSpan.FromSeconds(30), timeout);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolveAskTimeout_WithNonPositiveTimeout_FallsBackToDefault()
|
||||
{
|
||||
// A misconfigured zero/negative timeout would make every Ask fail
|
||||
// immediately; fall back to the safe default instead.
|
||||
var options = new ManagementServiceOptions { CommandTimeout = TimeSpan.Zero };
|
||||
|
||||
var timeout = ManagementEndpoints.ResolveAskTimeout(options);
|
||||
|
||||
Assert.Equal(TimeSpan.FromSeconds(30), timeout);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user