在我的应用我有我在Global.asax设置为DefaultBinder自定义模型绑定:单元测试自定义模型绑定控制器
ModelBinders.Binders.DefaultBinder = new XLDataAnnotationsModelBinder();
当编写单元测试控制器我需要确保控制器使用自定义模型绑定器,但我不知道如何做到这一点。
我的测试是这样的:
[Test]
public void Details_Post_Action_Fails_To_Change_Email_Address_With_Duplicate()
{
// Setup
var controller = new AccountController();
controller.SetFakeControllerContext();
var param = Customer.Load(30005);
param.EmailAddress = "[email protected]";
// Test
var result = controller.Details(param);
// Assert
Assert.IsTrue(result is ViewResult); // will be ViewResult if failed....
Assert.IsFalse(((ViewResult)result).ViewData.ModelState.IsValid);
}
有了这个单元测试控制器结束了使用DefaultModelBinder。我可以在此测试中添加什么来确保控制器使用自定义模型联编程序?
出现Hanselman的链接是什么我要找的,所以我标记为答案。我没有+1,因为实际的答案不是在stackoverflow(意思是说,如果hansleman的网站由于某种原因失败,这个答案没有价值)。 – 2009-11-11 19:17:14