• 单元测试解决HttpContext的问题


    C#代码

        [TestClass]
        public class UnitTest1
        {
            [TestMethod]
            public void TestMethod1()
            {
                Thread.GetDomain().SetData(".appPath", "c:\inetpub\wwwroot\webapp\");
                Thread.GetDomain().SetData(".appVPath", "/");
                TextWriter tw = new StringWriter();
                String address = "home.myspace.cn";
                HttpWorkerRequest wr = new MyWorkerRequest
                ("default.aspx", "friendId=1300000000", tw, address);
                HttpContext.Current = new HttpContext(wr);
    
    
                UsersController target = new UsersController(); // TODO: Initialize to an appropriate value
                JsonResult actual = target.login();
            }
        }
    
        public class MyWorkerRequest : SimpleWorkerRequest
        {
            private string localAdd = string.Empty;
    
            public MyWorkerRequest(string page, string query, TextWriter output, string address)
                : base(page, query, output)
            {
                this.localAdd = address;
            }
    
            public override string GetLocalAddress()
            {
                return this.localAdd;
            }
        }


    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    Yii2的View中JS代码添加
    Yii2命名规则
    Yii2 Redis的使用
    win7下php5.6安装redis扩展
    Ubuntu安装cuda
    Ubuntu 安装显卡驱动
    TensorFlow 图片resize方法
    anaconda的kernel对jupyter可见
    cuda和显卡驱动版本
    jupyter修改根目录
  • 原文地址:https://www.cnblogs.com/ful1021/p/4804311.html
Copyright © 2020-2023  润新知