コード例 #1
0
        public void TestPostFavoriteNews_Negative_Null()
        {
            var favController = new FavouriteNewsController(_repo);

            IActionResult result   = favController.Post(null);
            var           okResult = result as StatusCodeResult;

            Assert.Equal(400, okResult.StatusCode); //Bad request
        }
コード例 #2
0
        public void TestPostFavoriteNews_Negative()
        {
            var           favController = new FavouriteNewsController(_repo);
            FavouriteNews testNews      = new FavouriteNews();
            int           topId         = 0;

            testNews.Id          = topId + 1;
            testNews.Title       = "Test Title";
            testNews.Description = "Test description";
            testNews.ImageURL    = " Test URL";
            IActionResult result   = favController.Post(testNews);
            var           okResult = result as StatusCodeResult;

            if (okResult.StatusCode == 200)
            {
                //save once more
                result   = favController.Post(testNews);
                okResult = result as StatusCodeResult;
                Assert.Equal(409, okResult.StatusCode); //already exists
            }
        }
コード例 #3
0
        public void TestPostFavoriteNews()
        {
            var           favController = new FavouriteNewsController(_repo);
            FavouriteNews testNews      = new FavouriteNews();
            int           topId         = 0;

            testNews.Id          = topId + 1;
            testNews.Title       = "Test Title";
            testNews.Description = "Test description";
            testNews.ImageURL    = " Test URL";
            IActionResult result   = favController.Post(testNews);
            var           okResult = result as StatusCodeResult;

            Assert.Equal(200, okResult.StatusCode);
        }
コード例 #4
0
        public void TestDeleteFavoriteNews()
        {
            var           favController = new FavouriteNewsController(_repo);
            FavouriteNews testNews      = new FavouriteNews();
            int           topId         = 0;

            testNews.Id          = topId + 1;
            testNews.Title       = "Test Title";
            testNews.Description = "Test description";
            testNews.ImageURL    = " Test URL";
            IActionResult result   = favController.Post(testNews);
            var           okResult = result as StatusCodeResult;

            if (okResult.StatusCode == 200)
            {
                topId  = _context.FavouriteNews.Select(f => f.Id).FirstOrDefault();
                result = favController.Delete(topId);
                Assert.Equal(200, okResult.StatusCode);
            }
        }