public void Should_Set_Name()
        {
            // Act
            var app = new CommandLineInjectingApplication("test name", null);

            // Assert
            app.Name.ShouldBe("test name");
        }
        public void Should_Add_Help_Option()
        {
            // Act
            var app = new CommandLineInjectingApplication(null, null);

            // Assert
            app.OptionHelp.ShouldNotBeNull();
        }
        public void Should_Set_Command_Service_Commands()
        {
            // Arrange
            var app = new CommandLineInjectingApplication(null, null);

            // Act
            app.CommandService <TestCommandService>(nameof(TestCommandService.CommandOne), nameof(TestCommandService.CommandTwo));

            // Assert
            app.Commands.Count.ShouldBe(2);
        }
        public void Should_Set_Invoke_Method_On_New_Command()
        {
            // Arrange
            var app = new CommandLineInjectingApplication(null, null);

            // Act
            app.Command <TestCommand>("command name");

            // Assert
            app.Commands.Last().Invoke.ShouldNotBeNull();
        }
        public void Should_Set_Command()
        {
            // Arrange
            var app = new CommandLineInjectingApplication(null, null);

            // Act
            app.Command <TestCommand>("command name");

            // Assert
            app.Commands.Count.ShouldBe(1);
        }
        public void Should_Set_Names_On_Command_Service_Commands()
        {
            // Arrange
            var app = new CommandLineInjectingApplication(null, null);

            // Act
            app.CommandService <TestCommandService>(nameof(TestCommandService.CommandOne), nameof(TestCommandService.CommandTwo));

            // Assert
            app.Commands[0].Name.ShouldBe("commandOne");
            app.Commands[1].Name.ShouldBe("commandTwo");
        }
        public void Should_Set_Invoke_Methods_On_Command_Service_Commands()
        {
            // Arrange
            var app = new CommandLineInjectingApplication(null, null);

            // Act
            app.CommandService <TestCommandService>(nameof(TestCommandService.CommandOne), nameof(TestCommandService.CommandTwo));

            // Assert
            app.Commands[0].Invoke.ShouldNotBeNull();
            app.Commands[1].Invoke.ShouldNotBeNull();
        }
        public void Should_Set_Invoke_For_RequiresCommand()
        {
            // Arrange
            var app           = new CommandLineInjectingApplication(null, null);
            var defaultInvoke = app.Invoke;

            // Act
            app.RequiresCommand();

            // Assert
            app.Invoke.ShouldNotBeNull();
            app.Invoke.ShouldNotBe(defaultInvoke);
        }
Exemple #9
0
        static void Main(string[] args)
        {
            var serviceCollection = new ServiceCollection()
                                    .AddTransient <IExampleService, ExampleService>()
                                    .AddTransient <TestSimpleCommandClass>();

            var containerAdapter = new MicrosoftDependencyInjectionAdapter(serviceCollection, (scopeBuilder, commands) =>
            {
                scopeBuilder.AddSingleton <IExampleConfiguration>(new ExampleConfiguration(commands));
                return(scopeBuilder);
            });

            var app = new CommandLineInjectingApplication("commandlineinjector-example", containerAdapter);

            app.RequiresCommand();
            app.AddToSubsequentAllCommands(ExampleConfiguration.ConfigValueOption);

            app.Command <TestSimpleCommandClass>("simple");
            app.Execute(args);

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            var structureMapContainer = new Container(config =>
            {
                config.For <IExampleService>().Use <ExampleService>();
                config.For <IExampleConfiguration>().Use <ExampleConfiguration>();
                config.Injectable <ExampleConfiguration>();
            });

            var containerAdapter = new LamarContainerAdapter(structureMapContainer, (container, commands) =>
            {
                container.Inject(new ExampleConfiguration(commands));
                return(container);
            });

            var app = new CommandLineInjectingApplication("commandlineinjector-example", containerAdapter);

            app.RequiresCommand();
            app.AddToSubsequentAllCommands(ExampleConfiguration.ConfigValueOption);

            app.Command <TestSimpleCommandClass>("simple");
            app.Execute(args);
        }
Exemple #11
0
        static void Main(string[] args)
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <ExampleService>().As <IExampleService>();
            builder.RegisterType <TestSimpleCommandClass>().AsSelf();

            var autofacContainer = builder.Build();

            var containerAdapter = new AutofacContainerAdapter(autofacContainer, (scopeBuilder, commands) =>
            {
                scopeBuilder.RegisterInstance(new ExampleConfiguration(commands)).As <IExampleConfiguration>();
                return(scopeBuilder);
            });

            var app = new CommandLineInjectingApplication("commandlineinjector-example", containerAdapter);

            app.RequiresCommand();
            app.AddToSubsequentAllCommands(ExampleConfiguration.ConfigValueOption);

            app.Command <TestSimpleCommandClass>("simple");
            app.Execute(args);
        }