コード例 #1
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);
        }
コード例 #2
0
        public RssFeedControllerTest()
        {
            var fakeNews       = Enumerable.Repeat(new FeedItem(), 10);
            var moqFeedService = new Mock <IFeedService>();

            moqFeedService.Setup(x => x.GetAllNews(It.IsAny <string>())).Returns(fakeNews);
            _configuration = new Mock <IConfiguration>();
            _configuration.SetupAllProperties();
            _controller = new RssFeedController(moqFeedService.Object, _configuration.Object);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #5
0
        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);
        }