513fa1aa16
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.
77 lines
2.6 KiB
C#
77 lines
2.6 KiB
C#
using ZB.MOM.WW.ScadaBridge.CLI;
|
|
using ZB.MOM.WW.ScadaBridge.CLI.Commands;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.CLI.Tests;
|
|
|
|
/// <summary>
|
|
/// Regression tests for an empty success body and a non-JSON success
|
|
/// body) — both previously crashed table rendering with an unhandled exception.
|
|
/// </summary>
|
|
[Collection("Console")]
|
|
public class ResponseRenderingTests
|
|
{
|
|
/// <summary>Verifies that an empty response body in table format does not throw and yields exit code zero.</summary>
|
|
[Fact]
|
|
public void HandleResponse_EmptyBody_TableFormat_DoesNotThrow_ReturnsZero()
|
|
{
|
|
// A 200/204 with an empty body must be treated as "succeeded, no output".
|
|
var writer = new StringWriter();
|
|
Console.SetOut(writer);
|
|
|
|
try
|
|
{
|
|
var response = new ManagementResponse(204, "", null, null);
|
|
var exitCode = CommandHelpers.HandleResponse(response, "table");
|
|
|
|
Assert.Equal(0, exitCode);
|
|
}
|
|
finally
|
|
{
|
|
Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true });
|
|
}
|
|
}
|
|
|
|
/// <summary>Verifies that a whitespace-only response body in JSON format does not throw and yields exit code zero.</summary>
|
|
[Fact]
|
|
public void HandleResponse_EmptyBody_JsonFormat_DoesNotThrow_ReturnsZero()
|
|
{
|
|
var writer = new StringWriter();
|
|
Console.SetOut(writer);
|
|
|
|
try
|
|
{
|
|
var response = new ManagementResponse(200, " ", null, null);
|
|
var exitCode = CommandHelpers.HandleResponse(response, "json");
|
|
|
|
Assert.Equal(0, exitCode);
|
|
}
|
|
finally
|
|
{
|
|
Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true });
|
|
}
|
|
}
|
|
|
|
/// <summary>Verifies that a non-JSON success body in table format falls back to the raw body and yields exit code zero.</summary>
|
|
[Fact]
|
|
public void HandleResponse_NonJsonBody_TableFormat_FallsBackToRaw_ReturnsZero()
|
|
{
|
|
// A success status with a non-JSON body (e.g. proxy HTML error page)
|
|
// must not crash; it should print the raw body verbatim.
|
|
var writer = new StringWriter();
|
|
Console.SetOut(writer);
|
|
|
|
try
|
|
{
|
|
var response = new ManagementResponse(200, "<html>Service Unavailable</html>", null, null);
|
|
var exitCode = CommandHelpers.HandleResponse(response, "table");
|
|
|
|
Assert.Equal(0, exitCode);
|
|
Assert.Contains("<html>Service Unavailable</html>", writer.ToString());
|
|
}
|
|
finally
|
|
{
|
|
Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true });
|
|
}
|
|
}
|
|
}
|