惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Last Watchdog
The Last Watchdog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Secure Thoughts
MongoDB | Blog
MongoDB | Blog
博客园 - Franky
T
Tor Project blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Google DeepMind News
Google DeepMind News
L
LINUX DO - 最新话题
博客园_首页
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Vercel News
Vercel News
Last Week in AI
Last Week in AI
月光博客
月光博客
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
博客园 - 叶小钗
NISL@THU
NISL@THU
C
Check Point Blog
K
Kaspersky official blog
N
News and Events Feed by Topic
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
A
Arctic Wolf
T
Threatpost
GbyAI
GbyAI
L
LINUX DO - 热门话题
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy & Cybersecurity Law Blog
N
News and Events Feed by Topic
Scott Helme
Scott Helme
P
Privacy International News Feed
The Register - Security
The Register - Security
G
GRAHAM CLULEY
Recorded Future
Recorded Future
Apple Machine Learning Research
Apple Machine Learning Research
C
Cybersecurity and Infrastructure Security Agency CISA
B
Blog
Project Zero
Project Zero
Cyberwarzone
Cyberwarzone
Webroot Blog
Webroot Blog
Microsoft Security Blog
Microsoft Security Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
D
DataBreaches.Net
J
Java Code Geeks
AWS News Blog
AWS News Blog
Help Net Security
Help Net Security
Engineering at Meta
Engineering at Meta
M
MIT News - Artificial intelligence
T
Threat Research - Cisco Blogs
Google DeepMind News
Google DeepMind News

博客园 - 观无明

IE9 + django开发版WEB服务器 不响应或Socket报错 google chrome 下django用户登录失败的问题 django 开发多语言网站 不愁男女比例不协调 Word文件如源码一样也可比较和合并 python 的字符编码和中文处理 - 观无明 - 博客园 djang 测试心得 my django development environment (virtualenv+pip+django) nginx+fastcgi+django实践笔记 django 开发 - 小心模板文件的编码格式(utf-8) 汉王电子书D20使用笔记 使用south实现Django的数据库升级迁移 VIM 笔记 (for python ) 在Windows上使用Linux命令 cygwin 仍有人在真心关注这灾难 CruiseControl中应用NCover和NCoverExplore Resharper封装(Encapsulate)域Field为属性Property的命名问题 数据库开发的持续集成 - CruiseControl.Net的项目配置 数据库开发的持续集成 - Liquibase的简介和应用
CruiseControl中使用NUnit中测试WEB服务
观无明 · 2008-07-18 · via 博客园 - 观无明

我的项目需要在CruiseControl中自动测试WEB服务,测试需满足下列条件:
* 不依赖于IIS
* 不对WebService做部署,直接在其CC编译的生成目录中运行WEB服务

如果满足以上需求,当然也可以使用相同方式在VS和CC里测试网页。

在网上找到了SCOTT的文章NUnit Unit Testing of ASP.NET Pages, Base Classes, Controls and other widgetry using Cassini (ASP.NET Web Matrix/Visual Studio Web Developer),使用Cassini来做果然方便。

自己写了个帮助类(见页尾),然后这样使用(在

TestFixtureSetUp中运行Cassini,返回其服务地址给测试使用)

        [TestFixtureSetUp]
        
public void Init()
        
{
            _cassni 
= new CassiniHelper();
            _cassni.Start();
            
//你可如此获得Cassini运行起来的WEB服务地址
            
//config.CurrentServiceEntryUrl = _cassni.WebServerUrl;
        }


        [TestFixtureTearDown]
        
public void FixtureTearDown()
        
{
            _cassni.Close();
        }

  • CassiniHelper

        internal class CassiniHelper
        
    {
            
    private int _webServerPort = 26610;
            
    private Server _webServer;
            
    private readonly string _webServerVDir = "/ws";
            
    private string _workingPath;
            
    private string _webServerUrl;
            
    private string _abstractPathFromTestToWebService = @"..\..\..\WebService";

            
    public CassiniHelper()
            
    {
                SetWebServerUrl();
            }


            
    public int WebServerPort
            
    {
                
    get return _webServerPort; }
                
    set 
                

                    _webServerPort 
    = value;
                    SetWebServerUrl(); 
                }

            }


            
    public string WebServerUrl
            
    {
                
    get return _webServerUrl; }
                
    set { _webServerUrl = value; }
            }


            
    /// <summary>
            
    /// 从测试案例程序集所在目录到WEBServer所在目录的相对路径
            
    /// </summary>

            public string AbstractPathFromTestToWebService
            
    {
                
    get return _abstractPathFromTestToWebService; }
                
    set { _abstractPathFromTestToWebService = value; }
            }


            
    /// <summary>
            
    /// WEB服务的虚拟路径
            
    /// </summary>

            public string WebServerVDir
            
    {
                
    get return _webServerVDir; }
            }


            
    public void Start()
            
    {
                
    if(!Directory.Exists(_workingPath))
                    
    throw new DirectoryNotFoundException(_workingPath);

                _webServer 
    = new Server(_webServerPort, WebServerVDir, _workingPath);
                _webServer.Start();
            }


            
    public void Close()
            
    {
                
    try
                
    {
                    
    if (_webServer != null)
                    
    {
                        _webServer.Stop();
                        _webServer 
    = null;
                    }

                }

                
    catch { }
            }


            
    private void SetWebServerUrl()
            
    {
                
    string currentPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                DirectoryInfo dinfo 
    = new DirectoryInfo(Path.Combine(currentPath, _abstractPathFromTestToWebService));
                _workingPath 
    = dinfo.FullName;

                
    //拷贝Cassini.dll到web服务的bin目录下
                string cassini = "Cassini.dll";
                File.Copy(Path.Combine(currentPath, cassini), Path.Combine(Path.Combine(_workingPath,
    "bin"),cassini));

                _webServerUrl 
    = String.Format("http://localhost:{0}{1}", _webServerPort, WebServerVDir);
            }

        }