Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
This would typically list all NuGet packages used within this solution.
-->
<ItemGroup>
<PackageVersion Include="AwesomeAssertions" Version="9.4.0" />
<PackageVersion Include="IntelliTect.Multitool" Version="2.0.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="10.0.203" />
<PackageVersion Include="Moq" Version="4.20.70" />
Expand Down
56 changes: 26 additions & 30 deletions TrxLib.Tests/TestResultTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AwesomeAssertions;
using AwesomeAssertions.Execution;
using TUnit.Assertions;

namespace TrxLib.Tests;

Expand All @@ -9,77 +8,76 @@ 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]
[Arguments("namespace.class.test", "namespace.class")]
[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
Expand All @@ -91,12 +89,11 @@ 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]
Expand All @@ -106,7 +103,6 @@ public void ToString_DoesNotThrow_ForOutcomeValueNotInEnum()
// 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<ArgumentOutOfRangeException>();
_ = testResult.ToString();
Comment thread
BenjaminMichaelis marked this conversation as resolved.
Outdated
}
}
}
1 change: 0 additions & 1 deletion TrxLib.Tests/TrxLib.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AwesomeAssertions" />
<PackageReference Include="IntelliTect.Multitool" />
<PackageReference Include="TUnit" />
</ItemGroup>
Expand Down
12 changes: 6 additions & 6 deletions TrxLib.Tests/TrxParserRegressionTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.IO;

using AwesomeAssertions;
using TUnit.Assertions;

namespace TrxLib.Tests;

Expand All @@ -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
Expand All @@ -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));
}

// -------------------------------------------------------------------------
Expand Down
Loading
Loading