Пример #1
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var model      = new GuideCategoryListViewModel();
            var categories = await this.categoryListService.TakeGuideCategoryAsync(model);

            return(this.View(categories));
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }