zoukankan      html  css  js  c++  java
  • httpcontext in asp.net unit test

            [TestMethod]
            [HostType("ASP.NET")]
            [UrlToTest("http://localhost:25153/qq/a.aspx")]
            [AspNetDevelopmentServerHost(@"C:UsersPublicDocumentsooooooo", "/")]
            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:UsersPublicDocumentsooooooo", "/")]
            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);
            }

     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

  • 相关阅读:
    FullCalendar日历插件说明文档
    Git忽略规则及.gitignore规则不生效的解决办法
    学习git config配置文件
    拼接最长回文串
    Gildong owns a bulgogi restaurant
    前m大的数
    求水洼(dfs)
    循环数组的最大子段和
    求叶子节点
    周期
  • 原文地址:https://www.cnblogs.com/zyip/p/3532033.html
Copyright © 2011-2022 走看看