forked from ecoAPM/BenchmarkMockNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BenchmarkTests.cs
59 lines (54 loc) · 2.17 KB
/
BenchmarkTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using BenchmarkMockNet.Benchmarks;
namespace BenchmarkMockNet
{
public class BenchmarkTests
{
public void RunAll()
{
new Construction().Run();
new Callback().Run(true);
new EmptyMethod().Run();
new EmptyReturn().Run(0);
new Return().Run(1);
new Verify().Run();
new CallbackOnly().Run(true);
new EmptyMethodOnly().Run();
new EmptyReturnOnly().Run(0);
new ReturnOnly().Run(1);
new VerifyOnly().Run();
}
}
static class BenchmarkTestHelpers
{
public static void Run<T>(this IMockingBenchmark<T> benchmark, T expected)
{
Test(benchmark.GetType().Name, "Stub", () => benchmark.Stub().Equals(expected));
Test(benchmark.GetType().Name, "Moq", () => benchmark.Moq().Equals(expected));
Test(benchmark.GetType().Name, "NSubstitute", () => benchmark.NSubstitute().Equals(expected));
Test(benchmark.GetType().Name, "FakeItEasy", () => benchmark.FakeItEasy().Equals(expected));
Test(benchmark.GetType().Name, "Rocks", () => benchmark.Rocks().Equals(expected));
}
private static void Test(string test, string type, Func<bool> pass)
{
if (!pass())
throw new Exception($"{type} failed {test}");
}
public static void Run<T>(this IMockingBenchmark<T> benchmark)
{
Test(benchmark.GetType().Name, "Stub", () => benchmark.Stub() is IThingy);
Test(benchmark.GetType().Name, "Moq", () => benchmark.Moq() is IThingy);
Test(benchmark.GetType().Name, "NSubstitute", () => benchmark.NSubstitute() is IThingy);
Test(benchmark.GetType().Name, "FakeItEasy", () => benchmark.FakeItEasy() is IThingy);
Test(benchmark.GetType().Name, "Rocks", () => benchmark.Rocks() is IThingy);
}
public static void Run(this IMockingBenchmark benchmark)
{
benchmark.Stub();
benchmark.Moq();
benchmark.NSubstitute();
benchmark.FakeItEasy();
benchmark.Rocks();
}
}
}