I followed code sample in Steve Sanderson's MVC3 book, there is a piece of ControlContext mock code there I can setup form and query string values.
In order to support TryUpdateModel in unit test I made some change to the code, for example I have changed data type of formValues to FormCollection formValues
and I added following codes to make it work:
// form Values values setup
this.Request.Setup(x => x.Form).Returns(formValues);
// wire up form with value provider
if (formValues != null)
{
onController.ValueProvider = formValues.ToValueProvider();
}
Meanwhile I would like to do the same thing to querystring collection, but could not find equivalent class to support such a function.
Who has any idea what shall I do to query string?
Eventually, this is my solution