1+ using System ;
2+ using System . Linq ;
3+ using SqlKata . Compilers ;
4+ using Xunit ;
5+
6+ namespace SqlKata . Tests . Infrastructure
7+ {
8+ public class InfrastructureTests : TestSupport
9+ {
10+ [ Fact ]
11+ public void CanGetCompiler ( )
12+ {
13+ var compiler = Compilers . Get ( EngineCodes . SqlServer ) ;
14+
15+ Assert . NotNull ( compiler ) ;
16+ Assert . IsType < SqlServerCompiler > ( compiler ) ;
17+ }
18+
19+ [ Fact ]
20+ public void CanCompile ( )
21+ {
22+ var results = Compilers . Compile ( new Query ( "Table" ) ) ;
23+
24+ Assert . NotNull ( results ) ;
25+ Assert . Equal ( Compilers . KnownEngineCodes . Count ( ) , results . Count ) ;
26+ }
27+
28+ [ Fact ]
29+ public void CanCompileSelectively ( )
30+ {
31+ var desiredEngines = new [ ] { EngineCodes . SqlServer , EngineCodes . MySql } ;
32+ var results = Compilers . Compile ( desiredEngines , new Query ( "Table" ) ) ;
33+
34+ Assert . Equal ( desiredEngines . Length , results . Count ) ;
35+ Assert . Contains ( results , a => a . Key == EngineCodes . SqlServer ) ;
36+ Assert . Contains ( results , a => a . Key == EngineCodes . MySql ) ;
37+ }
38+
39+
40+ [ Fact ]
41+ public void ShouldThrowIfInvalidEngineCode ( )
42+ {
43+ Assert . Throws < InvalidOperationException > ( ( ) => Compilers . CompileFor ( "XYZ" , new Query ( ) ) ) ;
44+ }
45+
46+ [ Fact ]
47+ public void ShouldThrowIfAnyEngineCodesAreInvalid ( )
48+ {
49+ var codes = new [ ] { EngineCodes . SqlServer , "123" , EngineCodes . MySql , "abc" } ;
50+ Assert . Throws < InvalidOperationException > ( ( ) => Compilers . Compile ( codes , new Query ( ) ) ) ;
51+ }
52+ }
53+ }
0 commit comments