In my application I have a custom model binder that I set to the DefaultBinder in the global.asax:
ModelBinders.Binders.DefaultBinder = new XLDataAnnotationsModelBinder();
When writing unit tests for controllers I need to make sure the controller uses the custom model binder but I don't know how to do this.
My test looks like this:
[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);
}
With this unit test the controller ends up using the DefaultModelBinder. What can I add in this test to ensure the controller uses the custom model binder?