コード例 #1
0
        public void TestCanAddNewOrder()
        {
            // prepare
            var ordersProduct = new OrdersProduct(14, 8.1818m)
            {
                Item_id = 3, Order_id = 29
            };
            IOrdersProductRepository repository = new OrdersProductRepository();

            // run
            repository.Add(ordersProduct);

            // validate
            // use session to try to load the product

            using (ISession session = _sessionFactory.OpenSession())
            {
                var fromDb = session.Get <OrdersProduct>(ordersProduct.Id);

                // Test that the product was successfully inserted

                Assert.IsNotNull(fromDb);
                Assert.AreNotSame(ordersProduct, fromDb);
                Assert.AreEqual(ordersProduct.Id, fromDb.Id);
                Assert.AreEqual(ordersProduct.Amount, fromDb.Amount);
            }
        }
コード例 #2
0
        public void AddOrder()
        {
            Dictionary <string, OrdersProduct> dict = ReturnOrderedCart();

            IPurchaseRepository      repository0 = new PurchaseRepository();
            IProductRepository       repository1 = new ProductRepository();
            IOrdersProductRepository repository2 = new OrdersProductRepository();
            var order = new Purchase();

            repository0.Add(order);
            foreach (string key in dict.Keys)
            {
                var product = repository1.GetByBarcode(key);
                dict[key].Item_id  = product.Id;
                dict[key].Order_id = order.Id;
                repository2.Add(dict[key]);
            }
            cart.Clear();
        }