Esempio n. 1
0
        public void EditArticle_Short_Valid()
        {
            using (TransactionScope transaction = new TransactionScope())
            {
                articleRepository = new ArticlesRepository();
                int count = articleRepository.GetAllArticles().Count(); //Count articles pre-editting of existing article

                SMCC.Models.Article        originalArticle = new SMCC.Models.Article();
                SMCC.Models.Article        modArticle      = new SMCC.Models.Article();
                List <SMCC.Models.Article> existArticles   = new List <SMCC.Models.Article>();

                try
                {
                    //Set your controller ControllerContext with fake context
                    articleController.ControllerContext = MockContext().Object;

                    originalArticle = articleRepository.GetArticle(1);

                    var result = articleController.Edit(1) as ViewResult;
                    modArticle = (SMCC.Models.Article)result.ViewData.Model;

                    modArticle.Title = "A";
                    modArticle.Text  = "A";

                    articleController.Edit(modArticle);
                }
                finally
                {
                    articleRepository = new ArticlesRepository();
                    existArticles     = articleRepository.GetAllArticles().ToList();
                    Assert.AreEqual(count, existArticles.Count());  //Record count should remain the same after editting

                    SMCC.Models.Article originalArticle_Modified = new SMCC.Models.Article();
                    originalArticle_Modified = articleRepository.GetArticle(1);
                    Assert.IsFalse(AssertSameArticles(originalArticle, originalArticle_Modified)); //Article content should change, hence return false
                    Assert.IsTrue(AssertModifiedArticles(originalArticle, originalArticle_Modified));
                }
            }
        }