Skip to content

Conversation

@gliljas
Copy link
Contributor

@gliljas gliljas commented Jun 10, 2021

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.

#region (Not) BeExactly

[Fact]
public void Should_succeed_when_asserting_datetimeoffset_value_is_exactly_equal_to_the_same_value()
Copy link
Member

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.

Copy link
Contributor Author

@gliljas gliljas Jun 11, 2021

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();
Copy link
Member

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).

@gliljas gliljas force-pushed the datetimeoffsetexact branch from 71ed70a to 2088ab0 Compare June 11, 2021 09:21
@dennisdoomen dennisdoomen requested a review from jnyrup June 11, 2021 11:52
.FailWith("but found a <null> DateTimeOffset.")
.Then
.ForCondition(Subject == expected)
.FailWith("but its value {0} doesn't.", Subject)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.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 = "",
Copy link
Member

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)))
Copy link
Member

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.

Suggested change
.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)))

@dennisdoomen dennisdoomen requested a review from jnyrup June 22, 2021 12:15
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.

Aside from the failing tests, two other step are necessary to finish up this PR

  • Run AcceptChanges.ps1/sh to 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)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.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)
Copy link
Member

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.

Suggested change
.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)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.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)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.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)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.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);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.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);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.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);

@gliljas gliljas force-pushed the datetimeoffsetexact branch 2 times, most recently from c9eb1db to c27a434 Compare June 24, 2021 09:22
@dennisdoomen dennisdoomen requested a review from jnyrup June 29, 2021 06:42
@dennisdoomen dennisdoomen merged commit fdf0288 into fluentassertions:release-6.0 Jun 29, 2021
@gliljas gliljas deleted the datetimeoffsetexact branch August 30, 2021 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants