Exemplo n.º 1
0
        public async Task ExecuteNotAddDuplicates()
        {
            AddSystemRolePrivilegeCommand command;
            var id = Guid.NewGuid();

            using (var db = _dbHelper.GetDbContext())
            {
                db.SystemRolePrivileges.RemoveRange(db.SystemRolePrivileges);
                command = new AddSystemRolePrivilegeCommand()
                {
                    SystemRoleId = db.SystemRoles.First().Id, PrivilegeId = db.Privileges.First().Id
                };
                db.SystemRolePrivileges.Add(new SystemRolePrivilege()
                {
                    PrivilegeId = command.PrivilegeId, SystemRoleId = command.SystemRoleId, Id = id
                });
                db.SaveChanges();
            }
            using (var db = _dbHelper.GetDbContext())
            {
                db.SystemRolePrivileges.Count().ShouldEqual(1);
                db.SystemRolePrivileges.Any(e => e.Id == id).ShouldBeTrue();
            }
            await _handler.ExecuteAsync(command);

            using (var db = _dbHelper.GetDbContext())
            {
                db.SystemRolePrivileges.Count().ShouldEqual(1);
                db.SystemRolePrivileges.Any(e => e.Id == id).ShouldBeTrue();
            }
        }
Exemplo n.º 2
0
        public void Validator(Guid systemRoleId, Guid privilegeId, bool isValid)
        {
            var command = new AddSystemRolePrivilegeCommand()
            {
                SystemRoleId = systemRoleId, PrivilegeId = privilegeId
            };

            var result = _validator.Validate(command);

            result.IsValid.ShouldEqual(isValid);
        }
Exemplo n.º 3
0
        public void ValidatorValid()
        {
            AddSystemRolePrivilegeCommand command;

            using (var db = _dbHelper.GetDbContext())
            {
                command = new AddSystemRolePrivilegeCommand()
                {
                    SystemRoleId = db.SystemRoles.First().Id, PrivilegeId = db.Privileges.First().Id
                };
            }

            var result = _validator.Validate(command);

            result.IsValid.ShouldBeTrue();
        }
Exemplo n.º 4
0
        public async Task ExecuteAdd()
        {
            AddSystemRolePrivilegeCommand command;

            using (var db = _dbHelper.GetDbContext())
            {
                db.SystemRolePrivileges.RemoveRange(db.SystemRolePrivileges);
                command = new AddSystemRolePrivilegeCommand()
                {
                    SystemRoleId = db.SystemRoles.First().Id, PrivilegeId = db.Privileges.First().Id
                };
                await db.SaveChangesAsync();
            }

            await _handler.ExecuteAsync(command);

            using (var db = _dbHelper.GetDbContext())
            {
                db.SystemRolePrivileges.Count().ShouldEqual(1);
                db.SystemRolePrivileges.Any(e =>
                                            e.SystemRoleId == command.SystemRoleId && e.PrivilegeId == command.PrivilegeId).ShouldBeTrue();
            }
        }
Exemplo n.º 5
0
 public async Task <IActionResult> AddPrivilege([FromBody] AddSystemRolePrivilegeCommand command)
 {
     return(await _commandSender.ValidateAndSendAsync(command, ModelState));
 }