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);
        }
예제 #2
0
        public void IsValid_WithContext_ShouldNotBeNull()
        {
            var sut = new CustomerValidator();

            var result = sut.IsValid(new Customer(), new {});

            result.ShouldNotBeNull();
        }
예제 #3
0
        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);
        }
예제 #4
0
        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)));
        }
예제 #5
0
        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)));
            }
        }
예제 #6
0
        public void IsValid_WithRuleSet_ShouldNotBeNull()
        {
            var sut = new CustomerValidator();

            var result = sut.IsValid(new Customer(), "ruleset");

            result.ShouldNotBeNull();
        }