所以,我在测试以下场景时遇到了麻烦:
ICommand LoginCommand;
public LoginViewModel()
{
LoginCommand = new Command(async () => await LoginCommandAction());
}
private async Task LoginCommandAction()
{
var response = await _tokenService.GetToken(_user, _password, token);
}
那是我的视图模型。现在,在我的 ViewModel 测试中,我希望能够execute
在我的 LoginCommand 上调用 an 并等待GetToken 完成,以便我可以断言它的结果。
我试过只打电话,execute()
但测试在电话之前完成。
我也试过:
public async Task TestMethod() => await Task.Run(() => Vm.LoginCommand.Execute(null));
但这也没有用。我相信我必须在我的Action上返回一些东西,但我不确定是什么。