Exemplo n.º 1
0
        public void TestDeleteBookWithDependentEntityCascadeDeleteOk()
        {
            //SETUP
            int bookId;
            var options = SqliteInMemory.CreateOptions <EfCoreContext>();

            using (var context = new EfCoreContext(options))
            {
                context.Database.EnsureCreated();
                var book = new Book
                {
                    Title   = "Test Book",
                    Reviews = new List <Review> {
                        new Review()
                    }
                };
                context.Add(book);
                context.SaveChanges();
                bookId = book.BookId;
                context.Books.Count().ShouldEqual(1);
                context.Set <Review>().Count().ShouldEqual(1);
            }
            //ATTEMPT
            using (var context = new EfCoreContext(options))
            {
                var book = new Book {
                    BookId = bookId
                };
                context.RemoveRange(book);
                context.SaveChanges();
            }
            //VERIFY
            using (var context = new EfCoreContext(options))
            {
                context.Books.Count().ShouldEqual(0);
                context.Set <Review>().Count().ShouldEqual(0);
            }
        }
Exemplo n.º 2
0
        public void TestDeletePriceOfferQuicklyOk()
        {
            //SETUP
            int priceOfferId;
            var options = SqliteInMemory.CreateOptions <EfCoreContext>();

            using (var context = new EfCoreContext(options))
            {
                context.Database.EnsureCreated();
                var book = new Book
                {
                    Title     = "Test Book",
                    Promotion = new PriceOffer {
                        NewPrice = 1
                    }
                };
                context.Add(book);
                context.SaveChanges();
                priceOfferId = book.Promotion.PriceOfferId;
                context.Books.Count().ShouldEqual(1);
                context.PriceOffers.Count().ShouldEqual(1);
            }
            //ATTEMPT
            using (var context = new EfCoreContext(options))
            {
                var pOfferToDelete = new PriceOffer {
                    PriceOfferId = priceOfferId
                };
                context.RemoveRange(pOfferToDelete);
                context.SaveChanges();
            }
            //VERIFY
            using (var context = new EfCoreContext(options))
            {
                context.Books.Count().ShouldEqual(1);
                context.PriceOffers.Count().ShouldEqual(0);
            }
        }
Exemplo n.º 3
0
        public void TestDeletePriceOfferRemoveNullsNavigatinalLinkOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <EfCoreContext>();

            using (var context = new EfCoreContext(options))
            {
                context.Database.EnsureCreated();
                var book = new Book
                {
                    Title     = "Test Book",
                    Promotion = new PriceOffer {
                        NewPrice = 1
                    }
                };
                context.Add(book);
                context.SaveChanges();
                context.Books.Count().ShouldEqual(1);
                context.PriceOffers.Count().ShouldEqual(1);
            }
            //ATTEMPT
            using (var context = new EfCoreContext(options))
            {
                var bookWithPromotion = context.Books
                                        .Include(x => x.Promotion).Single();
                context.RemoveRange(bookWithPromotion.Promotion);
                context.SaveChanges();
                bookWithPromotion.Promotion.ShouldBeNull();
            }
            //VERIFY
            using (var context = new EfCoreContext(options))
            {
                context.Books.Count().ShouldEqual(1);
                context.PriceOffers.Count().ShouldEqual(0);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// This wipes all the existing orders and creates a new set of orders
 /// </summary>
 /// <param name="context"></param>
 /// <param name="books"></param>
 public static void ResetOrders(this EfCoreContext context, List <Book> books = null)
 {
     context.RemoveRange(context.Orders.ToList()); //remove the existing orders (the lineitems will go too)
     context.AddDummyOrders(books);                //add a dummy set of orders
     context.SaveChanges();
 }