Пример #1
0
        public void throws_exception_when_executing_a_command_that_has_not_been_registered()
        {
            var engine = CleeEngine.Create(cfg =>
            {
                cfg.Registry(r => { /* no command registration! */ });
            });

            Assert.Throws <NotSupportedException>(() => engine.Execute("foo"));
        }
Пример #2
0
        public void returns_expected_registry()
        {
            var expected = new Mock <ICommandRegistry>().Object;

            var engine = CleeEngine.Create(cfg =>
            {
                cfg.Registry(r => r.Use(expected));
            });

            Assert.Same(expected, engine.Registry);
        }
Пример #3
0
        public void returns_expected_mapper()
        {
            var expected = new Mock <IArgumentMapper>().Object;

            var engine = CleeEngine.Create(cfg =>
            {
                cfg.Mapper(m => m.Use(expected));
            });

            Assert.Same(expected, engine.Mapper);
        }
Пример #4
0
        public void returns_expected_factory()
        {
            var expected = new Mock <ICommandFactory>().Object;

            var engine = CleeEngine.Create(cfg =>
            {
                cfg.Factory(f => f.Use(expected));
            });

            Assert.Same(expected, engine.Factory);
        }
Пример #5
0
        public void throws_exception_if_required_argument_is_not_specified()
        {
            var stubCommand = new Mock <ICommand <IdArgument> >().Object;

            var engine = CleeEngine.Create(cfg =>
            {
                cfg.Factory(f => f.Use(new StubCommandFactory(stubCommand)));
                cfg.Registry(r => r.Register("foo", stubCommand.GetType()));
            });

            Assert.Throws <Exception>(() => engine.Execute("foo"));
        }
Пример #6
0
        public void throws_exception_on_command_exception_when_enabled_in_settings()
        {
            var errorCommand = new ExceptionThrowingCommand();

            var engine = CleeEngine.Create(cfg =>
            {
                cfg.Settings(s => { s.ThrowOnExceptions = true; });
                cfg.Factory(f => f.Use(new StubCommandFactory(errorCommand)));
                cfg.Registry(r => r.Register("foo", errorCommand.GetType()));
            });

            Assert.Throws <CustomCommandException>(() => engine.Execute("foo"));
        }
Пример #7
0
        public void does_not_throw_exception_on_command_exception_when_disabled_in_settings()
        {
            var errorCommand = new ExceptionThrowingCommand();

            var engine = CleeEngine.Create(cfg =>
            {
                cfg.Settings(s => { s.ThrowOnExceptions = false; });
                cfg.Factory(f => f.Use(new StubCommandFactory(errorCommand)));
                cfg.Registry(r => r.Register("foo", errorCommand.GetType()));
            });

            engine.Execute("foo");
        }
Пример #8
0
        public void system_commands_are_not_released_using_custom_factory()
        {
            var mock = new Mock <ICommandFactory>();

            var engine = CleeEngine.Create(cfg =>
            {
                cfg.Factory(f => f.Use(mock.Object));
            });

            engine.Execute("help");

            mock.Verify(x => x.Release(It.IsAny <HelpCommand>()), Times.Never());
        }
Пример #9
0
        public void can_executed_expected_command_from_list_of_inputs()
        {
            var mock = new Mock <ICommand <EmptyArgument> >();

            var engine = CleeEngine.Create(cfg =>
            {
                cfg.Factory(f => f.Use(new StubCommandFactory(mock.Object)));
                cfg.Registry(r => r.Register("foo", mock.Object.GetType()));
            });

            engine.Execute(new[] { "foo" });

            mock.Verify(x => x.Execute(It.IsAny <EmptyArgument>()));
        }
Пример #10
0
        public void has_expected_exit_code_when_command_does_NOT_throw_exception()
        {
            var exitCode = 0;

            var errorCommand = new FooCommand();

            var engine = CleeEngine.Create(cfg =>
            {
                cfg.Factory(f => f.Use(new StubCommandFactory(errorCommand)));
                cfg.Registry(r => r.Register("foo", errorCommand.GetType()));
            });

            engine.SetExitCodeAssigner(code => exitCode = code);

            engine.Execute("foo");

            Assert.Equal(0, exitCode);
        }
Пример #11
0
        public void executed_command_with_expected_argument()
        {
            var mock = new Mock <ICommand <IdArgument> >();

            var engine = CleeEngine.Create(cfg =>
            {
                cfg.Factory(f => f.Use(new StubCommandFactory(mock.Object)));
                cfg.Registry(r => r.Register("foo", mock.Object.GetType()));
            });

            engine.Execute("foo -id 1");

            var expectedArgument = new IdArgument {
                Id = "1"
            };

            mock.Verify(x => x.Execute(expectedArgument));
        }
Пример #12
0
        public void has_expected_exit_code_from_command_exception(int expectedExitCode)
        {
            var exitCode = 0;

            var errorCommand = new ExceptionThrowingCommandWithExitCode(expectedExitCode);

            var engine = CleeEngine.Create(cfg =>
            {
                cfg.Settings(s => { s.ThrowOnExceptions = false; });
                cfg.Factory(f => f.Use(new StubCommandFactory(errorCommand)));
                cfg.Registry(r => r.Register("foo", errorCommand.GetType()));
            });

            engine.SetExitCodeAssigner(code => exitCode = code);

            engine.Execute("foo");

            Assert.Equal(expectedExitCode, exitCode);
        }
Пример #13
0
 public CleeEngine Build()
 {
     return(CleeEngine.Create(cfg => { }));
 }