513fa1aa16
Comment/XML-doc changes only: - add summaries to ~10k test methods, fixtures, fakes and helpers (+ <param> on theories, <returns> on async Task methods, <inheritdoc/> on interface implementations the checker can resolve) - strip ~2.6k project-tracking references (WP*, P*-*, row-NN, Task N, #NN, Component-0NN) from comments, keeping the explanatory text; reword false positives in comments only - real docs on fakes implementing BCL/library interfaces (IDisposable, ILogger, IOptionsMonitor, IAsyncLifetime) - reword the last 5 src/ false positives (CWE-1236, failures-1, year-0001, M365) Only non-comment edits: four one-line nested classes split across lines so members can carry docs. Build 0 errors / 0 warnings.
71 lines
2.5 KiB
C#
71 lines
2.5 KiB
C#
using Microsoft.Extensions.Logging.Abstractions;
|
|
using ZB.MOM.WW.ScadaBridge.DataConnectionLayer.Adapters;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.DataConnectionLayer.Tests;
|
|
|
|
/// <summary>
|
|
/// Tests for protocol extensibility via DataConnectionFactory.
|
|
/// </summary>
|
|
public class DataConnectionFactoryTests
|
|
{
|
|
/// <summary>Verifies that creating an OPC UA connection returns the OPC UA adapter.</summary>
|
|
[Fact]
|
|
public void Create_OpcUa_ReturnsOpcUaAdapter()
|
|
{
|
|
var factory = new DataConnectionFactory(NullLoggerFactory.Instance);
|
|
|
|
var connection = factory.Create("OpcUa", new Dictionary<string, string>());
|
|
|
|
Assert.IsType<OpcUaDataConnection>(connection);
|
|
}
|
|
|
|
/// <summary>Verifies that creating an MxGateway connection returns the MxGateway adapter.</summary>
|
|
[Fact]
|
|
public void Create_MxGateway_ReturnsMxGatewayAdapter()
|
|
{
|
|
var factory = new DataConnectionFactory(NullLoggerFactory.Instance);
|
|
|
|
var connection = factory.Create("MxGateway", new Dictionary<string, string>());
|
|
|
|
Assert.IsType<MxGatewayDataConnection>(connection);
|
|
}
|
|
|
|
/// <summary>Verifies that protocol names are matched case-insensitively.</summary>
|
|
[Fact]
|
|
public void Create_CaseInsensitive()
|
|
{
|
|
var factory = new DataConnectionFactory(NullLoggerFactory.Instance);
|
|
|
|
var connection = factory.Create("opcua", new Dictionary<string, string>());
|
|
|
|
Assert.IsType<OpcUaDataConnection>(connection);
|
|
}
|
|
|
|
/// <summary>Verifies that an unknown protocol throws an exception.</summary>
|
|
[Fact]
|
|
public void Create_UnknownProtocol_Throws()
|
|
{
|
|
var factory = new DataConnectionFactory(NullLoggerFactory.Instance);
|
|
|
|
var ex = Assert.Throws<ArgumentException>(() =>
|
|
factory.Create("UnknownProtocol", new Dictionary<string, string>()));
|
|
|
|
Assert.Contains("Unknown protocol type", ex.Message);
|
|
Assert.Contains("OpcUa", ex.Message);
|
|
}
|
|
|
|
/// <summary>Verifies that a registered adapter extends the set of protocols the factory can create.</summary>
|
|
[Fact]
|
|
public void RegisterAdapter_ExtendsFactory()
|
|
{
|
|
var factory = new DataConnectionFactory(NullLoggerFactory.Instance);
|
|
|
|
// Adding a new protocol = register an adapter
|
|
factory.RegisterAdapter("Custom", _ => new OpcUaDataConnection(
|
|
new DefaultOpcUaClientFactory(), NullLogger<OpcUaDataConnection>.Instance));
|
|
|
|
var connection = factory.Create("Custom", new Dictionary<string, string>());
|
|
Assert.NotNull(connection);
|
|
}
|
|
}
|