public void Test_Add_QueryById_Update_Delete_ProductBrandProvider() { var product = new Product { Name = "Product1", UtcCreationDate = DateTime.UtcNow, UtcUpdateDate = DateTime.UtcNow }; var brand = new Brand { Name = "secondBrand", Description = "Hello description!", UtcCreationDate = DateTime.UtcNow, UtcUpdateDate = DateTime.UtcNow }; var productbrand = new ProductBrand { IsFeaturedProduct = false, DisplayOrder = 1, Brand = brand, Product = product }; //Add new ProductProvider(new NoDI_NHibernateContextFactory()).Add(product); Mock<IEntityFileProvider> entityFileProvider = new Mock<IEntityFileProvider>(); new BrandProvider(new NoDI_NHibernateContextFactory(),entityFileProvider.Object).Add(brand); provider.Add(productbrand); Console.WriteLine("Add Ok!"); //QueryById var productbrandQueryBy = provider.QueryById(productbrand.Id); Assert.IsNotNull(productbrandQueryBy); Console.WriteLine("QueryBy OK!"); //Update productbrand.DisplayOrder = 2; provider.Update(productbrand); var productbrandUpdate = provider.QueryById(productbrand.Id); Assert.AreEqual(2, productbrandUpdate.DisplayOrder); Console.WriteLine("Update OK!"); //Delete provider.Delete(productbrand); var productbrandDelete = provider.QueryById(productbrand.Id); Assert.IsNull(productbrandDelete); Console.WriteLine("Delete OK!"); }
public void Test_Simple_Mapping_ProductBrand() { var product = new Product { Name = "Product1", UtcCreationDate = DateTime.UtcNow, UtcUpdateDate = DateTime.UtcNow }; var brand = new Brand { Name = "secondBrand", Description = "Hello description!", UtcCreationDate = DateTime.UtcNow, UtcUpdateDate = DateTime.UtcNow }; var productbrand = new ProductBrand { IsFeaturedProduct = false, DisplayOrder = 1, Brand = brand, Product = product }; using (ISession session = MySessionFactory.OpenSession()) { ITransaction transaction = session.BeginTransaction(); session.Save(product); session.Save(brand); session.Save(productbrand); transaction.Commit(); } var productbrand1 = MySessionFactory.OpenSession().Query<ProductBrand>() .Where(it => it.Id == productbrand.Id) .FirstOrDefault(); Assert.AreEqual(productbrand1.Id, productbrand.Id); var product1 = MySessionFactory.OpenSession().Query<Product>() .Where(it => it.Id == product.Id) .FirstOrDefault(); Assert.AreEqual(1, product1.ProductBrands.Count); }