Exemplo n.º 1
0
        public async Task EFRepository_Logical_Deletion_ById()
        {
            try
            {
                Guid?id = null;
                using (var ctx = new TestDbContext())
                {
                    var entity = new WebSite
                    {
                        Url = "http://dotnet.microsoft.com/"
                    };
                    ctx.Add(entity);
                    await ctx.SaveChangesAsync().ConfigureAwait(false);

                    id = entity.Id;
                }
                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.MarkIdForDelete(id);
                    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();
            }
        }
Exemplo n.º 2
0
 public async Task EFRepository_Physical_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, true);
             await repo.SaveAsync().ConfigureAwait(false);
         }
         using (var repo = new TestBlogEFRepository())
         {
             repo.Get(includeDeleted: true).Count().Should().Be(0);
             repo.Get().Count().Should().Be(0);
         }
     }
     finally
     {
         DeleteAll();
     }
 }