public void DeleteArticle_ArticleDoesNotExists() { var article = new Article { Id = 1, Author = "author1", Comments = "comments1", Content = "content1", Description = "description1", PublishedAt = "11-11-2011", Title = "title1", Url = "url1", UrlToImage = "UrlToImage1" }; Article deletedArticle = null; var mockService = new Mock <IFavoriteService>(); mockService.Setup(service => service.GetArticle(article.Id)).Returns(deletedArticle); var mockHttp = new Mock <HttpClient>();//check later var mockController = new NewsController(mockService.Object, mockHttp.Object); var result = mockController.DeleteArticle(article.Id); var actionResult = Assert.IsType <NotFoundObjectResult>(result); Assert.Equal <int>(404, actionResult.StatusCode.Value); }
public void DeleteArticle_ArticleIsDeleted() { var mockService = new Mock <IFavoriteService>(); var article = new Article { Id = 5, Author = "Article Test", Comments = "comments5", Content = "content5", Description = "description5", PublishedAt = "11-11-2011", Title = "title5", Url = "url5", UrlToImage = "UrlToImage5" }; List <Article> addedArticle = new List <Article> { article }; mockService.Setup(service => service.GetArticle(article.Id)).Returns(article); mockService.Setup(service => service.DeleteArticle(article.Id)).Callback <int>((id) => addedArticle.Remove(addedArticle.Single(m => m.Id == id))); var mockHttp = new Mock <HttpClient>();//check later var controller = new NewsController(mockService.Object, mockHttp.Object); var result = controller.DeleteArticle(article.Id); var actionResult = Assert.IsType <OkObjectResult>(result); Assert.True(0 == addedArticle.Count); }