public async Task TestIfEditBoxesThrowsError() { var context = PCHUBDbContextInMemoryInitializer.InitializeContext(); var adminPageService = new Areas.Administration.Services.AdminIndexPageServices(context); await Assert.ThrowsAsync <NullReferenceException>(async() => { var form = new EditBoxViewModel(); await adminPageService.EditBoxesAsync(form); }); }
public async Task TestIfEditBoxesWorksAccordingly() { var context = PCHUBDbContextInMemoryInitializer.InitializeContext(); var adminPageService = new Areas.Administration.Services.AdminIndexPageServices(context); var model = new AddBoxViewModel(); await adminPageService.CreateIndexPageAsync("Index"); model.Color = "Red"; model.Href = "TestModelHref"; model.Text = "TestModelText"; await adminPageService.AddBoxAsync(model); var form = new EditBoxViewModel(); form.BoxViewModel = new List <AddBoxViewModel>(); form.BoxViewModel.Add(new AddBoxViewModel { Text = "Tested", Color = "Tested", Href = "Tested", IsDeleted = true, }); await adminPageService.EditBoxesAsync(form); var page = await context.Pages.FirstOrDefaultAsync(x => x.PageName == "Index"); var boxes = page.ColorfulBoxes.Where(x => x.IsDeleted == false).ToList(); Assert.Empty(boxes); var deletedBoxes = page.ColorfulBoxes.Where(x => x.IsDeleted == true).ToList(); foreach (var box in deletedBoxes) { Assert.Equal(box.Color, "Tested"); Assert.Equal(box.Href, "Tested"); Assert.Equal(box.Text, "Tested"); Assert.True(box.IsDeleted); } }