diff --git a/Atc.Test.sln b/Atc.Test.sln index 58c8e0c..6a84a12 100644 --- a/Atc.Test.sln +++ b/Atc.Test.sln @@ -7,6 +7,25 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Atc.Test", "src\Atc.Test\At EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Atc.Test.Tests", "test\Atc.Test.Tests\Atc.Test.Tests.csproj", "{FE44F21D-22E5-47ED-A551-74AF79E23C89}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".config", ".config", "{23CF9054-75B8-4E9E-A252-52C5C1455ECA}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + Directory.Build.props = Directory.Build.props + README.md = README.md + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2E82F528-471D-4451-ADD9-C0AF97692C8D}" + ProjectSection(SolutionItems) = preProject + src\.editorconfig = src\.editorconfig + src\Directory.Build.props = src\Directory.Build.props + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{4B46C47D-DE74-4FA4-9A27-4CBCB354AE05}" + ProjectSection(SolutionItems) = preProject + test\.editorconfig = test\.editorconfig + test\Directory.Build.props = test\Directory.Build.props + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -45,6 +64,10 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {7E15F9B0-040B-454B-BD29-E0A0CBC3473B} = {2E82F528-471D-4451-ADD9-C0AF97692C8D} + {FE44F21D-22E5-47ED-A551-74AF79E23C89} = {4B46C47D-DE74-4FA4-9A27-4CBCB354AE05} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {5E657CBB-3A3C-4C41-B832-7ACE196175AD} EndGlobalSection diff --git a/src/Atc.Test/ClassAutoNSubstituteDataAttribute.cs b/src/Atc.Test/ClassAutoNSubstituteDataAttribute.cs index 9de4b8e..8122a7a 100644 --- a/src/Atc.Test/ClassAutoNSubstituteDataAttribute.cs +++ b/src/Atc.Test/ClassAutoNSubstituteDataAttribute.cs @@ -31,9 +31,12 @@ public override IEnumerable GetData(MethodInfo testMethod) var fixture = FixtureFactory.Create(); foreach (var frozenValue in frozenValues) { - injectMethod? - .MakeGenericMethod(frozenValue.ParameterType) - .Invoke(null, [fixture, values[frozenValue.Index]]); + if (values.Length > frozenValue.Index) + { + injectMethod? + .MakeGenericMethod(frozenValue.ParameterType) + .Invoke(null, [fixture, values[frozenValue.Index]]); + } } yield return values diff --git a/test/.editorconfig b/test/.editorconfig index c8bf541..b2db3a3 100644 --- a/test/.editorconfig +++ b/test/.editorconfig @@ -62,4 +62,5 @@ dotnet_diagnostic.CA1812.severity = none # Test classes used as gener dotnet_diagnostic.SA1202.severity = none # Private helper methods makes sense to keep at top of test classes, as tests are added to bottom. dotnet_diagnostic.CA2201.severity = none # Instantiating Exceptions as test data should be allowed. dotnet_diagnostic.CA1711.severity = none # Identifiers should not have incorrect suffix -dotnet_diagnostic.S2344.severity = none # Enumeration type names should not have "Flags" or "Enum" suffixes \ No newline at end of file +dotnet_diagnostic.S2344.severity = none # Enumeration type names should not have "Flags" or "Enum" suffixes +dotnet_diagnostic.CA1515.severity = none # CA1515: Consider making public types internal \ No newline at end of file diff --git a/test/Atc.Test.Tests/ClassAutoNSubstituteDataAttributeTests.cs b/test/Atc.Test.Tests/ClassAutoNSubstituteDataAttributeTests.cs new file mode 100644 index 0000000..c1c46a6 --- /dev/null +++ b/test/Atc.Test.Tests/ClassAutoNSubstituteDataAttributeTests.cs @@ -0,0 +1,31 @@ +namespace Atc.Test.Tests; + +public class ClassAutoNSubstituteDataAttributeTests +{ + public class TestData : TheoryData + { + public TestData() + { + AddRow(SampleEnum.One); + AddRow(SampleEnum.Two); + AddRow(SampleEnum.Three); + } + } + + [Theory] + [ClassAutoNSubstituteData(typeof(TestData))] + public void MemberAutoNSubstituteData_Should_Call_For_MemberData( + SampleEnum value, + [Frozen] ISampleInterface interfaceType, + SampleClass concreteType, + SampleDependantClass dependantType) + { + value.Should().BeOneOf(SampleEnum.One, SampleEnum.Two, SampleEnum.Three); + interfaceType.Should().NotBeNull(); + interfaceType.IsSubstitute().Should().BeTrue(); + concreteType.Should().NotBeNull(); + concreteType.IsSubstitute().Should().BeFalse(); + dependantType.Should().NotBeNull(); + dependantType.Dependency.Should().Be(interfaceType); + } +}