jeudi 5 mars 2015

Mock for AspNet.Identity (GetUserId)

I have a web application where I am authenticating users over the extension method GetUserId() of AspNet.Identity.


Now I'm writing unit tests to check the functionality of the controller methods. Therefore I'm creating a Mock object of IIdentity.



var identity = new Mock<IIdentity>();

identity.Setup(id => id.IsAuthenticated).Returns(true);
identity.Setup(id => id.Name).Returns("username");


But how can I set the return value of GetUserId()? Is this even possible?


Aucun commentaire:

Enregistrer un commentaire