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

72 lines
3.0 KiB
C#

using ZB.MOM.WW.ScadaBridge.Commons.Messages.Management;
using ZB.MOM.WW.ScadaBridge.Commons.Types;
namespace ZB.MOM.WW.ScadaBridge.CLI.Tests;
/// <summary>
/// Verifies the CSV parsing + entry-mapping behaviour that backs
/// <c>instance native-alarm-source import</c>: parse errors block the apply step;
/// valid CSV produces the <see cref="NativeAlarmSourceOverrideEntry"/> list the
/// <see cref="SetInstanceNativeAlarmSourceOverridesCommand"/> consumes.
/// </summary>
public class ImportNativeAlarmSourceOverridesTests
{
// ── error path ───────────────────────────────────────────────────────────
/// <summary>Verifies that CSV input without a header row produces errors and no rows.</summary>
[Fact]
public void CsvWithMissingHeader_ProducesErrors()
{
var result = NativeAlarmSourceOverrideCsvParser.Parse("Pressure,ConnA,ref,Active");
Assert.NotEmpty(result.Errors);
Assert.Empty(result.Rows);
}
/// <summary>Verifies that a CSV row with a blank source name produces an error and no rows.</summary>
[Fact]
public void CsvWithBlankSourceName_ProducesError()
{
const string csv = "SourceName,Connection,SourceReference,Filter\n,ConnA,ref,Active";
var result = NativeAlarmSourceOverrideCsvParser.Parse(csv);
Assert.NotEmpty(result.Errors);
Assert.Empty(result.Rows);
}
// ── happy path ───────────────────────────────────────────────────────────
/// <summary>Verifies that valid CSV input produces the expected list of override entries.</summary>
[Fact]
public void ValidCsv_ProducesCorrectEntryList()
{
const string csv = """
SourceName,Connection,SourceReference,Filter
Pressure,ConnA,ns=2;s=Pump,Active
Temp,,,
""";
var parseResult = NativeAlarmSourceOverrideCsvParser.Parse(csv);
Assert.Empty(parseResult.Errors);
Assert.Equal(2, parseResult.Rows.Count);
// Build the same entry list that the CLI import action produces.
var entries = parseResult.Rows
.Select(r => new NativeAlarmSourceOverrideEntry(
r.SourceName, r.Connection, r.SourceReference, r.Filter))
.ToList();
Assert.Equal("Pressure", entries[0].SourceCanonicalName);
Assert.Equal("ConnA", entries[0].ConnectionNameOverride);
Assert.Equal("ns=2;s=Pump", entries[0].SourceReferenceOverride);
Assert.Equal("Active", entries[0].ConditionFilterOverride);
// All-blank override fields → inherited (null) on every field.
Assert.Equal("Temp", entries[1].SourceCanonicalName);
Assert.Null(entries[1].ConnectionNameOverride);
Assert.Null(entries[1].SourceReferenceOverride);
Assert.Null(entries[1].ConditionFilterOverride);
}
}