Ejemplo n.º 1
0
        public void DeleteNews_NonExisitingNews_ReturnsBadRequest()
        {
            // Arange
            var mockRepository = new Mock<INewsData>();
            mockRepository.Setup(rep => rep.News.Delete(It.IsAny<int>())).Verifiable();
            var controller = new NewsController(mockRepository.Object);

            // Act
            IHttpActionResult result = controller.Delete(7);

            // Assert
            Assert.IsInstanceOfType(result, typeof(BadRequestResult));
        }
Ejemplo n.º 2
0
        public void DeleteNews_ExisitngNews_ReturnsOKAndModifiedNews()
        {
            // Arange
            var mockRepository = new Mock<INewsData>();
            var newsItem = new News
            {
                Id = 100,
                Title = "News number 1",
                Content = "Content of first news",
                PublishDate = DateTime.Now
            };

            var news = new List<News> 
            {
                newsItem
            };

            mockRepository.Setup(rep => rep.News.Delete(It.IsAny<int>())).Callback(()=>news.Remove(newsItem));
            mockRepository.Setup(rep => rep.News.Find(It.IsAny<int>())).Returns(news.First());

            var controller = new NewsController(mockRepository.Object);

            // Act
            IHttpActionResult result = controller.Delete(100);

            // Assert
            Assert.IsInstanceOfType(result, typeof(OkResult));
            Assert.AreEqual(0, news.Count);
        }