Skip to content

Commit

Permalink
merged to main
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaj committed Nov 23, 2020
2 parents 6c60a99 + 3ac38f0 commit a19e029
Show file tree
Hide file tree
Showing 17 changed files with 646 additions and 423 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.1.5</Version>
<Version>0.2.0</Version>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# QAToolKit Engine Database library
[![Build .NET Library](https://github.com/qatoolkit/qatoolkit-engine-database-net/workflows/.NET%20Core/badge.svg?branch=main)](https://github.com/qatoolkit/qatoolkit-engine-database-net/actions)
[![Build .NET Library](https://github.com/qatoolkit/qatoolkit-engine-database-net/workflows/Build%20.NET%20Library/badge.svg)](https://github.com/qatoolkit/qatoolkit-engine-database-net/actions)
[![CodeQL](https://github.com/qatoolkit/qatoolkit-engine-database-net/workflows/CodeQL%20Analyze/badge.svg)](https://github.com/qatoolkit/qatoolkit-engine-database-net/security/code-scanning)
[![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)
[![NuGet package](https://img.shields.io/nuget/v/QAToolKit.Engine.DataBase?label=QAToolKit.Engine.Database)](https://www.nuget.org/packages/QAToolKit.Engine.Database/)
Expand Down
62 changes: 52 additions & 10 deletions src/QAToolKit.Engine.Database.Test/MySqlTestGeneratorTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using ExpectedObjects;
using QAToolKit.Engine.Database.Generators;
using QAToolKit.Engine.Database.Models;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xunit;
Expand All @@ -15,7 +14,6 @@ public async Task MySqlTableExistScriptTest_Success()
{
var generator = new MySqlTestGenerator(options =>
{
options.UseDatabase(DatabaseKind.MySQL);
options.AddDatabaseObjectExitsRule(new string[] { "mytable" }, DatabaseObjectType.Table);
});

Expand All @@ -37,7 +35,6 @@ public async Task MySqlViewExistScriptTest_Success()
{
var generator = new MySqlTestGenerator(options =>
{
options.UseDatabase(DatabaseKind.MySQL);
options.AddDatabaseObjectExitsRule(new string[] { "myview" }, DatabaseObjectType.View);
});

Expand All @@ -59,7 +56,6 @@ public async Task MySqlStoredProcedureExistScriptTest_Success()
{
var generator = new MySqlTestGenerator(options =>
{
options.UseDatabase(DatabaseKind.MySQL);
options.AddDatabaseObjectExitsRule(new string[] { "mystoredprocedure" }, DatabaseObjectType.StoredProcedure);
});

Expand All @@ -81,7 +77,6 @@ public async Task MySqlMultipleTableExistScriptTest_Success()
{
var generator = new MySqlTestGenerator(options =>
{
options.UseDatabase(DatabaseKind.MySQL);
options.AddDatabaseObjectExitsRule(new string[] { "table1", "table2" }, DatabaseObjectType.Table);
});

Expand All @@ -108,7 +103,6 @@ public async Task MySqlMultipleViewExistScriptTest_Success()
{
var generator = new MySqlTestGenerator(options =>
{
options.UseDatabase(DatabaseKind.MySQL);
options.AddDatabaseObjectExitsRule(new string[] { "view1", "view2" }, DatabaseObjectType.View);
});

Expand All @@ -135,7 +129,6 @@ public async Task MySqlMultipleStoredProcedureExistScriptTest_Success()
{
var generator = new MySqlTestGenerator(options =>
{
options.UseDatabase(DatabaseKind.MySQL);
options.AddDatabaseObjectExitsRule(new string[] { "sp1", "sp2" }, DatabaseObjectType.StoredProcedure);
});

Expand Down Expand Up @@ -169,12 +162,61 @@ public void MySqlObjectExistScriptNullDbKindTest_Success()
}

[Fact]
public async Task MySqlObjectExistScriptNullOptionsTest_Fails()
public async Task MySqlRecordExistScriptTest_Success()
{
var generator = new MySqlTestGenerator();
var generator = new MySqlTestGenerator(options =>
{
options.AddDatabaseRecordExitsRule(
new List<DatabaseRule>()
{
new DatabaseRule()
{
TableName = "mytable",
PredicateValue = "= 'myname'"
}
});
});

var results = new List<DatabaseScript>
{
new DatabaseScript(
"mytable",
$@"SELECT EXISTS (SELECT 1 FROM mytable WHERE = '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 DatabaseRule()
{
TableName = "mytable",
PredicateValue = "=100"
}
});
});

var results = new List<DatabaseScript>
{
new DatabaseScript(
"mytable",
$@"SELECT EXISTS (SELECT 1 FROM mytable WHERE (SELECT count(*) FROM mytable)=100);",
DatabaseTestType.RecordCount,
DatabaseKind.MySQL)
}.ToExpectedObject();

results.ShouldEqual(await generator.Generate());
Assert.Equal(DatabaseKind.MySQL, generator.DatabaseKind);
await Assert.ThrowsAsync<ArgumentNullException>(async() => await generator.Generate());
}
}
}
62 changes: 52 additions & 10 deletions src/QAToolKit.Engine.Database.Test/PostgresqlTestGeneratorTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using ExpectedObjects;
using QAToolKit.Engine.Database.Generators;
using QAToolKit.Engine.Database.Models;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xunit;
Expand All @@ -15,7 +14,6 @@ public async Task PostgresqlTableExistScriptTest_Success()
{
var generator = new PostgresqlTestGenerator(options =>
{
options.UseDatabase(DatabaseKind.PostgreSQL);
options.AddDatabaseObjectExitsRule(new string[] { "mytable" }, DatabaseObjectType.Table);
});

Expand All @@ -37,7 +35,6 @@ public async Task PostgresqlViewExistScriptTest_Success()
{
var generator = new PostgresqlTestGenerator(options =>
{
options.UseDatabase(DatabaseKind.PostgreSQL);
options.AddDatabaseObjectExitsRule(new string[] { "myview" }, DatabaseObjectType.View);
});

Expand All @@ -59,7 +56,6 @@ public async Task PostgresqlStoredProcedureExistScriptTest_Success()
{
var generator = new PostgresqlTestGenerator(options =>
{
options.UseDatabase(DatabaseKind.PostgreSQL);
options.AddDatabaseObjectExitsRule(new string[] { "mystoredprocedure" }, DatabaseObjectType.StoredProcedure);
});

Expand All @@ -81,7 +77,6 @@ public async Task PostgresqlMultipleTableExistScriptTest_Success()
{
var generator = new PostgresqlTestGenerator(options =>
{
options.UseDatabase(DatabaseKind.PostgreSQL);
options.AddDatabaseObjectExitsRule(new string[] { "table1", "table2" }, DatabaseObjectType.Table);
});

Expand All @@ -108,7 +103,6 @@ public async Task PostgresqlMultipleViewExistScriptTest_Success()
{
var generator = new PostgresqlTestGenerator(options =>
{
options.UseDatabase(DatabaseKind.PostgreSQL);
options.AddDatabaseObjectExitsRule(new string[] { "view1", "view2" }, DatabaseObjectType.View);
});

Expand All @@ -135,7 +129,6 @@ public async Task PostgresqlMultipleStoredProcedureExistScriptTest_Success()
{
var generator = new PostgresqlTestGenerator(options =>
{
options.UseDatabase(DatabaseKind.PostgreSQL);
options.AddDatabaseObjectExitsRule(new string[] { "sp1", "sp2" }, DatabaseObjectType.StoredProcedure);
});

Expand Down Expand Up @@ -169,12 +162,61 @@ public void PostgresqlObjectExistScriptNullDbKindTest_Success()
}

[Fact]
public async Task PostgresqlObjectExistScriptNullOptionsTest_Fails()
public async Task PostgresqlRecordExistScriptTest_Success()
{
var generator = new PostgresqlTestGenerator();
var generator = new PostgresqlTestGenerator(options =>
{
options.AddDatabaseRecordExitsRule(
new List<DatabaseRule>()
{
new DatabaseRule()
{
TableName = "mytable",
PredicateValue = "= 'myname'"
}
});
});

var results = new List<DatabaseScript>
{
new DatabaseScript(
"mytable",
$@"SELECT EXISTS (SELECT 1 FROM mytable WHERE = 'myname');",
DatabaseTestType.RecordExist,
DatabaseKind.PostgreSQL)
}.ToExpectedObject();

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

[Fact]
public async Task PostgresqlRecordCountScriptTest_Success()
{
var generator = new PostgresqlTestGenerator(options =>
{
options.AddDatabaseRecordsCountRule(
new List<DatabaseRule>()
{
new DatabaseRule()
{
TableName = "mytable",
PredicateValue = "=100"
}
});
});

var results = new List<DatabaseScript>
{
new DatabaseScript(
"mytable",
$@"SELECT EXISTS (SELECT 1 FROM mytable WHERE (SELECT count(*) FROM mytable)=100);",
DatabaseTestType.RecordCount,
DatabaseKind.PostgreSQL)
}.ToExpectedObject();

results.ShouldEqual(await generator.Generate());
Assert.Equal(DatabaseKind.PostgreSQL, generator.DatabaseKind);
await Assert.ThrowsAsync<ArgumentNullException>(async () => await generator.Generate());
}
}
}
63 changes: 53 additions & 10 deletions src/QAToolKit.Engine.Database.Test/SqlServerTestGeneratorTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using ExpectedObjects;
using QAToolKit.Engine.Database.Generators;
using QAToolKit.Engine.Database.Models;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xunit;
Expand All @@ -15,7 +14,6 @@ public async Task SqlServerTableExistScriptTest_Success()
{
var generator = new SqlServerTestGenerator(options =>
{
options.UseDatabase(DatabaseKind.SQLServer);
options.AddDatabaseObjectExitsRule(new string[] { "mytable" }, DatabaseObjectType.Table);
});

Expand All @@ -37,7 +35,6 @@ public async Task SqlServerViewExistScriptTest_Success()
{
var generator = new SqlServerTestGenerator(options =>
{
options.UseDatabase(DatabaseKind.SQLServer);
options.AddDatabaseObjectExitsRule(new string[] { "myview" }, DatabaseObjectType.View);
});

Expand All @@ -59,7 +56,6 @@ public async Task SqlServerStoredProcedureExistScriptTest_Success()
{
var generator = new SqlServerTestGenerator(options =>
{
options.UseDatabase(DatabaseKind.SQLServer);
options.AddDatabaseObjectExitsRule(new string[] { "mystoredprocedure" }, DatabaseObjectType.StoredProcedure);
});

Expand All @@ -81,7 +77,6 @@ public async Task SqlServerMultipleTableExistScriptTest_Success()
{
var generator = new SqlServerTestGenerator(options =>
{
options.UseDatabase(DatabaseKind.SQLServer);
options.AddDatabaseObjectExitsRule(new string[] { "table1", "table2" }, DatabaseObjectType.Table);
});

Expand All @@ -108,7 +103,6 @@ public async Task SqlServerMultipleViewExistScriptTest_Success()
{
var generator = new SqlServerTestGenerator(options =>
{
options.UseDatabase(DatabaseKind.SQLServer);
options.AddDatabaseObjectExitsRule(new string[] { "view1", "view2" }, DatabaseObjectType.View);
});

Expand All @@ -135,7 +129,6 @@ public async Task SqlServerMultipleStoredProcedureExistScriptTest_Success()
{
var generator = new SqlServerTestGenerator(options =>
{
options.UseDatabase(DatabaseKind.SQLServer);
options.AddDatabaseObjectExitsRule(new string[] { "sp1", "sp2" }, DatabaseObjectType.StoredProcedure);
});

Expand Down Expand Up @@ -168,13 +161,63 @@ public void SqlServerObjectExistScriptNullDbKindTest_Success()
Assert.Equal(DatabaseKind.SQLServer, generator.DatabaseKind);
}


[Fact]
public async Task SqlServerObjectExistScriptNullOptionsTest_Fails()
public async Task SqlServerRecordExistScriptTest_Success()
{
var generator = new SqlServerTestGenerator();
var generator = new SqlServerTestGenerator(options =>
{
options.AddDatabaseRecordExitsRule(
new List<DatabaseRule>()
{
new DatabaseRule()
{
TableName = "mytable",
PredicateValue = "= 'myname'"
}
});
});

var results = new List<DatabaseScript>
{
new DatabaseScript(
"mytable",
$@"IF EXISTS(SELECT 1 FROM mytable WHERE = 'myname') BEGIN Select 1 END ELSE BEGIN Select 0 END",
DatabaseTestType.RecordExist,
DatabaseKind.SQLServer)
}.ToExpectedObject();

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

[Fact]
public async Task SqlServerRecordCountScriptTest_Success()
{
var generator = new SqlServerTestGenerator(options =>
{
options.AddDatabaseRecordsCountRule(
new List<DatabaseRule>()
{
new DatabaseRule()
{
TableName = "mytable",
PredicateValue = "=100"
}
});
});

var results = new List<DatabaseScript>
{
new DatabaseScript(
"mytable",
$@"IF EXISTS(SELECT 1 FROM mytable WHERE (SELECT count(*) FROM mytable)=100) BEGIN Select 1 END ELSE BEGIN Select 0 END",
DatabaseTestType.RecordCount,
DatabaseKind.SQLServer)
}.ToExpectedObject();

results.ShouldEqual(await generator.Generate());
Assert.Equal(DatabaseKind.SQLServer, generator.DatabaseKind);
await Assert.ThrowsAsync<ArgumentNullException>(async () => await generator.Generate());
}
}
}
Loading

0 comments on commit a19e029

Please sign in to comment.