Esempio n. 1
0
        public async Task FindAllNewsShouldThrowException()
        {
            string      userId   = "Jack";
            List <News> lstnews  = null;
            var         mockRepo = new Mock <INewsRepository>();

            mockRepo.Setup(repo => repo.FindAllNewsByUserId(userId)).Returns(Task.FromResult(lstnews));
            var service = new NewsService.Services.NewsService(mockRepo.Object);

            var actual = await Assert.ThrowsAsync <NoNewsFoundException>(() => service.FindAllNewsByUserId(userId));

            Assert.Equal($"No news found for {userId}", actual.Message);
        }
Esempio n. 2
0
        public async Task FindAllNewsShouldReturnListOfNews()
        {
            string userId   = "Jack";
            var    mockRepo = new Mock <INewsRepository>();

            mockRepo.Setup(repo => repo.FindAllNewsByUserId(userId)).Returns(Task.FromResult(this.newsList));
            var service = new NewsService.Services.NewsService(mockRepo.Object);

            var actual = await service.FindAllNewsByUserId(userId);

            Assert.NotNull(actual);
            Assert.IsAssignableFrom <List <News> >(actual);
            Assert.Equal(2, actual.Count);
        }