我有一个使用 System.Func 表达式的测试。它应该很简单,但是测试一直失败。
测试:
[TestMethod]
public void GetUser()
{
var username = "john@resilientplc.com";
var user = new User() { UserId = 1, Username = username, Password = "123456789" };
someDataMock.Setup(s => s.GetUser(p => p.UserId == 1)).Returns(user);
var result = userProfileModel.GetUser(user.UserId);
Assert.AreEqual(user, result);
}
实现UserProfileModel:
public User GetUser(long userId)
{
return someDataMock.GetUser(u => u.UserId == UserId);
}
错误:
System.NotSupportedException:不支持的表达式:p =>(p.UserId == 1)
知道我的测试在哪里不正确吗?