public async Task TestIfGetAllBoxesForPageWorksAccordingly(string pageName, string href, string text,
                                                                   string color)
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var categoryPagesService = new Areas.Administration.Services.AdminCategoryPagesServices(context);

            await context.Pages.AddAsync(new Page
            {
                PageName      = pageName,
                ColorfulBoxes = new List <ColorfulBox>(),
            });

            await context.SaveChangesAsync();

            var model = new AddBoxViewModel();

            model.Color    = color;
            model.Href     = href;
            model.Text     = text;
            model.PageName = pageName;

            await categoryPagesService.AddBoxAsync(model);

            var result = await categoryPagesService.GetAllBoxesForPageAsync(pageName);

            Assert.NotEmpty(result);

            Assert.Contains(result, x => x.Href == href && x.Text == text && x.Color == color);
        }
        public async Task TestIfPageAlreadyExistsReturnsFalse(string category)
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var categoryPagesService = new Areas.Administration.Services.AdminCategoryPagesServices(context);

            Assert.False(await categoryPagesService.PageAlreadyExistsAsync(category));
        }
        public async Task TestIfGetPageReturnsNull(string pageName)
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var categoryPagesService = new Areas.Administration.Services.AdminCategoryPagesServices(context);

            var result = await categoryPagesService.GetPageAsync(pageName);

            Assert.Null(result);
        }
        public async Task TestIfGetAllPageNamesReturnsEmptyCollection()
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var categoryPagesService = new Areas.Administration.Services.AdminCategoryPagesServices(context);

            var result = await categoryPagesService.GetAllPageNamesAsync();

            Assert.Empty(result);
        }
        public async Task TestIfGetAllBoxesForPageThrowsError()
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var categoryPagesService = new Areas.Administration.Services.AdminCategoryPagesServices(context);

            await Assert.ThrowsAsync <NullReferenceException>(async() =>
            {
                await categoryPagesService.GetAllBoxesForPageAsync(null);
            });
        }
        public async Task TestIfAddBoxThrowsError()
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var categoryPagesService = new Areas.Administration.Services.AdminCategoryPagesServices(context);

            await Assert.ThrowsAsync <NullReferenceException>(async() =>
            {
                var model = new AddBoxViewModel();
                await categoryPagesService.AddBoxAsync(model);
            });
        }
        public async Task TestIfPageAlreadyExistsReturnsTrue(string category)
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var categoryPagesService = new Areas.Administration.Services.AdminCategoryPagesServices(context);

            await context.Pages.AddAsync(new Page
            {
                PageName = category
            });

            await context.SaveChangesAsync();

            Assert.True(await categoryPagesService.PageAlreadyExistsAsync(category));
        }
        public async Task TestIfGetPageReturnsCorrectResult(string pageName)
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var categoryPagesService = new Areas.Administration.Services.AdminCategoryPagesServices(context);


            await context.Pages.AddAsync(new Page
            {
                PageName = pageName,
            });

            await context.SaveChangesAsync();

            var result = await categoryPagesService.GetPageAsync(pageName);

            Assert.NotNull(result);

            Assert.Equal(pageName, result.PageName);
        }
        public async Task TestIfGetAllPageNamesWorksAccordingly(string pageName)
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var categoryPagesService = new Areas.Administration.Services.AdminCategoryPagesServices(context);

            await context.Pages.AddAsync(new Page
            {
                PageName = pageName,
            });

            await context.SaveChangesAsync();

            var result = await categoryPagesService.GetAllPageNamesAsync();

            Assert.NotEmpty(result);

            Assert.DoesNotContain(result, x => x == "Index");

            Assert.Contains(result, x => x == pageName);
        }
        public async Task TestIfCreateCategoryPageWorksAccordingly()
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var categoryPagesService = new Areas.Administration.Services.AdminCategoryPagesServices(context);

            var model = new CreateCategoryPageViewModel();

            var items = new List <PageCategoryItemsViewModel>
            {
                new PageCategoryItemsViewModel
                {
                    Href = "Href",
                    Text = "Text",
                },
                new PageCategoryItemsViewModel
                {
                    Href = "HrefTest",
                    Text = "TextTest",
                },
                new PageCategoryItemsViewModel
                {
                    Href = "HrefTestNext",
                    Text = "TextTestNext",
                },
            };

            var itemCategories = new List <CategoryPageItemsCategoryViewModel>
            {
                new CategoryPageItemsCategoryViewModel
                {
                    Category = "Price",
                    Items    = items,
                }
            };

            model.PageCategory = new PageCategoryViewModel
            {
                CategoryName = "Laptops",
                Pictures     = new List <string>
                {
                    "Url1", "Ur2", "Url3",
                },
                AllHref         = "AllHref",
                AllName         = "AllName",
                ItemsCategories = itemCategories,
            };

            model.PageName = "Laptops";

            await categoryPagesService.CreateCategoryPageAsync(model);

            var pageResult = await context.Pages.FirstOrDefaultAsync(x => x.PageName == "Laptops");

            Assert.NotNull(pageResult);

            Assert.Contains(pageResult.Categories, (x) => x.CategoryName == "Laptops");

            var resultItemsCategories = pageResult.Categories.SelectMany(x => x.ItemsCategories);

            Assert.NotEmpty(resultItemsCategories);

            var resultItems = resultItemsCategories.SelectMany(x => x.Items);

            Assert.Contains(resultItems, x => x.Text == "Text" && x.Href == "Href");
        }