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);
精彩评论