Skip to content

Commit aa22816

Browse files
committed
clean and refactor tests
derrive test classes from TestSupport reorganize tests (initial) move compiler specific tests to own namespace remove unused files / classes etc etc
1 parent 964dbed commit aa22816

22 files changed

Lines changed: 781 additions & 849 deletions

QueryBuilder.Tests/CompilerTest.cs

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using SqlKata.Execution;
3+
using Xunit;
4+
5+
namespace SqlKata.Tests
6+
{
7+
public class ExecutionTests
8+
{
9+
[Fact]
10+
public void ShouldThrowException()
11+
{
12+
Assert.Throws<InvalidOperationException>(() => { new Query("Books").Get(); });
13+
}
14+
}
15+
}

QueryBuilder.Tests/FirebirdLimitTest.cs renamed to QueryBuilder.Tests/Firebird/FirebirdLimitTests.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
using SqlKata;
21
using SqlKata.Compilers;
2+
using SqlKata.Tests.Infrastructure;
33
using Xunit;
44

5-
namespace SqlKata.Tests
5+
namespace SqlKata.Tests.Firebird
66
{
7-
public class FirebirdLimitTest
7+
public class FirebirdLimitTests : TestSupport
88
{
9-
private FirebirdCompiler compiler = new FirebirdCompiler();
9+
private readonly FirebirdCompiler compiler;
10+
11+
public FirebirdLimitTests()
12+
{
13+
compiler = Compilers.Get<FirebirdCompiler>(EngineCodes.Firebird);
14+
}
1015

1116
[Fact]
1217
public void NoLimitNorOffset()
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
using System.Collections;
22
using System.Linq;
3-
using SqlKata;
43
using Xunit;
54

65
namespace SqlKata.Tests
76
{
8-
public class HelperTest
7+
public class HelperTests
98
{
109
[Theory]
1110
[InlineData("")]

QueryBuilder.Tests/MySqlLimitTest.cs renamed to QueryBuilder.Tests/MySql/MySqlLimitTests.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
using SqlKata;
21
using SqlKata.Compilers;
2+
using SqlKata.Tests.Infrastructure;
33
using Xunit;
44

5-
namespace SqlKata.Tests
5+
namespace SqlKata.Tests.MySql
66
{
7-
public class MySqlLimitTest
7+
public class MySqlLimitTests : TestSupport
88
{
9-
private MySqlCompiler compiler = new MySqlCompiler();
9+
private readonly MySqlCompiler compiler;
10+
11+
public MySqlLimitTests()
12+
{
13+
compiler = Compilers.Get<MySqlCompiler>(EngineCodes.MySql);
14+
}
1015

1116
[Fact]
1217
public void WithNoLimitNorOffset()

QueryBuilder.Tests/WhiteListingOperators.cs renamed to QueryBuilder.Tests/OperatorWhitelistTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
using System;
2-
using SqlKata;
32
using SqlKata.Compilers;
43
using Xunit;
54

65
namespace SqlKata.Tests
76
{
8-
public class WhiteListingOperators
7+
public class OperatorWhitelistTests
98
{
109

11-
public WhiteListingOperators()
10+
public OperatorWhitelistTests()
1211
{
1312

1413
}

QueryBuilder.Tests/OracleLegacyLimitTests.cs renamed to QueryBuilder.Tests/Oracle/OracleLegacyLimitTests.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
using System;
2-
using SqlKata;
3-
using SqlKata.Compilers;
1+
using SqlKata.Compilers;
2+
using SqlKata.Tests.Infrastructure;
43
using Xunit;
54

6-
namespace SqlKata.Tests
5+
namespace SqlKata.Tests.Oracle
76
{
8-
public class OracleLegacyLimitTests
7+
public class OracleLegacyLimitTests : TestSupport
98
{
109
private const string TableName = "Table";
1110
private const string SqlPlaceholder = "GENERATED_SQL";
11+
private readonly OracleCompiler compiler;
1212

13-
private OracleCompiler compiler = new OracleCompiler()
13+
public OracleLegacyLimitTests()
1414
{
15-
UseLegacyPagination = true
16-
};
15+
compiler = Compilers.Get<OracleCompiler>(EngineCodes.Oracle);
16+
compiler.UseLegacyPagination = true;
17+
}
1718

1819
[Fact]
1920
public void WithNoLimitNorOffset()

QueryBuilder.Tests/OracleLimitTests.cs renamed to QueryBuilder.Tests/Oracle/OracleLimitTests.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
using System;
2-
using SqlKata;
3-
using SqlKata.Compilers;
1+
using SqlKata.Compilers;
2+
using SqlKata.Tests.Infrastructure;
43
using Xunit;
54

6-
namespace SqlKata.Tests
5+
namespace SqlKata.Tests.Oracle
76
{
8-
public class OracleLimitTests
7+
public class OracleLimitTests : TestSupport
98
{
109
private const string TableName = "Table";
1110
private const string SqlPlaceholder = "GENERATED_SQL";
1211

13-
private OracleCompiler compiler = new OracleCompiler();
12+
private OracleCompiler compiler;
13+
14+
public OracleLimitTests()
15+
{
16+
compiler = Compilers.Get<OracleCompiler>(EngineCodes.Oracle);
17+
}
1418

1519
[Fact]
1620
public void NoLimitNorOffset()
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Globalization;
4-
using SqlKata.Execution;
5-
using SqlKata;
64
using SqlKata.Compilers;
75
using Xunit;
86
using System.Collections;
7+
using SqlKata.Tests.Infrastructure;
98

109
namespace SqlKata.Tests
1110
{
@@ -16,31 +15,9 @@ public enum EnumExample
1615
Third,
1716
}
1817

19-
public class ParameterTypeTest
18+
public class ParameterTypeTests : TestSupport
2019
{
21-
private readonly Compiler pgsql;
22-
private readonly MySqlCompiler mysql;
23-
private readonly FirebirdCompiler fbsql;
24-
public SqlServerCompiler mssql { get; private set; }
2520

26-
public ParameterTypeTest()
27-
{
28-
mssql = new SqlServerCompiler();
29-
mysql = new MySqlCompiler();
30-
pgsql = new PostgresCompiler();
31-
fbsql = new FirebirdCompiler();
32-
}
33-
34-
private string[] Compile(Query q)
35-
{
36-
return new[]
37-
{
38-
mssql.Compile(q.Clone()).ToString(),
39-
mysql.Compile(q.Clone()).ToString(),
40-
pgsql.Compile(q.Clone()).ToString(),
41-
fbsql.Compile(q.Clone()).ToString(),
42-
};
43-
}
4421

4522
public class ParameterTypeGenerator : IEnumerable<object[]>
4623
{
@@ -71,7 +48,7 @@ public void CorrectParameterTypeOutput(string rendered, object input)
7148

7249
var c = Compile(query);
7350

74-
Assert.Equal($"SELECT * FROM [Table] WHERE [Col] = {rendered}", c[0]);
51+
Assert.Equal($"SELECT * FROM [Table] WHERE [Col] = {rendered}", c[EngineCodes.SqlServer]);
7552
}
7653
}
7754
}

QueryBuilder.Tests/PostgreSqlLimitTest.cs renamed to QueryBuilder.Tests/PostgreSql/PostgreSqlLimitTests.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
using SqlKata;
21
using SqlKata.Compilers;
2+
using SqlKata.Tests.Infrastructure;
33
using Xunit;
44

5-
namespace SqlKata.Tests
5+
namespace SqlKata.Tests.PostgreSql
66
{
7-
public class PostgreSqlLimitTest
7+
public class PostgreSqlLimitTests : TestSupport
88
{
9-
private PostgresCompiler compiler = new PostgresCompiler();
9+
private readonly PostgresCompiler compiler;
10+
11+
public PostgreSqlLimitTests()
12+
{
13+
compiler = Compilers.Get<PostgresCompiler>(EngineCodes.PostgreSql);
14+
}
1015

1116
[Fact]
1217
public void WithNoLimitNorOffset()

0 commit comments

Comments
 (0)