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); } }
public void TestCanUpdate() { //Prepare OrdersProduct originalOrdersProduct = new OrdersProduct(2, 10m) { Item_id = 3, Order_id = 29 }; OrdersProduct testOrdersProduct = new OrdersProduct(3, 8.1818m) { Item_id = 3, Order_id = 29 }; OrdersProductRepository repository = new OrdersProductRepository(); //Run using (ISession session = _sessionFactory.OpenSession()) { session.Save(originalOrdersProduct); testOrdersProduct.Id = originalOrdersProduct.Id; repository.Update(testOrdersProduct); } //Validate using (ISession session = _sessionFactory.OpenSession()) { //second session is used so fromDB get to take the changed table entry var fromDb = session.Get <OrdersProduct>(originalOrdersProduct.Id); Assert.IsNotNull(fromDb); Assert.AreEqual(testOrdersProduct.Amount, fromDb.Amount); } }
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(); }
public void TestCanDelete() { //prepare OrdersProduct testOrdersProduct = new OrdersProduct(4, 8.1818m) { Item_id = 3, Order_id = 29 }; OrdersProductRepository repository = new OrdersProductRepository(); //run using (ISession session = _sessionFactory.OpenSession()) { session.Save(testOrdersProduct); repository.Remove(testOrdersProduct); } //validate using (ISession session = _sessionFactory.OpenSession()) { var fromDb = session.Get <Purchase>(testOrdersProduct.Id); Assert.IsNull(fromDb); } }