Пример #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);
        }
Пример #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);
        }
Пример #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);
        }