public void SetOrderShipped(int orderId, DateTime shippedDate)
        {
            // If a transaction exists already, this transaction scope will join it.
            // Otherwise, it will create its own transaction.
            using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.Required))
            {
                Order order = rep.GetById(orderId);
                if (!(order is MissingOrder))
                {
                    order.ShippedDate = shippedDate;
                    order.OrderStatus = OrderStatus.Shipped;
                    rep.SaveOrder(order, false);

                    ProductBusinessComponent productBC = DependencyInjectionHelper.GetProductBusinessComponent();
                    foreach (OrderDetail detail in order.OrderDetails)
                    {
                        Product product      = detail.Product;
                        int     unitsOnStock = product.UnitsOnStock - detail.QuantityInUnits;
                        product.UnitsOnStock = unitsOnStock > 0 ? unitsOnStock : 0;
                        productBC.StoreProduct(product);
                    }
                }
                transaction.Complete();
            }
        }
        public void TestGetProductById()
        {
            ProductBusinessComponent service = new ProductBusinessComponent(this.context);
            Product product = new Product() {ProductId = 123};

            Expect.Once.On(context).Method("GetById").Will(Return.Value(product));
            Product resultProduct = service.GetProductById(123);
            Assert.AreEqual<decimal>(product.ProductId, resultProduct.ProductId);
            mockBuilder.VerifyAllExpectationsHaveBeenMet();
        }
        public void TestStoreProduct()
        {
            int productId = 123;
            ProductBusinessComponent service = new ProductBusinessComponent(this.context);
            Product product = new Product() {ProductId = 456, Name = "FakeProduct", Category = "FakeCategory"};

            Expect.Once.On(context).Method("SaveProduct").Will(Return.Value(productId));
            int resultProductId = service.StoreProduct(product);
            Assert.AreEqual<int>(productId, resultProductId);

            mockBuilder.VerifyAllExpectationsHaveBeenMet();
        }
        public void TestGetProductByCriteria()
        {
            ProductBusinessComponent service = new ProductBusinessComponent(this.context);
            Product product = new Product() {ProductId = 456, Name = "FakeProduct", Category = "FakeCategory"};
            IList<Product> products = new List<Product>();
            products.Add(product);

            foreach (ProductSearchType type in Enum.GetValues(typeof (ProductSearchType)))
            {
                Expect.Once.On(context).Method("GetAll").Will(Return.Value(products.AsQueryable()));
                IQueryable<Product> resultProducts = service.GetProductsByCriteria(type, "FakeCategory", "FakeProduct");
                Assert.AreEqual<decimal>(1, resultProducts.Count());
                Assert.AreEqual<decimal>(product.ProductId, resultProducts.First().ProductId);
            }

            mockBuilder.VerifyAllExpectationsHaveBeenMet();
        }
        public void TestDeleteProduct()
        {
            ProductBusinessComponent service = new ProductBusinessComponent(this.context);

            Expect.Once.On(context).Method("DeleteProduct").With(1);
            service.DeleteProduct(1);
            mockBuilder.VerifyAllExpectationsHaveBeenMet();
        }