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

            //Assert
            Assert.IsFalse(result);
        }
コード例 #2
0
        public void ExistInStock_Invoke_Test()
        {
            //Arrange
            Product product = new Product()
            {
                ProductId = 1,
                AmountInStock = 10
            };
            //act
            bool result = product.ExistStock();

            //Assert
            Assert.IsTrue(result);
        }
コード例 #3
0
        /// <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();

        }
コード例 #4
0
        /// <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();

        }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
     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();
             }
         }
     }
コード例 #7
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);
            }
        }