示例#1
0
        public async Task RunAsync(ScenarioExecutionContext context)
        {
            await BeforeExecuteAsync(context);

            var stopwatch = Stopwatch.StartNew();

            try {
                await ExecuteAsync(context);

                SuccessCount++;

                LastExecutionDuration = stopwatch.Elapsed.TotalMilliseconds;

                TotalExecutionDuration += LastExecutionDuration;

                if (MinExecutionDuration > LastExecutionDuration)
                {
                    MinExecutionDuration = LastExecutionDuration;
                }

                if (MaxExecutionDuration < LastExecutionDuration)
                {
                    MaxExecutionDuration = LastExecutionDuration;
                }
            } catch (Exception ex) {
                FailCount++;

                context
                .ServiceProvider
                .GetService <ILogger <ScenarioStep> > ()
                .LogException(ex);
            } finally {
                stopwatch.Stop();

                ExecutionCount++;
            }

            await AfterExecuteAsync(context);
        }
示例#2
0
 protected virtual Task AfterExecuteAsync(ScenarioExecutionContext context)
 {
     return(Task.CompletedTask);
 }
示例#3
0
 protected abstract Task ExecuteAsync(ScenarioExecutionContext context);
示例#4
0
 protected override Task ExecuteAsync(ScenarioExecutionContext context)
 {
     return(Task.Delay(Duration));
 }
示例#5
0
 protected Scenario(IServiceProvider serviceProvider)
 {
     ExecutionContext = new ScenarioExecutionContext(serviceProvider);
     Steps            = new List <ScenarioStep> ();
 }