我正在使用WatiN,NUnit和ReSharper在Visual Studio中运行我的ASP.NET单元测试。我想(如果它还没有运行)启动Cassini来运行我的测试。
这可能吗?我该怎么做?
答案 0 :(得分:8)
如果您有兴趣,我刚刚发布了CassiniDev 3.5.1 / 4.0.1测试版,其中包含一个简单的测试夹具示例。
Cassini for Developers and Testers:http://cassinidev.codeplex.com
莫比尔,单词。答案 1 :(得分:2)
以下是一些代码:
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文件的路径。我会把它留给读者练习(我现在已经用硬编码了)。
答案 2 :(得分:1)
Cassini服务器是WebDev.WebServer.EXE。有几个博客显示如何手动启动它。这是一个:
http://www.dotnetjunkies.com/WebLog/saravana/archive/2005/06/18/126143.aspx