-
-
Save johndowns/6701ac83e18734ac4566bfdc43c41d35 to your computer and use it in GitHub Desktop.
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 FunctionTestFixture : IDisposable | |
{ | |
private readonly Process _funcHostProcess; | |
public int Port { get; } = 7001; | |
public readonly HttpClient Client = new HttpClient(); | |
public FunctionTestFixture() | |
{ | |
var dotnetExePath = Environment.ExpandEnvironmentVariables(ConfigurationHelper.Settings.DotnetExecutablePath); | |
var functionHostPath = Environment.ExpandEnvironmentVariables(ConfigurationHelper.Settings.FunctionHostPath); | |
var functionAppFolder = Path.GetRelativePath(Directory.GetCurrentDirectory(), ConfigurationHelper.Settings.FunctionApplicationPath); | |
_funcHostProcess = new Process | |
{ | |
StartInfo = | |
{ | |
FileName = dotnetExePath, | |
Arguments = $"\"{functionHostPath}\" start -p {Port}", | |
WorkingDirectory = functionAppFolder | |
} | |
}; | |
var success = _funcHostProcess.Start(); | |
if (!success) | |
{ | |
throw new InvalidOperationException("Could not start Azure Functions host."); | |
} | |
Client.BaseAddress = new Uri($"http://localhost:{Port}"); | |
} | |
public virtual void Dispose() | |
{ | |
if (!_funcHostProcess.HasExited) | |
{ | |
_funcHostProcess.Kill(); | |
} | |
_funcHostProcess.Dispose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment