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.
85 lines
2.8 KiB
C#
85 lines
2.8 KiB
C#
using ZB.MOM.WW.ScadaBridge.Commons.Types.DataConnections;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Types.Flattening;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Validators;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.Commons.Tests.Validators;
|
|
|
|
public class MxGatewayEndpointConfigValidatorTests
|
|
{
|
|
private static MxGatewayEndpointConfig Valid() => new()
|
|
{
|
|
Endpoint = "http://gw:5000",
|
|
ApiKey = "key",
|
|
};
|
|
|
|
/// <summary>Verifies that a valid config passes validation.</summary>
|
|
[Fact]
|
|
public void Validate_ValidConfig_IsValid()
|
|
{
|
|
var result = MxGatewayEndpointConfigValidator.Validate(Valid());
|
|
Assert.True(result.IsValid);
|
|
Assert.Empty(result.Errors);
|
|
}
|
|
|
|
/// <summary>Verifies that a missing endpoint fails validation.</summary>
|
|
[Fact]
|
|
public void Validate_MissingEndpoint_Fails()
|
|
{
|
|
var c = Valid();
|
|
c.Endpoint = "";
|
|
var r = MxGatewayEndpointConfigValidator.Validate(c);
|
|
Assert.False(r.IsValid);
|
|
Assert.Contains(r.Errors, e =>
|
|
e.EntityName == "Endpoint"
|
|
&& e.Category == ValidationCategory.ConnectionConfig
|
|
&& e.Message.Contains("required", StringComparison.OrdinalIgnoreCase));
|
|
}
|
|
|
|
/// <summary>Verifies that an endpoint with an unsupported scheme fails validation.</summary>
|
|
/// <param name="url">The endpoint URL with the bad scheme.</param>
|
|
[Theory]
|
|
[InlineData("opc.tcp://x:4840")]
|
|
[InlineData("ftp://x")]
|
|
[InlineData("not a url")]
|
|
public void Validate_BadEndpointScheme_Fails(string url)
|
|
{
|
|
var c = Valid();
|
|
c.Endpoint = url;
|
|
var r = MxGatewayEndpointConfigValidator.Validate(c);
|
|
Assert.False(r.IsValid);
|
|
Assert.Contains(r.Errors, e => e.EntityName == "Endpoint");
|
|
}
|
|
|
|
/// <summary>Verifies that a missing API key fails validation.</summary>
|
|
[Fact]
|
|
public void Validate_MissingApiKey_Fails()
|
|
{
|
|
var c = Valid();
|
|
c.ApiKey = "";
|
|
var r = MxGatewayEndpointConfigValidator.Validate(c);
|
|
Assert.False(r.IsValid);
|
|
Assert.Contains(r.Errors, e => e.EntityName == "ApiKey");
|
|
}
|
|
|
|
/// <summary>Verifies that a non-positive read timeout fails validation.</summary>
|
|
[Fact]
|
|
public void Validate_NonPositiveReadTimeout_Fails()
|
|
{
|
|
var c = Valid();
|
|
c.ReadTimeoutMs = 0;
|
|
var r = MxGatewayEndpointConfigValidator.Validate(c);
|
|
Assert.False(r.IsValid);
|
|
Assert.Contains(r.Errors, e => e.EntityName == "ReadTimeoutMs");
|
|
}
|
|
|
|
/// <summary>Verifies that prefixed field names appear in the validation errors.</summary>
|
|
[Fact]
|
|
public void Validate_PrefixedFieldNames_AppearInErrors()
|
|
{
|
|
var c = Valid();
|
|
c.Endpoint = "";
|
|
var r = MxGatewayEndpointConfigValidator.Validate(c, "Primary.");
|
|
Assert.Contains(r.Errors, e => e.EntityName == "Primary.Endpoint");
|
|
}
|
|
}
|