public void CreateCustomer_Succsess() { var cOptions = new AddCustomerOptions() { Email = "*****@*****.**", FirstName = "Fname", LastName = "Lname", Phone = "343549342", VatNumber = $"{DateTime.UtcNow.Millisecond:D6}" }; var customer = customers_.AddCustomer(cOptions); Assert.NotNull(customer); var scustomer = customers_.SearchCustomer( new SearchCustomerOptions() { VatNumber = cOptions.VatNumber } ).SingleOrDefault(); Assert.NotNull(scustomer); Assert.Equal(cOptions.Email, scustomer.Email); Assert.Equal(cOptions.FirstName, scustomer.Firstname); Assert.Equal(cOptions.LastName, scustomer.Lastname); Assert.True(scustomer.Active); }
/// <summary> /// Creates a customer and adds him at the customer list /// </summary> /// <param name="options"></param> /// <returns></returns> public Customer AddCustomer(AddCustomerOptions options) { if (options == null) { return(null); } if (string.IsNullOrWhiteSpace(options.Email) || string.IsNullOrWhiteSpace(options.VatNumber)) { return(null); } if (options.VatNumber.Length > 9) { return(null); } var exists = SearchCustomer( new SearchCustomerOptions() { VatNumber = options.VatNumber }).Any(); if (exists) { return(null); } Customer customer = new Customer { VatNumber = options.VatNumber, Email = options.Email, Firstname = options.FirstName, Lastname = options.LastName, Phone = options.Phone, Active = true, Created = DateTime.UtcNow }; context_.Add(customer); try { context_.SaveChanges(); } catch { return(null); } return(customer); }
public void AddCustomer_Success() { var customer = new AddCustomerOptions() { Email = $"{CodeGenerator.CreateRandom()}@test.com", FirstName = "Test first name", LastName = "Test last name", Phone = "6969696969", VatNumber = $"{CodeGenerator.CreateRandom()}" }; Assert.NotNull(customers_.AddCustomer(customer)); }
public bool AddCustomer(AddCustomerOptions options) { if (options == null) { return(false); } if (!IsValidEmail(options.Email)) { return(false); } if (string.IsNullOrWhiteSpace(options.VatNumber)) { return(false); } var customer = GetCustomerByVatNumber(options.VatNumber); if (customer != null) { return(false); } var tempId = UniqueId(); customer = new Customer() { Id = tempId, Email = options.Email, VatNumber = options.VatNumber, Status = true }; CustomerList.Add(customer); Console.WriteLine($"{CustomerList[0].Email}" + $" and {CustomerList[0].Id} " + $"and {CustomerList[0].VatNumber}" + $" and {CustomerList[0].Status}"); return(true); }
public bool CreateCustomer(AddCustomerOptions optios) { if (optios == null) { return(false); } if (string.IsNullOrWhiteSpace(optios.FirstName)) { return(false); } if (string.IsNullOrWhiteSpace(optios.LastName)) { return(false); } if (string.IsNullOrWhiteSpace(optios.EmailAddress)) { return(false); } if (string.IsNullOrWhiteSpace(optios.VatNumber) || CustomerList.Where(s => s.VatNumber.Equals(optios.VatNumber)) == null) { return(false); } var newCustomer = new Customer(optios.VatNumber, optios.EmailAddress) { Email = optios.EmailAddress, FirstName = optios.FirstName, LastName = optios.LastName, VatNumber = optios.VatNumber, CustomerId = AddCustomerOptions.RandomGeneratorCustomerId(), DateCreated = DateTimeOffset.Now.Date, }; if (CustomerList.Contains(newCustomer)) { return(false); } CustomerList.Add(newCustomer); return(true); }