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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 观无明

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);
            }

        }