Domanda

I am trying to access a text file in asp.net mvc3 test project, the common way I know to access it is through HttpContext class like this

HttpContext.Current.Server.MapPath("Temp.txt");

But it returns "Current" as null!

After a little search I found few reasons of Current being null, in my case it is I guess using a router handler to route requests.

But not getting the way to do it for my case.

Can anyone help me on that?

È stato utile?

Soluzione

HttpContext is not available on test context, only on web enviroment. You need an HttpContext stub. Avoid this direct dependence.

http://vkreynin.wordpress.com/2009/03/23/stub-htttpcontext/

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top