public async void HighlightArticleInvalidIdTest() { var controller = new ArticlesController(_context, _userManager); var result = await controller.PostHighlightArticle(40); Assert.IsType <NotFoundResult>(result); var result2 = await controller.PostHighlightArticle(-1); Assert.IsType <BadRequestResult>(result2); }
public async void HighlightArticleNotPublishedTest() { var controller = new ArticlesController(_context, _userManager); var article = _articleDTOs.First(a => a.IsHighlighted == false && a.IsPublished == false); Assert.True(article.IsHighlighted == false); Assert.True(article.HighlightedAt == null); Assert.True(article.IsPublished == false); Assert.True(article.PublishedAt == null); //POST TEST (Highlight) var result = await controller.PostHighlightArticle(article.Id); Assert.IsType <BadRequestResult>(result); //GET TEST (Article unchanged) var result2 = await controller.GetArticle(article.Id); var objectResult2 = Assert.IsType <OkObjectResult>(result2); var model = Assert.IsAssignableFrom <ArticleDTO>(objectResult2.Value); Assert.True(article.IsHighlighted == false); Assert.True(article.HighlightedAt == null); }
public async void HighlightArticleTest() { var controller = new ArticlesController(_context, _userManager); var article = _articleDTOs.First(a => a.IsHighlighted == false && a.IsPublished == true); var highlightedArticle = _articleDTOs.First(a => a.IsHighlighted == true); Assert.True(article.IsHighlighted == false); Assert.True(article.HighlightedAt == null); Assert.True(article.IsPublished == true); Assert.True(article.PublishedAt != null); Assert.True(highlightedArticle.IsHighlighted == true); Assert.True(highlightedArticle.HighlightedAt != null); var result = await controller.PostHighlightArticle(article.Id); var objectResult = Assert.IsType <OkResult>(result); //GET TEST (Article highlighted) var result2 = await controller.GetArticle(article.Id); var objectResult2 = Assert.IsType <OkObjectResult>(result2); var model2 = Assert.IsAssignableFrom <ArticleDTO>(objectResult2.Value); Assert.True(model2.IsHighlighted == true); Assert.True(model2.HighlightedAt != null); //GET TEST 2 (Highlighted article no longer highlighted) var result3 = await controller.GetArticle(highlightedArticle.Id); var objectResult3 = Assert.IsType <OkObjectResult>(result3); var model3 = Assert.IsAssignableFrom <ArticleDTO>(objectResult3.Value); Assert.True(model3.IsHighlighted == false); Assert.True(model3.HighlightedAt == null); }
public async void HighlightArticleAlreadyHighlightedTest() { var controller = new ArticlesController(_context, _userManager); var article = _articleDTOs.First(a => a.IsHighlighted == true); Assert.True(article.IsHighlighted == true); Assert.True(article.HighlightedAt != null); //POST TEST (Highlight) var result = await controller.PostHighlightArticle(article.Id); var objectResult = Assert.IsType <OkResult>(result); //GET TEST (Article still highlighted) var result2 = await controller.GetArticle(article.Id); var objectResult2 = Assert.IsType <OkObjectResult>(result2); var model = Assert.IsAssignableFrom <ArticleDTO>(objectResult2.Value); Assert.True(article.IsHighlighted == true); Assert.True(article.HighlightedAt != null); }