You can use the Callback
method (see also in the Moq quickstart Callbacks section) to configure a callback which gets called with the original arguments of the mocked method call (AuthoriseUser
) so you can call your onSuccess
and onFailure
callbacks there:
var moq = new Mock<IMyService>();
moq.Setup(m => m.AuthoriseUser(It.IsAny<AuthDetails>(),
It.IsAny<Action<AuthResult>>(),
It.IsAny<Action<AuthResult>>()))
.Callback<AuthDetails, Action<AuthResult>, Action<AuthResult>>(
(loginDetails, onSuccess, onFailure) =>
{
onSuccess(new AuthResult()); // fire onSuccess
onFailure(new AuthResult()); // fire onFailure
});