public void ValidateGetEnumerator()
        {
            AggregateNumbers aggregateNos = new AggregateNumbers();
            CommandLineArguments parser = new CommandLineArguments();

            //add parameters
            parser.Parameter(ArgumentType.Required, "InputFile", ArgumentValueType.String, "i", "File containing numbers to add");
            parser.Parameter(ArgumentType.Required, "ResultFile", ArgumentValueType.String, "r", "File to store output");
            string inputfileName = Path.GetTempFileName().Replace(Path.GetTempPath(), "");
            string outputfileName = Path.GetTempFileName().Replace(Path.GetTempPath(), "");
            string[] args = { "-InputFile:" + inputfileName, "-ResultFile:" + outputfileName };
            parser.Parse(args, aggregateNos);
            IEnumerator parsedVals =  parser.GetEnumerator();
            Assert.IsNotNull(parsedVals);
            string current = string.Empty;
            int count = 0;
            parser.Reset();
            while (parser.MoveNext())
            {
                current = parser.Current.ToString();
                ApplicationLog.WriteLine(current);
                count++;
            }
            Assert.AreEqual(2, count);
        }
예제 #2
0
        public void InvalidateParseWithMissingRequiredParam()
        {
            try
            {
                AggregateNumbers     aggregateNos = new AggregateNumbers();
                CommandLineArguments parser       = new CommandLineArguments();

                //add parameters
                parser.Parameter(ArgumentType.Required, "bValue", ArgumentValueType.Bool, "bv", "bool");
                parser.Parameter(ArgumentType.Required, "iValue", ArgumentValueType.Int, "iv", "int");
                parser.Parameter(ArgumentType.Required, "bArrValues", ArgumentValueType.Bool, "bmv", "boolArrValues");
                parser.Parameter(ArgumentType.Required, "fValue", ArgumentValueType.Int, "fv", "float");
                parser.Parameter(ArgumentType.Required, "dValue", ArgumentValueType.Int, "dv", "double");
                parser.Parameter(ArgumentType.DefaultArgument, "usValues", ArgumentValueType.MultipleUniqueStrings, "usv", "Unique strings");

                //not including the first required param
                string[] args = { "-iValue:5",    "-bArrValues:true", "false",
                                  "-fValue:3.45", "-dValue:78.9876",  "Str1", "Str2", "Str3" };
                parser.Parse(args, aggregateNos);
                Assert.Fail();
            }
            catch (RequiredArgumentMissingException ex)
            {
                ApplicationLog.WriteLine("Successfully caught RequiredArgumentMissingException : " + ex.Message);
            }
        }
예제 #3
0
        public void InvalidateParse()
        {
            AggregateNumbers     aggregateNos = new AggregateNumbers();
            CommandLineArguments parser       = new CommandLineArguments();

            //add parameters
            parser.Parameter(ArgumentType.Required, "InputFile", ArgumentValueType.String, "i", "File containing numbers to add");
            parser.Parameter(ArgumentType.Required, "ResultFile", ArgumentValueType.String, "r", "File to store output");
            string outputfileName = Path.GetTempFileName().Replace(Path.GetTempPath(), "");

            //pass parameter without value
            try
            {
                string[] args = { "/InputFile:", "/ResultFile:" + outputfileName };
                parser.Parse(args, aggregateNos);
                Assert.Fail();
            }
            catch (ArgumentParserException ex)
            {
                ApplicationLog.WriteLine("CommandLineArguments P2: Successfully caught InvalidArgumentValueException : " + ex.Message);
            }

            //pass invalid starting character
            try
            {
                string[] args = { "*/ResultFile:" + outputfileName };
                parser.Parse(args, aggregateNos);
                Assert.Fail();
            }
            catch (ArgumentParserException ex)
            {
                ApplicationLog.WriteLine("CommandLineArguments P2: Successfully caught ArgumentNullException : " + ex.Message);
            }
        }
예제 #4
0
        public void ValidateGetEnumerator()
        {
            AggregateNumbers     aggregateNos = new AggregateNumbers();
            CommandLineArguments parser       = new CommandLineArguments();

            //add parameters
            parser.Parameter(ArgumentType.Required, "InputFile", ArgumentValueType.String, "i", "File containing numbers to add");
            parser.Parameter(ArgumentType.Required, "ResultFile", ArgumentValueType.String, "r", "File to store output");
            string inputfileName  = Path.GetTempFileName().Replace(Path.GetTempPath(), "");
            string outputfileName = Path.GetTempFileName().Replace(Path.GetTempPath(), "");

            string[] args = { "/InputFile:" + inputfileName, "/ResultFile:" + outputfileName };
            parser.Parse(args, aggregateNos);
            IEnumerator parsedVals = parser.GetEnumerator();

            Assert.IsNotNull(parsedVals);
            string current = string.Empty;
            int    count   = 0;

            parser.Reset();
            while (parser.MoveNext())
            {
                current = parser.Current.ToString();
                Console.WriteLine(current);
                count++;
            }
            Assert.AreEqual(2, count);
        }
        public void InvalidateParse()
        {
            AggregateNumbers aggregateNos = new AggregateNumbers();
            CommandLineArguments parser = new CommandLineArguments();

            //add parameters
            parser.Parameter(ArgumentType.Required, "InputFile", ArgumentValueType.String, "i", "File containing numbers to add");
            parser.Parameter(ArgumentType.Required, "ResultFile", ArgumentValueType.String, "r", "File to store output");
            string outputfileName = Path.GetTempFileName().Replace(Path.GetTempPath(), "");
            //pass parameter without value
            try
            {
                string[] args = { "/InputFile:", "/ResultFile:" + outputfileName };
                parser.Parse(args, aggregateNos);
                Assert.Fail();
            }
            catch (ArgumentParserException ex)
            {
                ApplicationLog.WriteLine("CommandLineArguments P2: Successfully caught InvalidArgumentValueException : " + ex.Message);
            }

            //pass invalid starting character
            try
            {
                string[] args = { "*/ResultFile:" + outputfileName };
                parser.Parse(args, aggregateNos);
                Assert.Fail();
            }
            catch (ArgumentParserException ex)
            {
                ApplicationLog.WriteLine("CommandLineArguments P2: Successfully caught ArgumentNullException : " + ex.Message);
            }
        }
예제 #6
0
        public void InvalidateParseForNullArguments()
        {
            AggregateNumbers     aggregateNos = new AggregateNumbers();
            CommandLineArguments parser       = new CommandLineArguments();

            try
            {
                parser.Parse(null, aggregateNos);
                Assert.Fail("CommandLineArguments P2: Not validated parameter Method for null value");
            }
            catch (ArgumentNullException ex)
            {
                ApplicationLog.WriteLine("CommandLineArguments P2: Successfully validated Parameter Method for null value:", ex.Message);
            }
        }
예제 #7
0
        public void ValidateTypesInParameter()
        {
            AggregateNumbers     aggregateNos = new AggregateNumbers();
            CommandLineArguments parser       = new CommandLineArguments();

            //add parameters
            parser.Parameter(ArgumentType.Required, "bValue", ArgumentValueType.Bool, "bv", "bool");
            parser.Parameter(ArgumentType.Required, "iValue", ArgumentValueType.Int, "iv", "int");
            parser.Parameter(ArgumentType.Required, "fValue", ArgumentValueType.Int, "fv", "float");
            parser.Parameter(ArgumentType.Required, "dValue", ArgumentValueType.Int, "dv", "double");
            parser.Parameter(ArgumentType.DefaultArgument, "usValues", ArgumentValueType.MultipleUniqueStrings, "usv", "Unique strings");

            string[] args = { "/bValue:true", "/iValue:5", "/fValue:3.45", "/dValue:78.9876", "Str1", "Str2", "Str3" };
            parser.Parse(args, aggregateNos);
            Assert.IsNotNull(parser);
        }
        public void ValidateCommandLineArguments()
        {
            AggregateNumbers aggregateNos = new AggregateNumbers();
            CommandLineArguments parser = new CommandLineArguments();

            //add parameters
            parser.Parameter(ArgumentType.Required, "InputFile", ArgumentValueType.String, "i", "File containing numbers to add");
            parser.Parameter(ArgumentType.Required, "ResultFile", ArgumentValueType.String, "r", "File to store output");
            string inputfileName = Path.GetTempFileName().Replace(Path.GetTempPath(), "");
            string outputfileName = Path.GetTempFileName().Replace(Path.GetTempPath(), "");
            string[] args = { "-InputFile:" + inputfileName , "-ResultFile:" + outputfileName };
            parser.Parse(args, aggregateNos);
            Assert.IsNotNull(parser);
            Assert.IsTrue(aggregateNos.InputFile.Contains(inputfileName));
            Assert.IsTrue(aggregateNos.ResultFile.Contains(outputfileName));
        }
예제 #9
0
        public void ValidateCommandLineArguments()
        {
            AggregateNumbers     aggregateNos = new AggregateNumbers();
            CommandLineArguments parser       = new CommandLineArguments();

            //add parameters
            parser.Parameter(ArgumentType.Required, "InputFile", ArgumentValueType.String, "i", "File containing numbers to add");
            parser.Parameter(ArgumentType.Required, "ResultFile", ArgumentValueType.String, "r", "File to store output");
            string inputfileName  = Path.GetTempFileName().Replace(Path.GetTempPath(), "");
            string outputfileName = Path.GetTempFileName().Replace(Path.GetTempPath(), "");

            string[] args = { "/InputFile:" + inputfileName, "/ResultFile:" + outputfileName };
            parser.Parse(args, aggregateNos);
            Assert.IsNotNull(parser);
            Assert.IsTrue(aggregateNos.InputFile.Contains(inputfileName));
            Assert.IsTrue(aggregateNos.ResultFile.Contains(outputfileName));
        }
예제 #10
0
        public void InvalidateParseWithEmptyParam()
        {
            try
            {
                AggregateNumbers     aggregateNos = new AggregateNumbers();
                CommandLineArguments parser       = new CommandLineArguments();

                //add parameters
                parser.Parameter(ArgumentType.Required, "bValue", ArgumentValueType.Bool, "bv", "bool");
                parser.Parameter(ArgumentType.Required, "iValue", ArgumentValueType.Int, "iv", "int");

                string[] args = { "-:true", "-iValue:5" };
                parser.Parse(args, aggregateNos);
                Assert.Fail();
            }
            catch (ArgumentSyntaxException ex)
            {
                ApplicationLog.Write("Successfully caught ArgumentSyntaxException : " + ex.Message);
            }
        }
예제 #11
0
        public void InvalidateParseWithWrongParamName()
        {
            try
            {
                AggregateNumbers     aggregateNos = new AggregateNumbers();
                CommandLineArguments parser       = new CommandLineArguments();

                //add parameters
                parser.Parameter(ArgumentType.Required, "bValue", ArgumentValueType.Bool, "bv", "bool");
                parser.Parameter(ArgumentType.Required, "iValue", ArgumentValueType.Int, "iv", "int");
                parser.Parameter(ArgumentType.Required, "bArrValues", ArgumentValueType.Bool, "bmv", "boolArrValues");
                //pass char in integer array
                string[] args = { "/wrongname:true", "/iValue:5", "/bArrValues:true", "false" };
                parser.Parse(args, aggregateNos);
                Assert.Fail();
            }
            catch (ArgumentParserException ex)
            {
                ApplicationLog.Write("Successfully caught ArgumentNotFoundException : " + ex.Message);
            }
        }
예제 #12
0
        public void InvalidateParseWithDuplicateString()
        {
            try
            {
                AggregateNumbers     aggregateNos = new AggregateNumbers();
                CommandLineArguments parser       = new CommandLineArguments();

                //add parameters
                parser.Parameter(ArgumentType.Required, "bValue", ArgumentValueType.Bool, "bv", "bool");
                parser.Parameter(ArgumentType.Required, "iValue", ArgumentValueType.Int, "iv", "int");
                parser.Parameter(ArgumentType.Required, "fValue", ArgumentValueType.Int, "fv", "float");
                parser.Parameter(ArgumentType.Required, "dValue", ArgumentValueType.Int, "dv", "double");
                parser.Parameter(ArgumentType.DefaultArgument, "usValues", ArgumentValueType.MultipleUniqueStrings, "usv", "Unique strings");

                string[] args = { "-bValue:true", "-iValue:5", "-fValue:3.45", "-dValue:78.9876", "Str1", "Str2", "Str1" };
                parser.Parse(args, aggregateNos);
            }
            catch (DuplicateArgumentValueException ex)
            {
                ApplicationLog.WriteLine("Successfully caught DuplicateArgumentValueException : " + ex.Message);
            }
        }
        public void ValidateTypesInParameter()
        {
            AggregateNumbers aggregateNos = new AggregateNumbers();
            CommandLineArguments parser = new CommandLineArguments();

            //add parameters
            parser.Parameter(ArgumentType.Required, "bValue", ArgumentValueType.Bool, "bv", "bool");
            parser.Parameter(ArgumentType.Required, "iValue", ArgumentValueType.Int, "iv", "int");
            parser.Parameter(ArgumentType.Required, "fValue", ArgumentValueType.Int, "fv", "float");
            parser.Parameter(ArgumentType.Required, "dValue", ArgumentValueType.Int, "dv", "double");
            parser.Parameter(ArgumentType.DefaultArgument, "usValues", ArgumentValueType.MultipleUniqueStrings, "usv", "Unique strings");

            string[] args = { "-bValue:true", "-iValue:5", "-fValue:3.45", "-dValue:78.9876", "Str1", "Str2","Str3"};
            parser.Parse(args, aggregateNos);
            Assert.IsNotNull(parser);
        }
        public void InvalidateParseForNullArguments()
        {
            AggregateNumbers aggregateNos = new AggregateNumbers();
            CommandLineArguments parser = new CommandLineArguments();

            try
            {
                parser.Parse(null, aggregateNos);
                Assert.Fail("CommandLineArguments P2: Not validated parameter Method for null value");
            }
            catch (ArgumentNullException ex)
            {
                ApplicationLog.WriteLine("CommandLineArguments P2: Successfully validated Parameter Method for null value:", ex.Message);
            }
        }
        public void InvalidateParseWithEmptyParam()
        {
            try
            {
                AggregateNumbers aggregateNos = new AggregateNumbers();
                CommandLineArguments parser = new CommandLineArguments();

                //add parameters
                parser.Parameter(ArgumentType.Required, "bValue", ArgumentValueType.Bool, "bv", "bool");
                parser.Parameter(ArgumentType.Required, "iValue", ArgumentValueType.Int, "iv", "int");

                string[] args = { "-:true", "-iValue:5" };
                parser.Parse(args, aggregateNos);
                Assert.Fail();
            }
            catch (ArgumentSyntaxException ex)
            {
                ApplicationLog.Write("Successfully caught ArgumentSyntaxException : " + ex.Message);
            }
        }
        public void InvalidateParseWithWrongParamName()
        {
            try
            {
                AggregateNumbers aggregateNos = new AggregateNumbers();
                CommandLineArguments parser = new CommandLineArguments();

                //add parameters
                parser.Parameter(ArgumentType.Required, "bValue", ArgumentValueType.Bool, "bv", "bool");
                parser.Parameter(ArgumentType.Required, "iValue", ArgumentValueType.Int, "iv", "int");
                parser.Parameter(ArgumentType.Required, "bArrValues", ArgumentValueType.Bool, "bmv", "boolArrValues");
                //pass char in integer array
                string[] args = { "/wrongname:true", "/iValue:5", "/bArrValues:true", "false" };
                parser.Parse(args, aggregateNos);
                Assert.Fail();
            }
            catch (ArgumentParserException ex)
            {
                ApplicationLog.Write("Successfully caught ArgumentNotFoundException : " + ex.Message);
            }
        }
        public void InvalidateParseWithDuplicateString()
        {
            try
            {
                AggregateNumbers aggregateNos = new AggregateNumbers();
                CommandLineArguments parser = new CommandLineArguments();

                //add parameters
                parser.Parameter(ArgumentType.Required, "bValue", ArgumentValueType.Bool, "bv", "bool");
                parser.Parameter(ArgumentType.Required, "iValue", ArgumentValueType.Int, "iv", "int");
                parser.Parameter(ArgumentType.Required, "fValue", ArgumentValueType.Int, "fv", "float");
                parser.Parameter(ArgumentType.Required, "dValue", ArgumentValueType.Int, "dv", "double");
                parser.Parameter(ArgumentType.DefaultArgument, "usValues", ArgumentValueType.MultipleUniqueStrings, "usv", "Unique strings");

                string[] args = { "-bValue:true", "-iValue:5", "-fValue:3.45", "-dValue:78.9876", "Str1", "Str2","Str1"};
                parser.Parse(args, aggregateNos);
            }
            catch (DuplicateArgumentValueException ex)
            {
                ApplicationLog.WriteLine("Successfully caught DuplicateArgumentValueException : " + ex.Message);
            }
        }
        public void InvalidateParseWithMissingRequiredParam()
        {
            try
            {
                AggregateNumbers aggregateNos = new AggregateNumbers();
                CommandLineArguments parser = new CommandLineArguments();

                //add parameters
                parser.Parameter(ArgumentType.Required, "bValue", ArgumentValueType.Bool, "bv", "bool");
                parser.Parameter(ArgumentType.Required, "iValue", ArgumentValueType.Int, "iv", "int");
                parser.Parameter(ArgumentType.Required, "bArrValues", ArgumentValueType.Bool, "bmv", "boolArrValues");
                parser.Parameter(ArgumentType.Required, "fValue", ArgumentValueType.Int, "fv", "float");
                parser.Parameter(ArgumentType.Required, "dValue", ArgumentValueType.Int, "dv", "double");
                parser.Parameter(ArgumentType.DefaultArgument, "usValues", ArgumentValueType.MultipleUniqueStrings, "usv", "Unique strings");

                //not including the first required param
                string[] args = { "-iValue:5", "-bArrValues:true" ,"false",
                            "-fValue:3.45", "-dValue:78.9876", "Str1", "Str2","Str3"};
                parser.Parse(args, aggregateNos);
                Assert.Fail();
            }
            catch (RequiredArgumentMissingException ex)
            {
                ApplicationLog.WriteLine("Successfully caught RequiredArgumentMissingException : " + ex.Message);
            }
        }