Created
February 21, 2018 14:41
-
-
Save shinkathe/9b87f7a2d6604b93c908bd3e3dcf93b7 to your computer and use it in GitHub Desktop.
Test should run it's own version of an executable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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