BenMorris / NetArchTest

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

In an ASP.NET Core 3.1 API, the tests are always passed #47

Closed anaselhajjaji closed 4 years ago

anaselhajjaji commented 4 years ago

My test is:

public void ApiController_DoesNotHaveDependency_ToRepository()
{
    Assembly ApiAssembly = typeof(Startup).Assembly;

    var otherModules = new List<string>
    {
        "ModuleNamespace"
    };
    var result = Types.InAssembly(ApiAssembly)
        .That()
        .ResideInNamespace("TheApiNamespace")
        .Should()
        .NotHaveDependencyOnAny(otherModules.ToArray())
        .GetResult();

    Assert.That(result.FailingTypes, Is.Null.Or.Empty);
}

When I tried to figure out why I noticed the following thing: image

It's like the library doesn't see the types in the assembly.

BenMorris commented 4 years ago

Sorry, but I just can't replicate this.

I'd need to see an example of a class that is not being picked up?

anaselhajjaji commented 4 years ago

Thank you for your prompt answer. My project is in: https://github.com/anaselhajjaji/systemdhealthcheck The ArchTest in: https://github.com/anaselhajjaji/systemdhealthcheck/tree/master/ArchTests

NeVeSpl commented 4 years ago

Problem is in that every type inside of namespace that starts with prefix "System" is excluded, and your project namespace is "SystemdHealthcheck". Fixed in #48.

anaselhajjaji commented 4 years ago

Yes, it was due to the System word in the namespace, I renamed my namespaces and it worked. Thank you, I'll close the issue.