public AzuriteFixture() { // This is to force newer protocol on machines with older .NET Framework. Otherwise tests don't connect to Azurite with unsigned cert. ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; var azuriteLocation = Environment.GetEnvironmentVariable(AzuriteLocationKey); var defaultPath = Path.Combine(Environment.GetEnvironmentVariable("APPDATA") ?? string.Empty, "npm"); if (string.IsNullOrWhiteSpace(azuriteLocation)) { if (Directory.Exists(defaultPath)) { azuriteLocation = defaultPath; } else { throw new ArgumentException(ErrorMessage($"{AzuriteLocationKey} environment variable is not set and {defaultPath} doesn't exist")); } } var azuriteScriptLocation = Path.Combine(azuriteLocation, "node_modules/azurite/dist/src/azurite.js"); if (!File.Exists(azuriteScriptLocation)) { throw new ArgumentException(ErrorMessage($"{azuriteScriptLocation} does not exist, check if {AzuriteLocationKey} is pointing to right location")); } account = new AzuriteAccount() { Name = Guid.NewGuid().ToString(), Key = System.Convert.ToBase64String(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString())), }; tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); Directory.CreateDirectory(tempDirectory); process = new Process(); process.StartInfo.FileName = "node"; process.StartInfo.WorkingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); process.StartInfo.Arguments = $"{azuriteScriptLocation} --oauth basic -l {tempDirectory} --blobPort 0 --queuePort 0 --cert cert.pem --key cert.pem --skipApiVersionCheck"; process.StartInfo.EnvironmentVariables.Add("AZURITE_ACCOUNTS", $"{account.Name}:{account.Key}"); process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardInput = true; process.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e) { if (e.Data != null) { if (e.Data.Contains("Azurite Blob service is successfully listening at")) { blobsPort = ParseAzuritePort(e.Data); countdownEvent.Signal(); } if (e.Data.Contains("Azurite Queue service is successfully listening at")) { queuesPort = ParseAzuritePort(e.Data); countdownEvent.Signal(); } if (!countdownEvent.IsSet) // stop output collection if it started successfully. { azuriteOutput.AppendLine(e.Data); } } }; try { process.Start(); } catch (Win32Exception e) { throw new ArgumentException(ErrorMessage("could not run NodeJS, make sure it's installed"), e); } process.BeginOutputReadLine(); var didAzuriteStart = countdownEvent.Wait(TimeSpan.FromSeconds(15)); if (!didAzuriteStart) { throw new InvalidOperationException(ErrorMessage($"azurite process could not start with following output:\n{azuriteOutput}")); } account.BlobsPort = blobsPort; account.QueuesPort = queuesPort; }
public AzuriteFixture() { var azuriteLocation = Environment.GetEnvironmentVariable(AzuriteLocationKey); if (string.IsNullOrWhiteSpace(azuriteLocation)) { throw new ArgumentException(ErrorMessage($"{AzuriteLocationKey} environment variable is not set")); } var azuriteScriptLocation = Path.Combine(azuriteLocation, "node_modules/azurite/dist/src/azurite.js"); if (!File.Exists(azuriteScriptLocation)) { throw new ArgumentException(ErrorMessage($"{azuriteScriptLocation} does not exist, check if {AzuriteLocationKey} is pointing to right location")); } account = new AzuriteAccount() { Name = Guid.NewGuid().ToString(), Key = System.Convert.ToBase64String(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString())), }; tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); Directory.CreateDirectory(tempDirectory); process = new Process(); process.StartInfo.FileName = "node"; process.StartInfo.Arguments = $"{azuriteScriptLocation} -l {tempDirectory} --blobPort 0 --queuePort 0"; process.StartInfo.EnvironmentVariables.Add("AZURITE_ACCOUNTS", $"{account.Name}:{account.Key}"); process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardInput = true; process.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e) { if (e.Data != null) { if (e.Data.Contains("Azurite Blob service is successfully listening at")) { blobsPort = ParseAzuritePort(e.Data); countdownEvent.Signal(); } if (e.Data.Contains("Azurite Queue service is successfully listening at")) { queuesPort = ParseAzuritePort(e.Data); countdownEvent.Signal(); } if (!countdownEvent.IsSet) // stop output collection if it started successfully. { azuriteOutput.AppendLine(e.Data); } } }; try { process.Start(); } catch (Win32Exception e) { throw new ArgumentException(ErrorMessage("could not run NodeJS, make sure it's installed"), e); } process.BeginOutputReadLine(); var didAzuriteStart = countdownEvent.Wait(TimeSpan.FromSeconds(15)); if (!didAzuriteStart) { throw new InvalidOperationException(ErrorMessage($"azurite process could not start with following output:\n{azuriteOutput}")); } account.BlobsPort = blobsPort; account.QueuesPort = queuesPort; }