feat(options): eager startup validation for edge/management options (InboundAPI, ESG, Notification, ManagementService) (arch-review 08 §1.5)
Claude-Session: https://claude.ai/code/session_01MtdgwpEeCUn6cUA5f1LMPj
This commit is contained in:
+58
@@ -0,0 +1,58 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user