I\'m having some difficulty writing some Unit Tests to test a custom ModelBinder that I created. The ModelBinder I\'m trying to Unit Test is the JsonDictionaryModelBinder that I
The culprit is this line:
httpContext.Setup(c => c.Request.RequestType).Returns(
verbs.ToString().ToUpper()
);
This is technically a second Setup
on the Request object, and it is wiping out the original Setup
, even though you're going "past" it in the object hierarchy. I'm not sure if this is a bug in Moq or desired behaviour, I've run into this before as well and haven't gotten around to checking it out.
You can solve it by moving that line to where you're setting up your request above, and setting it up directly, rather than by going through the httpContext. So,
request.Setup(c => c.RequestType).Returns(verbs.ToString().ToUpper());
I also notice that the "var u" that you declare is not being used ;)