private void CheckMessage(IActionResult result, string message) { BreedViewModel viewModel = CheckViewModel(result); Assert.True(viewModel.Messages.Any()); Assert.Equal(message, viewModel.Messages.FirstOrDefault()); }
private BreedViewModel CheckViewModel(IActionResult result) { ViewResult viewResult = Assert.IsType <ViewResult>(result); BreedViewModel viewModel = Assert.IsAssignableFrom <BreedViewModel>(viewResult.ViewData.Model); return(viewModel); }
public IActionResult Create(BreedViewModel model) { if (!ModelState.IsValid) { return(this.RedirectToAction("Error", "Home")); } BreedServiceModel serviceModel = this.mapper.Map <BreedServiceModel>(model); this.breedService.AddBreed(serviceModel); return(this.RedirectToAction("All")); }
public async void PostEditParentBreedDoesntExist() { using (var database = new TestDb()) { var controller = new BreedsController(database.Context); IActionResult result = await controller.Edit(1, new Breed { Id = 1, Name = "Test Breed with Invalid Parent Breed", BreedId = 500 }); BreedViewModel viewModel = CheckViewModel(result); CheckMessage(result, "The parent Breed selected could not be found."); } }
public async Task <IActionResult> Details(string id) { if (id == null) { return(NotFound()); } BreedViewModel breed = await breedService.GetBreed(id); if (breed == null) { return(NotFound()); } return(View(breed)); }
public void GetCreate() { using (var database = new TestDb()) { var controller = new BreedsController(database.Context); IActionResult result = controller.Create(); BreedViewModel viewModel = CheckViewModel(result); Assert.Equal(0, viewModel.Breed.Id); Assert.True(string.IsNullOrEmpty(viewModel.Breed.Name)); } }
protected override object GetUpdateDialogView() { if (ViewModel is BreedsViewModel viewModel && viewModel.SelectedModel != null) { var breedVm = new BreedViewModel() { Id = viewModel.SelectedModel.Id, Name = viewModel.SelectedModel.Name }; return(new BreedDialog("Изменить", breedVm)); } return(null); }
public async void GetDeleteSuccess() { using (var database = new TestDb()) { var controller = new BreedsController(database.Context); IActionResult result = await controller.Delete(3); BreedViewModel viewModel = CheckViewModel(result); Breed breed = database.Context.Breeds.SingleOrDefault(b => b.Id == 3); Assert.Equal(3, viewModel.Breed.Id); Assert.Equal(breed.Name, viewModel.Breed.Name); } }
public async void GetDetailsWithIndividuals() { using (var database = new TestDb()) { var controller = new BreedsController(database.Context); IActionResult result = await controller.Details(8); BreedViewModel viewModel = CheckViewModel(result); Breed breed = database.Context.Breeds.SingleOrDefault(b => b.Id == 8); Assert.Equal(8, viewModel.Breed.Id); Assert.Equal(breed.Name, viewModel.Breed.Name); Assert.Equal(viewModel.Individuals.Count(), database.Context.Individuals.Count(m => m.Breed.Id == 8)); } }
public async Task <BreedViewModel> GetBreed(string id) { Breed breed = await context.Breeds.FirstOrDefaultAsync(c => c.Id == id); BreedViewModel breedViewModel; if (breed != null) { breedViewModel = new BreedViewModel { Id = breed.Id, Name = breed.Name, }; return(breedViewModel); } return(null); }
public async Task <IActionResult> Edit(BreedViewModel breedModel) { Breed breed = await context.Breeds.FirstOrDefaultAsync(b => b.Id == breedModel.Id); if (breed == null) { return(NotFound()); } if (ModelState.IsValid) { breed.Name = breedModel.Name; context.Update(breed); context.SaveChangesAsync(); } return(Redirect($"/Breeds/Details/{breed.Id}")); }
public ActionResult Index(BreedViewModel breedViewModel) { IQueryable<Breed> QueryBreed = db.Breeds; if(breedViewModel.BreedName != null) { QueryBreed = QueryBreed.Where(q => q.Name.Contains(breedViewModel.BreedName)); } if (breedViewModel.SortBy != null && breedViewModel.SortDirection != null) { QueryBreed = QueryBreed.OrderBy(string.Format("{0} {1}", breedViewModel.SortBy, breedViewModel.SortDirection)); } breedViewModel.Count = QueryBreed.Count(); QueryBreed = QueryBreed.Skip((breedViewModel.Page - 1) * breedViewModel.PageSize).Take(breedViewModel.PageSize); breedViewModel.Breeds = QueryBreed.ToList(); return View(breedViewModel); }