public void Test_Simple_Mapping_ProductReview() { var product = new Product { Name = "Product1", ShortDescription = "show", FullDescription = "full", UtcCreationDate = DateTime.UtcNow, UtcUpdateDate = DateTime.UtcNow }; var productReview = new ProductReview { Title = "review1", Product = product, UtcCreationDate = DateTime.UtcNow, UtcUpdateDate = DateTime.UtcNow }; using (ISession session = MySessionFactory.OpenSession()) { ITransaction transaction = session.BeginTransaction(); session.Save(product); session.Save(productReview); transaction.Commit(); } var productReview1 = MySessionFactory.OpenSession().Query<ProductReview>() .Where(it => it.Id == productReview.Id) .FirstOrDefault(); Assert.AreEqual(productReview.Id, productReview1.Id); Assert.AreEqual(product.Id, productReview1.Product.Id); var product1 = MySessionFactory.OpenSession().Query<Product>() .Where(it => it.Id == product.Id) .FirstOrDefault(); Assert.AreEqual(1, product1.ProductReviews.Count); }
public void Test_Add_QueryById_Update_Delete_ProductProvider() { var product = new Product { Name = "Product1", UtcCreationDate = DateTime.UtcNow, UtcUpdateDate = DateTime.UtcNow }; //Add brand provider.Add(product); Console.WriteLine("Add OK!"); //QueryBy var productQueryBy = provider.QueryById(product.Id); Assert.IsNotNull(productQueryBy); Console.WriteLine("QueryBy OK!"); //update product.Name = "newName"; provider.Update(product); var productUpdate = provider.QueryById(product.Id); Assert.AreEqual("newName", productUpdate.Name); Console.WriteLine("Update OK!"); //Delete provider.Delete(product); var productDelete = provider.QueryById(product.Id); Assert.IsNull(productDelete); Console.WriteLine("Delete OK!"); }
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_ProductCategoryProvider() { var category = new Category { Name = "catagory1", Description = "Hello description!", Image = "", PageSize = 10, Published = true, Deleted = false, DisplayOrder = 1, UtcCreationDate = DateTime.UtcNow, UtcUpdateDate = DateTime.UtcNow }; var product = new Product { Name = "Product1", UtcCreationDate = DateTime.UtcNow, UtcUpdateDate = DateTime.UtcNow }; var productCategory = new ProductCategory { IsFeaturedProduct = false, DisplayOrder = 2, Product = product, Category = category }; Mock<IEntityFileProvider> entityFileProvider = new Mock<IEntityFileProvider>(); var categoryProvider = new CategoryProvider(new NoDI_NHibernateContextFactory(), entityFileProvider.Object); //Add brand new ProductProvider(new NoDI_NHibernateContextFactory()).Add(product); categoryProvider.Add(category); provider.Add(productCategory); Console.WriteLine("Add OK!"); //QueryBy var productCategoryQueryBy = provider.QueryById(productCategory.Id); Assert.IsNotNull(productCategoryQueryBy); Console.WriteLine("QueryBy OK!"); //update productCategory.DisplayOrder = 5; provider.Update(productCategory); var productCategoryUpdate = provider.QueryById(productCategory.Id); Assert.AreEqual(5, productCategoryUpdate.DisplayOrder); Console.WriteLine("Update OK!"); //Delete provider.Delete(productCategory); var productCategoryDelete = provider.QueryById(productCategory.Id); Assert.IsNull(productCategoryDelete); Console.WriteLine("Delete OK!"); }
public void Test_Simple_Mapping_ProductCategory() { var category = new Category { Name = "catagory1", Description = "Hello description!", Image = "", PageSize = 10, Published = true, Deleted = false, DisplayOrder = 1, UtcCreationDate = DateTime.UtcNow, UtcUpdateDate = DateTime.UtcNow }; var product = new Product { Name = "Product1", UtcCreationDate = DateTime.UtcNow, UtcUpdateDate = DateTime.UtcNow }; var productCategory = new ProductCategory { IsFeaturedProduct=false, DisplayOrder=2, Product=product, Category=category }; using (ISession session = MySessionFactory.OpenSession()) { ITransaction transaction = session.BeginTransaction(); session.Save(product); session.Save(category); session.Save(productCategory); transaction.Commit(); } var productCategory1 = MySessionFactory.OpenSession().Query<ProductCategory>() .Where(it => it.Id == productCategory.Id) .FirstOrDefault(); Assert.AreEqual(productCategory.Id, productCategory1.Id); Assert.AreEqual(product.Id, productCategory1.Product.Id); Assert.AreEqual(category.Id, productCategory1.Category.Id); Console.WriteLine(productCategory.Id); Console.WriteLine(product.Id); Console.WriteLine(category.Id); var product1 = MySessionFactory.OpenSession().Query<Product>() .Where(it => it.Id == product.Id) .FirstOrDefault(); Assert.AreEqual(1,product1.ProductCategories.Count); }
public void Test_Add_QueryById_Update_Delete_RelatedProductProvider() { var product1 = new Product { Name = "Product1", ShortDescription = "this is product1", FullDescription = "full", UtcCreationDate = DateTime.UtcNow, UtcUpdateDate = DateTime.UtcNow }; var product2 = new Product { Name = "Product2", ShortDescription = "this is product2", FullDescription = "full", UtcCreationDate = DateTime.UtcNow, UtcUpdateDate = DateTime.UtcNow }; var relatedProduct = new RelatedProduct { DisplayOrder = 1, Product1 = product1, Product2 = product2 }; //Add brand ProductProvider productProcider = new ProductProvider(new NoDI_NHibernateContextFactory()); productProcider.Add(product1); productProcider.Add(product2); provider.Add(relatedProduct); Console.WriteLine("Add OK!"); //QueryBy var relatedProductQueryBy = provider.QueryById(relatedProduct.Id); Assert.IsNotNull(relatedProductQueryBy); Console.WriteLine("QueryBy OK!"); //update relatedProduct.DisplayOrder = 5; provider.Update(relatedProduct); var brandUpdate = provider.QueryById(relatedProduct.Id); Assert.AreEqual(5, relatedProduct.DisplayOrder); Console.WriteLine("Update OK!"); //Delete provider.Delete(relatedProduct); var relatedProductDelete = provider.QueryById(relatedProduct.Id); Assert.IsNull(relatedProductDelete); Console.WriteLine("Delete OK!"); }
public void Test_Simple_Mapping_Product() { var p = new Product { Name = "Product1", UtcCreationDate = DateTime.UtcNow, UtcUpdateDate = DateTime.UtcNow }; using (ISession session = MySessionFactory.OpenSession()) { ITransaction transaction = session.BeginTransaction(); session.Save("Product", p); transaction.Commit(); } }
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_Add_QueryById_Update_Delete_ProductReviewProvider() { var product = new Product { Name = "Product1", ShortDescription = "show", FullDescription = "full", UtcCreationDate = DateTime.UtcNow, UtcUpdateDate = DateTime.UtcNow }; var productReview = new ProductReview { Title = "review1", Product = product, UtcCreationDate=DateTime.UtcNow, UtcUpdateDate=DateTime.UtcNow }; //Add brand new ProductProvider(new NoDI_NHibernateContextFactory()).Add(product); provider.Add(productReview); Console.WriteLine("Add OK!"); //QueryBy var productReviewQueryBy = provider.QueryById(productReview.Id); Assert.IsNotNull(productReviewQueryBy); Console.WriteLine("QueryBy OK!"); //update productReview.Title = "review"; provider.Update(productReview); var productReviewUpdate = provider.QueryById(productReview.Id); Assert.AreEqual("review", productReviewUpdate.Title); Console.WriteLine("Update OK!"); //Delete provider.Delete(productReview); var productReviewDelete = provider.QueryById(productReview.Id); Assert.IsNull(productReviewDelete); 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); }
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!"); }
public void Test_Simple_Mapping_RelatedProduct() { var product1 = new Product { Name = "Product1", ShortDescription = "this is product1", FullDescription = "full", UtcCreationDate = DateTime.UtcNow, UtcUpdateDate = DateTime.UtcNow }; var product2 = new Product { Name = "Product2", ShortDescription = "this is product2", FullDescription = "full", UtcCreationDate = DateTime.UtcNow, UtcUpdateDate = DateTime.UtcNow }; var relatedProduct = new RelatedProduct { DisplayOrder = 1, Product1 = product1, Product2 = product2 }; using (ISession session = MySessionFactory.OpenSession()) { ITransaction transcation = session.BeginTransaction(); session.Save(product1); session.Save(product2); session.Save(relatedProduct); transcation.Commit(); } var relatedProduct1 = MySessionFactory.OpenSession().Query<RelatedProduct>() .Where(it => it.Id == relatedProduct.Id) .FirstOrDefault(); Assert.AreEqual(relatedProduct.Id, relatedProduct1.Id); Assert.AreEqual(product1.Id, relatedProduct1.Product1.Id); Assert.AreEqual(product2.Id, relatedProduct1.Product2.Id); }
/// <summary> /// Sets the specified product. /// Change the product context. /// </summary> /// <param name="product">The product.</param> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public IProductAPI Set(Product product) { this._product = product; return this; }
public IEnumerable<ProductVariant> QueryByProduct(Product product) { return new ProductVariant[0]; }