public async Task <IViewComponentResult> InvokeAsync() { var model = new GuideCategoryListViewModel(); var categories = await this.categoryListService.TakeGuideCategoryAsync(model); return(this.View(categories)); }
public async Task <GuideCategoryListViewModel> TakeGuideCategoryAsync(GuideCategoryListViewModel model) { foreach (var category in (CategoryOfGuide[])Enum.GetValues(typeof(CategoryOfGuide))) { var guidesCount = await this.guideRepository.All().CountAsync(x => x.Category == category); var categoryToAdd = new GuideCategoryViewModel() { CategoryName = category.ToString(), GuidesCount = guidesCount, }; model.Categories.Add(categoryToAdd); } return(model); }
public async Task TakeGuideCategoryShouldTakeAllGuideCategories() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var context = new ApplicationDbContext(options.Options); var postRepository = new EfDeletableEntityRepository <Post>(context); var guideRepository = new EfDeletableEntityRepository <Guide>(context); var service = new CategoryListService(postRepository, guideRepository); var model = new GuideCategoryListViewModel(); var actual = await service.TakeGuideCategoryAsync(model); var expected = Enum.GetNames(typeof(CategoryOfGuide)).Length; Assert.Equal(expected, actual.Categories.Count); }