using ZB.MOM.WW.ScadaBridge.Commons.Types.Debugging; namespace ZB.MOM.WW.ScadaBridge.Commons.Tests.Debugging; /// /// Final review M1: the ONE 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. /// public class ExceptionHeaderTests { [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)); } [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)); } [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)); } [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)); } [Fact] public void Parse_LineWithoutAColon_IsAllTypeAndNoMessage() { Assert.Equal(("SomethingWentWrong", string.Empty), ExceptionHeader.Parse("SomethingWentWrong", shortenType: true)); } [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)); } [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)); } }