当前位置: 首页>>代码示例>>C#>>正文


C# RequestContext.Stub方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:Joebeazelman,项目名称:rebelcmsxu5,代码行数:53,代码来源:FakeHttpContextFactory.cs


注:本文中的System.Web.Routing.RequestContext.Stub方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。