title: Unit testing custom model binder in ASP.NET MVC 2
body: <p>I've wrote custom model binder in project, that uses ASP.NET MVC 2. This model binder bind just 2 fields of model:</p>
  
  <pre><code>public class TaskFormBinder : DefaultModelBinder
  {
      protected override void BindProperty(ControllerContext controllerContext,
          ModelBindingContext bindingContext,
          PropertyDescriptor propertyDescriptor)
      {           
          if (propertyDescriptor.Name == "Type")
          {
              var value = bindingContext.ValueProvider.GetValue("Type");
              var typeId = value.ConvertTo(typeof(int));
              TaskType foundedType;
              using (var nhSession = Domain.GetSession())
              {
                  foundedType = nhSession.Get&lt;TaskType&gt;(typeId);
              }
              if (foundedType != null)
              {
                  SetProperty(controllerContext, bindingContext, propertyDescriptor, foundedType);
              }
              else
              {
                  AddModelBindError(bindingContext, propertyDescriptor);
              }
              return;
          }
          if (propertyDescriptor.Name == "Priority")
          { /* Other field binding ... */
              return;
          }
          base.BindProperty(controllerContext, bindingContext, propertyDescriptor);
      }
  }
  </code></pre>
  
  <p>How can i test this model binder using standart VS unit testing? Spent some hours googling, find couple examples (<a href="http://www.hanselman.com/blog/SplittingDateTimeUnitTestingASPNETMVCCustomModelBinders.aspx" rel="nofollow noreferrer">http://www.hanselman.com/blog/SplittingDateTimeUnitTestingASPNETMVCCustomModelBinders.aspx</a>), but this examples is for MVC1, and dont work when using MVC2.</p>
  
  <p>I appreciate your help.</p>