Skip to content

Instantly share code, notes, and snippets.

@DoubleCouponDay
Last active April 28, 2019 23:40
Show Gist options
  • Select an option

  • Save DoubleCouponDay/ba88b685a0c39ece913cba6432f80f8c to your computer and use it in GitHub Desktop.

Select an option

Save DoubleCouponDay/ba88b685a0c39ece913cba6432f80f8c to your computer and use it in GitHub Desktop.
ASPNET 5 debug server
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
using System.Management.Automation;
using System.Windows.Forms;
namespace serversidearchitecture.tests.integration.fast.api
{
public class ApiTestServer : IDisposable
{
const string projectrootpath = @"";
private PowerShell shell;
private IAsyncResult invocation;
public string baselink { get; } = @"http://localhost:8080/";
public bool wasshutdown { get; private set; }
public ApiTestServer()
{
string iisexpresscommand = @" 'C:\Program Files\IIS Express\iisexpress.exe' '/path:" + projectrootpath + "' '/clr:v4.0' ";
try
{
shell = PowerShell.Create(RunspaceMode.NewRunspace)
.AddScript($"& {iisexpresscommand}");
invocation = shell.BeginInvoke();
Thread.Sleep(6000);
}
catch (Exception error)
{
shutdown();
throw;
}
}
void shutdown()
{
if (wasshutdown == false)
{
var processes = Process.GetProcessesByName("iisexpresstray");
foreach (Process item in processes)
{
item.Kill();
}
shell.Dispose();
wasshutdown = true;
}
}
public void Dispose()
{
shutdown();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment