Пример #1
0
        public void WhenCalledWithDefaultParameters_GivenSomeNotDeletedCategoriesExist_ShouldReturnThem()
        {
            var existingCategories = new List <Category>();

            existingCategories.Add(new Category()
            {
                Id = 1
            });
            existingCategories.Add(new Category()
            {
                Id = 2, Deleted = true
            });
            existingCategories.Add(new Category()
            {
                Id = 3
            });

            // Arange
            var categoryRepo = MockRepository.GenerateStub <IRepository <Category> >();

            categoryRepo.Stub(x => x.TableNoTracking).Return(existingCategories.AsQueryable());

            var productCategoryRepo = MockRepository.GenerateStub <IRepository <ProductCategory> >();

            // Act
            var cut        = new CategoryApiService(categoryRepo, productCategoryRepo);
            var categories = cut.GetCategories();

            // Assert
            Assert.AreEqual(2, categories.Count);
            Assert.AreEqual(existingCategories[0].Id, categories[0].Id);
            Assert.AreEqual(existingCategories[2].Id, categories[1].Id);
        }
        public void WhenCategoryIsReturnedByTheRepository_ShouldReturnTheSameCategory()
        {
            int      categoryId = 3;
            Category category   = new Category()
            {
                Id = 3, Name = "some name"
            };

            // Arange
            var categoryRepo = MockRepository.GenerateStub <IRepository <Category> >();

            var list = new List <Category>();

            list.Add(category);

            categoryRepo.Stub(x => x.Table).Return(list.AsQueryable());

            categoryRepo.Stub(x => x.GetById(categoryId)).Return(category);

            var productCategoryRepo = MockRepository.GenerateStub <IRepository <ProductCategory> >();

            // Act
            var cut    = new CategoryApiService(categoryRepo, productCategoryRepo);
            var result = cut.GetCategoryById(categoryId);

            // Assert
            Assert.AreSame(category, result);
        }
        public void WhenCalledWithDefaultParameters_GivenSomeNotDeletedCategoriesExist_ShouldReturnTheirCount()
        {
            var existingCategories = new List <Category>();

            existingCategories.Add(new Category()
            {
                Id = 1
            });
            existingCategories.Add(new Category()
            {
                Id = 2, Deleted = true
            });
            existingCategories.Add(new Category()
            {
                Id = 3
            });

            // Arange
            var categoryRepo = MockRepository.GenerateStub <IRepository <Category> >();

            categoryRepo.Stub(x => x.TableNoTracking).Return(existingCategories.AsQueryable());

            var productCategoryRepo = MockRepository.GenerateStub <IRepository <ProductCategory> >();

            var storeMappingService = MockRepository.GenerateStub <IStoreMappingService>();

            storeMappingService.Stub(x => x.Authorize(Arg <Category> .Is.Anything)).Return(true);

            // Act
            var cut         = new CategoryApiService(categoryRepo, productCategoryRepo, storeMappingService);
            var countResult = cut.GetCategoriesCount();

            // Assert
            Assert.AreEqual(2, countResult);
        }
Пример #4
0
        public void WhenCalledWithDefaultParameters_GivenOnlyDeletedCategoriesExist_ShouldReturnEmptyCollection()
        {
            var existingCategories = new List <Category>();

            existingCategories.Add(new Category()
            {
                Id = 1, Deleted = true
            });
            existingCategories.Add(new Category()
            {
                Id = 2, Deleted = true
            });

            // Arange
            var categoryRepo = MockRepository.GenerateStub <IRepository <Category> >();

            categoryRepo.Stub(x => x.TableNoTracking).Return(existingCategories.AsQueryable());

            var productCategoryRepo = MockRepository.GenerateStub <IRepository <ProductCategory> >();

            var storeMappingService = MockRepository.GenerateStub <IStoreMappingService>();

            // Act
            var cut        = new CategoryApiService(categoryRepo, productCategoryRepo, storeMappingService);
            var categories = cut.GetCategories();

            // Assert
            Assert.AreEqual(0, categories.Count);
        }
        private async void ShowCategories()
        {
            CategoryApiService cService = new CategoryApiService();
            var categoryList            = await cService.GetCategoriesAsync();

            tvCategories.ItemsSource = categoryList;
        }
        public void WhenCalledWithDefaultParameters_GivenSomeCategoriesExist_ShouldReturnTheirCount()
        {
            var existingCategories = new List <Category>();

            existingCategories.Add(new Category()
            {
                Id = 2, Published = false
            });
            existingCategories.Add(new Category()
            {
                Id = 3
            });
            existingCategories.Add(new Category()
            {
                Id = 1
            });

            // Arange
            var categoryRepo = MockRepository.GenerateStub <IRepository <Category> >();

            categoryRepo.Stub(x => x.TableNoTracking).Return(existingCategories.AsQueryable());

            var productCategoryRepo = MockRepository.GenerateStub <IRepository <ProductCategory> >();

            // Act
            var cut         = new CategoryApiService(categoryRepo, productCategoryRepo);
            var countResult = cut.GetCategoriesCount();

            // Assert
            Assert.AreEqual(existingCategories.Count, countResult);
        }
Пример #7
0
        private void ShowCategories()
        {
            CategoryApiService cService = new CategoryApiService();
            var cList = cService.GetCategories();

            CreateRbtCategories(cList);
            gbCategory.Content = spCategories;
        }
Пример #8
0
        protected async Task Load()
        {
            Category = await CategoryApiService.Get(Id);

            Events = await EventApiService.GetUpcomingForCategory(Id);

            IsLoading = false;
        }
Пример #9
0
        protected async Task Load()
        {
            var category = await CategoryApiService.Get(Id);

            Name           = category.Name;
            UpcomingEvents = await EventApiService.GetUpcomingForCategory(Id);

            IsLoading = false;
            StateHasChanged();
        }
Пример #10
0
        protected async Task Load()
        {
            var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();

            if (authState.User.Identity != null && authState.User.Identity.IsAuthenticated)
            {
                Categories = await CategoryApiService.Get();
            }

            IsLoading = false;
            StateHasChanged();
        }
Пример #11
0
        protected async Task HandleSubmit()
        {
            if (Category.Id == 0)
            {
                await CategoryApiService.Post(Category);
            }
            else
            {
                await CategoryApiService.Put(Category.Id, Category);
            }

            NavigationManager.NavigateTo("admin/categories");
        }
        public void WhenNegativeOrZeroCategoryIdPassed_ShouldReturnNull(int negativeOrZeroCategoryId)
        {
            // Aranges
            var categoryRepoStub    = MockRepository.GenerateStub <IRepository <Category> >();
            var productCategoryRepo = MockRepository.GenerateStub <IRepository <ProductCategory> >();

            // Act
            var cut    = new CategoryApiService(categoryRepoStub, productCategoryRepo);
            var result = cut.GetCategoryById(negativeOrZeroCategoryId);

            // Assert
            Assert.IsNull(result);
        }
        public void WhenCalledWithDefaultParameters_GivenNoCategoriesExist_ShouldReturnZero()
        {
            // Arange
            var categoryRepo = MockRepository.GenerateStub <IRepository <Category> >();

            categoryRepo.Stub(x => x.TableNoTracking).Return(new List <Category>().AsQueryable());

            var productCategoryRepo = MockRepository.GenerateStub <IRepository <ProductCategory> >();

            // Act
            var cut             = new CategoryApiService(categoryRepo, productCategoryRepo);
            var categoriesCount = cut.GetCategoriesCount();

            // Assert
            Assert.AreEqual(0, categoriesCount);
        }
        public void WhenNullIsReturnedByTheRepository_ShouldReturnNull()
        {
            int categoryId = 3;

            // Arange
            var categoryRepo = MockRepository.GenerateStub <IRepository <Category> >();

            categoryRepo.Stub(x => x.Table).Return((new List <Category>()).AsQueryable());
            categoryRepo.Stub(x => x.GetById(categoryId)).Return(null);

            var productCategoryRepo = MockRepository.GenerateStub <IRepository <ProductCategory> >();

            // Act
            var cut    = new CategoryApiService(categoryRepo, productCategoryRepo);
            var result = cut.GetCategoryById(categoryId);

            // Assert
            Assert.IsNull(result);
        }
Пример #15
0
        public async void ToggleSidebar()
        {
            _expandNavMenu = !_expandNavMenu;

            if (_expandNavMenu)
            {
                IsLoading = true;
                StateHasChanged();

                var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();

                if (authState.User.Identity != null && authState.User.Identity.IsAuthenticated)
                {
                    Categories = await CategoryApiService.Get();

                    IsLoading = false;
                }
            }

            StateHasChanged();
        }
Пример #16
0
        public void WhenCalledWithDefaultParameters_GivenSomeCategoriesExist_ShouldReturnThemSortedById()
        {
            var existingCategories = new List <Category>();

            existingCategories.Add(new Category()
            {
                Id = 2
            });
            existingCategories.Add(new Category()
            {
                Id = 3
            });
            existingCategories.Add(new Category()
            {
                Id = 1
            });

            var sortedIds = new List <int>()
            {
                1, 2, 3
            };

            // Arange
            var categoryRepo = MockRepository.GenerateStub <IRepository <Category> >();

            categoryRepo.Stub(x => x.TableNoTracking).Return(existingCategories.AsQueryable());

            var productCategoryRepo = MockRepository.GenerateStub <IRepository <ProductCategory> >();

            var storeMappingService = MockRepository.GenerateStub <IStoreMappingService>();

            // Act
            var cut        = new CategoryApiService(categoryRepo, productCategoryRepo, storeMappingService);
            var categories = cut.GetCategories();

            // Assert
            Assert.AreEqual(sortedIds[0], categories[0].Id);
            Assert.AreEqual(sortedIds[1], categories[1].Id);
            Assert.AreEqual(sortedIds[2], categories[2].Id);
        }
Пример #17
0
 public CategoriesController(ICategoryService categoryService, IMapper mapper, CategoryApiService categoryApiService)
 {
     _categoryService    = categoryService;
     _mapper             = mapper;
     _categoryApiService = categoryApiService;
 }
 public CategoryNotFoundFilter(CategoryApiService categoryService)
 {
     _categoryService = categoryService;
 }
Пример #19
0
        protected async Task HandleDelete()
        {
            await CategoryApiService.Delete(Id);

            NavigationManager.NavigateTo("admin/categories");
        }
Пример #20
0
 public CategoryController(IMapper mapper, CategoryApiService categoryApiService)
 {
     _mapper             = mapper;
     _categoryApiService = categoryApiService;
 }
 public CategoriesController(CategoryApiService categoryApiService, IMapper mapper)
 {
     _categoryApiService = categoryApiService;
     _mapper             = mapper;
 }
 //DI
 public ProductController(ProductApiService productApiService, CategoryApiService categoryApiService)
 {
     _productApiService  = productApiService;
     _categoryApiService = categoryApiService;
 }
Пример #23
0
 public NotFoundFilter(ICategoryService categoryService, CategoryApiService categoryApiService)
 {
     _categoryService    = categoryService;
     _categoryApiService = categoryApiService;
 }
Пример #24
0
 public CategoryController(CategoryApiService categoryApiService)
 {
     _categoryApiService = categoryApiService;
 }
Пример #25
0
        protected async Task Load()
        {
            Items = await CategoryApiService.Get();

            IsLoading = false;
        }