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(); } }
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); }
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(); }
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(); } }
public async Task <IActionResult> AddPrivilege([FromBody] AddSystemRolePrivilegeCommand command) { return(await _commandSender.ValidateAndSendAsync(command, ModelState)); }