2019-01-18 01:10:19 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using Xunit;
|
2019-01-11 23:20:28 +08:00
|
|
|
|
|
|
|
|
|
namespace Bootstrap.DataAccess
|
|
|
|
|
{
|
2019-01-24 17:58:06 +08:00
|
|
|
|
[Collection("SQLServerContext")]
|
2019-05-11 12:15:03 +08:00
|
|
|
|
public class GroupsTest
|
2019-01-11 23:20:28 +08:00
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Retrieves_Ok()
|
|
|
|
|
{
|
2019-05-14 15:08:46 +08:00
|
|
|
|
Assert.NotEmpty(GroupHelper.Retrieves());
|
2019-01-11 23:20:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2019-01-18 01:10:19 +08:00
|
|
|
|
public void SaveAndDelete_Ok()
|
2019-01-11 23:20:28 +08:00
|
|
|
|
{
|
|
|
|
|
Group g = new Group() { GroupName = "UnitTest", Description = "UnitTestSave" };
|
2019-05-14 15:08:46 +08:00
|
|
|
|
Assert.True(GroupHelper.Save(g));
|
2019-01-11 23:20:28 +08:00
|
|
|
|
|
2019-05-14 15:08:46 +08:00
|
|
|
|
var ids = GroupHelper.Retrieves().Where(t => t.GroupName == "UnitTest").Select(t => t.Id);
|
|
|
|
|
Assert.True(GroupHelper.Delete(ids));
|
2019-01-11 23:20:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void RetrievesByRoleId_Ok()
|
|
|
|
|
{
|
2019-05-14 15:08:46 +08:00
|
|
|
|
var groups = GroupHelper.RetrievesByRoleId(RoleHelper.Retrieves().Where(r => r.RoleName == "Administrators").First().Id);
|
2019-01-18 01:10:19 +08:00
|
|
|
|
Assert.NotEmpty(groups);
|
2019-01-11 23:20:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void RetrievesByUserId_Ok()
|
|
|
|
|
{
|
2019-05-14 15:08:46 +08:00
|
|
|
|
var userId = UserHelper.Retrieves().FirstOrDefault(r => r.UserName == "Admin").Id;
|
|
|
|
|
var groups = GroupHelper.RetrievesByUserId(userId);
|
|
|
|
|
Assert.NotNull(groups);
|
2019-01-11 23:20:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SaveByUserId_Ok()
|
|
|
|
|
{
|
2019-05-14 15:08:46 +08:00
|
|
|
|
var userId = UserHelper.Retrieves().FirstOrDefault(r => r.UserName == "Admin").Id;
|
|
|
|
|
Assert.True(GroupHelper.SaveByUserId(userId, GroupHelper.Retrieves().Select(g => g.Id)));
|
2019-01-11 23:20:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SaveByRoleId_Ok()
|
|
|
|
|
{
|
2019-05-14 15:08:46 +08:00
|
|
|
|
var roleId = RoleHelper.Retrieves().FirstOrDefault(r => r.RoleName == "Administrators").Id;
|
|
|
|
|
Assert.True(GroupHelper.SaveByRoleId(roleId, GroupHelper.Retrieves().Select(g => g.Id)));
|
2019-01-11 23:20:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void RetrievesByUserName_Ok()
|
|
|
|
|
{
|
2019-05-14 15:08:46 +08:00
|
|
|
|
Assert.NotNull(GroupHelper.RetrievesByUserName("Admin"));
|
2019-01-11 23:20:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|