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!");
        }
Beispiel #2
0
        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);
        }