Skip to content

Commit

Permalink
log entire content to see which assertion fails (#67586)
Browse files Browse the repository at this point in the history
* add AssertExtensions.Eqal(string, string) that logs entire content if provided strings are not equal

* log entire content to see which assertion fails
  • Loading branch information
adamsitnik authored Apr 6, 2022
1 parent f6ca720 commit bea863b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,17 @@ public static void AtLeastOneEquals<T>(T expected1, T expected2, T value)
throw new XunitException($"Expected: {expected1} || {expected2}{Environment.NewLine}Actual: {value}");
}

/// <summary>
/// Compares two strings, logs entire content if they are not equal.
/// </summary>
public static void Equal(string expected, string actual)
{
if (!expected.Equals(actual))
{
throw new AssertActualExpectedException(expected, actual, "Provided strings were not equal!");
}
}

public delegate void AssertThrowsActionReadOnly<T>(ReadOnlySpan<T> span);

public delegate void AssertThrowsAction<T>(Span<T> span);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void TestAsyncErrorStream_SynchronizingObject(bool invokeRequired)
p.WaitForExit(); // This ensures async event handlers are finished processing.

const string Expected = RemotelyInvokable.TestConsoleApp + " started error stream" + RemotelyInvokable.TestConsoleApp + " closed error stream";
Assert.Equal(Expected, sb.ToString());
AssertExtensions.Equal(Expected, sb.ToString());
Assert.Equal(invokeRequired ? 3 : 0, invokeCalled);
}

Expand Down

0 comments on commit bea863b

Please sign in to comment.