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.
95 lines
3.8 KiB
C#
95 lines
3.8 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 the table header union: <c>WriteAsTable</c> previously derived the table
|
|
/// header set from the first array element only, so any property unique to a later
|
|
/// element was silently dropped from the rendered table.
|
|
/// </summary>
|
|
[Collection("Console")]
|
|
public class TableHeaderUnionTests
|
|
{
|
|
/// <summary>Verifies that a table rendered from a heterogeneous array includes all columns.</summary>
|
|
[Fact]
|
|
public void HandleResponse_TableFormat_HeterogeneousArray_IncludesAllColumns()
|
|
{
|
|
// The second element has a "Status" property the first lacks. The pre-fix code
|
|
// derived headers from items[0] only, so "Status" (and its value "Faulted")
|
|
// were dropped from the table entirely.
|
|
var writer = new StringWriter();
|
|
Console.SetOut(writer);
|
|
|
|
try
|
|
{
|
|
var json = "[{\"Id\":1,\"Name\":\"Alpha\"},{\"Id\":2,\"Name\":\"Beta\",\"Status\":\"Faulted\"}]";
|
|
var response = new ManagementResponse(200, json, null, null);
|
|
var exitCode = CommandHelpers.HandleResponse(response, "table");
|
|
|
|
Assert.Equal(0, exitCode);
|
|
var output = writer.ToString();
|
|
Assert.Contains("Status", output);
|
|
Assert.Contains("Faulted", output);
|
|
}
|
|
finally
|
|
{
|
|
Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true });
|
|
}
|
|
}
|
|
|
|
/// <summary>Verifies that a table rendered from a heterogeneous array preserves the first-seen column order.</summary>
|
|
[Fact]
|
|
public void HandleResponse_TableFormat_HeterogeneousArray_PreservesFirstSeenColumnOrder()
|
|
{
|
|
// Column order must be the first-seen order across all elements: the first
|
|
// element contributes Id, Name; the second contributes Status after them.
|
|
var writer = new StringWriter();
|
|
Console.SetOut(writer);
|
|
|
|
try
|
|
{
|
|
var json = "[{\"Id\":1,\"Name\":\"Alpha\"},{\"Status\":\"Faulted\",\"Id\":2,\"Name\":\"Beta\"}]";
|
|
var response = new ManagementResponse(200, json, null, null);
|
|
var exitCode = CommandHelpers.HandleResponse(response, "table");
|
|
|
|
Assert.Equal(0, exitCode);
|
|
var output = writer.ToString();
|
|
var headerLine = output.Split('\n')[0];
|
|
Assert.True(headerLine.IndexOf("Id") < headerLine.IndexOf("Name"));
|
|
Assert.True(headerLine.IndexOf("Name") < headerLine.IndexOf("Status"));
|
|
}
|
|
finally
|
|
{
|
|
Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true });
|
|
}
|
|
}
|
|
|
|
/// <summary>Verifies that a table still renders all rows when the first element has an extra column.</summary>
|
|
[Fact]
|
|
public void HandleResponse_TableFormat_FirstElementHasExtraColumn_StillRendersAllRows()
|
|
{
|
|
// The reverse case: the first element has a property a later element lacks.
|
|
// The later row must still render (with an empty cell), and all columns kept.
|
|
var writer = new StringWriter();
|
|
Console.SetOut(writer);
|
|
|
|
try
|
|
{
|
|
var json = "[{\"Id\":1,\"Name\":\"Alpha\",\"Note\":\"first\"},{\"Id\":2,\"Name\":\"Beta\"}]";
|
|
var response = new ManagementResponse(200, json, null, null);
|
|
var exitCode = CommandHelpers.HandleResponse(response, "table");
|
|
|
|
Assert.Equal(0, exitCode);
|
|
var output = writer.ToString();
|
|
Assert.Contains("Note", output);
|
|
Assert.Contains("first", output);
|
|
Assert.Contains("Beta", output);
|
|
}
|
|
finally
|
|
{
|
|
Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true });
|
|
}
|
|
}
|
|
}
|