I’m trying to unit test my routes, and I’m starting to hit a problem. Some of the action method parameters won’t be coming from the URL anymore, but instead will be supplied by an action filter, based on this article: http://haacked.com/archive/2010/02/21/manipulating-action-method-parameters.aspx
The problem is that I have a url: /some/path/id which maps to an action method public ViewResult Action(int id, Guid sessionId) where sessionId is being added to the action parmaters by the action filter. There’s now now way that I can see to make this test pass without making Guid a Guid?:
"~/some/path/1".ShouldMapTo<SomeController>(x => x.Action(1, <anyGuid>));
Any ideas?
Well actually there is a way.
If you are using Rhino Mocks (which is bundled by default with
MvcContrib.TestHelper, so you are already implicitly using it):and if you are using Moq:
and if you are using some other mocking framework check the documentation about the syntax that would allow you to specify a parameter constraint that could be anything.