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.
58 lines
2.1 KiB
C#
58 lines
2.1 KiB
C#
using System.CommandLine;
|
|
using ZB.MOM.WW.ScadaBridge.CLI;
|
|
using ZB.MOM.WW.ScadaBridge.CLI.Commands;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.CLI.Tests;
|
|
|
|
public class FormatResolutionTests
|
|
{
|
|
private static (Option<string> formatOption, RootCommand root) BuildHarness()
|
|
{
|
|
var formatOption = new Option<string>("--format") { Recursive = true };
|
|
var root = new RootCommand();
|
|
root.Add(formatOption);
|
|
return (formatOption, root);
|
|
}
|
|
|
|
/// <summary>Verifies that an explicit format flag overrides the configured default format.</summary>
|
|
[Fact]
|
|
public void ResolveFormat_ExplicitFlag_OverridesConfig()
|
|
{
|
|
var (formatOption, root) = BuildHarness();
|
|
var result = root.Parse(new[] { "--format", "table" });
|
|
var config = new CliConfig { DefaultFormat = "json" };
|
|
|
|
var format = CommandHelpers.ResolveFormat(result, formatOption, config);
|
|
|
|
Assert.Equal("table", format);
|
|
}
|
|
|
|
/// <summary>Verifies that the configured default format is used when the format flag is absent.</summary>
|
|
[Fact]
|
|
public void ResolveFormat_FlagAbsent_UsesConfigDefaultFormat()
|
|
{
|
|
// Regression: when --format is not supplied, the config-file /
|
|
// env-var DefaultFormat must be honoured instead of always falling back to "json".
|
|
var (formatOption, root) = BuildHarness();
|
|
var result = root.Parse(Array.Empty<string>());
|
|
var config = new CliConfig { DefaultFormat = "table" };
|
|
|
|
var format = CommandHelpers.ResolveFormat(result, formatOption, config);
|
|
|
|
Assert.Equal("table", format);
|
|
}
|
|
|
|
/// <summary>Verifies that the format defaults to JSON when the flag and the configuration are both absent.</summary>
|
|
[Fact]
|
|
public void ResolveFormat_FlagAbsent_AndNoConfig_DefaultsToJson()
|
|
{
|
|
var (formatOption, root) = BuildHarness();
|
|
var result = root.Parse(Array.Empty<string>());
|
|
var config = new CliConfig { DefaultFormat = "json" };
|
|
|
|
var format = CommandHelpers.ResolveFormat(result, formatOption, config);
|
|
|
|
Assert.Equal("json", format);
|
|
}
|
|
}
|