zoukankan      html  css  js  c++  java
  • ASP.net MVC Mock Context(上下文)

    ASP.net MVC Mock Context(上下文)

     var fakeContext = new FakeControllerContext(controller, new NameValueCollection(), new NameValueCollection());


              controller.ControllerContext = fakeContext;

                controller.Request.QueryString["s"] = ""


    或:

     var controllerContext = new FakeControllerContext(controller,

                    new RouteData(), "", "", new string[] { }, new NameValueCollection(),

                    new NameValueCollection(), new HttpCookieCollection(), new System.Web.SessionState.SessionStateItemCollection());

                controller.ControllerContext = controllerContext; 

    如果要访问Request[""],则加上:

     var mockRequst = new Mock<HttpRequestBase>();


                mockRequst.ExpectGet(r => r.ServerVariables).Returns(new NameValueCollection());

                mockRequst.ExpectGet(r => r.QueryString).Returns(new NameValueCollection());

                mockRequst.ExpectGet(r => r.Form).Returns(new NameValueCollection());

                mockRequst.ExpectGet(r => r.Cookies).Returns(new HttpCookieCollection());


                var mockHttpContext = new Mock<HttpContextBase>();

                mockHttpContext.ExpectGet(hc => hc.Request).Returns(mockRequst.Object);

                controller.ControllerContext.HttpContext = mockHttpContext.Object;


    namespace MvcFakes 


    在 BFA项目BFA.Presentation.Impl.Test.BuyerCompanyControllerTest.AjaxPartialManagementReturnExpectWhenOnDefault()用到

     下载:MvcFakes.rar

  • 相关阅读:
    C++ 设计模式 —— 訪问者(Visitor)
    图解IIS配置过程
    JSBridge
    10大H5前端框架,让你开发不愁
    具体解释java中的volatilekeyword
    网速变慢解决方法.Tracert与PathPing(转)
    最快下载速度100Mbps!4G LTE技术全解析
    Windows客户端的JProfiler远程监控Linux上的Tomcat
    Java内存泄露原因详解
    JProfiler 解决 Java 服务器的性能跟踪
  • 原文地址:https://www.cnblogs.com/ycdx2001/p/1429111.html
Copyright © 2011-2022 走看看