Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
 public static void RunCommandWithRequiredStringParameterNotSet()
 {
     Assert.Throws <MissingCommandParameterException>(() =>
     {
         CmdLinery.Run(typeof(TestCommands1), new string[] { "CommandWithRequiredStringParameter" }, new TestApplicationInfo());
     });
 }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        public void JustifyTextOneShortWordSuccess()
        {
            TextFormater target   = new TextFormater();
            string       actual   = target.Justify("Thislinewillnotbejustified.", 80);
            const string expected = "Thislinewillnotbejustified.";

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        public void FloatObjectValue2String()
        {
            IValueConverter target   = new ValueConverter();
            var             actual   = target.ObjectValue2String(1.3456f);
            var             expected = 1.3456f.ToString();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
0
        public void BooleanObjectValue2String()
        {
            IValueConverter target   = new ValueConverter();
            var             actual   = target.ObjectValue2String(true);
            var             expected = true.ToString();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
0
        public void IntegerObjectValue2String()
        {
            IValueConverter target   = new ValueConverter();
            var             actual   = target.ObjectValue2String(1043);
            var             expected = 1043.ToString();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
0
        public void StringObjectValue2String()
        {
            IValueConverter target   = new ValueConverter();
            var             actual   = target.ObjectValue2String("1043");
            var             expected = "1043";

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 17
0
        public void EnumObjectValue2String()
        {
            IValueConverter target   = new ValueConverter();
            var             actual   = target.ObjectValue2String(TestEnum.Value2);
            var             expected = TestEnum.Value2.ToString();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 18
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);
        }
        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"));
            });
        }
Ejemplo n.º 21
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);
        }
Ejemplo n.º 22
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);
        }
Ejemplo n.º 23
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);
        }
Ejemplo n.º 24
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);
        }
Ejemplo n.º 25
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);
        }
Ejemplo n.º 26
0
        public void ParseArrayEmptyArrayStringReturnZeroItemArray()
        {
            const string arrayString = "";
            IArrayParser target      = new ArrayParser();
            var          actual      = target.Parse(arrayString);
            var          expected    = new string[] { };

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 27
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);
        }
        GetCommandRuleMetodHasCommandWithIncorrectlyOrderedParametersThrowMissingCommandParameterAttributeExceptionUnitTest
            ()
        {
            CommandRuleProvider target = new CommandRuleProvider();

            Assert.Throws <RequiredParameterFoundAfterOptionalParameterExecption>(() =>
            {
                target.GetCommandRule(typeof(TestCommands0).GetMethodEx("CommandWithIncorrectlyOrderedParameters"));
            });
        }
Ejemplo n.º 29
0
        public void ParseArraySemicolonSeparationCorruptThrowInvalidArrayParseExeption()
        {
            const string arrayString = "'123';'21';'142;'5'";
            IArrayParser target      = new ArrayParser();

            Assert.Throws <InvalidArrayParseException>(() =>
            {
                var actual = target.Parse(arrayString);
            });
        }
Ejemplo n.º 30
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());
         });
     }
 }