Skip to content
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

Should().Throw and Should().NotThrow throw for Func<T> #951

Merged
merged 14 commits into from Nov 8, 2018

Conversation

@krajek
Copy link
Contributor

krajek commented Oct 19, 2018

Closes #422.

This is still work in progress but if you would like to do an early review I would appreciate.
Implemented according to @jnyrup idea of returning AndWhichConstraint from NotThrow which allows continued assertions like this:

//-----------------------------------------------------------------------------------------------------------
// Arrange
//-----------------------------------------------------------------------------------------------------------
Func<int> f = () => 12;
 //-----------------------------------------------------------------------------------------------------------
// Act / Assert
//-----------------------------------------------------------------------------------------------------------
f.Should().NotThrow().Which.Should().Be(12);

All the commented code and tests are part of the WIP.

Copy link
Collaborator

jnyrup left a comment

To align with Action assertions we should add
public AndWhichConstraint<FunctionAssertions<T>, T> NotThrow<TException>
public ExceptionAssertions<TException> ThrowExactly<TException>

@krajek krajek changed the title [WIP] Should().Throw and Should_().NotThrow throw for Func<T> [WIP] Should().Throw and Should().NotThrow throw for Func<T> Oct 28, 2018
@krajek krajek changed the title [WIP] Should().Throw and Should().NotThrow throw for Func<T> Should().Throw and Should().NotThrow throw for Func<T> Oct 29, 2018
@krajek

This comment has been minimized.

Copy link
Contributor Author

krajek commented Oct 29, 2018

Ready for the merge with squash.

To align with Action assertions we should add
public AndWhichConstraint<FunctionAssertions, T> NotThrow

NotThrow<TException> does return void, because it does not guarantee that no exception was thrown and that assertion can be continued.

@jnyrup
jnyrup approved these changes Oct 29, 2018
Copy link
Collaborator

jnyrup left a comment

Looks good 👍

I didn't thought about the difficulty of the return type for NotThrow<TException>().
For now I agree with returning void.

At some later point I would like if we could come up with a nice way to represent the three possible outcomes:

  • didn't throw any exception => success and pass on result for chaining further assertions.
  • threw an exception but it was not the unexpected => success but no resulting value.
  • threw an exception and it was the unexpected one => fail.
@krajek krajek changed the title Should().Throw and Should().NotThrow throw for Func<T> [WIP] Should().Throw and Should().NotThrow throw for Func<T> Oct 29, 2018
@krajek

This comment has been minimized.

Copy link
Contributor Author

krajek commented Nov 2, 2018

@jnyrup tests you requested are added, it was a good idea.

Additionally, FunctionAssertions now inherits from ReferenceTypeAssertions. It was not extremely important to do it, but at least it is consistent with ActionAssertions among others.

Ready for a merge with squash.

@krajek krajek changed the title [WIP] Should().Throw and Should().NotThrow throw for Func<T> Should().Throw and Should().NotThrow throw for Func<T> Nov 2, 2018
@jnyrup jnyrup requested a review from dennisdoomen Nov 5, 2018
@dennisdoomen dennisdoomen self-assigned this Nov 7, 2018
@dennisdoomen dennisdoomen merged commit a1673b0 into fluentassertions:master Nov 8, 2018
1 check passed
1 check passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
@krajek krajek deleted the krajek:should_throw_for_func_t branch Nov 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.