Exemplo n.º 1
0
        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!");
        }
Exemplo n.º 2
0
 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);
 }