BenMorris / NetArchTest

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

Select types that are not inherited by any class #133

Open kristofferjalen opened 10 months ago

kristofferjalen commented 10 months ago

Say I have a class that inherits from another, non-abstract, class:

public sealed class UserNotFoundException : UserException { }

public class UserException : Exception { }

This will break my assertion that class should be sealed:

var result = Types.InCurrentDomain()
    .And().AreNotInterfaces()
    .And().AreNotAbstract()
    .Should().BeSealed()
    .GetResult();

Rather than filtering edge-cases:

    .And().DoNotInherit(typeof(Exception)) 

is there any way to select types that are not inherited by any class? Like:

var result = Types.InCurrentDomain()
    .And().AreNotInterfaces()
    .And().AreNotAbstract()
    .And().AreNotInheritedByAnyClass()  // <--- like this
    .Should().BeSealed()
    .GetResult();
NeVeSpl commented 10 months ago

It is interesting use case. As far as I know, right now it is not supported, but it looks like doable, and could be added in the future to the NetArchTest.