My application is an ASP.NET Core 1.0 Web API.
How do I test a controller which is decorated with the Authorize
attribute?
For example, with this controller and test method:
[TestMethod]
public void GetSomeDataTest()
{
var controller = new MyController();
Assert.AreEqual(controller.GetSomeData(), "Test");
}
[Authorize]
public ActionResult GetSomeData()
{
return this.Content("Test");
}
This is just an example code to make it possible for you guys to answer. I am actually invoking the Controller
via a TestServer
object.
This has already been asked but the accepted answer doesn't work anymore. Any suggestions how I could "fake" the users' authenticity?