Skip to content
Merged
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
7 changes: 7 additions & 0 deletions ArchUnit.sln
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArchUnitNET.TUnitTests", "A
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InterfaceAssembly", "TestAssemblies\InterfaceAssembly\InterfaceAssembly.csproj", "{076E223C-32D3-4672-8B00-925CDBC1383E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FilteredDirectoryAssemblyAttributeAssembly", "FilteredDirectoryAssemblyAttributeAssembly\FilteredDirectoryAssemblyAttributeAssembly.csproj", "{AA695589-8CCC-4474-9A7F-01A6376C375A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -136,6 +138,10 @@ Global
{076E223C-32D3-4672-8B00-925CDBC1383E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{076E223C-32D3-4672-8B00-925CDBC1383E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{076E223C-32D3-4672-8B00-925CDBC1383E}.Release|Any CPU.Build.0 = Release|Any CPU
{AA695589-8CCC-4474-9A7F-01A6376C375A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AA695589-8CCC-4474-9A7F-01A6376C375A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA695589-8CCC-4474-9A7F-01A6376C375A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA695589-8CCC-4474-9A7F-01A6376C375A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -148,5 +154,6 @@ Global
{5A24529B-1794-4080-ADCC-77440BA0A0B3} = {B1191F18-91CB-4387-B775-A5EB64D3AC30}
{E6CB8C69-25F5-4C94-8EA3-D56E444EB46B} = {B1191F18-91CB-4387-B775-A5EB64D3AC30}
{076E223C-32D3-4672-8B00-925CDBC1383E} = {B1191F18-91CB-4387-B775-A5EB64D3AC30}
{AA695589-8CCC-4474-9A7F-01A6376C375A} = {B1191F18-91CB-4387-B775-A5EB64D3AC30}
EndGlobalSection
EndGlobal
7 changes: 6 additions & 1 deletion ArchUnitNET/Loader/MonoCecilAttributeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ TypeFactory typeFactory
var attributeType = typeFactory.GetOrCreateStubTypeInstanceFromTypeReference(
attributeTypeReference
);
if (!(attributeType.Type is Attribute attribute))
var attribute = attributeType.Type as Attribute;
if (attributeType.Type is UnavailableType unavailableType)
{
attribute = new Attribute(unavailableType, null, null);
}
if (attribute == null)
{
throw new ArgumentException(
$"Attribute type {attributeType.Type.FullName} is not an attribute."
Expand Down
8 changes: 6 additions & 2 deletions ArchUnitNETTests/Loader/ArchLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
extern alias OtherLoaderTestAssemblyAlias;

using System;
using System.IO;
using System.Linq;
using ArchUnitNET.Domain;
using ArchUnitNET.Domain.Extensions;
Expand Down Expand Up @@ -132,15 +133,18 @@ public void UnavailableTypeTest()
// When loading an assembly from a file, there are situations where the assemblies dependencies are not
// available in the current AppDomain. This test checks that the loader does not throw an exception in this
// case.
var assemblyPath = AppDomain.CurrentDomain.BaseDirectory[
var currentAssemblyPath = AppDomain.CurrentDomain.BaseDirectory[
..AppDomain.CurrentDomain.BaseDirectory.IndexOf(
@"ArchUnitNETTests",
StringComparison.InvariantCulture
)
];
var assemblySearchPath = Path.Combine(
[currentAssemblyPath, "TestAssemblies", "FilteredDirectoryLoaderTestAssembly"]
);
var architecture = new ArchLoader()
.LoadFilteredDirectory(
assemblyPath,
assemblySearchPath,
"FilteredDirectoryLoaderTestAssembly.dll",
System.IO.SearchOption.AllDirectories
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace FilteredDirectoryAssemblyAttributeAssembly;

[AttributeUsage(AttributeTargets.Assembly)]
public class AssemblyAttribute : Attribute { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
2 changes: 2 additions & 0 deletions TestAssemblies/FilteredDirectoryLoaderTestAssembly/Class1.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Serilog;

[assembly: FilteredDirectoryAssemblyAttributeAssembly.AssemblyAttribute]

namespace FilteredDirectoryLoaderTestAssembly;

public class Class1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,11 @@
<PackageReference Include="Serilog" Version="4.2.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\FilteredDirectoryAssemblyAttributeAssembly\FilteredDirectoryAssemblyAttributeAssembly.csproj">
<!-- Do not copy the referenced assembly to the output directory -->
<!-- in order to test handling of unavailable types as attribute assemblies -->
<Private>False</Private>
</ProjectReference>
</ItemGroup>
</Project>
Loading