test: 增加 DBLog 单元测试

This commit is contained in:
Argo Zhang 2019-10-08 20:43:00 +08:00
parent 39c0d4965c
commit 0a563c6306
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
7 changed files with 65 additions and 3 deletions

View File

@ -38,7 +38,7 @@
function runUnitTest() {
write-host "dotnet test test\UnitTest" -ForegroundColor Cyan
dotnet test test\UnitTest --filter "FullyQualifiedName!~MySql" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Include="[Bootstrap*]*" /p:ExcludeByFile="..\..\src\admin\Bootstrap.Admin\Program.cs%2c..\..\src\admin\Bootstrap.Admin\Startup.cs" /p:CoverletOutput=..\..\
dotnet test test\UnitTest /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[*]*.MySql.*" /p:ExcludeByFile="..\..\src\admin\Bootstrap.Admin\Program.cs%2c..\..\src\admin\Bootstrap.Admin\Startup.cs%2c..\..\src\admin\Bootstrap.Admin\Extensions\SMSExtensions.cs%2c..\..\src\admin\Bootstrap.DataAccess\AutoDB.cs" /p:CoverletOutput=..\..\
}
function coverallUnitTest() {

View File

@ -18,7 +18,7 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="connectionName"></param>
/// <param name="keepAlive"></param>
/// <param name="log">是否记录日志</param>
/// <param name="enableLog">是否记录日志</param>
/// <returns></returns>
public static IDatabase Create(string connectionName = null, bool keepAlive = false, bool enableLog = true)
{

View File

@ -81,7 +81,7 @@ namespace Bootstrap.DataAccess
while (_messageQueue.TryTake(out var log))
{
logs.Add(log);
};
}
if (logs.Any())
{
using (var db = DbManager.Create(enableLog: false))

View File

@ -0,0 +1,14 @@
using Xunit;
namespace Bootstrap.DataAccess.MongoDB
{
[Collection("MongoContext")]
public class DBLogTest : SqlServer.DBLogTest
{
[Fact]
public override void Save_Ok()
{
Assert.True(new DBLog().Save(null));
}
}
}

View File

@ -0,0 +1,10 @@
using Xunit;
namespace Bootstrap.DataAccess.MySql
{
[Collection("MySqlContext")]
public class DBLogTest : SqlServer.DBLogTest
{
}
}

View File

@ -0,0 +1,28 @@
using System;
using Xunit;
namespace Bootstrap.DataAccess.SqlServer
{
[Collection("SQLServerContext")]
public class DBLogTest
{
[Fact]
public virtual void Save_Ok()
{
var log = new DBLog()
{
Id = "",
LogTime = DateTime.Now,
SQL = "UnitTest",
UserName = "UniTest"
};
Assert.True(log.Save(log));
}
[Fact]
public void Save_Exception()
{
Assert.Throws<ArgumentNullException>(() => new DBLog().Save(null));
}
}
}

View File

@ -0,0 +1,10 @@
using Xunit;
namespace Bootstrap.DataAccess.SQLite
{
[Collection("SQLiteContext")]
public class DBLogTest : SqlServer.DBLogTest
{
}
}