Exemplo n.º 1
0
        private void CheckMessage(IActionResult result, string message)
        {
            BreedViewModel viewModel = CheckViewModel(result);

            Assert.True(viewModel.Messages.Any());
            Assert.Equal(message, viewModel.Messages.FirstOrDefault());
        }
Exemplo n.º 2
0
        private BreedViewModel CheckViewModel(IActionResult result)
        {
            ViewResult     viewResult = Assert.IsType <ViewResult>(result);
            BreedViewModel viewModel  = Assert.IsAssignableFrom <BreedViewModel>(viewResult.ViewData.Model);

            return(viewModel);
        }
Exemplo n.º 3
0
        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"));
        }
Exemplo n.º 4
0
        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.");
            }
        }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
        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));
            }
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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);
            }
        }
Exemplo n.º 9
0
        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));
            }
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        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}"));
        }
Exemplo n.º 12
0
        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);
        }