Skip to content

Commit

Permalink
Add support for FrozenAttribute in ClassAutoNSubstituteDataAttribute
Browse files Browse the repository at this point in the history
  • Loading branch information
rickykaare committed Sep 15, 2024
1 parent 36b19f4 commit 45d06ae
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/Atc.Test/ClassAutoNSubstituteDataAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,29 @@ public ClassAutoNSubstituteDataAttribute(Type @class)

public override IEnumerable<object[]> GetData(MethodInfo testMethod)
{
var parameters = testMethod.GetParameters();
var frozenValues = parameters
.Select((p, i) => (Index: i, Parameter: p, p.ParameterType))
.Where(x => x.Parameter.GetCustomAttribute<FrozenAttribute>() != null)
.ToArray();
var injectMethod = typeof(FixtureRegistrar)
.GetMethod(
nameof(FixtureRegistrar.Inject),
BindingFlags.Public | BindingFlags.Static);

var data = base.GetData(testMethod);
foreach (var values in data)
{
var fixture = FixtureFactory.Create();
foreach (var frozenValue in frozenValues)
{
injectMethod?
.MakeGenericMethod(frozenValue.ParameterType)
.Invoke(null, [fixture, values[frozenValue.Index]]);

Check failure on line 36 in src/Atc.Test/ClassAutoNSubstituteDataAttribute.cs

View workflow job for this annotation

GitHub Actions / dotnet-build (ubuntu-latest)

Opening square brackets should not be preceded by a space. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1010.md)

Check failure on line 36 in src/Atc.Test/ClassAutoNSubstituteDataAttribute.cs

View workflow job for this annotation

GitHub Actions / dotnet-build (ubuntu-latest)

Opening square brackets should not be preceded by a space. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1010.md)

Check failure on line 36 in src/Atc.Test/ClassAutoNSubstituteDataAttribute.cs

View workflow job for this annotation

GitHub Actions / dotnet-build (ubuntu-latest)

Opening square brackets should not be preceded by a space. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1010.md)

Check failure on line 36 in src/Atc.Test/ClassAutoNSubstituteDataAttribute.cs

View workflow job for this annotation

GitHub Actions / dotnet-build (ubuntu-latest)

Opening square brackets should not be preceded by a space. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1010.md)

Check failure on line 36 in src/Atc.Test/ClassAutoNSubstituteDataAttribute.cs

View workflow job for this annotation

GitHub Actions / dotnet-build (macos-latest)

Opening square brackets should not be preceded by a space. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1010.md)

Check failure on line 36 in src/Atc.Test/ClassAutoNSubstituteDataAttribute.cs

View workflow job for this annotation

GitHub Actions / dotnet-build (macos-latest)

Opening square brackets should not be preceded by a space. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1010.md)

Check failure on line 36 in src/Atc.Test/ClassAutoNSubstituteDataAttribute.cs

View workflow job for this annotation

GitHub Actions / dotnet-build (macos-latest)

Opening square brackets should not be preceded by a space. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1010.md)

Check failure on line 36 in src/Atc.Test/ClassAutoNSubstituteDataAttribute.cs

View workflow job for this annotation

GitHub Actions / dotnet-build (macos-latest)

Opening square brackets should not be preceded by a space. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1010.md)
}

yield return values
.Concat(testMethod
.GetParameters()
.Concat(parameters
.Skip(values.Length)
.Select(p => GetSpecimen(fixture, p)))
.ToArray();
Expand Down

0 comments on commit 45d06ae

Please sign in to comment.