Files
ScadaBridge/tests/ZB.MOM.WW.ScadaBridge.DelmiaNotifier.Tests/NotifierTests.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

81 lines
3.7 KiB
C#

using ZB.MOM.WW.ScadaBridge.DelmiaNotifier;
namespace ZB.MOM.WW.ScadaBridge.DelmiaNotifier.Tests;
public class NotifierTests
{
private sealed class FakeSender(params AttemptOutcome[] outcomes) : IRecipeSender
{
private readonly Queue<AttemptOutcome> _outcomes = new(outcomes);
/// <summary>Gets the calls recorded by this fake.</summary>
public int Calls { get; private set; }
/// <inheritdoc />
public Task<AttemptOutcome> SendAsync(string baseUrl, RecipeDownload payload, CancellationToken ct)
{
Calls++;
return Task.FromResult(_outcomes.Dequeue());
}
}
private static readonly string[] TwoUrls = ["http://a", "http://b"];
private static readonly RecipeDownload Payload =
new() { MachineCode = "Z", DownloadPath = "x", WorkOrderNumber = "W", PartNumber = "P" };
/// <summary>Verifies that a connection failure advances to the next URL.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task ConnectFailure_advances_to_next_url()
{
var sender = new FakeSender(
new AttemptOutcome(AttemptKind.ConnectFailed, 0, null, "refused"),
new AttemptOutcome(AttemptKind.Connected, 200, new RecipeDownloadResult { Result = true }, null));
var result = await Notifier.RunAsync(TwoUrls, Payload, sender, CancellationToken.None);
Assert.True(result.Ok);
Assert.Equal(2, sender.Calls);
}
/// <summary>Verifies that a connected response with a false result is final and does not fail over.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task Connected_result_false_is_final_no_failover()
{
var sender = new FakeSender(
new AttemptOutcome(AttemptKind.Connected, 200, new RecipeDownloadResult { Result = false, ResultText = "bad machine" }, null),
new AttemptOutcome(AttemptKind.Connected, 200, new RecipeDownloadResult { Result = true }, null));
var result = await Notifier.RunAsync(TwoUrls, Payload, sender, CancellationToken.None);
Assert.False(result.Ok);
Assert.Contains("bad machine", result.Reason);
Assert.Equal(1, sender.Calls);
}
/// <summary>Verifies that a connected response with a 5xx status is final and does not fail over.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task Connected_5xx_is_final_no_failover()
{
var sender = new FakeSender(
new AttemptOutcome(AttemptKind.Connected, 500, null, null),
new AttemptOutcome(AttemptKind.Connected, 200, new RecipeDownloadResult { Result = true }, null));
var result = await Notifier.RunAsync(TwoUrls, Payload, sender, CancellationToken.None);
Assert.False(result.Ok);
Assert.Contains("500", result.Reason);
Assert.Equal(1, sender.Calls);
}
/// <summary>Verifies that when every URL fails to connect the notifier reports unreachable with the last error.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task All_connect_failures_report_unreachable_with_last_error()
{
var sender = new FakeSender(
new AttemptOutcome(AttemptKind.ConnectFailed, 0, null, "refused-a"),
new AttemptOutcome(AttemptKind.ConnectFailed, 0, null, "refused-b"));
var result = await Notifier.RunAsync(TwoUrls, Payload, sender, CancellationToken.None);
Assert.False(result.Ok);
Assert.Contains("unreachable", result.Reason);
Assert.Contains("refused-b", result.Reason);
Assert.Equal(2, sender.Calls);
}
}