From ed95fb20569a5cd951b356986b98b6933f59e139 Mon Sep 17 00:00:00 2001 From: Tom Longhurst <30480171+thomhurst@users.noreply.github.com> Date: Fri, 16 Jan 2026 00:49:58 +0000 Subject: [PATCH 1/2] fix: add support for [GenerateGenericTest] on generic classes (#4431) ## Summary - Fix generic class handling in reflection mode by supporting [GenerateGenericTest] attribute - Fix init-only property setters for generic types (UnsafeAccessor doesn't work with open generics) ## Changes - **ReflectionTestDataCollector.cs**: Handle [GenerateGenericTest] attributes that explicitly specify type arguments for generic test classes - **TestMetadataGenerator.cs**: Use reflection-based setter for init-only properties on generic types instead of UnsafeAccessor ## Test cases Added test files in TUnit.TestProject/Bugs/4431/ demonstrating: - Generic class with [GenerateGenericTest] attribute - Generic class with [ClassDataSource] property injection - Various combinations of generic classes/methods with data sources Co-Authored-By: Claude Opus 4.5 --- .../Generators/TestMetadataGenerator.cs | 286 ++++++++++++++---- .../Discovery/ReflectionTestDataCollector.cs | 158 ++++++++-- .../Bugs/4431/ComprehensiveGenericTests.cs | 249 +++++++++++++++ .../Bugs/4431/OpenGenericTestClassTests.cs | 67 ++++ 4 files changed, 672 insertions(+), 88 deletions(-) create mode 100644 TUnit.TestProject/Bugs/4431/ComprehensiveGenericTests.cs create mode 100644 TUnit.TestProject/Bugs/4431/OpenGenericTestClassTests.cs diff --git a/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs b/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs index 794954eab0..627876749e 100644 --- a/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs +++ b/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs @@ -1530,22 +1530,39 @@ private static void GeneratePropertyInjections(CodeWriter writer, INamedTypeSymb // Generate appropriate setter based on whether property is init-only if (property.SetMethod.IsInitOnly) { - // For init-only properties, use UnsafeAccessor on .NET 8+, throw on older frameworks - writer.AppendLine("#if NET8_0_OR_GREATER"); - // Cast to the property's containing type if needed + // For init-only properties, use UnsafeAccessor on .NET 8+ (but not for generic types) + // UnsafeAccessor doesn't work with open generic types var containingTypeName = property.ContainingType.GloballyQualified(); + var isGenericContainingType = property.ContainingType.IsGenericType; - if (containingTypeName != className) + if (isGenericContainingType) { - writer.AppendLine($"Setter = (instance, value) => Get{property.Name}BackingField(({containingTypeName})instance) = ({propertyType})value,"); + // For generic types, use reflection-based setter + writer.AppendLine($"Setter = (instance, value) =>"); + writer.AppendLine("{"); + writer.Indent(); + writer.AppendLine($"var backingField = instance.GetType().GetField(\"<{property.Name}>k__BackingField\","); + writer.AppendLine(" global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic);"); + writer.AppendLine($"backingField?.SetValue(instance, ({propertyType})value);"); + writer.Unindent(); + writer.AppendLine("},"); } else { - writer.AppendLine($"Setter = (instance, value) => Get{property.Name}BackingField(({className})instance) = ({propertyType})value,"); + writer.AppendLine("#if NET8_0_OR_GREATER"); + // Cast to the property's containing type if needed + if (containingTypeName != className) + { + writer.AppendLine($"Setter = (instance, value) => Get{property.Name}BackingField(({containingTypeName})instance) = ({propertyType})value,"); + } + else + { + writer.AppendLine($"Setter = (instance, value) => Get{property.Name}BackingField(({className})instance) = ({propertyType})value,"); + } + writer.AppendLine("#else"); + writer.AppendLine("Setter = (instance, value) => throw new global::System.NotSupportedException(\"Setting init-only properties requires .NET 8 or later\"),"); + writer.AppendLine("#endif"); } - writer.AppendLine("#else"); - writer.AppendLine("Setter = (instance, value) => throw new global::System.NotSupportedException(\"Setting init-only properties requires .NET 8 or later\"),"); - writer.AppendLine("#endif"); } else { @@ -2936,10 +2953,15 @@ private static void GenerateReflectionFieldAccessors(CodeWriter writer, INamedTy } // Generate UnsafeAccessor methods for init-only properties (only on .NET 8+) - if (initOnlyPropertiesWithDataSources.Any()) + // Skip for generic types since UnsafeAccessor doesn't work with open generic types + var nonGenericProperties = initOnlyPropertiesWithDataSources + .Where(p => !p.ContainingType.IsGenericType) + .ToList(); + + if (nonGenericProperties.Any()) { writer.AppendLine("#if NET8_0_OR_GREATER"); - foreach (var property in initOnlyPropertiesWithDataSources) + foreach (var property in nonGenericProperties) { var backingFieldName = $"<{property.Name}>k__BackingField"; var propertyType = property.Type.GloballyQualified(); @@ -3653,61 +3675,80 @@ private static void GenerateGenericTestWithConcreteTypes( } } - // Process GenerateGenericTest attributes from both methods and classes - var generateGenericTestAttributes = testMethod.MethodAttributes + // Process GenerateGenericTest attributes from both class and method levels + // When both class and method are generic, we need to generate cartesian products + var methodGenerateGenericTestAttributes = testMethod.MethodAttributes .Where(a => a.AttributeClass?.Name == "GenerateGenericTestAttribute") .ToList(); - // For generic classes, also check class-level GenerateGenericTest attributes - if (testMethod.IsGenericType) - { - var classLevelAttributes = testMethod.TypeSymbol.GetAttributes() + var classLevelAttributes = testMethod.IsGenericType + ? testMethod.TypeSymbol.GetAttributes() .Where(a => a.AttributeClass?.Name == "GenerateGenericTestAttribute") - .ToList(); - generateGenericTestAttributes.AddRange(classLevelAttributes); - } + .ToList() + : new List(); + + // Extract type arguments from class-level attributes + var classTypeArgSets = ExtractTypeArgumentSets(classLevelAttributes); + + // Extract type arguments from method-level attributes + var methodTypeArgSets = ExtractTypeArgumentSets(methodGenerateGenericTestAttributes); - foreach (var genAttr in generateGenericTestAttributes) + // Handle all combinations + if (classTypeArgSets.Count > 0 && methodTypeArgSets.Count > 0 && testMethod.IsGenericMethod) { - // Extract type arguments from the attribute - if (genAttr.ConstructorArguments.Length > 0) + // Both class and method are generic - generate cartesian product + foreach (var classTypeArgs in classTypeArgSets) { - var typeArgs = new List(); - foreach (var arg in genAttr.ConstructorArguments) + foreach (var methodTypeArgs in methodTypeArgSets) { - if (arg is { Kind: TypedConstantKind.Type, Value: ITypeSymbol typeSymbol }) + // Validate both class and method constraints + if (ValidateClassTypeConstraints(testMethod.TypeSymbol, classTypeArgs) && + ValidateTypeConstraints(testMethod.MethodSymbol, methodTypeArgs)) { - typeArgs.Add(typeSymbol); - } - else if (arg.Kind == TypedConstantKind.Array) - { - foreach (var arrayElement in arg.Values) + // Combine class + method type arguments + var combinedTypes = classTypeArgs.Concat(methodTypeArgs).ToArray(); + var typeKey = BuildTypeKey(combinedTypes); + + if (processedTypeCombinations.Add(typeKey)) { - if (arrayElement is { Kind: TypedConstantKind.Type, Value: ITypeSymbol arrayTypeSymbol }) - { - typeArgs.Add(arrayTypeSymbol); - } + writer.AppendLine($"[{string.Join(" + \",\" + ", combinedTypes.Select(FormatTypeForRuntimeName))}] = "); + GenerateConcreteTestMetadata(writer, testMethod, className, combinedTypes); + writer.AppendLine(","); } } } - - if (typeArgs.Count > 0) + } + } + else if (classTypeArgSets.Count > 0) + { + // Only class is generic + foreach (var classTypeArgs in classTypeArgSets) + { + if (ValidateClassTypeConstraints(testMethod.TypeSymbol, classTypeArgs)) { - var inferredTypes = typeArgs.ToArray(); - var typeKey = BuildTypeKey(inferredTypes); - - // Skip if we've already processed this type combination + var typeKey = BuildTypeKey(classTypeArgs); if (processedTypeCombinations.Add(typeKey)) { - // Validate constraints - if (ValidateTypeConstraints(testMethod.MethodSymbol, inferredTypes)) - { - // Generate a concrete instantiation for this type combination - // Use the same key format as runtime: FullName ?? Name - writer.AppendLine($"[{string.Join(" + \",\" + ", inferredTypes.Select(FormatTypeForRuntimeName))}] = "); - GenerateConcreteTestMetadata(writer, testMethod, className, inferredTypes); - writer.AppendLine(","); - } + writer.AppendLine($"[{string.Join(" + \",\" + ", classTypeArgs.Select(FormatTypeForRuntimeName))}] = "); + GenerateConcreteTestMetadata(writer, testMethod, className, classTypeArgs); + writer.AppendLine(","); + } + } + } + } + else if (methodTypeArgSets.Count > 0) + { + // Only method is generic + foreach (var methodTypeArgs in methodTypeArgSets) + { + if (ValidateTypeConstraints(testMethod.MethodSymbol, methodTypeArgs)) + { + var typeKey = BuildTypeKey(methodTypeArgs); + if (processedTypeCombinations.Add(typeKey)) + { + writer.AppendLine($"[{string.Join(" + \",\" + ", methodTypeArgs.Select(FormatTypeForRuntimeName))}] = "); + GenerateConcreteTestMetadata(writer, testMethod, className, methodTypeArgs); + writer.AppendLine(","); } } } @@ -3723,6 +3764,115 @@ private static void GenerateGenericTestWithConcreteTypes( writer.AppendLine("yield return genericMetadata;"); } + private static void ProcessGenerateGenericTestAttribute( + AttributeData genAttr, + TestMethodMetadata testMethod, + string className, + CodeWriter writer, + HashSet processedTypeCombinations, + bool isClassLevel) + { + // Extract type arguments from the attribute + if (genAttr.ConstructorArguments.Length == 0) + { + return; + } + + var typeArgs = new List(); + foreach (var arg in genAttr.ConstructorArguments) + { + if (arg is { Kind: TypedConstantKind.Type, Value: ITypeSymbol typeSymbol }) + { + typeArgs.Add(typeSymbol); + } + else if (arg.Kind == TypedConstantKind.Array) + { + foreach (var arrayElement in arg.Values) + { + if (arrayElement is { Kind: TypedConstantKind.Type, Value: ITypeSymbol arrayTypeSymbol }) + { + typeArgs.Add(arrayTypeSymbol); + } + } + } + } + + if (typeArgs.Count == 0) + { + return; + } + + var inferredTypes = typeArgs.ToArray(); + var typeKey = BuildTypeKey(inferredTypes); + + // Skip if we've already processed this type combination + if (!processedTypeCombinations.Add(typeKey)) + { + return; + } + + // Validate constraints based on whether this is a class-level or method-level attribute + bool constraintsValid; + if (isClassLevel) + { + // For class-level [GenerateGenericTest], validate against class type constraints + constraintsValid = ValidateClassTypeConstraints(testMethod.TypeSymbol, inferredTypes); + } + else + { + // For method-level [GenerateGenericTest], validate against method type constraints + constraintsValid = ValidateTypeConstraints(testMethod.MethodSymbol, inferredTypes); + } + + if (constraintsValid) + { + // Generate a concrete instantiation for this type combination + // Use the same key format as runtime: FullName ?? Name + writer.AppendLine($"[{string.Join(" + \",\" + ", inferredTypes.Select(FormatTypeForRuntimeName))}] = "); + GenerateConcreteTestMetadata(writer, testMethod, className, inferredTypes); + writer.AppendLine(","); + } + } + + private static List ExtractTypeArgumentSets(List attributes) + { + var result = new List(); + + foreach (var attr in attributes) + { + if (attr.ConstructorArguments.Length == 0) + { + continue; + } + + var typeArgs = new List(); + foreach (var arg in attr.ConstructorArguments) + { + if (arg is { Kind: TypedConstantKind.Type, Value: ITypeSymbol typeSymbol }) + { + typeArgs.Add(typeSymbol); + } + else if (arg.Kind == TypedConstantKind.Array) + { + foreach (var arrayElement in arg.Values) + { + if (arrayElement is { Kind: TypedConstantKind.Type, Value: ITypeSymbol arrayTypeSymbol }) + { + typeArgs.Add(arrayTypeSymbol); + } + } + } + } + + if (typeArgs.Count > 0) + { + result.Add(typeArgs.ToArray()); + } + } + + return result; + } + private static bool ValidateClassTypeConstraints(INamedTypeSymbol classSymbol, ITypeSymbol[] typeArguments) { var typeParams = classSymbol.TypeParameters; @@ -4534,24 +4684,16 @@ private static bool ValidateTypeConstraints(INamedTypeSymbol classType, ITypeSym private static bool ValidateTypeConstraints(IMethodSymbol method, ITypeSymbol[] typeArguments) { - // Get all type parameters (class + method) - var allTypeParams = new List(); + // Only validate method type parameters here - class type parameters are validated separately + // by ValidateClassTypeConstraints in the cartesian product loop + var methodTypeParams = method.TypeParameters; - // Add class type parameters first - if (method.ContainingType.IsGenericType) - { - allTypeParams.AddRange(method.ContainingType.TypeParameters); - } - - // Add method type parameters - allTypeParams.AddRange(method.TypeParameters); - - if (allTypeParams.Count != typeArguments.Length) + if (methodTypeParams.Length != typeArguments.Length) { return false; } - return ValidateTypeParameterConstraints(allTypeParams, typeArguments); + return ValidateTypeParameterConstraints(methodTypeParams, typeArguments); } private static bool ValidateTypeParameterConstraints(IEnumerable typeParams, ITypeSymbol[] typeArguments) @@ -4848,6 +4990,18 @@ private static void GenerateConcreteMetadataWithFilteredDataSources( var methodSymbol = testMethod.MethodSymbol; var typeSymbol = testMethod.TypeSymbol; + // For generic classes, construct the closed generic type for data source generation + // This ensures that static methods are called on the concrete type rather than the open generic + INamedTypeSymbol concreteTypeSymbol = typeSymbol; + if (testMethod.IsGenericType && typeArguments.Length > 0) + { + var classTypeArgCount = typeSymbol.TypeParameters.Length; + if (classTypeArgCount > 0 && typeArguments.Length >= classTypeArgCount) + { + var classTypeArgs = typeArguments.Take(classTypeArgCount).ToArray(); + concreteTypeSymbol = typeSymbol.Construct(classTypeArgs); + } + } GenerateDependencies(writer, compilation, methodSymbol); @@ -4941,7 +5095,7 @@ private static void GenerateConcreteMetadataWithFilteredDataSources( foreach (var attr in methodDataSources) { - GenerateDataSourceAttribute(writer, compilation, attr, methodSymbol, typeSymbol); + GenerateDataSourceAttribute(writer, compilation, attr, methodSymbol, concreteTypeSymbol); } writer.Unindent(); @@ -4961,7 +5115,7 @@ private static void GenerateConcreteMetadataWithFilteredDataSources( foreach (var attr in classDataSources) { - GenerateDataSourceAttribute(writer, compilation, attr, methodSymbol, typeSymbol); + GenerateDataSourceAttribute(writer, compilation, attr, methodSymbol, concreteTypeSymbol); } writer.Unindent(); @@ -4971,7 +5125,7 @@ private static void GenerateConcreteMetadataWithFilteredDataSources( // Empty property data sources for concrete instantiations writer.AppendLine("PropertyDataSources = global::System.Array.Empty(),"); - GeneratePropertyInjections(writer, typeSymbol, typeSymbol.GloballyQualified()); + GeneratePropertyInjections(writer, concreteTypeSymbol, concreteTypeSymbol.GloballyQualified()); // Other metadata writer.AppendLine($"FilePath = @\"{(testMethod.FilePath ?? "").Replace("\\", "\\\\")}\","); diff --git a/TUnit.Engine/Discovery/ReflectionTestDataCollector.cs b/TUnit.Engine/Discovery/ReflectionTestDataCollector.cs index 740f653d48..868f9924f9 100644 --- a/TUnit.Engine/Discovery/ReflectionTestDataCollector.cs +++ b/TUnit.Engine/Discovery/ReflectionTestDataCollector.cs @@ -566,17 +566,7 @@ private static async Task> DiscoverGenericTests(Type genericT { var discoveredTests = new List(100); - // Extract class-level data sources that will determine the generic type arguments - var classDataSources = ReflectionAttributeExtractor.ExtractDataSources(genericTypeDefinition); - - if (classDataSources.Length == 0) - { - // This is expected for generic test classes in reflection mode - // They need data sources to determine concrete types - return discoveredTests; - } - - // Get test methods from the generic type definition + // Get test methods from the generic type definition first (needed for both data sources and GenerateGenericTest) // Optimize: Manual filtering instead of LINQ Where().ToArray() var declaredMethods = genericTypeDefinition.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly); var testMethodsList = new List(declaredMethods.Length); @@ -594,6 +584,55 @@ private static async Task> DiscoverGenericTests(Type genericT return discoveredTests; } + // Check for GenerateGenericTest attributes that explicitly specify type arguments + var generateGenericTestAttributes = genericTypeDefinition.GetCustomAttributes(inherit: false).ToArray(); + foreach (var genAttr in generateGenericTestAttributes) + { + var typeArguments = genAttr.TypeArguments; + if (typeArguments.Length == 0) + { + continue; + } + + try + { + // Create concrete type with validation + var concreteType = ReflectionGenericTypeResolver.CreateConcreteType(genericTypeDefinition, typeArguments); + + // Build tests for each method in the concrete type + foreach (var genericMethod in testMethods) + { + var concreteMethod = concreteType.GetMethod(genericMethod.Name, + BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly); + + if (concreteMethod != null) + { + // Build test metadata for the concrete type + // No class data for GenerateGenericTest - it just provides type arguments + var testMetadata = await BuildTestMetadata(concreteType, concreteMethod, null).ConfigureAwait(false); + discoveredTests.Add(testMetadata); + } + } + } + catch (Exception ex) + { + throw new InvalidOperationException( + $"Failed to create concrete type for {genericTypeDefinition.FullName ?? genericTypeDefinition.Name} from [GenerateGenericTest]. " + + $"Error: {ex.Message}. " + + $"Generic parameter count: {genericTypeDefinition.GetGenericArguments().Length}, " + + $"Type arguments provided: {typeArguments.Length}", ex); + } + } + + // Extract class-level data sources that will determine the generic type arguments + var classDataSources = ReflectionAttributeExtractor.ExtractDataSources(genericTypeDefinition); + + if (classDataSources.Length == 0) + { + // Return any tests discovered from GenerateGenericTest attributes + return discoveredTests; + } + // For each data source combination, create a concrete generic type foreach (var dataSource in classDataSources) { @@ -655,17 +694,7 @@ private static async IAsyncEnumerable DiscoverGenericTestsStreamin Type genericTypeDefinition, [EnumeratorCancellation] CancellationToken cancellationToken = default) { - // Extract class-level data sources that will determine the generic type arguments - var classDataSources = ReflectionAttributeExtractor.ExtractDataSources(genericTypeDefinition); - - if (classDataSources.Length == 0) - { - // This is expected for generic test classes in reflection mode - // They need data sources to determine concrete types - yield break; - } - - // Get test methods from the generic type definition + // Get test methods from the generic type definition first (needed for both data sources and GenerateGenericTest) // Optimize: Manual filtering instead of LINQ Where().ToArray() var declaredMethods = genericTypeDefinition.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly); var testMethodsList = new List(declaredMethods.Length); @@ -683,6 +712,91 @@ private static async IAsyncEnumerable DiscoverGenericTestsStreamin yield break; } + // Check for GenerateGenericTest attributes that explicitly specify type arguments + var generateGenericTestAttributes = genericTypeDefinition.GetCustomAttributes(inherit: false).ToArray(); + foreach (var genAttr in generateGenericTestAttributes) + { + cancellationToken.ThrowIfCancellationRequested(); + + var typeArguments = genAttr.TypeArguments; + if (typeArguments.Length == 0) + { + continue; + } + + TestMetadata? failedMetadata = null; + List? successfulTests = null; + + try + { + // Create concrete type with validation + var concreteType = ReflectionGenericTypeResolver.CreateConcreteType(genericTypeDefinition, typeArguments); + + // Build tests for each method in the concrete type + foreach (var genericMethod in testMethods) + { + var concreteMethod = concreteType.GetMethod(genericMethod.Name, + BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly); + + if (concreteMethod != null) + { + // Build test metadata for the concrete type + // No class data for GenerateGenericTest - it just provides type arguments + var testMetadata = await BuildTestMetadata(concreteType, concreteMethod, null).ConfigureAwait(false); + + if (successfulTests == null) + { + successfulTests = []; + } + successfulTests.Add(testMetadata); + } + } + } + catch (Exception ex) + { + failedMetadata = new FailedTestMetadata( + new InvalidOperationException( + $"Failed to create concrete type for {genericTypeDefinition.FullName ?? genericTypeDefinition.Name} from [GenerateGenericTest]. " + + $"Error: {ex.Message}. " + + $"Generic parameter count: {genericTypeDefinition.GetGenericArguments().Length}, " + + $"Type arguments: {string.Join(", ", typeArguments.Select(static t => t.Name))}", ex), + $"[GENERIC TYPE CREATION FAILED] {genericTypeDefinition.Name}") + { + TestName = $"[GENERIC TYPE CREATION FAILED] {genericTypeDefinition.Name}", + TestClassType = genericTypeDefinition, + TestMethodName = "GenericTypeCreationFailed", + FilePath = "Unknown", + LineNumber = 0, + MethodMetadata = CreateDummyMethodMetadata(genericTypeDefinition, "GenericTypeCreationFailed"), + AttributeFactory = () => [], + DataSources = [], + ClassDataSources = [], + PropertyDataSources = [] + }; + } + + if (failedMetadata != null) + { + yield return failedMetadata; + } + else if (successfulTests != null) + { + foreach (var test in successfulTests) + { + yield return test; + } + } + } + + // Extract class-level data sources that will determine the generic type arguments + var classDataSources = ReflectionAttributeExtractor.ExtractDataSources(genericTypeDefinition); + + if (classDataSources.Length == 0) + { + // GenerateGenericTest tests have already been yielded above + yield break; + } + // For each data source combination, create a concrete generic type foreach (var dataSource in classDataSources) { diff --git a/TUnit.TestProject/Bugs/4431/ComprehensiveGenericTests.cs b/TUnit.TestProject/Bugs/4431/ComprehensiveGenericTests.cs new file mode 100644 index 0000000000..b79fdff0e7 --- /dev/null +++ b/TUnit.TestProject/Bugs/4431/ComprehensiveGenericTests.cs @@ -0,0 +1,249 @@ +using TUnit.TestProject.Attributes; + +namespace TUnit.TestProject.Bugs._4431; + +/// +/// Comprehensive tests for generic test classes and methods with [GenerateGenericTest]. +/// Covers all combinations of generic class/method with and without data sources. +/// + +#region Test Data Types + +public class TypeA +{ + public string Value => "TypeA"; +} + +public class TypeB : TypeA +{ + public new string Value => "TypeB"; +} + +public class TypeC +{ + public int Number => 42; +} + +#endregion + +#region 1. Generic Class (no data source) + +[GenerateGenericTest(typeof(TypeA))] +[GenerateGenericTest(typeof(TypeB))] +public class GenericClassNoDataSource where T : TypeA, new() +{ + [Test] + [EngineTest(ExpectedResult.Pass)] + public async Task Should_Create_Instance() + { + var instance = new T(); + await Assert.That(instance).IsNotNull(); + } +} + +#endregion + +#region 2. Generic Class with MethodDataSource + +[GenerateGenericTest(typeof(TypeA))] +[GenerateGenericTest(typeof(TypeB))] +public class GenericClassWithMethodDataSource where T : TypeA, new() +{ + public static IEnumerable GetNumbers() + { + yield return 1; + yield return 2; + yield return 3; + } + + [Test] + [EngineTest(ExpectedResult.Pass)] + [MethodDataSource(nameof(GetNumbers))] + public async Task Should_Have_Number(int number) + { + await Assert.That(number).IsGreaterThan(0); + } +} + +#endregion + +#region 3. Non-Generic Class with Generic Method (no data source) + +public class NonGenericClassWithGenericMethod +{ + [Test] + [EngineTest(ExpectedResult.Pass)] + [GenerateGenericTest(typeof(int))] + [GenerateGenericTest(typeof(string))] + [GenerateGenericTest(typeof(TypeA))] + public async Task GenericMethod_Should_Work() + { + await Assert.That(typeof(T)).IsNotNull(); + } +} + +#endregion + +#region 4. Non-Generic Class with Generic Method + MethodDataSource + +public class NonGenericClassWithGenericMethodAndDataSource +{ + public static IEnumerable GetStrings() + { + yield return "hello"; + yield return "world"; + } + + [Test] + [EngineTest(ExpectedResult.Pass)] + [GenerateGenericTest(typeof(int))] + [GenerateGenericTest(typeof(double))] + [MethodDataSource(nameof(GetStrings))] + public async Task GenericMethod_With_DataSource(string input) + { + await Assert.That(input).IsNotNull(); + await Assert.That(typeof(T).IsValueType).IsTrue(); + } +} + +#endregion + +#region 5. Generic Class with Generic Method (both generic, no data source) + +[GenerateGenericTest(typeof(TypeA))] +[GenerateGenericTest(typeof(TypeB))] +public class GenericClassWithGenericMethod where TClass : TypeA, new() +{ + [Test] + [EngineTest(ExpectedResult.Pass)] + [GenerateGenericTest(typeof(int))] + [GenerateGenericTest(typeof(string))] + public async Task BothGeneric_Should_Work() + { + var classInstance = new TClass(); + await Assert.That(classInstance).IsNotNull(); + await Assert.That(typeof(TMethod)).IsNotNull(); + } +} + +#endregion + +#region 6. Generic Class with Constructor Parameters + +[GenerateGenericTest(typeof(TypeA))] +[GenerateGenericTest(typeof(TypeB))] +public class GenericClassWithConstructor where T : TypeA, new() +{ + private readonly string _label; + + public GenericClassWithConstructor() + { + _label = "default"; + } + + [Test] + [EngineTest(ExpectedResult.Pass)] + public async Task Should_Have_Label() + { + await Assert.That(_label).IsEqualTo("default"); + } +} + +#endregion + +#region 7. Multiple Type Parameters + +[GenerateGenericTest(typeof(TypeA), typeof(TypeC))] +[GenerateGenericTest(typeof(TypeB), typeof(TypeC))] +public class MultipleTypeParameters where T1 : TypeA, new() where T2 : class, new() +{ + [Test] + [EngineTest(ExpectedResult.Pass)] + public async Task Should_Handle_Multiple_Type_Parameters() + { + var instance1 = new T1(); + var instance2 = new T2(); + await Assert.That(instance1).IsNotNull(); + await Assert.That(instance2).IsNotNull(); + } +} + +#endregion + +#region 8. Generic Class with Inheritance + +public abstract class GenericBaseClass where T : new() +{ + protected T CreateInstance() => new T(); +} + +[GenerateGenericTest(typeof(TypeA))] +[GenerateGenericTest(typeof(TypeB))] +public class DerivedGenericClass : GenericBaseClass where T : TypeA, new() +{ + [Test] + [EngineTest(ExpectedResult.Pass)] + public async Task Should_Create_From_Base() + { + var instance = CreateInstance(); + await Assert.That(instance).IsNotNull(); + await Assert.That(instance.Value).IsNotNull(); + } +} + +#endregion + +#region 9. Generic Class with ClassDataSource (init-only property) + +public class TestDataSource +{ + public string Data => "SharedData"; +} + +[GenerateGenericTest(typeof(TypeA))] +[GenerateGenericTest(typeof(TypeB))] +public class GenericClassWithClassDataSource where T : TypeA, new() +{ + [ClassDataSource(Shared = SharedType.PerTestSession)] + public TestDataSource DataSource { get; init; } = null!; + + [Test] + [EngineTest(ExpectedResult.Pass)] + public async Task Should_Have_DataSource() + { + await Assert.That(DataSource).IsNotNull(); + await Assert.That(DataSource.Data).IsEqualTo("SharedData"); + } +} + +#endregion + +#region 10. Generic Class with Generic Method + ClassDataSource + +[GenerateGenericTest(typeof(TypeA))] +[GenerateGenericTest(typeof(TypeB))] +public class GenericClassGenericMethodWithDataSources where TClass : TypeA, new() +{ + [ClassDataSource(Shared = SharedType.PerTestSession)] + public TestDataSource DataSource { get; init; } = null!; + + public static IEnumerable GetBooleans() + { + yield return true; + yield return false; + } + + [Test] + [EngineTest(ExpectedResult.Pass)] + [GenerateGenericTest(typeof(int))] + [GenerateGenericTest(typeof(double))] + [MethodDataSource(nameof(GetBooleans))] + public async Task FullyGeneric_With_DataSources(bool flag) where TMethod : struct + { + await Assert.That(DataSource).IsNotNull(); + await Assert.That(typeof(TClass).IsClass).IsTrue(); + await Assert.That(typeof(TMethod).IsValueType).IsTrue(); + } +} + +#endregion diff --git a/TUnit.TestProject/Bugs/4431/OpenGenericTestClassTests.cs b/TUnit.TestProject/Bugs/4431/OpenGenericTestClassTests.cs new file mode 100644 index 0000000000..988f09a075 --- /dev/null +++ b/TUnit.TestProject/Bugs/4431/OpenGenericTestClassTests.cs @@ -0,0 +1,67 @@ +using TUnit.Core.Interfaces; +using TUnit.TestProject.Attributes; + +namespace TUnit.TestProject.Bugs._4431; + +/// +/// Reproduces issue #4431: Open generic test classes with ClassDataSource cause runtime errors. +/// +/// The issue: When a test class is an open generic type (e.g., ChildTest<T>), +/// TUnit in reflection mode tries to discover tests from it and fails with: +/// "Could not resolve type for generic parameter(s) of type 'ChildTest`1' from constructor arguments." +/// +/// Expected: Generic test classes should work when [GenerateGenericTest] attribute specifies type arguments. +/// + +// Simple data source that mimics the user's InMemoryPostgres pattern +public class SimpleDataSource4431 : IAsyncInitializer +{ + public string ConnectionString { get; private set; } = null!; + + public Task InitializeAsync() + { + ConnectionString = "Server=localhost;Database=test"; + return Task.CompletedTask; + } +} + +// Matches user's ParentTest +public class ParentTest4431 +{ + [ClassDataSource(Shared = SharedType.PerTestSession)] + public SimpleDataSource4431 DataSource { get; init; } = null!; + + [Test] + [EngineTest(ExpectedResult.Pass)] + public virtual async Task Should_Succeed() + { + await Assert.That(DataSource.ConnectionString).IsNotNull(); + } +} + +// Matches user's ChildTest - WITH [GenerateGenericTest] to specify type argument +// This should work - TUnit should create a concrete instantiation with T = ParentTest4431 +[GenerateGenericTest(typeof(ParentTest4431))] +public class ChildTest4431 where T : ParentTest4431, new() +{ + [Test] + [EngineTest(ExpectedResult.Pass)] + public async Task Should_Succeed() + { + T testInstance = new T(); + // Note: This test demonstrates the issue - the manually created instance + // won't have its DataSource property initialized by TUnit's DI + await Assert.That(testInstance).IsNotNull(); + } +} + +// Matches user's SecondChildTest +public class SecondChildTest4431 : ParentTest4431 +{ + [Test] + [EngineTest(ExpectedResult.Pass)] + public override async Task Should_Succeed() + { + await Assert.That(DataSource.ConnectionString).IsNotNull(); + } +} From d30b2d6218916eb74553fc015f1d4f5bbcd8cf3f Mon Sep 17 00:00:00 2001 From: Tom Longhurst <30480171+thomhurst@users.noreply.github.com> Date: Fri, 16 Jan 2026 01:03:22 +0000 Subject: [PATCH 2/2] fix: address review feedback - AOT compatibility and snapshot tests - Replace reflection-based setter for init-only properties on generic types with NotSupportedException (AOT-compatible) - Add missing verified files for GenericPropertyInjection tests - Add source generator test for generic method with data source Co-Authored-By: Claude Opus 4.5 --- ...aSource_Should_Generate_Tests.verified.txt | 3257 +++++++++++++++++ .../GenericMethodWithDataSourceTests.cs | 81 + ...GeneratesMetadataForAllLevels.verified.txt | 321 ++ ...Diagnostic_ShowGeneratedFiles.verified.txt | 321 ++ ...rceProperty_GeneratesMetadata.verified.txt | 1149 ++++++ ...rProperties_GeneratesMetadata.verified.txt | 321 ++ ...tiations_EachGenerateMetadata.verified.txt | 321 ++ .../Generators/TestMetadataGenerator.cs | 14 +- 8 files changed, 5776 insertions(+), 9 deletions(-) create mode 100644 TUnit.Core.SourceGenerator.Tests/GenericMethodWithDataSourceTests.Generic_Method_With_MethodDataSource_Should_Generate_Tests.verified.txt create mode 100644 TUnit.Core.SourceGenerator.Tests/GenericMethodWithDataSourceTests.cs create mode 100644 TUnit.Core.SourceGenerator.Tests/GenericPropertyInjectionTests.DeepInheritance_GeneratesMetadataForAllLevels.verified.txt create mode 100644 TUnit.Core.SourceGenerator.Tests/GenericPropertyInjectionTests.Diagnostic_ShowGeneratedFiles.verified.txt create mode 100644 TUnit.Core.SourceGenerator.Tests/GenericPropertyInjectionTests.GenericBaseClass_WithDataSourceProperty_GeneratesMetadata.verified.txt create mode 100644 TUnit.Core.SourceGenerator.Tests/GenericPropertyInjectionTests.GenericClassDataSource_WithInitializerProperties_GeneratesMetadata.verified.txt create mode 100644 TUnit.Core.SourceGenerator.Tests/GenericPropertyInjectionTests.MultipleInstantiations_EachGenerateMetadata.verified.txt diff --git a/TUnit.Core.SourceGenerator.Tests/GenericMethodWithDataSourceTests.Generic_Method_With_MethodDataSource_Should_Generate_Tests.verified.txt b/TUnit.Core.SourceGenerator.Tests/GenericMethodWithDataSourceTests.Generic_Method_With_MethodDataSource_Should_Generate_Tests.verified.txt new file mode 100644 index 0000000000..d41e5d35c6 --- /dev/null +++ b/TUnit.Core.SourceGenerator.Tests/GenericMethodWithDataSourceTests.Generic_Method_With_MethodDataSource_Should_Generate_Tests.verified.txt @@ -0,0 +1,3257 @@ +// +#pragma warning disable + +#nullable enable +namespace TUnit.Generated; +internal sealed class TUnit_TestProject_Bugs__4431_GenericClassNoDataSource_T_Should_Create_Instance_TestSource : global::TUnit.Core.Interfaces.SourceGenerator.ITestSource, global::TUnit.Core.Interfaces.SourceGenerator.ITestDescriptorSource +{ + public async global::System.Collections.Generic.IAsyncEnumerable GetTestsAsync(string testSessionId, [global::System.Runtime.CompilerServices.EnumeratorCancellation] global::System.Threading.CancellationToken cancellationToken = default) + { + // Create generic metadata with concrete type registrations + var genericMetadata = new global::TUnit.Core.GenericTestMetadata + { + TestName = "Should_Create_Instance", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassNoDataSource<>), + TestMethodName = "Should_Create_Instance", + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeB)) + ], + DataSources = global::System.Array.Empty(), + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = global::System.Array.Empty(), + InheritanceDepth = 0, + FilePath = @"", + LineNumber = 35, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassNoDataSource<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassNoDataSource<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "Should_Create_Instance", + GenericTypeCount = 0, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = global::System.Array.Empty(), + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.GenericClassNoDataSource<>", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassNoDataSource<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassNoDataSource<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "GenericClassNoDataSource", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + Parent = null + }; + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + var genericType = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassNoDataSource<>); + if (typeArgs.Length > 0) + { + var closedType = genericType.MakeGenericType(typeArgs); + return global::System.Activator.CreateInstance(closedType, args)!; + } + throw new global::System.InvalidOperationException("No type arguments provided for generic class"); + }, + ConcreteInstantiations = new global::System.Collections.Generic.Dictionary + { + [(typeof(global::TUnit.TestProject.Bugs._4431.TypeA).FullName ?? typeof(global::TUnit.TestProject.Bugs._4431.TypeA).Name)] = + new global::TUnit.Core.TestMetadata> + { + TestName = "Should_Create_Instance", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassNoDataSource), + TestMethodName = "Should_Create_Instance", + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeB)) + ], + DataSources = global::System.Array.Empty(), + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = global::System.Array.Empty(), + FilePath = @"", + LineNumber = 35, + InheritanceDepth = 0, + TestSessionId = testSessionId, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassNoDataSource<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassNoDataSource<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "Should_Create_Instance", + GenericTypeCount = 0, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = global::System.Array.Empty(), + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.GenericClassNoDataSource<>", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassNoDataSource<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassNoDataSource<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "GenericClassNoDataSource", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + Parent = null + }; + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + return new global::TUnit.TestProject.Bugs._4431.GenericClassNoDataSource(); + }, + InvokeTypedTest = static (instance, args, cancellationToken) => + { + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._4431.GenericClassNoDataSource)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.Should_Create_Instance()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } + } + } + , + [(typeof(global::TUnit.TestProject.Bugs._4431.TypeB).FullName ?? typeof(global::TUnit.TestProject.Bugs._4431.TypeB).Name)] = + new global::TUnit.Core.TestMetadata> + { + TestName = "Should_Create_Instance", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassNoDataSource), + TestMethodName = "Should_Create_Instance", + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeB)) + ], + DataSources = global::System.Array.Empty(), + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = global::System.Array.Empty(), + FilePath = @"", + LineNumber = 35, + InheritanceDepth = 0, + TestSessionId = testSessionId, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassNoDataSource<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassNoDataSource<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "Should_Create_Instance", + GenericTypeCount = 0, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = global::System.Array.Empty(), + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.GenericClassNoDataSource<>", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassNoDataSource<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassNoDataSource<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "GenericClassNoDataSource", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + Parent = null + }; + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + return new global::TUnit.TestProject.Bugs._4431.GenericClassNoDataSource(); + }, + InvokeTypedTest = static (instance, args, cancellationToken) => + { + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._4431.GenericClassNoDataSource)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.Should_Create_Instance()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } + } + } + , + } + }; + genericMetadata.TestSessionId = testSessionId; + yield return genericMetadata; + yield break; + } + public global::System.Collections.Generic.IEnumerable EnumerateTestDescriptors() + { + yield return new global::TUnit.Core.TestDescriptor + { + TestId = "TUnit.TestProject.Bugs._4431.GenericClassNoDataSource.Should_Create_Instance", + ClassName = "GenericClassNoDataSource", + MethodName = "Should_Create_Instance", + FullyQualifiedName = "TUnit.TestProject.Bugs._4431.GenericClassNoDataSource.Should_Create_Instance", + FilePath = @"", + LineNumber = 35, + Categories = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + HasDataSource = false, + RepeatCount = 0, + DependsOn = global::System.Array.Empty(), + Materializer = GetTestsAsync + }; + } +} +internal static class TUnit_TestProject_Bugs__4431_GenericClassNoDataSource_T_Should_Create_Instance_ModuleInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.SourceRegistrar.Register(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassNoDataSource<>), new TUnit_TestProject_Bugs__4431_GenericClassNoDataSource_T_Should_Create_Instance_TestSource()); + } +} + + +// ===== FILE SEPARATOR ===== + +// +#pragma warning disable + +#nullable enable +namespace TUnit.Generated; +internal sealed class TUnit_TestProject_Bugs__4431_GenericClassWithMethodDataSource_T_Should_Have_Number__int_TestSource : global::TUnit.Core.Interfaces.SourceGenerator.ITestSource, global::TUnit.Core.Interfaces.SourceGenerator.ITestDescriptorSource +{ + public async global::System.Collections.Generic.IAsyncEnumerable GetTestsAsync(string testSessionId, [global::System.Runtime.CompilerServices.EnumeratorCancellation] global::System.Threading.CancellationToken cancellationToken = default) + { + // Create generic metadata with concrete type registrations + var genericMetadata = new global::TUnit.Core.GenericTestMetadata + { + TestName = "Should_Have_Number", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource<>), + TestMethodName = "Should_Have_Number", + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeB)) + ], + DataSources = global::System.Array.Empty(), + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = global::System.Array.Empty(), + InheritanceDepth = 0, + FilePath = @"", + LineNumber = 59, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "Should_Have_Number", + GenericTypeCount = 0, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = new global::TUnit.Core.ParameterMetadata[] + { + new global::TUnit.Core.ParameterMetadata(typeof(int)) + { + Name = "number", + TypeInfo = new global::TUnit.Core.ConcreteType(typeof(int)), + IsNullable = false, + ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource<>).GetMethod("Should_Have_Number", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] + } + }, + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource<>", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "GenericClassWithMethodDataSource", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + Parent = null + }; + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + var genericType = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource<>); + if (typeArgs.Length > 0) + { + var closedType = genericType.MakeGenericType(typeArgs); + return global::System.Activator.CreateInstance(closedType, args)!; + } + throw new global::System.InvalidOperationException("No type arguments provided for generic class"); + }, + ConcreteInstantiations = new global::System.Collections.Generic.Dictionary + { + [(typeof(global::TUnit.TestProject.Bugs._4431.TypeA).FullName ?? typeof(global::TUnit.TestProject.Bugs._4431.TypeA).Name)] = + new global::TUnit.Core.TestMetadata> + { + TestName = "Should_Have_Number", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource), + TestMethodName = "Should_Have_Number", + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.MethodDataSourceAttribute("GetNumbers"), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeB)) + ], + DataSources = new global::TUnit.Core.IDataSourceAttribute[] + { + new global::TUnit.Core.MethodDataSourceAttribute("GetNumbers") + { + Factory = (dataGeneratorMetadata) => + { + async global::System.Collections.Generic.IAsyncEnumerable>> Factory() + { + var result = global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource.GetNumbers(); + if (result is global::System.Collections.IEnumerable enumerable && !(result is string)) + { + foreach (var item in enumerable) + { + yield return () => global::System.Threading.Tasks.Task.FromResult(global::TUnit.Core.Helpers.DataSourceHelpers.ToObjectArray(item)); + } + } + else + { + yield return () => global::System.Threading.Tasks.Task.FromResult(global::TUnit.Core.Helpers.DataSourceHelpers.ToObjectArray(result)); + } + } + return Factory(); + } + }, + }, + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = global::System.Array.Empty(), + FilePath = @"", + LineNumber = 59, + InheritanceDepth = 0, + TestSessionId = testSessionId, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "Should_Have_Number", + GenericTypeCount = 0, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = new global::TUnit.Core.ParameterMetadata[] + { + new global::TUnit.Core.ParameterMetadata(typeof(int)) + { + Name = "number", + TypeInfo = new global::TUnit.Core.ConcreteType(typeof(int)), + IsNullable = false, + ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource<>).GetMethod("Should_Have_Number", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] + } + }, + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource<>", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "GenericClassWithMethodDataSource", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + Parent = null + }; + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + return new global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource(); + }, + InvokeTypedTest = static (instance, args, cancellationToken) => + { + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.Should_Have_Number((int)args[0]!)); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } + } + } + , + [(typeof(global::TUnit.TestProject.Bugs._4431.TypeB).FullName ?? typeof(global::TUnit.TestProject.Bugs._4431.TypeB).Name)] = + new global::TUnit.Core.TestMetadata> + { + TestName = "Should_Have_Number", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource), + TestMethodName = "Should_Have_Number", + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.MethodDataSourceAttribute("GetNumbers"), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeB)) + ], + DataSources = new global::TUnit.Core.IDataSourceAttribute[] + { + new global::TUnit.Core.MethodDataSourceAttribute("GetNumbers") + { + Factory = (dataGeneratorMetadata) => + { + async global::System.Collections.Generic.IAsyncEnumerable>> Factory() + { + var result = global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource.GetNumbers(); + if (result is global::System.Collections.IEnumerable enumerable && !(result is string)) + { + foreach (var item in enumerable) + { + yield return () => global::System.Threading.Tasks.Task.FromResult(global::TUnit.Core.Helpers.DataSourceHelpers.ToObjectArray(item)); + } + } + else + { + yield return () => global::System.Threading.Tasks.Task.FromResult(global::TUnit.Core.Helpers.DataSourceHelpers.ToObjectArray(result)); + } + } + return Factory(); + } + }, + }, + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = global::System.Array.Empty(), + FilePath = @"", + LineNumber = 59, + InheritanceDepth = 0, + TestSessionId = testSessionId, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "Should_Have_Number", + GenericTypeCount = 0, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = new global::TUnit.Core.ParameterMetadata[] + { + new global::TUnit.Core.ParameterMetadata(typeof(int)) + { + Name = "number", + TypeInfo = new global::TUnit.Core.ConcreteType(typeof(int)), + IsNullable = false, + ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource<>).GetMethod("Should_Have_Number", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] + } + }, + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource<>", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "GenericClassWithMethodDataSource", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + Parent = null + }; + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + return new global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource(); + }, + InvokeTypedTest = static (instance, args, cancellationToken) => + { + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.Should_Have_Number((int)args[0]!)); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } + } + } + , + } + }; + genericMetadata.TestSessionId = testSessionId; + yield return genericMetadata; + yield break; + } + public global::System.Collections.Generic.IEnumerable EnumerateTestDescriptors() + { + yield return new global::TUnit.Core.TestDescriptor + { + TestId = "TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource.Should_Have_Number", + ClassName = "GenericClassWithMethodDataSource", + MethodName = "Should_Have_Number", + FullyQualifiedName = "TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource.Should_Have_Number", + FilePath = @"", + LineNumber = 59, + Categories = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + HasDataSource = true, + RepeatCount = 0, + DependsOn = global::System.Array.Empty(), + Materializer = GetTestsAsync + }; + } +} +internal static class TUnit_TestProject_Bugs__4431_GenericClassWithMethodDataSource_T_Should_Have_Number__int_ModuleInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.SourceRegistrar.Register(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithMethodDataSource<>), new TUnit_TestProject_Bugs__4431_GenericClassWithMethodDataSource_T_Should_Have_Number__int_TestSource()); + } +} + + +// ===== FILE SEPARATOR ===== + +// +#pragma warning disable + +#nullable enable +namespace TUnit.Generated; +internal sealed class TUnit_TestProject_Bugs__4431_NonGenericClassWithGenericMethod_GenericMethod_Should_Work_TestSource : global::TUnit.Core.Interfaces.SourceGenerator.ITestSource, global::TUnit.Core.Interfaces.SourceGenerator.ITestDescriptorSource +{ + public async global::System.Collections.Generic.IAsyncEnumerable GetTestsAsync(string testSessionId, [global::System.Runtime.CompilerServices.EnumeratorCancellation] global::System.Threading.CancellationToken cancellationToken = default) + { + // Create generic metadata with concrete type registrations + var genericMetadata = new global::TUnit.Core.GenericTestMetadata + { + TestName = "GenericMethod_Should_Work", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod), + TestMethodName = "GenericMethod_Should_Work", + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(int)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(string)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)) + ], + DataSources = global::System.Array.Empty(), + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = global::System.Array.Empty(), + InheritanceDepth = 0, + FilePath = @"", + LineNumber = 74, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod), + TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod)), + Name = "GenericMethod_Should_Work", + GenericTypeCount = 1, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = global::System.Array.Empty(), + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod), + TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod)), + Name = "NonGenericClassWithGenericMethod", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + Parent = null + }; + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + return new global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod(); + }, + ConcreteInstantiations = new global::System.Collections.Generic.Dictionary + { + [(typeof(int).FullName ?? typeof(int).Name)] = + new global::TUnit.Core.TestMetadata + { + TestName = "GenericMethod_Should_Work", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod), + TestMethodName = "GenericMethod_Should_Work", + GenericMethodTypeArguments = new global::System.Type[] { typeof(int)}, + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(int)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(string)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)) + ], + DataSources = global::System.Array.Empty(), + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = global::System.Array.Empty(), + FilePath = @"", + LineNumber = 74, + InheritanceDepth = 0, + TestSessionId = testSessionId, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod), + TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod)), + Name = "GenericMethod_Should_Work", + GenericTypeCount = 1, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = global::System.Array.Empty(), + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod), + TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod)), + Name = "NonGenericClassWithGenericMethod", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + Parent = null + }; + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + return new global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod(); + }, + InvokeTypedTest = static (instance, args, cancellationToken) => + { + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.GenericMethod_Should_Work()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } + } + } + , + [(typeof(string).FullName ?? typeof(string).Name)] = + new global::TUnit.Core.TestMetadata + { + TestName = "GenericMethod_Should_Work", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod), + TestMethodName = "GenericMethod_Should_Work", + GenericMethodTypeArguments = new global::System.Type[] { typeof(string)}, + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(int)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(string)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)) + ], + DataSources = global::System.Array.Empty(), + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = global::System.Array.Empty(), + FilePath = @"", + LineNumber = 74, + InheritanceDepth = 0, + TestSessionId = testSessionId, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod), + TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod)), + Name = "GenericMethod_Should_Work", + GenericTypeCount = 1, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = global::System.Array.Empty(), + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod), + TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod)), + Name = "NonGenericClassWithGenericMethod", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + Parent = null + }; + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + return new global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod(); + }, + InvokeTypedTest = static (instance, args, cancellationToken) => + { + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.GenericMethod_Should_Work()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } + } + } + , + [(typeof(global::TUnit.TestProject.Bugs._4431.TypeA).FullName ?? typeof(global::TUnit.TestProject.Bugs._4431.TypeA).Name)] = + new global::TUnit.Core.TestMetadata + { + TestName = "GenericMethod_Should_Work", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod), + TestMethodName = "GenericMethod_Should_Work", + GenericMethodTypeArguments = new global::System.Type[] { typeof(global::TUnit.TestProject.Bugs._4431.TypeA)}, + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(int)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(string)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)) + ], + DataSources = global::System.Array.Empty(), + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = global::System.Array.Empty(), + FilePath = @"", + LineNumber = 74, + InheritanceDepth = 0, + TestSessionId = testSessionId, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod), + TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod)), + Name = "GenericMethod_Should_Work", + GenericTypeCount = 1, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = global::System.Array.Empty(), + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod), + TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod)), + Name = "NonGenericClassWithGenericMethod", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + Parent = null + }; + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + return new global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod(); + }, + InvokeTypedTest = static (instance, args, cancellationToken) => + { + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.GenericMethod_Should_Work()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } + } + } + , + } + }; + genericMetadata.TestSessionId = testSessionId; + yield return genericMetadata; + yield break; + } + public global::System.Collections.Generic.IEnumerable EnumerateTestDescriptors() + { + yield return new global::TUnit.Core.TestDescriptor + { + TestId = "TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod.GenericMethod_Should_Work", + ClassName = "NonGenericClassWithGenericMethod", + MethodName = "GenericMethod_Should_Work", + FullyQualifiedName = "TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod.GenericMethod_Should_Work", + FilePath = @"", + LineNumber = 74, + Categories = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + HasDataSource = false, + RepeatCount = 0, + DependsOn = global::System.Array.Empty(), + Materializer = GetTestsAsync + }; + } +} +internal static class TUnit_TestProject_Bugs__4431_NonGenericClassWithGenericMethod_GenericMethod_Should_Work_ModuleInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.SourceRegistrar.Register(typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethod), new TUnit_TestProject_Bugs__4431_NonGenericClassWithGenericMethod_GenericMethod_Should_Work_TestSource()); + } +} + + +// ===== FILE SEPARATOR ===== + +// +#pragma warning disable + +#nullable enable +namespace TUnit.Generated; +internal sealed class TUnit_TestProject_Bugs__4431_NonGenericClassWithGenericMethodAndDataSource_GenericMethod_With_DataSource__string_TestSource : global::TUnit.Core.Interfaces.SourceGenerator.ITestSource, global::TUnit.Core.Interfaces.SourceGenerator.ITestDescriptorSource +{ + public async global::System.Collections.Generic.IAsyncEnumerable GetTestsAsync(string testSessionId, [global::System.Runtime.CompilerServices.EnumeratorCancellation] global::System.Threading.CancellationToken cancellationToken = default) + { + // Create generic metadata with concrete type registrations + var genericMetadata = new global::TUnit.Core.GenericTestMetadata + { + TestName = "GenericMethod_With_DataSource", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource), + TestMethodName = "GenericMethod_With_DataSource", + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(int)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(double)) + ], + DataSources = global::System.Array.Empty(), + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = global::System.Array.Empty(), + InheritanceDepth = 0, + FilePath = @"", + LineNumber = 97, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource), + TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource)), + Name = "GenericMethod_With_DataSource", + GenericTypeCount = 1, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = new global::TUnit.Core.ParameterMetadata[] + { + new global::TUnit.Core.ParameterMetadata(typeof(string)) + { + Name = "input", + TypeInfo = new global::TUnit.Core.ConcreteType(typeof(string)), + IsNullable = false, + ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "GenericMethod_With_DataSource" && m.GetParameters().Length == 1)?.GetParameters()[0]! + } + }, + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource), + TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource)), + Name = "NonGenericClassWithGenericMethodAndDataSource", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + Parent = null + }; + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + return new global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource(); + }, + ConcreteInstantiations = new global::System.Collections.Generic.Dictionary + { + [(typeof(int).FullName ?? typeof(int).Name)] = + new global::TUnit.Core.TestMetadata + { + TestName = "GenericMethod_With_DataSource", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource), + TestMethodName = "GenericMethod_With_DataSource", + GenericMethodTypeArguments = new global::System.Type[] { typeof(int)}, + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(int)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(double)), + new global::TUnit.Core.MethodDataSourceAttribute("GetStrings") + ], + DataSources = new global::TUnit.Core.IDataSourceAttribute[] + { + new global::TUnit.Core.MethodDataSourceAttribute("GetStrings") + { + Factory = (dataGeneratorMetadata) => + { + async global::System.Collections.Generic.IAsyncEnumerable>> Factory() + { + var result = global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource.GetStrings(); + if (result is global::System.Collections.IEnumerable enumerable && !(result is string)) + { + foreach (var item in enumerable) + { + yield return () => global::System.Threading.Tasks.Task.FromResult(global::TUnit.Core.Helpers.DataSourceHelpers.ToObjectArray(item)); + } + } + else + { + yield return () => global::System.Threading.Tasks.Task.FromResult(global::TUnit.Core.Helpers.DataSourceHelpers.ToObjectArray(result)); + } + } + return Factory(); + } + }, + }, + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = global::System.Array.Empty(), + FilePath = @"", + LineNumber = 97, + InheritanceDepth = 0, + TestSessionId = testSessionId, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource), + TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource)), + Name = "GenericMethod_With_DataSource", + GenericTypeCount = 1, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = new global::TUnit.Core.ParameterMetadata[] + { + new global::TUnit.Core.ParameterMetadata(typeof(string)) + { + Name = "input", + TypeInfo = new global::TUnit.Core.ConcreteType(typeof(string)), + IsNullable = false, + ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "GenericMethod_With_DataSource" && m.GetParameters().Length == 1)?.GetParameters()[0]! + } + }, + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource), + TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource)), + Name = "NonGenericClassWithGenericMethodAndDataSource", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + Parent = null + }; + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + return new global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource(); + }, + InvokeTypedTest = static (instance, args, cancellationToken) => + { + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.GenericMethod_With_DataSource((string)args[0]!)); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } + } + } + , + [(typeof(double).FullName ?? typeof(double).Name)] = + new global::TUnit.Core.TestMetadata + { + TestName = "GenericMethod_With_DataSource", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource), + TestMethodName = "GenericMethod_With_DataSource", + GenericMethodTypeArguments = new global::System.Type[] { typeof(double)}, + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(int)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(double)), + new global::TUnit.Core.MethodDataSourceAttribute("GetStrings") + ], + DataSources = new global::TUnit.Core.IDataSourceAttribute[] + { + new global::TUnit.Core.MethodDataSourceAttribute("GetStrings") + { + Factory = (dataGeneratorMetadata) => + { + async global::System.Collections.Generic.IAsyncEnumerable>> Factory() + { + var result = global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource.GetStrings(); + if (result is global::System.Collections.IEnumerable enumerable && !(result is string)) + { + foreach (var item in enumerable) + { + yield return () => global::System.Threading.Tasks.Task.FromResult(global::TUnit.Core.Helpers.DataSourceHelpers.ToObjectArray(item)); + } + } + else + { + yield return () => global::System.Threading.Tasks.Task.FromResult(global::TUnit.Core.Helpers.DataSourceHelpers.ToObjectArray(result)); + } + } + return Factory(); + } + }, + }, + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = global::System.Array.Empty(), + FilePath = @"", + LineNumber = 97, + InheritanceDepth = 0, + TestSessionId = testSessionId, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource), + TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource)), + Name = "GenericMethod_With_DataSource", + GenericTypeCount = 1, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = new global::TUnit.Core.ParameterMetadata[] + { + new global::TUnit.Core.ParameterMetadata(typeof(string)) + { + Name = "input", + TypeInfo = new global::TUnit.Core.ConcreteType(typeof(string)), + IsNullable = false, + ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "GenericMethod_With_DataSource" && m.GetParameters().Length == 1)?.GetParameters()[0]! + } + }, + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource), + TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource)), + Name = "NonGenericClassWithGenericMethodAndDataSource", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + Parent = null + }; + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + return new global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource(); + }, + InvokeTypedTest = static (instance, args, cancellationToken) => + { + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.GenericMethod_With_DataSource((string)args[0]!)); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } + } + } + , + } + }; + genericMetadata.TestSessionId = testSessionId; + yield return genericMetadata; + yield break; + } + public global::System.Collections.Generic.IEnumerable EnumerateTestDescriptors() + { + yield return new global::TUnit.Core.TestDescriptor + { + TestId = "TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource.GenericMethod_With_DataSource", + ClassName = "NonGenericClassWithGenericMethodAndDataSource", + MethodName = "GenericMethod_With_DataSource", + FullyQualifiedName = "TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource.GenericMethod_With_DataSource", + FilePath = @"", + LineNumber = 97, + Categories = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + HasDataSource = true, + RepeatCount = 0, + DependsOn = global::System.Array.Empty(), + Materializer = GetTestsAsync + }; + } +} +internal static class TUnit_TestProject_Bugs__4431_NonGenericClassWithGenericMethodAndDataSource_GenericMethod_With_DataSource__string_ModuleInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.SourceRegistrar.Register(typeof(global::TUnit.TestProject.Bugs._4431.NonGenericClassWithGenericMethodAndDataSource), new TUnit_TestProject_Bugs__4431_NonGenericClassWithGenericMethodAndDataSource_GenericMethod_With_DataSource__string_TestSource()); + } +} + + +// ===== FILE SEPARATOR ===== + +// +#pragma warning disable + +#nullable enable +namespace TUnit.Generated; +internal sealed class TUnit_TestProject_Bugs__4431_GenericClassWithGenericMethod_TClass_BothGeneric_Should_Work_TestSource : global::TUnit.Core.Interfaces.SourceGenerator.ITestSource, global::TUnit.Core.Interfaces.SourceGenerator.ITestDescriptorSource +{ + public async global::System.Collections.Generic.IAsyncEnumerable GetTestsAsync(string testSessionId, [global::System.Runtime.CompilerServices.EnumeratorCancellation] global::System.Threading.CancellationToken cancellationToken = default) + { + // Create generic metadata with concrete type registrations + var genericMetadata = new global::TUnit.Core.GenericTestMetadata + { + TestName = "BothGeneric_Should_Work", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod<>), + TestMethodName = "BothGeneric_Should_Work", + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(int)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(string)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeB)) + ], + DataSources = global::System.Array.Empty(), + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = global::System.Array.Empty(), + InheritanceDepth = 0, + FilePath = @"", + LineNumber = 117, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod<>), [new global::TUnit.Core.GenericParameter(0, false, "TClass")]), + Name = "BothGeneric_Should_Work", + GenericTypeCount = 1, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = global::System.Array.Empty(), + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod<>", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod<>), [new global::TUnit.Core.GenericParameter(0, false, "TClass")]), + Name = "GenericClassWithGenericMethod", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + Parent = null + }; + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + var genericType = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod<>); + if (typeArgs.Length > 0) + { + var closedType = genericType.MakeGenericType(typeArgs); + return global::System.Activator.CreateInstance(closedType, args)!; + } + throw new global::System.InvalidOperationException("No type arguments provided for generic class"); + }, + ConcreteInstantiations = new global::System.Collections.Generic.Dictionary + { + [(typeof(global::TUnit.TestProject.Bugs._4431.TypeA).FullName ?? typeof(global::TUnit.TestProject.Bugs._4431.TypeA).Name) + "," + (typeof(int).FullName ?? typeof(int).Name)] = + new global::TUnit.Core.TestMetadata> + { + TestName = "BothGeneric_Should_Work", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod), + TestMethodName = "BothGeneric_Should_Work", + GenericMethodTypeArguments = new global::System.Type[] { typeof(int)}, + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(int)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(string)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeB)) + ], + DataSources = global::System.Array.Empty(), + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = global::System.Array.Empty(), + FilePath = @"", + LineNumber = 117, + InheritanceDepth = 0, + TestSessionId = testSessionId, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod<>), [new global::TUnit.Core.GenericParameter(0, false, "TClass")]), + Name = "BothGeneric_Should_Work", + GenericTypeCount = 1, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = global::System.Array.Empty(), + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod<>", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod<>), [new global::TUnit.Core.GenericParameter(0, false, "TClass")]), + Name = "GenericClassWithGenericMethod", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + Parent = null + }; + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + return new global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod(); + }, + InvokeTypedTest = static (instance, args, cancellationToken) => + { + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.BothGeneric_Should_Work()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } + } + } + , + [(typeof(global::TUnit.TestProject.Bugs._4431.TypeA).FullName ?? typeof(global::TUnit.TestProject.Bugs._4431.TypeA).Name) + "," + (typeof(string).FullName ?? typeof(string).Name)] = + new global::TUnit.Core.TestMetadata> + { + TestName = "BothGeneric_Should_Work", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod), + TestMethodName = "BothGeneric_Should_Work", + GenericMethodTypeArguments = new global::System.Type[] { typeof(string)}, + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(int)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(string)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeB)) + ], + DataSources = global::System.Array.Empty(), + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = global::System.Array.Empty(), + FilePath = @"", + LineNumber = 117, + InheritanceDepth = 0, + TestSessionId = testSessionId, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod<>), [new global::TUnit.Core.GenericParameter(0, false, "TClass")]), + Name = "BothGeneric_Should_Work", + GenericTypeCount = 1, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = global::System.Array.Empty(), + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod<>", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod<>), [new global::TUnit.Core.GenericParameter(0, false, "TClass")]), + Name = "GenericClassWithGenericMethod", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + Parent = null + }; + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + return new global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod(); + }, + InvokeTypedTest = static (instance, args, cancellationToken) => + { + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.BothGeneric_Should_Work()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } + } + } + , + [(typeof(global::TUnit.TestProject.Bugs._4431.TypeB).FullName ?? typeof(global::TUnit.TestProject.Bugs._4431.TypeB).Name) + "," + (typeof(int).FullName ?? typeof(int).Name)] = + new global::TUnit.Core.TestMetadata> + { + TestName = "BothGeneric_Should_Work", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod), + TestMethodName = "BothGeneric_Should_Work", + GenericMethodTypeArguments = new global::System.Type[] { typeof(int)}, + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(int)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(string)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeB)) + ], + DataSources = global::System.Array.Empty(), + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = global::System.Array.Empty(), + FilePath = @"", + LineNumber = 117, + InheritanceDepth = 0, + TestSessionId = testSessionId, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod<>), [new global::TUnit.Core.GenericParameter(0, false, "TClass")]), + Name = "BothGeneric_Should_Work", + GenericTypeCount = 1, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = global::System.Array.Empty(), + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod<>", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod<>), [new global::TUnit.Core.GenericParameter(0, false, "TClass")]), + Name = "GenericClassWithGenericMethod", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + Parent = null + }; + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + return new global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod(); + }, + InvokeTypedTest = static (instance, args, cancellationToken) => + { + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.BothGeneric_Should_Work()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } + } + } + , + [(typeof(global::TUnit.TestProject.Bugs._4431.TypeB).FullName ?? typeof(global::TUnit.TestProject.Bugs._4431.TypeB).Name) + "," + (typeof(string).FullName ?? typeof(string).Name)] = + new global::TUnit.Core.TestMetadata> + { + TestName = "BothGeneric_Should_Work", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod), + TestMethodName = "BothGeneric_Should_Work", + GenericMethodTypeArguments = new global::System.Type[] { typeof(string)}, + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(int)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(string)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeB)) + ], + DataSources = global::System.Array.Empty(), + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = global::System.Array.Empty(), + FilePath = @"", + LineNumber = 117, + InheritanceDepth = 0, + TestSessionId = testSessionId, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod<>), [new global::TUnit.Core.GenericParameter(0, false, "TClass")]), + Name = "BothGeneric_Should_Work", + GenericTypeCount = 1, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = global::System.Array.Empty(), + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod<>", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod<>), [new global::TUnit.Core.GenericParameter(0, false, "TClass")]), + Name = "GenericClassWithGenericMethod", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + Parent = null + }; + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + return new global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod(); + }, + InvokeTypedTest = static (instance, args, cancellationToken) => + { + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.BothGeneric_Should_Work()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } + } + } + , + } + }; + genericMetadata.TestSessionId = testSessionId; + yield return genericMetadata; + yield break; + } + public global::System.Collections.Generic.IEnumerable EnumerateTestDescriptors() + { + yield return new global::TUnit.Core.TestDescriptor + { + TestId = "TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod.BothGeneric_Should_Work", + ClassName = "GenericClassWithGenericMethod", + MethodName = "BothGeneric_Should_Work", + FullyQualifiedName = "TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod.BothGeneric_Should_Work", + FilePath = @"", + LineNumber = 117, + Categories = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + HasDataSource = false, + RepeatCount = 0, + DependsOn = global::System.Array.Empty(), + Materializer = GetTestsAsync + }; + } +} +internal static class TUnit_TestProject_Bugs__4431_GenericClassWithGenericMethod_TClass_BothGeneric_Should_Work_ModuleInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.SourceRegistrar.Register(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithGenericMethod<>), new TUnit_TestProject_Bugs__4431_GenericClassWithGenericMethod_TClass_BothGeneric_Should_Work_TestSource()); + } +} + + +// ===== FILE SEPARATOR ===== + +// +#pragma warning disable + +#nullable enable +namespace TUnit.Generated; +internal sealed class TUnit_TestProject_Bugs__4431_GenericClassWithConstructor_T_Should_Have_Label_TestSource : global::TUnit.Core.Interfaces.SourceGenerator.ITestSource, global::TUnit.Core.Interfaces.SourceGenerator.ITestDescriptorSource +{ + public async global::System.Collections.Generic.IAsyncEnumerable GetTestsAsync(string testSessionId, [global::System.Runtime.CompilerServices.EnumeratorCancellation] global::System.Threading.CancellationToken cancellationToken = default) + { + // Create generic metadata with concrete type registrations + var genericMetadata = new global::TUnit.Core.GenericTestMetadata + { + TestName = "Should_Have_Label", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithConstructor<>), + TestMethodName = "Should_Have_Label", + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeB)) + ], + DataSources = global::System.Array.Empty(), + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = global::System.Array.Empty(), + InheritanceDepth = 0, + FilePath = @"", + LineNumber = 144, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithConstructor<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithConstructor<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "Should_Have_Label", + GenericTypeCount = 0, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = global::System.Array.Empty(), + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.GenericClassWithConstructor<>", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithConstructor<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithConstructor<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "GenericClassWithConstructor", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + Parent = null + }; + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + var genericType = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithConstructor<>); + if (typeArgs.Length > 0) + { + var closedType = genericType.MakeGenericType(typeArgs); + return global::System.Activator.CreateInstance(closedType, args)!; + } + throw new global::System.InvalidOperationException("No type arguments provided for generic class"); + }, + ConcreteInstantiations = new global::System.Collections.Generic.Dictionary + { + [(typeof(global::TUnit.TestProject.Bugs._4431.TypeA).FullName ?? typeof(global::TUnit.TestProject.Bugs._4431.TypeA).Name)] = + new global::TUnit.Core.TestMetadata> + { + TestName = "Should_Have_Label", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithConstructor), + TestMethodName = "Should_Have_Label", + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeB)) + ], + DataSources = global::System.Array.Empty(), + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = global::System.Array.Empty(), + FilePath = @"", + LineNumber = 144, + InheritanceDepth = 0, + TestSessionId = testSessionId, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithConstructor<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithConstructor<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "Should_Have_Label", + GenericTypeCount = 0, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = global::System.Array.Empty(), + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.GenericClassWithConstructor<>", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithConstructor<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithConstructor<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "GenericClassWithConstructor", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + Parent = null + }; + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + return new global::TUnit.TestProject.Bugs._4431.GenericClassWithConstructor(); + }, + InvokeTypedTest = static (instance, args, cancellationToken) => + { + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._4431.GenericClassWithConstructor)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.Should_Have_Label()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } + } + } + , + [(typeof(global::TUnit.TestProject.Bugs._4431.TypeB).FullName ?? typeof(global::TUnit.TestProject.Bugs._4431.TypeB).Name)] = + new global::TUnit.Core.TestMetadata> + { + TestName = "Should_Have_Label", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithConstructor), + TestMethodName = "Should_Have_Label", + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeB)) + ], + DataSources = global::System.Array.Empty(), + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = global::System.Array.Empty(), + FilePath = @"", + LineNumber = 144, + InheritanceDepth = 0, + TestSessionId = testSessionId, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithConstructor<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithConstructor<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "Should_Have_Label", + GenericTypeCount = 0, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = global::System.Array.Empty(), + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.GenericClassWithConstructor<>", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithConstructor<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithConstructor<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "GenericClassWithConstructor", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + Parent = null + }; + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + return new global::TUnit.TestProject.Bugs._4431.GenericClassWithConstructor(); + }, + InvokeTypedTest = static (instance, args, cancellationToken) => + { + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._4431.GenericClassWithConstructor)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.Should_Have_Label()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } + } + } + , + } + }; + genericMetadata.TestSessionId = testSessionId; + yield return genericMetadata; + yield break; + } + public global::System.Collections.Generic.IEnumerable EnumerateTestDescriptors() + { + yield return new global::TUnit.Core.TestDescriptor + { + TestId = "TUnit.TestProject.Bugs._4431.GenericClassWithConstructor.Should_Have_Label", + ClassName = "GenericClassWithConstructor", + MethodName = "Should_Have_Label", + FullyQualifiedName = "TUnit.TestProject.Bugs._4431.GenericClassWithConstructor.Should_Have_Label", + FilePath = @"", + LineNumber = 144, + Categories = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + HasDataSource = false, + RepeatCount = 0, + DependsOn = global::System.Array.Empty(), + Materializer = GetTestsAsync + }; + } +} +internal static class TUnit_TestProject_Bugs__4431_GenericClassWithConstructor_T_Should_Have_Label_ModuleInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.SourceRegistrar.Register(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithConstructor<>), new TUnit_TestProject_Bugs__4431_GenericClassWithConstructor_T_Should_Have_Label_TestSource()); + } +} + + +// ===== FILE SEPARATOR ===== + +// +#pragma warning disable + +#nullable enable +namespace TUnit.Generated; +internal sealed class TUnit_TestProject_Bugs__4431_MultipleTypeParameters_T1_T2_Should_Handle_Multiple_Type_Parameters_TestSource : global::TUnit.Core.Interfaces.SourceGenerator.ITestSource, global::TUnit.Core.Interfaces.SourceGenerator.ITestDescriptorSource +{ + public async global::System.Collections.Generic.IAsyncEnumerable GetTestsAsync(string testSessionId, [global::System.Runtime.CompilerServices.EnumeratorCancellation] global::System.Threading.CancellationToken cancellationToken = default) + { + // Create generic metadata with concrete type registrations + var genericMetadata = new global::TUnit.Core.GenericTestMetadata + { + TestName = "Should_Handle_Multiple_Type_Parameters", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.MultipleTypeParameters<,>), + TestMethodName = "Should_Handle_Multiple_Type_Parameters", + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA), typeof(global::TUnit.TestProject.Bugs._4431.TypeC)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeB), typeof(global::TUnit.TestProject.Bugs._4431.TypeC)) + ], + DataSources = global::System.Array.Empty(), + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = global::System.Array.Empty(), + InheritanceDepth = 0, + FilePath = @"", + LineNumber = 160, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.MultipleTypeParameters<,>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.MultipleTypeParameters<,>), [new global::TUnit.Core.GenericParameter(0, false, "T1"), new global::TUnit.Core.GenericParameter(1, false, "T2")]), + Name = "Should_Handle_Multiple_Type_Parameters", + GenericTypeCount = 0, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = global::System.Array.Empty(), + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.MultipleTypeParameters<,>", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.MultipleTypeParameters<,>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.MultipleTypeParameters<,>), [new global::TUnit.Core.GenericParameter(0, false, "T1"), new global::TUnit.Core.GenericParameter(1, false, "T2")]), + Name = "MultipleTypeParameters", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + Parent = null + }; + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + var genericType = typeof(global::TUnit.TestProject.Bugs._4431.MultipleTypeParameters<,>); + if (typeArgs.Length > 0) + { + var closedType = genericType.MakeGenericType(typeArgs); + return global::System.Activator.CreateInstance(closedType, args)!; + } + throw new global::System.InvalidOperationException("No type arguments provided for generic class"); + }, + ConcreteInstantiations = new global::System.Collections.Generic.Dictionary + { + [(typeof(global::TUnit.TestProject.Bugs._4431.TypeA).FullName ?? typeof(global::TUnit.TestProject.Bugs._4431.TypeA).Name) + "," + (typeof(global::TUnit.TestProject.Bugs._4431.TypeC).FullName ?? typeof(global::TUnit.TestProject.Bugs._4431.TypeC).Name)] = + new global::TUnit.Core.TestMetadata> + { + TestName = "Should_Handle_Multiple_Type_Parameters", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.MultipleTypeParameters), + TestMethodName = "Should_Handle_Multiple_Type_Parameters", + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA), typeof(global::TUnit.TestProject.Bugs._4431.TypeC)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeB), typeof(global::TUnit.TestProject.Bugs._4431.TypeC)) + ], + DataSources = global::System.Array.Empty(), + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = global::System.Array.Empty(), + FilePath = @"", + LineNumber = 160, + InheritanceDepth = 0, + TestSessionId = testSessionId, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.MultipleTypeParameters<,>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.MultipleTypeParameters<,>), [new global::TUnit.Core.GenericParameter(0, false, "T1"), new global::TUnit.Core.GenericParameter(1, false, "T2")]), + Name = "Should_Handle_Multiple_Type_Parameters", + GenericTypeCount = 0, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = global::System.Array.Empty(), + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.MultipleTypeParameters<,>", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.MultipleTypeParameters<,>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.MultipleTypeParameters<,>), [new global::TUnit.Core.GenericParameter(0, false, "T1"), new global::TUnit.Core.GenericParameter(1, false, "T2")]), + Name = "MultipleTypeParameters", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + Parent = null + }; + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + return new global::TUnit.TestProject.Bugs._4431.MultipleTypeParameters(); + }, + InvokeTypedTest = static (instance, args, cancellationToken) => + { + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._4431.MultipleTypeParameters)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.Should_Handle_Multiple_Type_Parameters()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } + } + } + , + [(typeof(global::TUnit.TestProject.Bugs._4431.TypeB).FullName ?? typeof(global::TUnit.TestProject.Bugs._4431.TypeB).Name) + "," + (typeof(global::TUnit.TestProject.Bugs._4431.TypeC).FullName ?? typeof(global::TUnit.TestProject.Bugs._4431.TypeC).Name)] = + new global::TUnit.Core.TestMetadata> + { + TestName = "Should_Handle_Multiple_Type_Parameters", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.MultipleTypeParameters), + TestMethodName = "Should_Handle_Multiple_Type_Parameters", + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA), typeof(global::TUnit.TestProject.Bugs._4431.TypeC)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeB), typeof(global::TUnit.TestProject.Bugs._4431.TypeC)) + ], + DataSources = global::System.Array.Empty(), + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = global::System.Array.Empty(), + FilePath = @"", + LineNumber = 160, + InheritanceDepth = 0, + TestSessionId = testSessionId, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.MultipleTypeParameters<,>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.MultipleTypeParameters<,>), [new global::TUnit.Core.GenericParameter(0, false, "T1"), new global::TUnit.Core.GenericParameter(1, false, "T2")]), + Name = "Should_Handle_Multiple_Type_Parameters", + GenericTypeCount = 0, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = global::System.Array.Empty(), + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.MultipleTypeParameters<,>", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.MultipleTypeParameters<,>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.MultipleTypeParameters<,>), [new global::TUnit.Core.GenericParameter(0, false, "T1"), new global::TUnit.Core.GenericParameter(1, false, "T2")]), + Name = "MultipleTypeParameters", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + Parent = null + }; + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + return new global::TUnit.TestProject.Bugs._4431.MultipleTypeParameters(); + }, + InvokeTypedTest = static (instance, args, cancellationToken) => + { + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._4431.MultipleTypeParameters)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.Should_Handle_Multiple_Type_Parameters()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } + } + } + , + } + }; + genericMetadata.TestSessionId = testSessionId; + yield return genericMetadata; + yield break; + } + public global::System.Collections.Generic.IEnumerable EnumerateTestDescriptors() + { + yield return new global::TUnit.Core.TestDescriptor + { + TestId = "TUnit.TestProject.Bugs._4431.MultipleTypeParameters.Should_Handle_Multiple_Type_Parameters", + ClassName = "MultipleTypeParameters", + MethodName = "Should_Handle_Multiple_Type_Parameters", + FullyQualifiedName = "TUnit.TestProject.Bugs._4431.MultipleTypeParameters.Should_Handle_Multiple_Type_Parameters", + FilePath = @"", + LineNumber = 160, + Categories = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + HasDataSource = false, + RepeatCount = 0, + DependsOn = global::System.Array.Empty(), + Materializer = GetTestsAsync + }; + } +} +internal static class TUnit_TestProject_Bugs__4431_MultipleTypeParameters_T1_T2_Should_Handle_Multiple_Type_Parameters_ModuleInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.SourceRegistrar.Register(typeof(global::TUnit.TestProject.Bugs._4431.MultipleTypeParameters<,>), new TUnit_TestProject_Bugs__4431_MultipleTypeParameters_T1_T2_Should_Handle_Multiple_Type_Parameters_TestSource()); + } +} + + +// ===== FILE SEPARATOR ===== + +// +#pragma warning disable + +#nullable enable +namespace TUnit.Generated; +internal sealed class TUnit_TestProject_Bugs__4431_DerivedGenericClass_T_Should_Create_From_Base_TestSource : global::TUnit.Core.Interfaces.SourceGenerator.ITestSource, global::TUnit.Core.Interfaces.SourceGenerator.ITestDescriptorSource +{ + public async global::System.Collections.Generic.IAsyncEnumerable GetTestsAsync(string testSessionId, [global::System.Runtime.CompilerServices.EnumeratorCancellation] global::System.Threading.CancellationToken cancellationToken = default) + { + // Create generic metadata with concrete type registrations + var genericMetadata = new global::TUnit.Core.GenericTestMetadata + { + TestName = "Should_Create_From_Base", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.DerivedGenericClass<>), + TestMethodName = "Should_Create_From_Base", + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeB)) + ], + DataSources = global::System.Array.Empty(), + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = global::System.Array.Empty(), + InheritanceDepth = 0, + FilePath = @"", + LineNumber = 184, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.DerivedGenericClass<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.DerivedGenericClass<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "Should_Create_From_Base", + GenericTypeCount = 0, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = global::System.Array.Empty(), + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.DerivedGenericClass<>", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.DerivedGenericClass<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.DerivedGenericClass<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "DerivedGenericClass", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + Parent = null + }; + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + var genericType = typeof(global::TUnit.TestProject.Bugs._4431.DerivedGenericClass<>); + if (typeArgs.Length > 0) + { + var closedType = genericType.MakeGenericType(typeArgs); + return global::System.Activator.CreateInstance(closedType, args)!; + } + throw new global::System.InvalidOperationException("No type arguments provided for generic class"); + }, + ConcreteInstantiations = new global::System.Collections.Generic.Dictionary + { + [(typeof(global::TUnit.TestProject.Bugs._4431.TypeA).FullName ?? typeof(global::TUnit.TestProject.Bugs._4431.TypeA).Name)] = + new global::TUnit.Core.TestMetadata> + { + TestName = "Should_Create_From_Base", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.DerivedGenericClass), + TestMethodName = "Should_Create_From_Base", + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeB)) + ], + DataSources = global::System.Array.Empty(), + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = global::System.Array.Empty(), + FilePath = @"", + LineNumber = 184, + InheritanceDepth = 0, + TestSessionId = testSessionId, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.DerivedGenericClass<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.DerivedGenericClass<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "Should_Create_From_Base", + GenericTypeCount = 0, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = global::System.Array.Empty(), + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.DerivedGenericClass<>", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.DerivedGenericClass<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.DerivedGenericClass<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "DerivedGenericClass", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + Parent = null + }; + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + return new global::TUnit.TestProject.Bugs._4431.DerivedGenericClass(); + }, + InvokeTypedTest = static (instance, args, cancellationToken) => + { + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._4431.DerivedGenericClass)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.Should_Create_From_Base()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } + } + } + , + [(typeof(global::TUnit.TestProject.Bugs._4431.TypeB).FullName ?? typeof(global::TUnit.TestProject.Bugs._4431.TypeB).Name)] = + new global::TUnit.Core.TestMetadata> + { + TestName = "Should_Create_From_Base", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.DerivedGenericClass), + TestMethodName = "Should_Create_From_Base", + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeB)) + ], + DataSources = global::System.Array.Empty(), + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = global::System.Array.Empty(), + FilePath = @"", + LineNumber = 184, + InheritanceDepth = 0, + TestSessionId = testSessionId, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.DerivedGenericClass<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.DerivedGenericClass<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "Should_Create_From_Base", + GenericTypeCount = 0, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = global::System.Array.Empty(), + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.DerivedGenericClass<>", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.DerivedGenericClass<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.DerivedGenericClass<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "DerivedGenericClass", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + Parent = null + }; + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + return new global::TUnit.TestProject.Bugs._4431.DerivedGenericClass(); + }, + InvokeTypedTest = static (instance, args, cancellationToken) => + { + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._4431.DerivedGenericClass)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.Should_Create_From_Base()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } + } + } + , + } + }; + genericMetadata.TestSessionId = testSessionId; + yield return genericMetadata; + yield break; + } + public global::System.Collections.Generic.IEnumerable EnumerateTestDescriptors() + { + yield return new global::TUnit.Core.TestDescriptor + { + TestId = "TUnit.TestProject.Bugs._4431.DerivedGenericClass.Should_Create_From_Base", + ClassName = "DerivedGenericClass", + MethodName = "Should_Create_From_Base", + FullyQualifiedName = "TUnit.TestProject.Bugs._4431.DerivedGenericClass.Should_Create_From_Base", + FilePath = @"", + LineNumber = 184, + Categories = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + HasDataSource = false, + RepeatCount = 0, + DependsOn = global::System.Array.Empty(), + Materializer = GetTestsAsync + }; + } +} +internal static class TUnit_TestProject_Bugs__4431_DerivedGenericClass_T_Should_Create_From_Base_ModuleInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.SourceRegistrar.Register(typeof(global::TUnit.TestProject.Bugs._4431.DerivedGenericClass<>), new TUnit_TestProject_Bugs__4431_DerivedGenericClass_T_Should_Create_From_Base_TestSource()); + } +} + + +// ===== FILE SEPARATOR ===== + +// +#pragma warning disable + +#nullable enable +namespace TUnit.Generated; +internal sealed class TUnit_TestProject_Bugs__4431_GenericClassWithClassDataSource_T_Should_Have_DataSource_TestSource : global::TUnit.Core.Interfaces.SourceGenerator.ITestSource, global::TUnit.Core.Interfaces.SourceGenerator.ITestDescriptorSource +{ + public async global::System.Collections.Generic.IAsyncEnumerable GetTestsAsync(string testSessionId, [global::System.Runtime.CompilerServices.EnumeratorCancellation] global::System.Threading.CancellationToken cancellationToken = default) + { + // Create generic metadata with concrete type registrations + var genericMetadata = new global::TUnit.Core.GenericTestMetadata + { + TestName = "Should_Have_DataSource", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource<>), + TestMethodName = "Should_Have_DataSource", + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeB)) + ], + DataSources = global::System.Array.Empty(), + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = new global::TUnit.Core.PropertyInjectionData[] + { + new global::TUnit.Core.PropertyInjectionData + { + PropertyName = "DataSource", + PropertyType = typeof(global::TUnit.TestProject.Bugs._4431.TestDataSource), + Setter = (instance, value) => throw new global::System.NotSupportedException( + "Init-only property 'DataSource' on generic type 'global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource<>' cannot be set. " + + "Use a regular settable property or constructor injection instead."), + ValueFactory = () => throw new global::System.InvalidOperationException("ValueFactory should be provided by TestDataCombination"), + NestedPropertyInjections = global::System.Array.Empty(), + NestedPropertyValueFactory = obj => + { + return new global::System.Collections.Generic.Dictionary(); + } + }, + }, + InheritanceDepth = 0, + FilePath = @"", + LineNumber = 210, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "Should_Have_DataSource", + GenericTypeCount = 0, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = global::System.Array.Empty(), + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource<>", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "GenericClassWithClassDataSource", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = new global::TUnit.Core.PropertyMetadata[] + { + new global::TUnit.Core.PropertyMetadata + { + ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource<>).GetProperty("DataSource"), + Type = typeof(global::TUnit.TestProject.Bugs._4431.TestDataSource), + Name = "DataSource", + IsStatic = false, + IsNullable = false, + Getter = o => ((dynamic)o).DataSource, + ClassMetadata = null!, + ContainingTypeMetadata = null! + } + }, + Parent = null + }; + foreach (var prop in classMetadata.Properties) + { + prop.ClassMetadata = classMetadata; + prop.ContainingTypeMetadata = classMetadata; + } + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + var genericType = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource<>); + if (typeArgs.Length > 0) + { + var closedType = genericType.MakeGenericType(typeArgs); + return global::System.Activator.CreateInstance(closedType, args)!; + } + throw new global::System.InvalidOperationException("No type arguments provided for generic class"); + }, + ConcreteInstantiations = new global::System.Collections.Generic.Dictionary + { + [(typeof(global::TUnit.TestProject.Bugs._4431.TypeA).FullName ?? typeof(global::TUnit.TestProject.Bugs._4431.TypeA).Name)] = + new global::TUnit.Core.TestMetadata> + { + TestName = "Should_Have_DataSource", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource), + TestMethodName = "Should_Have_DataSource", + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeB)) + ], + DataSources = global::System.Array.Empty(), + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = new global::TUnit.Core.PropertyInjectionData[] + { + new global::TUnit.Core.PropertyInjectionData + { + PropertyName = "DataSource", + PropertyType = typeof(global::TUnit.TestProject.Bugs._4431.TestDataSource), + Setter = (instance, value) => throw new global::System.NotSupportedException( + "Init-only property 'DataSource' on generic type 'global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource' cannot be set. " + + "Use a regular settable property or constructor injection instead."), + ValueFactory = () => throw new global::System.InvalidOperationException("ValueFactory should be provided by TestDataCombination"), + NestedPropertyInjections = global::System.Array.Empty(), + NestedPropertyValueFactory = obj => + { + return new global::System.Collections.Generic.Dictionary(); + } + }, + }, + FilePath = @"", + LineNumber = 210, + InheritanceDepth = 0, + TestSessionId = testSessionId, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "Should_Have_DataSource", + GenericTypeCount = 0, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = global::System.Array.Empty(), + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource<>", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "GenericClassWithClassDataSource", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = new global::TUnit.Core.PropertyMetadata[] + { + new global::TUnit.Core.PropertyMetadata + { + ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource<>).GetProperty("DataSource"), + Type = typeof(global::TUnit.TestProject.Bugs._4431.TestDataSource), + Name = "DataSource", + IsStatic = false, + IsNullable = false, + Getter = o => ((dynamic)o).DataSource, + ClassMetadata = null!, + ContainingTypeMetadata = null! + } + }, + Parent = null + }; + foreach (var prop in classMetadata.Properties) + { + prop.ClassMetadata = classMetadata; + prop.ContainingTypeMetadata = classMetadata; + } + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + return new global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource(); + }, + InvokeTypedTest = static (instance, args, cancellationToken) => + { + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.Should_Have_DataSource()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } + } + } + , + [(typeof(global::TUnit.TestProject.Bugs._4431.TypeB).FullName ?? typeof(global::TUnit.TestProject.Bugs._4431.TypeB).Name)] = + new global::TUnit.Core.TestMetadata> + { + TestName = "Should_Have_DataSource", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource), + TestMethodName = "Should_Have_DataSource", + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeB)) + ], + DataSources = global::System.Array.Empty(), + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = new global::TUnit.Core.PropertyInjectionData[] + { + new global::TUnit.Core.PropertyInjectionData + { + PropertyName = "DataSource", + PropertyType = typeof(global::TUnit.TestProject.Bugs._4431.TestDataSource), + Setter = (instance, value) => throw new global::System.NotSupportedException( + "Init-only property 'DataSource' on generic type 'global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource' cannot be set. " + + "Use a regular settable property or constructor injection instead."), + ValueFactory = () => throw new global::System.InvalidOperationException("ValueFactory should be provided by TestDataCombination"), + NestedPropertyInjections = global::System.Array.Empty(), + NestedPropertyValueFactory = obj => + { + return new global::System.Collections.Generic.Dictionary(); + } + }, + }, + FilePath = @"", + LineNumber = 210, + InheritanceDepth = 0, + TestSessionId = testSessionId, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "Should_Have_DataSource", + GenericTypeCount = 0, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = global::System.Array.Empty(), + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource<>", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), + Name = "GenericClassWithClassDataSource", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = new global::TUnit.Core.PropertyMetadata[] + { + new global::TUnit.Core.PropertyMetadata + { + ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource<>).GetProperty("DataSource"), + Type = typeof(global::TUnit.TestProject.Bugs._4431.TestDataSource), + Name = "DataSource", + IsStatic = false, + IsNullable = false, + Getter = o => ((dynamic)o).DataSource, + ClassMetadata = null!, + ContainingTypeMetadata = null! + } + }, + Parent = null + }; + foreach (var prop in classMetadata.Properties) + { + prop.ClassMetadata = classMetadata; + prop.ContainingTypeMetadata = classMetadata; + } + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + return new global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource(); + }, + InvokeTypedTest = static (instance, args, cancellationToken) => + { + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.Should_Have_DataSource()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } + } + } + , + } + }; + genericMetadata.TestSessionId = testSessionId; + yield return genericMetadata; + yield break; + } + public global::System.Collections.Generic.IEnumerable EnumerateTestDescriptors() + { + yield return new global::TUnit.Core.TestDescriptor + { + TestId = "TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource.Should_Have_DataSource", + ClassName = "GenericClassWithClassDataSource", + MethodName = "Should_Have_DataSource", + FullyQualifiedName = "TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource.Should_Have_DataSource", + FilePath = @"", + LineNumber = 210, + Categories = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + HasDataSource = false, + RepeatCount = 0, + DependsOn = global::System.Array.Empty(), + Materializer = GetTestsAsync + }; + } +} +internal static class TUnit_TestProject_Bugs__4431_GenericClassWithClassDataSource_T_Should_Have_DataSource_ModuleInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.SourceRegistrar.Register(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource<>), new TUnit_TestProject_Bugs__4431_GenericClassWithClassDataSource_T_Should_Have_DataSource_TestSource()); + } +} + + +// ===== FILE SEPARATOR ===== + +// +#pragma warning disable + +#nullable enable +namespace TUnit.Generated; +internal sealed class TUnit_TestProject_Bugs__4431_GenericClassGenericMethodWithDataSources_TClass_FullyGeneric_With_DataSources__bool_TestSource : global::TUnit.Core.Interfaces.SourceGenerator.ITestSource, global::TUnit.Core.Interfaces.SourceGenerator.ITestDescriptorSource +{ + public async global::System.Collections.Generic.IAsyncEnumerable GetTestsAsync(string testSessionId, [global::System.Runtime.CompilerServices.EnumeratorCancellation] global::System.Threading.CancellationToken cancellationToken = default) + { + // Create generic metadata with concrete type registrations + var genericMetadata = new global::TUnit.Core.GenericTestMetadata + { + TestName = "FullyGeneric_With_DataSources", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>), + TestMethodName = "FullyGeneric_With_DataSources", + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(int)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(double)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeB)) + ], + DataSources = global::System.Array.Empty(), + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = new global::TUnit.Core.PropertyInjectionData[] + { + new global::TUnit.Core.PropertyInjectionData + { + PropertyName = "DataSource", + PropertyType = typeof(global::TUnit.TestProject.Bugs._4431.TestDataSource), + Setter = (instance, value) => throw new global::System.NotSupportedException( + "Init-only property 'DataSource' on generic type 'global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>' cannot be set. " + + "Use a regular settable property or constructor injection instead."), + ValueFactory = () => throw new global::System.InvalidOperationException("ValueFactory should be provided by TestDataCombination"), + NestedPropertyInjections = global::System.Array.Empty(), + NestedPropertyValueFactory = obj => + { + return new global::System.Collections.Generic.Dictionary(); + } + }, + }, + InheritanceDepth = 0, + FilePath = @"", + LineNumber = 236, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>), [new global::TUnit.Core.GenericParameter(0, false, "TClass")]), + Name = "FullyGeneric_With_DataSources", + GenericTypeCount = 1, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = new global::TUnit.Core.ParameterMetadata[] + { + new global::TUnit.Core.ParameterMetadata(typeof(bool)) + { + Name = "flag", + TypeInfo = new global::TUnit.Core.ConcreteType(typeof(bool)), + IsNullable = false, + ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "FullyGeneric_With_DataSources" && m.GetParameters().Length == 1)?.GetParameters()[0]! + } + }, + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>), [new global::TUnit.Core.GenericParameter(0, false, "TClass")]), + Name = "GenericClassGenericMethodWithDataSources", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = new global::TUnit.Core.PropertyMetadata[] + { + new global::TUnit.Core.PropertyMetadata + { + ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>).GetProperty("DataSource"), + Type = typeof(global::TUnit.TestProject.Bugs._4431.TestDataSource), + Name = "DataSource", + IsStatic = false, + IsNullable = false, + Getter = o => ((dynamic)o).DataSource, + ClassMetadata = null!, + ContainingTypeMetadata = null! + } + }, + Parent = null + }; + foreach (var prop in classMetadata.Properties) + { + prop.ClassMetadata = classMetadata; + prop.ContainingTypeMetadata = classMetadata; + } + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + var genericType = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>); + if (typeArgs.Length > 0) + { + var closedType = genericType.MakeGenericType(typeArgs); + return global::System.Activator.CreateInstance(closedType, args)!; + } + throw new global::System.InvalidOperationException("No type arguments provided for generic class"); + }, + ConcreteInstantiations = new global::System.Collections.Generic.Dictionary + { + [(typeof(global::TUnit.TestProject.Bugs._4431.TypeA).FullName ?? typeof(global::TUnit.TestProject.Bugs._4431.TypeA).Name) + "," + (typeof(int).FullName ?? typeof(int).Name)] = + new global::TUnit.Core.TestMetadata> + { + TestName = "FullyGeneric_With_DataSources", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources), + TestMethodName = "FullyGeneric_With_DataSources", + GenericMethodTypeArguments = new global::System.Type[] { typeof(int)}, + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(int)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(double)), + new global::TUnit.Core.MethodDataSourceAttribute("GetBooleans"), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeB)) + ], + DataSources = new global::TUnit.Core.IDataSourceAttribute[] + { + new global::TUnit.Core.MethodDataSourceAttribute("GetBooleans") + { + Factory = (dataGeneratorMetadata) => + { + async global::System.Collections.Generic.IAsyncEnumerable>> Factory() + { + var result = global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources.GetBooleans(); + if (result is global::System.Collections.IEnumerable enumerable && !(result is string)) + { + foreach (var item in enumerable) + { + yield return () => global::System.Threading.Tasks.Task.FromResult(global::TUnit.Core.Helpers.DataSourceHelpers.ToObjectArray(item)); + } + } + else + { + yield return () => global::System.Threading.Tasks.Task.FromResult(global::TUnit.Core.Helpers.DataSourceHelpers.ToObjectArray(result)); + } + } + return Factory(); + } + }, + }, + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = new global::TUnit.Core.PropertyInjectionData[] + { + new global::TUnit.Core.PropertyInjectionData + { + PropertyName = "DataSource", + PropertyType = typeof(global::TUnit.TestProject.Bugs._4431.TestDataSource), + Setter = (instance, value) => throw new global::System.NotSupportedException( + "Init-only property 'DataSource' on generic type 'global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources' cannot be set. " + + "Use a regular settable property or constructor injection instead."), + ValueFactory = () => throw new global::System.InvalidOperationException("ValueFactory should be provided by TestDataCombination"), + NestedPropertyInjections = global::System.Array.Empty(), + NestedPropertyValueFactory = obj => + { + return new global::System.Collections.Generic.Dictionary(); + } + }, + }, + FilePath = @"", + LineNumber = 236, + InheritanceDepth = 0, + TestSessionId = testSessionId, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>), [new global::TUnit.Core.GenericParameter(0, false, "TClass")]), + Name = "FullyGeneric_With_DataSources", + GenericTypeCount = 1, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = new global::TUnit.Core.ParameterMetadata[] + { + new global::TUnit.Core.ParameterMetadata(typeof(bool)) + { + Name = "flag", + TypeInfo = new global::TUnit.Core.ConcreteType(typeof(bool)), + IsNullable = false, + ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "FullyGeneric_With_DataSources" && m.GetParameters().Length == 1)?.GetParameters()[0]! + } + }, + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>), [new global::TUnit.Core.GenericParameter(0, false, "TClass")]), + Name = "GenericClassGenericMethodWithDataSources", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = new global::TUnit.Core.PropertyMetadata[] + { + new global::TUnit.Core.PropertyMetadata + { + ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>).GetProperty("DataSource"), + Type = typeof(global::TUnit.TestProject.Bugs._4431.TestDataSource), + Name = "DataSource", + IsStatic = false, + IsNullable = false, + Getter = o => ((dynamic)o).DataSource, + ClassMetadata = null!, + ContainingTypeMetadata = null! + } + }, + Parent = null + }; + foreach (var prop in classMetadata.Properties) + { + prop.ClassMetadata = classMetadata; + prop.ContainingTypeMetadata = classMetadata; + } + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + return new global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources(); + }, + InvokeTypedTest = static (instance, args, cancellationToken) => + { + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.FullyGeneric_With_DataSources((bool)args[0]!)); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } + } + } + , + [(typeof(global::TUnit.TestProject.Bugs._4431.TypeA).FullName ?? typeof(global::TUnit.TestProject.Bugs._4431.TypeA).Name) + "," + (typeof(double).FullName ?? typeof(double).Name)] = + new global::TUnit.Core.TestMetadata> + { + TestName = "FullyGeneric_With_DataSources", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources), + TestMethodName = "FullyGeneric_With_DataSources", + GenericMethodTypeArguments = new global::System.Type[] { typeof(double)}, + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(int)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(double)), + new global::TUnit.Core.MethodDataSourceAttribute("GetBooleans"), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeB)) + ], + DataSources = new global::TUnit.Core.IDataSourceAttribute[] + { + new global::TUnit.Core.MethodDataSourceAttribute("GetBooleans") + { + Factory = (dataGeneratorMetadata) => + { + async global::System.Collections.Generic.IAsyncEnumerable>> Factory() + { + var result = global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources.GetBooleans(); + if (result is global::System.Collections.IEnumerable enumerable && !(result is string)) + { + foreach (var item in enumerable) + { + yield return () => global::System.Threading.Tasks.Task.FromResult(global::TUnit.Core.Helpers.DataSourceHelpers.ToObjectArray(item)); + } + } + else + { + yield return () => global::System.Threading.Tasks.Task.FromResult(global::TUnit.Core.Helpers.DataSourceHelpers.ToObjectArray(result)); + } + } + return Factory(); + } + }, + }, + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = new global::TUnit.Core.PropertyInjectionData[] + { + new global::TUnit.Core.PropertyInjectionData + { + PropertyName = "DataSource", + PropertyType = typeof(global::TUnit.TestProject.Bugs._4431.TestDataSource), + Setter = (instance, value) => throw new global::System.NotSupportedException( + "Init-only property 'DataSource' on generic type 'global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources' cannot be set. " + + "Use a regular settable property or constructor injection instead."), + ValueFactory = () => throw new global::System.InvalidOperationException("ValueFactory should be provided by TestDataCombination"), + NestedPropertyInjections = global::System.Array.Empty(), + NestedPropertyValueFactory = obj => + { + return new global::System.Collections.Generic.Dictionary(); + } + }, + }, + FilePath = @"", + LineNumber = 236, + InheritanceDepth = 0, + TestSessionId = testSessionId, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>), [new global::TUnit.Core.GenericParameter(0, false, "TClass")]), + Name = "FullyGeneric_With_DataSources", + GenericTypeCount = 1, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = new global::TUnit.Core.ParameterMetadata[] + { + new global::TUnit.Core.ParameterMetadata(typeof(bool)) + { + Name = "flag", + TypeInfo = new global::TUnit.Core.ConcreteType(typeof(bool)), + IsNullable = false, + ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "FullyGeneric_With_DataSources" && m.GetParameters().Length == 1)?.GetParameters()[0]! + } + }, + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>), [new global::TUnit.Core.GenericParameter(0, false, "TClass")]), + Name = "GenericClassGenericMethodWithDataSources", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = new global::TUnit.Core.PropertyMetadata[] + { + new global::TUnit.Core.PropertyMetadata + { + ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>).GetProperty("DataSource"), + Type = typeof(global::TUnit.TestProject.Bugs._4431.TestDataSource), + Name = "DataSource", + IsStatic = false, + IsNullable = false, + Getter = o => ((dynamic)o).DataSource, + ClassMetadata = null!, + ContainingTypeMetadata = null! + } + }, + Parent = null + }; + foreach (var prop in classMetadata.Properties) + { + prop.ClassMetadata = classMetadata; + prop.ContainingTypeMetadata = classMetadata; + } + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + return new global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources(); + }, + InvokeTypedTest = static (instance, args, cancellationToken) => + { + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.FullyGeneric_With_DataSources((bool)args[0]!)); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } + } + } + , + [(typeof(global::TUnit.TestProject.Bugs._4431.TypeB).FullName ?? typeof(global::TUnit.TestProject.Bugs._4431.TypeB).Name) + "," + (typeof(int).FullName ?? typeof(int).Name)] = + new global::TUnit.Core.TestMetadata> + { + TestName = "FullyGeneric_With_DataSources", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources), + TestMethodName = "FullyGeneric_With_DataSources", + GenericMethodTypeArguments = new global::System.Type[] { typeof(int)}, + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(int)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(double)), + new global::TUnit.Core.MethodDataSourceAttribute("GetBooleans"), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeB)) + ], + DataSources = new global::TUnit.Core.IDataSourceAttribute[] + { + new global::TUnit.Core.MethodDataSourceAttribute("GetBooleans") + { + Factory = (dataGeneratorMetadata) => + { + async global::System.Collections.Generic.IAsyncEnumerable>> Factory() + { + var result = global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources.GetBooleans(); + if (result is global::System.Collections.IEnumerable enumerable && !(result is string)) + { + foreach (var item in enumerable) + { + yield return () => global::System.Threading.Tasks.Task.FromResult(global::TUnit.Core.Helpers.DataSourceHelpers.ToObjectArray(item)); + } + } + else + { + yield return () => global::System.Threading.Tasks.Task.FromResult(global::TUnit.Core.Helpers.DataSourceHelpers.ToObjectArray(result)); + } + } + return Factory(); + } + }, + }, + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = new global::TUnit.Core.PropertyInjectionData[] + { + new global::TUnit.Core.PropertyInjectionData + { + PropertyName = "DataSource", + PropertyType = typeof(global::TUnit.TestProject.Bugs._4431.TestDataSource), + Setter = (instance, value) => throw new global::System.NotSupportedException( + "Init-only property 'DataSource' on generic type 'global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources' cannot be set. " + + "Use a regular settable property or constructor injection instead."), + ValueFactory = () => throw new global::System.InvalidOperationException("ValueFactory should be provided by TestDataCombination"), + NestedPropertyInjections = global::System.Array.Empty(), + NestedPropertyValueFactory = obj => + { + return new global::System.Collections.Generic.Dictionary(); + } + }, + }, + FilePath = @"", + LineNumber = 236, + InheritanceDepth = 0, + TestSessionId = testSessionId, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>), [new global::TUnit.Core.GenericParameter(0, false, "TClass")]), + Name = "FullyGeneric_With_DataSources", + GenericTypeCount = 1, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = new global::TUnit.Core.ParameterMetadata[] + { + new global::TUnit.Core.ParameterMetadata(typeof(bool)) + { + Name = "flag", + TypeInfo = new global::TUnit.Core.ConcreteType(typeof(bool)), + IsNullable = false, + ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "FullyGeneric_With_DataSources" && m.GetParameters().Length == 1)?.GetParameters()[0]! + } + }, + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>), [new global::TUnit.Core.GenericParameter(0, false, "TClass")]), + Name = "GenericClassGenericMethodWithDataSources", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = new global::TUnit.Core.PropertyMetadata[] + { + new global::TUnit.Core.PropertyMetadata + { + ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>).GetProperty("DataSource"), + Type = typeof(global::TUnit.TestProject.Bugs._4431.TestDataSource), + Name = "DataSource", + IsStatic = false, + IsNullable = false, + Getter = o => ((dynamic)o).DataSource, + ClassMetadata = null!, + ContainingTypeMetadata = null! + } + }, + Parent = null + }; + foreach (var prop in classMetadata.Properties) + { + prop.ClassMetadata = classMetadata; + prop.ContainingTypeMetadata = classMetadata; + } + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + return new global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources(); + }, + InvokeTypedTest = static (instance, args, cancellationToken) => + { + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.FullyGeneric_With_DataSources((bool)args[0]!)); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } + } + } + , + [(typeof(global::TUnit.TestProject.Bugs._4431.TypeB).FullName ?? typeof(global::TUnit.TestProject.Bugs._4431.TypeB).Name) + "," + (typeof(double).FullName ?? typeof(double).Name)] = + new global::TUnit.Core.TestMetadata> + { + TestName = "FullyGeneric_With_DataSources", + TestClassType = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources), + TestMethodName = "FullyGeneric_With_DataSources", + GenericMethodTypeArguments = new global::System.Type[] { typeof(double)}, + Dependencies = global::System.Array.Empty(), + AttributeFactory = static () => + [ + new global::TUnit.Core.TestAttribute(), + new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(int)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(double)), + new global::TUnit.Core.MethodDataSourceAttribute("GetBooleans"), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeA)), + new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::TUnit.TestProject.Bugs._4431.TypeB)) + ], + DataSources = new global::TUnit.Core.IDataSourceAttribute[] + { + new global::TUnit.Core.MethodDataSourceAttribute("GetBooleans") + { + Factory = (dataGeneratorMetadata) => + { + async global::System.Collections.Generic.IAsyncEnumerable>> Factory() + { + var result = global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources.GetBooleans(); + if (result is global::System.Collections.IEnumerable enumerable && !(result is string)) + { + foreach (var item in enumerable) + { + yield return () => global::System.Threading.Tasks.Task.FromResult(global::TUnit.Core.Helpers.DataSourceHelpers.ToObjectArray(item)); + } + } + else + { + yield return () => global::System.Threading.Tasks.Task.FromResult(global::TUnit.Core.Helpers.DataSourceHelpers.ToObjectArray(result)); + } + } + return Factory(); + } + }, + }, + ClassDataSources = global::System.Array.Empty(), + PropertyDataSources = global::System.Array.Empty(), + PropertyInjections = new global::TUnit.Core.PropertyInjectionData[] + { + new global::TUnit.Core.PropertyInjectionData + { + PropertyName = "DataSource", + PropertyType = typeof(global::TUnit.TestProject.Bugs._4431.TestDataSource), + Setter = (instance, value) => throw new global::System.NotSupportedException( + "Init-only property 'DataSource' on generic type 'global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources' cannot be set. " + + "Use a regular settable property or constructor injection instead."), + ValueFactory = () => throw new global::System.InvalidOperationException("ValueFactory should be provided by TestDataCombination"), + NestedPropertyInjections = global::System.Array.Empty(), + NestedPropertyValueFactory = obj => + { + return new global::System.Collections.Generic.Dictionary(); + } + }, + }, + FilePath = @"", + LineNumber = 236, + InheritanceDepth = 0, + TestSessionId = testSessionId, + MethodMetadata = new global::TUnit.Core.MethodMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>), [new global::TUnit.Core.GenericParameter(0, false, "TClass")]), + Name = "FullyGeneric_With_DataSources", + GenericTypeCount = 1, + ReturnType = typeof(global::System.Threading.Tasks.Task), + ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), + Parameters = new global::TUnit.Core.ParameterMetadata[] + { + new global::TUnit.Core.ParameterMetadata(typeof(bool)) + { + Name = "flag", + TypeInfo = new global::TUnit.Core.ConcreteType(typeof(bool)), + IsNullable = false, + ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "FullyGeneric_With_DataSources" && m.GetParameters().Length == 1)?.GetParameters()[0]! + } + }, + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>", static () => + { + var classMetadata = new global::TUnit.Core.ClassMetadata + { + Type = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>), + TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>), [new global::TUnit.Core.GenericParameter(0, false, "TClass")]), + Name = "GenericClassGenericMethodWithDataSources", + Namespace = "TUnit.TestProject.Bugs._4431", + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Parameters = global::System.Array.Empty(), + Properties = new global::TUnit.Core.PropertyMetadata[] + { + new global::TUnit.Core.PropertyMetadata + { + ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>).GetProperty("DataSource"), + Type = typeof(global::TUnit.TestProject.Bugs._4431.TestDataSource), + Name = "DataSource", + IsStatic = false, + IsNullable = false, + Getter = o => ((dynamic)o).DataSource, + ClassMetadata = null!, + ContainingTypeMetadata = null! + } + }, + Parent = null + }; + foreach (var prop in classMetadata.Properties) + { + prop.ClassMetadata = classMetadata; + prop.ContainingTypeMetadata = classMetadata; + } + return classMetadata; + }) + }, + InstanceFactory = static (typeArgs, args) => + { + return new global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources(); + }, + InvokeTypedTest = static (instance, args, cancellationToken) => + { + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.FullyGeneric_With_DataSources((bool)args[0]!)); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } + } + } + , + } + }; + genericMetadata.TestSessionId = testSessionId; + yield return genericMetadata; + yield break; + } + public global::System.Collections.Generic.IEnumerable EnumerateTestDescriptors() + { + yield return new global::TUnit.Core.TestDescriptor + { + TestId = "TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources.FullyGeneric_With_DataSources", + ClassName = "GenericClassGenericMethodWithDataSources", + MethodName = "FullyGeneric_With_DataSources", + FullyQualifiedName = "TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources.FullyGeneric_With_DataSources", + FilePath = @"", + LineNumber = 236, + Categories = global::System.Array.Empty(), + Properties = global::System.Array.Empty(), + HasDataSource = true, + RepeatCount = 0, + DependsOn = global::System.Array.Empty(), + Materializer = GetTestsAsync + }; + } +} +internal static class TUnit_TestProject_Bugs__4431_GenericClassGenericMethodWithDataSources_TClass_FullyGeneric_With_DataSources__bool_ModuleInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.SourceRegistrar.Register(typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>), new TUnit_TestProject_Bugs__4431_GenericClassGenericMethodWithDataSources_TClass_FullyGeneric_With_DataSources__bool_TestSource()); + } +} diff --git a/TUnit.Core.SourceGenerator.Tests/GenericMethodWithDataSourceTests.cs b/TUnit.Core.SourceGenerator.Tests/GenericMethodWithDataSourceTests.cs new file mode 100644 index 0000000000..5557f40c36 --- /dev/null +++ b/TUnit.Core.SourceGenerator.Tests/GenericMethodWithDataSourceTests.cs @@ -0,0 +1,81 @@ +using TUnit.Core.SourceGenerator.Tests.Options; + +namespace TUnit.Core.SourceGenerator.Tests; + +internal class GenericMethodWithDataSourceTests : TestsBase +{ + [Test] + public Task Generic_Method_With_MethodDataSource_Should_Generate_Tests() => RunTest(Path.Combine(Git.RootDirectory.FullName, + "TUnit.TestProject", + "Bugs", + "4431", + "ComprehensiveGenericTests.cs"), + async generatedFiles => + { + // This test verifies that generic methods with [GenerateGenericTest] AND [MethodDataSource] + // generate proper test metadata including both the type instantiations and the data source + + // Find all files related to GenericMethod_With_DataSource + var matchingFiles = generatedFiles.Where(f => + f.Contains("GenericMethod_With_DataSource") && + f.Contains("TestSource")).ToList(); + + // Debug: output the matching file count + await Assert.That(matchingFiles.Count).IsGreaterThanOrEqualTo(1) + .Because($"At least one test source should be generated for GenericMethod_With_DataSource. Found {matchingFiles.Count} matching files."); + + // Debug: output if any file contains Int32 + var hasInt32 = matchingFiles.Any(f => f.Contains("Int32")); + var hasDouble = matchingFiles.Any(f => f.Contains("Double")); + + // Debug: Look at ConcreteInstantiations contents + foreach (var file in matchingFiles) + { + if (file.Contains("ConcreteInstantiations")) + { + var idx = file.IndexOf("ConcreteInstantiations"); + var snippet = file.Substring(idx, Math.Min(500, file.Length - idx)); + Console.WriteLine($"[DEBUG] ConcreteInstantiations snippet: {snippet}"); + } + } + + // Find the file WITH concrete instantiations (uses typeof(int) and typeof(double) syntax) + var genericMethodWithDataSourceFile = matchingFiles.FirstOrDefault(f => + f.Contains("typeof(int)") && f.Contains("typeof(double)")); + + await Assert.That(genericMethodWithDataSourceFile).IsNotNull() + .Because("A test source should be generated for GenericMethod_With_DataSource with concrete type instantiations (int and double)"); + + // If we found the file, verify it has both type instantiations + if (genericMethodWithDataSourceFile != null) + { + // Verify it includes the MethodDataSource + await Assert.That(genericMethodWithDataSourceFile).Contains("MethodDataSourceAttribute") + .Because("Should include the MethodDataSource attribute in DataSources"); + await Assert.That(genericMethodWithDataSourceFile).Contains("GetStrings") + .Because("Should reference the GetStrings method"); + } + + // Look for FullyGeneric_With_DataSources test generation (class+method generic with data source) + var fullyGenericFiles = generatedFiles.Where(f => + f.Contains("FullyGeneric_With_DataSources") && + f.Contains("TestSource")).ToList(); + + await Assert.That(fullyGenericFiles.Count).IsGreaterThanOrEqualTo(1) + .Because("At least one test source should be generated for FullyGeneric_With_DataSources"); + + // Find the file with concrete instantiations (uses typeof(int) or typeof(double) syntax) + var fullyGenericFile = fullyGenericFiles.FirstOrDefault(f => + f.Contains("ConcreteInstantiations") && + (f.Contains("typeof(int)") || f.Contains("typeof(double)"))); + + // Verify it has the data source + if (fullyGenericFile != null) + { + await Assert.That(fullyGenericFile).Contains("MethodDataSourceAttribute") + .Because("Should include the MethodDataSource attribute in DataSources"); + await Assert.That(fullyGenericFile).Contains("GetBooleans") + .Because("Should reference the GetBooleans method"); + } + }); +} diff --git a/TUnit.Core.SourceGenerator.Tests/GenericPropertyInjectionTests.DeepInheritance_GeneratesMetadataForAllLevels.verified.txt b/TUnit.Core.SourceGenerator.Tests/GenericPropertyInjectionTests.DeepInheritance_GeneratesMetadataForAllLevels.verified.txt new file mode 100644 index 0000000000..7b28dd257e --- /dev/null +++ b/TUnit.Core.SourceGenerator.Tests/GenericPropertyInjectionTests.DeepInheritance_GeneratesMetadataForAllLevels.verified.txt @@ -0,0 +1,321 @@ +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_GenericInitializerPropertyTests_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.GenericInitializerPropertyTests), new PropertyInjectionSource_61ab58e()); + } +} + +internal sealed class PropertyInjectionSource_61ab58e : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.GenericInitializerPropertyTests); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.GenericInitializerFixture GetFixtureBackingField(TUnit.TestProject.GenericInitializerPropertyTests instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Fixture", + PropertyType = typeof(global::TUnit.TestProject.GenericInitializerFixture), + ContainingType = typeof(TUnit.TestProject.GenericInitializerPropertyTests), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute>(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.GenericInitializerPropertyTests)instance; +#if NET8_0_OR_GREATER + GetFixtureBackingField((TUnit.TestProject.GenericInitializerPropertyTests)typedInstance) = (global::TUnit.TestProject.GenericInitializerFixture)value; +#else + var backingField = typeof(TUnit.TestProject.GenericInitializerPropertyTests).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_GenericFixtureBase_TUnit_TestProject_GenericPropertyInjectionTests_TestProgram__Generic_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.GenericFixtureBase), new PropertyInjectionSource_Generic_7a6c8287()); + } +} + +internal sealed class PropertyInjectionSource_Generic_7a6c8287 : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.GenericFixtureBase); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetPostgresBackingField(TUnit.TestProject.GenericFixtureBase instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Postgres", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.GenericFixtureBase), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.GenericFixtureBase)instance; +#if NET8_0_OR_GREATER + GetPostgresBackingField((TUnit.TestProject.GenericFixtureBase)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.GenericFixtureBase).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_GenericFixtureBase_TUnit_TestProject_MultipleGenericInstantiationTests_OtherProgram__Generic_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.GenericFixtureBase), new PropertyInjectionSource_Generic_64877686()); + } +} + +internal sealed class PropertyInjectionSource_Generic_64877686 : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.GenericFixtureBase); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetPostgresBackingField(TUnit.TestProject.GenericFixtureBase instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Postgres", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.GenericFixtureBase), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.GenericFixtureBase)instance; +#if NET8_0_OR_GREATER + GetPostgresBackingField((TUnit.TestProject.GenericFixtureBase)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.GenericFixtureBase).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_IntermediateBase_TUnit_TestProject_DeepInheritanceGenericTests_DeepProgram__Generic_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.IntermediateBase), new PropertyInjectionSource_Generic_344bd53a()); + } +} + +internal sealed class PropertyInjectionSource_Generic_344bd53a : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.IntermediateBase); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetPostgresBackingField(TUnit.TestProject.GenericFixtureBase instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Postgres", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.GenericFixtureBase), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.IntermediateBase)instance; +#if NET8_0_OR_GREATER + GetPostgresBackingField((TUnit.TestProject.GenericFixtureBase)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.GenericFixtureBase).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_GenericFixtureBase_TUnit_TestProject_DeepInheritanceGenericTests_DeepProgram__Generic_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.GenericFixtureBase), new PropertyInjectionSource_Generic_48a5b53f()); + } +} + +internal sealed class PropertyInjectionSource_Generic_48a5b53f : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.GenericFixtureBase); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetPostgresBackingField(TUnit.TestProject.GenericFixtureBase instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Postgres", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.GenericFixtureBase), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.GenericFixtureBase)instance; +#if NET8_0_OR_GREATER + GetPostgresBackingField((TUnit.TestProject.GenericFixtureBase)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.GenericFixtureBase).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using TUnit.Core.Discovery; + +namespace TUnit.Generated; + +internal static class TUnit_TestProject_GenericInitializerFixture_TUnit_TestProject_GenericInitializerPropertyTests__Generic_InitializerPropertiesInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + InitializerPropertyRegistry.Register(typeof(global::TUnit.TestProject.GenericInitializerFixture), new InitializerPropertyInfo[] + { + new InitializerPropertyInfo + { + PropertyName = "Database", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + GetValue = static obj => ((global::TUnit.TestProject.GenericInitializerFixture)obj).Database + }, + }); + } +} diff --git a/TUnit.Core.SourceGenerator.Tests/GenericPropertyInjectionTests.Diagnostic_ShowGeneratedFiles.verified.txt b/TUnit.Core.SourceGenerator.Tests/GenericPropertyInjectionTests.Diagnostic_ShowGeneratedFiles.verified.txt new file mode 100644 index 0000000000..dbf061f85e --- /dev/null +++ b/TUnit.Core.SourceGenerator.Tests/GenericPropertyInjectionTests.Diagnostic_ShowGeneratedFiles.verified.txt @@ -0,0 +1,321 @@ +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_GenericInitializerPropertyTests_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.GenericInitializerPropertyTests), new PropertyInjectionSource_1a6cab1c()); + } +} + +internal sealed class PropertyInjectionSource_1a6cab1c : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.GenericInitializerPropertyTests); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.GenericInitializerFixture GetFixtureBackingField(TUnit.TestProject.GenericInitializerPropertyTests instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Fixture", + PropertyType = typeof(global::TUnit.TestProject.GenericInitializerFixture), + ContainingType = typeof(TUnit.TestProject.GenericInitializerPropertyTests), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute>(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.GenericInitializerPropertyTests)instance; +#if NET8_0_OR_GREATER + GetFixtureBackingField((TUnit.TestProject.GenericInitializerPropertyTests)typedInstance) = (global::TUnit.TestProject.GenericInitializerFixture)value; +#else + var backingField = typeof(TUnit.TestProject.GenericInitializerPropertyTests).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_GenericFixtureBase_TUnit_TestProject_GenericPropertyInjectionTests_TestProgram__Generic_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.GenericFixtureBase), new PropertyInjectionSource_Generic_1fe2b02e()); + } +} + +internal sealed class PropertyInjectionSource_Generic_1fe2b02e : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.GenericFixtureBase); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetPostgresBackingField(TUnit.TestProject.GenericFixtureBase instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Postgres", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.GenericFixtureBase), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.GenericFixtureBase)instance; +#if NET8_0_OR_GREATER + GetPostgresBackingField((TUnit.TestProject.GenericFixtureBase)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.GenericFixtureBase).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_GenericFixtureBase_TUnit_TestProject_MultipleGenericInstantiationTests_OtherProgram__Generic_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.GenericFixtureBase), new PropertyInjectionSource_Generic_3db19b9d()); + } +} + +internal sealed class PropertyInjectionSource_Generic_3db19b9d : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.GenericFixtureBase); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetPostgresBackingField(TUnit.TestProject.GenericFixtureBase instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Postgres", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.GenericFixtureBase), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.GenericFixtureBase)instance; +#if NET8_0_OR_GREATER + GetPostgresBackingField((TUnit.TestProject.GenericFixtureBase)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.GenericFixtureBase).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_IntermediateBase_TUnit_TestProject_DeepInheritanceGenericTests_DeepProgram__Generic_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.IntermediateBase), new PropertyInjectionSource_Generic_738479fe()); + } +} + +internal sealed class PropertyInjectionSource_Generic_738479fe : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.IntermediateBase); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetPostgresBackingField(TUnit.TestProject.GenericFixtureBase instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Postgres", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.GenericFixtureBase), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.IntermediateBase)instance; +#if NET8_0_OR_GREATER + GetPostgresBackingField((TUnit.TestProject.GenericFixtureBase)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.GenericFixtureBase).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_GenericFixtureBase_TUnit_TestProject_DeepInheritanceGenericTests_DeepProgram__Generic_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.GenericFixtureBase), new PropertyInjectionSource_Generic_112df024()); + } +} + +internal sealed class PropertyInjectionSource_Generic_112df024 : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.GenericFixtureBase); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetPostgresBackingField(TUnit.TestProject.GenericFixtureBase instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Postgres", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.GenericFixtureBase), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.GenericFixtureBase)instance; +#if NET8_0_OR_GREATER + GetPostgresBackingField((TUnit.TestProject.GenericFixtureBase)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.GenericFixtureBase).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using TUnit.Core.Discovery; + +namespace TUnit.Generated; + +internal static class TUnit_TestProject_GenericInitializerFixture_TUnit_TestProject_GenericInitializerPropertyTests__Generic_InitializerPropertiesInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + InitializerPropertyRegistry.Register(typeof(global::TUnit.TestProject.GenericInitializerFixture), new InitializerPropertyInfo[] + { + new InitializerPropertyInfo + { + PropertyName = "Database", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + GetValue = static obj => ((global::TUnit.TestProject.GenericInitializerFixture)obj).Database + }, + }); + } +} diff --git a/TUnit.Core.SourceGenerator.Tests/GenericPropertyInjectionTests.GenericBaseClass_WithDataSourceProperty_GeneratesMetadata.verified.txt b/TUnit.Core.SourceGenerator.Tests/GenericPropertyInjectionTests.GenericBaseClass_WithDataSourceProperty_GeneratesMetadata.verified.txt new file mode 100644 index 0000000000..5095c30023 --- /dev/null +++ b/TUnit.Core.SourceGenerator.Tests/GenericPropertyInjectionTests.GenericBaseClass_WithDataSourceProperty_GeneratesMetadata.verified.txt @@ -0,0 +1,1149 @@ +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_GenericInitializerPropertyTests_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.GenericInitializerPropertyTests), new PropertyInjectionSource_3cd38317()); + } +} + +internal sealed class PropertyInjectionSource_3cd38317 : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.GenericInitializerPropertyTests); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.GenericInitializerFixture GetFixtureBackingField(TUnit.TestProject.GenericInitializerPropertyTests instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Fixture", + PropertyType = typeof(global::TUnit.TestProject.GenericInitializerFixture), + ContainingType = typeof(TUnit.TestProject.GenericInitializerPropertyTests), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute>(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.GenericInitializerPropertyTests)instance; +#if NET8_0_OR_GREATER + GetFixtureBackingField((TUnit.TestProject.GenericInitializerPropertyTests)typedInstance) = (global::TUnit.TestProject.GenericInitializerFixture)value; +#else + var backingField = typeof(TUnit.TestProject.GenericInitializerPropertyTests).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_MixedGenericAndDerivedPropertiesTests_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.MixedGenericAndDerivedPropertiesTests), new PropertyInjectionSource_4017f480()); + } +} + +internal sealed class PropertyInjectionSource_4017f480 : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.MixedGenericAndDerivedPropertiesTests); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.SecondaryDatabase GetDerivedDatabaseBackingField(TUnit.TestProject.MixedGenericAndDerivedPropertiesTests instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "DerivedDatabase", + PropertyType = typeof(global::TUnit.TestProject.SecondaryDatabase), + ContainingType = typeof(TUnit.TestProject.MixedGenericAndDerivedPropertiesTests), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.MixedGenericAndDerivedPropertiesTests)instance; +#if NET8_0_OR_GREATER + GetDerivedDatabaseBackingField((TUnit.TestProject.MixedGenericAndDerivedPropertiesTests)typedInstance) = (global::TUnit.TestProject.SecondaryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.MixedGenericAndDerivedPropertiesTests).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_GenericInitializerWithNestedPropertyTests_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.GenericInitializerWithNestedPropertyTests), new PropertyInjectionSource_e5cd3ee()); + } +} + +internal sealed class PropertyInjectionSource_e5cd3ee : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.GenericInitializerWithNestedPropertyTests); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.GenericInitializerFixture GetFixtureBackingField(TUnit.TestProject.GenericInitializerWithNestedPropertyTests instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Fixture", + PropertyType = typeof(global::TUnit.TestProject.GenericInitializerFixture), + ContainingType = typeof(TUnit.TestProject.GenericInitializerWithNestedPropertyTests), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute>(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.GenericInitializerWithNestedPropertyTests)instance; +#if NET8_0_OR_GREATER + GetFixtureBackingField((TUnit.TestProject.GenericInitializerWithNestedPropertyTests)typedInstance) = (global::TUnit.TestProject.GenericInitializerFixture)value; +#else + var backingField = typeof(TUnit.TestProject.GenericInitializerWithNestedPropertyTests).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_Issue4431_WebApplicationFactoryScenarioTests_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.Issue4431_WebApplicationFactoryScenarioTests), new PropertyInjectionSource_686a4b57()); + } +} + +internal sealed class PropertyInjectionSource_686a4b57 : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.Issue4431_WebApplicationFactoryScenarioTests); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.CustomWebApplicationFactory GetFactoryBackingField(TUnit.TestProject.Issue4431_WebApplicationFactoryScenarioTests instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Factory", + PropertyType = typeof(global::TUnit.TestProject.CustomWebApplicationFactory), + ContainingType = typeof(TUnit.TestProject.Issue4431_WebApplicationFactoryScenarioTests), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute>(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.Issue4431_WebApplicationFactoryScenarioTests)instance; +#if NET8_0_OR_GREATER + GetFactoryBackingField((TUnit.TestProject.Issue4431_WebApplicationFactoryScenarioTests)typedInstance) = (global::TUnit.TestProject.CustomWebApplicationFactory)value; +#else + var backingField = typeof(TUnit.TestProject.Issue4431_WebApplicationFactoryScenarioTests).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_Issue4431_ParentTestScenario_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.Issue4431_ParentTestScenario), new PropertyInjectionSource_2e994dce()); + } +} + +internal sealed class PropertyInjectionSource_2e994dce : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.Issue4431_ParentTestScenario); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetPostgresBackingField(TUnit.TestProject.Issue4431_ParentTestScenario instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Postgres", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.Issue4431_ParentTestScenario), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.Issue4431_ParentTestScenario)instance; +#if NET8_0_OR_GREATER + GetPostgresBackingField((TUnit.TestProject.Issue4431_ParentTestScenario)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.Issue4431_ParentTestScenario).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_GenericFixtureBase_TUnit_TestProject_GenericPropertyInjectionTests_TestProgram__Generic_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.GenericFixtureBase), new PropertyInjectionSource_Generic_326cb647()); + } +} + +internal sealed class PropertyInjectionSource_Generic_326cb647 : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.GenericFixtureBase); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetPostgresBackingField(TUnit.TestProject.GenericFixtureBase instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Postgres", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.GenericFixtureBase), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.GenericFixtureBase)instance; +#if NET8_0_OR_GREATER + GetPostgresBackingField((TUnit.TestProject.GenericFixtureBase)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.GenericFixtureBase).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_GenericFixtureBase_TUnit_TestProject_MultipleGenericInstantiationTests_OtherProgram__Generic_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.GenericFixtureBase), new PropertyInjectionSource_Generic_548e1200()); + } +} + +internal sealed class PropertyInjectionSource_Generic_548e1200 : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.GenericFixtureBase); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetPostgresBackingField(TUnit.TestProject.GenericFixtureBase instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Postgres", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.GenericFixtureBase), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.GenericFixtureBase)instance; +#if NET8_0_OR_GREATER + GetPostgresBackingField((TUnit.TestProject.GenericFixtureBase)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.GenericFixtureBase).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_IntermediateBase_TUnit_TestProject_DeepInheritanceGenericTests_DeepProgram__Generic_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.IntermediateBase), new PropertyInjectionSource_Generic_55f0de4()); + } +} + +internal sealed class PropertyInjectionSource_Generic_55f0de4 : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.IntermediateBase); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetPostgresBackingField(TUnit.TestProject.GenericFixtureBase instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Postgres", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.GenericFixtureBase), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.IntermediateBase)instance; +#if NET8_0_OR_GREATER + GetPostgresBackingField((TUnit.TestProject.GenericFixtureBase)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.GenericFixtureBase).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_GenericFixtureBase_TUnit_TestProject_DeepInheritanceGenericTests_DeepProgram__Generic_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.GenericFixtureBase), new PropertyInjectionSource_Generic_551b4117()); + } +} + +internal sealed class PropertyInjectionSource_Generic_551b4117 : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.GenericFixtureBase); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetPostgresBackingField(TUnit.TestProject.GenericFixtureBase instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Postgres", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.GenericFixtureBase), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.GenericFixtureBase)instance; +#if NET8_0_OR_GREATER + GetPostgresBackingField((TUnit.TestProject.GenericFixtureBase)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.GenericFixtureBase).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using TUnit.Core.Discovery; + +namespace TUnit.Generated; + +internal static class TUnit_TestProject_GenericInitializerFixture_TUnit_TestProject_GenericInitializerPropertyTests__Generic_InitializerPropertiesInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + InitializerPropertyRegistry.Register(typeof(global::TUnit.TestProject.GenericInitializerFixture), new InitializerPropertyInfo[] + { + new InitializerPropertyInfo + { + PropertyName = "Database", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + GetValue = static obj => ((global::TUnit.TestProject.GenericInitializerFixture)obj).Database + }, + }); + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_MultiPropertyGenericBase_TUnit_TestProject_MultiplePropertiesGenericTests_TestProgram__Generic_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.MultiPropertyGenericBase), new PropertyInjectionSource_Generic_467f7427()); + } +} + +internal sealed class PropertyInjectionSource_Generic_467f7427 : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.MultiPropertyGenericBase); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetFirstDbBackingField(TUnit.TestProject.MultiPropertyGenericBase instance); +#endif + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.SecondaryDatabase GetSecondDbBackingField(TUnit.TestProject.MultiPropertyGenericBase instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "FirstDb", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.MultiPropertyGenericBase), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.MultiPropertyGenericBase)instance; +#if NET8_0_OR_GREATER + GetFirstDbBackingField((TUnit.TestProject.MultiPropertyGenericBase)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.MultiPropertyGenericBase).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + yield return new PropertyInjectionMetadata + { + PropertyName = "SecondDb", + PropertyType = typeof(global::TUnit.TestProject.SecondaryDatabase), + ContainingType = typeof(TUnit.TestProject.MultiPropertyGenericBase), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.MultiPropertyGenericBase)instance; +#if NET8_0_OR_GREATER + GetSecondDbBackingField((TUnit.TestProject.MultiPropertyGenericBase)typedInstance) = (global::TUnit.TestProject.SecondaryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.MultiPropertyGenericBase).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_MultiTypeParamBase_TUnit_TestProject_MultiTypeParameterTests_Program1_TUnit_TestProject_MultiTypeParameterTests_Program2__Generic_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.MultiTypeParamBase), new PropertyInjectionSource_Generic_2513d22()); + } +} + +internal sealed class PropertyInjectionSource_Generic_2513d22 : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.MultiTypeParamBase); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetDatabaseBackingField(TUnit.TestProject.MultiTypeParamBase instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Database", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.MultiTypeParamBase), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.MultiTypeParamBase)instance; +#if NET8_0_OR_GREATER + GetDatabaseBackingField((TUnit.TestProject.MultiTypeParamBase)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.MultiTypeParamBase).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_ParentBase_TUnit_TestProject_DeepInheritanceMultiLevelPropertyTests_TestProgram__Generic_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.ParentBase), new PropertyInjectionSource_Generic_2bdc3e0a()); + } +} + +internal sealed class PropertyInjectionSource_Generic_2bdc3e0a : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.ParentBase); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.SecondaryDatabase GetParentDbBackingField(TUnit.TestProject.ParentBase instance); +#endif + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetGrandparentDbBackingField(TUnit.TestProject.GrandparentBase instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "ParentDb", + PropertyType = typeof(global::TUnit.TestProject.SecondaryDatabase), + ContainingType = typeof(TUnit.TestProject.ParentBase), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.ParentBase)instance; +#if NET8_0_OR_GREATER + GetParentDbBackingField((TUnit.TestProject.ParentBase)typedInstance) = (global::TUnit.TestProject.SecondaryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.ParentBase).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + yield return new PropertyInjectionMetadata + { + PropertyName = "GrandparentDb", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.GrandparentBase), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.ParentBase)instance; +#if NET8_0_OR_GREATER + GetGrandparentDbBackingField((TUnit.TestProject.GrandparentBase)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.GrandparentBase).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_GrandparentBase_TUnit_TestProject_DeepInheritanceMultiLevelPropertyTests_TestProgram__Generic_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.GrandparentBase), new PropertyInjectionSource_Generic_72e68a44()); + } +} + +internal sealed class PropertyInjectionSource_Generic_72e68a44 : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.GrandparentBase); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetGrandparentDbBackingField(TUnit.TestProject.GrandparentBase instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "GrandparentDb", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.GrandparentBase), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.GrandparentBase)instance; +#if NET8_0_OR_GREATER + GetGrandparentDbBackingField((TUnit.TestProject.GrandparentBase)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.GrandparentBase).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_GenericFixtureBase_TUnit_TestProject_MixedGenericAndDerivedPropertiesTests_TestProgram__Generic_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.GenericFixtureBase), new PropertyInjectionSource_Generic_23bcede5()); + } +} + +internal sealed class PropertyInjectionSource_Generic_23bcede5 : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.GenericFixtureBase); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetPostgresBackingField(TUnit.TestProject.GenericFixtureBase instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Postgres", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.GenericFixtureBase), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.GenericFixtureBase)instance; +#if NET8_0_OR_GREATER + GetPostgresBackingField((TUnit.TestProject.GenericFixtureBase)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.GenericFixtureBase).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_GenericFixtureBase_System_Collections_Generic_List_string___Generic_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.GenericFixtureBase>), new PropertyInjectionSource_Generic_48d518d8()); + } +} + +internal sealed class PropertyInjectionSource_Generic_48d518d8 : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.GenericFixtureBase>); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetPostgresBackingField(TUnit.TestProject.GenericFixtureBase> instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Postgres", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.GenericFixtureBase>), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.GenericFixtureBase>)instance; +#if NET8_0_OR_GREATER + GetPostgresBackingField((TUnit.TestProject.GenericFixtureBase>)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.GenericFixtureBase>).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using TUnit.Core.Discovery; + +namespace TUnit.Generated; + +internal static class TUnit_TestProject_GenericInitializerFixture_TUnit_TestProject_GenericInitializerWithNestedPropertyTests__Generic_InitializerPropertiesInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + InitializerPropertyRegistry.Register(typeof(global::TUnit.TestProject.GenericInitializerFixture), new InitializerPropertyInfo[] + { + new InitializerPropertyInfo + { + PropertyName = "Database", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + GetValue = static obj => ((global::TUnit.TestProject.GenericInitializerFixture)obj).Database + }, + }); + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_CustomWebApplicationFactory_TUnit_TestProject_Issue4431_WebApplicationFactoryScenarioTests_TestProgram__Generic_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.CustomWebApplicationFactory), new PropertyInjectionSource_Generic_39565e8e()); + } +} + +internal sealed class PropertyInjectionSource_Generic_39565e8e : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.CustomWebApplicationFactory); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetTestDatabaseBackingField(TUnit.TestProject.CustomWebApplicationFactory instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "TestDatabase", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.CustomWebApplicationFactory), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.CustomWebApplicationFactory)instance; +#if NET8_0_OR_GREATER + GetTestDatabaseBackingField((TUnit.TestProject.CustomWebApplicationFactory)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.CustomWebApplicationFactory).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using TUnit.Core.Discovery; + +namespace TUnit.Generated; + +internal static class TUnit_TestProject_CustomWebApplicationFactory_TUnit_TestProject_Issue4431_WebApplicationFactoryScenarioTests_TestProgram__Generic_InitializerPropertiesInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + InitializerPropertyRegistry.Register(typeof(global::TUnit.TestProject.CustomWebApplicationFactory), new InitializerPropertyInfo[] + { + new InitializerPropertyInfo + { + PropertyName = "TestDatabase", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + GetValue = static obj => ((global::TUnit.TestProject.CustomWebApplicationFactory)obj).TestDatabase + }, + }); + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_WebAppFactoryBase_TUnit_TestProject_CustomWebApplicationFactory_TUnit_TestProject_Issue4431_ComplexGenericInheritanceTests_MyProgram__TUnit_TestProject_Issue4431_ComplexGenericInheritanceTests_MyProgram__Generic_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.WebAppFactoryBase, global::TUnit.TestProject.Issue4431_ComplexGenericInheritanceTests.MyProgram>), new PropertyInjectionSource_Generic_3c089123()); + } +} + +internal sealed class PropertyInjectionSource_Generic_3c089123 : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.WebAppFactoryBase, global::TUnit.TestProject.Issue4431_ComplexGenericInheritanceTests.MyProgram>); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetSharedDatabaseBackingField(TUnit.TestProject.WebAppFactoryBase, TUnit.TestProject.Issue4431_ComplexGenericInheritanceTests.MyProgram> instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "SharedDatabase", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.WebAppFactoryBase, TUnit.TestProject.Issue4431_ComplexGenericInheritanceTests.MyProgram>), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.WebAppFactoryBase, global::TUnit.TestProject.Issue4431_ComplexGenericInheritanceTests.MyProgram>)instance; +#if NET8_0_OR_GREATER + GetSharedDatabaseBackingField((TUnit.TestProject.WebAppFactoryBase, TUnit.TestProject.Issue4431_ComplexGenericInheritanceTests.MyProgram>)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.WebAppFactoryBase, TUnit.TestProject.Issue4431_ComplexGenericInheritanceTests.MyProgram>).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} diff --git a/TUnit.Core.SourceGenerator.Tests/GenericPropertyInjectionTests.GenericClassDataSource_WithInitializerProperties_GeneratesMetadata.verified.txt b/TUnit.Core.SourceGenerator.Tests/GenericPropertyInjectionTests.GenericClassDataSource_WithInitializerProperties_GeneratesMetadata.verified.txt new file mode 100644 index 0000000000..7b28dd257e --- /dev/null +++ b/TUnit.Core.SourceGenerator.Tests/GenericPropertyInjectionTests.GenericClassDataSource_WithInitializerProperties_GeneratesMetadata.verified.txt @@ -0,0 +1,321 @@ +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_GenericInitializerPropertyTests_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.GenericInitializerPropertyTests), new PropertyInjectionSource_61ab58e()); + } +} + +internal sealed class PropertyInjectionSource_61ab58e : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.GenericInitializerPropertyTests); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.GenericInitializerFixture GetFixtureBackingField(TUnit.TestProject.GenericInitializerPropertyTests instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Fixture", + PropertyType = typeof(global::TUnit.TestProject.GenericInitializerFixture), + ContainingType = typeof(TUnit.TestProject.GenericInitializerPropertyTests), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute>(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.GenericInitializerPropertyTests)instance; +#if NET8_0_OR_GREATER + GetFixtureBackingField((TUnit.TestProject.GenericInitializerPropertyTests)typedInstance) = (global::TUnit.TestProject.GenericInitializerFixture)value; +#else + var backingField = typeof(TUnit.TestProject.GenericInitializerPropertyTests).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_GenericFixtureBase_TUnit_TestProject_GenericPropertyInjectionTests_TestProgram__Generic_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.GenericFixtureBase), new PropertyInjectionSource_Generic_7a6c8287()); + } +} + +internal sealed class PropertyInjectionSource_Generic_7a6c8287 : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.GenericFixtureBase); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetPostgresBackingField(TUnit.TestProject.GenericFixtureBase instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Postgres", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.GenericFixtureBase), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.GenericFixtureBase)instance; +#if NET8_0_OR_GREATER + GetPostgresBackingField((TUnit.TestProject.GenericFixtureBase)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.GenericFixtureBase).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_GenericFixtureBase_TUnit_TestProject_MultipleGenericInstantiationTests_OtherProgram__Generic_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.GenericFixtureBase), new PropertyInjectionSource_Generic_64877686()); + } +} + +internal sealed class PropertyInjectionSource_Generic_64877686 : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.GenericFixtureBase); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetPostgresBackingField(TUnit.TestProject.GenericFixtureBase instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Postgres", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.GenericFixtureBase), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.GenericFixtureBase)instance; +#if NET8_0_OR_GREATER + GetPostgresBackingField((TUnit.TestProject.GenericFixtureBase)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.GenericFixtureBase).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_IntermediateBase_TUnit_TestProject_DeepInheritanceGenericTests_DeepProgram__Generic_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.IntermediateBase), new PropertyInjectionSource_Generic_344bd53a()); + } +} + +internal sealed class PropertyInjectionSource_Generic_344bd53a : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.IntermediateBase); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetPostgresBackingField(TUnit.TestProject.GenericFixtureBase instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Postgres", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.GenericFixtureBase), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.IntermediateBase)instance; +#if NET8_0_OR_GREATER + GetPostgresBackingField((TUnit.TestProject.GenericFixtureBase)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.GenericFixtureBase).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_GenericFixtureBase_TUnit_TestProject_DeepInheritanceGenericTests_DeepProgram__Generic_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.GenericFixtureBase), new PropertyInjectionSource_Generic_48a5b53f()); + } +} + +internal sealed class PropertyInjectionSource_Generic_48a5b53f : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.GenericFixtureBase); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetPostgresBackingField(TUnit.TestProject.GenericFixtureBase instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Postgres", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.GenericFixtureBase), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.GenericFixtureBase)instance; +#if NET8_0_OR_GREATER + GetPostgresBackingField((TUnit.TestProject.GenericFixtureBase)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.GenericFixtureBase).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using TUnit.Core.Discovery; + +namespace TUnit.Generated; + +internal static class TUnit_TestProject_GenericInitializerFixture_TUnit_TestProject_GenericInitializerPropertyTests__Generic_InitializerPropertiesInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + InitializerPropertyRegistry.Register(typeof(global::TUnit.TestProject.GenericInitializerFixture), new InitializerPropertyInfo[] + { + new InitializerPropertyInfo + { + PropertyName = "Database", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + GetValue = static obj => ((global::TUnit.TestProject.GenericInitializerFixture)obj).Database + }, + }); + } +} diff --git a/TUnit.Core.SourceGenerator.Tests/GenericPropertyInjectionTests.MultipleInstantiations_EachGenerateMetadata.verified.txt b/TUnit.Core.SourceGenerator.Tests/GenericPropertyInjectionTests.MultipleInstantiations_EachGenerateMetadata.verified.txt new file mode 100644 index 0000000000..7b28dd257e --- /dev/null +++ b/TUnit.Core.SourceGenerator.Tests/GenericPropertyInjectionTests.MultipleInstantiations_EachGenerateMetadata.verified.txt @@ -0,0 +1,321 @@ +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_GenericInitializerPropertyTests_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.GenericInitializerPropertyTests), new PropertyInjectionSource_61ab58e()); + } +} + +internal sealed class PropertyInjectionSource_61ab58e : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.GenericInitializerPropertyTests); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.GenericInitializerFixture GetFixtureBackingField(TUnit.TestProject.GenericInitializerPropertyTests instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Fixture", + PropertyType = typeof(global::TUnit.TestProject.GenericInitializerFixture), + ContainingType = typeof(TUnit.TestProject.GenericInitializerPropertyTests), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute>(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.GenericInitializerPropertyTests)instance; +#if NET8_0_OR_GREATER + GetFixtureBackingField((TUnit.TestProject.GenericInitializerPropertyTests)typedInstance) = (global::TUnit.TestProject.GenericInitializerFixture)value; +#else + var backingField = typeof(TUnit.TestProject.GenericInitializerPropertyTests).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_GenericFixtureBase_TUnit_TestProject_GenericPropertyInjectionTests_TestProgram__Generic_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.GenericFixtureBase), new PropertyInjectionSource_Generic_7a6c8287()); + } +} + +internal sealed class PropertyInjectionSource_Generic_7a6c8287 : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.GenericFixtureBase); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetPostgresBackingField(TUnit.TestProject.GenericFixtureBase instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Postgres", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.GenericFixtureBase), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.GenericFixtureBase)instance; +#if NET8_0_OR_GREATER + GetPostgresBackingField((TUnit.TestProject.GenericFixtureBase)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.GenericFixtureBase).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_GenericFixtureBase_TUnit_TestProject_MultipleGenericInstantiationTests_OtherProgram__Generic_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.GenericFixtureBase), new PropertyInjectionSource_Generic_64877686()); + } +} + +internal sealed class PropertyInjectionSource_Generic_64877686 : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.GenericFixtureBase); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetPostgresBackingField(TUnit.TestProject.GenericFixtureBase instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Postgres", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.GenericFixtureBase), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.GenericFixtureBase)instance; +#if NET8_0_OR_GREATER + GetPostgresBackingField((TUnit.TestProject.GenericFixtureBase)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.GenericFixtureBase).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_IntermediateBase_TUnit_TestProject_DeepInheritanceGenericTests_DeepProgram__Generic_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.IntermediateBase), new PropertyInjectionSource_Generic_344bd53a()); + } +} + +internal sealed class PropertyInjectionSource_Generic_344bd53a : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.IntermediateBase); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetPostgresBackingField(TUnit.TestProject.GenericFixtureBase instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Postgres", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.GenericFixtureBase), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.IntermediateBase)instance; +#if NET8_0_OR_GREATER + GetPostgresBackingField((TUnit.TestProject.GenericFixtureBase)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.GenericFixtureBase).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using System.Collections.Generic; +using TUnit.Core; +using TUnit.Core.Interfaces.SourceGenerator; +using TUnit.Core.Enums; +using System.Linq; + +namespace TUnit.Core; + +internal static class TUnit_TestProject_GenericFixtureBase_TUnit_TestProject_DeepInheritanceGenericTests_DeepProgram__Generic_PropertyInjectionInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::TUnit.Core.PropertySourceRegistry.Register(typeof(global::TUnit.TestProject.GenericFixtureBase), new PropertyInjectionSource_Generic_48a5b53f()); + } +} + +internal sealed class PropertyInjectionSource_Generic_48a5b53f : IPropertySource +{ + public Type Type => typeof(global::TUnit.TestProject.GenericFixtureBase); + public bool ShouldInitialize => true; + +#if NET8_0_OR_GREATER + [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "k__BackingField")] + private static extern ref global::TUnit.TestProject.InMemoryDatabase GetPostgresBackingField(TUnit.TestProject.GenericFixtureBase instance); +#endif + + public IEnumerable GetPropertyMetadata() + { + yield return new PropertyInjectionMetadata + { + PropertyName = "Postgres", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + ContainingType = typeof(TUnit.TestProject.GenericFixtureBase), + CreateDataSource = () => + { + var dataSource = new TUnit.Core.ClassDataSourceAttribute(); + dataSource.Shared = (TUnit.Core.SharedType)3; + return dataSource; + }, + SetProperty = (instance, value) => + { + var typedInstance = (global::TUnit.TestProject.GenericFixtureBase)instance; +#if NET8_0_OR_GREATER + GetPostgresBackingField((TUnit.TestProject.GenericFixtureBase)typedInstance) = (global::TUnit.TestProject.InMemoryDatabase)value; +#else + var backingField = typeof(TUnit.TestProject.GenericFixtureBase).GetField("k__BackingField", + global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic); + backingField.SetValue(typedInstance, value); +#endif + } + }; + + } +} + + +// ===== FILE SEPARATOR ===== + +using System; +using TUnit.Core.Discovery; + +namespace TUnit.Generated; + +internal static class TUnit_TestProject_GenericInitializerFixture_TUnit_TestProject_GenericInitializerPropertyTests__Generic_InitializerPropertiesInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + InitializerPropertyRegistry.Register(typeof(global::TUnit.TestProject.GenericInitializerFixture), new InitializerPropertyInfo[] + { + new InitializerPropertyInfo + { + PropertyName = "Database", + PropertyType = typeof(global::TUnit.TestProject.InMemoryDatabase), + GetValue = static obj => ((global::TUnit.TestProject.GenericInitializerFixture)obj).Database + }, + }); + } +} diff --git a/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs b/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs index 627876749e..319410a9c1 100644 --- a/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs +++ b/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs @@ -1537,15 +1537,11 @@ private static void GeneratePropertyInjections(CodeWriter writer, INamedTypeSymb if (isGenericContainingType) { - // For generic types, use reflection-based setter - writer.AppendLine($"Setter = (instance, value) =>"); - writer.AppendLine("{"); - writer.Indent(); - writer.AppendLine($"var backingField = instance.GetType().GetField(\"<{property.Name}>k__BackingField\","); - writer.AppendLine(" global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic);"); - writer.AppendLine($"backingField?.SetValue(instance, ({propertyType})value);"); - writer.Unindent(); - writer.AppendLine("},"); + // For generic types, init-only properties with data sources are not supported + // UnsafeAccessor doesn't work with open generic types and reflection is not AOT-compatible + writer.AppendLine($"Setter = (instance, value) => throw new global::System.NotSupportedException("); + writer.AppendLine($" \"Init-only property '{property.Name}' on generic type '{containingTypeName}' cannot be set. \" +"); + writer.AppendLine($" \"Use a regular settable property or constructor injection instead.\"),"); } else {