Exemplo n.º 1
0
        public async Task VerifyNameIsNotTakenAsync_Should_Return_VerificationResult_With_Success_True()
        {
            const string name           = "RoleName";
            var          expectedResult = VerificationResult.Ok();

            _roleRepositoryMock.Setup(x => x.GetByNameAsync(It.IsAny <string>())).Returns(Task.FromResult <Role>(null));

            var result = await _roleVerificationService.VerifyNameIsNotTakenAsync(name);

            result.Should().BeEquivalentTo(expectedResult);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public async Task HandleAsync(CreateRoleCommand command, CancellationToken cancellationToken = default)
        {
            var nameIsNotTakenVerificationResult = await _roleVerificationService.VerifyNameIsNotTakenAsync(command.Name);

            if (!nameIsNotTakenVerificationResult.Success)
            {
                throw new ConflictException(nameIsNotTakenVerificationResult.Errors);
            }

            var role = _mapper.Map <CreateRoleCommand, Role>(command);
            await _roleRepository.AddAsync(role);
        }