public void Should_Not_Print_Delegated_Tasks_When_Verbosity_Does_Not_Suffice(Verbosity verbosity) { // Given var log = Substitute.For <ICakeLog>(); log.Verbosity.Returns(verbosity); var context = Substitute.For <ICakeContext>(); context.Log.Returns(log); var console = new FakeConsole(); var report = new CakeReport(); string taskName = "TaskName"; string tasknameThatWasDelegated = "TaskName-That-Was-Delegated"; TimeSpan duration = TimeSpan.FromSeconds(10); TimeSpan durationDelegatedTask = TimeSpan.FromSeconds(5); report.Add(taskName, duration); report.AddDelegated(tasknameThatWasDelegated, durationDelegatedTask); var printer = new CakeReportPrinter(console, context); // When printer.Write(report); // Then string expected = String.Format("{0,-30}{1,-20}", tasknameThatWasDelegated, durationDelegatedTask); Assert.DoesNotContain(console.Messages, s => s == expected); }
public void Should_Print_Delegated_Tasks_When_Verbosity_Suffices(Verbosity verbosity) { // Given var log = Substitute.For <ICakeLog>(); log.Verbosity.Returns(verbosity); var context = Substitute.For <ICakeContext>(); context.Log.Returns(log); var console = new FakeConsole(); var report = new CakeReport(); var taskName = "TaskName"; var tasknameThatWasDelegated = "TaskName-That-Was-Delegated"; var duration = TimeSpan.FromSeconds(10); var durationDelegatedTask = TimeSpan.FromSeconds(5); report.Add(taskName, duration); report.AddDelegated(tasknameThatWasDelegated, durationDelegatedTask); var printer = new CakeReportPrinter(console, context); // When printer.Write(report); // Then var expected = $"{tasknameThatWasDelegated, -30}{durationDelegatedTask, -20}"; Assert.Contains(console.Messages, s => s == expected); }
private async Task ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, CancellationTokenSource cts, CakeTask task, CakeReport report) { _log.Verbose($"Starting task {task.Name}"); var stopwatch = Stopwatch.StartNew(); PerformTaskSetup(context, strategy, task, false); var execptionWasThrown = false; try { var taskExecutionContext = new TaskExecutionContext(context, task); await strategy.ExecuteAsync(task, taskExecutionContext).ConfigureAwait(false); } catch (TaskCanceledException) { execptionWasThrown = true; throw; } catch (Exception exception) { execptionWasThrown = true; _log.Error($"An error occurred when executing task '{task.Name}'."); if (task.ErrorReporter != null) { ReportErrors(strategy, task.ErrorReporter, exception); } if (task.ErrorHandler != null) { HandleErrors(strategy, task.ErrorHandler, exception); } else { cts.Cancel(); throw; } } finally { strategy.InvokeFinally(task.FinallyHandler); PerformTaskTeardown(context, strategy, task, stopwatch.Elapsed, false, execptionWasThrown); } if (isDelegatedTask(task)) { report.AddDelegated(task.Name, stopwatch.Elapsed); } else { report.Add(task.Name, stopwatch.Elapsed); } }
public void Should_Add_A_New_Task() { // Given var report = new CakeReport(); var taskName = "task"; var duration = TimeSpan.FromMilliseconds(100); // When report.AddDelegated(taskName, duration); // Then var firstTask = report.First(); Assert.Equal(taskName, firstTask.TaskName); Assert.Equal(duration, firstTask.Duration); Assert.Equal(CakeTaskExecutionStatus.Delegated, firstTask.ExecutionStatus); }
public void Should_Add_To_End_Of_Sequence() { // Given var report = new CakeReport(); report.AddSkipped("task 1"); var taskName = "task 2"; var duration = TimeSpan.FromMilliseconds(100); // When report.AddDelegated(taskName, duration); // Then var lastTask = report.Last(); Assert.Equal(taskName, lastTask.TaskName); Assert.Equal(duration, lastTask.Duration); Assert.Equal(CakeTaskExecutionStatus.Delegated, lastTask.ExecutionStatus); }