public async Task TestIfAddIndexPageCategoryWorksProperly()
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var adminPageService = new Areas.Administration.Services.AdminIndexPageServices(context);


            await adminPageService.CreateIndexPageAsync("Index");


            var form = new CreatePageCategoryViewModel();

            form.AllHref      = "AllHref";
            form.AllName      = "AllLaptops";
            form.CategoryName = "Laptops";

            await adminPageService.AddIndexPageCategoryAsync(form, "pictureUrl", "PictureName");

            var result = await context.Pages.FirstOrDefaultAsync(x => x.PageName == "Index");

            Assert.Equal("Index", result.PageName);

            Assert.Contains(result.Categories, (pageCategory) => pageCategory.CategoryName == "Laptops");

            Assert.Contains(result.Categories, (pageCategory) => pageCategory.AllHref == "AllHref");

            Assert.Contains(result.Categories, (pageCategory) => pageCategory.AllName == "AllLaptops");
        }
        public async Task TestIfAddIndexPageCategoryThrowsError(string pagename)
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var adminPageService = new Areas.Administration.Services.AdminIndexPageServices(context);

            await Assert.ThrowsAsync <NullReferenceException>(async() =>
            {
                var form = new CreatePageCategoryViewModel();

                await adminPageService.AddIndexPageCategoryAsync(form, "pictureUrl", "PictureName");
            });
        }
        public async Task TestIfAdditemsToCategoryWorksAccordingly(string text, string href)
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var adminPageService = new Areas.Administration.Services.AdminIndexPageServices(context);

            await adminPageService.CreateIndexPageAsync("Index");


            var formCategory = new CreatePageCategoryViewModel();

            formCategory.AllHref      = "AllHref";
            formCategory.AllName      = "AllLaptops";
            formCategory.CategoryName = "Category";

            await adminPageService.AddIndexPageCategoryAsync(formCategory, "pictureUrl", "PictureName");

            var form = new IndexItemsCategoryViewModel();

            form.PageCategory = "Category";

            form.ItemCategory = "Price";

            form.Items = new List <IndexPageItemsViewModel>();

            form.Items.Add(new IndexPageItemsViewModel
            {
                Text = text,
                Href = href,
            });

            await adminPageService.AdditemsToCategoryAsync(form);

            var result = await context.PageCategories.FirstOrDefaultAsync(x => x.CategoryName == "Category");

            Assert.Contains(result.ItemsCategories, (ic) => ic.Category == "Price");
            Assert.Contains(result.ItemsCategories, (ic) => EnumerableExtensions.Any(ic.Items));



            foreach (var ic in result.ItemsCategories)
            {
                foreach (var item in ic.Items)
                {
                    Assert.Equal(text, item.Text);
                    Assert.Equal(href, item.Href);
                }
            }
        }
        public async Task TestIfGetAllPageCategoryNamesWorksAccordingly(string pagename, string categoryName)
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var adminPageService = new Areas.Administration.Services.AdminIndexPageServices(context);


            await adminPageService.CreateIndexPageAsync(pagename);


            var form = new CreatePageCategoryViewModel();

            form.AllHref      = "AllHref";
            form.AllName      = "AllLaptops";
            form.CategoryName = categoryName;

            await adminPageService.AddIndexPageCategoryAsync(form, "pictureUrl", "PictureName");

            var result = await adminPageService.GetAllPageCategoryNamesAsync();

            Assert.Contains(result, (str) => str == categoryName);
        }
        public async Task TestIfEditIndexPageCategoryWorksAccordingly(string text, string href)
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var adminPageService = new Areas.Administration.Services.AdminIndexPageServices(context);

            await adminPageService.CreateIndexPageAsync("Index");


            var formCategory = new CreatePageCategoryViewModel();

            formCategory.AllHref      = "AllHref";
            formCategory.AllName      = "AllLaptops";
            formCategory.CategoryName = "Category";

            await adminPageService.AddIndexPageCategoryAsync(formCategory, "pictureUrl", "PictureName");

            var form = new IndexItemsCategoryViewModel();

            form.PageCategory = "Category";

            form.ItemCategory = "Price";

            form.Items = new List <IndexPageItemsViewModel>();

            form.Items.Add(new IndexPageItemsViewModel
            {
                Text = text,
                Href = href,
            });

            await adminPageService.AdditemsToCategoryAsync(form);

            var model = new EditIndexCategoryViewModel();

            model.Category     = "Category";
            model.PageCategory = new List <EditCategoryViewModel>();

            var itemCategories = new List <EditItemCategoriesViewModel>();
            var items          = new List <IndexPageItemsViewModel>();

            items.Add(new IndexPageItemsViewModel
            {
                Text = "TextRand",
                Href = "HrefRand",
            });
            itemCategories.Add(new EditItemCategoriesViewModel
            {
                ItemCategory = "Price",
                Items        = items
            });
            model.PageCategory.Add(new EditCategoryViewModel
            {
                CategoryName   = "NewCategory",
                AllHref        = "NewAllHref",
                AllName        = "AllName",
                ItemCategories = itemCategories
            });


            await adminPageService.EditIndexPageCategoryAsync(model, "Category");

            var result = await context.Pages.FirstOrDefaultAsync(x => x.PageName == "Index");

            Assert.NotNull(result);

            Assert.Contains(result.Categories, (pc) => pc.CategoryName == "NewCategory");
            Assert.Contains(result.Categories, (pc) => pc.AllHref == "NewAllHref");
            Assert.Contains(result.Categories, (pc) => pc.AllName == "AllName");
        }