public void ParseBadArguments()
 {
     CounterControl prog = new CounterControl();
     Assert.IsFalse(prog.ParseArguments(new string[] { "/xyz" }));
     Assert.IsFalse(prog.ParseArguments(new string[] { "/xyz", "/r", "/u" }));
     Assert.IsFalse(prog.ParseArguments(new string[] { "/r", "/u", "/xyz" }));
 }
示例#2
0
        static int Main(string[] args)
        {
            var prog = new CounterControl();

            // Program ident
            AssemblyName thisProgram = Assembly.GetExecutingAssembly().GetName();
            var          progTitle   = string.Format("{0} v{1}", thisProgram.Name, thisProgram.Version.ToString());

            ConsoleText.WriteStatus(progTitle);
            Console.Title = progTitle;

            int result;

            if (!prog.ParseArguments(args))
            {
                prog.PrintUsage();
                result = -1;
            }
            else
            {
                result = prog.Run();
            }

            if (prog.PauseAtEnd)
            {
                Console.WriteLine("Press any key to exit");
                Console.ReadKey();
            }

            return(result);
        }
示例#3
0
        static int Main(string[] args)
        {
            var prog = new CounterControl();

            // Program ident
            AssemblyName thisProgram = typeof(Program).GetTypeInfo().Assembly.GetName();
            var progTitle = string.Format("{0} v{1}", thisProgram.Name, thisProgram.Version.ToString());
            ConsoleText.WriteStatus(progTitle);
            Console.Title = progTitle;

            int result;
            if (!prog.ParseArguments(args))
            {
                prog.PrintUsage();
                result = -1;
            }
            else
            {
                result = prog.Run();
            }

            if (prog.PauseAtEnd)
            {
                Console.WriteLine("Press any key to exit");
                Console.ReadKey();
            }

            return result;
        }
 public void ParseUsageArguments()
 {
     CounterControl prog = new CounterControl();
     Assert.IsFalse(prog.ParseArguments(new string[] { "/?" }));
     Assert.IsFalse(prog.ParseArguments(new string[] { "/help" }));
     Assert.IsFalse(prog.ParseArguments(new string[] { "/?", "/r", "/u" }));
     Assert.IsFalse(prog.ParseArguments(new string[] { "/r", "/u", "/?" }));
 }
        public void ParseMultipleArgs()
        {
            CounterControl prog = new CounterControl();

            Assert.IsTrue(prog.ParseArguments(new string[] { "/r", "/u" }));
            Assert.IsTrue(prog.Unregister);

            // Last arg wins
            Assert.IsTrue(prog.ParseArguments(new string[] { "/u", "/r" }));
            Assert.IsFalse(prog.Unregister);
        }
        public void ParseArguments()
        {
            CounterControl prog = new CounterControl();
            
            Assert.IsTrue(prog.ParseArguments(new string[] { "/r" }));
            Assert.IsFalse(prog.Unregister);
            Assert.IsTrue(prog.ParseArguments(new string[] { "/register" }));
            Assert.IsFalse(prog.Unregister);

            Assert.IsTrue(prog.ParseArguments(new string[] { "/u" }));
            Assert.IsTrue(prog.Unregister);
            Assert.IsTrue(prog.ParseArguments(new string[] { "/unregister" }));
            Assert.IsTrue(prog.Unregister);
        }
 public void DoNotNeedsRunAsAdminForUnknownCommand()
 {
     CounterControl prog = new CounterControl();
     prog.ParseArguments(new string[] { "/xyz" });
     Assert.IsFalse(prog.NeedRunAsAdministrator);
 }
 public void NeedsRunAsAdminForUnregisterCommand()
 {
     CounterControl prog = new CounterControl();
     prog.ParseArguments(new string[] { "/u" });
     Assert.IsTrue(prog.NeedRunAsAdministrator);
 }
 public void ParseNoArgs()
 {
     CounterControl prog = new CounterControl();
     Assert.True(prog.ParseArguments(new string[] { }));
     Assert.False(prog.Unregister);
 }