public static async Task <CommandLineResult> Execute( string command, string args, DirectoryInfo workingDir = null, Budget budget = null) { args = args ?? ""; budget = budget ?? new Budget(); var stdOut = new StringBuilder(); var stdErr = new StringBuilder(); using (var operation = CheckBudgetAndStartConfirmationLogger(command, args, budget)) using (var process = StartProcess( command, args, workingDir, output: data => { stdOut.AppendLine(data); }, error: data => { stdErr.AppendLine(data); })) { var exitCode = await process.Complete(budget); var output = stdOut.Replace("\r\n", "\n").ToString().Split('\n'); var error = stdErr.Replace("\r\n", "\n").ToString().Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); if (error.All(string.IsNullOrWhiteSpace)) { error = null; } var result = new CommandLineResult( exitCode: exitCode, output: output, error: error); if (exitCode == 0) { operation.Succeed( "{command} {args} exited with {code}", process.StartInfo.FileName, process.StartInfo.Arguments, process.ExitCode); } else { var ex = new BudgetExceededException(budget); operation.Fail(ex); } return(result); } }
public async Task When_time_budget_expires_prior_to_user_code_then_a_504_is_returned() { using (VirtualClock.Start()) { var budget = new TimeBudget(10.Seconds()); await Clock.Current.Wait(11.Seconds()); var exception = new BudgetExceededException(budget); exception.ToHttpStatusCode().Should().Be(504); } }
public async Task When_time_budget_expires_in_user_code_then_a_417_is_returned() { using (VirtualClock.Start()) { var budget = new TimeBudget(10.Seconds()); await Clock.Current.Wait(11.Seconds()); budget.RecordEntry(ScriptingWorkspaceServer.UserCodeCompletedBudgetEntryName); var exception = new BudgetExceededException(budget); exception.ToHttpStatusCode().Should().Be(417); } }