Ejemplo n.º 1
0
        public async Task EfDeletableEntityRepoUndeleteEntityShouldWork()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "EfDeletableEntityRepoUndeleteEntityShouldWork").Options;
            var dbContext = new ApplicationDbContext(options);

            var repository = new EfDeletableEntityRepository <Category>(dbContext);
            var service    = new CategoriesService(repository);
            await service.AddAsync("test", new Image()
            {
                Url = "https://miau.bg/files/lib/600x350/agresive-cat1.jpg"
            }, "description");

            await service.AddAsync("test2", new Image()
            {
                Url = "https://miau.bg/files/lib/600x350/agresive-cat1.jpg"
            }, "description2");

            await service.AddAsync("test3", new Image()
            {
                Url = "https://miau.bg/files/lib/600x350/agresive-cat1.jpg"
            }, "description3");

            var categoryToDelete = service.GetCategoryByName("test3");

            repository.Delete(categoryToDelete);
            await repository.SaveChangesAsync();

            var category = repository.AllWithDeleted().FirstOrDefault(x => x.Id == 3);

            repository.Undelete(category);
            await repository.SaveChangesAsync();

            var result = repository.All().ToList();

            Assert.Equal(3, result.Count);
        }