Migrate Microsoft.TemplateEngine.Utils.UnitTests to MSTest.Sdk on MTP#54759
Open
Evangelink wants to merge 1 commit into
Open
Migrate Microsoft.TemplateEngine.Utils.UnitTests to MSTest.Sdk on MTP#54759Evangelink wants to merge 1 commit into
Evangelink wants to merge 1 commit into
Conversation
Switches the project SDK to MSTest.Sdk so it picks up MSTest 4.x + Microsoft.Testing.Platform (MTP) defaults instead of xUnit v3 + VSTest. - csproj: <Project Sdk="MSTest.Sdk">, IsTestProject=true, ImplicitUsings=enable. Drop the explicit xunit.v3.extensibility.core and AwesomeAssertions PackageReferences (the latter is now added by test/Directory.Build.targets for MSTest.Sdk projects). - Convert xUnit attributes/assertions to MSTest equivalents: [Fact]/[Fact(DisplayName=...)] -> [TestMethod] [Theory] [InlineData] -> [TestMethod] [DataRow] [MemberData(nameof(X))] -> [DynamicData(nameof(X))] Assert.True/False -> Assert.IsTrue/IsFalse Assert.Equal/NotEqual -> Assert.AreEqual/AreNotEqual Assert.Null/NotNull -> Assert.IsNull/IsNotNull Assert.Single(coll, pred) -> Assert.AreEqual(1, coll.Count(pred)) TestContext.Current.CancellationToken -> TestContext.CancellationTokenSource.Token DirectedGraphTests keeps its existing FluentAssertions (AwesomeAssertions) usage; the global "using FluentAssertions" is provided by the repo Directory.Build.targets. - IClassFixture<EnvironmentSettingsHelper> replacement: MSTest has no IClassFixture equivalent. DefaultTemplatePackageProviderTests and InstallRequestPathResolutionTests now hold a lazily-initialized static EnvironmentSettingsHelper per class (matching the per-class lifetime xUnit's IClassFixture provided) and dispose it in [ClassCleanup]. Tests still call CreateEnvironment from a [TestInitialize] hook to preserve per-test virtualization. - Add a small NullMessageSink : Xunit.Sdk.IMessageSink so EnvironmentSettingsHelper's constructor (which requires an xUnit IMessageSink) can be satisfied without a running xUnit host. The xUnit types are still reachable transitively through the Microsoft.TemplateEngine.TestHelper project reference, which is consumed by other in-tree xUnit projects and intentionally left untouched as part of this migration. - Add a minimal GlobalUsings.cs that aliases Xunit.Sdk.IMessageSink / IMessageSinkMessage so NullMessageSink compiles without dragging in xUnit's full global using set (which would conflict with MSTest's global Assert). Verification: - build.cmd -projects ...Microsoft.TemplateEngine.Utils.UnitTests.csproj succeeds with 0 warnings / 0 errors on net11.0 and net481. - The produced executable is an MTP host; Microsoft.TemplateEngine.Utils.UnitTests.dll --list-tests discovers all 120 tests (theory rows expanded).
Contributor
There was a problem hiding this comment.
Pull request overview
Migrates Microsoft.TemplateEngine.Utils.UnitTests from xUnit v3 to MSTest.Sdk on Microsoft.Testing.Platform by updating the test project configuration and converting test attributes/assertions and shared test infrastructure usage to MSTest equivalents.
Changes:
- Switch test project SDK to
MSTest.Sdkand remove xUnit/AwesomeAssertions direct package references. - Convert xUnit
[Fact]/[Theory]/[MemberData]and assertions to MSTest[TestMethod]/[DataRow]/[DynamicData]andAssert.*. - Add an xUnit
IMessageSinkbridge (NullMessageSink) + aliases (GlobalUsings.cs) to continue usingEnvironmentSettingsHelperwithout a running xUnit host.
Show a summary per file
| File | Description |
|---|---|
| test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/Microsoft.TemplateEngine.Utils.UnitTests.csproj | Switches project to MSTest.Sdk and adjusts basic test project properties. |
| test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/GlobalUsings.cs | Adds global aliases for xUnit sink types to avoid pulling xUnit global usings. |
| test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/NullMessageSink.cs | Adds a no-op xUnit IMessageSink implementation for EnvironmentSettingsHelper. |
| test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/DefaultTemplatePackageProviderTests.cs | Converts fixture pattern and assertions; uses MSTest TestContext. |
| test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/InstallRequestPathResolutionTests.cs | Converts fixture pattern and assertions to MSTest. |
| test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/DirectedGraphTests.cs | Converts data-driven tests from xUnit theories to MSTest DynamicData. |
| test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/CombinedListTests.cs | Converts xUnit theory to MSTest data-driven test via DataRow. |
| test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/VersionStringTests.cs | Converts xUnit theories/assertions to MSTest equivalents. |
| test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/ListExtensionsTests.cs | Converts xUnit fact/assertions to MSTest and replaces Assert.Single usage. |
| test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/EqualityExtensionsTests.cs | Converts xUnit facts/assertions to MSTest equivalents. |
| test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/GlobTests.cs | Converts xUnit facts/assertions to MSTest equivalents. |
| test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/InMemoryFileSystemTests.cs | Converts xUnit fact/assertions to MSTest equivalents. |
| test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/WellKnownSearchFiltersTests.cs | Converts xUnit theories/assertions to MSTest DataRow + Assert.AreEqual. |
Copilot's findings
Comments suppressed due to low confidence (1)
test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/InstallRequestPathResolutionTests.cs:100
- File.Create returns a FileStream that must be disposed. Leaving these streams open can leak handles and may prevent deleting the temp directory on Windows.
var testRootDir = TestUtils.CreateTemporaryFolder();
File.Create(Path.Combine(testRootDir, "1.nupkg"));
File.Create(Path.Combine(testRootDir, "2.nupkg"));
File.Create(Path.Combine(testRootDir, "3.txt"));
- Files reviewed: 13/13 changed files
- Comments generated: 5
Comment on lines
+86
to
88
| [TestMethod] | ||
| [DynamicData(nameof(DirectedGraphHasCycleData))] | ||
| public void HasCycleTests(Dictionary<int, HashSet<int>> dependencies, bool shouldHaveCycle, IReadOnlyList<int> expectedCycle, IReadOnlyList<int> unused) |
Comment on lines
+95
to
97
| [TestMethod] | ||
| [DynamicData(nameof(DirectedGraphHasCycleData))] | ||
| public void EnumerateTopologicalSortTests(Dictionary<int, HashSet<int>> dependencies, bool shouldHaveCycle, IReadOnlyList<int> unused, IReadOnlyList<int> expectedOrder) |
Comment on lines
+211
to
213
| [TestMethod] | ||
| [DynamicData(nameof(DirectedGraphSubgraphData))] | ||
| public void GetSubGraphDependandOnVerticesTests(Dictionary<int, HashSet<int>> dependencies, IReadOnlyList<int> vertices, bool includeSeedVertices, Dictionary<int, HashSet<int>> expectedResult) |
Comment on lines
49
to
52
|
|
||
| var provider = new DefaultTemplatePackageProvider(null!, _engineEnvironmentSettings, nupkgs, folders); | ||
| var sources = await provider.GetAllTemplatePackagesAsync(TestContext.Current.CancellationToken); | ||
| var sources = await provider.GetAllTemplatePackagesAsync(TestContext.CancellationTokenSource.Token); | ||
|
|
Comment on lines
131
to
133
| Directory.CreateDirectory(Path.Combine(testRootDir, "dir")); | ||
| File.Create(Path.Combine(testRootDir, "dir", "1.nupkg")); | ||
| File.Create(Path.Combine(testRootDir, "dir", "2.nupkg")); |
This was referenced Jun 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Migrates the
Microsoft.TemplateEngine.Utils.UnitTestsproject from xUnit v3 to MSTest.Sdk on Microsoft.Testing.Platform (MTP). Follows the same pattern as #54758.Changes
MSTest.Sdk(drops the explicitxunit.v3.extensibility.coreandAwesomeAssertionsPackageReferences — the latter is now provided bytest/Directory.Build.targetsfor MSTest.Sdk projects).[Fact]/[Fact(DisplayName=...)]→[TestMethod][Theory] [InlineData]→[TestMethod] [DataRow][MemberData(nameof(X))]→[DynamicData(nameof(X))]Assert.True/Assert.False→Assert.IsTrue/Assert.IsFalseAssert.Equal/Assert.NotEqual→Assert.AreEqual/Assert.AreNotEqualAssert.Null/Assert.NotNull→Assert.IsNull/Assert.IsNotNullAssert.Single(coll, pred)→Assert.AreEqual(1, coll.Count(pred))TestContext.Current.CancellationToken→TestContext.CancellationTokenSource.TokenDirectedGraphTestskeeps its existing FluentAssertions usage; the globalusing FluentAssertionsis provided by the repo-widetest/Directory.Build.targets.IClassFixture replacement
MSTest has no
IClassFixture<T>equivalent.DefaultTemplatePackageProviderTestsandInstallRequestPathResolutionTestsnow hold a lazily-initialized staticEnvironmentSettingsHelperper class (matching the per-class lifetimeIClassFixtureprovides) and dispose it in[ClassCleanup]. Each test still callsCreateEnvironmentfrom a[TestInitialize]hook to preserve per-test virtualization.Bridging the xUnit
IMessageSinkconstructor requirementEnvironmentSettingsHelperlives in the sharedMicrosoft.TemplateEngine.TestHelperproject (consumed by other in-tree xUnit projects and intentionally left untouched as part of this migration). Its constructor takes anXunit.Sdk.IMessageSink.NullMessageSink : Xunit.Sdk.IMessageSinkis added so the helper can be constructed without a running xUnit host.GlobalUsings.csaliasesXunit.Sdk.IMessageSink/IMessageSinkMessageso the file compiles without dragging xUnit's full global using set (which would conflict with MSTest's globalAssert). The xUnit types remain reachable transitively through theMicrosoft.TemplateEngine.TestHelperproject reference.Verification
./build.cmd -projects test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/Microsoft.TemplateEngine.Utils.UnitTests.csprojsucceeds with 0 warnings / 0 errors on bothnet11.0andnet481.Microsoft.TemplateEngine.Utils.UnitTests.dll --list-testsdiscovers all 120 tests (theory rows expanded).Part of the larger MSTest migration effort.
cc @Evangelink