Exemplo n.º 1
0
        public async Task GetNationalDexPokemonByIdIsSuccessfulAndLogsInformation()
        {
            tlkpNationalDex pokemon = await _pokedexRepository.GetNationalDexPokemonById(0);

            Assert.AreEqual(0, pokemon.AbilityId);
            Assert.AreEqual("Name0", pokemon.Ability.Name);
            Assert.AreEqual(0, pokemon.CategoryId);
            Assert.AreEqual("Name0", pokemon.Category.Name);
            Assert.AreEqual("Desc0", pokemon.Description);
            Assert.AreEqual(1, pokemon.HeightInInches);
            Assert.AreEqual("Name1", pokemon.HiddenAbility.Name);
            Assert.AreEqual(1, pokemon.HiddenAbilityId);
            Assert.AreEqual(0, pokemon.Id);
            Assert.AreEqual("http://0.com", pokemon.ImageURL);
            Assert.AreEqual("JapaneseName0", pokemon.JapaneseName);
            Assert.AreEqual("Name0", pokemon.Name);
            Assert.AreEqual(0, pokemon.TypeOneId);
            Assert.AreEqual(1, pokemon.TypeTwoId);
            Assert.AreEqual(1, pokemon.WeightInPounds);

            _pokedexDBContextMock.Verify(m => m.tlkpNationalDex, Times.Once);

            VerifyLoggerMockLogsInformation("Retrieved Pokémon from DBContext with Id: 0");

            VerifyLoggerMockLogsLookupInformationWithId(0);
        }
Exemplo n.º 2
0
        public async Task GetNonExistentNationalDexPokemonByIdDoesNotLog()
        {
            tlkpNationalDex pokemon = await _pokedexRepository.GetNationalDexPokemonById(-333);

            Assert.IsNull(pokemon);

            _pokedexDBContextMock.Verify(m => m.tlkpNationalDex, Times.Once);
        }
Exemplo n.º 3
0
        public async Task <PokemonDetailViewModel> GetNationalDexPokemonById(int id)
        {
            tlkpNationalDex pokemon = await _pokedexRepository.GetNationalDexPokemonById(id);

            _logger.LogInformation(string.Format(Constants.InformationalMessageMappingWithCount, 1, Constants.Pokemon, ViewModels));

            PokemonDetailViewModel pokemonDetailViewModel = _mapper.Map <PokemonDetailViewModel>(pokemon);

            return(pokemonDetailViewModel);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Get the national dex entity from a given pokemonId.
        /// </summary>
        /// <param name="pokemonId">the pokemonId to find</param>
        /// <returns>the found nationsl dex Pokémon</returns>
        public async Task <tlkpNationalDex> GetNationalDexPokemonById(int pokemonId)
        {
            tlkpNationalDex nationalDexPokemon = await _context.tlkpNationalDex.FindAsync(pokemonId);

            if (nationalDexPokemon != null)
            {
                //Grab nested national dex lookup
                nationalDexPokemon = await GetNestedNationalDexInfo(nationalDexPokemon);

                _logger.LogInformation(string.Format(InfoMessageWithId, Constants.Retrieved, Constants.Pokemon, Constants.From, pokemonId));
            }

            return(nationalDexPokemon);
        }
Exemplo n.º 5
0
        private async Task <tblMyPokedex> MapDetailViewModelToMyPokemon(PokemonDetailViewModel pokemonDetailViewModel)
        {
            _logger.LogInformation(Constants.Mapping + " " + Constants.Pokemon + " " + ViewModels);

            tlkpNationalDex nationalDexLookup = await _pokedexRepository.GetNationalDexPokemonById(pokemonDetailViewModel.NationalDexPokemonId.Value);

            tblMyPokedex beforeUpdates = await _pokedexRepository.GetMyPokemonById(pokemonDetailViewModel.MyPokemonId.Value);

            tblMyPokedex updatedPokemon = _mapper.Map <tblMyPokedex>(pokemonDetailViewModel);

            updatedPokemon.PokeballId = beforeUpdates.PokeballId;
            updatedPokemon.Pokeball   = beforeUpdates.Pokeball;
            updatedPokemon.Pokemon    = nationalDexLookup;
            updatedPokemon.PokemonId  = nationalDexLookup.Id;

            return(updatedPokemon);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Get all the nested NationalDex lookup information for a given Pokémon.
        /// </summary>
        /// <param name="nationalDexPokemon">the National Dex Pokémon to grab lookups for.</param>
        /// <returns>the National Dex Pokémon with lookups filled.</returns>
        private async Task <tlkpNationalDex> GetNestedNationalDexInfo(tlkpNationalDex nationalDexPokemon)
        {
            nationalDexPokemon.Ability = await GetAbilityById(nationalDexPokemon.AbilityId.Value);

            if (nationalDexPokemon.HiddenAbilityId.HasValue)
            {
                nationalDexPokemon.HiddenAbility = await GetAbilityById(nationalDexPokemon.HiddenAbilityId.Value);
            }

            nationalDexPokemon.Category = await GetCategoryById(nationalDexPokemon.CategoryId.Value);

            nationalDexPokemon.TypeOne = await GetTypeById(nationalDexPokemon.TypeOneId.Value);

            if (nationalDexPokemon.TypeTwoId.HasValue)
            {
                nationalDexPokemon.TypeTwo = await GetTypeById(nationalDexPokemon.TypeTwoId.Value);
            }

            return(nationalDexPokemon);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Get all national dex entities and subsequent lookup information.
        /// Results ordered Id ascending.
        /// </summary>
        /// <returns>all national dex Pokémon with related lookup information</returns>
        public async Task <List <tlkpNationalDex> > GetNationalDex()
        {
            List <tlkpNationalDex> nationalDex = await _context.tlkpNationalDex.ToListAsync();

            //Grab all nested lookup data
            List <tlkpNationalDex> nestedNationalDex = new List <tlkpNationalDex>();

            foreach (tlkpNationalDex pokemon in nationalDex)
            {
                tlkpNationalDex nested = await GetNestedNationalDexInfo(pokemon);

                nestedNationalDex.Add(nested);
            }

            nestedNationalDex.OrderBy(p => p.Id);

            _logger.LogInformation(string.Format(InformationalMessageWithCount, nestedNationalDex.Count, Constants.Pokemon));

            return(nestedNationalDex);
        }
Exemplo n.º 8
0
        public async Task <GenericPokemonResult> GetNationalDexPokemonById(int id)
        {
            tlkpNationalDex nationalDex = await _pokedexRepository.GetNationalDexPokemonById(id);

            _logger.LogInformation(Constants.Mapping + " " + Constants.NationalDex + " " + Results + ".");

            return(nationalDex == null ? null : new GenericPokemonResult
            {
                Ability = nationalDex.Ability.Name,
                Category = nationalDex.Category.Name,
                Description = nationalDex.Description,
                HeightInInches = nationalDex.HeightInInches,
                HiddenAbility = nationalDex.HiddenAbilityId.HasValue ? nationalDex.HiddenAbility.Name : Constants.NotApplicable,
                ImageURL = nationalDex.ImageURL,
                JapaneseName = nationalDex.JapaneseName,
                Name = nationalDex.Name,
                NationalDexPokemonId = nationalDex.Id,
                TypeOne = nationalDex.TypeOne.Name,
                TypeTwo = nationalDex.TypeTwoId.HasValue ? nationalDex.TypeTwo.Name : Constants.NotApplicable,
                WeightInPounds = nationalDex.WeightInPounds
            });
        }