public async Task GivenOKResult_WhenResourceRequested_ThenProviderShouldReturnOKResultWithPokemonContent() { //Arrange string pokemonName = "testemon"; PokeApiNet.Pokemon testPokemon = new PokeApiNet.Pokemon() { Id = 1, Name = pokemonName, Height = 123, IsDefault = true }; _mockPokeApiClient.Setup(p => p.GetResourceAsync <PokeApiNet.Pokemon>(It.IsAny <string>())).ReturnsAsync(testPokemon); var pokemonProvider = new PokemonProvider(_mockLoggerFactory, _mockPokeApiClient.Object); // Act var pokemonResult = await pokemonProvider.GetPokemon(pokemonName); // Assert pokemonResult.Should().BeOfType(typeof(ServiceResult <PokeApiNet.Pokemon>)); pokemonResult.Content.Should().NotBeNull(); pokemonResult.Content.Name.Should().Be(pokemonName); pokemonResult.Result.Should().Be(Result.OK); }
/// <summary> /// Create a Pokemon Dto object. /// </summary> /// <param name="fromMon">Pokemon object is based on</param> public PokemonDto(PokeApiNet.Pokemon fromMon, PokeApiNet.PokemonSpecies fromSpecies) { Name = fromMon.Name.Contains("-mega") ? "Mega " : ""; Name += fromSpecies.Names.Where(name => name.Language.Name == "en").FirstOrDefault().Name; Generation = Int32.Parse(new Uri(fromSpecies.Generation.Url).Segments.Last().TrimEnd('/')); PictureURL = fromMon.Sprites.FrontDefault; Types = fromMon.Types.Select(type => type.Type.Name).ToList(); Id = fromMon.Id; }
public async Task <PokeApiNet.Pokemon> GetPokemonAPI(string name) { PokeApiNet.Pokemon pokemonItem = new PokeApiNet.Pokemon(); try { RestClient client = new RestClient("https://pokeapi.co/api/v2/"); RestRequest request = new RestRequest("/pokemon/" + name, Method.GET); request.RequestFormat = DataFormat.Json; var response = client.Execute(request); if (response.IsSuccessful) { pokemonItem = JsonConvert.DeserializeObject <PokeApiNet.Pokemon>(response.Content); } else { throw new Exception("Pokemon not found in PokeApi"); } } catch (Exception ex) { throw new Exception(ex.Message); } return(pokemonItem); }