public void FindPagedCustomers_Invoke_NullPageCountThrowArgumentException_Test()
        {
            //Arrange
            ICustomerManagementService customerService = IoCFactory.Instance.CurrentContainer.Resolve <ICustomerManagementService>();

            //Act
            List <Customer> customers = customerService.FindPagedCustomers(0, 0);
        }
        public void FindPagedCustomer_Invoke_Test()
        {
            //Arrange
            ICustomerManagementService customerService = IoCFactory.Instance.CurrentContainer.Resolve <ICustomerManagementService>();
            int pageIndex = 0;
            int pageCount = 1;

            //Act
            List <Customer> customers = customerService.FindPagedCustomers(pageIndex, pageCount);

            //Assert
            Assert.IsNotNull(customers);
            customers.ForEach(c => Assert.IsTrue(c.IsEnabled));
        }
        /// <summary>
        /// <see cref="Microsoft.Samples.NLayerApp.DistributedServices.MainModule.IMainModuleService"/>
        /// </summary>
        /// <param name="pagedCriteria"><see cref="Microsoft.Samples.NLayerApp.DistributedServices.MainModule.IMainModuleService"/></param>
        /// <returns><see cref="Microsoft.Samples.NLayerApp.DistributedServices.MainModule.IMainModuleService"/></returns>
        public List <Customer> GetPagedCustomer(PagedCriteria pagedCriteria)
        {
            try
            {
                //resolve root dependencies and perform query
                using (ICustomerManagementService customerService = IoCFactory.Instance.CurrentContainer.Resolve <ICustomerManagementService>())
                {
                    return(customerService.FindPagedCustomers(pagedCriteria.PageIndex, pagedCriteria.PageCount));
                }
            }
            catch (ArgumentException 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);
            }
            catch (NullReferenceException 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);
            }
        }
Exemple #4
0
        /// <summary>
        /// Display a paged listing of the existing customers.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="pageSize">The page size.</param>
        /// <returns></returns>
        public ActionResult Index(int page, int pageSize)
        {
            IList <Customer> customers = _CustomerService.FindPagedCustomers(page, pageSize);

            return(View(new CustomerListViewModel(customers, page, pageSize)));
        }