public CommandExecutor ( [NotNull] ILogger <CommandExecutor> logger, [NotNull] ICommandLineParser commandLineParser, [NotNull] IIndex <Identifier, IConsoleCommand> commands, [NotNull] ExecuteExceptionCallback executeExceptionCallback ) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _commandLineParser = commandLineParser ?? throw new ArgumentNullException(nameof(commandLineParser)); _commands = commands ?? throw new ArgumentNullException(nameof(commands)); _executeExceptionCallback = executeExceptionCallback; }
private static IContainer InitializeContainer(Action <CommandRegistrationBuilder> commands, ExecuteExceptionCallback executeExceptionCallback = null) { var builder = new ContainerBuilder(); builder .RegisterInstance(new LoggerFactory()) .As <ILoggerFactory>(); builder .RegisterGeneric(typeof(Logger <>)) .As(typeof(ILogger <>)); builder .RegisterModule(new CommanderModule(commands)); if (!(executeExceptionCallback is null)) { builder .RegisterInstance(executeExceptionCallback); } //builder // .RegisterInstance((ExecuteExceptionCallback)(ex => // { // Fail(ex.Message); // })); return(builder.Build()); }
public static TestContext CreateContext(Action <CommandRegistrationBuilder> commands, ExecuteExceptionCallback executeExceptionCallback = null) { var container = InitializeContainer(commands, executeExceptionCallback); var scope = container.BeginLifetimeScope(); var executor = scope.Resolve <ICommandLineExecutor>(); return(new TestContext( Disposable.Create(() => { scope.Dispose(); container.Dispose(); }), executor )); }