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

Added attributes inheritance support #385

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
21 changes: 20 additions & 1 deletion Allure.XUnit/AllureXunitHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private static void AddDistinct(this List<Label> labels, string labelName, strin

private static void UpdateTestDataFromAttributes(TestResult testResult, ITestCase testCase)
{
var classAttributes = testCase.TestMethod.TestClass.Class.GetCustomAttributes(typeof(IAllureInfo));
var classAttributes = GetCustomAttributesRecursive(testCase.TestMethod.TestClass.Class, typeof(IAllureInfo));
var methodAttributes = testCase.TestMethod.Method.GetCustomAttributes(typeof(IAllureInfo));

foreach (var attribute in classAttributes.Concat(methodAttributes))
Expand Down Expand Up @@ -279,5 +279,24 @@ private static string BuildFullName(ITestCase testCase)

return $"{testCase.TestMethod.TestClass.Class.Name}.{testCase.TestMethod.Method.Name}{parametersSegment}";
}

private static IEnumerable<IAttributeInfo> GetCustomAttributesRecursive(ITypeInfo typeInfo, Type attributeType)
{
foreach (var type in GetInheritanceTree(typeInfo).Reverse())
{
foreach (var attribute in type.GetCustomAttributes(attributeType.AssemblyQualifiedName))
yield return attribute;
}

static IEnumerable<ITypeInfo> GetInheritanceTree(ITypeInfo typeInfo)
{
var currentType = typeInfo;
while (currentType.ToRuntimeType() != typeof(object))
{
yield return currentType;
currentType = currentType.BaseType;
}
}
}
}
}