public void Can_update_existing_product() { var product = _products[0]; product.Name = "Yellow Pear"; IProductRepository repository = new ProductRepository(); repository.Update(product); // use session to try to load the product using (ISession session = _sessionFactory.OpenSession()) { var fromDb = session.Get<Product>(product.Id); Assert.AreEqual(product.Name, fromDb.Name); } }
public void Can_add_new_product() { var product = new Product { Name = "Apple", Category = "Fruits" }; IProductRepository repository = new ProductRepository(); repository.Add(product); // use session to try to load the product using (ISession session = _sessionFactory.OpenSession()) { var fromDb = session.Get<Product>(product.Id); // Test that the product was successfully inserted Assert.IsNotNull(fromDb); Assert.AreNotSame(product, fromDb); Assert.AreEqual(product.Name, fromDb.Name); Assert.AreEqual(product.Category, fromDb.Category); } }
public void Can_remove_existing_product() { var product = _products[0]; IProductRepository repository = new ProductRepository(); repository.Remove(product); using (ISession session = _sessionFactory.OpenSession()) { var fromDB = session.Get<Product>(product.Id); Assert.IsNull(fromDB); } }
public void Can_get_existing_products_by_category() { IProductRepository repository = new ProductRepository(); var fromDb = repository.GetByCategory("Fruits"); Assert.AreEqual(2, fromDb.Count); Assert.IsTrue(IsInCollection(_products[0], fromDb)); Assert.IsTrue(IsInCollection(_products[1], fromDb)); }
public void Can_get_existing_product_by_name() { IProductRepository repository = new ProductRepository(); var fromDb = repository.GetByName(_products[1].Name); Assert.IsNotNull(fromDb); Assert.AreNotSame(_products[1], fromDb); Assert.AreEqual(_products[1].Id, fromDb.Id); }