Example #1
0
        public static void RunNonStaticAndStaticCommands()
        {
            var nonStaticAndStaticCommands = new NonStaticAndStaticTestCommands8();

            var testLoggerMoc = new Mock <ITestLogger>();

            NonStaticAndStaticTestCommands8.TestLogger = testLoggerMoc.Object;
            const string logMessage1 = "Running NonStaticCommand(\"parameter 1 value\")";
            const string logMessage2 = "Running StaticCommand(\"parameter 1 value\")";

            testLoggerMoc.Setup(logger => logger.Write(logMessage1));
            testLoggerMoc.Setup(logger => logger.Write(logMessage2));

            int nonStaticResult = CmdLinery.Run(new object[] { nonStaticAndStaticCommands },
                                                new string[]
            {
                "NonStaticCommand",
                "/parameter1=\"parameter 1 value\""
            }, new TestApplicationInfo(), new ConsoleMessenger());

            int staticResult = CmdLinery.Run(new object[] { nonStaticAndStaticCommands },
                                             new string[]
            {
                "StaticCommand",
                "/parameter1=\"parameter 1 value\""
            }, new TestApplicationInfo(), new ConsoleMessenger());

            Assert.AreEqual(1, nonStaticResult);
            Assert.AreEqual(2, staticResult);
            testLoggerMoc.Verify(logger => logger.Write(logMessage1), Times.Once);
        }
        public void CommandLineParametersWithMultipleEqualCharcters()
        {
            using (var testBootStrapper = new TestBootStrapper(GetType()))
            {
                string[] args     = { "Command", "/name1=vaule1=1=1", "/name2=vaule2=2=2" };
                var      target   = testBootStrapper.Container.Resolve <IArgumentsParser>();
                var      actual   = target.GetCommandLineParameters(args);
                var      expected = new Dictionary <string, CommandLineParameter>
                {
                    { "name1", new CommandLineParameter()
                      {
                          Name = "name1", Value = "value1=1=1"
                      } },
                    { "name2", new CommandLineParameter()
                      {
                          Name = "name2", Value = "value2=2=2"
                      } }
                };

                Assert.AreEquivalent(expected, actual);

                Assert.IsTrue(expected.ContainsKey("name1"), "name1 not found");
                Assert.AreEqual("name1", expected["name1"].Name);
                Assert.AreEqual("value1=1=1", expected["name1"].Value);

                Assert.IsTrue(expected.ContainsKey("name2"), "name2 not found");
                Assert.AreEqual("name2", expected["name2"].Name);
                Assert.AreEqual("value2=2=2", expected["name2"].Value);
            }
        }
Example #3
0
        public void JustifyTextOneShortWordSuccess()
        {
            TextFormater target   = new TextFormater();
            string       actual   = target.Justify("Thislinewillnotbejustified.", 80);
            const string expected = "Thislinewillnotbejustified.";

            Assert.AreEqual(expected, actual);
        }
Example #4
0
        public void JustifyTextMoreThanHalfOfWidthSuccess()
        {
            TextFormater target   = new TextFormater();
            string       actual   = target.Justify("This line will be justified because it is 45.", 80);
            const string expected = "This   line    will     be         justified          because     it    is   45.";

            Assert.AreEqual(expected, actual);
        }
Example #5
0
        public void JustifyText1Success()
        {
            TextFormater target   = new TextFormater();
            string       actual   = target.Justify("This is a test of a line to be fitted to a 80 character line.", 80);
            const string expected = "This  is  a  test  of  a   line   to    be   fitted  to  a  80  character  line.";

            Assert.AreEqual(expected, actual);
        }
Example #6
0
        public void Justify2Words19to19_Success()
        {
            TextFormater target   = new TextFormater();
            string       actual   = target.Justify("[Required] Required", 29);
            const string expected = "[Required] Required";

            Assert.AreEqual(expected, actual);
        }
Example #7
0
        public void FloatArrayObjectValue2String()
        {
            IValueConverter target   = new ValueConverter();
            var             actual   = target.ObjectValue2String(new[] { 1.3456f, 2.3456f, 3.3456f });
            var             expected = "[" + 1.3456f.ToString() + ";" + 2.3456f.ToString() + ";" + 3.3456f.ToString() + "]";

            Assert.AreEqual(expected, actual);
        }
Example #8
0
        public void FloatObjectValue2String()
        {
            IValueConverter target   = new ValueConverter();
            var             actual   = target.ObjectValue2String(1.3456f);
            var             expected = 1.3456f.ToString();

            Assert.AreEqual(expected, actual);
        }
Example #9
0
        public void BoleanArrayObjectValue2String()
        {
            IValueConverter target   = new ValueConverter();
            var             actual   = target.ObjectValue2String(new[] { true, false, true });
            var             expected = "[True;False;True]";

            Assert.AreEqual(expected, actual);
        }
Example #10
0
        public void BooleanObjectValue2String()
        {
            IValueConverter target   = new ValueConverter();
            var             actual   = target.ObjectValue2String(true);
            var             expected = true.ToString();

            Assert.AreEqual(expected, actual);
        }
Example #11
0
        public void IntegerArrayObjectValue2String()
        {
            IValueConverter target   = new ValueConverter();
            var             actual   = target.ObjectValue2String(new[] { 2, 45, 26 });
            var             expected = "[2;45;26]";

            Assert.AreEqual(expected, actual);
        }
Example #12
0
        public void IntegerObjectValue2String()
        {
            IValueConverter target   = new ValueConverter();
            var             actual   = target.ObjectValue2String(1043);
            var             expected = 1043.ToString();

            Assert.AreEqual(expected, actual);
        }
Example #13
0
        public void StringArrayObjectValue2String()
        {
            IValueConverter target   = new ValueConverter();
            var             actual   = target.ObjectValue2String(new[] { "string2", "string45", "string26" });
            var             expected = "['string2';'string45';'string26']";

            Assert.AreEqual(expected, actual);
        }
Example #14
0
        public void StringObjectValue2String()
        {
            IValueConverter target   = new ValueConverter();
            var             actual   = target.ObjectValue2String("1043");
            var             expected = "1043";

            Assert.AreEqual(expected, actual);
        }
Example #15
0
        public void EnumArrayObjectValue2String()
        {
            IValueConverter target   = new ValueConverter();
            var             actual   = target.ObjectValue2String(new[] { TestEnum.Value2, TestEnum.Value3, TestEnum.Value1 });
            var             expected = "[" + TestEnum.Value2.ToString() + ";" + TestEnum.Value3.ToString() + ";" + TestEnum.Value1.ToString() + "]";

            Assert.AreEqual(expected, actual);
        }
Example #16
0
        public void EnumObjectValue2String()
        {
            IValueConverter target   = new ValueConverter();
            var             actual   = target.ObjectValue2String(TestEnum.Value2);
            var             expected = TestEnum.Value2.ToString();

            Assert.AreEqual(expected, actual);
        }
Example #17
0
        public void CreditProviderGetCreditsTest()
        {
            var target        = new CreditProvider();
            var actual        = target.GetCredits(typeof(CreditProvider).GetAssembly());
            var expectedCount = 2;

            Assert.AreEqual(expectedCount, actual.Count, "Number of embeded credit xml is not " + expectedCount);
        }
Example #18
0
        public void ParseArrayParantesis1SimplePlusSeparationSuccess()
        {
            const string arrayString = "{12+13+14+15}";
            IArrayParser target      = new ArrayParser();
            var          actual      = target.Parse(arrayString);
            var          expected    = new[] { "12", "13", "14", "15" };

            Assert.AreEqual(expected, actual);
        }
Example #19
0
        public void ParseArrayQuotedSemicolonSeparationEndingWithSemiColonSuccess()
        {
            const string arrayString = "'12';'13';'14';'15';";
            IArrayParser target      = new ArrayParser();
            var          actual      = target.Parse(arrayString);
            var          expected    = new[] { "12", "13", "14", "15", "" };

            Assert.AreEqual(expected, actual);
        }
Example #20
0
        public void ParseArrayParantesis2SimpleSemicolonSeparationSuccess()
        {
            const string arrayString = "[12;13;14;15]";
            IArrayParser target      = new ArrayParser();
            var          actual      = target.Parse(arrayString);
            var          expected    = new[] { "12", "13", "14", "15" };

            Assert.AreEqual(expected, actual);
        }
Example #21
0
        public void Parse2ItemArrayStringReturn2ItemArray()
        {
            const string arrayString = "{'MS.*.dll';'MS.*.exe'}";
            IArrayParser target      = new ArrayParser();
            var          actual      = target.Parse(arrayString);
            var          expected    = new string[] { "MS.*.dll", "MS.*.exe" };

            Assert.AreEqual(expected, actual);
        }
Example #22
0
        public void ParseItemArrayStringWithRegularExpressionReturnItemArray()
        {
            const string arrayString = @"{'^.+-133-3\d+-.+$'}";
            IArrayParser target      = new ArrayParser();
            var          actual      = target.Parse(arrayString);
            var          expected    = new string[] { @"^.+-133-3\d+-.+$" };

            Assert.AreEqual(expected, actual);
        }
Example #23
0
        public void ParseArrayEmptyArrayStringReturnZeroItemArray()
        {
            const string arrayString = "";
            IArrayParser target      = new ArrayParser();
            var          actual      = target.Parse(arrayString);
            var          expected    = new string[] { };

            Assert.AreEqual(expected, actual);
        }
Example #24
0
        public void ParseArrayNonSupportedDelimiterReturnOneItemArray()
        {
            const string arrayString = "12-13-14-15";
            IArrayParser target      = new ArrayParser();
            var          actual      = target.Parse(arrayString);
            var          expected    = new[] { "12-13-14-15" };

            Assert.AreEqual(expected, actual);
        }
Example #25
0
        public void BreakIntoLines1ShortWord80Width1LineSuccess()
        {
            TextFormater  target   = new TextFormater();
            List <string> actual   = target.BreakIntoLines("This", 80);
            List <string> expected = new List <string>()
            {
                "This"
            };

            Assert.AreEqual(expected, actual);
        }
        public static void GetCommandRuleMetodHasCommandWithTwoRequiredParameterAndOneOptionalParameterVerifyCommandRuleSucessUnitTest()
        {
            CommandRuleProvider target      = new CommandRuleProvider();
            string      expectedCommandName = "CommandWithTwoRequiredParameterAndOneOptionalParameter";
            CommandRule commandRule         = target.GetCommandRule(typeof(TestCommands0).GetMethodEx(expectedCommandName));

            Assert.AreEqual(expectedCommandName, commandRule.Command.Name);
            Assert.AreEqual(2, commandRule.Command.RequiredParameters.Count);
            Assert.AreEqual(1, commandRule.Command.OptionalParameters.Count);
            //Console.WriteLine(commandRule.Help());
        }
        public static void GetCommandRuleWithOnlyDescriptionAndNoSummaryDefinedTest()
        {
            var    target = new CommandRuleProvider();
            string expectedCommandName = "CommandWithOnlyDescriptionAndNoSummaryDefined";
            var    actualCommandRule   = target.GetCommandRule(typeof(TestCommands9).GetMethodEx(expectedCommandName));

            Assert.AreEqual(expectedCommandName, actualCommandRule.Command.Name);
            Assert.AreEqual(0, actualCommandRule.Command.RequiredParameters.Count);
            Assert.AreEqual(0, actualCommandRule.Command.OptionalParameters.Count);
            var expectedDescription = "Command with only description defined. Summary should the be set to the same as the description.";
            var epectedSummary      = "Command with only description defined. Summary should the be set to the same as the description.";

            Assert.AreEqual(expectedDescription, actualCommandRule.Command.Description);
            Assert.AreEqual(epectedSummary, actualCommandRule.Command.Summary);
        }
        public static void GetCommandRuleWithBothDescriptionAndSummaryDefinedTest()
        {
            var    target = new CommandRuleProvider();
            string expectedCommandName = "CommandWithBothDescriptionAndSummaryDefined";
            var    actualCommandRule   = target.GetCommandRule(typeof(TestCommands9).GetMethodEx(expectedCommandName));

            Assert.AreEqual(expectedCommandName, actualCommandRule.Command.Name);
            Assert.AreEqual(0, actualCommandRule.Command.RequiredParameters.Count);
            Assert.AreEqual(0, actualCommandRule.Command.OptionalParameters.Count);
            var expectedDescription = "Command with both summary and description defined";
            var epectedSummary      = "Summary of command";

            Assert.AreEqual(expectedDescription, actualCommandRule.Command.Description);
            Assert.AreEqual(epectedSummary, actualCommandRule.Command.Summary);
        }
Example #29
0
        public void BreakIntoLines10Words80Width3LinesSuccess()
        {
            TextFormater  target = new TextFormater();
            List <string> actual =
                target.BreakIntoLines(
                    "This is text should give no meaning what so ever. We are in this moment changing to second line. We should now be on the second line and if we write som more we get to the third line.",
                    80);
            List <string> expected = new List <string>()
            {
                "This is text should give no meaning what so ever. We are in this moment",
                "changing to second line. We should now be on the second line and if we write",
                "som more we get to the third line."
            };

            Assert.AreEqual(expected, actual);
        }
Example #30
0
        public static void CommandsFromMultipleNamespaces()
        {
            const int expected      = 10;
            var       testLoggerMoc = new Mock <ITestLogger>();

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

            testLoggerMoc.Setup(logger => logger.Write(logMessage));
            int actual = CmdLinery.Run(new Type[] { typeof(TestCommandsMulti1), typeof(TestCommandsMulti2) }, commandString, new TestApplicationInfo());

            Assert.AreEqual(expected, actual);
            testLoggerMoc.Verify(logger => logger.Write(logMessage), Times.Once);
        }