首页 > Web开发 > 详细

httpcontext in asp.net unit test

时间:2014-01-24 17:28:51      阅读:398      评论:0      收藏:0      [点我收藏+]

 

bubuko.com,布布扣
        [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);
        }
bubuko.com,布布扣

Using above code, there is a probem that the unit test method can‘t be debug, the break point will never be hitted.

 

 

bubuko.com,布布扣
        [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(10 * 1000);
//attach the web server process when it launched
            var url = HttpContext.Current.Request.Url;
            var root = HttpContext.Current.Server.MapPath("~/");
            Assert.AreNotEqual(url, null);
        }
bubuko.com,布布扣

 

 

 

 

 

 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

原文:http://www.cnblogs.com/zyip/p/3532033.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!