test: 增加 DBLog 单元测试
This commit is contained in:
parent
39c0d4965c
commit
0a563c6306
|
@ -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() {
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
using Xunit;
|
||||
|
||||
namespace Bootstrap.DataAccess.MySql
|
||||
{
|
||||
[Collection("MySqlContext")]
|
||||
public class DBLogTest : SqlServer.DBLogTest
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
using Xunit;
|
||||
|
||||
namespace Bootstrap.DataAccess.SQLite
|
||||
{
|
||||
[Collection("SQLiteContext")]
|
||||
public class DBLogTest : SqlServer.DBLogTest
|
||||
{
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue