public void Test_Simple_Mapping_ProductImage() { var product = new Product { Name = "Product1", ShortDescription = "show", FullDescription = "full", UtcCreationDate = DateTime.UtcNow, UtcUpdateDate = DateTime.UtcNow }; var productImage = new ProductImage { ImageType="jpg", ImageUrl="image/1.jpg", Product=product }; using (ISession session = MySessionFactory.OpenSession()) { ITransaction transaction = session.BeginTransaction(); session.Save(product); session.Save(productImage); transaction.Commit(); } var productImage1 = MySessionFactory.OpenSession().Query<ProductImage>() .Where(it => it.Id == productImage.Id) .FirstOrDefault(); Assert.AreEqual(productImage.Id, productImage1.Id); Assert.AreEqual(product.Id,productImage1.Product.Id); var product1 = MySessionFactory.OpenSession().Query<Product>() .Where(it => it.Id == product.Id) .FirstOrDefault(); Assert.AreEqual(1, product1.ProductImages.Count); }
public void Test_Add_QueryById_Update_Delete_BrandProvider() { var product = new Product { Name = "Product1", ShortDescription = "show", FullDescription = "full", UtcCreationDate = DateTime.UtcNow, UtcUpdateDate = DateTime.UtcNow }; var productImage = new ProductImage { ImageType = "jpg", ImageUrl = "image/1.jpg", Product = product }; //Add brand new ProductProvider(new NoDI_NHibernateContextFactory()).Add(product); provider.Add(productImage); Console.WriteLine("Add OK!"); //QueryBy var productImageQueryBy = provider.QueryById(productImage.Id); Assert.IsNotNull(productImageQueryBy); Console.WriteLine("QueryBy OK!"); //update productImage.ImageType = "type"; provider.Update(productImage); var productImageUpdate = provider.QueryById(productImage.Id); Assert.AreEqual("type", productImageUpdate.ImageType); Console.WriteLine("Update OK!"); //Delete provider.Delete(productImage); var productImageDelete = provider.QueryById(productImage.Id); Assert.IsNull(productImageDelete); Console.WriteLine("Delete OK!"); }