public async Task EFRepository_MarkForDelete_DeleteBlog_Should_Delete_Posts_Logical_Cascade()
        {
            try
            {
                using (var ctx = new TestDbContext())
                {
                    var entity = new WebSite
                    {
                        Url = "http://dotnet.microsoft.com/"
                    };
                    var post = new Post
                    {
                        WebSite         = entity,
                        Published       = true,
                        PublicationDate = DateTime.Today,
                        QuickUrl        = "http://dotnet.microsoft.com/abgfazJSQg2",
                        Version         = 1,
                        Content         = "test data"
                    };
                    entity.Posts = new List <Post> {
                        post
                    };
                    ctx.Add(entity);
                    ctx.SaveChanges();
                }

                using (var ctx = new TestDbContext())
                {
                    ctx.Set <WebSite>().Should().HaveCount(1);
                    ctx.Set <Post>().Should().HaveCount(1);
                }

                using (var rep = new TestBlogEFRepository())
                {
                    var b = await rep.GetAsync().FirstAsync().ConfigureAwait(false);

                    rep.MarkForDelete(b);
                    await rep.SaveAsync().ConfigureAwait(false);
                }

                using (var ctx = new TestDbContext())
                {
                    ctx.Set <WebSite>().Should().HaveCount(1);
                    ctx.Set <Post>().Should().HaveCount(1);

                    ctx.Set <WebSite>().ToList().Where(e => !e.Deleted).Should().HaveCount(0);
                    ctx.Set <Post>().ToList().Where(e => !e.Deleted).Should().HaveCount(1); // Le soft delete est à gérer niveau repository
                }
            }
            finally
            {
                DeleteAll();
            }
        }
        public async Task EFRepository_MarkForDelete_Logical_Deletion_Globally_Deactivated()
        {
            try
            {
                EFCoreInternalExecutionContext.DisableLogicalDeletion = true;
                using (var ctx = new TestDbContext())
                {
                    var entity = new WebSite
                    {
                        Url = "http://dotnet.microsoft.com/"
                    };
                    var post = new Post
                    {
                        WebSite         = entity,
                        Published       = true,
                        PublicationDate = DateTime.Today,
                        QuickUrl        = "http://dotnet.microsoft.com/abgfazJSQg2",
                        Version         = 1,
                        Content         = "test data"
                    };
                    entity.Posts = new List <Post> {
                        post
                    };
                    ctx.Add(entity);
                    ctx.SaveChanges();
                }

                using (var ctx = new TestDbContext())
                {
                    ctx.Set <WebSite>().Should().HaveCount(1);
                    ctx.Set <Post>().Should().HaveCount(1);
                }

                using (var rep = new TestBlogEFRepository())
                {
                    var b = await rep.GetAsync().FirstAsync().ConfigureAwait(false);

                    rep.MarkForDelete(b);
                    await rep.SaveAsync().ConfigureAwait(false);
                }

                using (var ctx = new TestDbContext())
                {
                    ctx.Set <WebSite>().Should().HaveCount(0);
                    ctx.Set <Post>().Should().HaveCount(0);
                }
            }
            finally
            {
                EFCoreInternalExecutionContext.DisableLogicalDeletion = false;
                DeleteAll();
            }
        }
 public async Task EFRepository_Logical_Deletion()
 {
     try
     {
         using (var ctx = new TestDbContext())
         {
             var entity = new WebSite
             {
                 Url = "http://dotnet.microsoft.com/"
             };
             ctx.Add(entity);
             await ctx.SaveChangesAsync().ConfigureAwait(false);
         }
         using (var repo = new TestBlogEFRepository())
         {
             repo.Get().Count().Should().Be(1);
             repo.Get(includeDeleted: true).Count().Should().Be(1);
         }
         using (var repo = new TestBlogEFRepository())
         {
             var entity = repo.Get().FirstOrDefault();
             entity.Should().NotBeNull();
             repo.MarkForDelete(entity);
             await repo.SaveAsync().ConfigureAwait(false);
         }
         using (var repo = new TestBlogEFRepository())
         {
             repo.Get(includeDeleted: true).Count().Should().Be(1);
             var entity = repo.Get(includeDeleted: true).FirstOrDefault();
             entity.DeletionDate.Should().BeSameDateAs(DateTime.Today);
             repo.Get().Count().Should().Be(0);
         }
     }
     finally
     {
         DeleteAll();
     }
 }