httpcontext in asp.net unit test
2024-10-18 00:50:39
[TestMethod]
[HostType("ASP.NET")]
[UrlToTest("http://localhost:25153/qq/a.aspx")]
[AspNetDevelopmentServerHost(@"C:\Users\Public\Documents\ooooooo", "/")]
public void Test1()
{
var url = HttpContext.Current.Request.Url;
var root = HttpContext.Current.Server.MapPath("~/");
Assert.AreNotEqual(url, null);
}
Using above code, there is a probem that the unit test method can't be debug, the break point will never be hitted.
[TestMethod]
[HostType("ASP.NET")]
[UrlToTest("http://localhost:25153/qq/a.aspx")]
[AspNetDevelopmentServerHost(@"C:\Users\Public\Documents\ooooooo", "/")]
public void Test1()
{ //System.Diagnostics.Debugger.Break();
System.Threading.Thread.Sleep( * );
//attach the web server process when it launched
var url = HttpContext.Current.Request.Url;
var root = HttpContext.Current.Server.MapPath("~/");
Assert.AreNotEqual(url, null);
}
reference:
http://msdn.microsoft.com/en-us/library/ms243172.aspx
http://www.asp.net/mvc/tutorials/older-versions/unit-testing/creating-unit-tests-for-asp-net-mvc-applications-cs
最新文章
- vijos1404 遭遇战
- 还是this的问题
- LinkedHahsMap和HashMap的比较
- Xamarin开发Android笔记:拍照或相册选取图片角度问题
- sql分页代码
- javascript实现数据结构与算法系列:栈 -- 顺序存储表示和链式表示及示例
- 开放封闭原则(OCP)
- Swift 实现图片转字符画的功能
- 深入了解一下PYTHON中关于SOCKETSERVER的模块-C
- vb combobox 用法问题总结
- stdarg.h头
- SQL-55 分页查询employees表,每5行一页,返回第2页的数据
- 今天在2cto网站看到一个有关try{}catch(){}finally{}语句中含有return的讲解,理解很透彻。
- mac date命令详解
- 初识Python-1
- B2B、B2C、C2C、O2O
- Linux基础知识之用户和用户组以及 Linux 权限管理
- Linux shell (6)
- 【Unity】6.7 向量和Vector3类
- Openstack入门篇(十二)之neutron服务(计算节点)的部署与测试
热门文章
- 动态修改 C 语言函数的实现
- 关于Eclispe插件开发起步(一)
- 使用jQuery获取Bootstrap Switch的值
- css关于宽度
- (原创)openvswitch实验连载1-fedora 17下安装openvswitch
- 关于async和await的一些误区实例详解
- 服务端缓存HttpRuntime.Cache的使用
- ASP.NET笔记之 ListView 与 DropDownList的使用(解决杨中科视频中的问题)
- VBA实现随意输入组合码,查询唯一标识码
- ubuntu下aircrack-ng的wifi破解