/// <summary> /// Injects a middleware to capture state at specific point. <br/> /// This method does not prevent referenced objects from being mutated after capture. <br/> /// It is the responsibility of capture action to clone data to prevent mutation. /// </summary> public static AppRunner CaptureState(this AppRunner runner, Action <CommandContext> capture, MiddlewareStages middlewareStage, int?orderWithinStage = null, bool exitAfterCapture = false) { return(runner.Configure(b => b.UseMiddleware((context, next) => { capture(context); return exitAfterCapture ? Task.FromResult <int>(0) : next(context); }, middlewareStage, orderWithinStage))); }
/// <summary> /// Injects a middleware to capture state at specific point. <br/> /// This method does not prevent referenced objects from being mutated after capture. <br/> /// It is the responsibility of capture action to clone data to prevent mutation. /// </summary> public static AppRunner CaptureState(this AppRunner runner, Action <CommandContext> capture, MiddlewareStages middlewareStage, short?orderWithinStage = null, bool exitAfterCapture = false) { return(runner.Configure(b => b.UseMiddleware((context, next) => { capture(context); return exitAfterCapture ? ExitCodes.Success : next(context); }, middlewareStage, orderWithinStage))); }
public static T GetFromContext <T>(this AppRunner runner, string args, ITestOutputHelper output, Func <CommandContext, T> capture, MiddlewareStages middlewareStage = MiddlewareStages.PostBindValuesPreInvoke) { return(runner.GetFromContext( args.SplitArgs(), output?.AsLogger(), capture, middlewareStage)); }
/// <summary> /// Convenience wrapper for <see cref="CaptureState"/> to capture state from the <see cref="CommandContext"/> /// </summary> public static T GetFromContext <T>(this AppRunner runner, string[] args, ILogger logger, Func <CommandContext, T> capture, MiddlewareStages middlewareStage = MiddlewareStages.PostBindValuesPreInvoke, int?orderWithinStage = null) { T state = default; runner.CaptureState( ctx => state = capture(ctx), exitAfterCapture: true, middlewareStage: middlewareStage, orderWithinStage: orderWithinStage) .RunInMem(args, logger); return(state); }
/// <summary> /// Convenience wrapper for <see cref="CaptureState"/> to capture state from the <see cref="CommandContext"/> /// </summary> public static T?GetFromContext <T>(this AppRunner runner, string[] args, Func <CommandContext, T> capture, Action <string?>?logLine = null, MiddlewareStages middlewareStage = MiddlewareStages.PostBindValuesPreInvoke, short?orderWithinStage = null) where T : class { T?state = default; runner.CaptureState( ctx => state = capture(ctx), exitAfterCapture: true, middlewareStage: middlewareStage, orderWithinStage: orderWithinStage) .RunInMem(args, logLine, config: TestConfig.Silent); return(state); }
public MiddlewareStep(MiddlewareStages stage, int?orderWithinStage = null) { Stage = stage; OrderWithinStage = orderWithinStage; }
public static AppRunner StopAfter(this AppRunner runner, MiddlewareStages stage) => runner.StopAfter(new MiddlewareStep(stage));
public MiddlewareStep(MiddlewareStages stage, short? orderWithinStage = null) { Stage = stage; OrderWithinStage = orderWithinStage.GetValueOrDefault(); }