示例#1
0
        /// <summary>
        /// <see cref="Microsoft.Samples.NLayerApp.DistributedServices.MainModule.IMainModuleService"/>
        /// </summary>
        /// <param name="product"><see cref="Microsoft.Samples.NLayerApp.DistributedServices.MainModule.IMainModuleService"/></param>
        public void ChangeProduct(Product product)
        {
            try
            {
                //Resolve root dependencies and perform query
                ISalesManagementService salesManagement = IoCFactory.Instance.CurrentContainer.Resolve <ISalesManagementService>();

                salesManagement.ChangeProduct(product);
            }
            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);
            }
        }
示例#2
0
        public void ChangeProduct_Invoke_NullItemThrowArgumentNullException_Test()
        {
            //Arrange
            ISalesManagementService productService = IoCFactory.Instance.CurrentContainer.Resolve <ISalesManagementService>();

            productService.ChangeProduct(null);
        }
示例#3
0
        public void ChangeProduct_Invoke_Test()
        {
            //Arrange
            ISalesManagementService productService = IoCFactory.Instance.CurrentContainer.Resolve <ISalesManagementService>();
            string publisherName = "Krasis Press";
            //Act
            List <Product> products = productService.FindProductBySpecification(publisherName, null);
            Product        product  = products.FirstOrDefault();

            product.UnitAmount = "$";

            productService.ChangeProduct(product);
            products = productService.FindProductBySpecification(publisherName, null);
            product  = products.FirstOrDefault();

            //Assert
            Assert.IsNotNull(product);
            Assert.IsTrue(product.UnitAmount == "$");
        }