public async Task DeleteNewsShouldThrowException() { string userId = "Jack"; int newsId = 101; var mockRepo = new Mock <INewsRepository>(); mockRepo.Setup(repo => repo.DeleteNews(userId, newsId)).Returns(Task.FromResult(false)); var service = new NewsService.Services.NewsService(mockRepo.Object); var actual = await Assert.ThrowsAsync <NoNewsFoundException>(() => service.DeleteNews(userId, newsId)); Assert.Equal($"NewsId {newsId} for {userId} doesn't exist", actual.Message); }
public async Task DeleteNewsShouldSuccess() { string userId = "Jack"; int newsId = 101; News news = new News { NewsId = 101, Title = "IT industry in 2020", Content = "It is expected to have positive growth in 2020.", PublishedAt = DateTime.Now, UrlToImage = null, Url = null }; var mockRepo = new Mock <INewsRepository>(); mockRepo.Setup(repo => repo.DeleteNews(userId, newsId)).Returns(Task.FromResult(true)); var service = new NewsService.Services.NewsService(mockRepo.Object); var actual = await service.DeleteNews(userId, newsId); Assert.True(actual); }