Skip to content

Add WithParameterName #1466

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

Merged
merged 1 commit into from
Jan 11, 2021
Merged

Conversation

jnyrup
Copy link
Member

@jnyrup jnyrup commented Jan 10, 2021

Add WithParameterName extension to assert on the ParamName property on ArgumentException.

This fixes #1453

@jnyrup jnyrup merged commit d641951 into fluentassertions:develop Jan 11, 2021
@jnyrup jnyrup deleted the WithParameterName branch January 11, 2021 06:44
/// </param>
public static ExceptionAssertions<TException> WithParameterName<TException>(
this ExceptionAssertions<TException> parent,
string paramName,

Choose a reason for hiding this comment

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

I know this has already been merged, but I'd suggest adding argument validation (!= null) for paramName here to improve the stacktrace in case people misuse the method.

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't think about that case, but ArgumentException allows a null ParamName.

Maybe I'm misunderstanding you, can you give an example on "misuse"?

params object[] becauseArgs)
where TException : ArgumentException
{
parent.Which.ParamName.Should().Be(paramName, because, becauseArgs);

Choose a reason for hiding this comment

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

Question: won't the final error message here be a bit cryptic to an outside consumer? Wouldn't it be better to create a custom validation instead of relying on the standard Should().Be in this case?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, I'll change that.

/// <param name="becauseArgs">
/// Zero or more objects to format using the placeholders in <paramref name="because"/>.
/// </param>
public static async Task<ExceptionAssertions<TException>> WithParameterName<TException>(

Choose a reason for hiding this comment

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

Shouldn't this one have the Async suffix?

Copy link
Member Author

Choose a reason for hiding this comment

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

The current approach in this class is that they don't have Async suffix.

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.

[Request] Add 'WithParamName' validation extension for 'ArgumentException' and derived exception types
3 participants