public void ExistInStock_LessThanZeroAmountInStockReturnFalse_Test()
        {
            //Arrange
            Product product = new Product()
            {
                ProductId = 1,
                AmountInStock = 0
            };
            //act
            bool result = product.ExistStock();

            //Assert
            Assert.IsFalse(result);
        }
        public void ExistInStock_Invoke_Test()
        {
            //Arrange
            Product product = new Product()
            {
                ProductId = 1,
                AmountInStock = 10
            };
            //act
            bool result = product.ExistStock();

            //Assert
            Assert.IsTrue(result);
        }
        /// <summary>
        /// <see cref="Microsoft.Samples.NLayerApp.Application.MainModule.SalesManagement.ISalesManagementService"/>
        /// </summary>
        /// <param name="product"><see cref="Microsoft.Samples.NLayerApp.Application.MainModule.SalesManagement.ISalesManagementService"/></param>
        public void AddProduct(Product product)
        {


            IUnitOfWork unitOfWork = _productRepository.UnitOfWork as IUnitOfWork;


            _productRepository.Add(product);

            //complete changes in this unit of work
            unitOfWork.Commit();

        }
        /// <summary>
        /// <see cref="Microsoft.Samples.NLayerApp.Application.MainModule.SalesManagement.ISalesManagementService"/>
        /// </summary>
        /// <param name="product"><see cref="Microsoft.Samples.NLayerApp.Application.MainModule.SalesManagement.ISalesManagementService"/></param>
        public void ChangeProduct(Product product)
        {


            IUnitOfWork unitOfWork = _productRepository.UnitOfWork as IUnitOfWork;


            _productRepository.Modify(product);

            //complete changes in this unit of work
            unitOfWork.CommitAndRefreshChanges();

        }
        public void AddProduct_Invoke_Test()
        {
            //Arrange
            using (ISalesManagementService productService = IoCFactory.Instance.CurrentContainer.Resolve<ISalesManagementService>())
            {
                Product product = new Product()
                {
                    AmountInStock = 10,
                    ProductDescription = "product description",
                    Publisher = "Microsoft Samples",
                    UnitAmount = "€",
                    UnitPrice = 100M
                };

                //Act
                productService.AddProduct(product);
                List<Product> products = productService.FindProductBySpecification("Microsoft Samples", null);

                //Assert
                Assert.IsNotNull(products);
                Assert.IsTrue(products.Count == 1);
            }
        }
     private void FixupProduct(Product previousValue)
     {
         if (IsDeserializing)
         {
             return;
         }
 
         if (previousValue != null && previousValue.OrderDetails.Contains(this))
         {
             previousValue.OrderDetails.Remove(this);
         }
 
         if (Product != null)
         {
             if (!Product.OrderDetails.Contains(this))
             {
                 Product.OrderDetails.Add(this);
             }
 
             ProductId = Product.ProductId;
         }
         if (ChangeTracker.ChangeTrackingEnabled)
         {
             if (ChangeTracker.OriginalValues.ContainsKey("Product")
                 && (ChangeTracker.OriginalValues["Product"] == Product))
             {
                 ChangeTracker.OriginalValues.Remove("Product");
             }
             else
             {
                 ChangeTracker.RecordOriginalValue("Product", previousValue);
             }
             if (Product != null && !Product.ChangeTracker.ChangeTrackingEnabled)
             {
                 Product.StartTracking();
             }
         }
     }
        /// <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);
            }
        }