This is ASP.NET MVC v1 (not using the v2 yet)
I have a route entry like this:
routes.MapRoute(
"Srp",
"soeg-{searchQuery}/{listingType}",
new { controller = "Srp", action = "Search", listingType = string.Empty },
new { listingType = "privat|forhandler|"}
);
and an action to match it:
public ActionResult Search(QueryParameters queryParameters)
It works perfectly - the mvc framework knows to map the searchQuery and listingType onto the two properties of the QueryParameters object with the same names.
My problem is unit testing. I'm using Mvccontrib project and LOVING the ShouldMapTo method:
[Test]
public void RegisterSrpRoutes_SoegWithKeywordAndValidListingType_ShouldMapCorrectly()
{
var queryParameters = new QueryParameters {SearchQuery = "hest", ListingType = "privat"};
"~/soeg-hest/privat".ShouldMapTo<SrpController>(controller => controller.Search(queryParameters));
}
It doesn't work though! I used to have specific parameters on my action like this:
public ActionResult Search(string searchQuery, string listingType)
which worked (obviously the unittest would try and map to Search with two parameters (strings) instead of this one object.
Does anyone have an idea of how to solve the problem, short of going back to writing all properties as parameters. The mvc automapping of properties rocks, but i'm hoping there is some way i can have mvccontribs testhelper work with that as well.