SimulateConsoleInput() public static méthode

public static SimulateConsoleInput ( string input ) : TestConsoleProvider
input string
Résultat TestConsoleProvider
        public void TestREPLReset()
        {
            SetupCleanup.ClearAttributeCache();
            var provider = TestConsoleProvider.SimulateConsoleInput("-b{enter}-s a{enter}quit");
            var def      = new CommandLineArgumentsDefinition(typeof(TestArgsWithREPL));
            var boolArg  = def.FindMatchingArgument("b");

            Assert.IsNotNull(boolArg);

            bool first         = true;
            bool validatedBoth = false;
            var  interceptor   = new AfterInvokeInterceptor((context) =>
            {
                if (first)
                {
                    first = false;
                    Assert.IsTrue((bool)boolArg.RevivedValue);
                }
                else
                {
                    Assert.IsNull(boolArg.RevivedValue);
                    validatedBoth = true;
                }
            });

            def.Metadata.Add(interceptor);

            var finalResult = Args.InvokeMain(def, "$");

            Assert.IsTrue(validatedBoth);
            Assert.IsFalse((finalResult.Value as TestArgsWithREPL).BoolParam);
        }
        public void TestBackspace()
        {
            TestConsoleProvider.SimulateConsoleInput("\b-sot\bmeparam Adam");
            var parsed = Args.Parse <TestArgs>("$");

            Assert.AreEqual("Adam", parsed.SomeParam);
        }
        public void TestArgAwareCompletionPositive()
        {
            TestConsoleProvider.SimulateConsoleInput("-name a\t");
            var parsed = Args.Parse <ArgAwareCompletionArgs>("$");

            Assert.AreEqual("Adam", parsed.Name);
        }
        public void TestAskOnceOnPromptIfEmpty()
        {
            TestConsoleProvider.SimulateConsoleInput("{enter}{enter}Adam{enter}");
            var parsed = Args.Parse <AskOnceArgs>("$");

            Assert.AreEqual(null, parsed.Name);
        }
        public void TestArrowAndDelete()
        {
            TestConsoleProvider.SimulateConsoleInput("-sot{left}{right}{left}{delete}meparam Adam");
            var parsed = Args.Parse <TestArgs>("$");

            Assert.AreEqual("Adam", parsed.SomeParam);
        }
        public void TestArgAwareCompletionNegative()
        {
            TestConsoleProvider.SimulateConsoleInput("-address a\t");
            var parsed = Args.Parse <ArgAwareCompletionArgs>("$");

            Assert.AreNotEqual("Adam", parsed.Address);
        }
        public void TestCustomCompletion()
        {
            TestConsoleProvider.SimulateConsoleInput("-som\t Abd\t");
            var parsed = Args.Parse <TestArgs>("$");

            Assert.AreEqual("Abdelhamed", parsed.SomeParam);
        }
        public void TestArgRequiredCancelBehaviorWithREPLAndConditional()
        {
            TestConsoleProvider.SimulateConsoleInput("-e{enter}{escape}-s\t thearg -e{enter}quit");
            var action = Args.InvokeMain <ArgsWithRequiredAndREPLAndConditional>("$");

            Assert.AreEqual("thearg", action.Args.SomeArg);
        }
        public void TestSecureStringBasic()
        {
            TestConsoleProvider.SimulateConsoleInput("mysecretpassword");
            var parsed = Args.Parse <TestArgs>();

            Assert.AreEqual("mysecretpassword", parsed.Password.ConvertToNonsecureString());
        }
        public void TestEnumShortcutsCompletion()
        {
            TestConsoleProvider.SimulateConsoleInput("-e\t numb\t");
            var parsed = Args.Parse <TestArgsWithEnum>("$");

            Assert.AreEqual(EnumWithShortcuts.One, parsed.Enum);
        }
        public void TestKeepAskingOnPromptIfEmpty()
        {
            TestConsoleProvider.SimulateConsoleInput("{enter}{enter}Adam{enter}");
            var parsed = Args.Parse <KeepAskingArgs>("$");

            Assert.AreEqual("Adam", parsed.Name);
        }
        public void TestMultiTabCyclingBackwards()
        {
            TestConsoleProvider.SimulateConsoleInput("\t\t{shift}\t 50 \t\t stringval \t\t");
            var parsed = Args.Parse <TestArgs>("$");

            Assert.AreEqual("stringval", parsed.SomeParam);
            Assert.AreEqual(50, parsed.AnotherParam);
        }
        public void TestHomeAndEnd()
        {
            TestConsoleProvider.SimulateConsoleInput("someparam Adam{home}-{end} -a 100");
            var parsed = Args.Parse <TestArgs>("$");

            Assert.AreEqual("Adam", parsed.SomeParam);
            Assert.AreEqual(100, parsed.AnotherParam);
        }
        public void TestBasicCompletion()
        {
            TestConsoleProvider.SimulateConsoleInput("-som\t Adam -an\t 100");
            var parsed = Args.Parse <TestArgs>("$");

            Assert.AreEqual("Adam", parsed.SomeParam);
            Assert.AreEqual(100, parsed.AnotherParam);
        }
        public void TestProperParsingOfQuotedArgs()
        {
            TestConsoleProvider.SimulateConsoleInput("-s \"Adam Abdelhamed\" -a 100");
            var parsed = Args.Parse <TestArgs>("$");

            Assert.AreEqual("Adam Abdelhamed", parsed.SomeParam);
            Assert.AreEqual(100, parsed.AnotherParam);
        }
        public void TestREPLCancelled()
        {
            var provider = TestConsoleProvider.SimulateConsoleInput("quit");
            var ret      = Args.InvokeMain <TestArgsWithREPL>("$");

            Assert.IsNotNull(ret);
            Assert.IsTrue(ret.Cancelled);
        }
        public void TestMultiTabCycling()
        {
            // First tab goes to 'anotherParam', second tab advances since the first tab was completed by empty string
            TestConsoleProvider.SimulateConsoleInput("\t 50 \t\t stringval");
            var parsed = Args.Parse <TestArgs>("$");

            Assert.AreEqual("stringval", parsed.SomeParam);
            Assert.AreEqual(50, parsed.AnotherParam);
        }
        public void TestShiftTabFileSystem()
        {
            using (var temps = new TempFiles())
            {
                temps.CreateDirectory("DummyFolder", "1", "2", "3", "4");

                TestConsoleProvider.SimulateConsoleInput("-som\t Dumm\t\\\t\t\t{shift}\t{shift}\t");
                var parsed = Args.Parse <TestArgs>("$");
                Assert.AreEqual(Path.Combine(Environment.CurrentDirectory, "DummyFolder\\1"), parsed.SomeParam);
            }
        }
        public void TestHistoryBasic()
        {
            ClearHistory();
            TestConsoleProvider.SimulateConsoleInput("-s historytest");
            var parsed = Args.Parse <TestArgs>("$");

            TestConsoleProvider.SimulateConsoleInput("{up}");
            parsed = Args.Parse <TestArgs>("$");
            Assert.AreEqual("historytest", parsed.SomeParam);
            ClearHistory();
        }
 public void TestSecureStringNoCommandLine()
 {
     try
     {
         TestConsoleProvider.SimulateConsoleInput("mysecretpassword");
         var parsed = Args.Parse <TestArgs>("-p", "passwordFromCommandLine");
         Assert.Fail("An exception should have been thrown");
     }
     catch (ArgException ex)
     {
         Assert.IsTrue(ex.Message.ToLower().Contains("cannot be specified on the command line"));
     }
 }
 public void TestArgRequiredCancelBehaviorWithNoREPLAndConditional()
 {
     try
     {
         TestConsoleProvider.SimulateConsoleInput("{escape}");
         var action = Args.InvokeMain <ArgsWithRequiredAndNoREPLAndConditional>("-e");
         Assert.Fail("An exception should have been thrown");
     }
     catch (MissingArgException ex)
     {
         Assert.IsTrue(ex.Message.ToLower().Contains("somearg"));
         Console.WriteLine("Yay!");
     }
 }
 public void TestSecureStringIsReadOnly()
 {
     try
     {
         TestConsoleProvider.SimulateConsoleInput("mysecretpassword");
         var parsed = Args.Parse <TestArgs>();
         parsed.Password.SecureString.AppendChar('$');
         Assert.Fail("An exception should have been thrown");
     }
     catch (InvalidOperationException ex)
     {
         // Expected
     }
 }
        public void TestREPL()
        {
            var provider = TestConsoleProvider.SimulateConsoleInput("-som\t Adam{enter}cls{enter}-some\t Abdelhamed{enter}quit");

            int clearCount = 0;

            provider.ClearHappened += () => { clearCount++; };

            Args.InvokeMain <TestArgsWithREPL>("$");
            Assert.AreEqual(2, TestArgsWithREPL.SomeParamValues.Count);
            Assert.AreEqual("Adam", TestArgsWithREPL.SomeParamValues[0]);
            Assert.AreEqual("Abdelhamed", TestArgsWithREPL.SomeParamValues[1]);
            Assert.AreEqual(1, clearCount);
        }
        public void TestHistoryCleanup()
        {
            ClearHistory();
            for (int i = 0; i < MaxHistory + 1; i++)
            {
                TestConsoleProvider.SimulateConsoleInput("-s historytest" + i);
                var parsed = Args.Parse <TestArgs>("$");
            }

            TestConsoleProvider.SimulateConsoleInput(Repeat("{up}", MaxHistory + 1));
            var parsedAgain = Args.Parse <TestArgs>("$");

            Assert.AreEqual("historytest10", parsedAgain.SomeParam);
            ClearHistory();
        }
        public void TestModeledActionREPL()
        {
            int invokeCount = 0;

            CommandLineArgumentsDefinition definition = new CommandLineArgumentsDefinition();

            definition.Metadata.Add(new TabCompletion()
            {
                REPL = true, Indicator = "$"
            });

            var action = new CommandLineAction((d) =>
            {
                Assert.AreEqual("go", d.SpecifiedAction.DefaultAlias);
                if (invokeCount == 0)
                {
                    Assert.AreEqual("Hawaii", d.SpecifiedAction.Arguments[0].RevivedValue);
                }
                else if (invokeCount == 1)
                {
                    Assert.AreEqual("Mexico", d.SpecifiedAction.Arguments[0].RevivedValue);
                }
                invokeCount++;
            });

            action.Aliases.Add("go");
            action.Description = "A simple action";


            definition.Actions.Add(action);

            var destination = new CommandLineArgument(typeof(string), "destination");

            destination.Metadata.Add(new ArgRequired());
            destination.Description = "The place to go to";

            action.Arguments.Add(destination);

            var provider = TestConsoleProvider.SimulateConsoleInput("g\t -dest\t Hawaii{enter}go -dest\t Mexico{enter}quit");

            Args.InvokeAction(definition, "$");
            Assert.AreEqual(2, invokeCount);
        }