-
Notifications
You must be signed in to change notification settings - Fork 748
Bug: Assert.That(IEnumerable<Type>, Has.All.Property(nameof(Type.Namespace)) fails. #4259
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
Thanks for the details and minimal reproduction @andrewimcclement As you say, there's a difference in the type of
I suspect there's a boxing going on in |
@stevenaw
This shouldn't be an issue as the code retrieves the real type here: https://github.com/nunit/nunit/blob/master/src/NUnitFramework/framework/Constraints/PropertyConstraint.cs#L74 That code works for all other types, except somehow for
Removing the "code exception" for Type and change the code from: Seems to fix this. (when changing the value in the debugger). I'll create a PR to see if this breaks any existing tests. |
Thanks for the in-depth look and analysis @manfred-brands , appreciate it! |
The problem is distinguishing between:
There are actually two different property constraints: |
I'm on the phone but this sounds very similar to #2436, but I've only skimmed the thread |
@mikkelbu yes that issue looks the same. Somehow that high priority issue from 2017 got forgotten. I guess there are only a few places where it surfaces. |
Originally posted as https://stackoverflow.com/questions/74475185.
Using NUnit v3.13.2, .NET Framework 4.8, running using ReSharper test runner. I'll try to find some time to run this with just nunit console runner and/or actually debug this myself.
I want to assert that all the types I am interested in are in the expected namespace using NUnit.
This fails with
ArgumentException Property Namespace not found on ...
.(Note the
StartsWith
is irrelevant.)However, the equivalent non-collection assert
Has.Property(nameof(Type.Namespace)).StartsWith("MyNamespace")
succeeds.I assume that this is a bug, if not, let's make sure the documentation is clear about how this is supposed to work.
Minimal reproducible example:
When running this test, we get
Potentially relevant comment from Ralf on the stackoverflow question:
Debugging through NUnit i would assume a bug here. When using Property on the AllItemConstraint there is an extra handling when the thing in there is already a type. It does not create a type on the type that you would need for your code to work. Now it searches "Namespace" on Foo and not on the type object of Foo.
The text was updated successfully, but these errors were encountered: