Esempio n. 1
0
        public async Task CommandParametersGetsBinded()
        {
            var rootCommand = new RootCommand();

            rootCommand.AddOption(new Option("--someoption")
            {
                Argument = new Argument <bool>()
            });

            var context    = new InvocationContext(new Parser(rootCommand).Parse("--someoption"), Substitute.For <IConsole>());
            var testParams = new TestArguments();

            var sut = new PretzelCommandHandler(
                Substitute.For <IConfiguration>(),
                testParams,
                new ExportFactory <Logic.Commands.ICommand, CommandInfoAttribute>(
                    () => Tuple.Create(
                        Substitute.For <Logic.Commands.ICommand>(),
                        new Action(() => { })
                        ), new CommandInfoAttribute()));

            await sut.InvokeAsync(context);

            Assert.True(testParams.SomeOption);
        }
Esempio n. 2
0
        public async Task ExecutionOrder()
        {
            var rootCommand = new RootCommand();

            var context       = new InvocationContext(new Parser(rootCommand).Parse(""), Substitute.For <IConsole>());
            var configuration = Substitute.For <IConfiguration>();
            var arguments     = Substitute.For <ICommandArguments, ISourcePathProvider>();

            ((ISourcePathProvider)arguments).Source.Returns("bar");
            var command = Substitute.For <Logic.Commands.ICommand>();

            var sut = new PretzelCommandHandler(
                configuration,
                arguments,
                new ExportFactory <Logic.Commands.ICommand, CommandInfoAttribute>(
                    () => Tuple.Create(
                        command,
                        new Action(() => { })
                        ), new CommandInfoAttribute()));

            await sut.InvokeAsync(context);

            Received.InOrder(async() =>
            {
                arguments.BindingCompleted();
                configuration.ReadFromFile("bar");
                await command.Execute(arguments);
            });
        }
Esempio n. 3
0
        public async Task CommandParametersExtention_BindingCompleted_IsCalled()
        {
            var rootCommand = new RootCommand();

            rootCommand.AddOption(new Option("--otheroption")
            {
                Argument = new Argument <bool>()
            });

            var context    = new InvocationContext(new Parser(rootCommand).Parse("--otheroption"), Substitute.For <IConsole>());
            var testParams = new TestArguments2();

            testParams.Extensions.Add(testParams.Args);
            var sut = new PretzelCommandHandler(
                Substitute.For <IConfiguration>(),
                testParams,
                new ExportFactory <Logic.Commands.ICommand, CommandInfoAttribute>(
                    () => Tuple.Create(
                        Substitute.For <Logic.Commands.ICommand>(),
                        new Action(() => { })
                        ), new CommandInfoAttribute()));

            await sut.InvokeAsync(context);

            Assert.True(testParams.Args.BindingCompletedCalled);
        }
Esempio n. 4
0
        public async Task CommandParameters_BindingCompleted_IsCalled()
        {
            var rootCommand = new RootCommand();

            var context      = new InvocationContext(new Parser(rootCommand).Parse(string.Empty), Substitute.For <IConsole>());
            var testArgument = Substitute.For <ICommandArguments>();

            var sut = new PretzelCommandHandler(
                Substitute.For <IConfiguration>(),
                testArgument,
                new ExportFactory <Logic.Commands.ICommand, CommandInfoAttribute>(
                    () => Tuple.Create(
                        Substitute.For <Logic.Commands.ICommand>(),
                        new Action(() => { })
                        ), new CommandInfoAttribute()));

            await sut.InvokeAsync(context);

            testArgument.Received().BindingCompleted();
        }
Esempio n. 5
0
        public async Task CommandGetsExecuted()
        {
            var rootCommand = new RootCommand();

            var context   = new InvocationContext(new Parser(rootCommand).Parse(""), Substitute.For <IConsole>());
            var command   = Substitute.For <Logic.Commands.ICommand>();
            var arguments = Substitute.For <ICommandArguments>();

            var sut = new PretzelCommandHandler(
                Substitute.For <IConfiguration>(),
                arguments,
                new ExportFactory <Logic.Commands.ICommand, CommandInfoAttribute>(
                    () => Tuple.Create(
                        command,
                        new Action(() => { })
                        ), new CommandInfoAttribute()));

            await sut.InvokeAsync(context);

            await command.Received(1).Execute(arguments);
        }
Esempio n. 6
0
        public async Task Configuration_ReadFromFile_IsCalled_WithPathProvider()
        {
            var configuration = Substitute.For <IConfiguration>();

            var rootCommand  = new RootCommand();
            var testArgument = Substitute.For <ICommandArguments, ISourcePathProvider>();

            ((ISourcePathProvider)testArgument).Source.Returns("foo");

            var context = new InvocationContext(new Parser(rootCommand).Parse(string.Empty), Substitute.For <IConsole>());

            var sut = new PretzelCommandHandler(
                configuration,
                testArgument,
                new ExportFactory <Logic.Commands.ICommand, CommandInfoAttribute>(
                    () => Tuple.Create(
                        Substitute.For <Logic.Commands.ICommand>(),
                        new Action(() => { })
                        ), new CommandInfoAttribute()));

            await sut.InvokeAsync(context);

            configuration.Received().ReadFromFile("foo");
        }