我编写了这个小函数来通过 ID 获取用户电子邮件:
public string GetUserEmailByID(int UserID)
{
string email = "";
var query = (
from c in dbContext.Users
where (c.ID == UserID)
select new
{
email = c.Email,
}
);
return email;
// return query.ToString();
}
然后我为它写了这个测试:
[Test]
public void ShouldGetUserEmailByUserIDVerifyItIsCorrect()
{
Assert.AreEqual("useremail@test.com", userRepository.GetUserEmailByID(4));
}
测试失败,因为它期待“useremail@test.com”,但它是 string.empty。
我究竟做错了什么?