Skip to content

Commit e784392

Browse files
authored
fix(sourcegen): generate a data source factory for [InstanceMethodDataSource] (#7225) (#7348)
* fix(sourcegen): generate a data source factory for [InstanceMethodDataSource] (#7225) [InstanceMethodDataSource] went through the generic attribute writer and got no Factory, so Native AOT fell back to a reflection member lookup that found no trimmed field metadata. Route it through GenerateMethodDataSourceAttribute and keep the declared attribute type so the engine still sees IAccessesInstanceData. * fix(sourcegen): keep runtime row expansion and private methods for [InstanceMethodDataSource] (#7225) - An object-typed property or method named by [InstanceMethodDataSource] decides its rows from the runtime value, as the attribute's reflection lookup did before it had a generated factory. - A parameterless private or protected data source method is read through a constant-name typeof(T).GetMethod lookup that Native AOT keeps, like private fields and properties, instead of a direct call the generated class cannot compile. - Share the InstanceMethodDataSourceAttribute name as a constant. * fix(sourcegen): skip generic overloads and keep null as an empty source for [InstanceMethodDataSource] (#7225) A private parameterless data source method beside a parameterless generic overload of the same name made the generated GetMethod lookup ambiguous; the factory now filters out generic method definitions instead. A null value from an [InstanceMethodDataSource] member became one null row, so SkipIfEmpty no longer skipped the test as the reflection path does. The generated factory now reads null as an empty source. * fix(core): read a null Task or IAsyncEnumerable data source as empty (#7225) FromTask and FromAsyncEnumerable (and their instance variants) awaited or enumerated a null value and threw. The attribute's reflection path reads a null source as one with no rows, so [InstanceMethodDataSource(..., SkipIfEmpty = true)] on such a member now skips in source-gen mode as it does in reflection mode. * fix(sourcegen): leave a void [InstanceMethodDataSource] method to the reflection fallback (#7225) TUnit0011 only analyzes [MethodDataSource], so a void method named by [InstanceMethodDataSource] reached the generated factory and failed with CS0030. * fix(sourcegen): rebuild a single System.Tuple parameter from unwrapped row elements (#7225) Generated data source factories unwrap a reference Tuple row into its elements, as they do a value tuple, but the generated invoker only rebuilt value tuples, so a test taking one Tuple<...> parameter failed with 'Expected exactly 1 argument'. Reflection mode keeps the row whole. This affected [MethodDataSource] already and [InstanceMethodDataSource] once it got a generated factory. * fix(sourcegen): fall through to the argument-count switch for a single System.Tuple parameter (#7225) Only rebuild the tuple when the row was unwrapped into its elements. A null argument, a whole tuple, and an omitted optional parameter keep the ordinary single-argument handling, as before the reference-tuple branch existed. Also move IsReferenceTuple above FormatSingleArgumentCall's doc comment and parenthesize the null-as-empty pattern. * fix(core): keep a tuple row whole for a single tuple parameter of [InstanceMethodDataSource] (#7225) A one-element System.Tuple row holding null, such as Tuple.Create<string?>(null), was split into [null] by the generated factory, so the test got a null tuple. Reflection mode keeps the row whole when the test takes a single tuple. The FromInstance* helpers and new From*(DataGeneratorMetadata, ...) overloads now read the parameter types from the metadata and do the same; [InstanceMethodDataSource] passes the metadata to its static helpers. * fix(sourcegen): preserve non-generic task source factories (#7225) * refactor(sourcegen): build complete reflection reads for #7225
1 parent a412ddd commit e784392

12 files changed

Lines changed: 1721 additions & 149 deletions

‎src/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs‎

Lines changed: 129 additions & 30 deletions
Large diffs are not rendered by default.

‎src/TUnit.Core/Helpers/DataSourceFactories.cs‎

Lines changed: 150 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -33,80 +33,119 @@ namespace TUnit.Core.Helpers;
3333
#endif
3434
public static class DataSourceFactories
3535
{
36-
#pragma warning disable CS1998 // sync-only async iterators: deferred invocation, no await by design
3736
/// <summary>Data member declared as a single (non-enumerable, non-task) value.</summary>
38-
public static async IAsyncEnumerable<Func<Task<object?[]?>>> FromValue(Func<object?> invoke)
37+
public static IAsyncEnumerable<Func<Task<object?[]?>>> FromValue(Func<object?> invoke)
38+
=> FromValueCore(invoke, keepTupleRowsWhole: false);
39+
40+
/// <summary>
41+
/// <see cref="FromValue(Func{object?})"/> that keeps a tuple row whole when the test takes a single tuple,
42+
/// as the attribute's reflection path does.
43+
/// </summary>
44+
public static IAsyncEnumerable<Func<Task<object?[]?>>> FromValue(DataGeneratorMetadata dataGeneratorMetadata, Func<object?> invoke)
45+
=> FromValueCore(invoke, KeepsTupleRowsWhole(dataGeneratorMetadata));
46+
47+
/// <summary>Data member declared as a synchronous enumerable.</summary>
48+
public static IAsyncEnumerable<Func<Task<object?[]?>>> FromEnumerable(Func<object?> invoke)
49+
=> FromEnumerableCore(invoke, keepTupleRowsWhole: false);
50+
51+
/// <summary>
52+
/// <see cref="FromEnumerable(Func{object?})"/> that keeps a tuple row whole when the test takes a single tuple,
53+
/// as the attribute's reflection path does.
54+
/// </summary>
55+
public static IAsyncEnumerable<Func<Task<object?[]?>>> FromEnumerable(DataGeneratorMetadata dataGeneratorMetadata, Func<object?> invoke)
56+
=> FromEnumerableCore(invoke, KeepsTupleRowsWhole(dataGeneratorMetadata));
57+
58+
/// <summary>Data member declared as <c>Task&lt;T&gt;</c>.</summary>
59+
public static IAsyncEnumerable<Func<Task<object?[]?>>> FromTask<T>(Func<Task<T>> invoke)
60+
=> FromTaskCore(invoke, keepTupleRowsWhole: false);
61+
62+
/// <summary>
63+
/// <see cref="FromTask{T}(Func{Task{T}})"/> that keeps a tuple row whole when the test takes a single tuple,
64+
/// as the attribute's reflection path does.
65+
/// </summary>
66+
public static IAsyncEnumerable<Func<Task<object?[]?>>> FromTask<T>(DataGeneratorMetadata dataGeneratorMetadata, Func<Task<T>> invoke)
67+
=> FromTaskCore(invoke, KeepsTupleRowsWhole(dataGeneratorMetadata));
68+
69+
/// <summary>Data member declared as <c>ValueTask&lt;T&gt;</c>.</summary>
70+
public static IAsyncEnumerable<Func<Task<object?[]?>>> FromValueTask<T>(Func<ValueTask<T>> invoke)
71+
=> FromValueTaskCore(invoke, keepTupleRowsWhole: false);
72+
73+
/// <summary>
74+
/// <see cref="FromValueTask{T}(Func{ValueTask{T}})"/> that keeps a tuple row whole when the test takes a single tuple,
75+
/// as the attribute's reflection path does.
76+
/// </summary>
77+
public static IAsyncEnumerable<Func<Task<object?[]?>>> FromValueTask<T>(DataGeneratorMetadata dataGeneratorMetadata, Func<ValueTask<T>> invoke)
78+
=> FromValueTaskCore(invoke, KeepsTupleRowsWhole(dataGeneratorMetadata));
79+
80+
/// <summary>Data member declared as <c>IAsyncEnumerable&lt;T&gt;</c>.</summary>
81+
public static IAsyncEnumerable<Func<Task<object?[]?>>> FromAsyncEnumerable<T>(Func<IAsyncEnumerable<T>> invoke)
82+
=> FromAsyncEnumerableCore(invoke, keepTupleRowsWhole: false);
83+
84+
/// <summary>
85+
/// <see cref="FromAsyncEnumerable{T}(Func{IAsyncEnumerable{T}})"/> that keeps a tuple row whole when the test takes a
86+
/// single tuple, as the attribute's reflection path does.
87+
/// </summary>
88+
public static IAsyncEnumerable<Func<Task<object?[]?>>> FromAsyncEnumerable<T>(DataGeneratorMetadata dataGeneratorMetadata, Func<IAsyncEnumerable<T>> invoke)
89+
=> FromAsyncEnumerableCore(invoke, KeepsTupleRowsWhole(dataGeneratorMetadata));
90+
91+
#pragma warning disable CS1998 // sync-only async iterators: deferred invocation, no await by design
92+
private static async IAsyncEnumerable<Func<Task<object?[]?>>> FromValueCore(Func<object?> invoke, bool keepTupleRowsWhole)
3993
{
4094
var result = invoke();
4195

42-
yield return () => Task.FromResult<object?[]?>(DataSourceHelpers.ToObjectArray(result));
96+
yield return () => Task.FromResult<object?[]?>(ToRow(result, keepTupleRowsWhole));
4397
}
4498

45-
/// <summary>Data member declared as a synchronous enumerable.</summary>
46-
public static async IAsyncEnumerable<Func<Task<object?[]?>>> FromEnumerable(Func<object?> invoke)
99+
private static async IAsyncEnumerable<Func<Task<object?[]?>>> FromEnumerableCore(Func<object?> invoke, bool keepTupleRowsWhole)
47100
{
48101
var result = invoke();
49102

50-
if (result is IEnumerable enumerable && !(result is string))
103+
foreach (var row in RowsFromValue(result, keepTupleRowsWhole))
51104
{
52-
foreach (var item in enumerable)
53-
{
54-
yield return () => Task.FromResult<object?[]?>(DataSourceHelpers.ToObjectArray(item));
55-
}
56-
}
57-
else
58-
{
59-
yield return () => Task.FromResult<object?[]?>(DataSourceHelpers.ToObjectArray(result));
105+
yield return row;
60106
}
61107
}
62108
#pragma warning restore CS1998
63109

64-
/// <summary>Data member declared as <c>Task&lt;T&gt;</c>.</summary>
65-
public static async IAsyncEnumerable<Func<Task<object?[]?>>> FromTask<T>(Func<Task<T>> invoke)
110+
private static async IAsyncEnumerable<Func<Task<object?[]?>>> FromTaskCore<T>(Func<Task<T>> invoke, bool keepTupleRowsWhole)
66111
{
67112
var result = invoke();
68113

69-
var taskResult = await result;
70-
if (taskResult is IEnumerable enumerable && !(taskResult is string))
114+
// A null task is a source with no rows, as the attribute's reflection path reads it, so SkipIfEmpty skips the test.
115+
if (result is null)
71116
{
72-
foreach (var item in enumerable)
73-
{
74-
yield return () => Task.FromResult<object?[]?>(DataSourceHelpers.ToObjectArray(item));
75-
}
117+
yield break;
76118
}
77-
else
119+
120+
var taskResult = await result;
121+
foreach (var row in RowsFromValue(taskResult, keepTupleRowsWhole))
78122
{
79-
yield return () => Task.FromResult<object?[]?>(DataSourceHelpers.ToObjectArray(taskResult));
123+
yield return row;
80124
}
81125
}
82126

83-
/// <summary>Data member declared as <c>ValueTask&lt;T&gt;</c>.</summary>
84-
public static async IAsyncEnumerable<Func<Task<object?[]?>>> FromValueTask<T>(Func<ValueTask<T>> invoke)
127+
private static async IAsyncEnumerable<Func<Task<object?[]?>>> FromValueTaskCore<T>(Func<ValueTask<T>> invoke, bool keepTupleRowsWhole)
85128
{
86-
var result = invoke();
87-
88-
var taskResult = await result;
89-
if (taskResult is IEnumerable enumerable && !(taskResult is string))
129+
var taskResult = await invoke();
130+
foreach (var row in RowsFromValue(taskResult, keepTupleRowsWhole))
90131
{
91-
foreach (var item in enumerable)
92-
{
93-
yield return () => Task.FromResult<object?[]?>(DataSourceHelpers.ToObjectArray(item));
94-
}
95-
}
96-
else
97-
{
98-
yield return () => Task.FromResult<object?[]?>(DataSourceHelpers.ToObjectArray(taskResult));
132+
yield return row;
99133
}
100134
}
101135

102-
/// <summary>Data member declared as <c>IAsyncEnumerable&lt;T&gt;</c>.</summary>
103-
public static async IAsyncEnumerable<Func<Task<object?[]?>>> FromAsyncEnumerable<T>(Func<IAsyncEnumerable<T>> invoke)
136+
private static async IAsyncEnumerable<Func<Task<object?[]?>>> FromAsyncEnumerableCore<T>(Func<IAsyncEnumerable<T>> invoke, bool keepTupleRowsWhole)
104137
{
105138
var result = invoke();
106139

140+
// A null source has no rows, as the attribute's reflection path reads it, so SkipIfEmpty skips the test.
141+
if (result is null)
142+
{
143+
yield break;
144+
}
145+
107146
await foreach (var item in result)
108147
{
109-
yield return () => Task.FromResult<object?[]?>(DataSourceHelpers.ToObjectArray(item));
148+
yield return () => Task.FromResult<object?[]?>(ToRow(item, keepTupleRowsWhole));
110149
}
111150
}
112151

@@ -115,25 +154,20 @@ public static class DataSourceFactories
115154
public static async IAsyncEnumerable<Func<Task<object?[]?>>> FromInstanceValue(DataGeneratorMetadata dataGeneratorMetadata, Func<object, object?> invoke)
116155
{
117156
var result = invoke(GetRequiredInstance(dataGeneratorMetadata));
157+
var keepTupleRowsWhole = KeepsTupleRowsWhole(dataGeneratorMetadata);
118158

119-
yield return () => Task.FromResult<object?[]?>(DataSourceHelpers.ToObjectArray(result));
159+
yield return () => Task.FromResult<object?[]?>(ToRow(result, keepTupleRowsWhole));
120160
}
121161

122162
/// <summary>Instance data member declared as a synchronous enumerable.</summary>
123163
public static async IAsyncEnumerable<Func<Task<object?[]?>>> FromInstanceEnumerable(DataGeneratorMetadata dataGeneratorMetadata, Func<object, object?> invoke)
124164
{
125165
var result = invoke(GetRequiredInstance(dataGeneratorMetadata));
166+
var keepTupleRowsWhole = KeepsTupleRowsWhole(dataGeneratorMetadata);
126167

127-
if (result is IEnumerable enumerable && !(result is string))
128-
{
129-
foreach (var item in enumerable)
130-
{
131-
yield return () => Task.FromResult<object?[]?>(DataSourceHelpers.ToObjectArray(item));
132-
}
133-
}
134-
else
168+
foreach (var row in RowsFromValue(result, keepTupleRowsWhole))
135169
{
136-
yield return () => Task.FromResult<object?[]?>(DataSourceHelpers.ToObjectArray(result));
170+
yield return row;
137171
}
138172
}
139173
#pragma warning restore CS1998
@@ -142,56 +176,57 @@ public static class DataSourceFactories
142176
public static async IAsyncEnumerable<Func<Task<object?[]?>>> FromInstanceTask<T>(DataGeneratorMetadata dataGeneratorMetadata, Func<object, Task<T>> invoke)
143177
{
144178
var result = invoke(GetRequiredInstance(dataGeneratorMetadata));
179+
var keepTupleRowsWhole = KeepsTupleRowsWhole(dataGeneratorMetadata);
145180

146-
var taskResult = await result;
147-
if (taskResult is IEnumerable enumerable && !(taskResult is string))
181+
// A null task is a source with no rows, as the attribute's reflection path reads it, so SkipIfEmpty skips the test.
182+
if (result is null)
148183
{
149-
foreach (var item in enumerable)
150-
{
151-
yield return () => Task.FromResult<object?[]?>(DataSourceHelpers.ToObjectArray(item));
152-
}
184+
yield break;
153185
}
154-
else
186+
187+
var taskResult = await result;
188+
foreach (var row in RowsFromValue(taskResult, keepTupleRowsWhole))
155189
{
156-
yield return () => Task.FromResult<object?[]?>(DataSourceHelpers.ToObjectArray(taskResult));
190+
yield return row;
157191
}
158192
}
159193

160194
/// <summary>Instance data member declared as <c>ValueTask&lt;T&gt;</c>.</summary>
161195
public static async IAsyncEnumerable<Func<Task<object?[]?>>> FromInstanceValueTask<T>(DataGeneratorMetadata dataGeneratorMetadata, Func<object, ValueTask<T>> invoke)
162196
{
163197
var result = invoke(GetRequiredInstance(dataGeneratorMetadata));
198+
var keepTupleRowsWhole = KeepsTupleRowsWhole(dataGeneratorMetadata);
164199

165200
var taskResult = await result;
166-
if (taskResult is IEnumerable enumerable && !(taskResult is string))
201+
foreach (var row in RowsFromValue(taskResult, keepTupleRowsWhole))
167202
{
168-
foreach (var item in enumerable)
169-
{
170-
yield return () => Task.FromResult<object?[]?>(DataSourceHelpers.ToObjectArray(item));
171-
}
172-
}
173-
else
174-
{
175-
yield return () => Task.FromResult<object?[]?>(DataSourceHelpers.ToObjectArray(taskResult));
203+
yield return row;
176204
}
177205
}
178206

179207
/// <summary>Instance data member declared as <c>IAsyncEnumerable&lt;T&gt;</c>.</summary>
180208
public static async IAsyncEnumerable<Func<Task<object?[]?>>> FromInstanceAsyncEnumerable<T>(DataGeneratorMetadata dataGeneratorMetadata, Func<object, IAsyncEnumerable<T>> invoke)
181209
{
182210
var result = invoke(GetRequiredInstance(dataGeneratorMetadata));
211+
var keepTupleRowsWhole = KeepsTupleRowsWhole(dataGeneratorMetadata);
212+
213+
// A null source has no rows, as the attribute's reflection path reads it, so SkipIfEmpty skips the test.
214+
if (result is null)
215+
{
216+
yield break;
217+
}
183218

184219
await foreach (var item in result)
185220
{
186-
yield return () => Task.FromResult<object?[]?>(DataSourceHelpers.ToObjectArray(item));
221+
yield return () => Task.FromResult<object?[]?>(ToRow(item, keepTupleRowsWhole));
187222
}
188223
}
189224

190225
/// <summary>
191226
/// A data source field, or a private or protected property that the generated code reads by reflection, whose
192227
/// declared type does not say whether it holds one row or many, such as <c>object</c>. The value's runtime type decides,
193228
/// as it does when <see cref="MethodDataSourceAttribute"/> has no factory and reads the member itself.
194-
/// A null value is one row holding null, as <see cref="FromValue"/> gives.
229+
/// A null value is one row holding null, as <see cref="FromValue(Func{object?})"/> gives.
195230
/// </summary>
196231
public static async IAsyncEnumerable<Func<Task<object?[]?>>> FromRuntimeValue(DataGeneratorMetadata dataGeneratorMetadata, Func<object?> invoke)
197232
{
@@ -226,6 +261,51 @@ public static class DataSourceFactories
226261
// nothing instead would become an empty row, so the test would fail for a missing argument.
227262
private static readonly Func<Task<object?[]?>> NullValueRow = static () => Task.FromResult<object?[]?>([null]);
228263

264+
// Splits a data member's value into rows the way FromEnumerable always has: an enumerable other than a string gives
265+
// one row per item, anything else is one row.
266+
private static IEnumerable<Func<Task<object?[]?>>> RowsFromValue(object? value, bool keepTupleRowsWhole)
267+
{
268+
if (value is IEnumerable enumerable && !(value is string))
269+
{
270+
foreach (var item in enumerable)
271+
{
272+
yield return () => Task.FromResult<object?[]?>(ToRow(item, keepTupleRowsWhole));
273+
}
274+
}
275+
else
276+
{
277+
yield return () => Task.FromResult<object?[]?>(ToRow(value, keepTupleRowsWhole));
278+
}
279+
}
280+
281+
// When the test takes a single tuple, the attribute's reflection path (ToObjectArrayWithTypes) passes a tuple row
282+
// as that one argument instead of splitting it into elements. Splitting would lose the difference between a null
283+
// row and a one-element tuple holding null, such as Tuple.Create<string?>(null): both become [null].
284+
private static bool KeepsTupleRowsWhole(DataGeneratorMetadata dataGeneratorMetadata)
285+
{
286+
return dataGeneratorMetadata.MembersToGenerate is [var member]
287+
&& TupleHelper.IsTupleType(member switch
288+
{
289+
ParameterMetadata parameter => parameter.Type,
290+
PropertyMetadata property => property.Type,
291+
_ => null
292+
});
293+
}
294+
295+
private static object?[] ToRow(object? item, bool keepTupleRowsWhole)
296+
{
297+
if (keepTupleRowsWhole)
298+
{
299+
item = DataSourceHelpers.InvokeIfFunc(item);
300+
if (DataSourceHelpers.IsTuple(item))
301+
{
302+
return [item];
303+
}
304+
}
305+
306+
return DataSourceHelpers.ToObjectArray(item);
307+
}
308+
229309
private static object GetRequiredInstance(DataGeneratorMetadata dataGeneratorMetadata)
230310
{
231311
return dataGeneratorMetadata.TestClassInstance
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
namespace TUnit.Core.SourceGenerator.Tests.Bugs._7225;
2+
3+
/// <summary>
4+
/// [InstanceMethodDataSource] gets the same generated Factory as [MethodDataSource], so Native AOT
5+
/// does not fall back to a reflection member lookup (#7225).
6+
/// </summary>
7+
internal class Tests7225 : TestsBase
8+
{
9+
[Test]
10+
public Task Test() => RunTest(Path.Combine(Git.TestsDirectory.FullName,
11+
"TUnit.TestProject",
12+
"Bugs",
13+
"_7225",
14+
"InstanceMethodDataSourceFieldTests.cs"),
15+
async generatedFiles =>
16+
{
17+
var source = string.Join(Environment.NewLine, generatedFiles);
18+
const string testClass = "global::TUnit.TestProject.Bugs._7225.InstanceMethodDataSourceFieldTests";
19+
await Assert.That(source).Contains($"FromInstanceRuntimeValue(dataGeneratorMetadata, static instance => (object?)(({testClass})instance).Rows ?? global::System.Array.Empty<object>())");
20+
await Assert.That(source).Contains($"FromInstanceEnumerable(dataGeneratorMetadata, static instance => (object?)(({testClass})instance).PropertyRows ?? global::System.Array.Empty<object>())");
21+
await Assert.That(source).Contains($"FromEnumerable(dataGeneratorMetadata, static () => (object?){testClass}.StaticRows() ?? global::System.Array.Empty<object>())");
22+
await Assert.That(source).DoesNotContain("new global::TUnit.Core.InstanceMethodDataSourceAttribute(\"Rows\"),");
23+
});
24+
25+
/// <summary>
26+
/// The factory keeps the behavior [InstanceMethodDataSource] had when it read members by reflection: an object
27+
/// value decides its rows at run time, a null value is an empty source, and a private method is looked up
28+
/// by a constant name that Native AOT keeps, as private fields and properties are.
29+
/// </summary>
30+
[Test]
31+
public Task MemberShapes() => RunTest(Path.Combine(Git.TestsDirectory.FullName,
32+
"TUnit.TestProject",
33+
"Bugs",
34+
"_7225",
35+
"InstanceMethodDataSourceMemberShapeTests.cs"),
36+
async generatedFiles =>
37+
{
38+
var source = string.Join(Environment.NewLine, generatedFiles);
39+
const string testClass = "global::TUnit.TestProject.Bugs._7225.InstanceMethodDataSourceMemberShapeTests";
40+
await Assert.That(source).Contains($"FromInstanceRuntimeValue(dataGeneratorMetadata, static instance => (object?)(({testClass})instance).ObjectProperty ?? global::System.Array.Empty<object>())");
41+
await Assert.That(source).Contains($"FromInstanceRuntimeValue(dataGeneratorMetadata, static instance => (object?)(({testClass})instance).ObjectMethod() ?? global::System.Array.Empty<object>())");
42+
await Assert.That(source).Contains($"FromInstanceEnumerable(dataGeneratorMetadata, static instance => (object?)(({testClass})instance).TupleRows ?? global::System.Array.Empty<object>())");
43+
await Assert.That(source).Contains($"FromInstanceEnumerable(dataGeneratorMetadata, static instance => typeof({testClass}).GetMethod(\"PrivateRows\", ");
44+
await Assert.That(source).DoesNotContain("new global::TUnit.Core.InstanceMethodDataSourceAttribute(\"PrivateRows\"),");
45+
await Assert.That(source).Contains($"FromInstanceRuntimeValue(dataGeneratorMetadata, static instance => (object?)(({testClass})instance).NonGenericTaskRows() ?? global::System.Array.Empty<object>())");
46+
await Assert.That(source).Contains($"FromInstanceRuntimeValue(dataGeneratorMetadata, static instance => (object?)(({testClass})instance).NonGenericValueTaskRows ?? global::System.Array.Empty<object>())");
47+
await Assert.That(source).Contains($"FromRuntimeValue(dataGeneratorMetadata, static () => (object?){testClass}.StaticNonGenericTaskRows ?? global::System.Array.Empty<object>())");
48+
await Assert.That(source).Contains($"FromRuntimeValue(dataGeneratorMetadata, static () => (object?){testClass}.StaticNonGenericValueTaskRows() ?? global::System.Array.Empty<object>())");
49+
// A generic overload of the same name would make the GetMethod lookup ambiguous
50+
await Assert.That(source).Contains($"global::System.Array.Find(typeof({testClass}).GetMethods(");
51+
await Assert.That(source).Contains("m.Name == \"OverloadedRows\" && !m.IsGenericMethodDefinition && m.GetParameters().Length == 0)!.Invoke(instance, null)");
52+
});
53+
}

0 commit comments

Comments
 (0)