public void IsValid_ShouldPassForValidCustomer() { //Arrange var customer = new CustomerBuilder().WithZipCode(_existingCities.First().ZipCode).Build(); //Act var result = _validator.IsValid(customer); //Assert Assert.That(result.IsValid, Is.True); }
public void IsValid_WithContext_ShouldNotBeNull() { var sut = new CustomerValidator(); var result = sut.IsValid(new Customer(), new {}); result.ShouldNotBeNull(); }
public bool Create(Customer customer) { bool success = false; var customerValidator = new CustomerValidator(customer); customer.Id = GenerateNextId(); if (customerValidator.IsValid()) { _customerRepository.Create(customer); success = true; } return(success); }
public virtual async Task <CustomerDto> SendVerificationCodeAgain(RegisterCustomerArgs args, CancellationToken cancellationToken) { if (!CustomerValidator.IsValid(args.customer, out string errorMessage)) { throw new DomainLogicException(errorMessage); } Customer customer = DtoEntityMapper.FromDtoToEntity(args.customer); customer = await(await CustomersRepository.GetAllAsync(cancellationToken)) .Where(cu => cu.NationalCode == customer.NationalCode || cu.Mobile == customer.Mobile) .FirstOrDefaultAsync(cancellationToken); customer.VerifyCode = await SmsService.SendVerifyCode(customer.Mobile); return(DtoEntityMapper.FromEntityToDto(await CustomersRepository.UpdateAsync(customer, cancellationToken))); }
public virtual async Task <CustomerDto> RegisterCustomer(RegisterCustomerArgs args, CancellationToken cancellationToken) { if (!CustomerValidator.IsValid(args.customer, out string errorMessage)) { throw new DomainLogicException(errorMessage); } Customer customer = DtoEntityMapper.FromDtoToEntity(args.customer); bool existingCustomer = await(await CustomersRepository.GetAllAsync(cancellationToken)) .Where(cu => cu.NationalCode == customer.NationalCode || cu.Mobile == customer.Mobile) .AnyAsync(cancellationToken); if (existingCustomer) { throw new DomainLogicException("CustomerIsAlreadyRegistered"); } else { customer.VerifyCode = await SmsService.SendVerifyCode(customer.Mobile); return(DtoEntityMapper.FromEntityToDto(await CustomersRepository.AddAsync(customer, cancellationToken))); } }
public void IsValid_WithRuleSet_ShouldNotBeNull() { var sut = new CustomerValidator(); var result = sut.IsValid(new Customer(), "ruleset"); result.ShouldNotBeNull(); }