public ActionResult Post([FromBody] Pokemon pokemon)
        {
            var validator = new PokemonValidator();
            var result    = validator.Validate(pokemon);

            if (ModelState.IsValid)
            {
                pokemonRepository.Add(pokemon);
                return(Ok());
            }
            return(BadRequest(result.Errors));
        }
Exemple #2
0
        public void GivenPokemon_WhenAddAndTryFind_ThenFindsPokemon()
        {
            var sut      = new PokemonRepository();
            var expected = new Pokemon("Foo", "Bar");

            sut.Remove(expected.Name); // Required or else second run fails because of existing db file.

            Assert.IsFalse(sut.TryFind(expected.Name, out var actual));

            sut.Add(expected);
            Assert.IsTrue(sut.TryFind(expected.Name, out actual));
            Assert.AreEqual(expected, actual);
        }
 public void Post(Pokemon p) => _repository.Add(p);