public async Task DeleteByIdAsync_WithCorrectData_ShouldSuccessfullyDelete() { var testContent = "TestContent"; // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var commentRepository = new EfDeletableEntityRepository <Comment>(context); var commentsService = new CommentsService(commentRepository); var inputModel = new CreateCommentInputModel() { CommentContent = testContent, }; await commentsService.CreateAsync(inputModel); var comment = commentRepository.All().FirstOrDefault(c => c.Content == testContent); // Act var expectedCommentsCount = 0; await commentsService.DeleteByIdAsync(comment.Id); var actualCommentsCount = commentRepository.All().Count(); // Assert Assert.Equal(expectedCommentsCount, actualCommentsCount); }
public async Task DeleteByIdAsync_WithIncorrectData_ShouldThrowArgumentNullException() { var incorrectId = Guid.NewGuid().ToString(); // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var commentRepository = new EfDeletableEntityRepository <Comment>(context); var commentsService = new CommentsService(commentRepository); // Act // Assert await Assert.ThrowsAsync <ArgumentException>(async() => { await commentsService.DeleteByIdAsync(incorrectId); }); }