Skip to content

Commit e003947

Browse files
authored
Merge pull request #40 from atc-net/feature/classdata
Add support for FrozenAttribute in ClassAutoNSubstituteDataAttribute
2 parents 36b19f4 + 20b9313 commit e003947

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,3 +522,4 @@ dotnet_diagnostic.SA1011.severity = none # Space needed after closing
522522

523523
dotnet_diagnostic.S1172.severity = none # False positive: Unused method parameters should be removed
524524
dotnet_diagnostic.CA1510.severity = none # ArgumentNullException throw helper not available for all targets
525+
dotnet_diagnostic.SA1010.severity = none # SA1010: Opening square brackets should be spaced correctly

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)