Ejemplo n.º 1
0
        public void test()
        {
            // Arrange
            var task = new TaskDefinition(
                BasicTaskStep.Empty("Step"));

            var executor = new TaskExecutorBuilder()
                           .RegisterStepExecution(typeof(BasicTaskStep), new ThrowingStepExecutorResolver())
                           .Build();

            // Act
            Action act = () => executor.Execute(task);

            // Assert
            act.Should().Throw <Exception>().Which.Should().BeSameAs(Error);
        }
Ejemplo n.º 2
0
        public void events_can_be_registered_for_Executor_instance()
        {
            // Arrange
            var eventHandled = false;

            var events = new TaskExecutionEvents(
                taskStarted: _ => eventHandled = true);

            var task = new TaskDefinition(
                BasicTaskStep.Empty("Step"));

            // Act
            var executor = TaskExecutorFactory.Create(ResolverType.Sequential, events);

            executor.Execute(task);

            // Assert
            eventHandled.Should().BeTrue();
        }
Ejemplo n.º 3
0
        public void logger_creates_and_fills_execution_log()
        {
            // Arrange
            var task = new TaskDefinition(
                BasicTaskStep.Empty("Step"));

            var events = TaskExecutionLogger.CreateEvents();

            // Act
            var startTs = DateTime.UtcNow;

            task.Execute(events: events);
            var endTs = DateTime.UtcNow;

            // Assert
            var log = task.GetExecutionLog();

            log.Should().NotBeNull();
            log.TaskDuration.StartTs.Should().BeOnOrAfter(startTs).And.BeOnOrBefore(endTs);
            log.DiagnosticsLog.Diagnostics.Should().NotBeEmpty();
        }
Ejemplo n.º 4
0
        public void step_ignored___report_still_generated()
        {
            // Arrange
            var task = new TaskDefinition(
                BasicTaskStep.Empty("Basic"),
                new BasicTaskStep(
                    "Ignored",
                    () => { },
                    x => false));

            var loggerEvents   = TaskExecutionLogger.CreateEvents();
            var reporterEvents = TaskExecutionReporter.CreateEvents();

            // Act
            task.Execute(events: loggerEvents.Concat(reporterEvents).ToArray());

            // Assert
            var reports = task.GetExecutionReports();

            reports.Should().NotBeNull().And.NotBeEmpty();
        }
Ejemplo n.º 5
0
        public void global_and_one_time_events_are_merged()
        {
            // Arrange
            var globalEventHandled = false;
            var globalEvents       = new TaskExecutionEvents(
                taskStarted: _ => globalEventHandled = true);

            var oneTimeEventHandled = false;
            var oneTimeEvents       = new TaskExecutionEvents(
                taskStarted: _ => oneTimeEventHandled = true);

            var task = new TaskDefinition(
                BasicTaskStep.Empty("Step"));

            // Act
            var executor = TaskExecutorFactory.Create(ResolverType.Sequential, globalEvents);

            executor.Execute(task, events: oneTimeEvents);

            // Assert
            globalEventHandled.Should().BeTrue();
            oneTimeEventHandled.Should().BeTrue();
        }
Ejemplo n.º 6
0
        public void step_start_and_end_is_reported()
        {
            // Arrange
            StepStartedEvent?startedEvent = null;
            StepEndedEvent?  endedEvent   = null;

            var events = new TaskExecutionEvents(
                stepStarted: x => startedEvent = x,
                stepEnded: x => endedEvent     = x);

            var task = new TaskDefinition(
                BasicTaskStep.Empty("Step"));

            // Act
            task.Execute(events: events);

            // Assert
            startedEvent.Should().NotBeNull();
            startedEvent.Value.Step.Should().BeSameAs(task.Steps[0]);

            endedEvent.Should().NotBeNull();
            endedEvent.Value.Step.Should().BeSameAs(task.Steps[0]);
            endedEvent.Value.Duration.Should().BePositive();
        }