本文整理汇总了C#中System.Web.Routing.RequestContext.Stub方法的典型用法代码示例。如果您正苦于以下问题:C# RequestContext.Stub方法的具体用法?C# RequestContext.Stub怎么用?C# RequestContext.Stub使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Routing.RequestContext
的用法示例。
在下文中一共展示了RequestContext.Stub方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateContext
/// <summary>
/// Mocks the http context to test against
/// </summary>
/// <param name="fullUrl"></param>
/// <param name="routeData"></param>
/// <returns></returns>
private void CreateContext(Uri fullUrl, RouteData routeData = null)
{
//Request context
RequestContext = MockRepository.GenerateMock<RequestContext>();
//Request
var request = MockRepository.GenerateMock<HttpRequestBase>();
request.Stub(x => x.AppRelativeCurrentExecutionFilePath).Return("~" + fullUrl.AbsolutePath);
request.Stub(x => x.PathInfo).Return(string.Empty);
request.Stub(x => x.RawUrl).Return(VirtualPathUtility.ToAbsolute("~" + fullUrl.AbsolutePath, "/"));
request.Stub(x => x.RequestContext).Return(RequestContext);
request.Stub(x => x.Url).Return(fullUrl);
request.Stub(x => x.ApplicationPath).Return("/");
request.Stub(x => x.Cookies).Return(new HttpCookieCollection());
//Cache
var cache = MockRepository.GenerateMock<HttpCachePolicyBase>();
//Response
//var response = new FakeHttpResponse();
var response = MockRepository.GenerateMock<HttpResponseBase>();
response.Stub(x => x.ApplyAppPathModifier(null)).IgnoreArguments().Do(new Func<string, string>(appPath => appPath));
response.Stub(x => x.Cache).Return(cache);
//Server
var server = MockRepository.GenerateStub<HttpServerUtilityBase>();
server.Stub(x => x.MapPath(Arg<string>.Is.Anything)).Return(Environment.CurrentDirectory);
//HTTP Context
HttpContext = MockRepository.GenerateMock<HttpContextBase>();
HttpContext.Stub(x => x.Cache).Return(HttpRuntime.Cache);
HttpContext.Stub(x => x.Items).Return(new Dictionary<object, object>());
HttpContext.Stub(x => x.Request).Return(request);
HttpContext.Stub(x => x.Server).Return(server);
HttpContext.Stub(x => x.Response).Return(response);
RequestContext.Stub(x => x.HttpContext).Return(HttpContext);
if (routeData != null)
{
RequestContext.Stub(x => x.RouteData).Return(routeData);
}
}