Reorganizing the structure of the project, adding unit testing, adding PokemonService and ShakespeareService.

This commit is contained in:
thepra committed 2020-11-22 18:38:59 +01:00
1 parent 6c5d77d696
commit d47641ccb4
26 files changed
+353 -86

No files matched your search

@@ -0,0 +1,52 @@
using Microsoft.AspNetCore.Mvc;
using Pokespearean.Controllers;
using Pokespearean.Models.Generic;
using Pokespearean.Models.Pokemon;
using Pokespearean.Services;
using System.Threading.Tasks;
using Xunit;
namespace Pokespearean.Tests
{
public class PokemonControllerTests
{
private readonly IPokemonService PokemonService;
private readonly IShakespeareService ShakespeareService;
public PokemonControllerTests(IPokemonService pokemonService, IShakespeareService shakespeareService)
{
PokemonService = pokemonService;
ShakespeareService = shakespeareService;
}
[Theory]
[InlineData("charizard")]
public async Task GetTest(string pokemonName)
{
var controller = new PokemonController(PokemonService, ShakespeareService);
Assert.NotNull(controller);
var result = await controller.Get(pokemonName);
Assert.NotNull(result);
Assert.IsType<OkObjectResult>(result);
var okResult = result as OkObjectResult;
Assert.IsType<PokeResult>(okResult.Value);
var pokemon = okResult.Value as PokeResult;
Assert.Equal("charizard", pokemon.Name);
Assert.Equal("Charizard flies 'round the sky in search of powerful opponents. 't breathes fire of such most wondrous heat yond 't melts aught. However, 't nev'r turns its fiery breath on any opponent weaker than itself.",
pokemon.Description);
}
[Theory]
[InlineData("amIaPokemon?")]
public async Task GetWithWrongPokemonTest(string pokemonName)
{
var controller = new PokemonController(PokemonService, ShakespeareService);
Assert.NotNull(controller);
var result = await controller.Get(pokemonName);
Assert.NotNull(result);
Assert.IsType<BadRequestObjectResult>(result);
var badRequestResult = result as BadRequestObjectResult;
Assert.IsType<WebResult>(badRequestResult.Value);
}
}
}