vendredi 4 mars 2016

Handle IActionResult in MVC6

I build my first mvc6 api with :

http://ift.tt/1WZga8k

I wanted to write test for it now but how can I cast a IActionResult which returns a JSON string to an Model(e.g User)

I get a error which says:

Cannot Convert IAction result to User ...

[HttpGet("{}")]
public IActionResult getUser()
{
  Benutzer benutzerData = _context.benutzer.FirstOrDefault<User>();

  return new ObjectResult(benutzerData);
}

and in my Test class :

  Benutzer user = _controller.getUser();

Aucun commentaire:

Enregistrer un commentaire