TNG / ArchUnitNET

A C# architecture test library to specify and assert architecture rules in C# for automated testing.
Apache License 2.0
877 stars 57 forks source link

Tests are always passing in latest 0.10+nuget package #162

Closed msmolka closed 2 years ago

msmolka commented 2 years ago

I have test:

using static ArchUnitNET.Fluent.ArchRuleDefinition;
    [Fact]
    public void EntityFrameworkCore_ShouldOnlyResideInInfrastructure_WhenEntityFrameworkCoreIsUsed()
    {
        IArchRule validatorNamingConventionRule = Classes().That()
            .DependOnAny("Microsoft.EntityFrameworkCore").And().DoNotResideInNamespace("Microsoft.Extensions.DependencyInjection")
            .Should()
            .NotResideInNamespace("Infrastructure.Data.EntityFramework");

        validatorNamingConventionRule.Check(Architecture);
    }

That is properly failing in version 0.9.1 but passing in version 0.10+

fgather commented 2 years ago

Hi @msmolka , how do you load your assemblies?

In cases where many third-party dependencies are loaded, it is not a good idea to fully load all of them, since it might take a while. As long as the recursive parameter in the LoadAssemblyIncludingDependencies is not set, it would only load direct dependencies and create stubs for all the others. -> does the test work if you set this recurse parameter?

Best Regards, Florian

msmolka commented 2 years ago

Whole my code is above. How can I modify it to load assembles?

Classes(true)

and

protected static readonly Architecture Architecture = new ArchLoader().LoadAssembliesIncludingDependencies(typeof(User).Assembly).Build();

also not working.

Including deps is teribly slow. And was not needed on version 0.9. But even including is not working. Version 0.9 works 0.10 not

brandhuf commented 2 years ago

With version 0.10 the default behaviour for string matching was changed. Previously

DependOnAny("Microsoft.EntityFrameworkCore")

found all types which had a dependency to a type with Microsoft.EntityFrameworkCore contained in it's full name. Now it only find dependencies to types with the exact full name Microsoft.EntityFrameworkCore. The same is true for all other methods which use strings as matching parameters. You can specify to use regex instead if you want to match parts of the full name:

DependOnAny("Microsoft.EntityFrameworkCore", useRegularExpressions:true)

Maybe this is the reason the behaviour of your rule changed?

msmolka commented 2 years ago

Looks working now