Exemplo n.º 1
0
        public void Test_Add_QueryById_Update_Delete_BrandProvider()
        {
            var brand = new Brand
            {
                Name = "secondBrand",
                Description = "Hello description!",
                UtcCreationDate = DateTime.UtcNow,
                UtcUpdateDate = DateTime.UtcNow
            };

            //Add brand
            provider.Add(brand);
            Console.WriteLine("Add OK!");

            //QueryBy
            var brandQueryBy = provider.QueryById(brand.Id);
            Assert.IsNotNull(brandQueryBy);
            Console.WriteLine("QueryBy OK!");

            //update
            brand.Description = "New description";
            provider.Update(brand);
            var brandUpdate = provider.QueryById(brand.Id);
            Assert.AreEqual("New description", brandUpdate.Description);
            Console.WriteLine("Update OK!");

            //Delete
            provider.Delete(brand);
            var brandDelete = provider.QueryById(brand.Id);
            Assert.IsNull(brandDelete);
            Console.WriteLine("Delete OK!");
        }
Exemplo n.º 2
0
        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!");
        }
Exemplo n.º 3
0
 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();
         }
     }
 }
Exemplo n.º 4
0
        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);
        }