httpcontext in asp.net unit test
[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
httpcontext in asp.net unit test的更多相关文章
- [转]模拟HttpContext 实现ASP.NET MVC 的单元测试
众所周知 ASP.NET MVC 的一个显著优势即可以很方便的实现单元测试,但在我们测试过程中经常要用到HttpContext,而默认情况下单元测试框架是不提供HttpContext的模拟的,本文通过 ...
- ASP.NET Core 运行原理解剖[4]:进入HttpContext的世界
HttpContext是ASP.NET中的核心对象,每一个请求都会创建一个对应的HttpContext对象,我们的应用程序便是通过HttpContext对象来获取请求信息,最终生成响应,写回到Http ...
- ASP.NET Core [3]:进入HttpContext的世界(笔记)
原文链接:http://www.cnblogs.com/RainingNight/p/httpcontext-in-asp-net-core.html HttpContext是ASP.NET中的核心对 ...
- 【转】ASP.NET Core 2.0中的HttpContext
ASP.NET Core 2.0中的HttpContext相较于ASP.NET Framework有一些变化,这边列出一些之间的区别. 在ASP.NET Framework中的 System. ...
- ASP.NET Core管道深度剖析(3):管道是如何处理HTTP请求的?
我们知道ASP.NET Core请求处理管道由一个服务器和一组有序的中间件组成,所以从总体设计来讲是非常简单的,但是就具体的实现来说,由于其中涉及很多对象的交互,我想很少人能够地把它弄清楚.为了让读者 ...
- 【译】ASP.NET应用程序和页面生命周期
为何翻译此文 一.此文是Code Project社区2010年4月ASP.NET板块的最佳文章,说明了此文的份量: 二.锻炼自己的英文技术文章翻译能力,提高英文技术文档阅读能力: 三.了解掌握ASP. ...
- ASP.NET MVC随想录——漫谈OWIN
什么是OWIN OWIN是Open Web Server Interface for .NET的首字母缩写,他的定义如下: OWIN在.NET Web Servers与Web Application之 ...
- Asp.Net在多线程环境下的状态存储问题
在应用开发中,我们经常需要设置一些上下文(Context)信息,这些上下文信息一般基于当前的会话(Session),比如当前登录用户的个人信息:或者基于当前方法调用栈,比如在同一个调用中涉及的多个层次 ...
- HttpContext.Current 的缺陷
了解ASP.NET的开发人员都知道它有个非常强大的对象 HttpContext,而且为了方便,ASP.NET还为它提供了一个静态属性HttpContext.Current来访问它,今天的博客打算就从H ...
随机推荐
- iOS之Git的使用
1.登录Git账号,创建一个新的仓库
- logstash-input-file 参数说明
参数 close_older close_older: # This has different implications depending on if a file is being tailed ...
- appium +python api 新手
发现一个网址的内容比较好,就转过来了 #默认系统语言对应的Strings.xml文件内的数据. get_app_string() #查找某一个语言环境对应的字符串文件Strings.xml内数据 ...
- 简单的ROT13码编码与解码
ROT13码意思是将字母左移13位.如'A' ↔ 'N', 'B' ↔ 'O','V' ↔ 'I'. 下面实现ROT13码的解码. function rot13(str) { var arr = [] ...
- jQuery mouseover与mouseenter,mouseout与mouseleave的区别
mouseover与mouseenter 不论鼠标指针穿过被选元素或其子元素,都会触发 mouseover 事件. 只有在鼠标指针穿过被选元素时,才会触发 mouseenter 事件. mouseou ...
- scala学习笔记:理解并行集合par
scala> (1 to 5).foreach(println(_)) 1 2 3 4 5 scala> (1 to 5).par.foreach(println(_)) 3 1 4 2 ...
- 使用jsonp跨域请求
一.异步对象,不能实现跨域请求 在站点A中访问站点B的数据: 站点A代码: window.onload = function () { document.getElementById("bt ...
- Open Flash Chart在php中的使用教程
http://www.cnblogs.com/huangcong/archive/2013/01/27/2878650.html 为了画一个漂亮的表格,我从网上找到了OpenFlashChart(of ...
- 命令行创建Android应用,生成签名,对APK包签名并编译运行
一.命令行创建Android应用 android create project -n HelloWorld -t android-22 -p HelloWorld1 -k org.crazyit.he ...
- ajaxError
$(document).ready(function () { $('input:button').click(function() { if($('#fileName').val() == '') ...