diff --git a/Directory.Packages.props b/Directory.Packages.props index 936f9d7..8bf5d2f 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -17,7 +17,6 @@ This would typically list all NuGet packages used within this solution. --> - diff --git a/TrxLib.Tests/TestResultTests.cs b/TrxLib.Tests/TestResultTests.cs index 701326e..69fb99e 100644 --- a/TrxLib.Tests/TestResultTests.cs +++ b/TrxLib.Tests/TestResultTests.cs @@ -1,5 +1,4 @@ -using AwesomeAssertions; -using AwesomeAssertions.Execution; +using TUnit.Assertions; namespace TrxLib.Tests; @@ -9,34 +8,34 @@ public class TestResultTests [Arguments("namespace.class.test", "namespace")] [Arguments("deeper.namespace.class.test", "deeper.namespace")] [Arguments("still.deeper.namespace.class.test", "still.deeper.namespace")] - public void Namespace_is_parsed_correctly( + public async Task Namespace_is_parsed_correctly( string fullyQualifiedTestName, string expectedNamespace) { var testResult = new TestResult(fullyQualifiedTestName, TestOutcome.NotExecuted); - testResult.Namespace.Should().Be(expectedNamespace); + await Assert.That(testResult.Namespace).IsEqualTo(expectedNamespace); } [Test] [Arguments("namespace.class.test")] [Arguments("deeper.namespace.class.test")] [Arguments("still.deeper.namespace.class.test")] - public void TestName_is_parsed_correctly( + public async Task TestName_is_parsed_correctly( string fullyQualifiedTestName) { var testResult = new TestResult(fullyQualifiedTestName, TestOutcome.NotExecuted); - testResult.TestName.Should().Be("test"); + await Assert.That(testResult.TestName).IsEqualTo("test"); } [Test] [Arguments("namespace.class.test")] [Arguments("deeper.namespace.class.test")] [Arguments("still.deeper.namespace.class.test")] - public void ClassName_is_parsed_correctly( + public async Task ClassName_is_parsed_correctly( string fullyQualifiedTestName) { var testResult = new TestResult(fullyQualifiedTestName, TestOutcome.NotExecuted); - testResult.ClassName.Should().Be("class"); + await Assert.That(testResult.ClassName).IsEqualTo("class"); } [Test] @@ -44,42 +43,41 @@ public void ClassName_is_parsed_correctly( [Arguments("deeper.namespace.class.test", "deeper.namespace.class")] [Arguments("still.deeper.namespace.class.test", "still.deeper.namespace.class")] [Arguments("deeper.namespace.class.theorytest(command: \"build\")", "deeper.namespace.class")] - public void FullyQualifiedClassName_is_parsed_correctly( + public async Task FullyQualifiedClassName_is_parsed_correctly( string fullyQualifiedTestName, string expected) { var testResult = new TestResult(fullyQualifiedTestName, TestOutcome.NotExecuted); - testResult.FullyQualifiedClassName.Should().Be(expected); + await Assert.That(testResult.FullyQualifiedClassName).IsEqualTo(expected); } [Test] - public void Theory_test_is_parsed_correctly() + public async Task Theory_test_is_parsed_correctly() { var testResult = new TestResult( "Microsoft.DotNet.Cli.MSBuild.IntegrationTests.GivenDotnetInvokesMSBuild.When_dotnet_command_invokes_msbuild_Then_env_vars_and_m_are_passed(command: \"build\")", outcome: TestOutcome.Passed); - using var _ = new AssertionScope(); - testResult.TestName.Should().Be("When_dotnet_command_invokes_msbuild_Then_env_vars_and_m_are_passed(command: \"build\")"); - testResult.Namespace.Should().Be("Microsoft.DotNet.Cli.MSBuild.IntegrationTests"); - testResult.ClassName.Should().Be("GivenDotnetInvokesMSBuild"); + await Assert.That(testResult.TestName).IsEqualTo("When_dotnet_command_invokes_msbuild_Then_env_vars_and_m_are_passed(command: \"build\")"); + await Assert.That(testResult.Namespace).IsEqualTo("Microsoft.DotNet.Cli.MSBuild.IntegrationTests"); + await Assert.That(testResult.ClassName).IsEqualTo("GivenDotnetInvokesMSBuild"); } [Test] [Arguments("Cell 1: #r \"nuget:TRexLib\"")] [Arguments("Cell 1: Console.Write(\"Hello world.\";")] - public void Inferred_properties_are_not_inferred_from_fully_qualified_test_name_if_they_do_not_match_dotnet_standards( + public async Task Inferred_properties_are_not_inferred_from_fully_qualified_test_name_if_they_do_not_match_dotnet_standards( string fullyQualifiedTestName) { var testResult = new TestResult(fullyQualifiedTestName, TestOutcome.NotExecuted); - testResult.ClassName.Should().BeNull(); - testResult.FullyQualifiedClassName.Should().BeNull(); - testResult.Namespace.Should().BeNull(); - testResult.TestName.Should().Be(fullyQualifiedTestName); + await Assert.That(testResult.ClassName).IsNull(); + await Assert.That(testResult.FullyQualifiedClassName).IsNull(); + await Assert.That(testResult.Namespace).IsNull(); + await Assert.That(testResult.TestName).IsEqualTo(fullyQualifiedTestName); } [Test] - public void Theory_test_with_dotted_param_is_parsed_correctly_when_testMethod_provided() + public async Task Theory_test_with_dotted_param_is_parsed_correctly_when_testMethod_provided() { // When testMethod is supplied the constructor must use testMethod.ClassName // directly instead of splitting the FQTN on '.'. Without the fix, a param @@ -91,22 +89,20 @@ public void Theory_test_with_dotted_param_is_parsed_correctly_when_testMethod_pr var testResult = new TestResult(fqtn, TestOutcome.Passed, testMethod: new TestMethod { ClassName = className, Name = methodName }); - using var _ = new AssertionScope(); - testResult.FullyQualifiedTestName.Should().Be(fqtn); - testResult.FullyQualifiedClassName.Should().Be(className); - testResult.ClassName.Should().Be("ParserTests"); - testResult.Namespace.Should().Be("System.CommandLine.Tests"); - testResult.TestName.Should().Be($"{methodName}(param: \"foo.bar\")"); + await Assert.That(testResult.FullyQualifiedTestName).IsEqualTo(fqtn); + await Assert.That(testResult.FullyQualifiedClassName).IsEqualTo(className); + await Assert.That(testResult.ClassName).IsEqualTo("ParserTests"); + await Assert.That(testResult.Namespace).IsEqualTo("System.CommandLine.Tests"); + await Assert.That(testResult.TestName).IsEqualTo($"{methodName}(param: \"foo.bar\")"); } [Test] - public void ToString_DoesNotThrow_ForOutcomeValueNotInEnum() + public async Task ToString_DoesNotThrow_ForOutcomeValueNotInEnum() { // TestResult.ToString() has a _ => throw arm that crashes on any enum value // not listed in its switch expression (e.g. future additions to TestOutcome, or // values written by vstest that TrxLib doesn't yet map, such as "Completed"). var testResult = new TestResult("some.namespace.SomeClass.SomeTest", (TestOutcome)99); - var act = () => testResult.ToString(); - act.Should().NotThrow(); + await Assert.That(() => testResult.ToString()).ThrowsNothing(); } -} \ No newline at end of file +} diff --git a/TrxLib.Tests/TrxLib.Tests.csproj b/TrxLib.Tests/TrxLib.Tests.csproj index cc19834..5684326 100644 --- a/TrxLib.Tests/TrxLib.Tests.csproj +++ b/TrxLib.Tests/TrxLib.Tests.csproj @@ -10,7 +10,6 @@ - diff --git a/TrxLib.Tests/TrxParserRegressionTests.cs b/TrxLib.Tests/TrxParserRegressionTests.cs index 2c4c9e5..dc13276 100644 --- a/TrxLib.Tests/TrxParserRegressionTests.cs +++ b/TrxLib.Tests/TrxParserRegressionTests.cs @@ -1,6 +1,6 @@ using System.IO; -using AwesomeAssertions; +using TUnit.Assertions; namespace TrxLib.Tests; @@ -17,11 +17,11 @@ public class TrxParserRegressionTests [Arguments("Aborted", TestOutcome.Aborted)] [Arguments("NotRunnable", TestOutcome.NotRunnable)] [Arguments(null, TestOutcome.Error)] // absent attribute = Error - public void Parse_OutcomeAttribute_RoundTrips(string? outcomeAttr, TestOutcome expected) + public async Task Parse_OutcomeAttribute_RoundTrips(string? outcomeAttr, TestOutcome expected) { using var trxFile = new TempTrxFile(MinimalTrx(outcome: outcomeAttr)); var results = TrxParser.Parse(trxFile.FileInfo); - results.Single().Outcome.Should().Be(expected); + await Assert.That(results.Single().Outcome).IsEqualTo(expected); } // TestProjectDirectory must resolve to the project root for all standard .NET SDK @@ -34,14 +34,14 @@ public void Parse_OutcomeAttribute_RoundTrips(string? outcomeAttr, TestOutcome e ]; [Test, MethodDataSource(nameof(DirectoryLayouts))] - public void Parse_TestProjectDirectory_ResolvesFromBinAnchor(string subfolder, string[] segments) + public async Task Parse_TestProjectDirectory_ResolvesFromBinAnchor(string subfolder, string[] segments) { var projectRoot = Path.GetFullPath(Path.Combine(Path.GetTempPath(), subfolder)); var codebase = Path.Combine(new[] { projectRoot }.Concat(segments).ToArray()); using var trxFile = new TempTrxFile(MinimalTrx(codeBase: codebase)); var results = TrxParser.Parse(trxFile.FileInfo); - results.Single().TestProjectDirectory!.FullName.TrimEnd(Path.DirectorySeparatorChar) - .Should().Be(projectRoot.TrimEnd(Path.DirectorySeparatorChar)); + await Assert.That(results.Single().TestProjectDirectory!.FullName.TrimEnd(Path.DirectorySeparatorChar)) + .IsEqualTo(projectRoot.TrimEnd(Path.DirectorySeparatorChar)); } // ------------------------------------------------------------------------- diff --git a/TrxLib.Tests/TrxParserTests.cs b/TrxLib.Tests/TrxParserTests.cs index f1cf6da..7f1e8db 100644 --- a/TrxLib.Tests/TrxParserTests.cs +++ b/TrxLib.Tests/TrxParserTests.cs @@ -1,8 +1,7 @@ using System.IO; using System.Runtime.InteropServices; -using AwesomeAssertions; -using AwesomeAssertions.Execution; +using TUnit.Assertions; namespace TrxLib.Tests; @@ -16,147 +15,144 @@ private static string GetSampleFilePath(string fileName) } [Test] - public void Parse_OneTestFailureTrx_ParsesClassNamesCorrectly() + public async Task Parse_OneTestFailureTrx_ParsesClassNamesCorrectly() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath("OneTestFailure.trx"))); - results.Should().HaveCount(19); - results.Select(r => r.TestMethod?.ClassName + "." + r.TestMethod?.Name ?? throw new InvalidOperationException("TestMethod is null")) - .Should() - .ContainEquivalentOf("AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_03.Tests.HelloWorldTests.Main_UpDown"); + await Assert.That(results).Count().IsEqualTo(19); + await Assert.That(results.Select(r => r.TestMethod?.ClassName + "." + r.TestMethod?.Name ?? throw new InvalidOperationException("TestMethod is null"))) + .Contains("AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_03.Tests.HelloWorldTests.Main_UpDown"); } [Test] - public void Parse_OneTestFailureTrx_ParsesTestNamesCorrectly() + public async Task Parse_OneTestFailureTrx_ParsesTestNamesCorrectly() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath("OneTestFailure.trx"))); - results.Select(r => r.FullyQualifiedTestName) - .Should() - .Contain("AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_03.Tests.HelloWorldTests.Main_UpDown"); + await Assert.That(results.Select(r => r.FullyQualifiedTestName)) + .Contains("AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_03.Tests.HelloWorldTests.Main_UpDown"); } [Test] - public void Parse_OneTestFailureTrx_CorrectlyParsesOutcomes() + public async Task Parse_OneTestFailureTrx_CorrectlyParsesOutcomes() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath("OneTestFailure.trx"))); // 19 tests in the file, 18 passed, 1 failed - results.Should().HaveCount(19); - results.Count(r => r.Outcome == TestOutcome.Passed).Should().Be(18); - results.Count(r => r.Outcome == TestOutcome.Failed).Should().Be(1); + await Assert.That(results).Count().IsEqualTo(19); + await Assert.That(results.Count(r => r.Outcome == TestOutcome.Passed)).IsEqualTo(18); + await Assert.That(results.Count(r => r.Outcome == TestOutcome.Failed)).IsEqualTo(1); } [Test] - public void Parse_OneTestFailureTrx_ParsesErrorMessageAndStackTraceCorrectly() + public async Task Parse_OneTestFailureTrx_ParsesErrorMessageAndStackTraceCorrectly() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath("OneTestFailure.trx"))); var errorTest = results.FirstOrDefault(t => t.ErrorMessage?.Contains("System.Exception") == true); - errorTest.Should().NotBeNull(); + await Assert.That(errorTest).IsNotNull(); - errorTest.ErrorMessage.Should().Contain("The expected length of 15 does not match the output length of 8."); + await Assert.That(errorTest!.ErrorMessage).Contains("The expected length of 15 does not match the output length of 8."); - errorTest.StackTrace.Should().Contain("IntelliTect.TestTools.Console.ConsoleAssert.AssertExpectation(String expectedOutput, String output, Func`3 areEquivalentOperator, String equivalentOperatorErrorMessage)"); - errorTest.StackTrace.Should().Contain("AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_03.Tests.HelloWorldTests.Main_UpDown()"); + await Assert.That(errorTest.StackTrace).Contains("IntelliTect.TestTools.Console.ConsoleAssert.AssertExpectation(String expectedOutput, String output, Func`3 areEquivalentOperator, String equivalentOperatorErrorMessage)"); + await Assert.That(errorTest.StackTrace).Contains("AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_03.Tests.HelloWorldTests.Main_UpDown()"); } [Test] - public void Parse_Example1OSXTrx_ParsesTestNamesCorrectly() + public async Task Parse_Example1OSXTrx_ParsesTestNamesCorrectly() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath(Path.Combine("1", "example1_OSX.trx")))); - results.Select(r => r.FullyQualifiedTestName) - .Should() - .Contain("Microsoft.DotNet.Cli.Utils.Tests.GivenARootedCommandResolver.It_returns_a_CommandSpec_with_CommandName_as_Path_when_CommandName_is_rooted"); + await Assert.That(results.Select(r => r.FullyQualifiedTestName)) + .Contains("Microsoft.DotNet.Cli.Utils.Tests.GivenARootedCommandResolver.It_returns_a_CommandSpec_with_CommandName_as_Path_when_CommandName_is_rooted"); } [Test] - public void Parse_Example1OSXTrx_ParsesOutcomesCorrectly() + public async Task Parse_Example1OSXTrx_ParsesOutcomesCorrectly() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath(Path.Combine("1", "example1_OSX.trx")))); // 88 tests in the file, 83 passed, 4 not executed, 1 failed - results.Should().HaveCount(88); - results.Count(r => r.Outcome == TestOutcome.Passed).Should().Be(83); - results.Count(r => r.Outcome == TestOutcome.NotExecuted).Should().Be(4); - results.Count(r => r.Outcome == TestOutcome.Failed).Should().Be(1); + await Assert.That(results).Count().IsEqualTo(88); + await Assert.That(results.Count(r => r.Outcome == TestOutcome.Passed)).IsEqualTo(83); + await Assert.That(results.Count(r => r.Outcome == TestOutcome.NotExecuted)).IsEqualTo(4); + await Assert.That(results.Count(r => r.Outcome == TestOutcome.Failed)).IsEqualTo(1); } [Test] - public void Parse_ComplexTrx_ParsesErrorMessageAndStackTraceCorrectly() + public async Task Parse_ComplexTrx_ParsesErrorMessageAndStackTraceCorrectly() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath("complex.trx"))); var errorTest = results.FirstOrDefault(t => t.ErrorMessage?.Contains("Index (zero based)") == true); - errorTest.Should().NotBeNull(); - errorTest.StackTrace.Should().Contain("System.Text.StringBuilder.AppendFormatHelper"); + await Assert.That(errorTest).IsNotNull(); + await Assert.That(errorTest!.StackTrace).Contains("System.Text.StringBuilder.AppendFormatHelper"); } [Test] - public void Parse_ComplexTrx_ParsesStdOutCorrectly() + public async Task Parse_ComplexTrx_ParsesStdOutCorrectly() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath("complex.trx"))); var stdOutTest = results.FirstOrDefault(t => t.FullyQualifiedTestName == "System.CommandLine.Tests.ParserTests.Option_arguments_can_match_subcommands"); - stdOutTest.Should().NotBeNull(); - stdOutTest.StdOut.Should().Contain("ParseResult: ![ testhost.net462.x86"); + await Assert.That(stdOutTest).IsNotNull(); + await Assert.That(stdOutTest!.StdOut).Contains("ParseResult: ![ testhost.net462.x86"); } [Test] - public void Parse_Example1WindowsTrx_ParsesDurationsCorrectly() + public async Task Parse_Example1WindowsTrx_ParsesDurationsCorrectly() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath(Path.Combine("example1_Windows.trx")))); var test = results.Single(r => r.FullyQualifiedTestName == "Microsoft.DotNet.Cli.Sln.Internal.Tests.GivenAnSlnFile.WhenGivenAValidPathItReadsAnSlnFile"); - test.Duration.Should().Be(TimeSpan.FromMilliseconds(138)); + await Assert.That(test.Duration).IsEqualTo(TimeSpan.FromMilliseconds(138)); } [Test] - public void Parse_Example1WindowsTrx_ParsesStartTimesCorrectly() + public async Task Parse_Example1WindowsTrx_ParsesStartTimesCorrectly() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath(Path.Combine("example1_Windows.trx")))); var test = results.Single(r => r.FullyQualifiedTestName == "Microsoft.DotNet.Cli.Sln.Internal.Tests.GivenAnSlnFile.WhenGivenAValidPathItReadsAnSlnFile"); - test.StartTime.Should().Be(DateTimeOffset.Parse("2016-12-21T11:15:51.8308573-08:00")); + await Assert.That(test.StartTime).IsEqualTo(DateTimeOffset.Parse("2016-12-21T11:15:51.8308573-08:00")); } [Test] - public void Parse_Example1WindowsTrx_ParsesEndTimesCorrectly() + public async Task Parse_Example1WindowsTrx_ParsesEndTimesCorrectly() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath(Path.Combine("example1_Windows.trx")))); var test = results.Single(r => r.FullyQualifiedTestName == "Microsoft.DotNet.Cli.Sln.Internal.Tests.GivenAnSlnFile.WhenGivenAValidPathItReadsAnSlnFile"); - test.EndTime.Should().Be(DateTimeOffset.Parse("2016-12-21T11:15:51.8308573-08:00")); + await Assert.That(test.EndTime).IsEqualTo(DateTimeOffset.Parse("2016-12-21T11:15:51.8308573-08:00")); } [Test] - public void Parse_Example1WindowsTrx_ParsesPassOutcomeCorrectly() + public async Task Parse_Example1WindowsTrx_ParsesPassOutcomeCorrectly() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath(Path.Combine("example1_Windows.trx")))); var test = results.Single(r => r.FullyQualifiedTestName == "Microsoft.DotNet.Cli.Sln.Internal.Tests.GivenAnSlnFile.WhenGivenAValidPathItReadsAnSlnFile"); - test.Outcome.Should().Be(TestOutcome.Passed); + await Assert.That(test.Outcome).IsEqualTo(TestOutcome.Passed); } [Test] - public void Parse_Example1WindowsTrx_ParsesFailOutcomeCorrectly() + public async Task Parse_Example1WindowsTrx_ParsesFailOutcomeCorrectly() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath(Path.Combine("example1_Windows.trx")))); var test = results.Single(r => r.FullyQualifiedTestName == "Microsoft.DotNet.Cli.Sln.Internal.Tests.GivenAnSlnFile.WhenGivenAValidPathItReadsModifiesThenWritesAnSln"); - test.Outcome.Should().Be(TestOutcome.Failed); + await Assert.That(test.Outcome).IsEqualTo(TestOutcome.Failed); } [Test, WindowsOnly] - public void Parse_Example1WindowsTrx_ParsesTestProjectDirectoryCorrectly() + public async Task Parse_Example1WindowsTrx_ParsesTestProjectDirectoryCorrectly() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath(Path.Combine("example1_Windows.trx")))); var test = results.Single(r => r.FullyQualifiedTestName == "Microsoft.DotNet.Cli.Sln.Internal.Tests.GivenAnSlnFile.WhenGivenAValidPathItReadsModifiesThenWritesAnSln"); - test.TestProjectDirectory?.FullName.Should().Be(@"C:\dev\github\cli\test\Microsoft.DotNet.Cli.Sln.Internal.Tests"); + await Assert.That(test.TestProjectDirectory?.FullName).IsEqualTo(@"C:\dev\github\cli\test\Microsoft.DotNet.Cli.Sln.Internal.Tests"); } [Test, WindowsOnly] - public void Parse_Example1WindowsTrx_ParsesCodebaseCorrectly() + public async Task Parse_Example1WindowsTrx_ParsesCodebaseCorrectly() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath(Path.Combine("example1_Windows.trx")))); var test = results.Single(r => r.FullyQualifiedTestName == "Microsoft.DotNet.Cli.Sln.Internal.Tests.GivenAnSlnFile.WhenGivenAValidPathItReadsModifiesThenWritesAnSln"); - test.Codebase?.FullName.Should().Be(@"C:\dev\github\cli\test\Microsoft.DotNet.Cli.Sln.Internal.Tests\bin\Debug\netcoreapp1.0\Microsoft.DotNet.Cli.Sln.Internal.Tests.dll"); + await Assert.That(test.Codebase?.FullName).IsEqualTo(@"C:\dev\github\cli\test\Microsoft.DotNet.Cli.Sln.Internal.Tests\bin\Debug\netcoreapp1.0\Microsoft.DotNet.Cli.Sln.Internal.Tests.dll"); } [Test, NonWindowsOnly] - public void Parse_Example1OSXTrx_ParsesTestProjectDirectoryCorrectly() + public async Task Parse_Example1OSXTrx_ParsesTestProjectDirectoryCorrectly() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath(Path.Combine("1", "example1_OSX.trx")))); var test = results.Single(r => r.FullyQualifiedTestName == "Microsoft.DotNet.Cli.Utils.Tests.GivenARootedCommandResolver.It_escapes_CommandArguments_when_returning_a_CommandSpec"); - test.TestProjectDirectory?.FullName.Should().Be(@"/Users/josequ/dev/cli/test/Microsoft.DotNet.Cli.Utils.Tests"); + await Assert.That(test.TestProjectDirectory?.FullName).IsEqualTo(@"/Users/josequ/dev/cli/test/Microsoft.DotNet.Cli.Utils.Tests"); } private static bool IsWindows() @@ -170,39 +166,37 @@ private static bool NotWindows() } [Test] - public void Parse_TheoryTestsTrx_AppendsSuffixToFqtnForParameterizedTests() + public async Task Parse_TheoryTestsTrx_AppendsSuffixToFqtnForParameterizedTests() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath("theory-tests.trx"))); - results.Select(r => r.FullyQualifiedTestName) - .Should() - .Contain("Acme.Tests.MathTests.AddNumbers(left: 1, right: 2)"); - results.Select(r => r.FullyQualifiedTestName) - .Should() - .Contain("Acme.Tests.MathTests.AddNumbers(left: 0, right: 0)"); + await Assert.That(results.Select(r => r.FullyQualifiedTestName)) + .Contains("Acme.Tests.MathTests.AddNumbers(left: 1, right: 2)"); + await Assert.That(results.Select(r => r.FullyQualifiedTestName)) + .Contains("Acme.Tests.MathTests.AddNumbers(left: 0, right: 0)"); } [Test] - public void Parse_TheoryTestsTrx_DoesNotAppendSuffixForNonParameterizedTest() + public async Task Parse_TheoryTestsTrx_DoesNotAppendSuffixForNonParameterizedTest() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath("theory-tests.trx"))); - results.Single(r => r.FullyQualifiedTestName == "Acme.Tests.MathTests.PlainTest") - .Should().NotBeNull(); + await Assert.That(results.Single(r => r.FullyQualifiedTestName == "Acme.Tests.MathTests.PlainTest")) + .IsNotNull(); } [Test] - public void Parse_TheoryTestsTrx_ParsesAllThreeTestResults() + public async Task Parse_TheoryTestsTrx_ParsesAllThreeTestResults() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath("theory-tests.trx"))); - results.Should().HaveCount(3); - results.Count(r => r.Outcome == TestOutcome.Passed).Should().Be(3); + await Assert.That(results).Count().IsEqualTo(3); + await Assert.That(results.Count(r => r.Outcome == TestOutcome.Passed)).IsEqualTo(3); } [Test, NonWindowsOnly] - public void Parse_Example1OSXTrx_ParsesCodebaseCorrectly() + public async Task Parse_Example1OSXTrx_ParsesCodebaseCorrectly() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath(Path.Combine("1", "example1_OSX.trx")))); var test = results.Single(r => r.FullyQualifiedTestName == "Microsoft.DotNet.Cli.Utils.Tests.GivenARootedCommandResolver.It_escapes_CommandArguments_when_returning_a_CommandSpec"); - test.Codebase?.FullName.Should().Be(@"/Users/josequ/dev/cli/test/Microsoft.DotNet.Cli.Utils.Tests/bin/Debug/netcoreapp1.0/Microsoft.DotNet.Cli.Utils.Tests.dll"); + await Assert.That(test.Codebase?.FullName).IsEqualTo(@"/Users/josequ/dev/cli/test/Microsoft.DotNet.Cli.Utils.Tests/bin/Debug/netcoreapp1.0/Microsoft.DotNet.Cli.Utils.Tests.dll"); } // ── Parser regression tests ────────────────────────────────────────────────── @@ -210,101 +204,99 @@ public void Parse_Example1OSXTrx_ParsesCodebaseCorrectly() // previously silently discarded. All tests below should be GREEN. [Test] - public void Parse_OneTestFailureTrx_PopulatesTestRunId() + public async Task Parse_OneTestFailureTrx_PopulatesTestRunId() { // TestResultSet.TestRunId is never assigned; parser must set it from TestRun.Id. var results = TrxParser.Parse(new FileInfo(GetSampleFilePath("OneTestFailure.trx"))); - results.TestRunId.Should().Be("a1293f2f-ba2d-4aa4-91a7-ceed97fd4735"); + await Assert.That(results.TestRunId).IsEqualTo("a1293f2f-ba2d-4aa4-91a7-ceed97fd4735"); } [Test] - public void Parse_OneTestFailureTrx_ParsesRunUser() + public async Task Parse_OneTestFailureTrx_ParsesRunUser() { // runUser attribute on is present in every TRX file but currently not parsed. var results = TrxParser.Parse(new FileInfo(GetSampleFilePath("OneTestFailure.trx"))); - results.OriginalTestRun.Should().NotBeNull(); - results.OriginalTestRun!.RunUser.Should().Be("BenjaminMichaelis"); + await Assert.That(results.OriginalTestRun).IsNotNull(); + await Assert.That(results.OriginalTestRun!.RunUser).IsEqualTo("BenjaminMichaelis"); } [Test] - public void Parse_OneTestFailureTrx_ParsesResultSummaryOutcome() + public async Task Parse_OneTestFailureTrx_ParsesResultSummaryOutcome() { // is present in every TRX file but currently not parsed. var results = TrxParser.Parse(new FileInfo(GetSampleFilePath("OneTestFailure.trx"))); - results.OriginalTestRun.Should().NotBeNull(); - results.OriginalTestRun!.ResultSummary.Should().NotBeNull(); - results.OriginalTestRun!.ResultSummary!.Outcome.Should().Be("Failed"); + await Assert.That(results.OriginalTestRun).IsNotNull(); + await Assert.That(results.OriginalTestRun!.ResultSummary).IsNotNull(); + await Assert.That(results.OriginalTestRun!.ResultSummary!.Outcome).IsEqualTo("Failed"); } [Test] - public void Parse_OneTestFailureTrx_ParsesCountersTotals() + public async Task Parse_OneTestFailureTrx_ParsesCountersTotals() { // inside but currently not parsed. var results = TrxParser.Parse(new FileInfo(GetSampleFilePath("OneTestFailure.trx"))); - results.OriginalTestRun.Should().NotBeNull(); + await Assert.That(results.OriginalTestRun).IsNotNull(); var counters = results.OriginalTestRun!.ResultSummary?.Counters; - counters.Should().NotBeNull(); - using var _ = new AssertionScope(); - counters!.Total.Should().Be(19); - counters.Passed.Should().Be(18); - counters.Failed.Should().Be(1); - counters.Executed.Should().Be(19); + await Assert.That(counters).IsNotNull(); + await Assert.That(counters!.Total).IsEqualTo(19); + await Assert.That(counters.Passed).IsEqualTo(18); + await Assert.That(counters.Failed).IsEqualTo(1); + await Assert.That(counters.Executed).IsEqualTo(19); } [Test] - public void Parse_OneTestFailureTrx_ParsesTestLists() + public async Task Parse_OneTestFailureTrx_ParsesTestLists() { // always has two default entries but currently not parsed. var results = TrxParser.Parse(new FileInfo(GetSampleFilePath("OneTestFailure.trx"))); - results.OriginalTestRun.Should().NotBeNull(); + await Assert.That(results.OriginalTestRun).IsNotNull(); var testLists = results.OriginalTestRun!.TestLists?.Items; - testLists.Should().NotBeNull(); - testLists.Should().HaveCount(2); - testLists.Should().ContainSingle(l => l.Name == "Results Not in a List" && l.Id == "8c84fa94-04c1-424b-9868-57a2d4851a1d"); - testLists.Should().ContainSingle(l => l.Name == "All Loaded Results" && l.Id == "19431567-8539-422a-85d7-44ee4e166bda"); + await Assert.That(testLists).IsNotNull(); + await Assert.That(testLists!).Count().IsEqualTo(2); + await Assert.That(testLists).HasSingleItem(l => l.Name == "Results Not in a List" && l.Id == "8c84fa94-04c1-424b-9868-57a2d4851a1d"); + await Assert.That(testLists).HasSingleItem(l => l.Name == "All Loaded Results" && l.Id == "19431567-8539-422a-85d7-44ee4e166bda"); } [Test] - public void Parse_OneTestFailureTrx_ParsesTestEntries() + public async Task Parse_OneTestFailureTrx_ParsesTestEntries() { // is present in every TRX file but currently not parsed. var results = TrxParser.Parse(new FileInfo(GetSampleFilePath("OneTestFailure.trx"))); - results.OriginalTestRun.Should().NotBeNull(); + await Assert.That(results.OriginalTestRun).IsNotNull(); var entries = results.OriginalTestRun!.TestEntries?.Items; - entries.Should().NotBeNull(); - entries.Should().HaveCount(19); + await Assert.That(entries).IsNotNull(); + await Assert.That(entries!).Count().IsEqualTo(19); // Spot-check one entry links testId -> executionId -> testListId correctly. - entries.Should().ContainSingle(e => + await Assert.That(entries).HasSingleItem(e => e.TestId == "35e9c03c-7c18-2ee8-7216-91e69cfe406e" && e.ExecutionId == "9682c228-090a-47f3-96d2-26ffa23c9a53" && e.TestListId == "8c84fa94-04c1-424b-9868-57a2d4851a1d"); } [Test] - public void Parse_OneTestFailureTrx_ParsesUnitTestResultExecutionId() + public async Task Parse_OneTestFailureTrx_ParsesUnitTestResultExecutionId() { // executionId attribute on is present in every TRX but currently not parsed. var results = TrxParser.Parse(new FileInfo(GetSampleFilePath("OneTestFailure.trx"))); - results.OriginalTestRun.Should().NotBeNull(); + await Assert.That(results.OriginalTestRun).IsNotNull(); var rawResults = results.OriginalTestRun!.Results?.UnitTestResults; - rawResults.Should().NotBeNull(); - rawResults.Should().ContainSingle(r => r.ExecutionId == "9682c228-090a-47f3-96d2-26ffa23c9a53"); + await Assert.That(rawResults).IsNotNull(); + await Assert.That(rawResults!).HasSingleItem(r => r.ExecutionId == "9682c228-090a-47f3-96d2-26ffa23c9a53"); } [Test] - public void Parse_OneTestFailureTrx_ParsesUnitTestDefinitionAttributes() + public async Task Parse_OneTestFailureTrx_ParsesUnitTestDefinitionAttributes() { // Both storage and are on but currently not parsed. var results = TrxParser.Parse(new FileInfo(GetSampleFilePath("OneTestFailure.trx"))); var unitTests = results.OriginalTestRun?.TestDefinitions?.UnitTests; - unitTests.Should().NotBeNull(); - using var _ = new AssertionScope(); - unitTests.Should().Contain(u => u.Storage == @"essentialcsharp\src\chapter01.tests\bin\debug\net6.0\chapter01.tests.dll"); - unitTests.Should().Contain(u => u.Execution != null && u.Execution.Id == "86ff1fe0-ef46-4281-b70a-7ecc3ed2376b"); + await Assert.That(unitTests).IsNotNull(); + await Assert.That(unitTests!).Contains(u => u.Storage == @"essentialcsharp\src\chapter01.tests\bin\debug\net6.0\chapter01.tests.dll"); + await Assert.That(unitTests).Contains(u => u.Execution != null && u.Execution.Id == "86ff1fe0-ef46-4281-b70a-7ecc3ed2376b"); } [Test] - public void Parse_ComplexTrx_FullyQualifiedTestNameIncludesTheoryParameters() + public async Task Parse_ComplexTrx_FullyQualifiedTestNameIncludesTheoryParameters() { // The parser builds FQTN from ClassName.Name, discarding the (params) suffix from testName. // For theory tests every invocation gets the same FQTN, making distinct runs indistinguishable. @@ -313,96 +305,95 @@ public void Parse_ComplexTrx_FullyQualifiedTestNameIncludesTheoryParameters() "System.CommandLine.Tests.ParserTests+MultiplePositions" + ".When_an_option_is_shared_between_an_outer_and_inner_command_then_specifying_in_one_does_not_result_in_error_on_other" + "(commandLine: \"outer --the-option xyz inner\")"; - results.Select(r => r.FullyQualifiedTestName).Should().Contain(expectedFqtn); + await Assert.That(results.Select(r => r.FullyQualifiedTestName)).Contains(expectedFqtn); } [Test] - public void Parse_Example2WindowsTrx_TestsDoNotAppearWithMoreThanOneOutcome() + public async Task Parse_Example2WindowsTrx_TestsDoNotAppearWithMoreThanOneOutcome() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath(Path.Combine("2", "example2_Windows.trx")))); var recombinedCount = results.Count(r => r.Outcome == TestOutcome.Passed) + results.Count(r => r.Outcome == TestOutcome.Failed) + results.Count(r => r.Outcome == TestOutcome.NotExecuted); - results.Count.Should().Be(recombinedCount); + await Assert.That(results.Count).IsEqualTo(recombinedCount); } // ── Regression tests ───────────────────────────────────────────────────────── [Test] - public void Parse_AbortedRunTrx_ParsesRealAbortedRunFixture() + public async Task Parse_AbortedRunTrx_ParsesRealAbortedRunFixture() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath("aborted-outcome.trx"))); - results.Should().HaveCount(1); - results.Single().Outcome.Should().Be(TestOutcome.Passed); - results.OriginalTestRun?.ResultSummary?.Outcome.Should().Be("Failed"); + await Assert.That(results).Count().IsEqualTo(1); + await Assert.That(results.Single().Outcome).IsEqualTo(TestOutcome.Passed); + await Assert.That(results.OriginalTestRun?.ResultSummary?.Outcome).IsEqualTo("Failed"); } // Real NUnit TRX captured without xmlns on the root element, sourced from: // https://github.com/joaoopereira/dotnet-test-rerun/blob/main/test/dotnet-test-rerun.UnitTests/Fixtures/RerunCommand/NUnitTrxFileWithOneFailedTest.trx [Test] - public void Parse_NoNamespaceTrx_ParsesResultsWithoutNamespace() + public async Task Parse_NoNamespaceTrx_ParsesResultsWithoutNamespace() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath("no-namespace.trx"))); - results.Should().HaveCount(5, - "the parser must fall back to namespace-agnostic element matching when xmlns is absent"); + await Assert.That(results).Count().IsEqualTo(5).Because("the parser must fall back to namespace-agnostic element matching when xmlns is absent"); } [Test] - public void Parse_ComplexTrx_ParsesTestRunNameCorrectly() + public async Task Parse_ComplexTrx_ParsesTestRunNameCorrectly() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath("complex.trx"))); - results.TestRunName.Should().Be("josequ@JOSEQU10 2022-06-13 12:30:01"); + await Assert.That(results.TestRunName).IsEqualTo("josequ@JOSEQU10 2022-06-13 12:30:01"); } [Test] - public void Parse_Example1OSXTrx_ParsesTestRunIdCorrectly() + public async Task Parse_Example1OSXTrx_ParsesTestRunIdCorrectly() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath(Path.Combine("1", "example1_OSX.trx")))); - results.OriginalTestRun.Should().NotBeNull(); - results.OriginalTestRun?.Id.Should().Be("c6378a10-566e-4745-8f62-ed85e8dc7147"); + await Assert.That(results.OriginalTestRun).IsNotNull(); + await Assert.That(results.OriginalTestRun?.Id).IsEqualTo("c6378a10-566e-4745-8f62-ed85e8dc7147"); } [Test] - public void Parse_Example1OSXTrx_ParsesDeploymentRootCorrectly() + public async Task Parse_Example1OSXTrx_ParsesDeploymentRootCorrectly() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath(Path.Combine("1", "example1_OSX.trx")))); - results.OriginalTestRun.Should().NotBeNull(); - results.OriginalTestRun?.TestSettings?.Deployment?.RunDeploymentRoot.Should().Be("_josequMac 2017-01-17 10:39:30"); + await Assert.That(results.OriginalTestRun).IsNotNull(); + await Assert.That(results.OriginalTestRun?.TestSettings?.Deployment?.RunDeploymentRoot).IsEqualTo("_josequMac 2017-01-17 10:39:30"); } [Test] - public void Parse_Example1OSXTrx_ParsesTestSettingsNameCorrectly() + public async Task Parse_Example1OSXTrx_ParsesTestSettingsNameCorrectly() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath(Path.Combine("1", "example1_OSX.trx")))); - results.OriginalTestRun.Should().NotBeNull(); - results.OriginalTestRun?.TestSettings?.Name.Should().Be("default"); + await Assert.That(results.OriginalTestRun).IsNotNull(); + await Assert.That(results.OriginalTestRun?.TestSettings?.Name).IsEqualTo("default"); } [Test] - public void Parse_Example1OSXTrx_ParsesCreationTimeCorrectly() + public async Task Parse_Example1OSXTrx_ParsesCreationTimeCorrectly() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath(Path.Combine("1", "example1_OSX.trx")))); - results.CreatedTime.Should().Be(DateTimeOffset.Parse("2017-01-17T10:39:30.9542170-08:00")); + await Assert.That(results.CreatedTime).IsEqualTo(DateTimeOffset.Parse("2017-01-17T10:39:30.9542170-08:00")); } [Test] - public void Parse_Example1OSXTrx_ParsesQueueingTimeCorrectly() + public async Task Parse_Example1OSXTrx_ParsesQueueingTimeCorrectly() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath(Path.Combine("1", "example1_OSX.trx")))); - results.QueuedTime.Should().Be(DateTimeOffset.Parse("2017-01-17T10:39:30.9542630-08:00")); + await Assert.That(results.QueuedTime).IsEqualTo(DateTimeOffset.Parse("2017-01-17T10:39:30.9542630-08:00")); } [Test] - public void Parse_Example1OSXTrx_ParsesStartTimeCorrectly() + public async Task Parse_Example1OSXTrx_ParsesStartTimeCorrectly() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath(Path.Combine("1", "example1_OSX.trx")))); - results.StartedTime.Should().Be(DateTimeOffset.Parse("2017-01-17T10:39:27.7784340-08:00")); + await Assert.That(results.StartedTime).IsEqualTo(DateTimeOffset.Parse("2017-01-17T10:39:27.7784340-08:00")); } [Test] - public void Parse_Example1OSXTrx_ParsesFinishTimeCorrectly() + public async Task Parse_Example1OSXTrx_ParsesFinishTimeCorrectly() { var results = TrxParser.Parse(new FileInfo(GetSampleFilePath(Path.Combine("1", "example1_OSX.trx")))); - results.CompletedTime.Should().Be(DateTimeOffset.Parse("2017-01-17T10:39:57.1294340-08:00")); + await Assert.That(results.CompletedTime).IsEqualTo(DateTimeOffset.Parse("2017-01-17T10:39:57.1294340-08:00")); } }