/// <summary>
        /// <see cref="Microsoft.Samples.NLayerApp.DistributedServices.MainModule.IMainModuleService"/>
        /// </summary>
        /// <param name="customerCode"><see cref="Microsoft.Samples.NLayerApp.DistributedServices.MainModule.IMainModuleService"/></param>
        /// <returns><see cref="Microsoft.Samples.NLayerApp.DistributedServices.MainModule.IMainModuleService"/></returns>
        public Customer GetCustomerByCode(string customerCode)
        {
            try
            {
                //Resolve root dependency and perform operation
                using (ICustomerManagementService customerService = IoCFactory.Instance.CurrentContainer.Resolve <ICustomerManagementService>())
                {
                    return(customerService.FindCustomerByCode(customerCode));
                }
            }
            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_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);
        }
示例#3
0
        /// <summary>
        /// Returns the picture of the customer.
        /// </summary>
        /// <param name="customerCode">The customer code.</param>
        /// <returns>The picture of the customer.</returns>
        public ActionResult CustomerPicture(string customerCode)
        {
            //Get the customer aggregate
            CustomerPicture photo = _CustomerService.FindCustomerByCode(customerCode).CustomerPicture;

            //Check if the customer has a photo and if it is a valid photo.
            if (photo != null && photo.Photo != (byte [])null)
            {
                //Return the associated customer photo.
                return(File(photo.Photo, "img"));
            }
            else
            {
                // Return a default picture if the customer hasn't got any photo.
                return(File("~/Content/Images/Unknown.png", "img/png"));
            }
        }
        public void DeleteCustomer_Invoke_Test()
        {
            //Arrange
            ICustomerManagementService customerService = IoCFactory.Instance.CurrentContainer.Resolve <ICustomerManagementService>();

            Customer randomCustomer = null;

            //Act
            randomCustomer = customerService.FindCustomerByCode("A0001");

            customerService.RemoveCustomer(randomCustomer);

            //Assert

            Customer removedCustomer = customerService.FindCustomerByCode("A0001");

            Assert.IsNull(removedCustomer);
        }
        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);
        }
        public void FindCustomerByCode_Invoke_Test()
        {
            //Arrange
            ICustomerManagementService customerService = IoCFactory.Instance.CurrentContainer.Resolve <ICustomerManagementService>();
            string customerCode = "A0004";

            //Act
            Customer customer = customerService.FindCustomerByCode(customerCode);

            //Assert
            Assert.IsNotNull(customer);
            Assert.AreEqual(customer.CustomerCode, customerCode);
        }