public void UnitTest_VerifyPokemonDTO() { List <string> listTyping = new List <string>() { "Grass", "Fire", "Water" }; var testDto = new PokemonDTO() { Name = "Villager", PokedexEntry = 111, Generation = 111, Types = new List <string> { "Grass" }, Classification = "Village Pokemon", EggGroup = "Minecraft", Hp = 1, Attack = 1, Defense = 1, SpAtk = 1, SpDef = 1, Speed = 1 }; var result = PokemonHelper.VerifyPokemonDTO(testDto, listTyping); Assert.Equal(true, result.Item1); testDto.Types = new List <string>() { "Dirt" }; result = PokemonHelper.VerifyPokemonDTO(testDto, listTyping); Assert.NotEqual(true, result.Item1); }
public async Task <Tuple <bool, string> > VerifyPokemonDTO(PokemonDTO pokemonDTO) { // Verify if values are correct var listTypes = await _typeRepository.GetTypings_List(); return(PokemonHelper.VerifyPokemonDTO(pokemonDTO, listTypes)); }
public async Task <ActionResult <Pokemon> > AddPokemon(PokemonDTO pokemonDTO) { try{ // Clean + verify pokemonDTO = PokemonHelper.CleanupPokemonDTO(pokemonDTO); var verify = await _pokemonService.VerifyPokemonDTO(pokemonDTO); if (verify.Item1 == false) { return(new BadRequestObjectResult($"The provided values cannot be used to create a Pokemon - {verify.Item2}")); } // Add pokemon var result = await _pokemonService.AddPokemon(pokemonDTO); if (result == null) { return(new BadRequestObjectResult("Pokemon with given entry and generation already exists in database")); } _logger.LogInformation($"Pokemon was added - {result}"); return(new OkObjectResult(result)); } catch (Exception ex) { _logger.LogWarning($"Warning {ex.Message}"); return(new StatusCodeResult(500)); } }
public IActionResult Create(CreatePokemonViewModel createPokemonViewModel, ICollection <IFormFile> files) { if (PokemonHelper.ProcessImages(files, createPokemonViewModel.pokemon, _context, _environment, ModelState).Result) { return(RedirectToAction("Index")); } else { return(View()); } }
public Pokemon(int id, string name, PokemonType firstPokemonType, PokemonType secondPokemonType = PokemonType.None, LegendaryType legendaryType = LegendaryType.None, bool hasFemale = false) : base(id, name, PokemonHelper.GetGenerationTypeByID(id), firstPokemonType, secondPokemonType) { LegendaryType = legendaryType; Sprite = PokemonIconPool.GetPokemonSprite(ID, string.Empty); ShinySprite = PokemonIconPool.GetPokemonSprite(ID, string.Empty, true); if (hasFemale) { Female = new FemaleMon(this); } }
private async Task AddPokemon_Ok(PokemonDTO pokemonDTO) { string json = JsonConvert.SerializeObject(pokemonDTO); StringContent contentSend = new StringContent(json, Encoding.UTF8, "application/json"); var response = await Client.PostAsync("/api/pokemon", contentSend); response.StatusCode.Should().Be(HttpStatusCode.OK); pokemonDTO = PokemonHelper.CleanupPokemonDTO(pokemonDTO); var contentReceived = await response.Content.ReadAsStringAsync(); var body = JsonConvert.DeserializeObject <Pokemon>(contentReceived); Assert.NotNull(body); Assert.Equal(pokemonDTO.Name, body.Name); Assert.Equal(pokemonDTO.PokedexEntry, body.PokedexEntry); Assert.Equal(pokemonDTO.Generation, body.Generation); }
public void UnitTest_CleanupPokemonDTO() { var testDto = new PokemonDTO() { Name = "Villager #27", Types = new List <string> { "Gr ass " }, EggGroup = "Mine craft ", PokedexEntry = 111, Generation = 111, Classification = "Village Pokemon", Hp = 1, Attack = 1, Defense = 1, SpAtk = 1, SpDef = 1, Speed = 1 }; var result = PokemonHelper.CleanupPokemonDTO(testDto); Assert.Equal("Villager#27", result.Name); Assert.Equal("Minecraft", result.EggGroup); Assert.Equal(new List <string> { "Grass" }, result.Types); }
public IActionResult Edit( int id, [Bind("ID,BaseAttack,BaseDefense,BaseSpecialAttack,BaseHitpoints,BaseSpecialDefense,BaseSpeed,Harvestables,Description,IsInMod,Name,PokedexNumber,tamingType")] Pokemon pokemon, ICollection <IFormFile> files) { if (id != pokemon.ID) { return(NotFound()); } try { if (PokemonHelper.ProcessImages(files, pokemon, _context, _environment, ModelState).Result) { return(RedirectToAction("Index")); } else { return(View(pokemon)); } //_context.Update(pokemon); //await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PokemonExists(pokemon.ID)) { return(NotFound()); } else { throw; } } //return View(pokemon); }
public async Task DiscoverPokemonAsync(EduardoContext context) { int roll = new Random().Next(0, _pokemonData.PokemonCount); IMessage waitingMessage = await context.Channel.SendMessageAsync($"{Format.Bold(context.User.Username)} is looking for a Pokemon..."); Pokemon pokemonRoll = await PokemonHelper.GetPokemonFromApiAsync(roll + 1); await waitingMessage.DeleteAsync(); if (pokemonRoll.Id != 0) { using Stream stream = await NetworkHelper.GetStreamAsync(pokemonRoll.Sprites.FrontDefaultSpriteUrl); await context.Channel.SendFileAsync(stream, $"{pokemonRoll.Name}.png", $"{Format.Bold(context.User.Username)} has found a wild {Format.Bold(pokemonRoll.Name.UpperFirstChar())}!"); await _pokemonRepository.AddPokemonAsync((long)context.Message.Author.Id, (long)((context.Message.Channel as SocketGuildChannel)?.Guild.Id ?? 0), pokemonRoll); } else { await Logger.Log($"Error fetching Pokemon with id {roll}", LogSeverity.Error); } }