public void _01_can_save_new_customer() { IInquiryCustomer customer = _customerBusinessLogic.GetCustomer(new InquiryCriteria { CustomerId = 1, Email = "*****@*****.**" }).Result; if (customer == null) { customer = new InquiryCustomer { Id = 1, Name = "Firstname Lastname", Email = "*****@*****.**", MobileNumber = "0123456789" }; customer.Transactions.Add(CreateTransaction(1, 1234.56, "USD", TransactionStatus.Success)); customer.Transactions.Add(CreateTransaction(1, 6543.21, "GBP", TransactionStatus.Canceled)); customer.Transactions.Add(CreateTransaction(1, 1111.22, "USD", TransactionStatus.Failed)); customer.Transactions.Add(CreateTransaction(1, 2222.23, "EUR", TransactionStatus.Success)); customer.Transactions.Add(CreateTransaction(1, 3333.34, "THB", TransactionStatus.Canceled)); customer.Transactions.Add(CreateTransaction(1, 7890.12, "USD", TransactionStatus.Failed)); _customerBusinessLogic.Save(customer).Wait(); } Assert.IsNotNull(customer); Assert.IsNotNull(customer.Transactions); }
// POST api/customers public async Task <HttpResponseMessage> Post(InquiryCriteriaViewmodel inquiryCriteria) { if (inquiryCriteria.customerID <= 0 && string.IsNullOrEmpty(inquiryCriteria.email)) { return(CreateResponse(HttpStatusCode.BadRequest, "No inquiry criteria")); } else { if (!Validator.IsValidEmail(inquiryCriteria.email)) { return(CreateResponse(HttpStatusCode.BadRequest, "Invalid Email")); } if (!Validator.IsValidCustomerId(inquiryCriteria.customerID)) { return(CreateResponse(HttpStatusCode.BadRequest, "Invalid Customer ID")); } IInquiryCriteria criteria = inquiryCriteria.Convert(); IInquiryCustomer customer = await _customerBusinessLogic.GetCustomer(criteria); if (customer == null) { return(CreateResponse(HttpStatusCode.NotFound, "Not found")); } return(CreateResponse(new CustomerViewmodel(customer, criteria))); } }