Exemplo n.º 1
0
        public void GetFavoriteNews_Test()
        {
            var newsController = new NewsController(this.mockNewsService.Object);

            mockNewsService.Setup(fk => fk.GetFavoriteNews("user1")).Returns(getMockFavoriteNewsList("user1"));
            mockNewsService.Setup(fk => fk.GetFavoriteNews("user2")).Returns(getMockFavoriteNewsList("user2"));

            // Test for user1
            var result       = newsController.GetFavoriteNews("user1") as ObjectResult;
            var favoriteNews = Assert.IsType <List <News> >(result.Value);

            Assert.Equal((int)HttpStatusCode.OK, result.StatusCode);
            Assert.Equal(2, favoriteNews.Count);

            // Test for user2
            result       = newsController.GetFavoriteNews("user2") as ObjectResult;
            favoriteNews = Assert.IsType <List <News> >(result.Value);
            Assert.Equal((int)HttpStatusCode.OK, result.StatusCode);
            Assert.Single(favoriteNews);
        }
Exemplo n.º 2
0
        public void GetFavoriteNews_DBException_Test()
        {
            var newsController = new NewsController(this.mockNewsService.Object);

            mockNewsService.Setup(fk => fk.GetFavoriteNews("user1")).Throws(new Exception());

            var result       = newsController.GetFavoriteNews("user1") as ObjectResult;
            var errorMessage = Assert.IsType <string>(result.Value);

            Assert.Equal("Failed to get Favorite news", errorMessage);
            Assert.Equal((int)HttpStatusCode.InternalServerError, result.StatusCode);
        }
Exemplo n.º 3
0
        public void GetFavoriteNews_UserInvalid_Test()
        {
            var newsController = new NewsController(this.mockNewsService.Object);

            mockNewsService.Setup(fk => fk.GetFavoriteNews("user1")).Returns(new List <News>());

            var result       = newsController.GetFavoriteNews("") as ObjectResult;
            var errorMessage = Assert.IsType <string>(result.Value);

            Assert.Equal("User id is invalid!", errorMessage);
            Assert.Equal((int)HttpStatusCode.BadRequest, result.StatusCode);
        }
Exemplo n.º 4
0
        public void GetFavoriteNews_NotFound_Test()
        {
            var newsController = new NewsController(this.mockNewsService.Object);

            mockNewsService.Setup(fk => fk.GetFavoriteNews("user1")).Returns(new List <News>());

            var result       = newsController.GetFavoriteNews("user1") as ObjectResult;
            var favoriteNews = Assert.IsType <List <News> >(result.Value);

            Assert.Equal((int)HttpStatusCode.OK, result.StatusCode);
            Assert.Empty(favoriteNews);
        }