public Role CreateRole(Guid[] licenseeIds = null, ICollection <PermissionData> permissions = null)
        {
            var addRoleData = new AddRoleData
            {
                Code               = "Role-" + TestDataGenerator.GetRandomString(5),
                Name               = "Role-" + TestDataGenerator.GetRandomString(5),
                Description        = TestDataGenerator.GetRandomString(),
                CheckedPermissions = (permissions != null ? permissions.Select(p => p.Id)
                    : _authQueries.GetPermissions().Select(o => o.Id)).ToList(),
                AssignedLicensees = licenseeIds
            };

            _roleService.CreateRole(addRoleData);

            return(_roleService.GetRoles().Single(r => r.Name == addRoleData.Name));
        }
Esempio n. 2
0
        public void Can_create_role()
        {
            _authCommands.CreatePermission(new CreatePermission
            {
                Name   = "Test",
                Module = "Test"
            });

            var createRole = new CreateRole
            {
                RoleId      = Guid.NewGuid(),
                Permissions = _authQueries.GetPermissions().Select(p => p.Id).ToList()
            };

            _authCommands.CreateRole(createRole);

            var role = _authRepository.Roles.SingleOrDefault(r => r.Id == createRole.RoleId);

            role.Should().NotBeNull();
            role.Permissions.Count.Should().Be(createRole.Permissions.Count);
        }
Esempio n. 3
0
        public void Can_verify_permission_for_admin()
        {
            _authCommands.CreatePermission(new CreatePermission
            {
                Name   = "Test",
                Module = "Test"
            });
            var permissions = _authQueries.GetPermissions().Select(p => p.Id);
            var roleId      = Guid.NewGuid();

            _authCommands.CreateRole(new CreateRole
            {
                RoleId      = roleId,
                Permissions = permissions.ToList()
            });
            var actorId          = Guid.NewGuid();
            var createActorModel = new CreateActor
            {
                ActorId  = actorId,
                Password = TestDataGenerator.GetRandomString(),
                Username = TestDataGenerator.GetRandomString()
            };

            _authCommands.CreateActor(createActorModel);
            _authCommands.AssignRoleToActor(new AssignRole
            {
                ActorId = createActorModel.ActorId,
                RoleId  = roleId
            });

            var actorHasPermission   = _authQueries.VerifyPermission(actorId, "Test", "Test");
            var actorHasNoPermission = _authQueries.VerifyPermission(actorId, "Invalid", "Invalid");

            actorHasPermission.Should().BeTrue();
            actorHasNoPermission.Should().BeFalse();
        }