public async Task TestIfEditIndexPageCategoryThrowsError() { var context = PCHUBDbContextInMemoryInitializer.InitializeContext(); var adminPageService = new Areas.Administration.Services.AdminIndexPageServices(context); var form = new EditIndexCategoryViewModel(); await Assert.ThrowsAsync <NullReferenceException>(async() => { await adminPageService.EditIndexPageCategoryAsync(form, "RandomCategory"); }); }
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"); }