Example #1
0
        public void Get_WhenCalled_ReturnsOkResult()
        {
            //Act
            var okResult = _controller.Get();

            //Assert
            Assert.IsType <OkObjectResult>(okResult);
        }
Example #2
0
        public async void CallApiWithNoParameter_ShouldReturnBadRequest()
        {
            _rssFeedService.Setup(x => x.ParseRssFeedAsync("testUrl")).Returns(
                It.IsAny <Task <List <Models.ParsedEpisodeInfo> > >());

            var apiController = new RssFeedController(_rssFeedService.Object);
            var result        = await apiController.Get("");

            Assert.IsType <BadRequestResult>(result.Result);
        }
Example #3
0
        public void Get_WithErrorException_ReturnsNotFound()
        {
            //Arrange
            var moqFeedService = new Mock <IFeedService>();

            moqFeedService.Setup(x => x.GetAllNews(It.IsAny <string>())).Throws(new Exception());
            var controller = new RssFeedController(moqFeedService.Object, _configuration.Object);

            //Act
            var result = controller.Get();

            //Assert
            Assert.IsType <NotFoundObjectResult>(result);
        }
Example #4
0
        public void Get_WithNullResult_ReturnsNotFound()
        {
            //Arrange
            var moqFeedService = new Mock <IFeedService>();

            moqFeedService.Setup(x => x.GetAllNews("")).Returns((List <FeedItem>)null);
            var controller = new RssFeedController(moqFeedService.Object, _configuration.Object);

            //Act
            var result = controller.Get();

            //Assert
            Assert.IsType <NotFoundObjectResult>(result);
        }
        public void CallApiWithCorrectParameter_ShouldReturnOk()
        {
            _rssFeedService.Setup(x => x.GetRssFeed("testUrl")).Returns(
                new List <Models.ParsedEpisodeInfo> {
                new Models.ParsedEpisodeInfo {
                    CheckSum = 123, Title = "TestEpisode", Url = "http://test.se"
                }
            });

            var apiController = new RssFeedController(_rssFeedService.Object);
            var result        = apiController.Get("test");

            Assert.IsType <OkObjectResult>(result.Result);
        }