0
我想驗證何時調用AuthenticateUserAsync()(它具有void的返回類型),以引發相應的操作。如何在調用方法時驗證是否引發了操作(使用Moq進行單元測試)
這裏我目前的做法:
var mock = new Mock<ILoginPresenter>();
mock.Setup(x => x.AuthenticateUserAsync(username, password))
.Raises(x => x.UserPassesAuthentication += null, new LoginEventArgs(thing));
的問題是,當這個測試運行,我得到一個錯誤:
Could not locate event for attach or detach method Void set_UserPassesAuthentication(System.Action`1[Common.View.LoginEventArgs]).
好像我在與.Raises問題的呼籲一個行動而不是一個事件。
有什麼建議嗎?
編輯
下面是ILoginPresenter定義:
public interface ILoginPresenter
{
Action<LoginEventArgs> UserPassesAuthentication { get; set; }
Action UserFailedAuthentication { get; set; }
void AuthenticateUserAsync(string user, string password);
bool IsLoginFabVisible(int userTextCount, int passwordTextCount);
}
回你可以顯示'ILoginPresenter' – Nkosi
@Nkosi代碼定義發佈 – kformeck
'.Raises'用於事件。你試圖用一個不起作用的動作來調用它。您需要模擬該操作並在來自'AuthenticateUserAsync'設置的回調中調用它 – Nkosi