更新时间:2023-02-17 07:44:59
您可以通过返回的对象转换为相应的类,而不是使用其基类(这是默认返回)测试
You can test by casting the returned object to the appropriate class, instead of using their base class (which is returned by default)
例如,要测试默认的的AccountController
你会这样是这样的:
For example, to test the default AccountController
you'd so something like this:
var controller = new AccountController();
var result = controller.LogOn() as ViewResult;
var model = result.Model as LogOnModel;
Assert.IsTrue(model.RememberMe); // assuming you "pre-populated" enabled the checkbox
检查返回的对象充满了正确的数据似乎并没有不自然对我来说,还是你的意思是不同的?
Checking if the returned object is filled with the right data does not seem "unnatural" to me, or did you meant it differently?