lundi 1 février 2016

Trying to mock IAuthorizationRequirement in asp.net5 vNext

I have the following code setup in my test constructor

public TestMyController()
{
    var mockMyService = new Mock<IMyService>();
    var mockAuthorizationService = new Mock<IAuthorizationService>();
    var mockAuthorizationRequirement = new Mock<IAuthorizationRequirement>();
    mockAuthorizationService.Setup(e => e.AuthorizeAsync(It.IsAny<ClaimsPrincipal>(), It.IsAny<object>(), mockAuthorizationRequirement.Object))
        .ReturnsAsync(true);

    _controller = new MyController(mockMyService.Object, mockAuthorizationService.Object);
}

But everytime the code hits the link to setup the authorizationService AuthorizeAsync method, code seems to throw this exception

Result Message: Expression references a method that does not belong to the mocked object: e => e.AuthorizeAsync(It.IsAny(), It.IsAny(), .mockAuthorizationRequirement.Object)

But this method does exist, else it wouldnt compile??

Whats going on?

Aucun commentaire:

Enregistrer un commentaire