Skip to content

Commit

Permalink
NonTypedDataSourceGeneratorAttribute (#1555)
Browse files Browse the repository at this point in the history
* NonTypedDataSourceGeneratorAttribute

* Verify
  • Loading branch information
thomhurst authored Jan 14, 2025
1 parent 6b5fce8 commit e254bb7
Show file tree
Hide file tree
Showing 12 changed files with 1,026 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
[
// <auto-generated/>
#pragma warning disable
using global::System.Linq;
using global::System.Reflection;
using global::TUnit.Core;
using global::TUnit.Core.Extensions;

namespace TUnit.SourceGenerated;

[global::System.Diagnostics.StackTraceHidden]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
file partial class AutoDataTests : TUnit.Core.Interfaces.SourceGenerator.ITestSource
{
[global::System.Runtime.CompilerServices.ModuleInitializer]
public static void Initialise()
{
SourceRegistrar.Register(new AutoDataTests());
}
public global::System.Collections.Generic.IReadOnlyList<SourceGeneratedTestNode> CollectTests(string sessionId)
{
return Tests0(sessionId);
}
private global::System.Collections.Generic.List<SourceGeneratedTestNode> Tests0(string sessionId)
{
global::System.Collections.Generic.List<SourceGeneratedTestNode> nodes = [];
var classDataIndex = 0;
var testMethodDataIndex = 0;
try
{
var testClassType = typeof(global::TUnit.TestProject.AutoDataTests);
var methodInfo = global::TUnit.Core.Helpers.MethodInfoRetriever.GetMethodInfo(typeof(global::TUnit.TestProject.AutoDataTests), "Test1", 0, [typeof(global::System.String), typeof(global::System.Int32), typeof(global::System.Double), typeof(global::System.Boolean)]);

var testBuilderContext = new global::TUnit.Core.TestBuilderContext();
var testBuilderContextAccessor = new global::TUnit.Core.TestBuilderContextAccessor(testBuilderContext);
var methodArgDataGeneratorMetadata = new DataGeneratorMetadata
{
Type = TUnit.Core.Enums.DataGeneratorType.Parameters,
TestClassType = testClassType,
ParameterInfos = methodInfo.GetParameters(),
PropertyInfo = null,
TestBuilderContext = testBuilderContextAccessor,
TestSessionId = sessionId,
};
var methodDataAttribute = new global::TUnit.TestProject.Attributes.AutoDataAttribute()
{

};

var methodArgGeneratedDataArray = methodDataAttribute.GenerateDataSources(methodArgDataGeneratorMetadata);

foreach (var methodArgGeneratedDataAccessor in methodArgGeneratedDataArray)
{
testMethodDataIndex++;

var methodArgGeneratedData = methodArgGeneratedDataAccessor();
global::System.String methodArg = (global::System.String)methodArgGeneratedData[0];
global::System.Int32 methodArg1 = (global::System.Int32)methodArgGeneratedData[1];
global::System.Double methodArg2 = (global::System.Double)methodArgGeneratedData[2];
global::System.Boolean methodArg3 = (global::System.Boolean)methodArgGeneratedData[3];
var resettableClassFactoryDelegate = () => new ResettableLazy<global::TUnit.TestProject.AutoDataTests>(() =>
new global::TUnit.TestProject.AutoDataTests()
, sessionId, testBuilderContext);

var resettableClassFactory = resettableClassFactoryDelegate();

nodes.Add(new TestMetadata<global::TUnit.TestProject.AutoDataTests>
{
TestId = $"global::TUnit.TestProject.Attributes.AutoDataAttribute:{testMethodDataIndex}:TL-GAC0:TUnit.TestProject.AutoDataTests.Test1(System.String,System.Int32,System.Double,System.Boolean):0",
TestClassArguments = [],
TestMethodArguments = [methodArg, methodArg1, methodArg2, methodArg3],
TestClassProperties = [],
CurrentRepeatAttempt = 0,
RepeatLimit = 0,
MethodInfo = methodInfo,
ResettableClassFactory = resettableClassFactory,
TestMethodFactory = (classInstance, cancellationToken) => AsyncConvert.Convert(() => classInstance.Test1(methodArg, methodArg1, methodArg2, methodArg3)),
TestFilePath = @"",
TestLineNumber = 8,
TestAttributes = [ new global::TUnit.TestProject.Attributes.AutoDataAttribute()
{

}, new global::TUnit.Core.TestAttribute()
{

} ],
ClassAttributes = [ ],
AssemblyAttributes = [ ],
DataAttributes = [ methodDataAttribute ],
TestBuilderContext = testBuilderContext,
});
resettableClassFactory = resettableClassFactoryDelegate();
testBuilderContext = new();
testBuilderContextAccessor.Current = testBuilderContext;
}
}
catch (global::System.Exception exception)
{
nodes.Add(new FailedInitializationTest
{
TestId = $"global::TUnit.TestProject.Attributes.AutoDataAttribute:{testMethodDataIndex}:TL-GAC0:TUnit.TestProject.AutoDataTests.Test1(System.String,System.Int32,System.Double,System.Boolean):0",
TestClass = typeof(global::TUnit.TestProject.AutoDataTests),
ReturnType = global::TUnit.Core.Helpers.MethodInfoRetriever.GetMethodInfo(typeof(global::TUnit.TestProject.AutoDataTests), "Test1", 0, [typeof(global::System.String), typeof(global::System.Int32), typeof(global::System.Double), typeof(global::System.Boolean)]).ReturnType,
ParameterTypeFullNames = [typeof(global::System.String), typeof(global::System.Int32), typeof(global::System.Double), typeof(global::System.Boolean)],
TestName = "Test1",
TestFilePath = @"",
TestLineNumber = 8,
Exception = exception,
});
}
return nodes;
}
}

]
Loading

0 comments on commit e254bb7

Please sign in to comment.