Beispiel #1
0
        public void SaveWithProduct()
        {
            // ts.Dispose();
            var c = new Category { Name = "olo" };

            var p = new Product { Title = "olo" };

            c.Products.Add(p);
            var p2 = new Product { Title = "olo2" };
            Category fromDb;
            c.Products.Add(p2);
            //p.CategoryId = c.Id;
            using (var session = factory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    session.Save(c);
                    transaction.Commit();
                }
            }
            using (var session = factory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    fromDb = session.Get<Category>(c.Id);
                }
                Assert.That(fromDb.Products.Count == 2);
            }
        }
Beispiel #2
0
        private async Task <Product> GetProductAsync()
        {
            var product = new Product()
            {
                Price = 200
            };

            return(await Task.FromResult(product));
        }
Beispiel #3
0
        public void SaveWithPicture()
        {
            Product p;

            using (var session = factory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    p = new Product { Title = "Tytu³", Price = 90m, Description = "jakisopis" };
                    session.Save(p);
                    var pic = new Picture();
                    p.AddPicture(pic);

                    transaction.Commit();
                }
            }
            using (var session = factory.OpenSession())
            {
                var fromDb=session.Get<Product>(p.Id);

                Assert.That(fromDb.Pictures.Count(),Is.EqualTo(1));
            }
        }
Beispiel #4
0
 public void Save()
 {
     var c = new Category {Name = "olo"};
     var p = new Product {Category = c};
     using (var session = factory.OpenSession())
     {
         using (var transaction = session.BeginTransaction())
         {
             session.Save(c);
             session.Save(p);
             transaction.Commit();
         }
     }
     Product fromDb;
     using (var session = factory.OpenSession())
     {
         using (var transaction = session.BeginTransaction())
         {
             fromDb = session.Get<Product>(p.Id);
             Assert.That(fromDb.Category.Id == c.Id);
         }
     }
 }
Beispiel #5
0
 public void Basic()
 {
     var p = new Product();
     Assert.IsNotNull(p, "nie utworzy³");
 }