Ejemplo n.º 1
0
        public async Task GetPokemonType_ReturnsTypes()
        {
            #region Arrange
            string pokemonName           = PokemonNameMother.Name();
            var    pokemonTypeRepository = new Mock <PokemonTypeRepository>();

            pokemonTypeRepository
            .Setup(r => r.Search(It.Is <PokemonName>(n => String.Equals(n.Name, pokemonName, StringComparison.InvariantCultureIgnoreCase))))
            .ReturnsAsync(PokemonTypesMother.PokemonTypes());

            PokemonTypeSearcher pokemonTypeSearcher = new PokemonTypeSearcher(pokemonTypeRepository.Object);
            GetPokemonTypes     getPokemonTypes     = new GetPokemonTypes(pokemonTypeSearcher);

            #endregion

            #region Act
            PokemonTypes pokemonTypes = await getPokemonTypes.Execute(pokemonName);

            #endregion

            #region Assert
            Assert.Equal(pokemonTypes.Types.Select(s => s.PokemonTypeName.Name).ToArray(), PokemonTypesMother.PokemonTypes().Types.Select(s => s.PokemonTypeName.Name).ToArray());

            #endregion
        }
Ejemplo n.º 2
0
        public void GetPokemonType_NotFound_ReturnsException()
        {
            #region Arrange
            string pokemonName     = PokemonNameMother.Random();
            string expectedMessage = $"Pokemon '{pokemonName}' does not exist";

            var pokemonTypeRepository = new Mock <PokemonTypeRepository>();

            pokemonTypeRepository
            .Setup(r => r.Search(It.Is <PokemonName>(n => String.Equals(n.Name, pokemonName, StringComparison.InvariantCultureIgnoreCase))))
            .ReturnsAsync(null as PokemonTypes);

            PokemonTypeSearcher pokemonTypeSearcher = new PokemonTypeSearcher(pokemonTypeRepository.Object);
            GetPokemonTypes     getPokemonTypes     = new GetPokemonTypes(pokemonTypeSearcher);

            #endregion

            #region Act
            var exception = Record.ExceptionAsync(async() => await getPokemonTypes.Execute(pokemonName));

            #endregion

            #region Assert
            Assert.Equal(expectedMessage, exception.Result.Message);

            #endregion
        }
Ejemplo n.º 3
0
        public static async Task Main(string[] args)
        {
            string pokemonName;

            if (args.Any())
            {
                pokemonName = args.First();
            }
            else
            {
                Console.WriteLine("Enter pokemon name:");
                pokemonName = Console.ReadLine();
            }

            try
            {
                PokeApiPokemonTypeRepository pokeApiPokemonTypeRepository = new PokeApiPokemonTypeRepository();
                PokemonTypeSearcher          pokemonTypeSearcher          = new PokemonTypeSearcher(pokeApiPokemonTypeRepository);

                GetPokemonTypes getPokemonType = new GetPokemonTypes(pokemonTypeSearcher);
                PokemonTypes    pokemonTypes   = await getPokemonType.Execute(pokemonName);

                Console.WriteLine(PokemonTypeToStringConverter.Execute(pokemonTypes));
            }
            catch (PokemonNotFoundException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
 public async Task <IActionResult> Get(string name)
 {
     try
     {
         return(Ok(PokemonTypeToJsonConverter.Execute(await _getPokemonType.Execute(name))));
     }
     catch (PokemonNotFoundException ex)
     {
         return(NotFound(ex.Message));
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex.Message));
     }
 }