我的.Net web api端点之一返回以下structre
的JSON对象 public class UserModel
{
public int StudentID { get; set; }
public int ClassID { get; set; }
public string ClassName { get; set; }
public int TestLevelID { get; set; }
public string Firstname { get; set; }
public string Lastname { get; set; }
public string Email { get; set; }
public int? Active { get; set; }
public string Displayname { get
{
return Firstname + " " + Lastname;
}
}
public List<TestSummary> CourseSummary { get; set; }
}
public class TestSummary
{
public string Coursename { get; set; }
public int Progressvalue { get; set; }
}
如何以检查所有属性的方式实现单元测试方法是否正确?必填字段包含非空数据,可选字段至少包含空
[TestMethod]
public void GetStudent()
{
var service = new StudentDbHandler();
var students = service.GetStudents(1).ToList();
bool _exists = false;
if (students.Count > 0)
{
_exists = true;
}
Assert.IsTrue(_exists);
//now checls first name is not null
Assert.IsNotNull(students.FirstOrDefault().Firstname);
}
我应该为所有属性做这件事还是更容易的方式