jeudi 15 septembre 2016

How do I verify that an action is raised when calling a method (unit testing with Moq)

I would like to verify that when AuthenticateUserAsync() (which has a return type of void) is called that the appropriate action is raised.

Here my current approach:

var mock = new Mock<ILoginPresenter>();
mock.Setup(x => x.AuthenticateUserAsync(username, password))
    .Raises(x => x.UserPassesAuthentication += null, new LoginEventArgs(thing));

The problem is that when this test runs, I get an error:

Could not locate event for attach or detach method Void set_UserPassesAuthentication(System.Action`1[Common.View.LoginEventArgs]).

It seems like I'm having issues with .Raises call on an action instead of an event.

Any suggestions?

Aucun commentaire:

Enregistrer un commentaire