-
-
Notifications
You must be signed in to change notification settings - Fork 542
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
Add new namespace assertions to TypeSelectorAssertions #1175
Comments
Looks like useful additions - I didn't think about those when I initially wrote #645 |
You could potentially also add Ah! I assumed that types in the global namespace would have |
Good suggestion indeed. We are open to a PR ;-) |
I just noticed that the current |
I'm not sure whether the original intention of I do note that changing it to the way you specify could break the following made-up test, which validly relies on the current behavior. namespace FOO.BAR
{
class A {}
}
namespace FOO.BAZ
{
class B {}
} AllTypes.From(...)
.ThatAreUnderNamespace("FOO.BA")
.As<IEnumerable<Type>>()
.Should()
.HaveCount(2); |
Yep. Changing it would be a breaking change. However, I think the filter name specifies the intention that it looks at nested namespaces, not namespace prefixes. Otherwise, it could have been named |
In any case, shouldn't I implement and test that the |
Indeed they should match. |
I'll do that when these new assertions have merged. Other inconsistencies/bugs:
Should I also just mirror that behavior in the assertions? |
I'm not sure I follow you (My brain has been in complete weekend mode ever since I had brunsviger for breakfast). |
I completely understand what brunsviger can do to the brain. Here are some examples: For classes: class ClassInGlobalNamespace { }
namespace DummyNamespace {
class ClassInDummyNamespace { }
} And for type selectors: var typeInGlobalNamespace = typeof(ClassInGlobalNamespace);
var typesInGlobalNamespace = new TypeSelector(typeInGlobalNamespace);
var typeInDummyNamespace = typeof(ClassInDummyNamespace);
var typesInDummyNamespace = new TypeSelector(typeInDummyNamespace); I would expect that: typesInGlobalNamespace.ThatAreUnderNamespace(typeInGlobalNamespace.Namespace).Count()
== typesInGlobalNamespace.ThatAreUnderNamespace(null).Count()
== 1
typesInGlobalNamespace.ThatAreNotUnderNamespace(typeInGlobalNamespace.Namespace).Count()
== typesInGlobalNamespace.ThatAreNotUnderNamespace(null).Count()
== 0
typesInDummyNamespace.ThatAreUnderNamespace(null).Count()
== 1
typesInDummyNamespace.ThatAreNotUnderNamespace(null).Count()
== 0 However, with the existing implementation: typesInGlobalNamespace.ThatAreUnderNamespace(typeInGlobalNamespace.Namespace).Count()
== typesInGlobalNamespace.ThatAreUnderNamespace(null).Count()
== 0
typesInGlobalNamespace.ThatAreNotUnderNamespace(typeInGlobalNamespace.Namespace).Count()
== typesInGlobalNamespace.ThatAreNotUnderNamespace(null).Count()
== 1
typesInDummyNamespace.ThatAreUnderNamespace(null).Count()
// throws an ArgumentNullException
typesInDummyNamespace.ThatAreNotUnderNamespace(null).Count()
// throws an ArgumentNullException |
Just to summarise the two bugs I'm seeing and agree with:
The second tests aren't failing for me? typesInGlobalNamespace.ThatAreNotUnderNamespace(typeInGlobalNamespace.Namespace).Count()
== typesInGlobalNamespace.ThatAreNotUnderNamespace(null).Count()
== 0 |
Oh, you're right. If you want to keep the concise form of the existing I'll create a new issue for this. |
This is most definitely a design flaw. We never intended to be able to check a namespace against a partial string |
I've opened #1196 to track issue with |
Description
Currently, TypeSelectorAssertions only contains methods for asserting that types are (not) decorated with specific attributes, e.g.,
BeDecoratedWith<>
. However, TypeSelector contains more selectors that would also be useful as assertions.One such group of selectors filter on the namespace of types and contain the methods
ThatAreInNamespace
,ThatAreNotInNamespace
,ThatAreUnderNamespace
, andThatAreNotUnderNamespace
. Corresponding assertions could be namedBeInNamespace
,NotBeInNamespace
,BeUnderNamespace
, andNotBeUnderNamespace
.Use case
A concrete use case I have that prompted this suggestion is that the JsonSubTypes library, which is used to deserialize JSON into one of a number of subclasses based on a discriminator value, only supports deserializing into subclasses in the same namespace as the base class. Therefore, I would like to be able to write a test that asserts that all subclasses of a specific class are in the same namespace as it, à la:
Draft implementation as custom extension
To support the use case above, I have implemented the
BeInNamespace
assertion in our project as the following custom extension:The text was updated successfully, but these errors were encountered: