Skip to content

Instantly share code, notes, and snippets.

@jittuu
Created June 26, 2011 10:47
Show Gist options
  • Save jittuu/1047502 to your computer and use it in GitHub Desktop.
Save jittuu/1047502 to your computer and use it in GitHub Desktop.
private const int PORT_NUMBER = 1852; // the port number to used for SpecFlow testing
[BeforeTestRun()]
public static void StartWebServer()
{
if (ExistsPort())
return;
// settings
string LocalHostUrl = string.Format("http://localhost:{0}", PORT_NUMBER);
string PhysicalPath = Path.GetFullPath(@"..\..\..\Web"); // the path of compiled web app
// create a new process to start the ASP.NET Development Server
Process process = new Process();
/// configure the web server
process.StartInfo.FileName = @"C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\WebDev.WebServer40.EXE";
process.StartInfo.Arguments = string.Format("/port:{0} /path:\"{1}\" /virtual:\"{2}\"", PORT_NUMBER, PhysicalPath, LocalHostUrl);
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
// start the web server
var started = process.Start();
}
private static bool ExistsPort()
{
var ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
return ipGlobalProperties.GetActiveTcpConnections().Any(info => info.LocalEndPoint.Port == PORT_NUMBER);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment