启动 ASP.NET 开发 Web 服务器 (Cassini) 作为单元测试设置的一部分?

发布于 2024-07-10 06:11:07 字数 127 浏览 9 评论 0原文

我使用 WatiN、NUnit 和 ReSharper 在 Visual Studio 中运行 ASP.NET 单元测试。 我想(如果它尚未运行)启动 Cassini 来运行我的测试。

这可能吗? 我该怎么做呢?

I'm using WatiN, NUnit and ReSharper to run my ASP.NET unit tests inside Visual Studio. I'd like (if it's not already running) to start Cassini to run my tests against.

Is this possible? How would I do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

明明#如月 2024-07-17 06:11:07

如果您有兴趣,我刚刚发布了 CassiniDev 3.5.1/4.0.1 beta 和一个简单的测试夹具示例。

Cassini 面向开发人员和测试人员:http://cassinidev.codeplex.com

Mo betta,单词。

I just released the CassiniDev 3.5.1/4.0.1 beta with a simple test fixture example if you are interested.

Cassini for Developers and Testers: http://cassinidev.codeplex.com

Mo betta, word.

满身野味 2024-07-17 06:11:07

下面是一些代码:

private static void GetDevelopmentServerVPathAndPortFromProjectFile(
    string csprojFileName,
    out string developmentServerVPath,
    out int developmentServerPort)
{
    XPathDocument doc = new XPathDocument(csprojFileName);
    XPathNavigator navigator = doc.CreateNavigator();

    XmlNamespaceManager manager = new XmlNamespaceManager(navigator.NameTable);
    manager.AddNamespace("msbuild",
        "http://schemas.microsoft.com/developer/msbuild/2003");

    const string xpath = "/msbuild:Project/msbuild:ProjectExtensions/"
                       + "msbuild:VisualStudio/msbuild:FlavorProperties/"
                       + "msbuild:WebProjectProperties";

    XPathNavigator webProjectPropertiesNode =
        navigator.SelectSingleNode(xpath, manager);
    XPathNavigator developmentServerPortNode =
        webProjectPropertiesNode.SelectSingleNode("msbuild:DevelopmentServerPort",
            manager);
    XPathNavigator developmentServerVPathNode =
        webProjectPropertiesNode.SelectSingleNode("msbuild:DevelopmentServerVPath",
            manager);

    developmentServerPort = developmentServerPortNode.ValueAsInt;
    developmentServerVPath = developmentServerVPathNode.Value;
}

private static string GetCommonProgramFilesPath()
{
    string commonProgramFiles =
        Environment.GetEnvironmentVariable("CommonProgramFiles(x86)");
    if (string.IsNullOrEmpty(commonProgramFiles))
    {
        commonProgramFiles =
            Environment.GetEnvironmentVariable("CommonProgramFiles");
    }
    if (string.IsNullOrEmpty(commonProgramFiles))
    {
        commonProgramFiles =
            Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles);
    }
    return commonProgramFiles;
}

private static Process PrepareCassiniProcess(int developmentServerPort,
                                             string projectPhysicalPath,
                                             string developmentServerVPath)
{
    string commonProgramFiles = GetCommonProgramFilesPath();
    string cassiniPath = Path.Combine(commonProgramFiles,
        @"Microsoft Shared\DevServer\9.0\WebDev.WebServer.exe");
    string cassiniArgs = string.Format(
        CultureInfo.InvariantCulture,
        "/port:{0} /nodirlist /path:\"{1}\" /vpath:\"{2}\"",
        developmentServerPort, projectPhysicalPath, developmentServerVPath);

    Process cassiniProcess = new Process();
    cassiniProcess.StartInfo.FileName = cassiniPath;
    cassiniProcess.StartInfo.Arguments = cassiniArgs;
    return cassiniProcess;
}

要使用它,您需要找到正在测试的 Web 项目的 CSPROJ 文件的路径。 我将把它作为练习留给读者(我目前已经对其进行了硬编码)。

Here's some code:

private static void GetDevelopmentServerVPathAndPortFromProjectFile(
    string csprojFileName,
    out string developmentServerVPath,
    out int developmentServerPort)
{
    XPathDocument doc = new XPathDocument(csprojFileName);
    XPathNavigator navigator = doc.CreateNavigator();

    XmlNamespaceManager manager = new XmlNamespaceManager(navigator.NameTable);
    manager.AddNamespace("msbuild",
        "http://schemas.microsoft.com/developer/msbuild/2003");

    const string xpath = "/msbuild:Project/msbuild:ProjectExtensions/"
                       + "msbuild:VisualStudio/msbuild:FlavorProperties/"
                       + "msbuild:WebProjectProperties";

    XPathNavigator webProjectPropertiesNode =
        navigator.SelectSingleNode(xpath, manager);
    XPathNavigator developmentServerPortNode =
        webProjectPropertiesNode.SelectSingleNode("msbuild:DevelopmentServerPort",
            manager);
    XPathNavigator developmentServerVPathNode =
        webProjectPropertiesNode.SelectSingleNode("msbuild:DevelopmentServerVPath",
            manager);

    developmentServerPort = developmentServerPortNode.ValueAsInt;
    developmentServerVPath = developmentServerVPathNode.Value;
}

private static string GetCommonProgramFilesPath()
{
    string commonProgramFiles =
        Environment.GetEnvironmentVariable("CommonProgramFiles(x86)");
    if (string.IsNullOrEmpty(commonProgramFiles))
    {
        commonProgramFiles =
            Environment.GetEnvironmentVariable("CommonProgramFiles");
    }
    if (string.IsNullOrEmpty(commonProgramFiles))
    {
        commonProgramFiles =
            Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles);
    }
    return commonProgramFiles;
}

private static Process PrepareCassiniProcess(int developmentServerPort,
                                             string projectPhysicalPath,
                                             string developmentServerVPath)
{
    string commonProgramFiles = GetCommonProgramFilesPath();
    string cassiniPath = Path.Combine(commonProgramFiles,
        @"Microsoft Shared\DevServer\9.0\WebDev.WebServer.exe");
    string cassiniArgs = string.Format(
        CultureInfo.InvariantCulture,
        "/port:{0} /nodirlist /path:\"{1}\" /vpath:\"{2}\"",
        developmentServerPort, projectPhysicalPath, developmentServerVPath);

    Process cassiniProcess = new Process();
    cassiniProcess.StartInfo.FileName = cassiniPath;
    cassiniProcess.StartInfo.Arguments = cassiniArgs;
    return cassiniProcess;
}

To use it, you need to discover the path to the CSPROJ file of the web project under test. I'll leave that as an exercise for the reader (I've currently got it hard-coded).

破晓 2024-07-17 06:11:07

Cassini 服务器是 WebDev.WebServer.EXE。 有几个博客展示了如何手动启动它。 这是一个:

http://www.dotnetjunkies。 com/WebLog/saravana/archive/2005/06/18/126143.aspx

The Cassini server is WebDev.WebServer.EXE. There are several blogs that show how to start it manually. Here is one:

http://www.dotnetjunkies.com/WebLog/saravana/archive/2005/06/18/126143.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文