nunit: Improve PropertyConstraint error output
I normally get far too distracted by interesting but niche things. This is one that bites me almost daily.
I use PropertyConstraint a lot - this is the error message that’s currently shown when the property can’t be found on the object.

I hit this regularly - either because my constraint is not actually on the object I think it is, because I go the property name wrong, or because I’m trying to look at an explicit interface implementation.
I want to improve this so it provides a proper error message rather than stack trace. What I’m interested in seeing is:
- The property name I was looking for. (I almost always use
nameof()here - maybe the string passed in wasn’t what I thought) - The type of the object I’m looking for the property on.
I’ll PR this at some point - any other suggestions before I do? I considered listing all available property names - but decided against it as it could get noisy quickly.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 24 (24 by maintainers)
@jnm2 I believe we are all in violent agreement!
Well, @ChrisMaddock accidentally convinced me of that point of view in the first part of this thread, but it turned out I misunderstood him. 😃
My logic in implementing this was that
Has.Property("Name")implies you don’t know if the property exists and are testing for it, whileHas.Property("Name").EqualTo("Something")means you are checking the value of a property, which you know is there. It seemed unlikely to me that you would be checking the value of a property, which might not exist. Clearly, it can be understood in other ways.We should make sure that whatever we end up with is clearly stated in the docs.