Add HaveMillisecond/NotHaveMillisecond assertion methods for DateTime and DateTimeOffset#3164
Conversation
Co-authored-by: jnyrup <[email protected]>
Test Results 37 files ± 0 37 suites ±0 6m 26s ⏱️ -23s Results for commit eee7305. ± Comparison against base commit 27bd2f9. This pull request removes 10 and adds 20 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
Qodana for .NETIt 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 Contact Qodana teamContact us at [email protected]
|
There was a problem hiding this comment.
@copilot please address the following points:
- Update
docs/_pages/releases.mdto include a sub-item under "What's New" succiently summarizing the feature added in this PR - Run either of
AcceptApiChanges.shorAcceptApiChanges.ps1to updates the approved API. - Update the naming of the added test methods to the folllow the new naming convention.
- See e.g. Tests/FluentAssertions.Specs/Numeric/NumericAssertionSpecs.BeNaN.cs
@copilot apply the requested changes |
…nges Co-authored-by: dennisdoomen <[email protected]>
All requested changes have been applied in commit fcb2dfc:
All tests pass: 18 HaveMillisecond tests, 4 approval tests, and no regressions in existing DateTime/DateTimeOffset tests. |
Pull Request Test Coverage Report for Build 22803252634Details
💛 - Coveralls |
Tests/FluentAssertions.Specs/Primitives/DateTimeAssertionSpecs.HaveMillisecond.cs
Show resolved
Hide resolved
Co-authored-by: dennisdoomen <[email protected]>
Implementation Complete ✓
HaveMillisecondandNotHaveMillisecondmethods to DateTimeAssertions classHaveMillisecondandNotHaveMillisecondmethods to DateTimeOffsetAssertions classdocs/_pages/releases.mdwith feature summaryAcceptApiChanges.shto update approved APISummary
Successfully implemented
HaveMillisecondandNotHaveMillisecondassertion methods for bothDateTimeandDateTimeOffsettypes, following the existing patterns. All tests pass successfully with no regressions detected. Test naming has been refined to follow clean naming conventions without rigid and noisy words.Original prompt
This section details on the original issue you should resolve
<issue_title>Method to assert the millisecond part of a DateTime / DateTimeOffset instance</issue_title>
<issue_description>### Background and motivation
Currently, FluentAssertions has methods to assert the year, month, day, hour, minute, second and offset of a DateTimeOffset (HaveX), but an equivalent method for the millisecond part is missing. Generally, it would be nice to assert the millisecond part in the style of FluentAssertions instead of using
result.Millisecond.Should().Be(milliseconds).I'm currently working on a library that provides convenience methods based on DateTime/DateTimeOffset and implement date and time related unit tests for it.
This is very easy to implement, because we can extend the DateTimeAssertions class and DateTimeOffsetAssertions class by a method called
HaveMillisecond.The implementation of this method could look like following:
Also the opponent of
HaveMillisecond, which would beNotHaveMillisecond, can be implemented this way by inverting / changing the condition tothis.Subject!.Value.Millisecond != expectedMilliseconds.API Proposal
API Usage
Alternative Designs
Alternately, you could write an extension method based on
DateTimeOffsetAssertionsclass and add there theHaveMillisecondmethod. This would not directly change the API of FluentAssertions, but would not be consistent with the rest of the DateTime/DateTimeOffset method provided by FluentAssertions.The extension method could be implemented like following:
Risks
None, because it adds an extra method to assert the millisecond part of a DateTime / DateTimeOffset instance.
Are you willing to help with a proof-of-concept (as PR in that or a separate repo) first and as pull-request later on?
Yes, please assign this issue to me.</issue_description>
Comments on the Issue (you are @copilot ...
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.