-
Notifications
You must be signed in to change notification settings - Fork 715
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
Add WithParameterName #1466
Conversation
/// </param> | ||
public static ExceptionAssertions<TException> WithParameterName<TException>( | ||
this ExceptionAssertions<TException> parent, | ||
string paramName, |
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 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.
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 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); |
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.
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?
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.
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>( |
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.
Shouldn't this one have the Async
suffix?
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.
The current approach in this class is that they don't have Async
suffix.
Add
WithParameterName
extension to assert on theParamName
property onArgumentException
.This fixes #1453