Exemple #1
0
        public async Task EditPokemonIsSuccessfulAndLogsInformation()
        {
            tblMyPokedex generatedPokemon = DataGenerator.GenerateMyPokemon(1)[0];

            await _pokedexRepository.EditPokemon(generatedPokemon);

            _pokedexDBContextMock.Verify(m => m.tblMyPokedex.FindAsync(new object[] { DataGenerator.DefaultGuid }), Times.Once);

            VerifyDBContextMockRemovesPokemon(1);

            VerifyDBContextMockAddsAsync(generatedPokemon);

            VerifyDBContextMockSavesChanges(2);

            VerifyLoggerMockLogsLookupInformationWithId(0);

            VerifyLoggerMockLogsPokeballAndNationalDexWithId(0);

            VerifyLoggerMockLogsDefaultPokemonRetrieval();

            VerifyLoggerMockLogsInformation("Deleted Pokémon from DBContext with Id: " + DataGenerator.DefaultGuid);

            VerifyLoggerMockLogsInformation("Added Pokémon to DBContext with Id: " + DataGenerator.DefaultGuid);

            VerifyLoggerMockLogsInformation("Updated Pokémon in DBContext with Id: " + DataGenerator.DefaultGuid);
        }
Exemple #2
0
        public async Task GetMyNonExistentPokemonByIdDoesNotLog()
        {
            tblMyPokedex pokemon = await _pokedexRepository.GetMyPokemonById(Guid.NewGuid());

            Assert.IsNull(pokemon);

            _pokedexDBContextMock.Verify(m => m.tblMyPokedex, Times.Once);
        }
Exemple #3
0
        public async Task <PokemonDetailViewModel> GetMyPokemonById(Guid id)
        {
            tblMyPokedex myPokemon = await _pokedexRepository.GetMyPokemonById(id);

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

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

            return(pokemonDetailViewModel);
        }
Exemple #4
0
        public async Task <PokemonDetailViewModel> EditPokemon(PokemonDetailViewModel pokemonDetailViewModel)
        {
            tblMyPokedex pokemon = await MapDetailViewModelToMyPokemon(pokemonDetailViewModel);

            await _pokedexRepository.EditPokemon(pokemon);

            _logger.LogInformation(Constants.Updated + " " + Constants.Pokemon + ": " + pokemonDetailViewModel.MyPokemonId);

            return(pokemonDetailViewModel);
        }
Exemple #5
0
        /// <summary>
        /// Add the given pokemon to pokedex context & save changes.
        /// </summary>
        /// <param name="pokemon">entity to add</param>
        /// <returns>the added entity</returns>
        public async Task <tblMyPokedex> AddPokemon(tblMyPokedex pokemon)
        {
            await _context.AddAsync(pokemon);

            await _context.SaveChangesAsync();

            _logger.LogInformation(string.Format(InfoMessageWithId, Constants.Added, Constants.Pokemon, Constants.To, pokemon.Id));

            return(pokemon);
        }
Exemple #6
0
        public async Task <PokemonFormViewModel> AddPokemon(PokemonFormViewModel pokemonFormViewModel)
        {
            _logger.LogInformation(Constants.Mapping + " " + Constants.Pokemon + " " + ViewModels);

            tblMyPokedex pokemon = _mapper.Map <tblMyPokedex>(pokemonFormViewModel);

            pokemon.Id = Guid.NewGuid();

            await _pokedexRepository.AddPokemon(pokemon);

            return(pokemonFormViewModel);
        }
Exemple #7
0
        public async Task DeleteNonExistentPokemonByIdDoesNotLogOrDelete()
        {
            tblMyPokedex tblMyPokedex = await _pokedexRepository.DeletePokemonById(Guid.NewGuid());

            Assert.IsNull(tblMyPokedex);

            _pokedexDBContextMock.Verify(m => m.tblMyPokedex.FindAsync(new object[] { It.IsAny <Guid>() }), Times.Once);

            VerifyDBContextMockRemovesPokemon(0);

            VerifyDBContextMockSavesChanges(0);
        }
Exemple #8
0
        public async Task AddPokemonIsSuccessfulAndLogsInformation()
        {
            tblMyPokedex generatedPokemon = DataGenerator.GenerateMyPokemon(1)[0];

            await _pokedexRepository.AddPokemon(generatedPokemon);

            VerifyDBContextMockAddsAsync(generatedPokemon);

            VerifyDBContextMockSavesChanges(1);

            VerifyLoggerMockLogsInformation("Added Pokémon to DBContext with Id: " + DataGenerator.DefaultGuid);
        }
Exemple #9
0
        /// <summary>
        /// Delete & re-add updated entity to pokedex context.
        /// </summary>
        /// <param name="pokemon">entity to update</param>
        /// <returns>updated entity</returns>
        public async Task <tblMyPokedex> EditPokemon(tblMyPokedex pokemon)
        {
            tblMyPokedex myPokemon = await DeletePokemonById(pokemon.Id);

            if (myPokemon != null)
            {
                await AddPokemon(pokemon);

                _logger.LogInformation(string.Format(InfoMessageWithId, Constants.Updated, Constants.Pokemon, Constants.In, pokemon.Id));
            }

            return(pokemon);
        }
Exemple #10
0
        /// <summary>
        /// Delete the given pokemon from pokedex context & save changes.
        /// </summary>
        /// <param name="myPokemonId">guid to find & delete</param>
        /// <returns>deleted entity</returns>
        public async Task <tblMyPokedex> DeletePokemonById(Guid myPokemonId)
        {
            tblMyPokedex myPokemon = await GetMyPokemonById(myPokemonId);

            if (myPokemon != null)
            {
                _context.Remove(myPokemon);

                await _context.SaveChangesAsync();

                _logger.LogInformation(string.Format(InfoMessageWithId, Constants.Deleted, Constants.Pokemon, Constants.From, myPokemonId));
            }

            return(myPokemon);
        }
Exemple #11
0
        /// <summary>
        /// Get the pokedex entity from a given myPokemonId with lookup information.
        /// </summary>
        /// <param name="myPokemonId">the myPokemonId to find</param>
        /// <returns>the found pokedex entity</returns>
        public async Task <tblMyPokedex> GetMyPokemonById(Guid myPokemonId)
        {
            tblMyPokedex myPokemon = await _context.tblMyPokedex.FindAsync(myPokemonId);

            if (myPokemon != null)
            {
                //Grab nested lookup data
                myPokemon.Pokemon = await GetNationalDexPokemonById(myPokemon.PokemonId);

                myPokemon.Pokeball = await GetPokeballById(myPokemon.PokeballId.Value);

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

            return(myPokemon);
        }
Exemple #12
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);
        }
Exemple #13
0
        public async Task GetMyPokemonByIdIsSuccessfulAndLogsInformation()
        {
            tblMyPokedex pokemon = await _pokedexRepository.GetMyPokemonById(DataGenerator.DefaultGuid);

            Assert.AreEqual(DateTime.Today, pokemon.Date);
            Assert.AreEqual(1, pokemon.Level);
            Assert.AreEqual("0 Main Street", pokemon.Location);
            Assert.AreEqual("Nickname0", pokemon.Nickname);
            Assert.AreEqual(0, pokemon.PokeballId);
            Assert.AreEqual(0, pokemon.PokemonId);
            Assert.IsTrue(pokemon.Sex.Value); //ie, Sex == bit 0 in SQL.

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

            VerifyLoggerMockLogsDefaultPokemonRetrieval();

            VerifyLoggerMockLogsLookupInformationWithId(0);
            VerifyLoggerMockLogsPokeballAndNationalDexWithId(0);
        }
Exemple #14
0
 private void VerifyDBContextMockAddsAsync(tblMyPokedex pokemon)
 {
     _pokedexDBContextMock.Verify(m => m.AddAsync(pokemon, It.IsAny <CancellationToken>()), Times.Once);
 }