-
Notifications
You must be signed in to change notification settings - Fork 743
Properties on System.Type cannot be used with either property constraint #2436
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
Comments
Affected versions: 2.5.7–3.8.1. (Didn't test < 2.5.7.) |
So this is what's going on: nunit/src/NUnitFramework/framework/Constraints/PropertyConstraint.cs Lines 61 to 63 in dba87e5
I think when |
I guess this a design question now. Do you agree that my fallback suggestion is more intuitive than the current ArgumentException and uselessness of PropertyValueConstraint on System.Type objects? |
Hang on. I understand examining a type rather than an instance for the property existence constraint, but how does it make sense to examine a type rather than an instance for the property value constraint? You can't have a value without an instance anyway. |
I'd say you should separate this from the collection issue in order to zero in on any problem. What happens if you do Assert.That(typeof(TopLevelType, Has.Property("IsNested"));
Assert.That(typeof(TopLevelType.NestedType, Has.Property("IsNested")); I can't think of a common use for this sort of assertion, but it seems like it should be possible. You might use it in a library for accessing type information. |
@CharliePoole Sure, I can see that for the property existence constraint, but not for the property value constraint. I also can't see why the property existence constraint can't fall back to examining properties on the passed object instance if it fails to find the properties via the passed object's GetProperty method. In order of preference:
|
@jnm2 We're missing each other here. I'm still back at trying to confirm there is a problem. Your original example seems to me to confuse the issue by involving a collection constraint, which could be the source of further problems. Therefore I was suggesting you verify there is a problem using a plain property constraint (i.e. try oth An instance of So... what happens if you do the following... Assert.That(typeof(TopLevelType, Has.Property("IsNested"));
Assert.That(typeof(TopLevelType.NestedType, Has.Property("IsNested")); The question was not rhetorical. 😄 Also, what happens with Assert.That(typeof(TopLevelType, Has.Property("IsNested").EqualTo(false));
Assert.That(typeof(TopLevelType.NestedType, Has.Property("IsNested").EqualTo(true)); If those don't all succeed, I'll agree there is an issue. |
@CharliePoole I'm sorry, I must not have answered directly. It's inherent to the property constraints and unrelated to the collection constraint. Assert.That(typeof(TopLevelType, Has.Property("IsNested"));
Assert.That(typeof(TopLevelType.NestedType, Has.Property("IsNested")); ^ Allows you to check the existence of properties defined on Assert.That(typeof(TopLevelType, Has.Property("IsNested").EqualTo(true));
Assert.That(typeof(TopLevelType.NestedType, Has.Property("IsNested").EqualTo(true)); ^ Currently does not work at all for any purpose if the instance you pass in is a System.Type. |
So, has it always been that way or is it a consequence of the recent changes that were intended to bring the two constraints more in line with one another WRT messages? |
My usual sequence...
😃 |
There does seem to be a bug here, as indicated by the last two assertions. |
I've verified that this is the behavior as far back into v2 as we have on NUnit. This is not a regression. As to 4, that is this comment. 😄 |
Understood, you were just getting a bit ahead of me there. |
My guess would be that it was an organically overlooked scenario when making property constraints composable to assert against property values. |
I think I like your option 1 best, but we should get other comments on it. Can you post an example of an assertion that would be broken by the change? |
Given:
I get:
Just as though the
.None.With
was not there!But it gets weirder. If I use any type other than System.Type, it behaves:
Gives what it should:
The text was updated successfully, but these errors were encountered: