Files
ScadaBridge/tests/ZB.MOM.WW.ScadaBridge.Commons.Tests/Debugging/ExceptionHeaderTests.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

80 lines
3.9 KiB
C#

using ZB.MOM.WW.ScadaBridge.Commons.Types.Debugging;
namespace ZB.MOM.WW.ScadaBridge.Commons.Tests.Debugging;
/// <summary>
/// The single parser behind the graph node's exception subtitle and the step
/// detail panel's exception block. Before it, the panel showed the OUTERMOST exception of a
/// wrapped chain while the node showed the innermost — the two now agree by construction.
/// </summary>
public class ExceptionHeaderTests
{
/// <summary>Verifies that a plain detail splits the type from the message and shortens the type only when asked.</summary>
[Fact]
public void Parse_PlainDetail_SplitsTypeFromMessage_AndShortensOnlyWhenAsked()
{
const string detail = "System.InvalidOperationException: Recipe 42 rejected\n at X.Y()";
Assert.Equal(("InvalidOperationException", "Recipe 42 rejected"), ExceptionHeader.Parse(detail, shortenType: true));
Assert.Equal(("System.InvalidOperationException", "Recipe 42 rejected"), ExceptionHeader.Parse(detail, shortenType: false));
}
/// <summary>Verifies that a wrapped exception chain resolves to the innermost exception.</summary>
[Fact]
public void Parse_WrappedChain_TakesTheINNERMOSTException()
{
const string detail = "A.Outer: outer ---> B.Middle: middle ---> C.Innermost: the real one\n at X";
Assert.Equal(("Innermost", "the real one"), ExceptionHeader.Parse(detail, shortenType: true));
// The panel keeps the namespace but still names the innermost exception, not the wrapper.
Assert.Equal(("C.Innermost", "the real one"), ExceptionHeader.Parse(detail, shortenType: false));
}
/// <summary>Verifies that a generic type keeps its arity and arguments verbatim and only the head is shortened.</summary>
[Fact]
public void Parse_GenericType_KeepsTheArityAndArgumentsVerbatim_ShorteningOnlyTheHead()
{
Assert.Equal(("RecipeException`1[System.String]", "msg"),
ExceptionHeader.Parse("MyApp.RecipeException`1[System.String]: msg", shortenType: true));
Assert.Equal(("RecipeException`1[System.String]", "msg"),
ExceptionHeader.Parse("RecipeException`1[System.String]: msg", shortenType: true));
}
/// <summary>Verifies that the chain marker is matched after trimming, so a trailing marker is not treated as a chain.</summary>
[Fact]
public void Parse_ChainMarkerIsMatchedAfterTrimming_SoATrailingMarkerIsNotAChain()
{
// The first line is trimmed BEFORE the " ---> " chain is walked (behaviour carried over
// verbatim from the FlowGraphView original), so a detail ending in the marker keeps it as
// part of the message rather than resolving to an empty innermost segment.
Assert.Equal(("Outer", "outer --->"), ExceptionHeader.Parse("A.Outer: outer ---> ", shortenType: true));
}
/// <summary>Verifies that a line without a colon is treated as all type and no message.</summary>
[Fact]
public void Parse_LineWithoutAColon_IsAllTypeAndNoMessage()
{
Assert.Equal(("SomethingWentWrong", string.Empty), ExceptionHeader.Parse("SomethingWentWrong", shortenType: true));
}
/// <summary>Verifies that a CRLF detail has the carriage return trimmed off the first line.</summary>
[Fact]
public void Parse_CrLfDetail_TrimsTheCarriageReturnOffTheFirstLine()
{
Assert.Equal(("TimeoutException", "took too long"),
ExceptionHeader.Parse("System.TimeoutException: took too long\r\n at X\r\n", shortenType: true));
}
/// <summary>Verifies that a missing or blank detail returns null.</summary>
/// <param name="detail">The exception detail text to parse.</param>
[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData(" ")]
public void Parse_NothingUsable_ReturnsNull(string? detail)
{
Assert.Null(ExceptionHeader.Parse(detail, shortenType: true));
Assert.Null(ExceptionHeader.Parse(detail, shortenType: false));
}
}