public async Task GetByIdAsync_Should_Return_GetResult_With_Role() { var id = Guid.NewGuid(); var role = new Role(id, Array.Empty <byte>(), DefaultRoleEnumeration.Administrator.DisplayName); var expectedResult = GetResult <Role> .Ok(role); _roleRepositoryMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(role); var result = await _roleGetterService.GetByIdAsync(id); result.Should().BeEquivalentTo(expectedResult); }
public async Task HandleAsync(UpdateRoleCommand command, CancellationToken cancellationToken = default) { var getRoleResult = await _roleGetterService.GetByIdAsync(command.RoleId); if (!getRoleResult.Success) { throw new ResourceNotFoundException(getRoleResult.Errors); } if (getRoleResult.Value.RowVersion.Except(command.RowVersion).Any()) { throw new PreconditionFailedException(); } if (!getRoleResult.Value.Name.Equals(command.Name)) { var nameIsNotTakenVerificationResult = await _roleVerificationService.VerifyNameIsNotTakenAsync(command.Name); if (!nameIsNotTakenVerificationResult.Success) { throw new ConflictException(nameIsNotTakenVerificationResult.Errors); } getRoleResult.Value.ChangeName(command.Name); } await _roleRepository.UpdateAsync(getRoleResult.Value); }
public async Task <RoleOutputQuery> HandleAsync(GetRoleInputQuery inputQuery, CancellationToken cancellationToken = default) { var getRoleResult = await _roleGetterService.GetByIdAsync(inputQuery.RoleId); if (getRoleResult.Success) { return(_mapper.Map <Role, RoleOutputQuery>(getRoleResult.Value)); } throw new ResourceNotFoundException(getRoleResult.Errors); }
public async Task HandleAsync(DeleteRoleCommand command, CancellationToken cancellationToken = default) { var getRoleResult = await _roleGetterService.GetByIdAsync(command.RoleId); if (!getRoleResult.Success) { throw new ResourceNotFoundException(getRoleResult.Errors); } if (getRoleResult.Value.RowVersion.Except(command.RowVersion).Any()) { throw new PreconditionFailedException(); } await _roleRepository.DeleteAsync(getRoleResult.Value); }