public override Task RunAsync(CancellationToken cancellationToken) { return(Task.Factory. StartNew( () => { using (var shutdownFile = ShutdownFile.CreateRandom( new DirectoryInfo( Path.GetDirectoryName(_startInfo.FileName)))) { _startInfo.UseShellExecute = false; _startInfo.EnvironmentVariables[WorkerRoleShutdownFileEnvironmentVariableName] = shutdownFile.FullName; using (var process = Process.Start(_startInfo)) { cancellationToken.WaitHandle.WaitOne(); shutdownFile.Notify(); if (!process.WaitForExit(Convert.ToInt32(_waitForExitTimeout.TotalMilliseconds))) { process.Kill(); } } } }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Default)); }
public void CreateRandomHasExpectedResult() { using (var sut = ShutdownFile.CreateRandom(new DirectoryInfo(Environment.CurrentDirectory))) { Assert.That(Path.GetDirectoryName(sut.FullName), Is.EqualTo(Environment.CurrentDirectory)); Assert.That(Path.GetFileName(sut.FullName), Is.Not.EqualTo(Path.GetFileName(_sut.FullName))); } }
public void CreateRandomDirectoryCanNotBeNull() { Assert.Throws <ArgumentNullException>(() => ShutdownFile.CreateRandom(null)); }
public void SetUp() { _sut = ShutdownFile.CreateRandom(new DirectoryInfo(Environment.CurrentDirectory)); }