Skip to content

Commit

Permalink
Added attributes inheritance support
Browse files Browse the repository at this point in the history
  • Loading branch information
vmingazhev committed Sep 26, 2023
1 parent 38394d9 commit 212a0b5
Showing 1 changed file with 20 additions and 1 deletion.
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;
}
}
}
}
}

0 comments on commit 212a0b5

Please sign in to comment.