单元测试:增加App类单元测试

This commit is contained in:
Argo-Surface 2019-02-25 15:14:27 +08:00
parent 473641b155
commit 45d2394f15
3 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,40 @@
using System.Linq;
using Xunit;
namespace Bootstrap.DataAccess
{
[Collection("SQLServerContext")]
public class AppTest
{
[Fact]
public void RetrievesByRoleId_Ok()
{
var db = DbManager.Create();
db.Execute("delete from RoleApp");
var rid = new Role().Retrieves().Where(r => r.RoleName == "Administrators").First().Id;
var app = new App();
Assert.NotEmpty(app.RetrievesByRoleId(rid));
}
[Fact]
public void RetrievesByUserName_Ok()
{
var app = new App();
Assert.NotEmpty(app.RetrievesByUserName("Admin"));
}
[Fact]
public void SaveByRoleId_Ok()
{
var db = DbManager.Create();
db.Execute("delete from RoleApp");
var rid = new Role().Retrieves().Where(r => r.RoleName == "Administrators").First().Id;
var app = new App();
Assert.True(app.SaveByRoleId(rid, new string[] { "1", "2" }));
var count = db.ExecuteScalar<int>("select count(Id) from RoleApp where RoleID = @0", rid);
Assert.Equal(2, count);
}
}
}

View File

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

View File

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