コード例 #1
0
        public void CreateArticle_Null_Content_Invalid()
        {
            using (TransactionScope transaction = new TransactionScope())
            {
                articleRepository = new ArticlesRepository();
                int count = articleRepository.GetAllArticles().Count(); //Count articles pre-creation of new article

                SMCC.Models.Article        newArticle     = new SMCC.Models.Article();
                SMCC.Models.Article        createdArticle = 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;
                    newArticle.Title = "A";
                    newArticle.Text  = null;

                    articleController.Create(newArticle);
                }
                finally
                {
                    articleRepository = new ArticlesRepository();
                    existArticles     = articleRepository.GetAllArticles().ToList();
                    createdArticle    = articleRepository.GetArticle(newArticle.ArticleId);

                    Assert.AreEqual(count, existArticles.Count());
                    CollectionAssert.DoesNotContain(existArticles, createdArticle);
                }
            }
        }
コード例 #2
0
        public void DeleteArticle_Valid_Id()
        {
            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        deleteArticle   = 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.Delete(1) as ViewResult;
                    deleteArticle = (SMCC.Models.Article)result.ViewData.Model;

                    articleController.DeleteConfirmed(deleteArticle.ArticleId);
                }
                finally
                {
                    articleRepository = new ArticlesRepository();
                    existArticles     = articleRepository.GetAllArticles().ToList();

                    Assert.AreEqual(count - 1, existArticles.Count());               //Record count should be deducted by 1 after deletion
                    CollectionAssert.DoesNotContain(existArticles, originalArticle); // Article should no longer be present in db.
                }
            }
        }
コード例 #3
0
        public void DetailsArticle_Existing_Id_Valid()
        {
            articleRepository = new ArticlesRepository();
            SMCC.Models.Article expectedArticle = articleRepository.GetArticle(1);

            var result = articleController.Details(1) as ViewResult;

            SMCC.Models.Article actualArticle = (SMCC.Models.Article)result.ViewData.Model;

            Assert.IsTrue(AssertSameArticles(expectedArticle, actualArticle));
        }
コード例 #4
0
        public void EditArticle_Long_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 = "";
                    for (int i = 0; i < 50; i++)
                    {
                        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));
                }
            }
        }
コード例 #5
0
        public bool AssertModifiedArticles(SMCC.Models.Article originalArticle, SMCC.Models.Article editedArticle)
        {
            bool articlesEqualMod = true;

            if (originalArticle.ArticleId != editedArticle.ArticleId)
            {
                articlesEqualMod = false;                                                       //Id Should remain the same
            }
            if (originalArticle.ArticleUserId != editedArticle.ArticleUserId)
            {
                articlesEqualMod = false;                                                               //UserId Should remain the same
            }
            if (originalArticle.Title == editedArticle.Title)
            {
                articlesEqualMod = false;                                                //Title should change if modified correctly
            }
            if (originalArticle.Text == editedArticle.Text)
            {
                articlesEqualMod = false;                                             //Text should change if modified correctly
            }
            return(articlesEqualMod);
        }
コード例 #6
0
        public bool AssertSameArticles(SMCC.Models.Article originalArticle, SMCC.Models.Article newArticle)
        {
            bool articlesEqual = true;

            if (originalArticle.ArticleId != newArticle.ArticleId)
            {
                articlesEqual = false;
            }
            if (originalArticle.ArticleUserId != newArticle.ArticleUserId)
            {
                articlesEqual = false;
            }
            if (originalArticle.ArticleStateId != newArticle.ArticleStateId)
            {
                articlesEqual = false;
            }
            if (originalArticle.ArticleReviewId != newArticle.ArticleReviewId)
            {
                articlesEqual = false;
            }
            if (originalArticle.DateCreated != newArticle.DateCreated)
            {
                articlesEqual = false;
            }
            if (originalArticle.DatePublished != newArticle.DatePublished)
            {
                articlesEqual = false;
            }
            if (originalArticle.Title != newArticle.Title)
            {
                articlesEqual = false;
            }
            if (originalArticle.Text != newArticle.Text)
            {
                articlesEqual = false;
            }

            return(articlesEqual);
        }
コード例 #7
0
        public void CreateArticle_Long_Valid()
        {
            using (TransactionScope transaction = new TransactionScope())
            {
                articleRepository = new ArticlesRepository();
                int count = articleRepository.GetAllArticles().Count(); //Count articles pre-creation of new article

                SMCC.Models.Article        newArticle     = new SMCC.Models.Article();
                SMCC.Models.Article        createdArticle = 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;

                    for (int i = 0; i < 50; i++)
                    {
                        newArticle.Title += "A";
                    }

                    newArticle.Text = "A";

                    articleController.Create(newArticle);
                }
                finally
                {
                    articleRepository = new ArticlesRepository();
                    existArticles     = articleRepository.GetAllArticles().ToList();
                    createdArticle    = articleRepository.GetArticle(newArticle.ArticleId);

                    Assert.AreEqual(count + 1, existArticles.Count());
                    CollectionAssert.Contains(existArticles, createdArticle);
                }
            }
        }