Пример #1
0
 public static void RunCommandWithRequiredStringParameterNotSet()
 {
     Assert.Throws <MissingCommandParameterException>(() =>
     {
         CmdLinery.Run(typeof(TestCommands1), new string[] { "CommandWithRequiredStringParameter" }, new TestApplicationInfo());
     });
 }
        public static void GetCommandRuleMetodHasCommandWithNonAllowedDuplicateAttributesParametersThrowMissingCommandParameterAttributeExceptionUnitTest()
        {
            CommandRuleProvider target = new CommandRuleProvider();

            Assert.Throws <DuplicateCommandParameterAttributeException>(() =>
            {
                target.GetCommandRule(typeof(TestCommands0).GetMethodEx("CommandWithNonAllowedDuplicateAttributesParameters"));
            });
        }
        public static void GetCommandRuleMetodHasValidCommandWithOneParameterWithoutParameterAttributeThrowMissingCommandParameterAttributeExceptionUnitTest()
        {
            CommandRuleProvider target = new CommandRuleProvider();

            Assert.Throws <MissingCommandParameterAttributeException>(() =>
            {
                target.GetCommandRule(typeof(TestCommands0).GetMethodEx("CommandWithOneParameterWithoutParameterAttribute"));
            });
        }
Пример #4
0
        public void ParseArraySemicolonSeparationCorruptThrowInvalidArrayParseExeption()
        {
            const string arrayString = "'123';'21';'142;'5'";
            IArrayParser target      = new ArrayParser();

            Assert.Throws <InvalidArrayParseException>(() =>
            {
                var actual = target.Parse(arrayString);
            });
        }
        GetCommandRuleMetodHasCommandWithIncorrectlyOrderedParametersThrowMissingCommandParameterAttributeExceptionUnitTest
            ()
        {
            CommandRuleProvider target = new CommandRuleProvider();

            Assert.Throws <RequiredParameterFoundAfterOptionalParameterExecption>(() =>
            {
                target.GetCommandRule(typeof(TestCommands0).GetMethodEx("CommandWithIncorrectlyOrderedParameters"));
            });
        }
Пример #6
0
 public static void ValidateCommandNotInitializedThrowNullReferenceExceptionTest()
 {
     using (var testBootStrapper = new TestBootStrapper())
     {
         var target = testBootStrapper.Container.Resolve <ICommandRuleValidator>();
         Assert.Throws <NullReferenceException>(() =>
         {
             target.Validate(new string[] { "SomeCommand", "/SomeRequiredParameter=\"SomeRequiredValue\"" }, new CommandRule());
         });
     }
 }
Пример #7
0
 public static void ValidateArgsNullThrowArgumentNullExceptionTest()
 {
     using (var testBootStrapper = new TestBootStrapper())
     {
         var target = testBootStrapper.Container.Resolve <ICommandRuleValidator>();
         Assert.Throws <ArgumentNullException>(() =>
         {
             target.Validate(null, new CommandRule());
         });
     }
 }
Пример #8
0
 public void InvalidCommandLineParametersThrow()
 {
     using (var testBootStrapper = new TestBootStrapper(GetType()))
     {
         string[] args   = { "12;13;14;15", "12" };
         var      target = new ArgumentsParser();
         Assert.Throws <InvalidCommandParameterFormatException>(() =>
         {
             var actual = target.GetCommandLineParameters(args);
         });
     }
 }
Пример #9
0
 ValidateCommandHasTwoRequiredAndOneOtionalParameterArgsHasUnknownCommandThrowInvalidCommandExceptionTest()
 {
     using (var testBootStrapper = new TestBootStrapper())
     {
         var target      = testBootStrapper.Container.Resolve <ICommandRuleValidator>();
         var commandRule = GetTestCommandRule();
         Assert.Throws <InvalidCommandException>(() =>
         {
             target.Validate(new string[] { "SomeUnknownCommand", "/SomeUnknownRequiredParameter=\"SomeRequiredValue\"" }, commandRule);
         });
     }
 }
Пример #10
0
 ValidateCommandHasTwoRequiredAndOneOtionalParameterArgsIsEmptyListThrowMissingCommandExceptionTest()
 {
     using (var testBootStrapper = new TestBootStrapper())
     {
         var target      = testBootStrapper.Container.Resolve <ICommandRuleValidator>();
         var commandRule = GetTestCommandRule();
         Assert.Throws <MissingCommandException>(() =>
         {
             target.Validate(new string[] { }, commandRule);
         });
     }
 }
Пример #11
0
 public static void ValidateCommandHasTwoRequiredAndOneOtionalParameterArgsHasValidCommandAndMissingParameterThrowMissingCommandParameterExceptionTest()
 {
     using (var testBootStrapper = new TestBootStrapper())
     {
         var target      = testBootStrapper.Container.Resolve <ICommandRuleValidator>();
         var commandRule = GetTestCommandRule();
         Assert.Throws <MissingCommandParameterException>(() =>
         {
             target.Validate(new string[] { "SomeValidCommand" }, commandRule);
         });
     }
 }
Пример #12
0
        public static void RunCommandWithNoParametersThrowingException()
        {
            var testLoggerMoc = new Mock <ITestLogger>();

            TestCommands1.TestLogger = testLoggerMoc.Object;
            const string logMessage = "Running CommandWithNoParametersThrowingException";

            testLoggerMoc.Setup(logger => logger.Write(logMessage));
            Assert.Throws <NCmdLinerException>(() =>
            {
                CmdLinery.Run(typeof(TestCommands1), new string[] { "CommandWithNoParametersThrowingException" }, new TestApplicationInfo());
            });
            testLoggerMoc.Verify(logger => logger.Write(logMessage), Times.Once);
        }
Пример #13
0
        public static void CommandsFromMultipleNamespacesDuplicateCommandThrowDuplicateCommandException()
        {
            var testLoggerMoc = new Mock <ITestLogger>();

            TestCommandsMulti2Duplicate.TestLogger = testLoggerMoc.Object;
            const string logMessage    = "Running FirstCommand()";
            var          commandString = new string[]
            {
                "FirstCommand"
            };

            testLoggerMoc.Setup(logger => logger.Write(logMessage));
            Assert.Throws <DuplicateCommandException>(() =>
            {
                CmdLinery.Run(new Type[] { typeof(TestCommandsMulti1Duplicate), typeof(TestCommandsMulti2Duplicate) }, commandString, new TestApplicationInfo());
            });
        }
Пример #14
0
        public static void RunHelpCommandWithCustomHelperProvider()
        {
            var nonStaticTestCommands = new NonStaticTestCommands7();
            var testLoggerMoc         = new Mock <ITestLogger>();

            nonStaticTestCommands.TestLogger = testLoggerMoc.Object;
            const string logMessage    = "Running NonStaticCommand()";
            var          commandString = new string[]
            {
                "Help"
            };

            testLoggerMoc.Setup(logger => logger.Write(logMessage));
            Assert.Throws <CustomTestHelpProviderException>(() =>
            {
                CmdLinery.Run(new object[] { nonStaticTestCommands }, commandString, new TestApplicationInfo(), new ConsoleMessenger(), new CustomTestHelpProvider());
            });
        }
Пример #15
0
        public static void RunCommandWithNoOptionalDefaultValueThrowMissingExampleValueException()
        {
            var testLoggerMoc = new Mock <ITestLogger>();

            TestCommands5.TestLogger = testLoggerMoc.Object;
            const string logMessage    = "Running CommandWithNoOptionalDefaultValue(\"parameter 1 value\")";
            var          commandString = new string[]
            {
                "CommandWithNoOptionalDefaultValue",
                "/parameter1=\"parameter 1 value\""
            };

            testLoggerMoc.Setup(logger => logger.Write(logMessage));
            Assert.Throws <MissingDefaultValueException>(() =>
            {
                CmdLinery.Run(typeof(TestCommands5), commandString, new TestApplicationInfo());
            });
        }