public async Task CheckIfDeleteAsyncDeletesData() { var options = new DbContextOptionsBuilder <ElectricTravelDbContext>() .UseInMemoryDatabase(databaseName: "ArticlesTestDb").Options; using var dbContext = new ElectricTravelDbContext(options); using var repo = new EfDeletableEntityRepository <Article>(dbContext); var service = new ArticlesService(repo); var userId = "goshoasd"; var articleToAdd = new Article { ShortDescription = "asdasd", Content = "asdasdad", CreatedById = userId, Title = "asdas", }; await repo.AddAsync(articleToAdd); await repo.SaveChangesAsync(); var id = articleToAdd.Id; await service.DeleteAsync(id, userId); var article = await dbContext.Articles .FirstOrDefaultAsync(x => x.Id == id && x.CreatedById == userId); Assert.Null(article); }
public async Task CheckDeletingArticleAsync() { ApplicationDbContext db = GetDb(); var repository = new EfDeletableEntityRepository <Article>(db); var clientArticleLikesRepository = new EfRepository <ClientArticleLike>(db); var commentsRepository = new EfDeletableEntityRepository <Comment>(db); var service = new ArticlesService( repository, commentsRepository, clientArticleLikesRepository, this.cloudinaryService.Object); string articleId = await this.GetArticleAsync(service); var article = await repository.All().FirstOrDefaultAsync(a => a.Id == articleId); article.Comments.Add(this.comment); var articleLike = new ClientArticleLike() { ClientId = this.client.Id, ArticleId = articleId, }; await clientArticleLikesRepository.AddAsync(articleLike); await clientArticleLikesRepository.SaveChangesAsync(); repository.Update(article); await repository.SaveChangesAsync(); await service.DeleteAsync(articleId); Assert.True(article.IsDeleted); }