TNG / ArchUnitNET

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

Question: Load assemblies example #177

Closed ChangeTheCode closed 1 year ago

ChangeTheCode commented 1 year ago

I have a question about you example for loading the assemblies.

Create a Test private static readonly Architecture Architecture = new ArchLoader().LoadAssemblies(typeof(ExampleClass).Assembly, typeof(ForbiddenClass).Assembly) .Build();

You using a class instance to find the correct assembly to load it. This will assume that the class instance is in the correct assembly. From my point of view it could be that someone move this class and then the test isn't testing what it should.

From my point of view it would make more sense to use the System.Reflection.Assembly.Load("AssemblyName"). Advantages:

So now my question is there any reason which I didn't saw yet to use the class instances instead of loading the assembly by using the assembly name?

fgather commented 1 year ago

I think you're right here, your approach is cleaner and should be used in the example. I believe it was there due to the fact that we had a different loading mechanism in the past, which needed the class reference. Do you care to create a PR to fix it?

ChangeTheCode commented 1 year ago

@fgather I will create a PR to adapt this in the example