public async Task VerifyUserDoesNotExistAsync_Should_Return_VerificationResult_With_Success_True() { var errors = new List <IError> { new Error(UserErrorCodeEnumeration.NotFound, UserErrorMessage.NotFound) }; var getUserResult = GetResult <User> .Fail(errors); var expectedResult = VerificationResult.Ok(); _userGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(getUserResult); var result = await _service.VerifyUserDoesNotExistAsync(Guid.NewGuid()); result.Should().BeEquivalentTo(expectedResult); }
public async Task HandleAsync(CreateUserCommand command, CancellationToken cancellationToken = default) { var userDoesNotExistsVerificationResult = await _userVerificationService.VerifyUserDoesNotExistAsync(command.UserId); if (!userDoesNotExistsVerificationResult.Success) { throw new ConflictException(userDoesNotExistsVerificationResult.Errors); } var accountExistsVerificationResult = await _accountVerificationService.VerifyAccountExistsAsync(command.UserId, command.Email); if (!accountExistsVerificationResult.Success) { throw new ValidationException(accountExistsVerificationResult.Errors); } var user = _mapper.Map <CreateUserCommand, User>(command); user.AddCreatedEvent(Guid.NewGuid()); await _communicationBus.DispatchDomainEventsAsync(user, cancellationToken); await _userRepository.AddAsync(user); }