Skip to content

Commit 45d06ae

Browse files
committed
Add support for FrozenAttribute in ClassAutoNSubstituteDataAttribute
1 parent 36b19f4 commit 45d06ae

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/Atc.Test/ClassAutoNSubstituteDataAttribute.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,29 @@ public ClassAutoNSubstituteDataAttribute(Type @class)
1515

1616
public override IEnumerable<object[]> GetData(MethodInfo testMethod)
1717
{
18+
var parameters = testMethod.GetParameters();
19+
var frozenValues = parameters
20+
.Select((p, i) => (Index: i, Parameter: p, p.ParameterType))
21+
.Where(x => x.Parameter.GetCustomAttribute<FrozenAttribute>() != null)
22+
.ToArray();
23+
var injectMethod = typeof(FixtureRegistrar)
24+
.GetMethod(
25+
nameof(FixtureRegistrar.Inject),
26+
BindingFlags.Public | BindingFlags.Static);
27+
1828
var data = base.GetData(testMethod);
1929
foreach (var values in data)
2030
{
2131
var fixture = FixtureFactory.Create();
32+
foreach (var frozenValue in frozenValues)
33+
{
34+
injectMethod?
35+
.MakeGenericMethod(frozenValue.ParameterType)
36+
.Invoke(null, [fixture, values[frozenValue.Index]]);
37+
}
38+
2239
yield return values
23-
.Concat(testMethod
24-
.GetParameters()
40+
.Concat(parameters
2541
.Skip(values.Length)
2642
.Select(p => GetSpecimen(fixture, p)))
2743
.ToArray();

0 commit comments

Comments
 (0)