我正在使用Moq在C#中进行单元测试,并希望在下面的类中添加一些假数据。
public class UserResponse
{
public IEnumerable<usertab> userlist{get;set;}
public string Name {get;set;}
public string state {get;set;}
public string country {get;set}
}
public class usertab
{
public string tname {get;set;}
public string fname {get;set;}
}
如果以下代码与IEnumerable
伪造一个类是正确的,请纠正我 var userdata = new usertab[]{
new usertab{tName="Employee",fName="abc"},
new usertab{tName="Employee",fName="xyz"},
};
答案 0 :(得分:3)
嗯,你根本就不是“假装”它 - 你只是使用数组作为实现。这样做是没有错的 - 我个人喜欢在测试中使用真实代码,只要: