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

97 lines
3.5 KiB
C#

using ZB.MOM.WW.ScadaBridge.Commons.Types;
namespace ZB.MOM.WW.ScadaBridge.CLI.Tests;
/// <summary>
/// Verifies the CSV parsing behaviour that backs <c>instance import-overrides</c>:
/// parse errors block the apply step; valid CSV produces the expected
/// <c>attributeName → value</c> dictionary that <see cref="SetInstanceOverridesCommand"/>
/// consumes.
/// </summary>
public class ImportOverridesTests
{
// ── error path ───────────────────────────────────────────────────────────
/// <summary>Verifies that a CSV with a missing header produces errors.</summary>
[Fact]
public void CsvWithMissingHeader_ProducesErrors()
{
var result = OverrideCsvParser.Parse("Speed,100");
Assert.NotEmpty(result.Errors);
Assert.Empty(result.Rows);
}
/// <summary>Verifies that a CSV row with a blank attribute name produces an error.</summary>
[Fact]
public void CsvWithBlankAttributeName_ProducesError()
{
const string csv = "AttributeName,Value\n,100";
var result = OverrideCsvParser.Parse(csv);
Assert.NotEmpty(result.Errors);
// The bad row is excluded; no rows flow through.
Assert.Empty(result.Rows);
}
/// <summary>Verifies that a CSV row with the wrong column count produces an error.</summary>
[Fact]
public void CsvWithWrongColumnCount_ProducesError()
{
const string csv = "AttributeName,Value\nSpeed,100,extra";
var result = OverrideCsvParser.Parse(csv);
Assert.NotEmpty(result.Errors);
Assert.Empty(result.Rows);
}
// ── happy path ───────────────────────────────────────────────────────────
/// <summary>Verifies that a valid CSV produces the expected overrides dictionary.</summary>
[Fact]
public void ValidCsv_ProducesCorrectOverridesDictionary()
{
const string csv = """
AttributeName,Value
Speed,100
Mode,
Label,Hello
""";
var parseResult = OverrideCsvParser.Parse(csv);
Assert.Empty(parseResult.Errors);
Assert.Equal(3, parseResult.Rows.Count);
// Build the same dictionary that BuildImportOverrides produces.
var overrides = parseResult.Rows.ToDictionary(r => r.AttributeName, r => r.Value);
Assert.Equal("100", overrides["Speed"]);
Assert.Null(overrides["Mode"]); // empty Value → null → clear the override
Assert.Equal("Hello", overrides["Label"]);
}
/// <summary>Verifies that the element type column of a valid CSV is ignored when building the overrides dictionary.</summary>
[Fact]
public void ValidCsvWithElementTypeColumn_OverridesDictIgnoresElementType()
{
const string csv = """
AttributeName,Value,ElementType
Speed,100,Float
Mode,,
""";
var parseResult = OverrideCsvParser.Parse(csv);
Assert.Empty(parseResult.Errors);
Assert.Equal(2, parseResult.Rows.Count);
// ElementType is carried on the row but SetInstanceOverridesCommand only
// takes attributeName → value; confirm the dict shape matches.
var overrides = parseResult.Rows.ToDictionary(r => r.AttributeName, r => r.Value);
Assert.Equal("100", overrides["Speed"]);
Assert.Null(overrides["Mode"]);
}
}