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

BeAssignableTo does not work across multiple layers of inheritance and multiple assemblies #320

Open
tnotheis opened this issue Oct 28, 2024 · 5 comments
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@tnotheis
Copy link

My ArchUnit tests test for assignability across multiple layers of inheritance, like so:

// Assembly 1
public class Parent;

// Assembly 2
public class Child : Parent;

// Assembly 3
public class Grandchild : Child;

// ArchUnit test
public class Tests
{
    private static readonly Architecture Architecture = new ArchLoader()
            .LoadAssemblies(typeof(Parent).Assembly, typeof(Child).Assembly, typeof(Grandchild).Assembly)
            .Build();
    
    [Fact]
    public void Test()
    {
        Classes().That().Are(typeof(Grandchild))
            .Should().BeAssignableTo(typeof(Parent))
            .Check(Architecture);
    }
}

(I created a minimal example, which you can find here: https://github.com/tnotheis/archunit-bug-example)

With version 0.11.0 this worked just fine. But since I upgraded to version 0.11.1, the test fails with the following error:

AssemblyOfGrandchild.Grandchild is not assignable to "AssemblyOfParent.Parent"

It only fails if Child and Grandchild reside in different assemblies. If you move the Grandchild class into AssemblyOfChild the test passes.

@NicolaSeitz
Copy link

Are there any Updates about this Bug?

@alexanderlinne alexanderlinne added the kind/bug Categorizes issue or PR as related to a bug. label Jan 24, 2025
@alexanderlinne
Copy link
Collaborator

Hi, this is currently caused by types not being resolved correctly and is fixed by #318. I'll see that I get this PR merged soon.

@alexanderlinne alexanderlinne self-assigned this Jan 24, 2025
@alexanderlinne
Copy link
Collaborator

We've just released #318 as a preview release 0.11.3-preview.1. Would you be able to check whether this resolves this issue for you?

@NicolaSeitz
Copy link

I just tested my cases quickly and it looks like it works so far 😊

@NicolaSeitz
Copy link

NicolaSeitz commented Jan 27, 2025

@alexanderlinne
After retest, for the given case it works, but with freezing files there is a problem because the EvaluatedObjectIdentifier is not unique,
when working with multiple assemblies with same namespaces.

if (
frozenViolations.Contains(
evalResult.EvaluatedObjectIdentifier,
new StringIdentifierComparer()
) && !evalResult.Passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

No branches or pull requests

3 participants