예제 #1
0
        public void ArticlesFromCategory_TwoArticlesInCategory_PageSizeOne_PageNumberTwo_MustReturnSecondArticle()
        {
            //Mock repository
            var mockedArticles = new Mock <IRepository <Article> >();

            mockedArticles.Setup(repo => repo.All()).Returns(_articles.AsQueryable());

            //Mock data
            var mockedUow = new Mock <IUowData>();

            mockedUow.Setup(uow => uow.Articles).Returns(() => { return(mockedArticles.Object); });

            // Act
            ArticlesController articlesController = new ArticlesController(mockedUow.Object);

            articlesController.PageSize = 1;

            var results = articlesController.ArticlesFromCategory(2, 2) as ViewResult;
            var model   = results.Model as ICollection <ArticleViewModel>;

            var expectedArticle = _articles.Where(article => article.CateoryId == 2).ToList()[1];

            Assert.AreEqual(1, model.Count);
            Assert.AreEqual(expectedArticle.Id, model.FirstOrDefault().Id);
        }
예제 #2
0
        public void ArticlesFromCategory_NoCategoryId_MustReturnStatusCodeBadRequest()
        {
            //Mock repository
            var mockedArticles = new Mock <IRepository <Article> >();

            mockedArticles.Setup(repo => repo.All()).Returns(_articles.AsQueryable());

            //Mock data
            var mockedUow = new Mock <IUowData>();

            mockedUow.Setup(uow => uow.Articles).Returns(() => { return(mockedArticles.Object); });

            // Act
            ArticlesController articlesController = new ArticlesController(mockedUow.Object);

            var results = articlesController.ArticlesFromCategory(null, null) as HttpStatusCodeResult;

            Assert.AreEqual(results.StatusCode, (int)HttpStatusCode.BadRequest);
        }
예제 #3
0
        public void ArticlesFromCategory_TwoArticlesInCategory_BiggerPageSize_NoPageNumber_MustReturnTwoArticles()
        {
            //Mock repository
            var mockedArticles = new Mock <IRepository <Article> >();

            mockedArticles.Setup(repo => repo.All()).Returns(_articles.AsQueryable());

            //Mock data
            var mockedUow = new Mock <IUowData>();

            mockedUow.Setup(uow => uow.Articles).Returns(() => { return(mockedArticles.Object); });

            // Act
            ArticlesController articlesController = new ArticlesController(mockedUow.Object);

            var results = articlesController.ArticlesFromCategory(2, null) as ViewResult;
            var model   = results.Model as ICollection <ArticleViewModel>;

            Assert.AreEqual(2, model.Count);
        }
예제 #4
0
        public void ArticlesFromCategory_NotExistingCategoryId_MustThrowHttpException()
        {
            //Mock categories repository
            int categoryId       = 50;
            var mockedCategories = new Mock <IRepository <Category> >();

            mockedCategories.Setup(repo => repo.GetById(50)).Returns(_categories.FirstOrDefault(cat => cat.Id == categoryId));

            //Mock articles repository
            var mockedArticles = new Mock <IRepository <Article> >();

            mockedArticles.Setup(repo => repo.All()).Returns(_articles.AsQueryable());

            //Mock data
            var mockedUow = new Mock <IUowData>();

            mockedUow.Setup(uow => uow.Articles).Returns(() => { return(mockedArticles.Object); });
            mockedUow.Setup(uow => uow.Categories).Returns(() => { return(mockedCategories.Object); });

            // Act
            ArticlesController articlesController = new ArticlesController(mockedUow.Object);

            var results = articlesController.ArticlesFromCategory(categoryId, null) as ViewResult;
        }