Pokespearean/Pokespearean.Tests/ControllerTests/PokemonControllerTests.cs

53 lines
1.8 KiB
C#

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);
}
}
}