Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ public static class FailedTestInitializationWriter
public static void GenerateFailedTestCode(ICodeWriter sourceBuilder,
DynamicTestSourceDataModel testSourceDataModel)
{
var testId = $"{testSourceDataModel.Class.ContainingNamespace}.{testSourceDataModel.Class.Name}.{testSourceDataModel.Method.Name}_InitializationFailure";
var className = testSourceDataModel.Class.GetNestedClassName();
var testId = $"{testSourceDataModel.Class.ContainingNamespace}.{className}.{testSourceDataModel.Method.Name}_InitializationFailure";

sourceBuilder.Append("return");
sourceBuilder.Append("[");
sourceBuilder.Append($"new global::TUnit.Core.FailedDynamicTest<{testSourceDataModel.Class.GloballyQualified()}>");
sourceBuilder.Append("{");
sourceBuilder.Append($"TestId = \"{testId}\",");
sourceBuilder.Append($"MethodName = $\"{testSourceDataModel.Method.Name}\",");
sourceBuilder.Append($"Exception = new global::TUnit.Core.Exceptions.TestFailedInitializationException(\"{testSourceDataModel.Class.Name}.{testSourceDataModel.Method.Name} failed to initialize\", exception),");
sourceBuilder.Append($"Exception = new global::TUnit.Core.Exceptions.TestFailedInitializationException(\"{className}.{testSourceDataModel.Method.Name} failed to initialize\", exception),");
sourceBuilder.Append($"TestFilePath = @\"{testSourceDataModel.FilePath}\",");
sourceBuilder.Append($"TestLineNumber = {testSourceDataModel.LineNumber},");
sourceBuilder.Append("}");
Expand Down
23 changes: 23 additions & 0 deletions TUnit.Core.SourceGenerator/Extensions/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,27 @@ public static bool IsCollectionType(this ITypeSymbol typeSymbol, Compilation com
innerType = null;
return false;
}

/// <summary>
/// Gets the nested class name with '+' separator (matching .NET Type.FullName convention).
/// For example: OuterClass+InnerClass
/// </summary>
public static string GetNestedClassName(this INamedTypeSymbol typeSymbol)
{
var typeHierarchy = new List<string>();
var currentType = typeSymbol;

// Walk up the containing type chain
while (currentType != null)
{
typeHierarchy.Add(currentType.Name);
currentType = currentType.ContainingType;
}

// Reverse to get outer-to-inner order
typeHierarchy.Reverse();

// Join with '+' separator (matching .NET Type.FullName convention for nested types)
return string.Join("+", typeHierarchy);
}
}
4 changes: 2 additions & 2 deletions TUnit.Engine/Services/TestIdentifierService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ private static string GetTypeNameWithGenerics(Type type)
// Reverse to get outer-to-inner order
typeHierarchy.Reverse();

// Append all types with dot separator
// Append all types with + separator (matching .NET Type.FullName convention for nested types)
for (var i = 0; i < typeHierarchy.Count; i++)
{
if (i > 0)
{
sb.Append('.');
sb.Append('+');
}
sb.Append(typeHierarchy[i]);
}
Expand Down
Loading