Estou utilizando Xunit
para realizar meus testes, estou tentando acessar minha CampeonatosController
, consequentemente tenho que passar o valor mostrado na imagem abaixo como parâmetro, mas estou recebendo o erro abaixo.
Saberiam me auxiliar.
Minha classe de teste:
public class CampeonatoTest
{
private const string IdReturnsOk = "2021";
private const string IdNotFound = "XXXX";
private readonly CampeonatosController _campeonato;
private readonly ICompetitionService _competitionManager;
public CampeonatoTest(
CompetitionService competitionManager)
{
_competitionManager = competitionManager;
_campeonato = new CampeonatosController(_competitionManager);
}
[Fact]
public async Task Campeonato_GetById_ValuesReturnsOkResponse()
{
var response = await _campeonato.Get(IdReturnsOk);
var objectResponse = response as ObjectResult;
Assert.Equal(200, objectResponse.StatusCode);
}
[Fact]
public async Task Campeonato_GetById_ReturnsNotFoundResponse()
{
var response = await _campeonato.Get(IdNotFound);
var objectResponse = response as ObjectResult;
Assert.Equal(404, objectResponse.StatusCode);
}
}
E aqui está minha Controller:
public class CampeonatosController : ControllerBase
{
private readonly ICompetitionService _competitionManager;
public CampeonatosController(
CompetitionService competitionManager)
{
_competitionManager = competitionManager;
}
// GET api/campeonatos/5
[HttpGet("{id}")]
public async Task<IActionResult> Get(string id)
{
HttpResponseMessage respToken = await _competitionManager.GetIdCompetitionAsync(id);
string conteudo = respToken.Content.ReadAsStringAsync().Result;
if (respToken.StatusCode == HttpStatusCode.OK)
{
return Ok(conteudo);
}
else
{
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
}