Skip to content

Commit ff25884

Browse files
authored
Readme and interfaces from Core library
* moved interfaces to core library * readme file updated, small test fix
1 parent a19e029 commit ff25884

File tree

9 files changed

+77
-45
lines changed

9 files changed

+77
-45
lines changed

README.md

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,74 @@
44
[![Sonarcloud Quality gate](https://github.com/qatoolkit/qatoolkit-engine-database-net/workflows/Sonarqube%20Analyze/badge.svg)](https://sonarcloud.io/dashboard?id=qatoolkit_qatoolkit-engine-database-net)
55
[![NuGet package](https://img.shields.io/nuget/v/QAToolKit.Engine.DataBase?label=QAToolKit.Engine.Database)](https://www.nuget.org/packages/QAToolKit.Engine.Database/)
66

7-
**Not ready for release.**
7+
## Description
8+
`QAToolKit.Engine.Database` is a .NET standard library, which can be used to do database fitness tests. For example, if you want to test that table is present in database, or certain number of records exist in specific table or if a record exists.
9+
10+
`DatabaseTestType` enumeration currently described those three test types:
11+
- `ObjectExits`: Check if table, view or stored procedure exists.
12+
- `RecordCount`: Check if record count in specific table equals an expression.
13+
- `RecordExist`: Check if a record exists in specific table.
14+
15+
Currently supports only relational databases: `SQLServer`, `MySQL` and `PostgreSQL`.
16+
17+
## Sample
18+
19+
```csharp
20+
var generator = new SqlServerTestGenerator(options =>
21+
{
22+
options.AddDatabaseObjectExitsRule(new string[] { "mytable" }, DatabaseObjectType.Table);
23+
24+
options.AddDatabaseRecordExitsRule(
25+
new List<DatabaseRule>()
26+
{
27+
new DatabaseRule()
28+
{
29+
TableName = "mytable",
30+
PredicateValue = "name = 'myname'"
31+
}
32+
});
33+
34+
options.AddDatabaseRecordsCountRule(
35+
new List<DatabaseRule>()
36+
{
37+
new DatabaseRule()
38+
{
39+
TableName = "mytable",
40+
PredicateValue = "=100"
41+
}
42+
});
43+
});
44+
45+
List<DatabaseScript> scripts = await generator.Generate();
46+
```
47+
The code above will generate a SQLServer `DatabaseScript` list, which will be used by runner to run the tests against database.
48+
49+
Above example adds all three test types to the generator:
50+
- `AddDatabaseObjectExitsRule`: will check if a table `mytable` exists in the database.
51+
- `AddDatabaseRecordExitsRule`: will check if a record in table `mytable` with `name` equals `myname` exists.
52+
- `AddDatabaseRecordsCountRule`: will check if there is exactly 100 records in the `mytable` table.
53+
54+
Alternatively if you want to use `MySQL` or `PostgreSQL` generators, you can use MySqlTestGenerator` or `PostgresqlTestGenerator` respectively.
55+
56+
To run the tests, we create a `SqlServerTestRunner` runner:
57+
58+
```csharp
59+
var runner = new SqlServerTestRunner(scripts, options =>
60+
{
61+
options.AddSQLServerConnection("server=localhost;user=sa;password=Mihaj666.;Initial Catalog=");
62+
});
63+
64+
List<DatabaseScriptResult> results = await runner.Run();
65+
```
66+
67+
Alternatively if you want to use `MySQL` or `PostgreSQL` runners, you can use MySqlTestRunner` or `PostgresqlTestRunner` respectively.
68+
69+
Please note that **your user must have correct database permissions**. I suggest a read-only permissions that can also access `sys` or `information_schema` schemas.
70+
71+
## To-Do
72+
73+
- Implement asserters for processing the `DatabaseScriptResult` list.
74+
- Add more test types if necessary.
875

976
## License
1077

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public async Task MySqlRecordExistScriptTest_Success()
172172
new DatabaseRule()
173173
{
174174
TableName = "mytable",
175-
PredicateValue = "= 'myname'"
175+
PredicateValue = "name = 'myname'"
176176
}
177177
});
178178
});
@@ -181,7 +181,7 @@ public async Task MySqlRecordExistScriptTest_Success()
181181
{
182182
new DatabaseScript(
183183
"mytable",
184-
$@"SELECT EXISTS (SELECT 1 FROM mytable WHERE = 'myname');",
184+
$@"SELECT EXISTS (SELECT 1 FROM mytable WHERE name = 'myname');",
185185
DatabaseTestType.RecordExist,
186186
DatabaseKind.MySQL)
187187
}.ToExpectedObject();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public async Task PostgresqlRecordExistScriptTest_Success()
172172
new DatabaseRule()
173173
{
174174
TableName = "mytable",
175-
PredicateValue = "= 'myname'"
175+
PredicateValue = "name = 'myname'"
176176
}
177177
});
178178
});
@@ -181,7 +181,7 @@ public async Task PostgresqlRecordExistScriptTest_Success()
181181
{
182182
new DatabaseScript(
183183
"mytable",
184-
$@"SELECT EXISTS (SELECT 1 FROM mytable WHERE = 'myname');",
184+
$@"SELECT EXISTS (SELECT 1 FROM mytable WHERE name = 'myname');",
185185
DatabaseTestType.RecordExist,
186186
DatabaseKind.PostgreSQL)
187187
}.ToExpectedObject();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public async Task SqlServerRecordExistScriptTest_Success()
173173
new DatabaseRule()
174174
{
175175
TableName = "mytable",
176-
PredicateValue = "= 'myname'"
176+
PredicateValue = "name = 'myname'"
177177
}
178178
});
179179
});
@@ -182,7 +182,7 @@ public async Task SqlServerRecordExistScriptTest_Success()
182182
{
183183
new DatabaseScript(
184184
"mytable",
185-
$@"IF EXISTS(SELECT 1 FROM mytable WHERE = 'myname') BEGIN Select 1 END ELSE BEGIN Select 0 END",
185+
$@"IF EXISTS(SELECT 1 FROM mytable WHERE name = 'myname') BEGIN Select 1 END ELSE BEGIN Select 0 END",
186186
DatabaseTestType.RecordExist,
187187
DatabaseKind.SQLServer)
188188
}.ToExpectedObject();

src/QAToolKit.Engine.Database/Generators/RelationalDatabaseTestGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using QAToolKit.Engine.Database.Interfaces;
1+
using QAToolKit.Core.Interfaces;
22
using QAToolKit.Engine.Database.Models;
33
using System;
44
using System.Collections.Generic;

src/QAToolKit.Engine.Database/Interfaces/IDatabaseTestGenerator.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/QAToolKit.Engine.Database/Interfaces/IDatabaseTestRunner.cs

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/QAToolKit.Engine.Database/QAToolKit.Engine.Database.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<PackageReference Include="MySql.Data" Version="8.0.22" />
3939
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
4040
<PackageReference Include="Npgsql" Version="5.0.0" />
41-
<PackageReference Include="QAToolKit.Core" Version="0.3.0" />
41+
<PackageReference Include="QAToolKit.Core" Version="0.3.2" />
4242
<PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
4343
</ItemGroup>
4444
</Project>

src/QAToolKit.Engine.Database/Runners/RelationalDatabaseTestRunner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using Dapper;
2-
using QAToolKit.Engine.Database.Interfaces;
32
using QAToolKit.Engine.Database.Models;
43
using System;
54
using System.Collections.Generic;
65
using System.Data;
76
using System.Threading.Tasks;
7+
using QAToolKit.Core.Interfaces;
88

99
namespace QAToolKit.Engine.Database.Runners
1010
{

0 commit comments

Comments
 (0)