protected override void Context() { Username = "******"; base.Context(); _createCustomerInputModel = Builder<CreateCustomerInputModel>.CreateNew().Build(); _createCustomerInputModel.CustomerType = CustomerType.Undefined; CustomerService.Stub( x => x.CreateCustomer(Arg<string>.Is.Equal(Username), Arg<CreateCustomerRequest>.Is.Anything)) .Return( new CreateCustomerResponse(new List<string> {"some error from the domain", "another error from the domain"}) { Success = false, }); _expectedViewModel = new CreateCustomerViewModel(new List<string> {"some error from the domain", "another error from the domain"}) { Name = _createCustomerInputModel.Name, Street = _createCustomerInputModel.Street, AdditionalInfo = _createCustomerInputModel.AdditionalInfo, City = _createCustomerInputModel.City, State = _createCustomerInputModel.State, Zipcode = _createCustomerInputModel.Zipcode, ContactFirstName = _createCustomerInputModel.ContactFirstName, ContactLastName = _createCustomerInputModel.ContactLastName, ContactPhone = _createCustomerInputModel.ContactPhone, Phone = _createCustomerInputModel.Phone, CustomerType = _createCustomerInputModel.CustomerType, GooglePlacesUrl = _createCustomerInputModel.GooglePlacesUrl, ListName = _createCustomerInputModel.ListName, TwitterHandle = _createCustomerInputModel.TwitterHandle, WebsiteUrl = _createCustomerInputModel.WebsiteUrl, FacebookUrl = _createCustomerInputModel.FacebookUrl }; }
protected override void Context() { Username = "******"; base.Context(); _createCustomerInputModel = Builder<CreateCustomerInputModel>.CreateNew().Build(); _createCustomerRequestReturnedFromMappingEngine = new CreateCustomerRequest { CustomerType = _createCustomerInputModel.CustomerType, FacebookUrl = _createCustomerInputModel.FacebookUrl, GooglePlacesUrl = _createCustomerInputModel.GooglePlacesUrl, ListName = _createCustomerInputModel.ListName, Name = _createCustomerInputModel.Name, ParentCustomerId = _createCustomerInputModel.ParentCustomerId, Phone = _createCustomerInputModel.Phone, TwitterHandle = _createCustomerInputModel.TwitterHandle, WebsiteUrl = _createCustomerInputModel.WebsiteUrl, MailingAddress = new Address { City = _createCustomerInputModel.City, State = _createCustomerInputModel.State, Street = _createCustomerInputModel.Street, AdditionalInfo = _createCustomerInputModel.AdditionalInfo, Zipcode = _createCustomerInputModel.Zipcode, }, }; MappingEngine.Stub( x => x.Map<CreateCustomerInputModel, CreateCustomerRequest>( Arg<CreateCustomerInputModel>.Is.Equal(_createCustomerInputModel))) .Return(_createCustomerRequestReturnedFromMappingEngine); _contactReturnedFromMappingEngine = new Contact { Email = _createCustomerInputModel.ContactEmail, FirstName = _createCustomerInputModel.ContactFirstName, IsPrimary = true, LastName = _createCustomerInputModel.ContactLastName, Phone = _createCustomerInputModel.ContactPhone, }; MappingEngine.Stub( x => x.Map<CreateCustomerInputModel, Contact>( Arg<CreateCustomerInputModel>.Is.Equal(_createCustomerInputModel))) .Return(_contactReturnedFromMappingEngine); CustomerCreator.Stub( x => x.Execute(Arg<string>.Is.Equal(Username), Arg<CreateCustomerRequest>.Is.Equal(_createCustomerRequestReturnedFromMappingEngine))) .WhenCalled(x => _requestPassedToCustomerService = x.Arguments[1] as CreateCustomerRequest) .Return(new CreateCustomerResponse { Success = true, }); _expectedRequest = new CreateCustomerRequest { Name = _createCustomerInputModel.Name, Phone = _createCustomerInputModel.Phone, MailingAddress = new Address { Street = _createCustomerInputModel.Street, AdditionalInfo = _createCustomerInputModel.AdditionalInfo, City = _createCustomerInputModel.City, State = _createCustomerInputModel.State, Zipcode = _createCustomerInputModel.Zipcode, }, CustomerType = _createCustomerInputModel.CustomerType, ListName = _createCustomerInputModel.ListName, TwitterHandle = _createCustomerInputModel.TwitterHandle, GooglePlacesUrl = _createCustomerInputModel.GooglePlacesUrl, WebsiteUrl = _createCustomerInputModel.WebsiteUrl, ParentCustomerId = _createCustomerInputModel.ParentCustomerId, FacebookUrl = _createCustomerInputModel.FacebookUrl }; _expectedRequest.AddContact(new Contact { FirstName = _createCustomerInputModel.ContactFirstName, LastName = _createCustomerInputModel.ContactLastName, Phone = _createCustomerInputModel.ContactPhone, Email = _createCustomerInputModel.ContactEmail, IsPrimary = true, }); }
public ActionResult ProcessCreateCustomerInput(CreateCustomerInputModel createCustomerInputModel) { try { CreateCustomerRequest createCustomerRequest = _mappingEngine.Map<CreateCustomerInputModel, CreateCustomerRequest>(createCustomerInputModel); Contact contact = _mappingEngine.Map<CreateCustomerInputModel, Contact>(createCustomerInputModel); createCustomerRequest.AddContact(contact); CreateCustomerResponse response = _customerCreator.Execute(User.Identity.Name, createCustomerRequest); if (!response.Success) { var failureViewModel = _mappingEngine.Map<CreateCustomerInputModel, CreateCustomerViewModel>(createCustomerInputModel); foreach (var error in response.Errors) { failureViewModel.AddMessage(error); } IEnumerable<Customer> customers = GetCustomers(User.Identity.Name, new GetCustomersRequest()); customers.ToList().ForEach(x => failureViewModel.AddParentCustomer(new CustomerViewModel { Id = x.CustomerId, Name = x.Name, })); return View("CreateCustomer", failureViewModel); } } catch (Exception e) { _logger.LogException(e); return RedirectToAction("Generic", "Error"); } TempData["Message"] = "Customer was added successfully"; return RedirectToAction("CustomerManagement", "Customer"); }