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

52 lines
2.6 KiB
C#

using System.CommandLine;
using System.Net;
using System.Net.Sockets;
using System.Text;
using ZB.MOM.WW.ScadaBridge.CLI.Commands;
namespace ZB.MOM.WW.ScadaBridge.CLI.Tests;
public class DeploySiteExitCodeTests
{
/// <summary>Verifies that the actual deploy command returns an exit code derived from the success and failure counts in the response.</summary>
/// <param name="response">The JSON response body served by the fake management endpoint.</param>
/// <param name="expected">The expected process exit code.</param>
/// <returns>A task that represents the asynchronous operation.</returns>
[Theory]
[InlineData("{\"successCount\":2,\"failureCount\":0}", 0)]
[InlineData("{\"successCount\":1,\"failureCount\":1}", 1)]
[InlineData("{\"unexpected\":true}", 1)]
public async Task DC6_ActualDeployCommandReturnsDomainExitCode(string response, int expected)
{
var listener = new TcpListener(IPAddress.Loopback, 0);
listener.Start();
try
{
var port = ((IPEndPoint)listener.LocalEndpoint).Port;
var server = Task.Run(async () =>
{
using var client = await listener.AcceptTcpClientAsync();
await using var stream = client.GetStream();
using var reader = new StreamReader(stream, Encoding.ASCII, leaveOpen: true);
while (await reader.ReadLineAsync() is { Length: > 0 }) { }
var body = Encoding.UTF8.GetBytes(response);
var headers = Encoding.ASCII.GetBytes($"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: {body.Length}\r\nConnection: close\r\n\r\n");
await stream.WriteAsync(headers);
await stream.WriteAsync(body);
});
var root = new RootCommand();
var url = new Option<string>("--url") { Recursive = true };
var format = new Option<string>("--format") { Recursive = true };
var user = new Option<string>("--username") { Recursive = true };
var password = new Option<string>("--password") { Recursive = true };
root.Add(url); root.Add(format); root.Add(user); root.Add(password);
root.Add(DeployCommands.Build(url, format, user, password));
var exit = await root.Parse(["deploy", "site", "--site-id", "1", "--url", $"http://127.0.0.1:{port}",
"--username", "test", "--password", "test", "--format", "json"]).InvokeAsync();
await server.WaitAsync(TimeSpan.FromSeconds(5));
Assert.Equal(expected, exit);
}
finally { listener.Stop(); }
}
}