コード例 #1
0
        public void GetEstimatedDeliveryTime(int productId, out int unitsAvailable, out int estimatedDeliveryTimeInDays)
        {
            OrderBusinessComponent    orderBC    = DependencyInjectionHelper.GetOrderBusinessComponent();
            SupplierBusinessComponent supplierBC = DependencyInjectionHelper.GetSupplierBusinessComponent();
            Product product = rep.GetById(productId);

            int unitsOrdered = orderBC.GetAllOrderDetails()
                               .Where(od => od.Product.ProductId == product.ProductId)
                               .Sum(od => od.QuantityInUnits);

            unitsAvailable = product.UnitsOnStock - unitsOrdered;
            if ((unitsAvailable) < 0)
            {
                unitsAvailable = 0;
            }

            estimatedDeliveryTimeInDays = -1;
            IQueryable <Supplier> defaultSuppliers = supplierBC.GetSuppliersByCriteria(SupplierSearchType.None, null, 0);

            foreach (Supplier supplier in defaultSuppliers)
            {
                if (supplier.ActiveFlag && supplier.PreferredSupplierFlag)
                {
                    Supplier        supplierWithCondition = supplierBC.GetSupplierById(supplier.SupplierId);
                    SupplierProduct supProd = supplierWithCondition.SupplierProduct.FirstOrDefault(c => c.Product.ProductId == productId);
                    if (supProd != null)
                    {
                        estimatedDeliveryTimeInDays = supProd.AverageLeadTimeInDays;
                        return;
                    }
                }
            }
        }
コード例 #2
0
        public void TestGetOrderById()
        {
            OrderBusinessComponent service = new OrderBusinessComponent(this.context);
            Order order = new Order() {OrderId = 123};

            Expect.Once.On(context).Method("GetById").Will(Return.Value(order));
            Order resultOrder = service.GetOrderById(123);
            Assert.AreEqual<decimal>(order.OrderId, resultOrder.OrderId);
            mockBuilder.VerifyAllExpectationsHaveBeenMet();
        }
コード例 #3
0
        public void TestGetOrderByCriteria()
        {
            OrderBusinessComponent service = new OrderBusinessComponent(this.context);
            Order order = new Order {OrderId = 456, Customer = new Customer {CustomerId = 1234}};
            IList<Order> orders = new List<Order> {order};

            foreach (OrderSearchType type in Enum.GetValues(typeof (OrderSearchType)))
            {
                Expect.Once.On(context).Method("GetAll").Will(Return.Value(orders.AsQueryable()));
                IQueryable<Order> resultOrders = service.GetOrdersByCriteria(type, 1234);
                Assert.AreEqual<decimal>(1, resultOrders.Count());
                Assert.AreEqual<decimal>(order.OrderId, resultOrders.First().OrderId);
            }

            mockBuilder.VerifyAllExpectationsHaveBeenMet();
        }
コード例 #4
0
        public void GetEstimatedDeliveryTime(int productId, out int unitsAvailable, out int estimatedDeliveryTimeInDays)
        {
            OrderBusinessComponent orderBC = DependencyInjectionHelper.GetOrderBusinessComponent();
            Product product = this.repository.GetById(productId);

            int unitsOrdered = orderBC.GetAllOrderDetails().Where(od => od.Product.ProductId == product.ProductId).Sum(od => od.QuantityInUnits);

            unitsAvailable = product.UnitsOnStock - unitsOrdered;
            if ((unitsAvailable) < 0)
            {
                unitsAvailable = 0;
            }

            estimatedDeliveryTimeInDays = -1;
            // Todo: Implement the logic to calculate the estimatedDelivertyTimeInDays (see SupplierCondition)
        }
コード例 #5
0
        public void TestStoreOrder()
        {
            int orderId = 123;
            OrderBusinessComponent service = new OrderBusinessComponent(this.context);
            Order order = new Order() {OrderId = orderId};
            List<ChangeItem> changeItems = new List<ChangeItem>
                                               {
                                                   new ChangeItem(ChangeType.ChildInsert, new OrderDetail()),
                                                   new ChangeItem(ChangeType.ChildUpate, new OrderDetail()),
                                                   new ChangeItem(ChangeType.ChildDelete, new OrderDetail())
                                               };

            Expect.Once.On(context).Method("SaveOrder").Will(Return.Value(orderId));
            Expect.Once.On(context).Method("SaveOrderDetail").Will(Return.Value(1));
            Expect.Once.On(context).Method("SaveOrderDetail").Will(Return.Value(1));
            Expect.Once.On(context).Method("DeleteOrderDetail");
            int resultOrderId = service.StoreOrder(order, changeItems);
            Assert.AreEqual<int>(orderId, resultOrderId);

            mockBuilder.VerifyAllExpectationsHaveBeenMet();
        }
コード例 #6
0
        public void TestDeleteOrder()
        {
            OrderBusinessComponent service = new OrderBusinessComponent(this.context);

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