public void CmdArgs_Help1()
        {
            var argsArray = new[] {
                new [] { "?" },
                new [] { "?", "asdf" },
                new [] { "-?" },
                new [] { "-?", "asdf" },
                new [] { "-h" },
                new [] { "-h", "asdf" },
                new [] { "-H" },
                new [] { "-H", "asdf" },
                new [] { "/?" },
                new [] { "/?", "asdf" },
                new [] { "/h" },
                new [] { "/h", "asdf" },
                new [] { "/H" },
                new [] { "/H", "asdf" },
                new [] { "-help" },
                new [] { "-help", "asdf" },
                new [] { "--help" },
                new [] { "--help", "asdf" }
            };

            foreach (var args in argsArray)
            {
                var settings = new Args1();

                var parser = ArgumentParser.Parse(args, settings);

                Assert.IsTrue(parser.IsHelp);
            }
        }
        public void CmdArgs_Usage1()
        {
            var settings = new Args1();

            var parser = ArgumentParser.Parse(new[] { "?" }, settings);

            var expected = "SenseNet.Tools.Tests [Arg1] [Arg2] [-A:Boolean] [-B:Boolean] [-C:Boolean] [-INT:Int32] [-STRING:String] [?]";
            var usage    = parser.GetUsage();

            Assert.AreEqual(expected, usage);
        }
        public void CmdArgs_Acceptance5()
        {
            var args        = new[] { "-STRING", "asdf", "-INT", "42" };
            var settings    = new Args1();
            var settingsAcc = new PrivateObject(settings);

            ArgumentParser.Parse(args, settings);

            Assert.AreEqual(false, settings.A);
            Assert.AreEqual(false, settings.B);
            Assert.AreEqual(false, settings.A);
            Assert.AreEqual(null, settings.Source);
            Assert.AreEqual(null, settings.Target);
            Assert.AreEqual("asdf", (string)settingsAcc.GetFieldOrProperty("StringParam1"));
            Assert.AreEqual(42, settings.IntParam1);
        }
        public void CmdArgs_Acceptance1()
        {
            var args        = new[] { "/a", "/string:asdf", "/int:42" };
            var settings    = new Args1();
            var settingsAcc = new PrivateObject(settings);

            ArgumentParser.Parse(args, settings);

            Assert.AreEqual(true, settings.A);
            Assert.AreEqual(false, settings.B);
            Assert.AreEqual(false, (bool)settingsAcc.GetProperty("C"));
            Assert.AreEqual(null, settings.Source);
            Assert.AreEqual(null, settings.Target);
            Assert.AreEqual("asdf", (string)settingsAcc.GetFieldOrProperty("StringParam1"));
            Assert.AreEqual(42, settings.IntParam1);
        }
        public void CmdArgs_Error_MissingValue()
        {
            var args     = new[] { "-INT" };
            var settings = new Args1();

            ParsingException ex = null;

            try
            {
                ArgumentParser.Parse(args, settings);
                Assert.Fail(); // must have an error
            }
            catch (ParsingException e)
            {
                ex = e;
            }

            Assert.AreEqual(ResultState.MissingValue, ex.ErrorCode);
        }
        public void CmdArgs_Error_UnknownArgument()
        {
            var args     = new[] { "-UNKNOWN:asdf" };
            var settings = new Args1();

            ParsingException ex = null;

            try
            {
                ArgumentParser.Parse(args, settings);
                Assert.Fail(); // must have an error
            }
            catch (ParsingException e)
            {
                ex = e;
            }

            Assert.AreEqual(ResultState.UnknownArgument, ex.ErrorCode);
        }
        public void CmdArgs_Acceptance8()
        {
            var defaultSource = "defaultSource";
            var defaultInt    = 444;

            var args     = new string[0];
            var settings = new Args1 {
                IntParam1 = defaultInt, Source = defaultSource
            };
            var settingsAcc = new PrivateObject(settings);

            ArgumentParser.Parse(args, settings);

            Assert.AreEqual(false, settings.A);
            Assert.AreEqual(false, settings.B);
            Assert.AreEqual(false, settings.A);
            Assert.AreEqual(defaultSource, settings.Source);
            Assert.AreEqual(null, settings.Target);
            Assert.AreEqual(null, (string)settingsAcc.GetFieldOrProperty("StringParam1"));
            Assert.AreEqual(defaultInt, settings.IntParam1);
        }