开发者

fake httpcontext using Moq framework

I am following the Scott hanselman's blog

but here i am getting httpcontext.current 开发者_如何学JAVAas null. Sometime back i do remember that i wrote some code to fake Httpcontext.current. but unfortunately i dont have the code with me.

How can i fake do this???

I am using Nunit.


This is how you would do it with Moq:

var url = "~/sample/url";

var mockHttpContext = new Mock<HttpContextBase>();
var mockRequest = new Mock<HttpRequestBase>();
mockHttpContext.Setup(x => x.Request).Returns(mockRequest.Object);
mockRequest.Setup(x => x.AppRelativeCurrentExecutionFilePath).Returns(url);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜