コード例 #1
0
 public void Add(Role role)
 {
     if(this.RoleNamed(role.TenantId, role.Name)!=null) {
         throw new InvalidOperationException("Role is not unique.");
     }
     _session.Save(role.Group);
     _session.Save(role);
 }
コード例 #2
0
 public void Remove(Role role)
 {
     _session.Delete(role);
 }
コード例 #3
0
        public virtual Role ProvisionRole(string name, string description, bool supportsNesting = false)
        {
            AssertionConcern.True(this.Active, "Tenant is not active.");

            Role role = new Role(this.TenantId, name, description, supportsNesting);

            DomainEventPublisher.Instance.Publish(new RoleProvisioned(this.TenantId, name));

            return role;
        }
コード例 #4
0
        public void TestUserIsNotInRole()
        {
            Tenant tenant = this.CreateTenant();
            User user = this.CreateUser(tenant);
            Role managerRole = tenant.ProvisionRole("Manager", "A manager role.", true);
            Group group = new Group(user.TenantId, "Managers", "A group of managers.");

            Mock<IGroupRepository> groupRepository = new Mock<IGroupRepository>();
            groupRepository.Setup(r => r.GroupNamed(group.TenantId, group.Name)).Returns(group);
            Mock<IUserRepository> userRepository = new Mock<IUserRepository>();
            userRepository.Setup(r => r.UserWithUserName(user.TenantId, user.UserName)).Returns(user);

            GroupMemberService groupMemberService = new GroupMemberService(userRepository.Object, groupRepository.Object);

            managerRole.AssignGroup(group, groupMemberService);
            Role accountantRole = new Role(user.TenantId, "Accountant", "An accountant role.", false);

            Assert.IsFalse(managerRole.IsInRole(user, groupMemberService));
            Assert.IsFalse(accountantRole.IsInRole(user, groupMemberService));
        }