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); }
protected virtual Task AfterExecuteAsync(ScenarioExecutionContext context) { return(Task.CompletedTask); }
protected abstract Task ExecuteAsync(ScenarioExecutionContext context);
protected override Task ExecuteAsync(ScenarioExecutionContext context) { return(Task.Delay(Duration)); }
protected Scenario(IServiceProvider serviceProvider) { ExecutionContext = new ScenarioExecutionContext(serviceProvider); Steps = new List <ScenarioStep> (); }