Ejemplo n.º 1
0
 public decimal CalculateTax(Order order)
 {
     if (order.StateCode == "OH")
         return Math.Round(order.TotalPriceOfAllProducts * .07m, 2);
     else if (order.StateCode == "MI")
         return Math.Round(order.TotalPriceOfAllProducts * .065m, 2);
     return 0;
 }
        protected override void Establish_context()
        {
            var productRepository = ObjectFactory.GetInstance<ISaveObjectService<Product>>();
            var orderRepository = ObjectFactory.GetInstance<ISaveObjectService<Order>>();

            var product = new Product { Price = 10, IsActive = true, Name = "foo" };
            productRepository.Create(product);

            _order = new Order
                         {
                             StateCode = "OH",
                             Products = new List<Product> { product }
                         };
            orderRepository.Create(_order);
            _orderProcessor = ObjectFactory.GetInstance<IOrderProcessor>();
        }
Ejemplo n.º 3
0
 public ActionResult AddToOrder(int productId)
 {
     var product = _getProductService.Get(productId);
     var orderId = (int?) _session["OrderId"];
     if (orderId != null)
     {
         var order = _getOrderService.Get(orderId.Value);
         order.Products.Add(product);
         _saveOrderService.Update(order);
     }
     else
     {
         var order = new Order();
         order.Products.Add(product);
         _saveOrderService.Create(order);
         _session["OrderId"] = order.OrderId;
     }
     return RedirectToAction("Index");
 }
        protected override void Establish_context()
        {
            base.Establish_context();

            // order
            _order = new Order
                         {
                             OrderId = 111,
                             StateCode = "OH"
                         };
            _mocker.Get<IGetObjectService<Order>>().Stub(s => s.Get(111)).Return(_order);
            _session["OrderId"] = 111;

            _mocker.Get<IGetProductService>().Stub(s => s.Get(3)).Return(new Product { ProductId = 3 });
        }
        protected override void Establish_context()
        {
            base.Establish_context();

            // order
            var order = new Order
                            {
                                OrderId = 111,
                                Products = new List<Product> { _product1, _product2 },
                                StateCode = "OH"
                            };
            _mocker.Get<IGetObjectService<Order>>().Stub(s => s.Get(111)).Return(order);
            _session["OrderId"] = 111;

            // order processor - we've already tested that the order
            // processor works, so we don't need to do it again
            var orderProcessor = _mocker.Get<IOrderProcessor>();
            orderProcessor.Stub(op => op.SubtotalBeforeTaxAndShipping(order)).Return(3.33m);
            orderProcessor.Stub(op => op.ShippingCharges(order)).Return(5);
            orderProcessor.Stub(op => op.Tax(order)).Return(0.23m);
            orderProcessor.Stub(op => op.TotalPrice(order)).Return(8.56m);
        }
 protected override void Establish_context()
 {
     _order = OrderBuilder.CreateOrderWithProductsForState("OH");
 }