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

How to check for annotations #227

Closed achimmihca closed 6 months ago

achimmihca commented 6 months ago

I want to check that if a class has a specific annotation (e.g. MyAnnotation), then it should implement a specific interface (e.g. MyInterface).

Example:

public class GoodImpl : MyInterface
{
    [MyAnnotation]
    private bool foo;
}

public class BadImpl /* issue: does not implement MyInterface */
{
    [MyAnnotation]
    private bool bar;
}

However, I did not find any methods for annotations. Did I look in the wrong place or is this not supported?

Thank you for this great port of ArchUnit ❤️ !

achimmihca commented 6 months ago

Did I look in the wrong place

Yes!

There are lots of methods like HaveAnyAttributes, HaveAttributeWithArguments, etc.

Nevermind.