public void Execute_ReturnsNonZeroWhenNoCommandsAreAvailable()
        {
            var controller = new ConsoleController();

            int exitCode = controller.Execute(new string[] { });

            Assert.That(exitCode, Is.EqualTo(1));
        }
        public void Execute_RunNonExistantCommand()
        {
            var commandFactory = MockRepository.GenerateStub <ICommandFactory>();
            var controller     = new ConsoleController(commandFactory);

            int exitCode = controller.Execute(new[] { "donothing" });

            Assert.That(exitCode, Is.EqualTo(1));
        }
        public void RethrowExceptions_False()
        {
            var command        = MockRepository.GenerateStub <ThrowingCommand>();
            var commandFactory = MockRepository.GenerateStub <ICommandFactory>();

            commandFactory.Stub(f => f.Create(typeof(ThrowingCommand))).Return(command);
            var controller = new ConsoleController(commandFactory);

            controller.Register(typeof(ThrowingCommand));
            controller.RethrowExceptions = false;

            Assert.DoesNotThrow(delegate { controller.Execute(new[] { "throwing" }); });
        }
        public void Execute_CreatesAndDelegatesToSubCommand()
        {
            var commandFactory       = MockRepository.GenerateStub <ICommandFactory>();
            RemoteAddCommand command = new RemoteAddCommand();

            commandFactory.Stub(f => f.Create(typeof(RemoteAddCommand))).Return(command);
            var controller = new ConsoleController(commandFactory);

            controller.Register(typeof(RemoteCommand));
            controller.RethrowExceptions = true;

            controller.Execute(new[] { "remote", "add", "test_name" });

            Assert.That(command.Name, Is.EqualTo("test_name"));
        }
        public void Execute_PositionalArguments()
        {
            var command        = MockRepository.GenerateStub <CloneCommand>();
            var commandFactory = MockRepository.GenerateStub <ICommandFactory>();

            commandFactory.Stub(f => f.Create(typeof(CloneCommand))).Return(command);
            var controller = new ConsoleController(commandFactory);

            controller.Register(typeof(CloneCommand));

            controller.Execute(new[] { "clone", "the_repo" });

            command.AssertWasCalled(c => c.Execute());
            Assert.That(command.Repository, Is.EqualTo("the_repo"));
        }
        public void Execute_RunSpecificCommand()
        {
            var command        = MockRepository.GenerateStub <CloneCommand>();
            var commandFactory = MockRepository.GenerateStub <ICommandFactory>();

            commandFactory.Stub(f => f.Create(typeof(CloneCommand))).Return(command);
            var controller = new ConsoleController(commandFactory);

            controller.Register(typeof(CloneCommand));

            int exitCode = controller.Execute(new[] { "clone" });

            command.AssertWasCalled(c => c.Execute());
            Assert.That(exitCode, Is.EqualTo(0));
        }
        public void Execute_MixOfPositionalAndNamedArgumentsWithArrays()
        {
            var command        = MockRepository.GenerateStub <PositionalStringArrayArgCommand>();
            var commandFactory = MockRepository.GenerateStub <ICommandFactory>();

            commandFactory.Stub(f => f.Create(typeof(PositionalStringArrayArgCommand))).Return(command);
            var controller = new ConsoleController(commandFactory);

            controller.Register(typeof(PositionalStringArrayArgCommand));

            controller.Execute(new[] { "positionalstringarrayarg", "value_one", "--arg", "value_two" });

            command.AssertWasCalled(c => c.Execute());
            Assert.That(command.ArrayArgument, Is.EqualTo(new[] { "value_one", "value_two" }));
            Assert.That(command.Argument);
        }
        public void Execute_EnableThenDisableFlagArgument()
        {
            var command        = MockRepository.GenerateStub <LsAppCommand>();
            var commandFactory = MockRepository.GenerateStub <ICommandFactory>();

            commandFactory.Stub(f => f.Create(typeof(LsAppCommand))).Return(command);
            var controller = new ConsoleController(commandFactory);

            controller.Register(typeof(LsAppCommand));
            controller.SetDefaultCommand(typeof(LsAppCommand));

            controller.Execute(new[] { "--human-readable+", "--human-readable-" });

            command.AssertWasCalled(c => c.Execute());
            Assert.That(command.HumanReadableSizes, Is.EqualTo(false));
        }
        public void Execute_DoubleQuotedStringValue()
        {
            var command        = MockRepository.GenerateStub <StringArgCommand>();
            var commandFactory = MockRepository.GenerateStub <ICommandFactory>();

            commandFactory.Stub(f => f.Create(typeof(StringArgCommand))).Return(command);
            var controller = new ConsoleController(commandFactory);

            controller.Register(typeof(StringArgCommand));
            controller.SetDefaultCommand(typeof(StringArgCommand));

            controller.Execute(new[] { "/arg:\"First Second Third\"" });

            command.AssertWasCalled(c => c.Execute());
            Assert.That(command.Argument, Is.EqualTo("First Second Third"));
        }
        public void Execute_DefaultCommandWithMultipleArguments()
        {
            var command        = MockRepository.GenerateStub <LsAppCommand>();
            var commandFactory = MockRepository.GenerateStub <ICommandFactory>();

            commandFactory.Stub(f => f.Create(typeof(LsAppCommand))).Return(command);
            var controller = new ConsoleController(commandFactory);

            controller.Register(typeof(LsAppCommand));
            controller.SetDefaultCommand(typeof(LsAppCommand));

            int exitCode = controller.Execute(new[] { "--ignore=ntuser*", "--ignore=NTUSER*" });

            command.AssertWasCalled(c => c.Execute());
            Assert.That(exitCode, Is.EqualTo(0));
            CollectionAssert.AreEqual(new[] { "ntuser*", "NTUSER*" }, command.IgnorePatterns);
        }
        public void Execute_DefaultCommandWithArguments()
        {
            var command        = MockRepository.GenerateStub <LsAppCommand>();
            var commandFactory = MockRepository.GenerateStub <ICommandFactory>();

            commandFactory.Stub(f => f.Create(typeof(LsAppCommand))).Return(command);
            var controller = new ConsoleController(commandFactory);

            controller.Register(typeof(LsAppCommand));
            controller.SetDefaultCommand(typeof(LsAppCommand));

            int exitCode = controller.Execute(new[] { "-l", "-h", "-S" });

            command.AssertWasCalled(c => c.Execute());
            Assert.That(exitCode, Is.EqualTo(0));
            Assert.IsTrue(command.LongListingFormat);
            Assert.IsTrue(command.HumanReadableSizes);
            Assert.IsTrue(command.SortByFileSize);
        }
예제 #12
0
        static int Main(string[] args)
        {
            ConsoleController controller = new ConsoleController();

            controller.Register(typeof(CloneCommand));
            controller.Register(typeof(CommitCommand));
            controller.Register(typeof(RemoteCommand));
            controller.SetDefaultCommand(typeof(CloneCommand));
            return(controller.Execute(args));

            //TODO
            // With this:
            //     clone --quiet http://example.com/app.git
            // It will:
            //     command = new CloneCommand();
            //     command.Quiet = true;
            //     command.Repository = "...";
            //     command.Execute();
        }
예제 #13
0
        static int Main(string[] args)
        {
            Repository = new XilinxRepository();

            ConsoleController controller = new ConsoleController();

            // Main Commands
            controller.Register(typeof(HelpCommand));

            // Core Commands
            controller.Register(typeof(CoreTreeCommand));
            controller.Register(typeof(CoreXiseGenCommand));
            controller.Register(typeof(CorePrjGenCommand));
            controller.Register(typeof(CoreISimCommand));
            controller.Register(typeof(CoreSynthesizeCommand));
            controller.Register(typeof(DeviceInformationCommand));
            controller.Register(typeof(ClearCacheCommand));

            // Set default command
            controller.SetDefaultCommand(typeof(HelpCommand));

            // For debugging purposes allow exceptions to passthrough the handler.
            controller.RethrowExceptions = true;

            try
            {
                return(controller.Execute(args));
            }
            catch
            {
                HelpCommand help = new HelpCommand();
                help.Execute();
#if DEBUG
                throw;
#endif
            }
#if !DEBUG
            return(1);
#endif
        }