Skip to content

Commit 54eab50

Browse files
committed
merged from main
2 parents 0dfafac + 8070365 commit 54eab50

13 files changed

+222
-99
lines changed

Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>0.2.0</Version>
3+
<Version>0.2.5</Version>
44
</PropertyGroup>
55
</Project>

README.md

+12-11
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,25 @@ var generator = new SqlServerTestGenerator(options =>
2121
{
2222
options.AddDatabaseObjectExitsRule(new string[] { "mytable" }, DatabaseObjectType.Table);
2323

24-
options.AddDatabaseRecordExitsRule(
25-
new List<DatabaseRule>()
24+
options.AddDatabaseRecordExitsRule(new List<DatabaseRecordExistRule>()
2625
{
27-
new DatabaseRule()
26+
new DatabaseRecordExistRule()
2827
{
2928
TableName = "mytable",
30-
PredicateValue = "name = 'myname'"
29+
ColumnName = "name",
30+
Operator = "=",
31+
Value = "myname"
3132
}
3233
});
3334

34-
options.AddDatabaseRecordsCountRule(
35-
new List<DatabaseRule>()
35+
options.AddDatabaseRecordsCountRule(new List<DatabaseRecordCountRule>()
3636
{
37-
new DatabaseRule()
37+
new DatabaseRecordCountRule()
3838
{
39-
TableName = "mytable",
40-
PredicateValue = "=100"
41-
}
39+
TableName = "mytable",
40+
Count = 100,
41+
Operator = "="
42+
}
4243
});
4344
});
4445

@@ -58,7 +59,7 @@ To run the tests, we create a `SqlServerTestRunner` runner:
5859
```csharp
5960
var runner = new SqlServerTestRunner(scripts, options =>
6061
{
61-
options.AddSQLServerConnection("server=localhost;user=sa;password=passw0rd;Initial Catalog=myDatabase");
62+
options.AddSQLServerConnection("server=localhost;user=user;password=mypassword;Initial Catalog=myDatabase");
6263
});
6364

6465
List<DatabaseScriptResult> results = await runner.Run();

src/QAToolKit.Engine.Database.Test/MySqlTestGeneratorTests.cs

+21-18
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public async Task MySqlTableExistScriptTest_Success()
2121
{
2222
new DatabaseScript(
2323
"mytable",
24-
$@"SELECT EXISTS(SELECT * FROM information_schema.tables WHERE table_name = 'mytable');",
24+
$@"SELECT EXISTS(SELECT * FROM `information_schema`.`tables` WHERE `table_name` = 'mytable');",
2525
DatabaseTestType.ObjectExist,
2626
DatabaseKind.MySQL)
2727
}.ToExpectedObject();
@@ -42,7 +42,7 @@ public async Task MySqlViewExistScriptTest_Success()
4242
{
4343
new DatabaseScript(
4444
"myview",
45-
$@"SELECT EXISTS(SELECT * FROM information_schema.views WHERE table_name = 'myview');",
45+
$@"SELECT EXISTS(SELECT * FROM `information_schema`.`views` WHERE `table_name` = 'myview');",
4646
DatabaseTestType.ObjectExist,
4747
DatabaseKind.MySQL)
4848
}.ToExpectedObject();
@@ -63,7 +63,7 @@ public async Task MySqlStoredProcedureExistScriptTest_Success()
6363
{
6464
new DatabaseScript(
6565
"mystoredprocedure",
66-
$@"SELECT EXISTS(SELECT * FROM information_schema.routines WHERE routine_name = 'mystoredprocedure');",
66+
$@"SELECT EXISTS(SELECT * FROM `information_schema`.`routines` WHERE `routine_name` = 'mystoredprocedure');",
6767
DatabaseTestType.ObjectExist,
6868
DatabaseKind.MySQL)
6969
}.ToExpectedObject();
@@ -84,12 +84,12 @@ public async Task MySqlMultipleTableExistScriptTest_Success()
8484
{
8585
new DatabaseScript(
8686
"table1",
87-
$@"SELECT EXISTS(SELECT * FROM information_schema.tables WHERE table_name = 'table1');",
87+
$@"SELECT EXISTS(SELECT * FROM `information_schema`.`tables` WHERE `table_name` = 'table1');",
8888
DatabaseTestType.ObjectExist,
8989
DatabaseKind.MySQL),
9090
new DatabaseScript(
9191
"table2",
92-
$@"SELECT EXISTS(SELECT * FROM information_schema.tables WHERE table_name = 'table2');",
92+
$@"SELECT EXISTS(SELECT * FROM `information_schema`.`tables` WHERE `table_name` = 'table2');",
9393
DatabaseTestType.ObjectExist,
9494
DatabaseKind.MySQL)
9595
}.ToExpectedObject();
@@ -110,12 +110,12 @@ public async Task MySqlMultipleViewExistScriptTest_Success()
110110
{
111111
new DatabaseScript(
112112
"view1",
113-
$@"SELECT EXISTS(SELECT * FROM information_schema.views WHERE table_name = 'view1');",
113+
$@"SELECT EXISTS(SELECT * FROM `information_schema`.`views` WHERE `table_name` = 'view1');",
114114
DatabaseTestType.ObjectExist,
115115
DatabaseKind.MySQL),
116116
new DatabaseScript(
117117
"view2",
118-
$@"SELECT EXISTS(SELECT * FROM information_schema.views WHERE table_name = 'view2');",
118+
$@"SELECT EXISTS(SELECT * FROM `information_schema`.`views` WHERE `table_name` = 'view2');",
119119
DatabaseTestType.ObjectExist,
120120
DatabaseKind.MySQL)
121121
}.ToExpectedObject();
@@ -136,12 +136,12 @@ public async Task MySqlMultipleStoredProcedureExistScriptTest_Success()
136136
{
137137
new DatabaseScript(
138138
"sp1",
139-
$@"SELECT EXISTS(SELECT * FROM information_schema.routines WHERE routine_name = 'sp1');",
139+
$@"SELECT EXISTS(SELECT * FROM `information_schema`.`routines` WHERE `routine_name` = 'sp1');",
140140
DatabaseTestType.ObjectExist,
141141
DatabaseKind.MySQL),
142142
new DatabaseScript(
143143
"sp2",
144-
$@"SELECT EXISTS(SELECT * FROM information_schema.routines WHERE routine_name = 'sp2');",
144+
$@"SELECT EXISTS(SELECT * FROM `information_schema`.`routines` WHERE `routine_name` = 'sp2');",
145145
DatabaseTestType.ObjectExist,
146146
DatabaseKind.MySQL)
147147
}.ToExpectedObject();
@@ -167,12 +167,14 @@ public async Task MySqlRecordExistScriptTest_Success()
167167
var generator = new MySqlTestGenerator(options =>
168168
{
169169
options.AddDatabaseRecordExitsRule(
170-
new List<DatabaseRule>()
170+
new List<DatabaseRecordExistRule>()
171171
{
172-
new DatabaseRule()
172+
new DatabaseRecordExistRule()
173173
{
174174
TableName = "mytable",
175-
PredicateValue = "name = 'myname'"
175+
ColumnName = "name",
176+
Operator = "=",
177+
Value = "myname"
176178
}
177179
});
178180
});
@@ -181,27 +183,28 @@ public async Task MySqlRecordExistScriptTest_Success()
181183
{
182184
new DatabaseScript(
183185
"mytable",
184-
$@"SELECT EXISTS (SELECT 1 FROM mytable WHERE name = 'myname');",
186+
$@"SELECT EXISTS(SELECT * FROM `mytable` WHERE `name` = 'myname');",
185187
DatabaseTestType.RecordExist,
186188
DatabaseKind.MySQL)
187189
}.ToExpectedObject();
188190

189191
results.ShouldEqual(await generator.Generate());
190192
Assert.Equal(DatabaseKind.MySQL, generator.DatabaseKind);
191193
}
192-
194+
193195
[Fact]
194196
public async Task MySqlRecordCountScriptTest_Success()
195197
{
196198
var generator = new MySqlTestGenerator(options =>
197199
{
198200
options.AddDatabaseRecordsCountRule(
199-
new List<DatabaseRule>()
201+
new List<DatabaseRecordCountRule>()
200202
{
201-
new DatabaseRule()
203+
new DatabaseRecordCountRule()
202204
{
203205
TableName = "mytable",
204-
PredicateValue = "=100"
206+
Operator = "=",
207+
Count = 100
205208
}
206209
});
207210
});
@@ -210,7 +213,7 @@ public async Task MySqlRecordCountScriptTest_Success()
210213
{
211214
new DatabaseScript(
212215
"mytable",
213-
$@"SELECT EXISTS (SELECT 1 FROM mytable WHERE (SELECT count(*) FROM mytable)=100);",
216+
$@"SELECT EXISTS (SELECT * FROM `mytable` WHERE (SELECT COUNT(*) AS `count` FROM `mytable`) = 100);",
214217
DatabaseTestType.RecordCount,
215218
DatabaseKind.MySQL)
216219
}.ToExpectedObject();

src/QAToolKit.Engine.Database.Test/PostgresqlTestGeneratorTests.cs

+20-17
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public async Task PostgresqlTableExistScriptTest_Success()
2121
{
2222
new DatabaseScript(
2323
"mytable",
24-
$@"SELECT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'mytable');",
24+
$@"SELECT EXISTS(SELECT * FROM ""information_schema"".""tables"" WHERE ""table_name"" = 'mytable');",
2525
DatabaseTestType.ObjectExist,
2626
DatabaseKind.PostgreSQL)
2727
}.ToExpectedObject();
@@ -42,7 +42,7 @@ public async Task PostgresqlViewExistScriptTest_Success()
4242
{
4343
new DatabaseScript(
4444
"myview",
45-
$@"SELECT EXISTS (SELECT * FROM information_schema.views WHERE table_name = 'myview');",
45+
$@"SELECT EXISTS(SELECT * FROM ""information_schema"".""views"" WHERE ""table_name"" = 'myview');",
4646
DatabaseTestType.ObjectExist,
4747
DatabaseKind.PostgreSQL)
4848
}.ToExpectedObject();
@@ -63,7 +63,7 @@ public async Task PostgresqlStoredProcedureExistScriptTest_Success()
6363
{
6464
new DatabaseScript(
6565
"mystoredprocedure",
66-
$@"SELECT EXISTS (SELECT * FROM information_schema.routines WHERE routine_name = 'mystoredprocedure');",
66+
$@"SELECT EXISTS(SELECT * FROM ""information_schema"".""routines"" WHERE ""routine_name"" = 'mystoredprocedure');",
6767
DatabaseTestType.ObjectExist,
6868
DatabaseKind.PostgreSQL)
6969
}.ToExpectedObject();
@@ -84,12 +84,12 @@ public async Task PostgresqlMultipleTableExistScriptTest_Success()
8484
{
8585
new DatabaseScript(
8686
"table1",
87-
$@"SELECT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'table1');",
87+
$@"SELECT EXISTS(SELECT * FROM ""information_schema"".""tables"" WHERE ""table_name"" = 'table1');",
8888
DatabaseTestType.ObjectExist,
8989
DatabaseKind.PostgreSQL),
9090
new DatabaseScript(
9191
"table2",
92-
$@"SELECT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'table2');",
92+
$@"SELECT EXISTS(SELECT * FROM ""information_schema"".""tables"" WHERE ""table_name"" = 'table2');",
9393
DatabaseTestType.ObjectExist,
9494
DatabaseKind.PostgreSQL)
9595
}.ToExpectedObject();
@@ -110,12 +110,12 @@ public async Task PostgresqlMultipleViewExistScriptTest_Success()
110110
{
111111
new DatabaseScript(
112112
"view1",
113-
$@"SELECT EXISTS (SELECT * FROM information_schema.views WHERE table_name = 'view1');",
113+
$@"SELECT EXISTS(SELECT * FROM ""information_schema"".""views"" WHERE ""table_name"" = 'view1');",
114114
DatabaseTestType.ObjectExist,
115115
DatabaseKind.PostgreSQL),
116116
new DatabaseScript(
117117
"view2",
118-
$@"SELECT EXISTS (SELECT * FROM information_schema.views WHERE table_name = 'view2');",
118+
$@"SELECT EXISTS(SELECT * FROM ""information_schema"".""views"" WHERE ""table_name"" = 'view2');",
119119
DatabaseTestType.ObjectExist,
120120
DatabaseKind.PostgreSQL)
121121
}.ToExpectedObject();
@@ -136,12 +136,12 @@ public async Task PostgresqlMultipleStoredProcedureExistScriptTest_Success()
136136
{
137137
new DatabaseScript(
138138
"sp1",
139-
$@"SELECT EXISTS (SELECT * FROM information_schema.routines WHERE routine_name = 'sp1');",
139+
$@"SELECT EXISTS(SELECT * FROM ""information_schema"".""routines"" WHERE ""routine_name"" = 'sp1');",
140140
DatabaseTestType.ObjectExist,
141141
DatabaseKind.PostgreSQL),
142142
new DatabaseScript(
143143
"sp2",
144-
$@"SELECT EXISTS (SELECT * FROM information_schema.routines WHERE routine_name = 'sp2');",
144+
$@"SELECT EXISTS(SELECT * FROM ""information_schema"".""routines"" WHERE ""routine_name"" = 'sp2');",
145145
DatabaseTestType.ObjectExist,
146146
DatabaseKind.PostgreSQL)
147147
}.ToExpectedObject();
@@ -167,12 +167,14 @@ public async Task PostgresqlRecordExistScriptTest_Success()
167167
var generator = new PostgresqlTestGenerator(options =>
168168
{
169169
options.AddDatabaseRecordExitsRule(
170-
new List<DatabaseRule>()
170+
new List<DatabaseRecordExistRule>()
171171
{
172-
new DatabaseRule()
172+
new DatabaseRecordExistRule()
173173
{
174174
TableName = "mytable",
175-
PredicateValue = "name = 'myname'"
175+
ColumnName = "name",
176+
Operator = "=",
177+
Value = "myname"
176178
}
177179
});
178180
});
@@ -181,7 +183,7 @@ public async Task PostgresqlRecordExistScriptTest_Success()
181183
{
182184
new DatabaseScript(
183185
"mytable",
184-
$@"SELECT EXISTS (SELECT 1 FROM mytable WHERE name = 'myname');",
186+
$@"SELECT EXISTS(SELECT * FROM ""mytable"" WHERE ""name"" = 'myname');",
185187
DatabaseTestType.RecordExist,
186188
DatabaseKind.PostgreSQL)
187189
}.ToExpectedObject();
@@ -196,12 +198,13 @@ public async Task PostgresqlRecordCountScriptTest_Success()
196198
var generator = new PostgresqlTestGenerator(options =>
197199
{
198200
options.AddDatabaseRecordsCountRule(
199-
new List<DatabaseRule>()
201+
new List<DatabaseRecordCountRule>()
200202
{
201-
new DatabaseRule()
203+
new DatabaseRecordCountRule()
202204
{
203205
TableName = "mytable",
204-
PredicateValue = "=100"
206+
Operator = "=",
207+
Count = 100
205208
}
206209
});
207210
});
@@ -210,7 +213,7 @@ public async Task PostgresqlRecordCountScriptTest_Success()
210213
{
211214
new DatabaseScript(
212215
"mytable",
213-
$@"SELECT EXISTS (SELECT 1 FROM mytable WHERE (SELECT count(*) FROM mytable)=100);",
216+
$@"SELECT EXISTS (SELECT * FROM ""mytable"" WHERE (SELECT COUNT(*) AS ""count"" FROM ""mytable"") = 100);",
214217
DatabaseTestType.RecordCount,
215218
DatabaseKind.PostgreSQL)
216219
}.ToExpectedObject();

0 commit comments

Comments
 (0)