Skip to content

Fix MSTest analyzer warnings (MSTEST0058, MSTEST0037)#107

Merged
Malcolmnixon merged 4 commits intomainfrom
copilot/fix-sonar-issues-in-tests
Feb 13, 2026
Merged

Fix MSTest analyzer warnings (MSTEST0058, MSTEST0037)#107
Malcolmnixon merged 4 commits intomainfrom
copilot/fix-sonar-issues-in-tests

Conversation

Copy link
Contributor

Copilot AI commented Feb 13, 2026

Pull Request

Description

Addressed 7 Sonar/MSTest analyzer warnings in test files:

MSTEST0058 (RequirementsReadTests.cs): Asserts in catch blocks don't fail if no exception is thrown.

  • Changed: try { code; Assert.Fail(); } catch { Assert.Contains(...); }
  • To: var ex = Assert.ThrowsExactly<T>(() => code); Assert.Contains(...);

MSTEST0037 (ContextTests.cs): Using Assert.IsTrue with collection predicates instead of explicit assertions.

  • Changed: Assert.IsTrue(files.Any(f => f.EndsWith("file.yaml")))
  • To: Assert.ContainsSingle(f => f.EndsWith("file.yaml"), files)

The Assert.ContainsSingle approach is the idiomatic MSTest v4 way to assert that exactly one element matches a predicate. Collections contain full paths, hence the .EndsWith() predicate.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code quality improvement

Related Issues

Pre-Submission Checklist

Before submitting this pull request, ensure you have completed the following:

Build and Test

  • Code builds successfully: dotnet build --configuration Release
  • All tests pass: dotnet test --configuration Release
  • Code produces zero warnings

Code Quality

  • Code formatting is correct: dotnet format --verify-no-changes
  • New code has appropriate XML documentation comments
  • Static analyzer warnings have been addressed

Quality Checks

Please run the following checks before submitting:

  • Spell checker passes: cspell "**/*.{md,cs}"
  • Markdown linter passes: markdownlint "**/*.md"
  • YAML linter passes: yamllint '**/*.{yml,yaml}'

Testing

  • Added unit tests for new functionality
  • Updated existing tests if behavior changed
  • All tests follow the AAA (Arrange, Act, Assert) pattern
  • Test coverage is maintained or improved

Documentation

  • Updated README.md (if applicable)
  • Updated ARCHITECTURE.md (if applicable)
  • Added code examples for new features (if applicable)
  • Updated requirements.yaml (if applicable)

Additional Notes

No functional changes—test behavior is identical. All 132 tests pass.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix Sonar issues in test files Fix MSTest analyzer warnings (MSTEST0058, MSTEST0037) Feb 13, 2026
@Malcolmnixon Malcolmnixon marked this pull request as ready for review February 13, 2026 12:38
Copilot AI requested a review from Malcolmnixon February 13, 2026 12:38
@Malcolmnixon
Copy link
Contributor

@copilot Sonar is reporting new issues and suggests using Assert.ContainsSingle - specifically try:

Assert.ContainsSingle(s => s.EndsWith("pattern"), collection);

Copy link
Contributor Author

Copilot AI commented Feb 13, 2026

@copilot Sonar is reporting new issues and suggests using Assert.ContainsSingle - specifically try:

Assert.ContainsSingle(s => s.EndsWith("pattern"), collection);

...

Updated to use Assert.ContainsSingle(f => f.EndsWith("pattern"), collection) as suggested. This is cleaner and more idiomatic for MSTest v4. Commit: cce429b

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.

2 participants