BenMorris / NetArchTest

A fluent API for .Net that can enforce architectural rules in unit tests.
MIT License
1.39k stars 82 forks source link

Predicates.Inherit incorrectly identifies some types as inheriting from unrelated types #56

Closed wardac closed 4 years ago

wardac commented 4 years ago

I have a type that inherits from Microsoft.AspNetCore.ActionResult and it is detected as inheriting from Microsoft.EntityFrameworkCore.DbContext, even though it does not.

This appears to be because the TypeDefinitions for ActionResult and DbContext have the same MetadataToken, which is all TypeDefinitionExtensions.IsSubClassOf checks for. However, a MetadataToken only uniquely identifies a type within a Module, not in general.

To correctly determine if one class inherits from another, TypeDefinitionExtensions.IsSubClassOf should also ensure that the Module of the two TypeDefinitions match.

BenMorris commented 4 years ago

This has been fixed in #52