diff --git a/BenchmarkMockNet.Tests/BenchmarkData.cs b/BenchmarkMockNet.Tests/BenchmarkData.cs new file mode 100644 index 0000000..0b4a03c --- /dev/null +++ b/BenchmarkMockNet.Tests/BenchmarkData.cs @@ -0,0 +1,32 @@ +using System.Reflection; +using BenchmarkMockNet.Benchmarks; +using Xunit; + +namespace BenchmarkMockNet.Tests; + +public class BenchmarkData : TheoryData +{ + public BenchmarkData() + { + var methods = typeof(IMockingBenchmark).GetMethods(); + + foreach (var benchmark in Benchmarks) + { + foreach (var method in methods) + { + Add(benchmark.Key, method); + } + } + } + + public static readonly Dictionary> Benchmarks = new() + { + { typeof(Construction), result => result is IThing }, + { typeof(Callback), result => result is true }, + { typeof(EmptyMethod), result => result is null }, + { typeof(EmptyReturn), result => result is 0 }, + { typeof(OneParameter), result => result is null }, + { typeof(Return), result => result is 1 }, + { typeof(Verify), result => result is null } + }; +} \ No newline at end of file diff --git a/BenchmarkMockNet.Tests/BenchmarkTests.cs b/BenchmarkMockNet.Tests/BenchmarkTests.cs index b085769..b0e4d17 100644 --- a/BenchmarkMockNet.Tests/BenchmarkTests.cs +++ b/BenchmarkMockNet.Tests/BenchmarkTests.cs @@ -1,44 +1,13 @@ using System.Reflection; -using BenchmarkMockNet.Benchmarks; using Xunit; namespace BenchmarkMockNet.Tests; -public static class BenchmarkTests +public class BenchmarkTests { - private static readonly MethodInfo[] Methods = typeof(IMockingBenchmark).GetMethods(); - - private static readonly Dictionary> Benchmarks = new() - { - { typeof(Construction), result => result is IThing }, - { typeof(Callback), result => result is true }, - { typeof(EmptyMethod), result => result is null }, - { typeof(EmptyReturn), result => result is 0 }, - { typeof(OneParameter), result => result is null }, - { typeof(Return), result => result is 1 }, - { typeof(Verify), result => result is null } - }; - - public static TheoryData Matrix - { - get - { - var matrix = new TheoryData(); - foreach (var benchmark in Benchmarks) - { - foreach (var method in Methods) - { - matrix.Add(benchmark.Key, method); - } - } - - return matrix; - } - } - [Theory] - [MemberData(nameof(Matrix))] - public static void RunAll(Type type, MethodInfo library) + [ClassData(typeof(BenchmarkData))] + public void RunAll(Type type, MethodInfo library) { //arrange var benchmark = Activator.CreateInstance(type); @@ -48,7 +17,7 @@ public static void RunAll(Type type, MethodInfo library) var result = method?.Invoke(benchmark, []); //assert - var assertion = Benchmarks[type]; + var assertion = BenchmarkData.Benchmarks[type]; Assert.True(assertion(result)); } } \ No newline at end of file