diff --git a/ArchUnitNET/Domain/Assembly.cs b/ArchUnitNET/Domain/Assembly.cs index f80701859..497cc6875 100644 --- a/ArchUnitNET/Domain/Assembly.cs +++ b/ArchUnitNET/Domain/Assembly.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Linq; -using JetBrains.Annotations; namespace ArchUnitNET.Domain { @@ -10,7 +9,7 @@ public Assembly( string name, string fullName, bool isOnlyReferenced, - [CanBeNull] List referencedAssemblyNames + List referencedAssemblyNames ) { Name = name; @@ -23,7 +22,6 @@ [CanBeNull] List referencedAssemblyNames public string Name { get; } - [CanBeNull] public List ReferencedAssemblyNames { get; } public string FullName { get; } diff --git a/ArchUnitNET/Loader/ArchBuilder.cs b/ArchUnitNET/Loader/ArchBuilder.cs index 9e67c366b..55919fda4 100644 --- a/ArchUnitNET/Loader/ArchBuilder.cs +++ b/ArchUnitNET/Loader/ArchBuilder.cs @@ -38,13 +38,11 @@ public ArchBuilder() public IEnumerable Assemblies => _assemblyRegistry.Assemblies; public IEnumerable Namespaces => _namespaceRegistry.Namespaces; - public void AddAssembly( - [NotNull] AssemblyDefinition moduleAssembly, - bool isOnlyReferenced, - [CanBeNull] IEnumerable moduleReferences - ) + public void AddAssembly([NotNull] AssemblyDefinition moduleAssembly, 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)) { diff --git a/ArchUnitNET/Loader/ArchLoader.cs b/ArchUnitNET/Loader/ArchLoader.cs index 6d2751889..5ac7ab920 100644 --- a/ArchUnitNET/Loader/ArchLoader.cs +++ b/ArchUnitNET/Loader/ArchLoader.cs @@ -128,7 +128,7 @@ private void LoadModule( var processedAssemblies = new List { module.Assembly.Name }; var resolvedModules = new List(); _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) @@ -151,7 +151,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); } } @@ -197,7 +197,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); } diff --git a/ArchUnitNETTests/Loader/ArchLoaderTests.cs b/ArchUnitNETTests/Loader/ArchLoaderTests.cs index f2e8d4e52..356e2d07a 100644 --- a/ArchUnitNETTests/Loader/ArchLoaderTests.cs +++ b/ArchUnitNETTests/Loader/ArchLoaderTests.cs @@ -63,12 +63,16 @@ 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 + Assert.True(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) ); } @@ -85,6 +89,9 @@ 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]