Exemple #1
0
        public async Task PokemonRequestTestAsync()
        {
            using var pokedexClient = new PokedexClient();
            await Assert.ThrowsAsync <UnknownPokemonException>(() => pokedexClient.GetPokemonAsync("dito"));

            await Assert.ThrowsAsync <UnknownPokemonTypeException>(() => pokedexClient.GetPokemonsByTypeAsync("firre"));
        }
Exemple #2
0
        public void GivenHtml_WhenParseDescription_ThenReturnsDescription()
        {
            var html     = File.ReadAllText("PokedexPokemon.html");
            var expected = "Charizard flies around the sky in search of powerful opponents. It breathes fire of such great heat that it melts anything. However, it never turns its fiery breath on any opponent weaker than itself.";

            Assert.True(PokedexClient.TryParse(html, out var actual));
            Assert.AreEqual(expected, actual);
        }
Exemple #3
0
        public void GivenPokemonName_WhenGetDescription_ThenReturnsExpected()
        {
            var sut      = new PokedexClient();
            var expected = "Squirtle's shell is not merely used for protection. The shell's rounded shape and the grooves on its surface help minimize resistance in water, enabling this Pokémon to swim at high speeds.";

            Assert.IsTrue(sut.TryGet("squirtle", out var actual));

            Assert.AreEqual(expected, actual);
        }
Exemple #4
0
        /// <summary>
        /// Envoie une requête vers L'API à partir d'arguments.
        /// </summary>
        /// <param name="args"></param>
        /// <param name="pokedexClient"></param>
        /// <returns></returns>
        public static async Task RequestAsync(this string[] args, PokedexClient pokedexClient)
        {
            var command = args[0];

            switch (command)
            {
            // Recherche d'un Pokémon par son nom
            case var cmd when command == "name":
                var pokemonName = args[1];
                var pokemon     = await pokedexClient.GetPokemonAsync(pokemonName);

                Console.WriteLine(pokemon);
                break;

            // Recherche de Pokémons avec un type
            case var cmd when command == "type":
                var type           = args[1];
                var pokemonsByType = await pokedexClient.GetPokemonsByTypeAsync(type);

                var pokemonNames       = pokemonsByType.Pokemons.Select((pokemon) => pokemon.PokemonResource.Name);
                var pokemonNamesJoined = string.Join(", ", pokemonNames);

                Console.WriteLine(pokemonNamesJoined);
                break;

            // Affichage de l'aide
            case var cmd when command == "help":
                Console.WriteLine("Commandes :");

                // Nom
                Console.ForegroundColor = ConsoleColor.DarkGreen;
                Console.Write("name <nom du Pokémon>              ");
                Console.ResetColor();
                Console.Write(" - obtient les détails d'un Pokémon à partir de son nom\n");

                // Type
                Console.ForegroundColor = ConsoleColor.DarkGreen;
                Console.Write("type <type de Pokémon (en anglais)>");
                Console.ResetColor();
                Console.Write(" - obtient une liste de Pokémons ayant ce type\n");

                // Sortie
                Console.ForegroundColor = ConsoleColor.DarkGreen;
                Console.Write("exit                               ");
                Console.ResetColor();
                Console.Write(" - sortie du programme\n");
                break;

            // Sortie du programme
            case var cmd when command == "exit":
                Program.Exit = true;
                break;
            }
        }