Skip to content

Instantly share code, notes, and snippets.

@shinkathe
Created February 21, 2018 14:41
Show Gist options
  • Save shinkathe/9b87f7a2d6604b93c908bd3e3dcf93b7 to your computer and use it in GitHub Desktop.
Save shinkathe/9b87f7a2d6604b93c908bd3e3dcf93b7 to your computer and use it in GitHub Desktop.
Test should run it's own version of an executable
public class ExecutableFixture : IDisposable
{
private Process _process;
private bool _isDevelopment;
public ExecutableFixture()
{
var executableRootPath = "../../../../APIProject/bin/Debug/netcoreapp1.1/";
_isDevelopment = File.Exists($"{executableRootPath}APIProject.dll");
if (_isDevelopment) {
_process = new Process
{
StartInfo =
{
WorkingDirectory = executableRootPath,
FileName = "dotnet",
Arguments = "APIProject.dll",
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = true,
}
};
_process.OutputDataReceived += (sender, args) => Log.Information(args.Data);
_process.Start();
_process.BeginOutputReadLine();
}
}
public void Dispose()
{
if (_isDevelopment)
{
_process.Kill();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment