예제 #1
0
        public void ListArticlesFilteredNoResultsTest(
            [Frozen] Mock <IRepository <Article> > repo,
            [Frozen] Mock <IUnitOfWork> unitOfWork,
            List <Article> articles,
            HomeController sut)
        {
            // arrange:
            unitOfWork.Setup(x => x.ArticlesRepository).Returns(repo.Object);
            repo.Setup(x => x.All()).Returns(articles.AsQueryable());

            var filter = new FrontModel.ArticleFilter
            {
                Name = articles[0].Name.Substring(0, articles[0].Name.Length / 2),
                Code = articles[1].Code.Substring(0, articles[1].Code.Length / 2)
            };

            // act:
            var result = sut.Index(filter);
            var model  = result.Model as FrontModel.ArticlesList;

            // assert:
            Assert.NotNull(model);
            Assert.NotNull(model.Filter);
            Assert.NotNull(model.Items);
            Assert.Empty(model.Items);
            Assert.Empty(result.ViewName);
        }
예제 #2
0
        public void ListArticlesFilteredTest(
            [Frozen] Mock <IRepository <Article> > repo,
            [Frozen] Mock <IUnitOfWork> unitOfWork,
            List <Article> articles,
            HomeController sut)
        {
            // arrange:
            unitOfWork.Setup(x => x.ArticlesRepository).Returns(repo.Object);
            repo.Setup(x => x.All()).Returns(articles.AsQueryable());
            var article = articles[0];

            var filter = new FrontModel.ArticleFilter
            {
                Name = article.Name.Substring(0, article.Name.Length / 2),
                Code = article.Code.Substring(0, article.Code.Length / 2)
            };

            // act:
            var result = sut.Index(filter);
            var model  = result.Model as FrontModel.ArticlesList;

            // assert:

            Assert.NotNull(model);
            Assert.NotNull(model.Filter);
            Assert.NotNull(model.Items);
            Assert.NotEmpty(model.Items);
            Assert.Equal(1, model.Items.Count());
            Assert.Empty(result.ViewName);

            // just mocked vm:
            //var articlevm = model.Items.FirstOrDefault(x => x.Id == article.Id);
            //Assert.NotNull(articlevm);
            //Assert.Equal(article.Name, articlevm.Name);
            //Assert.Equal(article.Code, articlevm.Code);
            //Assert.Equal(article.Price, articlevm.Price);
            //Assert.Equal(article.ExpiryDays, articlevm.ExpiryDays);
        }