Skip to content

Conversation

dennisdoomen
Copy link
Member

@dennisdoomen dennisdoomen commented May 25, 2025

Introduces a new DateAndTimeEquivalencyStep for BeEquivalentTo that will include the type of the comparands in the failure message if the subject and expectation aren't of the same date/time type like this:

Expected property subject.SomeDate to be <2020-01-02> (of type System.DateTime), but found <2020-01-02> (of type System.DateOnly

#3048

IMPORTANT

  • If the PR touches the public API, the changes have been approved in a separate issue with the "api-approved" label.
  • The code complies with the Coding Guidelines for C#.
  • The changes are covered by unit tests which follow the Arrange-Act-Assert syntax and the naming conventions such as is used in these tests.
  • If the PR adds a feature or fixes a bug, please update the release notes with a functional description that explains what the change means to consumers of this library, which are published on the website.
  • If the PR changes the public API the changes needs to be included by running AcceptApiChanges.ps1 or AcceptApiChanges.sh.
  • If the PR affects the documentation, please include your changes in this pull request so the documentation will appear on the website.
    • Please also run ./build.sh --target spellcheck or .\build.ps1 --target spellcheck before pushing and check the good outcome

Copy link

github-actions bot commented May 25, 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 [email protected]

@dennisdoomen dennisdoomen marked this pull request as ready for review May 25, 2025 08:28
@dennisdoomen dennisdoomen requested review from Copilot and jnyrup May 25, 2025 08:28
Copy link

@Copilot 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

Adds a new equivalency step to include explicit type information when comparing date/time values of different types, along with tests and API approvals.

  • Introduce DateAndTimeEquivalencyStep to fail with type details when subject and expectation are both date/time types but not the same type
  • Register the new step in the default equivalency plan (EquivalencyPlan)
  • Add missing tests covering DateOnly, TimeOnly, TimeSpan, DateTimeOffset comparisons
  • Update API approval snapshots to include the new public step

Reviewed Changes

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

File Description
Src/FluentAssertions/Equivalency/Steps/DateAndTimeEquivalencyStep.cs New step implementation comparing mismatched date/time types
Src/FluentAssertions/Equivalency/EquivalencyPlan.cs Register DateAndTimeEquivalencyStep in the default steps sequence
Tests/FluentAssertions.Equivalency.Specs/DateTimePropertiesSpecs.cs Add tests to verify failure messages include type information for all date/time combinations
Tests/Approval.Tests/ApprovedApi/FluentAssertions/net*.verified.txt Update API approval files to include the new DateAndTimeEquivalencyStep
Comments suppressed due to low confidence (2)

Src/FluentAssertions/Equivalency/Steps/DateAndTimeEquivalencyStep.cs:13

  • [nitpick] Override ToString() for this class to give a descriptive name when listing or debugging equivalency steps, matching the pattern used by other steps.
public class DateAndTimeEquivalencyStep : IEquivalencyStep

Src/FluentAssertions/Equivalency/EquivalencyPlan.cs:155

  • Align the indentation of this line with the surrounding step registrations to maintain consistent formatting.
            new DateAndTimeEquivalencyStep(),

@coveralls
Copy link

coveralls commented May 25, 2025

Pull Request Test Coverage Report for Build 15236385907

Details

  • 18 of 21 (85.71%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.04%) to 97.322%

Changes Missing Coverage Covered Lines Changed/Added Lines %
Src/FluentAssertions/Equivalency/Steps/DateAndTimeEquivalencyStep.cs 17 20 85.0%
Totals Coverage Status
Change from base Build 15115079380: -0.04%
Covered Lines: 12460
Relevant Lines: 12658

💛 - Coveralls

Copy link
Member

@jnyrup jnyrup left a comment

Choose a reason for hiding this comment

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

I'm fine with this as it improves clarity of the failure message.
I had preferred if we just changed DateTimeOffsetValueFormatter to not skip rendering the time of day at midnight.

@dennisdoomen dennisdoomen requested a review from jnyrup May 25, 2025 09:19
This was referenced Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants