66 lines
2.6 KiB
C#
66 lines
2.6 KiB
C#
using Microsoft.Extensions.Options;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.DataConnectionLayer.Tests;
|
|
|
|
/// <summary>
|
|
/// Regression: <see cref="DataConnectionOptions"/> intervals/timeouts drive the
|
|
/// DCL reconnect/tag-resolution timers and the seed-read retry loop; a
|
|
/// zero/negative duration (or a non-positive <c>SeedReadMaxAttempts</c>) must be
|
|
/// rejected at startup by an <see cref="IValidateOptions{TOptions}"/> with a
|
|
/// clear, key-naming message rather than surfacing later at runtime.
|
|
/// </summary>
|
|
public class DataConnectionOptionsValidatorTests
|
|
{
|
|
private static ValidateOptionsResult Validate(DataConnectionOptions options) =>
|
|
new DataConnectionOptionsValidator().Validate(Options.DefaultName, options);
|
|
|
|
/// <summary>Verifies that the default options are valid.</summary>
|
|
[Fact]
|
|
public void DefaultOptions_AreValid()
|
|
{
|
|
var result = Validate(new DataConnectionOptions());
|
|
Assert.True(result.Succeeded, result.FailureMessage);
|
|
}
|
|
|
|
/// <summary>Verifies that a zero reconnect interval is rejected.</summary>
|
|
[Fact]
|
|
public void ZeroReconnectInterval_IsRejected()
|
|
{
|
|
var result = Validate(new DataConnectionOptions { ReconnectInterval = TimeSpan.Zero });
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("ReconnectInterval", result.FailureMessage);
|
|
}
|
|
|
|
/// <summary>Verifies that a non-positive seed-read max attempts value is rejected.</summary>
|
|
[Fact]
|
|
public void NonPositiveSeedReadMaxAttempts_IsRejected()
|
|
{
|
|
var result = Validate(new DataConnectionOptions { SeedReadMaxAttempts = 0 });
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("SeedReadMaxAttempts", result.FailureMessage);
|
|
}
|
|
|
|
/// <summary>Verifies that an out-of-range MxGateway alarm-reopen debounce is rejected (review 2026-10-21 02/P3).</summary>
|
|
/// <param name="milliseconds">The debounce under test.</param>
|
|
[Theory]
|
|
[InlineData(-1)]
|
|
[InlineData(5001)]
|
|
public void OutOfRangeMxAlarmStreamReopenDebounce_IsRejected(int milliseconds)
|
|
{
|
|
var result = Validate(new DataConnectionOptions
|
|
{
|
|
MxAlarmStreamReopenDebounce = TimeSpan.FromMilliseconds(milliseconds)
|
|
});
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("MxAlarmStreamReopenDebounce", result.FailureMessage);
|
|
}
|
|
|
|
/// <summary>Verifies that a zero debounce (reopen per subscribe) is accepted.</summary>
|
|
[Fact]
|
|
public void ZeroMxAlarmStreamReopenDebounce_IsAccepted()
|
|
{
|
|
var result = Validate(new DataConnectionOptions { MxAlarmStreamReopenDebounce = TimeSpan.Zero });
|
|
Assert.True(result.Succeeded, result.FailureMessage);
|
|
}
|
|
}
|