Headless.IntegrationTests.IisExpress.Start C# (CSharp) Method

Start() public method

Starts IIS Express using the specified directory path and port.
public Start ( string directoryPath, int port, Uri address ) : void
directoryPath string /// The directory path. ///
port int /// The port. ///
address System.Uri /// The address. ///
return void
        public void Start(string directoryPath, int port, Uri address)
        {
            if (_process != null)
            {
                throw new InvalidOperationException("The IISExpress process is already running.");
            }

            if (address != null)
            {
                try
                {
                    var request = (HttpWebRequest)WebRequest.Create(address);
                    var webResponse = (HttpWebResponse)request.GetResponse();

                    if (webResponse.StatusCode == HttpStatusCode.OK)
                    {
                        return;
                    }
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex);
                }
            }

            var iisExpressPath = DetermineIisExpressPath();
            var arguments = string.Format(CultureInfo.InvariantCulture, "/path:\"{0}\" /port:{1}", directoryPath, port);

            var info = new ProcessStartInfo(iisExpressPath)
            {
                WindowStyle = ProcessWindowStyle.Hidden,
                ErrorDialog = true,
                LoadUserProfile = true,
                CreateNoWindow = false,
                UseShellExecute = false,
                Arguments = arguments
            };

            var startThread = new Thread(() => StartIisExpress(info))
            {
                IsBackground = true
            };

            startThread.Start();
        }

Usage Example

示例#1
0
        public static void AssemblyInitialize(TestContext context)
        {
            var solutionDirectory = context.FindSolutionDirectory();
            var projectDirectory  = Path.Combine(solutionDirectory, "Headless.DemoSite");
            var address           = Config.BaseWebAddress;

            _iisExpress = new IisExpress();

            _iisExpress.Start(projectDirectory, address.Port, address);
        }
All Usage Examples Of Headless.IntegrationTests.IisExpress::Start