Example #1
0
        public IActionResult ListAll()
        {
            var x = new PokemonTypeListVm();

            List <Pokemon> pokemons = _repo.GetAll();

            x.AllPokemons = pokemons;

            return(View(x));
        }
Example #2
0
        public int GetCantPokemons(PokemonRepository pkm)
        {
            var allPokemons = pkm.GetAll();
            var cant        = allPokemons.Count();

            return(cant);
        }
        public async Task It_Should_Return_All_Pokemons()
        {
            //Arrange
            using (var context = new ApplicationContext(_options))
            {
                context.Pokemons.Add(new Pokemon {
                    Name = "Pikachu", Level = 80
                });
                context.Pokemons.Add(new Pokemon {
                    Name = "Charmander", Level = 60
                });
                context.Pokemons.Add(new Pokemon {
                    Name = "Bulbasaur", Level = 50
                });
                context.SaveChanges();
            }
            int expectedQuantity = 4;

            //Act
            using (var context = new ApplicationContext(_options))
            {
                PokemonRepository pokemonRepository = new PokemonRepository(context);
                List <Pokemon>    pokemons          = await pokemonRepository.GetAll();

                //Assert
                Assert.Equal(expectedQuantity, pokemons.Count);
            }
        }
Example #4
0
        public async Task <IList <PokemonResponse> > GetAll()
        {
            using (var db = Db)
            {
                var pokemonRepository = new PokemonRepository(db);

                var pokemons = await pokemonRepository.GetAll();

                var pokemonResponse = new List <PokemonResponse>();

                foreach (var pokemon in pokemons)
                {
                    pokemonResponse.Add(
                        new PokemonResponse()
                    {
                        Id          = pokemon.Id,
                        Name        = pokemon.Name,
                        BaseAttack  = pokemon.BaseAttack,
                        BaseDefense = pokemon.BaseDefense,
                        BaseHP      = pokemon.BaseHP,
                        BaseSpAtk   = pokemon.BaseSpAtk,
                        BaseSpDef   = pokemon.BaseSpDef,
                        BaseSpeed   = pokemon.BaseSpeed,
                        Skills      = await GetPokemonSkills(pokemon.Id, db),
                        Types       = await GetPokemonTypes(pokemon.Id, db)
                    });
                }
                return(pokemonResponse);
            }
        }
        public object Get(Filter filter)
        {
            var list = _repository.GetAll(filter);

            // list = list.Where(p => string.IsNullOrEmpty(filtro.SearchText) || p.Name.Contains(filtro.SearchText)).ToList();
            int filtrados = list.Count;

            // PropertyInfo prop = typeof(Pokemon).GetProperty(filtro.OrderBy);

            // if (prop != null)
            // {
            //   if (filtro.OrderDir == "asc")
            //     list = list.OrderBy(p => prop.GetValue(p, null)).ToList();
            //   else
            //     list = list.OrderByDescending(p => prop.GetValue(p, null)).ToList();
            // }

            // list = list.Skip(filtro.Start).Take(filtro.Length).ToList();
            var first = list.First();

            return(new
            {
                data = list,
                recordsTotal = first.Total,
                recordsFiltered = first.Filtered
            });
        }
Example #6
0
        public string GetMostFat(PokemonRepository pokeList)
        {
            var pokemons = pokeList.GetAll();

            int cantmax = pokemons.Max(p => p.Weight);
            PokemonData pkm = pokemons.Find(u => u.Weight == cantmax);
            var text = "nombre: " + pkm.Name + "alias: " + pkm.Alias + " altura: " + pkm.Height + "peso: " + pkm.Weight;

            return text;
        }
        public async Task It_Should_Create_A_New_Pokemon()
        {
            int     expectedQuantity = 1;
            Pokemon newPokemon       = new Pokemon
            {
                Name  = "Eevee",
                Level = 100,
            };

            using (var context = new ApplicationContext(_options))
            {
                PokemonRepository pokemonRepository = new PokemonRepository(context);
                await pokemonRepository.Save(newPokemon);

                int currentQuantity = (await pokemonRepository.GetAll()).Count;

                //Assert
                Assert.Equal(expectedQuantity, currentQuantity);
            }
        }
Example #8
0
 public IActionResult Get()
 {
     return(Ok(pokemonRepository.GetAll()));
 }