public void Save_AfterSavingArticle_ArticleIsInRepository() { FakeNewsRepository fakeNewsRepository = new FakeNewsRepository(); NewsAdminController controller = CreateNewsAdminController(fakeNewsRepository); string testTitle = "TestTitle"; NewsArticle newNewsArticle = new NewsArticle(); newNewsArticle.Id = 0; newNewsArticle.Title = testTitle; newNewsArticle.Content = "TestContent"; newNewsArticle.Category = "TestCategory"; newNewsArticle.PictureUrl = "TestURL"; int previousNumberOfArticles = fakeNewsRepository.News.Count; RedirectToRouteResult result = controller.Save(newNewsArticle) as RedirectToRouteResult; NewsArticle savedArticle = fakeNewsRepository.News.Find(a => a.Title == testTitle); Assert.IsTrue(previousNumberOfArticles + 1 == fakeNewsRepository.News.Count); Assert.IsTrue(TestHelper.NewsArticlesAreSame(newNewsArticle, savedArticle)); if (savedArticle != null) { fakeNewsRepository.News.Remove(savedArticle); } }
public void Save_AfterSavingArticle_RedirectsToTableView() { FakeNewsRepository fakeNewsRepository = new FakeNewsRepository(); NewsAdminController controller = CreateNewsAdminController(fakeNewsRepository); NewsArticle existingArticle = fakeNewsRepository.News[0]; RedirectToRouteResult result = controller.Save(existingArticle) as RedirectToRouteResult; Assert.IsNotNull(result); Assert.IsTrue(result.RouteValues["action"].ToString() == "IndexAdmin"); Assert.IsTrue(result.RouteValues["controller"].ToString() == "NewsAdmin"); }
public void Save_AfterUpdatingArticle_ChangesAreInRepository() { FakeNewsRepository fakeNewsRepository = new FakeNewsRepository(); NewsAdminController controller = CreateNewsAdminController(fakeNewsRepository); NewsArticle existingArticle = fakeNewsRepository.News[0]; string oldTitle = existingArticle.Title; string newTitle = "TestTitle"; existingArticle.Title = newTitle; RedirectToRouteResult result = controller.Save(existingArticle) as RedirectToRouteResult; NewsArticle savedArticle = fakeNewsRepository.News.Find(a => a.Id == existingArticle.Id); Assert.IsTrue(savedArticle.Title == newTitle); }