本文整理汇总了C#中IRoleRepository.GetRoleByRoleName方法的典型用法代码示例。如果您正苦于以下问题:C# IRoleRepository.GetRoleByRoleName方法的具体用法?C# IRoleRepository.GetRoleByRoleName怎么用?C# IRoleRepository.GetRoleByRoleName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IRoleRepository
的用法示例。
在下文中一共展示了IRoleRepository.GetRoleByRoleName方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddUsersToRoles
public void AddUsersToRoles()
{
var users = Builder<User>.CreateListOfSize(2).
TheFirst(1).With(x => x.Login = "A").
TheLast(1).With(x => x.Login = "B").Build();
var roles = Builder<Role>.CreateListOfSize(2).
TheFirst(1).With(x => x.RoleName = "User").
TheLast(1).With( x => x.RoleName = "Admin").Build();
_userRepository = Mockery.Stub<IUserRepository>();
_roleRepository = Mockery.Stub<IRoleRepository>();
using (Mockery.Record())
{
Expect.Call(_userRepository.GetUserByLogin("A")).Return(users[0]);
Expect.Call(_userRepository.GetUserByLogin("B")).Return(users[1]);
Expect.Call(_roleRepository.GetRoleByRoleName("User")).Return(roles[0]);
Expect.Call(_roleRepository.GetRoleByRoleName("Admin")).Return(roles[1]);
}
using (Mockery.Playback())
{
_roleService = new RoleService(_roleRepository, _userRepository);
_roleService.AddUsersToRoles(new[] {"A", "B"}, new[] {"User", "Admin"});
}
Assert.AreEqual(users[0].Roles.Count, 2);
Assert.AreEqual(users[1].Roles.Count, 2);
}
示例2: AddUsersToRoles_methodAddUserToRoleIsCalled
public void AddUsersToRoles_methodAddUserToRoleIsCalled()
{
var users = Builder<User>.CreateListOfSize(2).
TheFirst(1).With(x => x.Login = "A").
TheLast(1).With(x => x.Login = "B").Build();
var roles = Builder<Role>.CreateListOfSize(2).
TheFirst(1).With(x => x.RoleName = "User").
TheLast(1).With(x => x.RoleName = "Admin").Build();
_userRepository = Mockery.Stub<IUserRepository>();
_roleRepository = Mockery.Stub<IRoleRepository>();
var mockRoleService = Mockery.PartialMock<RoleService>(_roleRepository, _userRepository);
var t = users[0];
using (Mockery.Record())
{
Expect.Call(_userRepository.GetUserByLogin("A")).Return(users[0]);
Expect.Call(_userRepository.GetUserByLogin("B")).Return(users[1]);
Expect.Call(_roleRepository.GetRoleByRoleName("User")).Return(roles[0]);
Expect.Call(_roleRepository.GetRoleByRoleName("Admin")).Return(roles[1]);
Expect.Call(() => mockRoleService.AddRoleToUser(Arg<User>.Is.Equal(users[0]), Arg<Role>.Is.Equal(roles[0]))).Repeat.Once();
Expect.Call(() => mockRoleService.AddRoleToUser(Arg<User>.Is.Equal(users[0]), Arg<Role>.Is.Equal(roles[1]))).Repeat.Once();
Expect.Call(() => mockRoleService.AddRoleToUser(Arg<User>.Is.Equal(users[1]), Arg<Role>.Is.Equal(roles[0]))).Repeat.Once();
Expect.Call(() => mockRoleService.AddRoleToUser(Arg<User>.Is.Equal(users[1]), Arg<Role>.Is.Equal(roles[1]))).Repeat.Once();
}
using (Mockery.Playback())
{
_roleService = new RoleService(_roleRepository, _userRepository);
mockRoleService.AddUsersToRoles(new[] { "A", "B" }, new[] { "User", "Admin" });
}
}
示例3: UserInRoleExists_returnsTrueIfUserInRoleExists
public void UserInRoleExists_returnsTrueIfUserInRoleExists()
{
bool validate;
var user = Builder<User>.CreateNew().Build();
var role = Builder<Role>.CreateNew().With(x => x.Users = new List<User> { user }).Build();
_userRepository = Mockery.Stub<IUserRepository>();
_roleRepository = Mockery.Stub<IRoleRepository>();
using (Mockery.Record())
{
Expect.Call(_roleRepository.GetRoleByRoleName(null)).IgnoreArguments().Return(role);
}
using (Mockery.Playback())
{
_roleService = new RoleService(_roleRepository, _userRepository);
validate = _roleService.UserInRoleExists(role.RoleName);
}
Assert.AreEqual(true, validate);
}
示例4: UserInRoleExists_returnsFalseIfRoleNotExists
public void UserInRoleExists_returnsFalseIfRoleNotExists()
{
bool validate;
_userRepository = Mockery.Stub<IUserRepository>();
_roleRepository = Mockery.Stub<IRoleRepository>();
using (Mockery.Record())
{
Expect.Call(_roleRepository.GetRoleByRoleName(null)).IgnoreArguments().Return(null);
}
using (Mockery.Playback())
{
_roleService = new RoleService(_roleRepository, _userRepository);
validate = _roleService.UserInRoleExists("UnknownRole");
}
Assert.AreEqual(false, validate);
}
示例5: IsUserInRole_returnsFalseIfUserNotInRole
public void IsUserInRole_returnsFalseIfUserNotInRole()
{
bool validate;
var role = Builder<Role>.CreateNew().Build();
var user = Builder<User>.CreateNew().Build();
_userRepository = Mockery.Stub<IUserRepository>();
_roleRepository = Mockery.Stub<IRoleRepository>();
using (Mockery.Record())
{
Expect.Call(_userRepository.GetUserByLogin(null)).IgnoreArguments().Return(user);
Expect.Call(_roleRepository.GetRoleByRoleName(null)).IgnoreArguments().Return(role);
}
using (Mockery.Playback())
{
_roleService = new RoleService(_roleRepository, _userRepository);
validate = _roleService.IsUserInRole(user.Login, role.RoleName);
}
Assert.AreEqual(false, validate);
}
示例6: DeleteRole_returnsTrueIfRoleExists
public void DeleteRole_returnsTrueIfRoleExists()
{
bool validate;
var role = Builder<Role>.CreateNew().Build();
_userRepository = Mockery.Stub<IUserRepository>();
_roleRepository = Mockery.Stub<IRoleRepository>();
using (Mockery.Record())
{
Expect.Call(_roleRepository.GetRoleByRoleName(null)).IgnoreArguments().Return(role);
Expect.Call(() => _roleRepository.Delete(Arg<Role>.Is.Anything)).Repeat.Once();
}
using (Mockery.Playback())
{
_roleService = new RoleService(_roleRepository, _userRepository);
validate = _roleService.DeleteRole(role.RoleName);
}
Assert.AreEqual(true, validate);
}