如何设置系统.单元测试的类型属性?



我有一个类,它的属性是type。我如何为单元测试设置这个?

示例类:

public class School
{
public string Name { get; set; }
public Type SchoolType { get; set; }
}

我可以模拟Name,但我不确定如何模拟SchoolType属性。

示例测试:

string expectedName = "Richmond";
var expectedType = ???
var school = new School();
school.Name = expectedName;
school.SchoolType = expectedType;
Assert.AreEqual(expectedName, school.Name);
Assert.AreEqual(?, school.SchoolType);

您可以这样做,在这里HighSchool是您想要分配给SchoolType属性的类。

string expectedName = "Richmond";
var expectedType = typeof(HighSchool);
var school = new School();
school.Name = expectedName;
school.SchoolType = expectedType;
Assert.AreEqual(expectedName, school.Name);
Assert.AreEqual(expectedType, school.SchoolType);

相关内容

  • 没有找到相关文章