-
Notifications
You must be signed in to change notification settings - Fork 731
Add new BeExactly assertions for DateTimeOffset #1609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new BeExactly assertions for DateTimeOffset #1609
Conversation
| #region (Not) BeExactly | ||
|
|
||
| [Fact] | ||
| public void Should_succeed_when_asserting_datetimeoffset_value_is_exactly_equal_to_the_same_value() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔧 No need to mention datetimeoffset in there since it's clear from the context. Also, we prefer to keep literal names of code elements out of the test name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gladly. I just copied the Be/NotBe tests, which has the misleading "numeric" name, and changed it. Will fix.
| Action act = () => dateTime.Should().BeExactly(sameDateTime); | ||
|
|
||
| // Assert | ||
| act.Should().NotThrow(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔧 If the assertion is not expected to throw anything, you don't need to explicitly use NotThrow (anymore).
71ed70a to
2088ab0
Compare
| .FailWith("but found a <null> DateTimeOffset.") | ||
| .Then | ||
| .ForCondition(Subject == expected) | ||
| .FailWith("but its value {0} doesn't.", Subject) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| .FailWith("but its value {0} doesn't.", Subject) | |
| .FailWith("but {0} does not.", Subject) |
| /// Zero or more objects to format using the placeholders in <paramref name="because" />. | ||
| /// </param> | ||
| public AndConstraint<TAssertions> NotBe(DateTimeOffset unexpected, string because = "", | ||
| public AndConstraint<TAssertions> NotBeExactly(DateTimeOffset unexpected, string because = "", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the summary be updated?
| { | ||
| Execute.Assertion | ||
| .ForCondition(Subject == expected) | ||
| .ForCondition((Subject == null && expected == null) || (Subject != null && expected != null && Subject.Value.EqualsExact(expected.Value))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We strive to keep lines at atmost 130 characters wide.
| .ForCondition((Subject == null && expected == null) || (Subject != null && expected != null && Subject.Value.EqualsExact(expected.Value))) | |
| .ForCondition((Subject == null && expected == null) | |
| || (Subject != null && expected != null && Subject.Value.EqualsExact(expected.Value))) |
jnyrup
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from the failing tests, two other step are necessary to finish up this PR
- Run
AcceptChanges.ps1/shto update the accepted public methods. - Add a line to the release notes.
Both steps are explained in https://github.com/fluentassertions/fluentassertions/blob/release-6.0/CONTRIBUTING.md, but ping me if anything is unclear or causing trouble.
| .FailWith("but found a <null> DateTimeOffset.", expected) | ||
| .Then | ||
| .ForCondition(Subject == expected) | ||
| .FailWith("but {1} does not.", expected, Subject) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| .FailWith("but {1} does not.", expected, Subject) | |
| .FailWith("but {0} does not.", Subject) |
| .ForCondition(Subject.HasValue) | ||
| .FailWith("but found a <null> DateTimeOffset.") | ||
| .Then | ||
| .ForCondition(Subject.Value.EqualsExact(expected) == true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't checked the code out, but I would believe == true to be superfluous.
| .ForCondition(Subject.Value.EqualsExact(expected) == true) | |
| .ForCondition(Subject.Value.EqualsExact(expected)) |
| .FailWith("but found a <null> DateTimeOffset.", expected) | ||
| .Then | ||
| .ForCondition(Subject.Value.EqualsExact(expected.Value)) | ||
| .FailWith("but it was {0}.", expected, Subject) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| .FailWith("but it was {0}.", expected, Subject) | |
| .FailWith("but it was {0}.", Subject) |
| .BecauseOf(because, becauseArgs) | ||
| .WithExpectation("Expected {context:the date and time} to be exactly {0}{reason}, ", expected) | ||
| .ForCondition(Subject.HasValue) | ||
| .FailWith("but found a <null> DateTimeOffset.", expected) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| .FailWith("but found a <null> DateTimeOffset.", expected) | |
| .FailWith("but found a <null> DateTimeOffset.") |
| .BecauseOf(because, becauseArgs) | ||
| .WithExpectation("Expected {context:the date and time} to represent the same point in time as {0}{reason}, ", expected) | ||
| .ForCondition(Subject.HasValue) | ||
| .FailWith("but found a <null> DateTimeOffset.", expected) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| .FailWith("but found a <null> DateTimeOffset.", expected) | |
| .FailWith("but found a <null> DateTimeOffset.") |
| Execute.Assertion | ||
| .ForCondition(Subject?.EqualsExact(unexpected) != true) | ||
| .BecauseOf(because, becauseArgs) | ||
| .FailWith("Did not expect {context:the date and time} to be {0}{reason}, but it was.", unexpected); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| .FailWith("Did not expect {context:the date and time} to be {0}{reason}, but it was.", unexpected); | |
| .FailWith("Did not expect {context:the date and time} to be exactly {0}{reason}, but it was.", unexpected); |
| .ForCondition(Subject != unexpected) | ||
| .ForCondition(!((Subject == null && unexpected == null) || (Subject != null && unexpected != null && Subject.Value.EqualsExact(unexpected.Value)))) | ||
| .BecauseOf(because, becauseArgs) | ||
| .FailWith("Did not expect {context:the date and time} to be {0}{reason}, but it was.", unexpected); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| .FailWith("Did not expect {context:the date and time} to be {0}{reason}, but it was.", unexpected); | |
| .FailWith("Did not expect {context:the date and time} to be exactly {0}{reason}, but it was.", unexpected); |
c9eb1db to
c27a434
Compare
Not quite ready yet. More a basis for discussion.
The value formatting was one issue. I don't think the offset should be hidden, even if it's zero. It's no less significant than a positive or negative offset.
The assertion could perhaps be made with a Then step and a "...but the offsets differ" message.