test: 修复单元测试一起运行时出错问题
This commit is contained in:
parent
d2e56e85e9
commit
8a32aecbf5
|
@ -353,5 +353,5 @@ Bootstrap.Admin.xml
|
||||||
###### -- Custom Ignore Section, Make sure all files you add to the git repo are below this line -- ######
|
###### -- Custom Ignore Section, Make sure all files you add to the git repo are below this line -- ######
|
||||||
|
|
||||||
# Coverage
|
# Coverage
|
||||||
coverage.xml
|
coverage*.xml
|
||||||
tools/
|
tools/
|
|
@ -126,11 +126,6 @@ namespace Bootstrap.Admin
|
||||||
TestHelper.SQLServerConnectionString = con.GetConnectionString("sqlserver-app");
|
TestHelper.SQLServerConnectionString = con.GetConnectionString("sqlserver-app");
|
||||||
TestHelper.MySqlConnectionString = con.GetConnectionString("mysql-app");
|
TestHelper.MySqlConnectionString = con.GetConnectionString("mysql-app");
|
||||||
TestHelper.NpgSqlConnectionString = con.GetConnectionString("npgsql-app");
|
TestHelper.NpgSqlConnectionString = con.GetConnectionString("npgsql-app");
|
||||||
builder.ConfigureAppConfiguration(app => app.AddInMemoryCollection(new KeyValuePair<string, string>[] {
|
|
||||||
new KeyValuePair<string, string>("Logging:LogLevel:Default", "Error"),
|
|
||||||
new KeyValuePair<string, string>("Logging:LogLevel:System", "Error"),
|
|
||||||
new KeyValuePair<string, string>("Logging:LogLevel:Microsoft", "Error")
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -141,6 +136,7 @@ namespace Bootstrap.Admin
|
||||||
new KeyValuePair<string, string>("MongoDB", con.GetValue("MongoDB", "UnitTest"))
|
new KeyValuePair<string, string>("MongoDB", con.GetValue("MongoDB", "UnitTest"))
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
builder.ConfigureAppConfiguration(app => app.AddJsonFile(TestHelper.RetrievePath($"UnitTest{Path.DirectorySeparatorChar}appsettings.unittest.json"), false, true));
|
||||||
TestHelper.SQLiteConnectionString = con.GetConnectionString("sqlite");
|
TestHelper.SQLiteConnectionString = con.GetConnectionString("sqlite");
|
||||||
TestHelper.ConfigureWebHost(builder);
|
TestHelper.ConfigureWebHost(builder);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace Bootstrap.Admin.Api.SqlServer
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void Get_Ok()
|
public async void Get_Ok()
|
||||||
{
|
{
|
||||||
var rid = new Role().Retrieves().Where(r => r.RoleName == "Administrators").First().Id;
|
var rid = RoleHelper.Retrieves().Where(r => r.RoleName == "Administrators").First().Id;
|
||||||
var cates = await Client.GetAsJsonAsync<IEnumerable<App>>(rid);
|
var cates = await Client.GetAsJsonAsync<IEnumerable<App>>(rid);
|
||||||
Assert.NotEmpty(cates);
|
Assert.NotEmpty(cates);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,13 +23,10 @@ namespace Bootstrap.Admin.Api.SqlServer
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void PostAndDelete_Ok()
|
public async void PostAndDelete_Ok()
|
||||||
{
|
{
|
||||||
var dict = new Dict();
|
|
||||||
dict.Delete(new Dict().RetrieveDicts().Where(d => d.Category == "UnitTest-Category").Select(d => d.Id));
|
|
||||||
|
|
||||||
var ret = await Client.PostAsJsonAsync<BootstrapDict, bool>("", new BootstrapDict() { Name = "UnitTest-Dict", Category = "UnitTest-Category", Code = "0", Define = 0 });
|
var ret = await Client.PostAsJsonAsync<BootstrapDict, bool>("", new BootstrapDict() { Name = "UnitTest-Dict", Category = "UnitTest-Category", Code = "0", Define = 0 });
|
||||||
Assert.True(ret);
|
Assert.True(ret);
|
||||||
|
|
||||||
var ids = dict.RetrieveDicts().Where(d => d.Name == "UnitTest-Dict").Select(d => d.Id);
|
var ids = DictHelper.RetrieveDicts().Where(d => d.Name == "UnitTest-Dict").Select(d => d.Id);
|
||||||
Assert.True(await Client.DeleteAsJsonAsync<IEnumerable<string>, bool>(ids));
|
Assert.True(await Client.DeleteAsJsonAsync<IEnumerable<string>, bool>(ids));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ namespace Bootstrap.Admin.Api.SqlServer
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void GetById_Ok()
|
public async void GetById_Ok()
|
||||||
{
|
{
|
||||||
var id = new Group().Retrieves().Where(gp => gp.GroupName == "Admin").First().Id;
|
var id = GroupHelper.Retrieves().Where(gp => gp.GroupName == "Admin").First().Id;
|
||||||
var g = await Client.GetAsJsonAsync<Group>(id);
|
var g = await Client.GetAsJsonAsync<Group>(id);
|
||||||
Assert.Equal("Admin", g.GroupName);
|
Assert.Equal("Admin", g.GroupName);
|
||||||
}
|
}
|
||||||
|
@ -33,18 +33,18 @@ namespace Bootstrap.Admin.Api.SqlServer
|
||||||
var ret = await Client.PostAsJsonAsync<Group, bool>("", new Group() { GroupName = "UnitTest-Group", Description = "UnitTest-Desc" });
|
var ret = await Client.PostAsJsonAsync<Group, bool>("", new Group() { GroupName = "UnitTest-Group", Description = "UnitTest-Desc" });
|
||||||
Assert.True(ret);
|
Assert.True(ret);
|
||||||
|
|
||||||
var ids = new Group().Retrieves().Where(d => d.GroupName == "UnitTest-Group").Select(d => d.Id);
|
var ids = GroupHelper.Retrieves().Where(d => d.GroupName == "UnitTest-Group").Select(d => d.Id);
|
||||||
Assert.True(await Client.DeleteAsJsonAsync<IEnumerable<string>, bool>(ids));
|
Assert.True(await Client.DeleteAsJsonAsync<IEnumerable<string>, bool>(ids));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void PostById_Ok()
|
public async void PostById_Ok()
|
||||||
{
|
{
|
||||||
var uid = new User().Retrieves().Where(u => u.UserName == "Admin").First().Id;
|
var uid = UserHelper.Retrieves().Where(u => u.UserName == "Admin").First().Id;
|
||||||
var ret = await Client.PostAsJsonAsync<string, IEnumerable<Group>>($"{uid}?type=user", string.Empty);
|
var ret = await Client.PostAsJsonAsync<string, IEnumerable<Group>>($"{uid}?type=user", string.Empty);
|
||||||
Assert.NotEmpty(ret);
|
Assert.NotEmpty(ret);
|
||||||
|
|
||||||
var rid = new Role().Retrieves().Where(r => r.RoleName == "Administrators").First().Id;
|
var rid = RoleHelper.Retrieves().Where(r => r.RoleName == "Administrators").First().Id;
|
||||||
ret = await Client.PostAsJsonAsync<string, IEnumerable<Group>>($"{rid}?type=role", string.Empty);
|
ret = await Client.PostAsJsonAsync<string, IEnumerable<Group>>($"{rid}?type=role", string.Empty);
|
||||||
Assert.NotEmpty(ret);
|
Assert.NotEmpty(ret);
|
||||||
}
|
}
|
||||||
|
@ -52,12 +52,12 @@ namespace Bootstrap.Admin.Api.SqlServer
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void PutById_Ok()
|
public async void PutById_Ok()
|
||||||
{
|
{
|
||||||
var ids = new Group().Retrieves().Select(g => g.Id);
|
var ids = GroupHelper.Retrieves().Select(g => g.Id);
|
||||||
var uid = new User().Retrieves().Where(u => u.UserName == "Admin").First().Id;
|
var uid = UserHelper.Retrieves().Where(u => u.UserName == "Admin").First().Id;
|
||||||
var ret = await Client.PutAsJsonAsync<IEnumerable<string>, bool>($"{uid}?type=user", ids);
|
var ret = await Client.PutAsJsonAsync<IEnumerable<string>, bool>($"{uid}?type=user", ids);
|
||||||
Assert.True(ret);
|
Assert.True(ret);
|
||||||
|
|
||||||
var rid = new Role().Retrieves().Where(r => r.RoleName == "Administrators").First().Id;
|
var rid = RoleHelper.Retrieves().Where(r => r.RoleName == "Administrators").First().Id;
|
||||||
ret = await Client.PutAsJsonAsync<IEnumerable<string>, bool>($"{rid}?type=role", ids);
|
ret = await Client.PutAsJsonAsync<IEnumerable<string>, bool>($"{rid}?type=role", ids);
|
||||||
Assert.True(ret);
|
Assert.True(ret);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,7 @@ namespace Bootstrap.Admin.Api.SqlServer
|
||||||
var ret = await Client.PostAsJsonAsync<BootstrapMenu, bool>(new BootstrapMenu() { Name = "UnitTest-Menu", Application = "0", Category = "0", ParentId = "0", Url = "#", Target = "_self", IsResource = 0 });
|
var ret = await Client.PostAsJsonAsync<BootstrapMenu, bool>(new BootstrapMenu() { Name = "UnitTest-Menu", Application = "0", Category = "0", ParentId = "0", Url = "#", Target = "_self", IsResource = 0 });
|
||||||
Assert.True(ret);
|
Assert.True(ret);
|
||||||
|
|
||||||
var menu = new Menu();
|
var ids = MenuHelper.RetrieveAllMenus("Admin").Where(d => d.Name == "UnitTest-Menu").Select(d => d.Id);
|
||||||
var ids = menu.RetrieveAllMenus("Admin").Where(d => d.Name == "UnitTest-Menu").Select(d => d.Id);
|
|
||||||
Assert.True(await Client.DeleteAsJsonAsync<IEnumerable<string>, bool>("", ids));
|
Assert.True(await Client.DeleteAsJsonAsync<IEnumerable<string>, bool>("", ids));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,11 +34,11 @@ namespace Bootstrap.Admin.Api.SqlServer
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void PostById_Ok()
|
public async void PostById_Ok()
|
||||||
{
|
{
|
||||||
var uid = new User().Retrieves().Where(u => u.UserName == "Admin").First().Id;
|
var uid = UserHelper.Retrieves().Where(u => u.UserName == "Admin").First().Id;
|
||||||
var ret = await Client.PostAsJsonAsync<string, IEnumerable<object>>($"{uid}?type=user", string.Empty);
|
var ret = await Client.PostAsJsonAsync<string, IEnumerable<object>>($"{uid}?type=user", string.Empty);
|
||||||
Assert.NotEmpty(ret);
|
Assert.NotEmpty(ret);
|
||||||
|
|
||||||
var rid = new Role().Retrieves().Where(r => r.RoleName == "Administrators").First().Id;
|
var rid = RoleHelper.Retrieves().Where(r => r.RoleName == "Administrators").First().Id;
|
||||||
ret = await Client.PostAsJsonAsync<string, IEnumerable<object>>($"{rid}?type=role", string.Empty);
|
ret = await Client.PostAsJsonAsync<string, IEnumerable<object>>($"{rid}?type=role", string.Empty);
|
||||||
Assert.NotEmpty(ret);
|
Assert.NotEmpty(ret);
|
||||||
}
|
}
|
||||||
|
@ -47,8 +46,8 @@ namespace Bootstrap.Admin.Api.SqlServer
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void PutById_Ok()
|
public async void PutById_Ok()
|
||||||
{
|
{
|
||||||
var ids = new Menu().RetrieveAllMenus("Admin").Select(g => g.Id);
|
var ids = MenuHelper.RetrieveAllMenus("Admin").Select(g => g.Id);
|
||||||
var rid = new Role().Retrieves().Where(r => r.RoleName == "Administrators").First().Id;
|
var rid = RoleHelper.Retrieves().Where(r => r.RoleName == "Administrators").First().Id;
|
||||||
var ret = await Client.PutAsJsonAsync<IEnumerable<string>, bool>($"{rid}", ids);
|
var ret = await Client.PutAsJsonAsync<IEnumerable<string>, bool>($"{rid}", ids);
|
||||||
Assert.True(ret);
|
Assert.True(ret);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace Bootstrap.Admin.Api.SqlServer
|
||||||
Assert.True(resp);
|
Assert.True(resp);
|
||||||
|
|
||||||
// 删除新用户
|
// 删除新用户
|
||||||
nusr.Delete(new string[] { nusr.Id });
|
UserHelper.Delete(new string[] { nusr.Id });
|
||||||
|
|
||||||
// Reject
|
// Reject
|
||||||
nusr = InsertNewUser();
|
nusr = InsertNewUser();
|
||||||
|
@ -48,15 +48,15 @@ namespace Bootstrap.Admin.Api.SqlServer
|
||||||
private User InsertNewUser()
|
private User InsertNewUser()
|
||||||
{
|
{
|
||||||
// 插入新用户
|
// 插入新用户
|
||||||
var nusr = new User() { UserName = "UnitTest-Register", DisplayName = "UnitTest", Password = "1", Description = "UnitTest" };
|
var nusr = new User() { UserName = "UnitTest_New", DisplayName = "UnitTest", Password = "1", Description = "UnitTest" };
|
||||||
Assert.True(new User().Save(nusr));
|
Assert.True(UserHelper.Save(nusr));
|
||||||
return nusr;
|
return nusr;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DeleteUnitTestUser()
|
private void DeleteUnitTestUser()
|
||||||
{
|
{
|
||||||
var ids = new User().RetrieveNewUsers().Where(u => u.UserName == "UnitTest-Register").Select(u => u.Id);
|
var ids = UserHelper.RetrieveNewUsers().Where(u => u.UserName == "UnitTest_New").Select(u => u.Id);
|
||||||
new User().Delete(ids);
|
UserHelper.Delete(ids);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ namespace Bootstrap.Admin.Api.SqlServer
|
||||||
var nusr = new User() { UserName = "UnitTest_RegisterController", DisplayName = "UnitTest", Password = "1", Description = "UnitTest" };
|
var nusr = new User() { UserName = "UnitTest_RegisterController", DisplayName = "UnitTest", Password = "1", Description = "UnitTest" };
|
||||||
var resp = await Client.PostAsJsonAsync<User, bool>(nusr);
|
var resp = await Client.PostAsJsonAsync<User, bool>(nusr);
|
||||||
Assert.True(resp);
|
Assert.True(resp);
|
||||||
nusr.Delete(nusr.RetrieveNewUsers().Where(u => u.UserName == nusr.UserName).Select(u => u.Id));
|
UserHelper.Delete(nusr.RetrieveNewUsers().Where(u => u.UserName == nusr.UserName).Select(u => u.Id));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
|
@ -25,16 +25,16 @@ namespace Bootstrap.Admin.Api.SqlServer
|
||||||
var ret = await Client.PostAsJsonAsync<Role, bool>(new Role() { RoleName = "UnitTest-Role", Description = "UnitTest-Desc" });
|
var ret = await Client.PostAsJsonAsync<Role, bool>(new Role() { RoleName = "UnitTest-Role", Description = "UnitTest-Desc" });
|
||||||
Assert.True(ret);
|
Assert.True(ret);
|
||||||
|
|
||||||
var ids = new Role().Retrieves().Where(d => d.RoleName == "UnitTest-Role").Select(d => d.Id);
|
var ids = RoleHelper.Retrieves().Where(d => d.RoleName == "UnitTest-Role").Select(d => d.Id);
|
||||||
Assert.True(await Client.DeleteAsJsonAsync<IEnumerable<string>, bool>(ids));
|
Assert.True(await Client.DeleteAsJsonAsync<IEnumerable<string>, bool>(ids));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void PostById_Ok()
|
public async void PostById_Ok()
|
||||||
{
|
{
|
||||||
var uid = new User().Retrieves().Where(u => u.UserName == "Admin").First().Id;
|
var uid = UserHelper.Retrieves().Where(u => u.UserName == "Admin").First().Id;
|
||||||
var gid = new Group().Retrieves().Where(g => g.GroupName == "Admin").First().Id;
|
var gid = GroupHelper.Retrieves().Where(g => g.GroupName == "Admin").First().Id;
|
||||||
var mid = new Menu().RetrieveAllMenus("Admin").Where(m => m.Url == "~/Admin/Index").First().Id;
|
var mid = MenuHelper.RetrieveAllMenus("Admin").Where(m => m.Url == "~/Admin/Index").First().Id;
|
||||||
|
|
||||||
var ret = await Client.PostAsJsonAsync<string, IEnumerable<object>>($"{uid}?type=user", string.Empty);
|
var ret = await Client.PostAsJsonAsync<string, IEnumerable<object>>($"{uid}?type=user", string.Empty);
|
||||||
Assert.NotEmpty(ret);
|
Assert.NotEmpty(ret);
|
||||||
|
@ -49,10 +49,10 @@ namespace Bootstrap.Admin.Api.SqlServer
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void PutById_Ok()
|
public async void PutById_Ok()
|
||||||
{
|
{
|
||||||
var uid = new User().Retrieves().Where(u => u.UserName == "Admin").First().Id;
|
var uid = UserHelper.Retrieves().Where(u => u.UserName == "Admin").First().Id;
|
||||||
var gid = new Group().Retrieves().Where(g => g.GroupName == "Admin").First().Id;
|
var gid = GroupHelper.Retrieves().Where(g => g.GroupName == "Admin").First().Id;
|
||||||
var mid = new Menu().RetrieveAllMenus("Admin").Where(m => m.Url == "~/Admin/Index").First().Id;
|
var mid = MenuHelper.RetrieveAllMenus("Admin").Where(m => m.Url == "~/Admin/Index").First().Id;
|
||||||
var ids = new Role().Retrieves().Select(r => r.Id);
|
var ids = RoleHelper.Retrieves().Select(r => r.Id);
|
||||||
|
|
||||||
var ret = await Client.PutAsJsonAsync<IEnumerable<string>, bool>($"{uid}?type=user", ids);
|
var ret = await Client.PutAsJsonAsync<IEnumerable<string>, bool>($"{uid}?type=user", ids);
|
||||||
Assert.True(ret);
|
Assert.True(ret);
|
||||||
|
|
|
@ -21,24 +21,23 @@ namespace Bootstrap.Admin.Api.SqlServer
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void Post_Ok()
|
public async void Post_Ok()
|
||||||
{
|
{
|
||||||
var dict = new Dict();
|
var dicts = DictHelper.RetrieveDicts();
|
||||||
var dicts = dict.RetrieveDicts();
|
|
||||||
|
|
||||||
var ids = dicts.Where(d => d.Category == "UnitTest-Settings").Select(d => d.Id);
|
var ids = dicts.Where(d => d.Category == "UnitTest-Settings").Select(d => d.Id);
|
||||||
dict.Delete(ids);
|
DictHelper.Delete(ids);
|
||||||
|
|
||||||
Assert.True(dict.Save(new Dict() { Category = "UnitTest-Settings", Name = "UnitTest", Code = "0", Define = 0 }));
|
Assert.True(DictHelper.Save(new BootstrapDict() { Category = "UnitTest-Settings", Name = "UnitTest", Code = "0", Define = 0 }));
|
||||||
|
|
||||||
// 获得原来值
|
// 获得原来值
|
||||||
var resp = await Client.PostAsJsonAsync<BootstrapDict, bool>(new Dict() { Category = "UnitTest-Settings", Name = "UnitTest", Code = "UnitTest" });
|
var resp = await Client.PostAsJsonAsync<BootstrapDict, bool>(new BootstrapDict() { Category = "UnitTest-Settings", Name = "UnitTest", Code = "UnitTest" });
|
||||||
Assert.True(resp);
|
Assert.True(resp);
|
||||||
|
|
||||||
var code = dict.RetrieveDicts().FirstOrDefault(d => d.Category == "UnitTest-Settings").Code;
|
var code = DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "UnitTest-Settings").Code;
|
||||||
Assert.Equal("UnitTest", code);
|
Assert.Equal("UnitTest", code);
|
||||||
|
|
||||||
// Delete
|
// Delete
|
||||||
ids = dict.RetrieveDicts().Where(d => d.Category == "UnitTest-Settings").Select(d => d.Id);
|
ids = DictHelper.RetrieveDicts().Where(d => d.Category == "UnitTest-Settings").Select(d => d.Id);
|
||||||
dict.Delete(ids);
|
DictHelper.Delete(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class CacheCorsItem : ICacheCorsItem
|
internal class CacheCorsItem : ICacheCorsItem
|
||||||
|
|
|
@ -31,30 +31,29 @@ namespace Bootstrap.Admin.Api.SqlServer
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void PostAndDelete_Ok()
|
public async void PostAndDelete_Ok()
|
||||||
{
|
{
|
||||||
var user = new User();
|
UserHelper.Delete(UserHelper.Retrieves().Where(usr => usr.UserName == "UnitTest_Delete").Select(usr => usr.Id));
|
||||||
user.Delete(user.Retrieves().Where(usr => usr.UserName == "UnitTest-Delete").Select(usr => usr.Id));
|
|
||||||
|
|
||||||
var nusr = new User { UserName = "UnitTest_Delete", Password = "1", DisplayName = "DisplayName", ApprovedBy = "System", ApprovedTime = DateTime.Now, Description = "Desc", Icon = "default.jpg" };
|
var nusr = new User { UserName = "UnitTest_Delete", Password = "1", DisplayName = "DisplayName", ApprovedBy = "System", ApprovedTime = DateTime.Now, Description = "Desc", Icon = "default.jpg" };
|
||||||
var resp = await Client.PostAsJsonAsync<User, bool>("", nusr);
|
var resp = await Client.PostAsJsonAsync<User, bool>("", nusr);
|
||||||
Assert.True(resp);
|
Assert.True(resp);
|
||||||
|
|
||||||
nusr.Id = user.Retrieves().First(u => u.UserName == nusr.UserName).Id;
|
nusr.Id = UserHelper.Retrieves().First(u => u.UserName == nusr.UserName).Id;
|
||||||
resp = await Client.PostAsJsonAsync<User, bool>(nusr);
|
resp = await Client.PostAsJsonAsync<User, bool>(nusr);
|
||||||
Assert.True(resp);
|
Assert.True(resp);
|
||||||
|
|
||||||
var ids = user.Retrieves().Where(d => d.UserName == nusr.UserName).Select(d => d.Id);
|
var ids = UserHelper.Retrieves().Where(d => d.UserName == nusr.UserName).Select(d => d.Id);
|
||||||
Assert.True(await Client.DeleteAsJsonAsync<IEnumerable<string>, bool>(ids));
|
Assert.True(await Client.DeleteAsJsonAsync<IEnumerable<string>, bool>(ids));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void PostById_Ok()
|
public async void PostById_Ok()
|
||||||
{
|
{
|
||||||
var rid = new Role().Retrieves().Where(r => r.RoleName == "Administrators").First().Id;
|
var rid = RoleHelper.Retrieves().Where(r => r.RoleName == "Administrators").First().Id;
|
||||||
|
|
||||||
var ret = await Client.PostAsJsonAsync<string, IEnumerable<object>>($"{rid}?type=role", string.Empty);
|
var ret = await Client.PostAsJsonAsync<string, IEnumerable<object>>($"{rid}?type=role", string.Empty);
|
||||||
Assert.NotNull(ret);
|
Assert.NotNull(ret);
|
||||||
|
|
||||||
var gid = new Group().Retrieves().Where(r => r.GroupName == "Admin").First().Id;
|
var gid = GroupHelper.Retrieves().Where(r => r.GroupName == "Admin").First().Id;
|
||||||
ret = await Client.PostAsJsonAsync<string, IEnumerable<object>>($"{gid}?type=group", string.Empty);
|
ret = await Client.PostAsJsonAsync<string, IEnumerable<object>>($"{gid}?type=group", string.Empty);
|
||||||
Assert.NotNull(ret);
|
Assert.NotNull(ret);
|
||||||
|
|
||||||
|
@ -65,12 +64,12 @@ namespace Bootstrap.Admin.Api.SqlServer
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void PutById_Ok()
|
public async void PutById_Ok()
|
||||||
{
|
{
|
||||||
var ids = new User().Retrieves().Where(u => u.UserName == "Admin").Select(u => u.Id);
|
var ids = UserHelper.Retrieves().Where(u => u.UserName == "Admin").Select(u => u.Id);
|
||||||
var gid = new Group().Retrieves().Where(r => r.GroupName == "Admin").First().Id;
|
var gid = GroupHelper.Retrieves().Where(r => r.GroupName == "Admin").First().Id;
|
||||||
var ret = await Client.PutAsJsonAsync<IEnumerable<string>, bool>($"{gid}?type=group", ids);
|
var ret = await Client.PutAsJsonAsync<IEnumerable<string>, bool>($"{gid}?type=group", ids);
|
||||||
Assert.True(ret);
|
Assert.True(ret);
|
||||||
|
|
||||||
var rid = new Role().Retrieves().Where(r => r.RoleName == "Administrators").First().Id;
|
var rid = RoleHelper.Retrieves().Where(r => r.RoleName == "Administrators").First().Id;
|
||||||
ret = await Client.PutAsJsonAsync<IEnumerable<string>, bool>($"{rid}?type=role", ids);
|
ret = await Client.PutAsJsonAsync<IEnumerable<string>, bool>($"{rid}?type=role", ids);
|
||||||
Assert.True(ret);
|
Assert.True(ret);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using Bootstrap.Security;
|
using Bootstrap.Security;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
@ -9,6 +9,8 @@ namespace Bootstrap.DataAccess.SqlServer
|
||||||
[Collection("SQLServerContext")]
|
[Collection("SQLServerContext")]
|
||||||
public class DictsTest
|
public class DictsTest
|
||||||
{
|
{
|
||||||
|
protected virtual string DatabaseName { get; set; } = "SQLServer";
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void SaveAndDelete_Ok()
|
public void SaveAndDelete_Ok()
|
||||||
{
|
{
|
||||||
|
@ -168,6 +170,14 @@ namespace Bootstrap.DataAccess.SqlServer
|
||||||
Assert.Equal("10", DictHelper.RetrieveLocaleIPSvrCachePeriod());
|
Assert.Equal("10", DictHelper.RetrieveLocaleIPSvrCachePeriod());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void DatabaseCheck_Ok()
|
||||||
|
{
|
||||||
|
var dict = new BootstrapDict() { Category = "系统检查", Name = "系统设置", Code = DatabaseName, Define = 0 };
|
||||||
|
Assert.True(DictHelper.Save(dict));
|
||||||
|
Assert.Equal(DatabaseName, DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == dict.Category && d.Name == dict.Name)?.Code ?? "unknown");
|
||||||
|
}
|
||||||
|
|
||||||
#region Private Class For Test
|
#region Private Class For Test
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
|
|
|
@ -5,6 +5,6 @@ namespace Bootstrap.DataAccess.MongoDB
|
||||||
[Collection("MongoContext")]
|
[Collection("MongoContext")]
|
||||||
public class DictsTest : SqlServer.DictsTest
|
public class DictsTest : SqlServer.DictsTest
|
||||||
{
|
{
|
||||||
|
protected override string DatabaseName { get; set; } = "MongoDB";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,6 @@ namespace Bootstrap.DataAccess.MySql
|
||||||
[Collection("MySqlContext")]
|
[Collection("MySqlContext")]
|
||||||
public class DictsTest : SqlServer.DictsTest
|
public class DictsTest : SqlServer.DictsTest
|
||||||
{
|
{
|
||||||
|
protected override string DatabaseName { get; set; } = "MySql";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,6 @@ namespace Bootstrap.DataAccess.SQLite
|
||||||
[Collection("SQLiteContext")]
|
[Collection("SQLiteContext")]
|
||||||
public class DictsTest : SqlServer.DictsTest
|
public class DictsTest : SqlServer.DictsTest
|
||||||
{
|
{
|
||||||
|
protected override string DatabaseName { get; set; } = "SQLite";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,10 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="coverlet.msbuild" Version="2.0.0" />
|
<PackageReference Include="coverlet.msbuild" Version="2.6.1">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="2.2.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="2.2.0" />
|
||||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.2.4" />
|
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.2.4" />
|
||||||
|
|
|
@ -1,9 +1,4 @@
|
||||||
{
|
{
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Debug"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"MongoDB": "UnitTest",
|
"MongoDB": "UnitTest",
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"sqlite": "Data Source=UnitTest.db;",
|
"sqlite": "Data Source=UnitTest.db;",
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Error",
|
||||||
|
"System": "Error",
|
||||||
|
"Microsoft": "Error"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"LongbowCache": {
|
||||||
|
"Enabled": false
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue