单元测试解决HttpContext的问题
2015-06-05 21:44 -夜 阅读(405) 评论(0) 编辑 收藏 举报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; } }
版权声明:本文为博主原创文章,未经博主允许不得转载。