Add new BeExactly assertions for DateTimeOffset#1609
Add new BeExactly assertions for DateTimeOffset#1609dennisdoomen merged 1 commit intofluentassertions:release-6.0from
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.
🔧 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.
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.
🔧 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.
| .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 = "", |
| { | ||
| 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.
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.
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.
| .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.
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.
| .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.
| .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.
| .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.
| .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.
| .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.