public void InsertAutoGeneratedGuid()
 {
     using (var context = new DataAnnotationContext("DataAnnotation"))
     {
         context.Categories.Add(new DACategory { CategoryName = "Test Generated Guid" });
         context.SaveChanges();
     }
 }
 public void TestTPTWhetherInsertToSubTypeCauseAutomaticallyInsertToBaseTypeBeforeHand()
 {
     var category = new DACategory { CategoryName = "test" };
     using (var context = new DataAnnotationContext("DataAnnotation"))
     {
         context.Categories.Add(category);
         context.ProductOutOfStocks.Add(new DAProductOutOfStock {Category = category, LastDate = DateTime.Now});
         context.SaveChanges();
     }
 }
        public void TestTPHOfProductAndProductInStock()
        {
            var category = new DACategory { CategoryName = "test" };
            using (var context = new DataAnnotationContext("DataAnnotation"))
            {
                context.Categories.Add(category);
                context.Products.Add(new DAProduct { ProductIdentity = 123, ProductName = "Product 1", CategoryId = category.CategoryId });
                context.SaveChanges();
            }

            using (var context = new DataAnnotationContext("DataAnnotation"))
            {
                var persistedCategory = context.Categories.FirstOrDefault(x => x.CategoryId == category.CategoryId);
                context.ProductInStocks.Add(new DAProductInStock
                    {
                        ProductIdentity = 2,
                        ProductName = "Product 2",
                        Remaining = 2,
                        Category = persistedCategory
                    });
                context.SaveChanges();
            }
        }
        public void UpdateRowsWhichEnableRowVersionExpectsConcurrencyException()
        {
            using (var context = new DataAnnotationContext("DataAnnotation"))
            {
                context.Categories.Add(new DACategory { CategoryName = "Test Generated Guid" });
                context.SaveChanges();

                var first = context.Categories.FirstOrDefault();
                var second = first.Clone();

                first.CategoryName = "Update by First";
                second.CategoryName = "Update by Second";

                context.Categories.Attach(first);
                context.Entry(first).State = EntityState.Modified;
                context.SaveChanges();
                first.CategoryName.Should().Be("Update by First");

                context.Categories.Attach(second);
                context.Entry(second).State = EntityState.Modified;
                context.SaveChanges();
            }
        }