Fix MSTest analyzer violations breaking main#54807
Conversation
…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 <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes MSTest “Recommended” analyzer violations introduced as build errors, restoring clean builds for Microsoft.TemplateEngine.Authoring.Tasks.IntegrationTests and unblocking the ongoing MSTest migration PR stack.
Changes:
- Replace equality-in-boolean asserts with
Assert.AreEqual/Assert.AreNotEqualin the MSTestCommandResultAssertionshelper. - Replace negated
Assert.IsTrue(!...)patterns withAssert.IsFalse(...). - Replace
AreEqual(expected, array.Length)withAssert.HasCount(expected, array)in localization integration tests.
Show a summary per file
| File | Description |
|---|---|
| test/TemplateEngine/Microsoft.TemplateEngine.Authoring.Tasks.IntegrationTests/LocalizeTemplateTests.cs | Uses Assert.HasCount for file count assertions to satisfy MSTest analyzers. |
| test/TemplateEngine/Microsoft.TemplateEngine.Authoring.Tasks.IntegrationTests/CommandResultAssertions.MSTest.cs | Updates assertions to analyzer-preferred forms (AreEqual/AreNotEqual/IsFalse) while preserving behavior. |
Copilot's findings
- Files reviewed: 2/2 changed files
- Comments generated: 0
|
/ba-g #54813 The CI failure on this PR is not related to its changes. This PR only modifies two files in The only failing tests are in |
Problem
PR #54766 enabled the Recommended MSTest analyzers as build errors. PR #54758 merged ~2 minutes later, and its
Microsoft.TemplateEngine.Authoring.Tasks.IntegrationTestscode contains assertions that those analyzers now flag — so main is currently red and every open MSTest migration PR is blocked (their merge builds fail on these same errors).Fix
Resolve the analyzer violations in the two affected files (no behavior change):
CommandResultAssertions.MSTest.cs:MSTEST0037(Assert.IsTrue(a == b)->Assert.AreEqual;Assert.IsFalse(a == b)->Assert.AreNotEqual) andMSTEST0023(Assert.IsTrue(!x)->Assert.IsFalse(x)).LocalizeTemplateTests.cs:MSTEST0037(Assert.AreEqual(n, x.Length)->Assert.HasCount(n, x)).Verification
Microsoft.TemplateEngine.Authoring.Tasks.IntegrationTestsbuilds clean (0 warnings / 0 errors) with the analyzers enabled.This unblocks #54722 #54723 #54724 #54725 #54726 #54729 #54730 #54732 #54759 #54761 #54785 #54787.