Skip to content

Migrate Microsoft.TemplateSearch.Common.UnitTests to MSTest.Sdk on MTP - #54787

Merged
Evangelink merged 4 commits into
dotnet:mainfrom
Evangelink:evangelink/mstest-mtp-templatesearch-common
Jun 17, 2026
Merged

Evangelink merged 4 commits into
dotnet:mainfrom
Evangelink:evangelink/mstest-mtp-templatesearch-common

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Migrates Microsoft.TemplateSearch.Common.UnitTests from xUnit (v3) to MSTest on MTP via MSTest.Sdk, following the same pattern as #54758 / #54759 / #54761.

Changes

  • csproj: Sdk="MSTest.Sdk", IsTestProject=true (kept FakeItEasy and the test-data None items).
  • Test files: [Fact] -> [TestMethod] + [TestClass]; assertions mapped to MSTest:
    • Equal -> AreEqual, True/False -> IsTrue/IsFalse, NotNull -> IsNotNull
    • IsAssignableFrom<T> -> IsInstanceOfType<T> (assignable semantics preserved)
    • Single -> ContainsSingle (predicate-first overload where a predicate was used)
    • Assert.Equal over IEnumerable -> Assert.AreSequenceEqual
  • Fixtures: IClassFixture<EnvironmentSettingsHelper> -> static Lazy<EnvironmentSettingsHelper> + [ClassCleanup] (per-class shared instance, matching xUnit's class-fixture scope).
  • IMessageSink: EnvironmentSettingsHelper's ctor takes an Xunit.Sdk.IMessageSink; satisfied with a local no-op NullMessageSink and a GlobalUsings alias — identical to Migrate Microsoft.TemplateEngine.Utils.UnitTests to MSTest.Sdk on MTP #54759. The shared Microsoft.TemplateEngine.TestHelper still references xunit.v3 and is out of scope here.
  • TestContext.Current.CancellationToken -> instance TestContext.CancellationToken (property injection).

Notes

Verification

  • ✅ Builds clean (0 warnings / 0 errors).
  • ✅ All 17 tests pass on MTP (same count as the xUnit baseline; includes the live NuGet search tests).

Relates to #52914.

Convert from xUnit (v3) to MSTest via MSTest.Sdk (MTP on by default), matching the
TemplateEngine migration pattern (dotnet#54758/dotnet#54759/dotnet#54761):
- csproj uses Sdk="MSTest.Sdk", IsTestProject=true.
- [Fact] -> [TestMethod]; [TestClass] added.
- Assertions mapped: Equal->AreEqual, True/False->IsTrue/IsFalse, NotNull->IsNotNull,
  IsAssignableFrom<T>->IsInstanceOfType<T>, Single->ContainsSingle (predicate-first
  overload where applicable), IEnumerable Equal->AreSequenceEqual.
- IClassFixture<EnvironmentSettingsHelper> -> static Lazy<EnvironmentSettingsHelper> +
  [ClassCleanup]; EnvironmentSettingsHelper's IMessageSink ctor arg satisfied by a local
  no-op NullMessageSink (+ GlobalUsings alias for Xunit.Sdk.IMessageSink), since the shared
  TestHelper still references xunit.v3 and is out of scope for this migration.
- TestContext.Current.CancellationToken -> instance TestContext.CancellationToken.

Parallelization left to the repo-wide MSTest.Sdk default (dotnet#54766). All 17 tests pass.

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings June 16, 2026 08:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Migrates Microsoft.TemplateSearch.Common.UnitTests from xUnit v3 to MSTest on Microsoft.Testing.Platform by switching the project to MSTest.Sdk and updating fixtures, assertions, and cancellation token usage to MSTest patterns consistent with other TemplateEngine test migrations.

Changes:

  • Switch the test project SDK to MSTest.Sdk and mark it as a test project.
  • Convert xUnit attributes/assertions to MSTest ([Fact] → [TestMethod], Assert.* mappings) and move cancellation tokens to TestContext.CancellationToken.
  • Replace IClassFixture<EnvironmentSettingsHelper> with a per-class static Lazy<EnvironmentSettingsHelper> plus [ClassCleanup], and add a local NullMessageSink + global aliases for xUnit’s IMessageSink.
Show a summary per file
File Description
test/TemplateEngine/Microsoft.TemplateSearch.Common.UnitTests/Microsoft.TemplateSearch.Common.UnitTests.csproj Switches project to MSTest.Sdk and marks it as a test project.
test/TemplateEngine/Microsoft.TemplateSearch.Common.UnitTests/GlobalUsings.cs Adds xUnit IMessageSink aliases to construct EnvironmentSettingsHelper without xUnit global usings.
test/TemplateEngine/Microsoft.TemplateSearch.Common.UnitTests/NullMessageSink.cs Introduces a no-op message sink for EnvironmentSettingsHelper construction under MSTest.
test/TemplateEngine/Microsoft.TemplateSearch.Common.UnitTests/TemplateSearchCoordinatorTests.cs Converts test class to MSTest and updates assertions/cancellation token usage.
test/TemplateEngine/Microsoft.TemplateSearch.Common.UnitTests/TemplateSearchCacheReaderTests.cs Converts test class to MSTest and updates assertions/fixture lifecycle.
test/TemplateEngine/Microsoft.TemplateSearch.Common.UnitTests/NuGetMetadataSearchProviderTests.cs Converts test class to MSTest and updates assertions/cancellation token usage.
test/TemplateEngine/Microsoft.TemplateSearch.Common.UnitTests/AllComponents.cs Converts to MSTest and updates sequence assertions.

Copilot's findings

  • Files reviewed: 7/7 changed files
  • Comments generated: 2

@Evangelink

Copy link
Copy Markdown
Member Author

/azp run dotnet-sdk-public-ci

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

…tionTests)

PR dotnet#54766 enabled the Recommended MSTest analyzers as errors; dotnet#54758 merged shortly
after with violations that are now build errors, leaving main red and blocking all
open migration PRs. Fix the two affected files:
- CommandResultAssertions.MSTest.cs: MSTEST0037 (IsTrue(a==b)->AreEqual, IsFalse(a==b)
  ->AreNotEqual) and MSTEST0023 (IsTrue(!x)->IsFalse(x)).
- LocalizeTemplateTests.cs: MSTEST0037 (AreEqual(n, x.Length)->HasCount(n, x)).

Co-authored-by: Copilot <[email protected]>
(cherry picked from commit 6ac4ef0)
@Evangelink
Evangelink enabled auto-merge (squash) June 17, 2026 08:46
@Evangelink
Evangelink merged commit 714611c into dotnet:main Jun 17, 2026
25 checks passed
@Evangelink
Evangelink deleted the evangelink/mstest-mtp-templatesearch-common branch June 22, 2026 16:44
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants