Skip to content

Conversation

@dennisdoomen
Copy link
Member

@dennisdoomen dennisdoomen commented Jun 27, 2025

By default, BeEquivalentTo will consider objects equivalent as long as their members match, regardless of whether the types are exactly the same. This means that objects of different types can be considered equivalent if they have the same structure and values.

However, sometimes you may want to ensure that not only the values match, but also the types are exactly the same. For such scenarios, you can use the strict typing options WithStrictTyping and WithStrictTypingFor.

Closes #798

  • Release notes
  • Documentation

@github-actions
Copy link

github-actions bot commented Jun 27, 2025

Qodana for .NET

It seems all right 👌

No new problems were found according to the checks applied

💡 Qodana analysis was run in the pull request mode: only the changed files were checked
☁️ View the detailed Qodana report

Contact Qodana team

Contact us at qodana-support@jetbrains.com

@dennisdoomen dennisdoomen force-pushed the feature/strict-typing branch 6 times, most recently from 39828ec to d51474e Compare June 28, 2025 12:28
@dennisdoomen dennisdoomen requested a review from Copilot June 28, 2025 12:28
Copy link

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

This PR extends the BeEquivalentTo API to support strict typing, ensuring that the types of properties are compared exactly between the subject and expectation.

  • Updated release notes documentation to include the new WithStrictTyping and WithStrictTypingFor options.
  • Added comprehensive tests for type equality, including new test cases in TypeEqualitySpecs.cs.
  • Implemented strict typing support across several modules (e.g., ITypingRule, AlwaysBeStrictTypingRule, PredicateBasedTypingRule, and TypeEquivalencyStep) and integrated them into the equivalency options.

Reviewed Changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated no comments.

Show a summary per file
File Description
docs/_pages/releases.md Release notes updated with new strict typing features.
Tests/FluentAssertions.Equivalency.Specs/TypeEqualitySpecs.cs New tests to validate strict typing behaviors in equivalency assertions.
Tests/Benchmarks/UsersOfGetClosedGenericInterfaces.cs Benchmark config updated to include TypingRules.
Tests/Approval.Tests/ApprovedApi/FluentAssertions/*.verified.txt Approval tests updated for new strict typing API members.
Src/FluentAssertions/Equivalency/Steps/TypeEquivalencyStep.cs New equivalency step implementation for enforcing strict typing.
Src/FluentAssertions/Equivalency/Typing/*.cs New strict typing rule implementations added and exposed in the API.
Src/FluentAssertions/Equivalency/SelfReferenceEquivalencyOptions.cs Integrated strict typing rules into equivalency options for global override.
Comments suppressed due to low confidence (1)

Src/FluentAssertions/Equivalency/IEquivalencyStep.cs:13

  • It appears that the documentation comment is truncated (''). Please update this comment to correctly reflect the intended message.
    /// have to be executed. Should return <see cref="EquivalencyResult.ContinueWithNext"/> otherwise. <see langword="tru"/>

@dennisdoomen dennisdoomen force-pushed the feature/strict-typing branch from d51474e to e14b254 Compare June 28, 2025 12:37
@dennisdoomen dennisdoomen marked this pull request as ready for review June 28, 2025 12:38
@coveralls
Copy link

coveralls commented Jun 28, 2025

Pull Request Test Coverage Report for Build 15982170862

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 37 of 38 (97.37%) changed or added relevant lines in 6 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.02%) to 97.308%

Changes Missing Coverage Covered Lines Changed/Added Lines %
Src/FluentAssertions/Equivalency/Steps/TypeEquivalencyStep.cs 15 16 93.75%
Totals Coverage Status
Change from base Build 15980707080: -0.02%
Covered Lines: 12541
Relevant Lines: 12741

💛 - Coveralls

@dennisdoomen dennisdoomen force-pushed the feature/strict-typing branch from e14b254 to bab34e5 Compare June 28, 2025 12:41
@dennisdoomen dennisdoomen requested a review from jnyrup June 28, 2025 12:42
@dennisdoomen dennisdoomen force-pushed the feature/strict-typing branch from bab34e5 to db63a3f Compare June 29, 2025 06:24
@dennisdoomen dennisdoomen force-pushed the feature/strict-typing branch from db63a3f to 5ee62a4 Compare June 29, 2025 16:53
@dennisdoomen dennisdoomen requested a review from jnyrup June 29, 2025 16:55
@dennisdoomen dennisdoomen changed the title Extended BeEquivalentTo to support checking the type of the properties Extended BeEquivalentTo with support for checking the type of the properties Jun 29, 2025
@dennisdoomen dennisdoomen force-pushed the feature/strict-typing branch from 5ee62a4 to 86fb81c Compare June 30, 2025 19:41
@dennisdoomen dennisdoomen force-pushed the feature/strict-typing branch from 86fb81c to 58a0949 Compare June 30, 2025 19:43
@dennisdoomen dennisdoomen requested a review from jnyrup June 30, 2025 19:43
@dennisdoomen dennisdoomen merged commit 74f07de into fluentassertions:main Jun 30, 2025
6 checks passed
@dennisdoomen dennisdoomen deleted the feature/strict-typing branch June 30, 2025 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an option to BeEquivalentTo that compares types of objects recursively.

3 participants