BenMorris / NetArchTest

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

ImplementInterface does not select types implementing that interface #69

Closed sm-g closed 4 years ago

sm-g commented 4 years ago

i.e. interfaces from https://github.com/jbogard/MediatR/blob/master/src/MediatR/IRequest.cs

and my code:

public class MyQuery : IRequest<Guid>
{
}

and failing test:

Types.InAssembly(MyAssembly)
            .That()
            .ImplementInterface(typeof(IBaseRequest))
            .GetTypes().Should().Contain(typeof(MyQuery))
BenMorris commented 4 years ago

After the changes in #62:

Given the interfaces and classes:

public interface IBaseRequest { }

public interface IRequest<T> : IBaseRequest { }

public class MyQuery : IRequest<string> { }

The following will yield MyQuery:

Types.InCurrentDomain()
    .That()
    .AreClasses()
    .And()
    .ImplementInterface(typeof(IBaseRequest))
    .GetTypes();
NeVeSpl commented 4 years ago

Are you sure about that? ImplementInterface() does not use dependency search, so I would be very surprised if #62 would change anything in this mater. The same goes for #71

BenMorris commented 4 years ago

It's more accurate to say that I can't replicate this on the current version of the master code branch.

Perhaps the problems are more down to usage and interpretation.

Yaevh commented 3 years ago

The issue seems to be caused by Mono.Cecil and its handling of interfaces, see https://github.com/jbevain/cecil/issues/625. The example given in that issue also seems to fail on NetArchTest.