Files
ScadaBridge/tests/ZB.MOM.WW.ScadaBridge.ExternalSystemGateway.Tests/ExternalSystemGatewayOptionsValidatorTests.cs
T
Joseph Doherty 513fa1aa16 docs(tests): fix CommentChecker findings across tests/ — 13,392 → 0 (repo-wide scan clean)
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.
2026-10-07 15:05:49 -04:00

74 lines
2.9 KiB
C#

using Microsoft.Extensions.Options;
namespace ZB.MOM.WW.ScadaBridge.ExternalSystemGateway.Tests;
/// <summary>
/// Arch-review 08 §1.5: <see cref="ExternalSystemGatewayOptions"/> feeds a per-call HTTP
/// timeout, a per-system connection cap (used as <c>SocketsHttpHandler.MaxConnectionsPerServer</c>),
/// and a response-body byte cap into the gateway. A zero/negative timeout or a non-positive
/// count crashes the handler or silently disables the gateway; reject them fast at startup.
/// </summary>
public class ExternalSystemGatewayOptionsValidatorTests
{
private static ValidateOptionsResult Validate(ExternalSystemGatewayOptions options) =>
new ExternalSystemGatewayOptionsValidator().Validate(Options.DefaultName, options);
/// <summary>Verifies that the default options are valid.</summary>
[Fact]
public void DefaultOptions_AreValid()
{
var result = Validate(new ExternalSystemGatewayOptions());
Assert.True(result.Succeeded, result.FailureMessage);
}
/// <summary>Verifies that a zero default HTTP timeout is rejected.</summary>
[Fact]
public void ZeroDefaultHttpTimeout_IsRejected()
{
var result = Validate(new ExternalSystemGatewayOptions { DefaultHttpTimeout = TimeSpan.Zero });
Assert.True(result.Failed);
Assert.Contains("DefaultHttpTimeout", result.FailureMessage);
}
/// <summary>Verifies that a negative default HTTP timeout is rejected.</summary>
[Fact]
public void NegativeDefaultHttpTimeout_IsRejected()
{
var result = Validate(new ExternalSystemGatewayOptions { DefaultHttpTimeout = TimeSpan.FromSeconds(-1) });
Assert.True(result.Failed);
Assert.Contains("DefaultHttpTimeout", result.FailureMessage);
}
/// <summary>Verifies that a zero maximum of concurrent connections per system is rejected.</summary>
[Fact]
public void ZeroMaxConcurrentConnectionsPerSystem_IsRejected()
{
var result = Validate(new ExternalSystemGatewayOptions { MaxConcurrentConnectionsPerSystem = 0 });
Assert.True(result.Failed);
Assert.Contains("MaxConcurrentConnectionsPerSystem", result.FailureMessage);
}
/// <summary>Verifies that a negative maximum of concurrent connections per system is rejected.</summary>
[Fact]
public void NegativeMaxConcurrentConnectionsPerSystem_IsRejected()
{
var result = Validate(new ExternalSystemGatewayOptions { MaxConcurrentConnectionsPerSystem = -1 });
Assert.True(result.Failed);
Assert.Contains("MaxConcurrentConnectionsPerSystem", result.FailureMessage);
}
/// <summary>Verifies that a zero maximum response body size is rejected.</summary>
[Fact]
public void ZeroMaxResponseBodyBytes_IsRejected()
{
var result = Validate(new ExternalSystemGatewayOptions { MaxResponseBodyBytes = 0 });
Assert.True(result.Failed);
Assert.Contains("MaxResponseBodyBytes", result.FailureMessage);
}
}