Skip to content

Commit

Permalink
merged from main
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaj committed Nov 27, 2020
2 parents 0dfafac + 8070365 commit 54eab50
Show file tree
Hide file tree
Showing 13 changed files with 222 additions and 99 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<Version>0.2.0</Version>
<Version>0.2.5</Version>
</PropertyGroup>
</Project>
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,25 @@ var generator = new SqlServerTestGenerator(options =>
{
options.AddDatabaseObjectExitsRule(new string[] { "mytable" }, DatabaseObjectType.Table);

options.AddDatabaseRecordExitsRule(
new List<DatabaseRule>()
options.AddDatabaseRecordExitsRule(new List<DatabaseRecordExistRule>()
{
new DatabaseRule()
new DatabaseRecordExistRule()
{
TableName = "mytable",
PredicateValue = "name = 'myname'"
ColumnName = "name",
Operator = "=",
Value = "myname"
}
});

options.AddDatabaseRecordsCountRule(
new List<DatabaseRule>()
options.AddDatabaseRecordsCountRule(new List<DatabaseRecordCountRule>()
{
new DatabaseRule()
new DatabaseRecordCountRule()
{
TableName = "mytable",
PredicateValue = "=100"
}
TableName = "mytable",
Count = 100,
Operator = "="
}
});
});

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

List<DatabaseScriptResult> results = await runner.Run();
Expand Down
39 changes: 21 additions & 18 deletions src/QAToolKit.Engine.Database.Test/MySqlTestGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public async Task MySqlTableExistScriptTest_Success()
{
new DatabaseScript(
"mytable",
$@"SELECT EXISTS(SELECT * FROM information_schema.tables WHERE table_name = 'mytable');",
$@"SELECT EXISTS(SELECT * FROM `information_schema`.`tables` WHERE `table_name` = 'mytable');",
DatabaseTestType.ObjectExist,
DatabaseKind.MySQL)
}.ToExpectedObject();
Expand All @@ -42,7 +42,7 @@ public async Task MySqlViewExistScriptTest_Success()
{
new DatabaseScript(
"myview",
$@"SELECT EXISTS(SELECT * FROM information_schema.views WHERE table_name = 'myview');",
$@"SELECT EXISTS(SELECT * FROM `information_schema`.`views` WHERE `table_name` = 'myview');",
DatabaseTestType.ObjectExist,
DatabaseKind.MySQL)
}.ToExpectedObject();
Expand All @@ -63,7 +63,7 @@ public async Task MySqlStoredProcedureExistScriptTest_Success()
{
new DatabaseScript(
"mystoredprocedure",
$@"SELECT EXISTS(SELECT * FROM information_schema.routines WHERE routine_name = 'mystoredprocedure');",
$@"SELECT EXISTS(SELECT * FROM `information_schema`.`routines` WHERE `routine_name` = 'mystoredprocedure');",
DatabaseTestType.ObjectExist,
DatabaseKind.MySQL)
}.ToExpectedObject();
Expand All @@ -84,12 +84,12 @@ public async Task MySqlMultipleTableExistScriptTest_Success()
{
new DatabaseScript(
"table1",
$@"SELECT EXISTS(SELECT * FROM information_schema.tables WHERE table_name = 'table1');",
$@"SELECT EXISTS(SELECT * FROM `information_schema`.`tables` WHERE `table_name` = 'table1');",
DatabaseTestType.ObjectExist,
DatabaseKind.MySQL),
new DatabaseScript(
"table2",
$@"SELECT EXISTS(SELECT * FROM information_schema.tables WHERE table_name = 'table2');",
$@"SELECT EXISTS(SELECT * FROM `information_schema`.`tables` WHERE `table_name` = 'table2');",
DatabaseTestType.ObjectExist,
DatabaseKind.MySQL)
}.ToExpectedObject();
Expand All @@ -110,12 +110,12 @@ public async Task MySqlMultipleViewExistScriptTest_Success()
{
new DatabaseScript(
"view1",
$@"SELECT EXISTS(SELECT * FROM information_schema.views WHERE table_name = 'view1');",
$@"SELECT EXISTS(SELECT * FROM `information_schema`.`views` WHERE `table_name` = 'view1');",
DatabaseTestType.ObjectExist,
DatabaseKind.MySQL),
new DatabaseScript(
"view2",
$@"SELECT EXISTS(SELECT * FROM information_schema.views WHERE table_name = 'view2');",
$@"SELECT EXISTS(SELECT * FROM `information_schema`.`views` WHERE `table_name` = 'view2');",
DatabaseTestType.ObjectExist,
DatabaseKind.MySQL)
}.ToExpectedObject();
Expand All @@ -136,12 +136,12 @@ public async Task MySqlMultipleStoredProcedureExistScriptTest_Success()
{
new DatabaseScript(
"sp1",
$@"SELECT EXISTS(SELECT * FROM information_schema.routines WHERE routine_name = 'sp1');",
$@"SELECT EXISTS(SELECT * FROM `information_schema`.`routines` WHERE `routine_name` = 'sp1');",
DatabaseTestType.ObjectExist,
DatabaseKind.MySQL),
new DatabaseScript(
"sp2",
$@"SELECT EXISTS(SELECT * FROM information_schema.routines WHERE routine_name = 'sp2');",
$@"SELECT EXISTS(SELECT * FROM `information_schema`.`routines` WHERE `routine_name` = 'sp2');",
DatabaseTestType.ObjectExist,
DatabaseKind.MySQL)
}.ToExpectedObject();
Expand All @@ -167,12 +167,14 @@ public async Task MySqlRecordExistScriptTest_Success()
var generator = new MySqlTestGenerator(options =>
{
options.AddDatabaseRecordExitsRule(
new List<DatabaseRule>()
new List<DatabaseRecordExistRule>()
{
new DatabaseRule()
new DatabaseRecordExistRule()
{
TableName = "mytable",
PredicateValue = "name = 'myname'"
ColumnName = "name",
Operator = "=",
Value = "myname"
}
});
});
Expand All @@ -181,27 +183,28 @@ public async Task MySqlRecordExistScriptTest_Success()
{
new DatabaseScript(
"mytable",
$@"SELECT EXISTS (SELECT 1 FROM mytable WHERE name = 'myname');",
$@"SELECT EXISTS(SELECT * FROM `mytable` WHERE `name` = 'myname');",
DatabaseTestType.RecordExist,
DatabaseKind.MySQL)
}.ToExpectedObject();

results.ShouldEqual(await generator.Generate());
Assert.Equal(DatabaseKind.MySQL, generator.DatabaseKind);
}

[Fact]
public async Task MySqlRecordCountScriptTest_Success()
{
var generator = new MySqlTestGenerator(options =>
{
options.AddDatabaseRecordsCountRule(
new List<DatabaseRule>()
new List<DatabaseRecordCountRule>()
{
new DatabaseRule()
new DatabaseRecordCountRule()
{
TableName = "mytable",
PredicateValue = "=100"
Operator = "=",
Count = 100
}
});
});
Expand All @@ -210,7 +213,7 @@ public async Task MySqlRecordCountScriptTest_Success()
{
new DatabaseScript(
"mytable",
$@"SELECT EXISTS (SELECT 1 FROM mytable WHERE (SELECT count(*) FROM mytable)=100);",
$@"SELECT EXISTS (SELECT * FROM `mytable` WHERE (SELECT COUNT(*) AS `count` FROM `mytable`) = 100);",
DatabaseTestType.RecordCount,
DatabaseKind.MySQL)
}.ToExpectedObject();
Expand Down
37 changes: 20 additions & 17 deletions src/QAToolKit.Engine.Database.Test/PostgresqlTestGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public async Task PostgresqlTableExistScriptTest_Success()
{
new DatabaseScript(
"mytable",
$@"SELECT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'mytable');",
$@"SELECT EXISTS(SELECT * FROM ""information_schema"".""tables"" WHERE ""table_name"" = 'mytable');",
DatabaseTestType.ObjectExist,
DatabaseKind.PostgreSQL)
}.ToExpectedObject();
Expand All @@ -42,7 +42,7 @@ public async Task PostgresqlViewExistScriptTest_Success()
{
new DatabaseScript(
"myview",
$@"SELECT EXISTS (SELECT * FROM information_schema.views WHERE table_name = 'myview');",
$@"SELECT EXISTS(SELECT * FROM ""information_schema"".""views"" WHERE ""table_name"" = 'myview');",
DatabaseTestType.ObjectExist,
DatabaseKind.PostgreSQL)
}.ToExpectedObject();
Expand All @@ -63,7 +63,7 @@ public async Task PostgresqlStoredProcedureExistScriptTest_Success()
{
new DatabaseScript(
"mystoredprocedure",
$@"SELECT EXISTS (SELECT * FROM information_schema.routines WHERE routine_name = 'mystoredprocedure');",
$@"SELECT EXISTS(SELECT * FROM ""information_schema"".""routines"" WHERE ""routine_name"" = 'mystoredprocedure');",
DatabaseTestType.ObjectExist,
DatabaseKind.PostgreSQL)
}.ToExpectedObject();
Expand All @@ -84,12 +84,12 @@ public async Task PostgresqlMultipleTableExistScriptTest_Success()
{
new DatabaseScript(
"table1",
$@"SELECT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'table1');",
$@"SELECT EXISTS(SELECT * FROM ""information_schema"".""tables"" WHERE ""table_name"" = 'table1');",
DatabaseTestType.ObjectExist,
DatabaseKind.PostgreSQL),
new DatabaseScript(
"table2",
$@"SELECT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'table2');",
$@"SELECT EXISTS(SELECT * FROM ""information_schema"".""tables"" WHERE ""table_name"" = 'table2');",
DatabaseTestType.ObjectExist,
DatabaseKind.PostgreSQL)
}.ToExpectedObject();
Expand All @@ -110,12 +110,12 @@ public async Task PostgresqlMultipleViewExistScriptTest_Success()
{
new DatabaseScript(
"view1",
$@"SELECT EXISTS (SELECT * FROM information_schema.views WHERE table_name = 'view1');",
$@"SELECT EXISTS(SELECT * FROM ""information_schema"".""views"" WHERE ""table_name"" = 'view1');",
DatabaseTestType.ObjectExist,
DatabaseKind.PostgreSQL),
new DatabaseScript(
"view2",
$@"SELECT EXISTS (SELECT * FROM information_schema.views WHERE table_name = 'view2');",
$@"SELECT EXISTS(SELECT * FROM ""information_schema"".""views"" WHERE ""table_name"" = 'view2');",
DatabaseTestType.ObjectExist,
DatabaseKind.PostgreSQL)
}.ToExpectedObject();
Expand All @@ -136,12 +136,12 @@ public async Task PostgresqlMultipleStoredProcedureExistScriptTest_Success()
{
new DatabaseScript(
"sp1",
$@"SELECT EXISTS (SELECT * FROM information_schema.routines WHERE routine_name = 'sp1');",
$@"SELECT EXISTS(SELECT * FROM ""information_schema"".""routines"" WHERE ""routine_name"" = 'sp1');",
DatabaseTestType.ObjectExist,
DatabaseKind.PostgreSQL),
new DatabaseScript(
"sp2",
$@"SELECT EXISTS (SELECT * FROM information_schema.routines WHERE routine_name = 'sp2');",
$@"SELECT EXISTS(SELECT * FROM ""information_schema"".""routines"" WHERE ""routine_name"" = 'sp2');",
DatabaseTestType.ObjectExist,
DatabaseKind.PostgreSQL)
}.ToExpectedObject();
Expand All @@ -167,12 +167,14 @@ public async Task PostgresqlRecordExistScriptTest_Success()
var generator = new PostgresqlTestGenerator(options =>
{
options.AddDatabaseRecordExitsRule(
new List<DatabaseRule>()
new List<DatabaseRecordExistRule>()
{
new DatabaseRule()
new DatabaseRecordExistRule()
{
TableName = "mytable",
PredicateValue = "name = 'myname'"
ColumnName = "name",
Operator = "=",
Value = "myname"
}
});
});
Expand All @@ -181,7 +183,7 @@ public async Task PostgresqlRecordExistScriptTest_Success()
{
new DatabaseScript(
"mytable",
$@"SELECT EXISTS (SELECT 1 FROM mytable WHERE name = 'myname');",
$@"SELECT EXISTS(SELECT * FROM ""mytable"" WHERE ""name"" = 'myname');",
DatabaseTestType.RecordExist,
DatabaseKind.PostgreSQL)
}.ToExpectedObject();
Expand All @@ -196,12 +198,13 @@ public async Task PostgresqlRecordCountScriptTest_Success()
var generator = new PostgresqlTestGenerator(options =>
{
options.AddDatabaseRecordsCountRule(
new List<DatabaseRule>()
new List<DatabaseRecordCountRule>()
{
new DatabaseRule()
new DatabaseRecordCountRule()
{
TableName = "mytable",
PredicateValue = "=100"
Operator = "=",
Count = 100
}
});
});
Expand All @@ -210,7 +213,7 @@ public async Task PostgresqlRecordCountScriptTest_Success()
{
new DatabaseScript(
"mytable",
$@"SELECT EXISTS (SELECT 1 FROM mytable WHERE (SELECT count(*) FROM mytable)=100);",
$@"SELECT EXISTS (SELECT * FROM ""mytable"" WHERE (SELECT COUNT(*) AS ""count"" FROM ""mytable"") = 100);",
DatabaseTestType.RecordCount,
DatabaseKind.PostgreSQL)
}.ToExpectedObject();
Expand Down
Loading

0 comments on commit 54eab50

Please sign in to comment.