コード例 #1
0
ファイル: ProductCategoryTest.cs プロジェクト: qgate/CMS
        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);
        }
コード例 #2
0
ファイル: CategoryTest.cs プロジェクト: qgate/CMS
        public void Test_Parent_Mapping_Category()
        {
            var session   = MySessionFactory.OpenSession();
            var category1 = new Category
            {
                Name        = "catagory1",
                Description = "Hello description!",

                UtcCreationDate = DateTime.UtcNow,
                UtcUpdateDate   = DateTime.UtcNow,
                Parent          = null
            };
            var category2 = new Category
            {
                Name        = "catagory2",
                Description = "Hello description!",

                UtcCreationDate = DateTime.UtcNow,
                UtcUpdateDate   = DateTime.UtcNow,

                Parent = category1
            };

            using (ITransaction transaction = session.BeginTransaction())
            {
                session.Save(category1);
                session.Save(category2);
                transaction.Commit();
            }


            Assert.AreNotEqual(0, category2.Id);

            var actualCategory2 = session.Query <Category>()
                                  .Where(it => it.Id == category2.Id)
                                  .FirstOrDefault();

            Assert.AreEqual(category2.Id, actualCategory2.Id);

            session = MySessionFactory.OpenSession();

            var actualCategory1 = session.Query <Category>()
                                  .Where(it => it.Id == category1.Id)
                                  .FirstOrDefault();

            using (var transaction = session.BeginTransaction())
            {
                session.Delete(actualCategory1);
                transaction.Commit();
            }
        }
コード例 #3
0
        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();
            }
        }
コード例 #4
0
ファイル: BrandTest.cs プロジェクト: qgate/CMS
        public void Test_Simple_Mapping_Brand()
        {
            var brand = new Brand
            {
                Name            = "secondBrand",
                Description     = "Hello description!",
                UtcCreationDate = DateTime.UtcNow,
                UtcUpdateDate   = DateTime.UtcNow
            };

            using (ISession session = MySessionFactory.OpenSession())
            {
                session.Save(brand);
                using (ITransaction transaction = session.BeginTransaction())
                {
                    transaction.Commit();
                }
            }
        }
コード例 #5
0
ファイル: ProductBrandTest.cs プロジェクト: qgate/CMS
        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);
        }
コード例 #6
0
ファイル: RelatedProductTest.cs プロジェクト: qgate/CMS
        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);
        }
コード例 #7
0
ファイル: ProductReviewTest.cs プロジェクト: qgate/CMS
        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);
        }
コード例 #8
0
ファイル: CategoryTest.cs プロジェクト: qgate/CMS
        public void Test_Simple_Mapping_Category()
        {
            var category = new Category
            {
                Name            = "catagory1",
                Description     = "Hello description!",
                Image           = "",
                PageSize        = 10,
                Published       = true,
                Deleted         = false,
                DisplayOrder    = 1,
                UtcCreationDate = DateTime.UtcNow,
                UtcUpdateDate   = DateTime.UtcNow
            };

            using (ISession session = MySessionFactory.OpenSession())
            {
                ITransaction transaction = session.BeginTransaction();
                session.Save(category);
                session.Flush();
                transaction.Commit();
            }
        }
コード例 #9
0
        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);
        }
コード例 #10
0
ファイル: CategoryTest.cs プロジェクト: qgate/CMS
        public void Test_Change_Parent()
        {
            var session = MySessionFactory.OpenSession();
            var parent1 = new Category
            {
                Name        = "parent1",
                Description = "Hello description!",

                UtcCreationDate = DateTime.UtcNow,
                UtcUpdateDate   = DateTime.UtcNow,
                Parent          = null
            };
            var child1 = new Category
            {
                Name        = "child",
                Description = "Hello description!",

                UtcCreationDate = DateTime.UtcNow,
                UtcUpdateDate   = DateTime.UtcNow,

                Parent = parent1
            };

            var parent2 = new Category
            {
                Name        = "parent2",
                Description = "Hello description!",

                UtcCreationDate = DateTime.UtcNow,
                UtcUpdateDate   = DateTime.UtcNow,
            };

            using (ITransaction transaction = session.BeginTransaction())
            {
                session.Save(parent1);
                session.Save(child1);
                session.Save(parent2);
                transaction.Commit();
            }

            session = MySessionFactory.OpenSession();

            var actualChild1 = session.Query <Category>()
                               .Where(it => it.Id == child1.Id)
                               .First();
            var actualParent2 = session.Query <Category>()
                                .Where(it => it.Id == parent2.Id)
                                .First();

            actualChild1.Parent = actualParent2;

            using (ITransaction transaction = session.BeginTransaction())
            {
                session.Save(actualChild1);
                transaction.Commit();
            }
            actualChild1 = session.Query <Category>()
                           .Where(it => it.Id == child1.Id)
                           .FirstOrDefault();

            Assert.AreEqual(actualParent2.Id, actualChild1.ParentId);

            using (ITransaction transaction = session.BeginTransaction())
            {
                session.Delete(actualParent2);
                transaction.Commit();
            }

            actualChild1 = session.Query <Category>()
                           .Where(it => it.Id == child1.Id)
                           .FirstOrDefault();
            Assert.IsNull(actualChild1);
        }