using Microsoft.Extensions.Options;
namespace ZB.MOM.WW.ScadaBridge.NotificationService.Tests;
///
/// Arch-review 08 ยง1.5: supplies the SMTP fallback
/// connection timeout and max-concurrent-connections used by the central Email delivery
/// adapter when the deployed SmtpConfiguration leaves them unset. A non-positive
/// value there is not a usable fallback; reject it fast at startup with a key-naming message.
///
public class NotificationOptionsValidatorTests
{
private static ValidateOptionsResult Validate(NotificationOptions options) =>
new NotificationOptionsValidator().Validate(Options.DefaultName, options);
/// Verifies that the default options pass validation.
[Fact]
public void DefaultOptions_AreValid()
{
var result = Validate(new NotificationOptions());
Assert.True(result.Succeeded, result.FailureMessage);
}
/// Verifies that a zero connection timeout is rejected.
[Fact]
public void ZeroConnectionTimeoutSeconds_IsRejected()
{
var result = Validate(new NotificationOptions { ConnectionTimeoutSeconds = 0 });
Assert.True(result.Failed);
Assert.Contains("ConnectionTimeoutSeconds", result.FailureMessage);
}
/// Verifies that a negative connection timeout is rejected.
[Fact]
public void NegativeConnectionTimeoutSeconds_IsRejected()
{
var result = Validate(new NotificationOptions { ConnectionTimeoutSeconds = -1 });
Assert.True(result.Failed);
Assert.Contains("ConnectionTimeoutSeconds", result.FailureMessage);
}
/// Verifies that a zero maximum concurrent connection count is rejected.
[Fact]
public void ZeroMaxConcurrentConnections_IsRejected()
{
var result = Validate(new NotificationOptions { MaxConcurrentConnections = 0 });
Assert.True(result.Failed);
Assert.Contains("MaxConcurrentConnections", result.FailureMessage);
}
/// Verifies that a negative maximum concurrent connection count is rejected.
[Fact]
public void NegativeMaxConcurrentConnections_IsRejected()
{
var result = Validate(new NotificationOptions { MaxConcurrentConnections = -1 });
Assert.True(result.Failed);
Assert.Contains("MaxConcurrentConnections", result.FailureMessage);
}
}