Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fill the ReferencedAssemblyNames property for all loaded assemblies #311 #319

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions ArchUnitNET/Domain/Assembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;

namespace ArchUnitNET.Domain
{
Expand All @@ -16,7 +15,7 @@ public Assembly(
string name,
string fullName,
bool isOnlyReferenced,
[CanBeNull] List<string> referencedAssemblyNames
List<string> referencedAssemblyNames
)
{
Name = name;
Expand All @@ -29,7 +28,6 @@ [CanBeNull] List<string> referencedAssemblyNames

public string Name { get; }

[CanBeNull]
public List<string> ReferencedAssemblyNames { get; }
public string FullName { get; }

Expand Down
5 changes: 2 additions & 3 deletions ArchUnitNET/Loader/ArchBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ public ArchBuilder()

public void AddAssembly(
[NotNull] AssemblyDefinition moduleAssembly,
bool isOnlyReferenced,
[CanBeNull] IEnumerable<AssemblyNameReference> moduleReferences
bool isOnlyReferenced
)
{
var references = moduleReferences?.Select(reference => reference.Name).ToList();
var references = moduleAssembly.MainModule.AssemblyReferences.Select(reference => reference.Name).ToList();

if (!_assemblyRegistry.ContainsAssembly(moduleAssembly.Name.FullName))
{
Expand Down
6 changes: 3 additions & 3 deletions ArchUnitNET/Loader/ArchLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private void LoadModule(
var processedAssemblies = new List<AssemblyNameReference> { module.Assembly.Name };
var resolvedModules = new List<ModuleDefinition>();
_assemblyResolver.AddLib(module.Assembly);
_archBuilder.AddAssembly(module.Assembly, false, module.AssemblyReferences);
_archBuilder.AddAssembly(module.Assembly, false);
foreach (var assemblyReference in module.AssemblyReferences)
{
if (includeDependencies && recursive)
Expand All @@ -157,7 +157,7 @@ private void LoadModule(
var assemblyDefinition =
_assemblyResolver.Resolve(assemblyReference)
?? throw new AssemblyResolutionException(assemblyReference);
_archBuilder.AddAssembly(assemblyDefinition, false, null);
_archBuilder.AddAssembly(assemblyDefinition, false);
resolvedModules.AddRange(assemblyDefinition.Modules);
}
}
Expand Down Expand Up @@ -203,7 +203,7 @@ FilterFunc filterFunc
var filterResult = filterFunc?.Invoke(assemblyDefinition);
if (filterResult?.LoadThisAssembly != false)
{
_archBuilder.AddAssembly(assemblyDefinition, false, null);
_archBuilder.AddAssembly(assemblyDefinition, false);
resolvedModules.AddRange(assemblyDefinition.Modules);
}

Expand Down
16 changes: 14 additions & 2 deletions ArchUnitNETTests/Loader/ArchLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,18 @@ public void SameFullNameInMultipleAssemblies()
[Fact]
public void LoadAssembliesIncludingRecursiveDependencies()
{
var archUnitNetTestArchitectureWithRecursiveDependencies = new ArchLoader()
var architecture = new ArchLoader()
.LoadAssembliesIncludingDependencies(new[] { typeof(BaseClass).Assembly }, true)
.Build();

Assert.True(
archUnitNetTestArchitectureWithRecursiveDependencies.Assemblies.Count() > 100
architecture.Assemblies.Count() > 100
);

// Check for well-known assemblies, that ReferencedAssemblyNames is not empty
Assert.All(
architecture.Assemblies.Where(x => x.Name.StartsWith("ArchUnit")),
x => Assert.NotEmpty(x.ReferencedAssemblyNames)
);
}

Expand All @@ -63,6 +69,12 @@ public void LoadAssembliesRecursivelyWithCustomFilter()
.Build();

Assert.Equal(3, architecture.Assemblies.Count());

// Check that ReferencedAssemblyNames is not empty
Assert.All(
architecture.Assemblies,
x => Assert.NotEmpty(x.ReferencedAssemblyNames)
);
}

[Fact]
Expand Down