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

推荐订阅源

S
Security @ Cisco Blogs
罗磊的独立博客
宝玉的分享
宝玉的分享
Last Week in AI
Last Week in AI
T
The Blog of Author Tim Ferriss
美团技术团队
T
Tailwind CSS Blog
博客园 - 三生石上(FineUI控件)
博客园 - Franky
G
Google Developers Blog
Jina AI
Jina AI
Stack Overflow Blog
Stack Overflow Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
V
Visual Studio Blog
腾讯CDC
S
SegmentFault 最新的问题
Recent Announcements
Recent Announcements
博客园 - 叶小钗
Microsoft Security Blog
Microsoft Security Blog
雷峰网
雷峰网
L
LangChain Blog
Vercel News
Vercel News
Forbes - Security
Forbes - Security
PCI Perspectives
PCI Perspectives
N
News | PayPal Newsroom
S
Security Affairs
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 司徒正美
J
Java Code Geeks
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Hacker News: Ask HN
Hacker News: Ask HN
Schneier on Security
Schneier on Security
A
About on SuperTechFans
Attack and Defense Labs
Attack and Defense Labs
Google Online Security Blog
Google Online Security Blog
aimingoo的专栏
aimingoo的专栏
MongoDB | Blog
MongoDB | Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
酷 壳 – CoolShell
酷 壳 – CoolShell
Cloudbric
Cloudbric
B
Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
P
Proofpoint News Feed
D
DataBreaches.Net
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
B
Blog RSS Feed
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News and Events Feed by Topic

博客园 - 观无明

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

        }