public async System.Threading.Tasks.Task AddCustomer_New_ReturnTrueAsync() { //Arrange var customerModel = new CustomerModel() { FirstName = "Rachelly", LastName = "Lamberger", Email = "*****@*****.**", Password = "******", }; var emailVerificationModel = new EmailVerificationModel() { VerificationCode = 1234, Email = "*****@*****.**", }; var verificationHelperModel = new VerificationHelperModel() { Customer = customerModel, EmailVerification = emailVerificationModel }; //Act var result = await _service.AddCustomer(verificationHelperModel); //Assert Assert.True(result); }
public async Task AddCustomer_Old_ReturnFalseAsync() { //Arrange var customerModel = new CustomerModel() { FirstName = "Rachelly", LastName = "Lamberger", Email = "*****@*****.**", Password = "******", }; var emailVerificationModel = new EmailVerificationModel() { VerificationCode = 1234, Email = "*****@*****.**", }; var verificationHelperModel = new VerificationHelperModel() { Customer = customerModel, EmailVerification = emailVerificationModel }; //Act var result = await _service.AddCustomer(verificationHelperModel); //Assert Assert.False(result); }
public async Task <bool> AddCustomer(VerificationHelperModel customerModel) { try { EmailVerification emailVerification = await _context.EmailVerifications.FirstOrDefaultAsync(e => e.Email == customerModel.EmailVerification.Email).ConfigureAwait(false); if (emailVerification.VerificationCode != customerModel.EmailVerification.VerificationCode || emailVerification.ExpirationTime.CompareTo(DateTime.Now) ! < 0) { return(false); } if (_context.Customers.ToList().Any(c => c.Email == customerModel.Customer.Email)) { return(false); } Customer customer = _mapper.Map <Customer>(customerModel.Customer); customer.Salt = Hashing.GetSalt(); customer.CustomerId = Guid.NewGuid(); customer.Password = Hashing.GenerateHash(customer.Password, customer.Salt); _context.Customers.Add(customer); _context.Accounts.Add(new Entities.Account() { CustomerId = customer.CustomerId, AccountId = Guid.NewGuid(), OpenDate = DateTime.Now }); _context.SaveChanges(); return(true); } catch { return(false); } }
public async Task <bool> AddCustomer(VerificationHelperModel customerModel) { return(await _repository.AddCustomer(customerModel)); }