/// <summary> /// <see cref="Microsoft.Samples.NLayerApp.DistributedServices.MainModule.IMainModuleService"/> /// </summary> /// <param name="customer"><see cref="Microsoft.Samples.NLayerApp.DistributedServices.MainModule.IMainModuleService"/></param> public void AddCustomer(Customer customer) { try { //Resolve root dependency and perform operation using (ICustomerManagementService customerService = IoCFactory.Instance.CurrentContainer.Resolve <ICustomerManagementService>()) { customerService.AddCustomer(customer); } } catch (ArgumentNullException ex) { //trace data for internal health system and return specific FaultException here! //Log and throw is a knowed anti-pattern but in this point ( entry point for clients this is admited!) //log exception for manage health system ITraceManager traceManager = IoCFactory.Instance.CurrentContainer.Resolve <ITraceManager>(); traceManager.TraceError(ex.Message); //propagate exception to client ServiceError detailedError = new ServiceError() { ErrorMessage = Resources.Messages.exception_InvalidArguments }; throw new FaultException <ServiceError>(detailedError); } }
public void AddCustomer_Invoke_NullItemThrowArgumentNullException_Test() { //Arrange ICustomerManagementService customerService = IoCFactory.Instance.CurrentContainer.Resolve <ICustomerManagementService>(); customerService.AddCustomer(null); }
public void AddCustomer_Invoke_Test() { //Arrange ICustomerManagementService customerService = IoCFactory.Instance.CurrentContainer.Resolve <ICustomerManagementService>(); string newCustomerCode = "C0001"; Customer customer = new Customer() { CustomerCode = newCustomerCode, ContactName = "Test", CountryId = 1, CompanyName = "Unit test", Address = new AddressInformation() { Address = "address2", City = "Madrid", Fax = "+340010001", Telephone = "+340010001" }, IsEnabled = true, CustomerPicture = new CustomerPicture() { Photo = null } }; //Act customerService.AddCustomer(customer); Customer inStorage = customerService.FindCustomerByCode(newCustomerCode); //Assert Assert.IsNotNull(inStorage); }
public ActionResult Create(Customer customer) { //Check if there aren't validation errors on the customer. if (ModelState.IsValid) { //Add the customer to the data base. _CustomerService.AddCustomer(customer); //Show the fist page of the customers list. return(RedirectToAction("Index", new { page = 0, pageSize = 10 })); } else { //Return the Create view and display the validation errors. return(View()); } }