Skip to content

fix: address SonarCloud code smell issues in TrxSerializer#135

Merged
Malcolmnixon merged 1 commit intomainfrom
copilot/fix-sonarcloud-code-smells
Apr 3, 2026
Merged

fix: address SonarCloud code smell issues in TrxSerializer#135
Malcolmnixon merged 1 commit intomainfrom
copilot/fix-sonarcloud-code-smells

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 3, 2026

Pull Request

Description

Resolves six SonarCloud INFO/CODE_SMELL diagnostics in TrxSerializer.cs and TrxSerializerTests.cs.

TrxSerializer.cs

  • CA1859: ParseTestResult parameter narrowed from IReadOnlyDictionary<string, XElement> to Dictionary<string, XElement> — safe since BuildTestMethodLookup already returns Dictionary
  • CA2263: Switched to the generic Enum.IsDefined<TestOutcome>(outcome) overload

TrxSerializerTests.cs

  • MSTEST0037 (×4): Replaced Assert.IsTrue(Math.Abs(...) < 0.001) with Assert.IsLessThan(0.001, Math.Abs(...)):
// Before
Assert.IsTrue(Math.Abs((passed.Duration - TimeSpan.FromSeconds(1.5)).TotalSeconds) < 0.001);

// After
Assert.IsLessThan(0.001, Math.Abs((passed.Duration - TimeSpan.FromSeconds(1.5)).TotalSeconds));

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 unit 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:

  • All linters pass: ./lint.sh (Unix/macOS) or cmd /c lint.bat / ./lint.bat (Windows)

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 behaviour changes — purely diagnostic-driven code quality fixes.

Agent-Logs-Url: https://github.com/demaconsulting/TestResults/sessions/abd6bd89-9755-4bbc-8405-8be8a363d47c

Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
@Malcolmnixon Malcolmnixon marked this pull request as ready for review April 3, 2026 11:45
Copilot AI review requested due to automatic review settings April 3, 2026 11:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Addresses SonarCloud/MSTest analyzer code-smell findings in TRX serialization and related unit tests, aiming for cleaner and more analyzer-compliant implementations without intended behavior changes.

Changes:

  • Narrows ParseTestResult lookup parameter type to Dictionary<string, XElement> to satisfy CA1859.
  • Replaces Enum.IsDefined(typeof(TestOutcome), outcome) with the generic Enum.IsDefined<TestOutcome>(outcome) overload (CA2263).
  • Updates duration assertions in TrxSerializerTests to use Assert.IsLessThan instead of Assert.IsTrue with a comparison (MSTEST0037).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/DemaConsulting.TestResults/IO/TrxSerializer.cs Analyzer-driven refactors in parsing helpers (ParseTestResult, ParseTestOutcome).
test/DemaConsulting.TestResults.Tests/IO/TrxSerializerTests.cs Replaces tolerance checks with Assert.IsLessThan per MSTest analyzer guidance.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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