当前位置: 首页>>代码示例>>C#>>正文


C# IRoleRepository.GetRoleByRoleName方法代码示例

本文整理汇总了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);
 }
开发者ID:AndreyB1990,项目名称:Task1,代码行数:25,代码来源:RoleServiceTests.cs

示例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" });
            }
        }
开发者ID:AndreyB1990,项目名称:Task1,代码行数:30,代码来源:RoleServiceTests.cs

示例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);
 }
开发者ID:AndreyB1990,项目名称:Task1,代码行数:18,代码来源:RoleServiceTests.cs

示例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);
 }
开发者ID:AndreyB1990,项目名称:Task1,代码行数:16,代码来源:RoleServiceTests.cs

示例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);
 }
开发者ID:AndreyB1990,项目名称:Task1,代码行数:19,代码来源:RoleServiceTests.cs

示例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);
 }
开发者ID:AndreyB1990,项目名称:Task1,代码行数:18,代码来源:RoleServiceTests.cs


注:本文中的IRoleRepository.GetRoleByRoleName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。