public async Task <ActionResult <PokemonModel> > Get(string pokemonname) { string description = null; string descriptionShakespearified = null; try { PokemonProxy pokemonProxy = new PokemonProxy(); description = await pokemonProxy.GetPokemonDescription(pokemonname); } catch (Exception ex) { string error = string.Format(errorJson, 400, "Unable to retrieve pokemon."); return(BadRequest(error)); } try { ShakespeareProxy shakespeareProxy = new ShakespeareProxy(); descriptionShakespearified = await shakespeareProxy.Shakespearify(description); } catch (Exception) { string error = string.Format(errorJson, 400, "Shakespeare Generic Error."); return(BadRequest(error)); } PokemonModel pokemon = new PokemonModel() { Name = pokemonname, Description = descriptionShakespearified }; return(pokemon); }
public async Task PokemonProxyIntensiveTest() { PokemonProxy pokemonProxy = new PokemonProxy(); string pokemonsUrl = "https://pokeapi.co/api/v2/pokemon/?offset={0}&limit=20"; int pokemonnumber = 1; int count = 0; int offset = 0; do { offset += 20; PokemonList lst = null; string url = string.Format(pokemonsUrl, offset); HttpWebRequest webrequest = (HttpWebRequest)System.Net.WebRequest.Create(url); webrequest.Method = "GET"; using (var response = await webrequest.GetResponseAsync()) using (var reader = new StreamReader(response.GetResponseStream())) { var result = reader.ReadToEnd(); lst = JsonConvert.DeserializeObject <PokemonList>(result); } if (count == 0) { count = lst.count; if (count == 0) { throw new Exception("No pokemons retrieved!!!"); } } // Test foreach (var pokemon in lst.results) { string pokemonDescription = await pokemonProxy.GetPokemonDescription(pokemon.name); // Just debugging informations System.Diagnostics.Debug.WriteLine($"#{pokemonnumber}"); System.Diagnostics.Debug.WriteLine(pokemon.name); System.Diagnostics.Debug.WriteLine(pokemonDescription); pokemonnumber++; Assert.True(!String.IsNullOrWhiteSpace(pokemonDescription)); } } while (offset < count); }