考虑以下代码
public class MyClass
{
public string FirstName { get; set; }
public string SurName { get; set; }
public MyClass GetInfo()
{
//Get data from database
...
return new MyClass(FirstName, SurName);
}
}
我想单元测试GetInfo()
但似乎无法弄清楚如何实际测试它。我是否会创建MyClass
的模拟,然后执行Assert.AreEqual(uinfo.FirstName,"John");
提前感谢您的帮助和支持
答案 0 :(得分:1)
[TestMethod]
public void GetInfo_ClonesAllProperties()
{
// arrange
var myClass = new myClass() { FirstName = "John", SurName = "Smith" };
// act
var clone = myClass.GetInfo();
// assert
Assert.AreEqual(clone.FirstName,"John");
Assert.AreEqual(clone.SurName,"Smith");
}