Exemplo n.º 1
0
        public void FindPagedProducts_Invoke_NullPageCountThrowArgumentException_Test()
        {
            //Arrange
            ISalesManagementService productService = IoCFactory.Instance.CurrentContainer.Resolve <ISalesManagementService>();

            //Act
            List <Product> products = productService.FindPagedProducts(0, 0);
        }
Exemplo n.º 2
0
        public void FindPagedProducts_Invoke_Tests()
        {
            //Arrange
            ISalesManagementService productService = IoCFactory.Instance.CurrentContainer.Resolve <ISalesManagementService>();
            int pageIndex = 0;
            int pageCount = 1;

            //Act
            List <Product> products = productService.FindPagedProducts(pageIndex, pageCount);

            //Assert
            Assert.IsNotNull(products);
            Assert.IsTrue(products.Count == 1);
        }
        /// <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 <Product> GetPagedProducts(PagedCriteria pagedCriteria)
        {
            try
            {
                //Resolve root dependencies and perform query
                using (ISalesManagementService salesManagement = IoCFactory.Instance.CurrentContainer.Resolve <ISalesManagementService>())
                {
                    return(salesManagement.FindPagedProducts(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);
            }
        }