public void CreateCustomerIntegrationTest() { string returnMessage; TransactionalInformation transaction; CustomerApplicationService customerApplicationService = new CustomerApplicationService(customerDataService); List <PaymentType> paymentTypes = customerApplicationService.GetPaymentTypes(out transaction); var paymentType = (from p in paymentTypes where p.Description == "Visa" select p).First(); Customer customer = new Customer(); customer.FirstName = "William"; customer.LastName = "Gates"; customer.EmailAddress = "*****@*****.**"; customer.PhoneNumber = "08615976111157"; customer.Address = "One Microsoft Way"; customer.City = "Redmond"; customer.Region = "WA"; customer.PostalCode = "98052-7329"; customer.PaymentTypeID = paymentType.PaymentTypeID; customer.CreditCardExpirationDate = Convert.ToDateTime("12/31/2014"); customer.CreditCardSecurityCode = "111"; customer.CreditCardNumber = "123111234"; customerApplicationService.CreateCustomer(customer, out transaction); returnMessage = Utilities.GetReturnMessage(transaction.ReturnMessage); Assert.AreEqual(true, transaction.ReturnStatus, returnMessage); }
public HttpResponseMessage SeedData(HttpRequestMessage request) { TransactionalInformation transaction; SeedDataViewModel seedDataViewModel = new SeedDataViewModel(); SeedData seedData = new SeedData(); List <Customer> customers = seedData.LoadDataSet(out transaction); if (transaction.ReturnStatus == false) { seedDataViewModel.ReturnStatus = false; seedDataViewModel.ReturnMessage = transaction.ReturnMessage; var badresponse = Request.CreateResponse <SeedDataViewModel>(HttpStatusCode.BadRequest, seedDataViewModel); return(badresponse); } long startTickCount = System.Environment.TickCount; CustomerApplicationService customerApplicationService = new CustomerApplicationService(customerDataService); customerApplicationService.DeleteAllCustomers(out transaction); if (transaction.ReturnStatus == false) { seedDataViewModel.ReturnStatus = false; seedDataViewModel.ReturnMessage = transaction.ReturnMessage; var badresponse = Request.CreateResponse <SeedDataViewModel>(HttpStatusCode.BadRequest, seedDataViewModel); return(badresponse); } foreach (Customer customer in customers) { customerApplicationService.CreateCustomer(customer, out transaction); if (transaction.ReturnStatus == false) { transaction.ReturnMessage.Add("for " + customer.LastName + "," + customer.FirstName); seedDataViewModel.ReturnStatus = false; seedDataViewModel.ReturnMessage = transaction.ReturnMessage; var badresponse = Request.CreateResponse <SeedDataViewModel>(HttpStatusCode.BadRequest, seedDataViewModel); return(badresponse); } } long endTickCount = System.Environment.TickCount; decimal ticks = ((endTickCount - startTickCount) / 1000) / 60; List <String> returnMessage = new List <String>(); returnMessage.Add(customers.Count.ToString() + " customers created in " + ticks.ToString() + " minutes"); seedDataViewModel.ReturnStatus = true; seedDataViewModel.ReturnMessage = returnMessage; var response = Request.CreateResponse <SeedDataViewModel>(HttpStatusCode.OK, seedDataViewModel); return(response); }
public void createCustomerOkTest() { Mock <ICustomerDomainService> mock = new Mock <ICustomerDomainService>(); mock.Setup(x => x.CreateCustomer(It.IsAny <TSeg_Clientes>())).Returns(getTSegCliente()); CustomerApplicationService test = new CustomerApplicationService(mock.Object); var response = test.CreateCustomer(getCustomerRequest()); Assert.IsTrue(response.id > 0); }
public ActionResult Create(CustomerRequest customer) { CustomerResponse response = CustomerApplicationService.CreateCustomer(customer); if (response.id > 0) { return(RedirectToAction("Customers")); } else { ViewBag.Error = "El cliente no pudo ser creado."; return(View("~/Views/Customers/Create.cshtml")); } }
public HttpResponseMessage CreateCustomer(HttpRequestMessage request, [FromBody] CustomerMaintenanceDTO customerDTO) { TransactionalInformation transaction; CustomerMaintenanceViewModel customerMaintenanceViewModel = new CustomerMaintenanceViewModel(); if (!ModelState.IsValid) { var errors = ModelState.Errors(); customerMaintenanceViewModel.ReturnMessage = ModelStateHelper.ReturnErrorMessages(errors); customerMaintenanceViewModel.ValidationErrors = ModelStateHelper.ReturnValidationErrors(errors); customerMaintenanceViewModel.ReturnStatus = false; var badresponse = Request.CreateResponse <CustomerMaintenanceViewModel>(HttpStatusCode.BadRequest, customerMaintenanceViewModel); return(badresponse); } Customer customer = new Customer(); ModelStateHelper.UpdateViewModel(customerDTO, customer); CustomerApplicationService customerApplicationService = new CustomerApplicationService(customerDataService); customerApplicationService.CreateCustomer(customer, out transaction); customerMaintenanceViewModel.Customer = customer; customerMaintenanceViewModel.ReturnStatus = transaction.ReturnStatus; customerMaintenanceViewModel.ReturnMessage = transaction.ReturnMessage; customerMaintenanceViewModel.ValidationErrors = transaction.ValidationErrors; if (transaction.ReturnStatus == false) { var badresponse = Request.CreateResponse <CustomerMaintenanceViewModel>(HttpStatusCode.BadRequest, customerMaintenanceViewModel); return(badresponse); } else { var response = Request.CreateResponse <CustomerMaintenanceViewModel>(HttpStatusCode.Created, customerMaintenanceViewModel); return(response); } }