How to use the user-provided message? #125
Unanswered
stephenemerson85
asked this question in
Q&A
Replies: 1 comment
-
Seems like you may have discovered a bug. Here is the only unit test for that overload of that method: [Theory]
[InlineData(null, "Required input parameterName was empty.")]
[InlineData("Value is empty", "Value is empty")]
public void ErrorMessageMatchesExpected(string customMessage, string expectedMessage)
{
var exception = Assert.Throws<ArgumentException>(() => Guard.Against.NullOrWhiteSpace(" ", "parameterName", customMessage));
Assert.NotNull(exception);
Assert.NotNull(exception.Message);
Assert.Equal(expectedMessage + " (Parameter 'parameterName')", exception.Message);
} The second test seems to show that the customMessage should show up followed by " (Parameter 'parametername')". That's not what you're seeing? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I watched Nick Chapsas tutorial on GuardClauses and I think it's a really neat package that helps make the code more readable and control exceptions.
One issue I'm trying to work out is how I would use the supplied-message within the catch? Normally I would just do something like ex.Message and my understanding is that it's setting the Message, but when doing this I am getting the generic Message and Input value rather than my own that i typed in.
Example
Guard.Against.NullOrWhiteSpace(FirstName, nameof(FirstName), "You must provide a first name");
When i deliberately cause the exception to throw, this is the Message that comes though.
Required input FirstName was empty. Parameter name: FirstName
Beta Was this translation helpful? Give feedback.
All reactions