public async Task AddOrUpdateReminderShouldThrowException() { string userId = "Sam"; int newsId = 101; Reminder reminder = new Reminder { Schedule = DateTime.Now.AddDays(2) }; News mockNews = null; var mockRepo = new Mock <INewsRepository>(); mockRepo.Setup(repo => repo.GetNewsById(userId, newsId)).Returns(Task.FromResult(mockNews)); var service = new NewsService.Services.NewsService(mockRepo.Object); var actual = await Assert.ThrowsAsync <NoNewsFoundException>(() => service.AddOrUpdateReminder(userId, newsId, reminder)); Assert.Equal($"NewsId {newsId} for {userId} doesn't exist", actual.Message); }
public async Task AddOrUpdateReminderShouldSuccess() { string userId = "Sam"; int newsId = 101; Reminder reminder = new Reminder { Schedule = DateTime.Now.AddDays(2) }; News mockNews = new News { NewsId = 101, Title = "chandrayaan2-spacecraft" }; var mockRepo = new Mock <INewsRepository>(); mockRepo.Setup(repo => repo.GetNewsById(userId, newsId)).Returns(Task.FromResult(mockNews)); mockRepo.Setup(repo => repo.AddOrUpdateReminder(userId, newsId, reminder)).Returns(Task.FromResult(true)); var service = new NewsService.Services.NewsService(mockRepo.Object); var actual = await service.AddOrUpdateReminder(userId, newsId, reminder); Assert.True(actual); }