public async Task AllShouldReturnModelWithCorrectInformation() { // ARRANGE const string database = "AllShouldReturnModelWithCorrectInformation"; const int pageSize = 5; const int totalArticlesCount = 25; await using var context = new FakeDbContext(database); await context.SeedArticles(25); var mapper = new Mapper( new MapperConfiguration(conf => conf.AddProfile(new ServiceMappingProfile()))); var dataTimeService = new DateTimeService(); var configuration = new ConfigurationBuilder() .AddInMemoryCollection(new KeyValuePair <string, string>[] { new KeyValuePair <string, string>("Articles:PageSize", pageSize.ToString()), }) .Build(); var articleService = new ArticleService(context, mapper, dataTimeService); var controller = new ArticlesController(articleService, mapper, configuration); // ACT ViewResult result = Assert.IsType <ViewResult>(await controller.All()); ArticleListingViewModel model = Assert.IsType <ArticleListingViewModel>(result.Model); // ASSERT Assert.Equal(pageSize, model.Articles.Count()); Assert.Equal(totalArticlesCount, model.Total); }
public async Task <IActionResult> Index(int page = 1) { var articlesForListing = new ArticleListingViewModel { Articles = await this.articleService.AllAsync(page), TotalArticels = await this.articleService.TotalAsync(), CurrentPage = page }; return(this.View(articlesForListing)); }
public async Task <IActionResult> Index(int page = 1) { var model = new ArticleListingViewModel { Articles = await this.articleService.GetAllAsync(page), TotalArticles = await this.articleService.GetTotalArticlesCountAsync(), CurrentPage = page }; return(View(model)); }
public async Task <IActionResult> Index(int page = 1) { var model = new ArticleListingViewModel { Articles = this.blogArticleService.AllArticles <BlogArticleViewModel>(page), TotalArticles = await this.blogArticleService.TotalAsync(), CurrentPage = page }; return(this.View(model)); }
public async Task <IActionResult> Index(int page = 1) { var model = new ArticleListingViewModel { Articles = await this.articles.AllAsync <BlogArticleListingModel>(page), PagesModel = new PagesModel { TotalItems = await this.articles.TotalAsync(), CurrentPage = page, ItemsOnPage = ArticlesPageSize } }; return(this.View(model)); }
public IViewComponentResult Invoke(Guid categoryId, int pageIndex, int pageSize) { IList <ArticleProvider> articles = null; if (categoryId != Guid.Empty) { articles = _articlesRepository.GetArticles(categoryId, pageIndex, pageSize); } else { articles = _articlesRepository.GetArticles(pageIndex, pageSize); } var model = new ArticleListingViewModel { Articles = _mapper.Map <IEnumerable <ArticleItemViewModel> >(articles), Categories = new SelectList(_articlesRepository.GetCategories(), nameof(Category.Id), nameof(Category.Title)) }; return(View(model)); }