fix(dcl): feed ScadaBridge:MxGateway:ClientNamePrefix into the MxGateway client-name fallback (review 2026-10-21 02/U1, 08/O2)
This commit is contained in:
+19
@@ -59,6 +59,25 @@ public class MxGatewayDataConnectionTests
|
||||
Assert.Equal("scadabridge", fake.ConnectedWith!.ClientName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Review 2026-10-21 02/U1: a blank per-connection ClientName falls back to the configured
|
||||
/// <c>ScadaBridge:MxGateway:ClientNamePrefix</c> rather than a hard-coded literal.
|
||||
/// </summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task ConnectAsync_blank_client_name_uses_configured_prefix()
|
||||
{
|
||||
var fake = new FakeMxGatewayClient();
|
||||
var adapter = new MxGatewayDataConnection(
|
||||
fake, NullLogger<MxGatewayDataConnection>.Instance, clientNamePrefix: "plant7-scadabridge");
|
||||
var details = Details();
|
||||
details["ClientName"] = " ";
|
||||
|
||||
await adapter.ConnectAsync(details);
|
||||
|
||||
Assert.Equal("plant7-scadabridge", fake.ConnectedWith!.ClientName);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the Disconnected event fires exactly once when the event loop faults.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Microsoft.Extensions.Options;
|
||||
using ZB.MOM.WW.ScadaBridge.DataConnectionLayer.Adapters;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.DataConnectionLayer.Tests;
|
||||
|
||||
@@ -32,4 +35,27 @@ public class GlobalOptionsValidationTests
|
||||
using var provider = services.BuildServiceProvider();
|
||||
provider.GetRequiredService<IStartupValidator>().Validate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Review 2026-10-21 02/U1: the bound <c>ScadaBridge:MxGateway:ClientNamePrefix</c> actually
|
||||
/// reaches the MxGateway adapters the DI-built factory creates.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ClientNamePrefix_FlowsIntoTheMxGatewayAdapter()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<IConfiguration>(new ConfigurationBuilder().AddInMemoryCollection(
|
||||
new Dictionary<string, string?> { ["ScadaBridge:MxGateway:ClientNamePrefix"] = "plant7" }).Build());
|
||||
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
|
||||
services.AddDataConnectionLayer();
|
||||
using var provider = services.BuildServiceProvider();
|
||||
|
||||
var adapter = provider.GetRequiredService<IDataConnectionFactory>()
|
||||
.Create("MxGateway", new Dictionary<string, string>());
|
||||
|
||||
var prefix = typeof(MxGatewayDataConnection)
|
||||
.GetField("_clientNamePrefix", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!
|
||||
.GetValue(adapter);
|
||||
Assert.Equal("plant7", prefix);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user