/// <inheritdoc/> public Pokemon Get(int id) { if (id < 1) { throw new InvalidOperationException($"Id must be at least 1. Id parameter: {id}."); } var pokemon = pokemonRepository.Get(id); return(pokemon); }
public void IfRepositoryThrowsArgumentOutOfRangeException_GetPokemon_ShouldReturnHttpNotFound() { var pokemonName = new Faker().Lorem.Word(); A.CallTo(() => _pokemonRepository.Get(A <string> ._)).Throws <ArgumentOutOfRangeException>(); var actionResult = _pokemonService.GetPokemon(pokemonName); var result = CastActionResultOrFail <NotFoundResult, Pokemon>(actionResult); result.StatusCode.Should().Be((int)HttpStatusCode.NotFound); }
public ActionResult <Pokemon> GetPokemon(string name) { try { var sw = AStartedStopwatch(); _logger.LogInformation($"{nameof(GetPokemon)} invoked, pokemon name: {name}"); var result = ToPokemon(_pokemonRepository.Get(name)); _logger.LogInformation($"{nameof(GetPokemon)} completed, elapsed time: {sw.ElapsedMilliseconds}ms"); return(result); } catch (ArgumentOutOfRangeException ex) { _logger.LogError(ex, "No pokemon found with the given name"); return(NotFound()); } catch (Exception ex) { _logger.LogError(ex, "An unexpected error occurred while retrieving pokemon information"); return(StatusCode(500)); } }
public PokemonModel Get(long id) { return(new PokemonModel(pokemonRepository.Get(id))); }
public void IfGivenNameIsNull_Get_ShouldThrowException() { this.Invoking(t => _pokemonRepository.Get(null)) .Should().ThrowExactly <ArgumentNullException>() .And.ParamName.Should().Be("name"); }