-
-
Notifications
You must be signed in to change notification settings - Fork 514
/
Copy pathTestSupport.cs
49 lines (43 loc) · 1.43 KB
/
TestSupport.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
using SqlKata;
using SqlKata.Compilers;
namespace QueryBuilder.Benchmarks.Infrastructure;
public class TestSupport
{
public static SqlResult CompileFor(string engine, Query query, Func<Compiler, Compiler> configuration = null)
{
var compiler = CreateCompiler(engine);
if (configuration != null)
{
compiler = configuration(compiler);
}
return compiler.Compile(query);
}
public static SqlResult CompileFor(string engine, Query query, Action<Compiler> configuration)
{
return CompileFor(engine, query, compiler =>
{
configuration(compiler);
return compiler;
});
}
public static Compiler CreateCompiler(string engine)
{
return engine switch
{
EngineCodes.Firebird => new FirebirdCompiler(),
EngineCodes.MySql => new MySqlCompiler(),
EngineCodes.Oracle => new OracleCompiler
{
UseLegacyPagination = false
},
EngineCodes.PostgreSql => new PostgresCompiler(),
EngineCodes.Sqlite => new SqliteCompiler(),
EngineCodes.SqlServer => new SqlServerCompiler
{
UseLegacyPagination = false
},
EngineCodes.Generic => new TestCompiler(),
_ => throw new ArgumentException($"Unsupported engine type: {engine}", nameof(engine)),
};
}
}