Files
ScadaBridge/tests/ZB.MOM.WW.ScadaBridge.NotificationService.Tests/NotificationOptionsValidatorTests.cs
T

59 lines
2.0 KiB
C#

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