Skip to content
Merged
18 changes: 14 additions & 4 deletions Allure.NUnit/Core/AllureNUnitHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Allure.Net.Commons;
Expand Down Expand Up @@ -96,6 +95,7 @@ internal static TestResult CreateTestResult(ITest test)
var testResult = new TestResult
{
name = test.Name,
titlePath = EnumerateNamesFromTestFixtureToRoot(test).Reverse().ToList(),
labels = new List<Label>
{
Label.Thread(),
Expand Down Expand Up @@ -135,6 +135,16 @@ TestStatus.Failed when IsBroken(result) => Status.broken,
};
}

static IEnumerable<string> EnumerateNamesFromTestFixtureToRoot(ITest test)
{
for (ITest suite = GetTestFixture(test); suite is not null; suite = suite.Parent)
yield return suite switch
{
TestAssembly a => a.Assembly?.GetName()?.Name ?? a.Name,
_ => suite.Name,
};
}

TestResultContainer CreateTestContainer() =>
new()
{
Expand Down Expand Up @@ -236,17 +246,17 @@ static string GetClassName(string classFullName)
static TestFixture GetTestFixture(ITest test)
{
var currentTest = test;

while (currentTest != null)
{
if (currentTest is TestFixture testFixture)
{
return testFixture;
}

currentTest = currentTest.Parent;
}

throw new InvalidOperationException(
$"Could not find TestFixture in the hierarchy for test: {test.FullName}. " +
$"Test type: {test.GetType().Name}"
Expand Down
62 changes: 47 additions & 15 deletions Allure.Net.Commons.Tests/FunctionTests/IdTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,48 @@ public void TestUUIDGeneration()
);
}

[TestCase(typeof(IdTests), "Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests")]
[TestCase(typeof(ClassWithoutNamespace), "Allure.Net.Commons.Tests:ClassWithoutNamespace")]
[TestCase(typeof(MyClass), "Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass")]
[TestCase(typeof(MyClass<>), "Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass`1[T]")]
[TestCase(typeof(MyClass<string>), "Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass`1[System.String]")]
[TestCase(
typeof(IdTests),
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests",
TestName = "FullNameOfNonGenericClass"
)]
[TestCase(
typeof(ClassWithoutNamespace),
"Allure.Net.Commons.Tests:ClassWithoutNamespace",
TestName = "FullNameOfClassWithNoNamespace"
)]
[TestCase(
typeof(MyClass),
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass",
TestName = "FullNameOfNestedClass"
)]
[TestCase(
typeof(MyClass<>),
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass`1[T]",
TestName = "FullNameOfNestedGenericClassDefinition"
)]
[TestCase(
typeof(MyClass<string>),
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass`1[System.String]",
TestName = "FullNameOfNestedConstructedGenericClass"
)]
[TestCase(
typeof(MyClass<MyClass<string, int>, MyClass<MyClass>>),
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass`2[" +
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass`2[System.String,System.Int32]," +
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass`1[" +
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass]]"
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass]]",
TestName = "FullNameOfComplexConstructedGenericClass"
)]
[TestCase(
typeof(MyClass<>.Nested),
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass`1+Nested[T]",
TestName = "FullNameOfNestedClassOfGenericClassDefinition"
)]
[TestCase(
typeof(MyClass<int>.Nested),
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass`1+Nested[System.Int32]",
TestName = "FullNameOfNestedClassOfConstructedGenericClass"
)]
public void TestFullNameFromClass(Type targetClass, string expectedFullName)
{
Expand All @@ -55,6 +86,7 @@ internal void MethodWithArgumentOfGenericUserType<T>(MyClass<T> _) { }

class MyClass<T>
{
public class Nested { }
internal void GenericMethodOfGenericClass<V>(List<T> _, List<V> __) { }
}

Expand All @@ -63,21 +95,21 @@ class MyClass<T1, T2> { }
[TestCase(
nameof(MyClass.ParameterlessMethod),
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass.ParameterlessMethod()",
TestName = "ParameterlessMethod"
TestName = "FullNameOfParameterlessMethod"
)]
[TestCase(
nameof(MyClass.MethodWithParameterOfBuiltInType),
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass" +
".MethodWithParameterOfBuiltInType(System.Int32)",
TestName = "MethodWithParameterOfBuiltInType"
TestName = "FullNameOfMethodWithParameterOfBuiltInType"
)]
[TestCase(
nameof(MyClass.MethodWithParameterOfUserType),
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass" +
".MethodWithParameterOfUserType(" +
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass" +
")",
TestName = "MethodWithParameterOfUserType"
TestName = "FullNameOfMethodWithParameterOfUserType"
)]
[TestCase(
nameof(MyClass.MethodWithTwoParameters),
Expand All @@ -86,41 +118,41 @@ class MyClass<T1, T2> { }
"System.Int32," +
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass" +
")",
TestName = "MethodWithTwoParameters"
TestName = "FullNameOfMethodWithTwoParameters"
)]
[TestCase(
nameof(MyClass.MethodWithRefParameter),
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass" +
".MethodWithRefParameter(System.Int32&)",
TestName = "MethodWithRefParameter"
TestName = "FullNameOfMethodWithRefParameter"
)]
[TestCase(
nameof(MyClass.MethodWithGenericParameter),
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass" +
".MethodWithGenericParameter[T]()",
TestName = "MethodWithGenericParameter"
TestName = "FullNameOfMethodWithGenericParameter"
)]
[TestCase(
nameof(MyClass.MethodWithArgumentOfGenericType),
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass" +
".MethodWithArgumentOfGenericType[T](T)",
TestName = "MethodWithArgumentOfGenericType"
TestName = "FullNameOfMethodWithArgumentOfGenericType"
)]
[TestCase(
nameof(MyClass.MethodWithArgumentOfTypeParametrizedByGenericType),
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass" +
".MethodWithArgumentOfTypeParametrizedByGenericType[T](" +
"System.Collections.Generic.Dictionary`2[System.Int32,T]" +
")",
TestName = "MethodWithArgumentOfTypeParametrizedByGenericType"
TestName = "FullNameOfMethodWithArgumentOfTypeParametrizedByGenericType"
)]
[TestCase(
nameof(MyClass.MethodWithArgumentOfGenericUserType),
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass" +
".MethodWithArgumentOfGenericUserType[T](" +
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass`1[T]" +
")",
TestName = "MethodWithArgumentOfGenericUserType"
TestName = "FullNameOfMethodWithArgumentOfGenericUserType"
)]
public void FullNameFromMethod(string methodName, string expectedFullName)
{
Expand Down
124 changes: 124 additions & 0 deletions Allure.Net.Commons.Tests/FunctionTests/TitlePathTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
using System;
using System.Collections.Generic;
using Allure.Net.Commons.Functions;
using NUnit.Framework;

namespace Allure.Net.Commons.Tests.FunctionTests;

class TitlePathTests
{
[TestCase(
typeof(TitlePathTests),
"Allure.Net.Commons.Tests",
"Allure",
"Net",
"Commons",
"Tests",
"FunctionTests",
"TitlePathTests",
TestName = "Outmost type with namespave"
)]
[TestCase(
typeof(ClassWithoutNamespace),
"Allure.Net.Commons.Tests",
"ClassWithoutNamespace",
TestName = "Outmost type no namespace"
)]
[TestCase(
typeof(MyClass),
"Allure.Net.Commons.Tests",
"Allure",
"Net",
"Commons",
"Tests",
"FunctionTests",
"TitlePathTests+MyClass",
TestName = "Nested class"
)]
[TestCase(
typeof(MyClass<>),
"Allure.Net.Commons.Tests",
"Allure",
"Net",
"Commons",
"Tests",
"FunctionTests",
"TitlePathTests+MyClass`1[T]",
TestName = "Nested generic class definition"
)]
[TestCase(
typeof(MyClass<string>),
"Allure.Net.Commons.Tests",
"Allure",
"Net",
"Commons",
"Tests",
"FunctionTests",
"TitlePathTests+MyClass`1[System.String]",
TestName = "Nested constructed generic class - system type alias"
)]
[TestCase(
typeof(MyClass<DateTime>),
"Allure.Net.Commons.Tests",
"Allure",
"Net",
"Commons",
"Tests",
"FunctionTests",
"TitlePathTests+MyClass`1[System.DateTime]",
TestName = "Nested constructed generic class - system type"
)]
[TestCase(
typeof(MyClass<ClassWithoutNamespace>),
"Allure.Net.Commons.Tests",
"Allure",
"Net",
"Commons",
"Tests",
"FunctionTests",
"TitlePathTests+MyClass`1[Allure.Net.Commons.Tests:ClassWithoutNamespace]",
TestName = "Nested constructed generic class - custom type"
)]
[TestCase(
typeof(MyClass<MyClass<string, int>, MyClass<MyClass>>),
"Allure.Net.Commons.Tests",
"Allure",
"Net",
"Commons",
"Tests",
"FunctionTests",
"TitlePathTests+MyClass`2[" +
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.TitlePathTests+MyClass`2[System.String,System.Int32]," +
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.TitlePathTests+MyClass`1[" +
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.TitlePathTests+MyClass]]",
TestName = "Nested constructed generic class - complex"
)]
public void TestTitlePathByClass(Type targetClass, params string[] expectedTitlePath)
{
Assert.That(
IdFunctions.CreateTitlePath(targetClass),
Is.EqualTo(expectedTitlePath)
);
}

class MyClass
{
internal void ParameterlessMethod() { }
internal void MethodWithParameterOfBuiltInType(int _) { }
internal void MethodWithParameterOfUserType(MyClass _) { }
internal void MethodWithTwoParameters(int _, MyClass __) { }
internal void MethodWithRefParameter(ref int _) { }
internal void MethodWithGenericParameter<T>() { }
internal void MethodWithArgumentOfGenericType<T>(T _) { }
internal void MethodWithArgumentOfTypeParametrizedByGenericType<T>(Dictionary<int, T> _) { }
internal void MethodWithArgumentOfGenericUserType<T>(MyClass<T> _) { }
}

class MyClass<T>
{
public class Nested<G> { }
internal void GenericMethodOfGenericClass<V>(List<T> _, List<V> __) { }
}

class MyClass<T1, T2> { }
}
Loading
Loading