TNG / ArchUnitNET

A C# architecture test library to specify and assert architecture rules in C# for automated testing.
Apache License 2.0
927 stars 61 forks source link

How to check for annotations #227

Closed achimmihca closed 10 months ago

achimmihca commented 10 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 10 months ago

Did I look in the wrong place

Yes!

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

Nevermind.