/// <summary>
        /// <see cref="Microsoft.Samples.NLayerApp.DistributedServices.MainModule.IMainModuleService"/>
        /// </summary>
        /// <param name="customer"><see cref="Microsoft.Samples.NLayerApp.DistributedServices.MainModule.IMainModuleService"/></param>
        public void ChangeCustomer(Customer customer)
        {
            try
            {
                //Resolve root dependency and perform operation
                using (ICustomerManagementService customerService = IoCFactory.Instance.CurrentContainer.Resolve <ICustomerManagementService>())
                {
                    customerService.ChangeCustomer(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 ChangeCustomer_Invoke_NullItemThrowNewArgumentNullException_Test()
        {
            //Arrange
            ICustomerManagementService customerService = IoCFactory.Instance.CurrentContainer.Resolve <ICustomerManagementService>();

            //Act
            customerService.ChangeCustomer(null);
        }
        public void ChangeCustomer_Invoke_Test()
        {
            //Arrange
            ICustomerManagementService customerService = IoCFactory.Instance.CurrentContainer.Resolve <ICustomerManagementService>();
            string   customerCode = "A0004";
            Customer customer     = customerService.FindCustomerByCode(customerCode);

            //Act
            customer.ContactName = "Set new customer name";
            customerService.ChangeCustomer(customer);
        }
Exemplo n.º 4
0
 public ActionResult Edit(Customer customer)
 {
     if (ModelState.IsValid)
     {
         _CustomerService.ChangeCustomer(customer);
         return(RedirectToAction("Details", new RouteValueDictionary()
         {
             { "customerCode", customer.CustomerCode }
         }));
     }
     else
     {
         return(View());
     }
 }