예제 #1
0
        public void NoSuchLongOption()
        {
            var c = new Commands();

            using (var o = new CaptureConsoleOutput())
            {
                var e = GetOpt.Run(c, new[] { "c", "s", "1", "1", "--printer" });
                Assert.AreEqual(e, -1);
            }
        }
예제 #2
0
        public void OptionsAfterArguments()
        {
            var hw = new HelloWorld();

            using (var c = new CaptureConsoleOutput())
            {
                var e = GetOpt.Run(hw, new[] { "Donald", "--cordially" });
                Assert.AreEqual(0, e);
                StringAssert.Contains("dear Donald", c.output.ToString());
            }
        }
예제 #3
0
 public void HandleExceptionsInAsyncMethodsCorrectly()
 {
     using (var c = new CaptureConsoleOutput())
     {
         var hw       = new TestAsyncApp();
         var exitCode = Sidi.GetOpt.GetOpt.Run(hw, new[] { "TestAsyncWithException" });
         Assert.IsTrue(hw.TestAsyncWasCalled);
         Assert.AreEqual(-1, exitCode);
         StringAssert.Contains(TestAsyncApp.anErrorOccured, c.error.ToString());
     }
 }
예제 #4
0
        public void OptionsAfterArgumentsAreConsidered()
        {
            var commands = new Commands();

            using (var c = new CaptureConsoleOutput())
            {
                Assert.AreEqual(0, GetOpt.Run(commands, new[] { "calculator", "sum", "1", "2", "3", "--print" }));
                Assert.AreEqual(true, commands.Calculator.Print);
                Assert.AreEqual(6.0, commands.Calculator.Result);
            }
        }
예제 #5
0
        public void ShowHelpIfNoArgumentsInMultiCommandMode()
        {
            var calc = new Calculator();

            using (var c = new CaptureConsoleOutput())
            {
                var e = GetOpt.Run(calc, new string[] { });
                Assert.AreEqual(0, e);
                Assert.IsTrue(c.output.ToString().StartsWith("Usage:"));
            }
        }
예제 #6
0
        public void ShowHelp()
        {
            var calc = new Calculator();

            using (var c = new CaptureConsoleOutput())
            {
                var e = GetOpt.Run(calc, new[] { "--help" });
                Assert.AreEqual(0, e);
                Assert.IsTrue(c.output.ToString().StartsWith("Usage:"));
            }
        }
예제 #7
0
        public void AbbreviateCommands()
        {
            var c = new Commands();

            using (var o = new CaptureConsoleOutput())
            {
                var e = GetOpt.Run(c, new[] { "c", "s", "1", "1", "--pr", "-p" });
                Assert.AreEqual(e, 0);
                Assert.AreEqual(2.0, c.Calculator.Result);
            }
        }
예제 #8
0
 public void EnumHelp()
 {
     using (var c = new CaptureConsoleOutput())
     {
         var a = new ValueParserTestApplication();
         Assert.AreEqual(0, Sidi.GetOpt.GetOpt.Run(a, new[] { "--help" }));
         foreach (var n in Enum.GetNames(typeof(ValueParserTestApplication.Fruits)))
         {
             StringAssert.Contains(n, c.output.ToString());
         }
     }
 }
예제 #9
0
 public void CustomExceptionHandler()
 {
     using (var c = new CaptureConsoleOutput())
     {
         var hw = new TestAsyncApp();
         var go = new Sidi.GetOpt.GetOpt
         {
             Application = hw,
             Arguments   = new[] { "TestAsyncWithException" },
             OnException = (e) => - 123
         };
         var exitCode = go.Run();
         Assert.IsTrue(hw.TestAsyncWasCalled);
         Assert.AreEqual(-123, exitCode);
     }
 }
예제 #10
0
        public void ParseValues()
        {
            using (var c = new CaptureConsoleOutput())
            {
                var a = new ValueParserTestApplication();
                Assert.AreEqual(0, Sidi.GetOpt.GetOpt.Run(a, new[] { "--birthday=2394-03-01" }));
                Assert.AreEqual(new DateTime(2394, 3, 1, 0, 0, 0), a.Birthday);

                Assert.AreEqual(0, Sidi.GetOpt.GetOpt.Run(a, new[] { "--duration=1.2:3:4.5" }));
                Assert.AreEqual(new TimeSpan(1, 2, 3, 4, 500), a.Duration);

                Assert.AreEqual(0, Sidi.GetOpt.GetOpt.Run(a, new[] { "--duration=0:10" }));
                Assert.AreEqual(TimeSpan.FromMinutes(10), a.Duration);

                Assert.AreEqual(0, Sidi.GetOpt.GetOpt.Run(a, new[] { "--fruit=orange" }));
                Assert.AreEqual(ValueParserTestApplication.Fruits.Orange, a.Fruit);

                Assert.AreEqual(0, Sidi.GetOpt.GetOpt.Run(a, new[] { "--fruit=o" }));
                Assert.AreEqual(ValueParserTestApplication.Fruits.Orange, a.Fruit);
            }
        }