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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail with better exception if guard is invalid #1024

Merged

Conversation

zvirja
Copy link
Member

@zvirja zvirja commented Apr 22, 2018

Closes #1010

Improved the failure message in case Guard Clause is present, but is invalid (e.g. wrong parameter name is passed to ArgumentNullException constructor). New exception message:

AutoFixture.Idioms.GuardClauseException: An attempt was made to assign the value <null> to the property Property, and Guard Clause prevented it, however the thrown exception contains invalid parameter name. Ensure you pass correct parameter name to the ArgumentNullException constructor.
Expected parameter name: value
Actual parameter name: invalidParamName
Property Type: System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Declaring Type: AutoFixture.IdiomsUnitTest.GuardClauseAssertionTest+NonProperlyGuardedClass, AutoFixture.IdiomsUnitTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Reflected Type: AutoFixture.IdiomsUnitTest.GuardClauseAssertionTest+NonProperlyGuardedClass, AutoFixture.IdiomsUnitTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

@moodmosaic Please take a look 馃槈

@zvirja zvirja force-pushed the missing-guard-fail-with-better-message branch 2 times, most recently from 91bead2 to c35a4f2 Compare April 23, 2018 08:40
@zvirja zvirja requested a review from moodmosaic April 23, 2018 08:43
@zvirja zvirja changed the title [WIP] Fail with better exception if guard is invalid Fail with better exception if guard is invalid Apr 23, 2018
@zvirja zvirja force-pushed the missing-guard-fail-with-better-message branch from c35a4f2 to 073b9e1 Compare April 23, 2018 08:52
Previously we failed with "Missing Guard" error even if
guard was actually present, but contained wrong parameter name.
To avoid confusion now we fail with a different message.
@zvirja zvirja force-pushed the missing-guard-fail-with-better-message branch from 073b9e1 to 476c468 Compare April 23, 2018 16:06
@moodmosaic
Copy link
Member

馃寠

@zvirja zvirja merged commit f2378ec into AutoFixture:master Apr 25, 2018
@zvirja zvirja deleted the missing-guard-fail-with-better-message branch April 25, 2018 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants