Exemple #1
0
        public void Tests()
        {
            using (SoftDeleteDbContext.ContextCreated.OfType <SoftDeleteDbContext>().Subscribe(db => db.SoftDeletes()))
            {
                using (var db = new SoftDeleteDbContext())
                {
                    db.Items.Add(new TestItem {
                        Description = "1"
                    });
                    db.SaveChanges();
                }

                using (var db = new SoftDeleteDbContext())
                {
                    var item = db.Items.Single(x => x.Description == "1");
                    db.Items.Remove(item);
                    db.SaveChanges();
                }

                using (var db = new SoftDeleteDbContext())
                {
                    var item = db.Items.IgnoreQueryFilters().Single(x => x.Description == "1");
                    item.Should().NotBeNull();
                    item.IsDeleted.Should().Be(true, "IsDeleted should be marked true");
                }

                using (var db = new SoftDeleteDbContext())
                {
                    var item = db.Items.SingleOrDefault(x => x.Description == "1");
                    item.Should().BeNull("IsDeleted auto filter did not work");
                }
            }
        }
Exemple #2
0
        private static void DeleteProduct(SoftDeleteDbContext db, int id)
        {
            var prodcut = db.Products.SingleOrDefault(x => x.Id == id);

            if (prodcut != null)
            {
                db.Products.Remove(prodcut);
                db.SaveChanges();
            }
        }
Exemple #3
0
 private static void InitialData(SoftDeleteDbContext db)
 {
     if (!db.Products.Any())
     {
         for (int i = 1; i <= 10; i++)
         {
             var product = new Models.Product {
                 Title = $"Title {new Random().Next(1, 2000)}"
             };
             db.Products.Add(product);
         }
         db.SaveChanges();
     }
 }