views:

174

answers:

1

I just got my first Unit Test project working, and immediately ran into some problems. One of the nice details about the Unit Testing concept that were pointed out to me was that I won't have to mock up http-contexts or such in order to test my application.

However, I have made use of the Request.IsMvcAjaxRequest() check in my controllers in order to determine what to return to the browser depending on whether the request was made with AJAX or not. When I run the unit tests, I get a System.ArgumentNullException on Request...

How do I work around this?

+2  A: 

You will have to mock ControllerContext.

See http://weblogs.asp.net/scottgu/archive/2009/01/27/asp-net-mvc-1-0-release-candidate-now-available.aspx

liammclennan
There's a lot of good stuff in that article, so I'll need to spend some time going through it... But I found an instruction explicitly for this problem, so I know it'll work. Thanks! =)
Tomas Lycken