Exemple #1
0
        public async Task <ActionResult <List <PokemonDTO> > > GetPokemon_ByName(string name)
        {
            try{
                if (name == null || name.Length < 3)
                {
                    return(new BadRequestObjectResult("Pokemon name not long enough"));
                }

                PokemonDTO results = await _pokemonService.GetPokemon_ByName(name);

                if (results == null)
                {
                    return(new BadRequestObjectResult($"No pokemon were found with given name - {name}"));
                }

                return(new OkObjectResult(results));
            }
            catch (Exception ex) {
                _logger.LogError(ex.Message);
                return(new StatusCodeResult(500));
            }
        }
Exemple #2
0
        public async Task IsName_IsEmptyOrWhiteSpace_ValidationException()
        {
            // ARRANGE
            var pokemon = new PokemonDTO()
            {
                Id         = Guid.Parse("8372c3f3-8281-4c21-8d0f-8830817bc2fb"),
                Name       = "",
                Avatar     = "Edipus",
                Generation = 2,
                Height     = 100,
                Weight     = 100,
                Type       = PokemonType.Fire
            };

            // ACT

            var loggerValidator = new Mock <ILogger <PokemonValidator> >();

            var validator = new PokemonValidator(loggerValidator.Object);

            // ASSERT
            Assert.Throws <ValidationException>(() => validator.IsValid(pokemon));
        }
Exemple #3
0
        public async Task AddPokemon_Return_NotOk()
        {
            // PokedexEntry not correct
            PokemonDTO testDto = new PokemonDTO()
            {
                Name         = "Vi",
                PokedexEntry = 0,
                Generation   = 0,
                Types        = new List <string> {
                    "Wood"
                },
                Classification = "Village Pokemon",
                EggGroup       = "Minecraft",
                Hp             = 1,
                Attack         = 1,
                Defense        = 1,
                SpAtk          = 1,
                SpDef          = 1,
                Speed          = 1
            };

            await AddPokemon_NotOk(testDto);
        }
Exemple #4
0
        public async Task Add_And_Delete_Pokemon_Ok()
        {
            PokemonDTO pokemonDTO = new PokemonDTO()
            {
                Name         = "tester",
                PokedexEntry = 88,
                Generation   = 88,
                Types        = new List <string> {
                    "Steel"
                },
                Classification = "testing pokemon",
                EggGroup       = "tester",
                Hp             = 1,
                Attack         = 1,
                Defense        = 1,
                SpAtk          = 1,
                SpDef          = 1,
                Speed          = 1
            };

            await AddPokemon_Ok(pokemonDTO);
            await AddPokemon_NotOk(pokemonDTO);
            await DeletePokemon_Ok(pokemonDTO.PokedexEntry, pokemonDTO.Generation);
        }
        public async Task <IActionResult> Update([FromBody] PokemonDTO pokemon, CancellationToken cancellationToken = default)
        {
            await _pokemonService.Update(pokemon, cancellationToken);

            return(Accepted());
        }
 public async Task <IActionResult> Create([FromBody] PokemonDTO pokemon, CancellationToken cancellationToken = default)
 {
     return(Ok(await _pokemonService.Create(pokemon, cancellationToken)));
 }
Exemple #7
0
 public void Update(PokemonDTO pokemon)
 {
     repository.Update(pokemon);
 }
Exemple #8
0
 public void Add(PokemonDTO pokemon)
 {
     repository.Add(pokemon);
 }