开发者

fake httpcontext using Moq framework

开发者 https://www.devze.com 2023-01-30 16:03 出处:网络
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 unfo

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

精彩评论

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

关注公众号