Skip to content

Commit

Permalink
Refactor helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink committed Dec 11, 2023
1 parent bd529cf commit c737de5
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers;
internal static class AcceptanceAssert
{
public static void HasExitCode(int exitCode, TestHostResult testHostResult)
=> Assert.That(exitCode == testHostResult.ExitCode, $"Output of the test host is:\n{testHostResult}");
=> Assert.That(exitCode == testHostResult.ExitCode, GenerateFailedAssertionMessage(testHostResult));

public static void OutputMatchesRegex(string pattern, TestHostResult testHostResult)
=> Assert.That(Regex.IsMatch(testHostResult.StandardOutput, pattern), $"Output of the test host is:\n{testHostResult}");
=> Assert.That(Regex.IsMatch(testHostResult.StandardOutput, pattern), GenerateFailedAssertionMessage(testHostResult));

public static void OutputDoesNotMatchRegex(string pattern, TestHostResult testHostResult)
=> Assert.That(!Regex.IsMatch(testHostResult.StandardOutput, pattern), $"Output of the test host is:\n{testHostResult}");
=> Assert.That(!Regex.IsMatch(testHostResult.StandardOutput, pattern), GenerateFailedAssertionMessage(testHostResult));

public static void OutputContains(string pattern, TestHostResult testHostResult)
=> Assert.That(testHostResult.StandardOutput.Contains(pattern, StringComparison.Ordinal), GenerateFailedAssertionMessage(testHostResult));

private static string GenerateFailedAssertionMessage(TestHostResult testHostResult)
=> $"Output of the test host is:\n{testHostResult}";
}

0 comments on commit c737de5

Please sign in to comment.