我有以下用于测试控制器的测试方法。
[TestMethod()]
public void ResetTest()
{
var target = new Mock<PROJECT.Reset.Controllers.ResetController>();
//var target = new PROJECT.Reset.Controllers.ResetController();
FormCollection form = new FormCollection();
form.Set("username","domain\\username");
form.Set("password","testpass123");
form.Set("confirmpassword","testpass123");
ViewResult expected = new ViewResult();
expected.ViewName = "Reset";
expected.ViewData.Model = rm;
ActionResult action = target.Object.;
action = target.Object.Reset(form);
ViewResult actual = (ViewResult)action;
Assert.AreEqual(expected, actual);
}
如果我使用:
var target = new Mock<PROJECT.Reset.Controllers.ResetController>();
然后该操作被评估为空。如果我将其更改为未注释的代码行下方,则正在设置操作。任何想法可能导致这种行为?