public void Array_Numbers() { var printer = new Printer(); var sample = new Sample_08 { Printer = printer }; // array // Parser.Run(new[] { "printnumbers", "/numbers:1,2,3", "/prefix:test_", }, sample); Assert.AreEqual(3, printer.PrintedTexts.Count); Assert.AreEqual("test_1", printer.PrintedTexts[0]); Assert.AreEqual("test_2", printer.PrintedTexts[1]); Assert.AreEqual("test_3", printer.PrintedTexts[2]); // JSON // Parser.Run(new[] { "printnumbers", "/numbers:[1,2,3]", "/prefix:test_", }, sample); Assert.AreEqual(6, printer.PrintedTexts.Count); Assert.AreEqual("test_1", printer.PrintedTexts[3]); Assert.AreEqual("test_2", printer.PrintedTexts[4]); Assert.AreEqual("test_3", printer.PrintedTexts[5]); }
public void Array_Numbers() { var printer = new Printer(); var sample = new Sample_08 { Printer = printer }; // array // Parser.Run(new[] { "printnumbers", "/numbers:1,2,3", "/prefix:test_", }, sample); Expect(printer.PrintedTexts, Is.EqualTo(new[] { "test_1", "test_2", "test_3" })); // JSON // Parser.Run(new[] { "printnumbers", "/numbers:[1,2,3]", "/prefix:test_", }, sample); Expect(printer.PrintedTexts, Is.EqualTo(new[] { "test_1", "test_2", "test_3", "test_1", "test_2", "test_3" })); }
public void Array_Enum() { var printer = new Printer(); var sample = new Sample_08 { Printer = printer }; // using array convertion // Parser.Run(new[] { "printenums", "/enums:Upper,Lower", "/prefix:test_", }, sample); Expect(printer.PrintedTexts, Is.EqualTo(new[] { "test_Upper", "test_Lower" })); // using JSON deserialization // Parser.Run(new[] { "printenums", "/enums:['Upper','Lower']", "/prefix:test_", }, sample); Expect(printer.PrintedTexts, Count.EqualTo(4)); Expect(printer.PrintedTexts[2], Is.EqualTo("test_Upper")); Expect(printer.PrintedTexts[3], Is.EqualTo("test_Lower")); }
public void Array_Enum() { var printer = new Printer(); var sample = new Sample_08 { Printer = printer }; // using array convertion // Parser.Run(new[] { "printenums", "/enums:Upper,Lower", "/prefix:test_", }, sample); Assert.AreEqual(2, printer.PrintedTexts.Count); Assert.AreEqual("test_Upper", printer.PrintedTexts[0]); Assert.AreEqual("test_Lower", printer.PrintedTexts[1]); // using JSON deserialization // Parser.Run(new[] { "printenums", "/enums:['Upper','Lower']", "/prefix:test_", }, sample); Assert.AreEqual(4, printer.PrintedTexts.Count); Assert.AreEqual("test_Upper", printer.PrintedTexts[2]); Assert.AreEqual("test_Lower", printer.PrintedTexts[3]); }
public void Array_Enum_NoInput() { var printer = new Printer(); var sample = new Sample_08 { Printer = printer }; Parser.Run(new[] { "printenums", "/prefix:test_", }, sample); Assert.AreEqual(0, printer.PrintedTexts.Count); }
public void Array_Enum_NoInput() { var printer = new Printer(); var sample = new Sample_08 { Printer = printer }; Parser.Run(new[] { "printenums", "/prefix:test_", }, sample); Expect(printer.PrintedTexts, Is.Empty); }
public void Required_Exception() { var printer = new Printer(); var sample = new Sample_07 { Printer = printer }; Expect(() => Parser.Run(new[] { "print", "/message:world", }, sample), Throws.InstanceOf<CommandLineParserException>()); }
public void Array_Strings_WithSeparator() { var printer = new Printer(); var sample = new Sample_69 { Printer = printer }; // array // Parser.Run(new[] { "print", "/messages:a|b|c", "/prefix:test_", }, sample); Expect(printer.PrintedTexts, Is.EqualTo(new[] {"test_a", "test_b", "test_c"})); sample.Printer.Reset(); Parser.Run(new[] { "printnumbers", "/numbers:1-78-100", "/prefix:test_", }, sample); Expect(printer.PrintedTexts, Is.EqualTo(new[] { "test_1", "test_78", "test_100" })); }
public void RegisterParameterHandler_CallsTheHandler_UseTheValue() { var printer = new Printer(); var sample = new Sample_02 { Printer = printer }; var debug = String.Empty; var p = new Parser<Sample_02>(); p.Register.ParameterHandler<string>("debug", str => debug = str); p.Run("print /c=5 /msg=test /prefix=hello_ /debug=true".Split(' '), sample); Expect(debug, Is.EqualTo("true")); }
public void Execute_Verb() { var printer = new Printer(); var sample = new Sample_02 { Printer = printer }; Parser.Run(new[] { "print", "/c=5", "/msg=test", "/prefix=hello_", }, sample); Assert.AreEqual(5, printer.PrintedTexts.Count); Assert.IsTrue(printer.PrintedTexts.All(t => t.Equals("hello_test"))); }
public void Interception_Registered_Called() { var printer = new Printer(); var sample = new Sample_02 { Printer = printer }; var p = new Parser<Sample_02>(); var preInterceptorCalled = false; var postInterceptorCalled = false; p.Register.PreVerbInterceptor(c => preInterceptorCalled = true); p.Register.PostVerbInterceptor(c => postInterceptorCalled = true); p.Run(new[] { "print", "/c=5", "/msg=test", "/prefix=hello_", }, sample); Assert.AreEqual(5, printer.PrintedTexts.Count); Assert.IsTrue(printer.PrintedTexts.All(t => t.Equals("hello_test"))); Assert.IsTrue(preInterceptorCalled); Assert.IsTrue(postInterceptorCalled); }
public void Foo(string x, Uri u) { Printer.Print(x + u); }
public void Print() { Printer.Print("x"); }
public void Print([DefaultValue("bar")] string foo) { Printer.Print(foo); }
public void Help(string help) { Printer.Print(help); }
public void Zoo([DefaultValue("5")] int n) { Printer.Print(n.ToString()); }
public void Foo(string x, Guid g) { Printer.Print(x + g); }
public void Help(string h, string boo) { Printer.Print("help"); }
public void Execute_DefaultVerb_Switch() { var printer = new Printer(); var sample = new Sample_02 { Printer = printer }; Parser.Run(new[] { "/c=5", "/msg=test", "/prefix=hello_", "/u", }, sample); Assert.AreEqual(5, printer.PrintedTexts.Count); Assert.IsTrue(printer.PrintedTexts.All(t => t.Equals("HELLO_TEST"))); }
public void Foo() { Printer.Print("works!"); }
public void Help(string h) { Printer.Print("help"); }
public void Foo(string x, int y) { Printer.Print("works!"); }
public void Execute_NoParameterValue() { var printer = new Printer(); var sample = new Sample_02 { Printer = printer }; Parser.Run(new[] { "print", "/c=5", "/msg=", "/prefix=hello_", }, sample); }
public void Print(string foo) { Printer.Print(foo); }
public void Array_Strings() { var printer = new Printer(); var sample = new Sample_08 { Printer = printer }; // array // Parser.Run(new[] { "print", "/messages:a,b,c", "/prefix:test_", }, sample); Assert.AreEqual(3, printer.PrintedTexts.Count); Assert.AreEqual("test_a", printer.PrintedTexts[0]); Assert.AreEqual("test_b", printer.PrintedTexts[1]); Assert.AreEqual("test_c", printer.PrintedTexts[2]); // JSON // Parser.Run(new[] { "print", "/messages:['a','b','c']", "/prefix:test_" }, sample); Assert.AreEqual(6, printer.PrintedTexts.Count); Assert.AreEqual("test_a", printer.PrintedTexts[3]); Assert.AreEqual("test_b", printer.PrintedTexts[4]); Assert.AreEqual("test_c", printer.PrintedTexts[5]); }
public void Array_Strings_WithSeparator() { var printer = new Printer(); var sample = new Sample_69 { Printer = printer }; // array // Parser.Run(new[] { "print", "/messages:a|b|c", "/prefix:test_", }, sample); Assert.AreEqual(3, printer.PrintedTexts.Count); Assert.AreEqual("test_a", printer.PrintedTexts[0]); Assert.AreEqual("test_b", printer.PrintedTexts[1]); Assert.AreEqual("test_c", printer.PrintedTexts[2]); sample.Printer.Reset(); Parser.Run(new[] { "printnumbers", "/numbers:1-78-100", "/prefix:test_", }, sample); Assert.AreEqual(3, printer.PrintedTexts.Count); Assert.AreEqual("test_1", printer.PrintedTexts[0]); Assert.AreEqual("test_78", printer.PrintedTexts[1]); Assert.AreEqual("test_100", printer.PrintedTexts[2]); }
public void MapArguments_InvalidPrefix_Exception() { var printer = new Printer(); var sample = new Sample_02 { Printer = printer }; Parser.Run(new[] { "print", "*c=5", "/msg=test", "/prefix=hello_", }, sample); }
public void RegisteredVerbInterceptorTest() { var printer = new Printer(); var sample = new Sample_02 { Printer = printer }; var list = new List<string>(); var p = new Parser<Sample_02>(); p.RegisterInterceptor(x => list.Add(x.Verb)); p.Run("print /c=5 /msg=test /prefix=hello_".Split(' '), sample); Assert.AreEqual(1, list.Count()); Assert.AreEqual("print", list[0]); }
public void RegisterParameterHandler_CallsTheHandler_IgnoreTheValue() { var printer = new Printer(); var sample = new Sample_02 { Printer = printer }; int x = 0; var p = new Parser<Sample_02>(); // with and without description for coverage // p.Register.ParameterHandler("dec,d", delegate { x--; }); p.Register.ParameterHandler("inc", delegate { x++; }, "description"); p.Run("print /c=5 /msg=test /prefix=hello_ /inc".Split(' '), sample); Expect(x, Is.EqualTo(1)); p.Run("print /c=5 /msg=test /prefix=hello_ /dec".Split(' '), sample); p.Run("print /c=5 /msg=test /prefix=hello_ /d".Split(' '), sample); Expect(x, Is.EqualTo(-1)); }
public void Required_Exception() { try { var printer = new Printer(); var sample = new Sample_07 { Printer = printer }; Parser.Run(new[] { "print", "/message:world", }, sample); Assert.Fail(); } catch (CommandLineException) { } }
public void Required() { var printer = new Printer(); var sample = new Sample_07 { Printer = printer }; Parser.Run(new[] { "print", "/prefix:hello", }, sample); Assert.AreEqual(1, printer.PrintedTexts.Count); Assert.AreEqual("HELLO", printer.PrintedTexts[0]); }
public void Foo(int h) { Printer.Print("a"); }
public void ShowHelp(string help) { Printer.Print("help"); }
public void Execute_Verb() { var printer = new Printer(); var sample = new Sample_02 { Printer = printer }; Parser.Run(new[] { "print", "/c=5", "/msg=test", "/prefix=hello_", }, sample); Expect(printer.PrintedTexts, Count.EqualTo(5)); Expect(printer.PrintedTexts, All.EqualTo("hello_test")); }
public void Execute_DefaultVerbWithoutDefaultValue() { var printer = new Printer(); var sample = new Sample_02_No_Default { Printer = printer }; Parser.Run(new string[] { }, sample); Assert.AreEqual(null, printer.PrintedTexts[0]); }
public void Bar() { Printer.Print("zoo"); }
public void Execute_DuplicateParameterNames() { var printer = new Printer(); var sample = new Sample_05 { Printer = printer }; Expect(() => Parser.Run(new[] { "p", }, sample), Throws.InstanceOf<InvalidOperationException>() .With.Message.ContainsSubstring("Duplicate parameter names found in Print: c, x")); }
public void Foo(string h, int n) { Printer.Print("a"); }
public void Execute_NoParameterValue() { var printer = new Printer(); var sample = new Sample_02 { Printer = printer }; Expect(() => Parser.Run(new[] { "print", "/c=5", "/msg=", "/prefix=hello_", }, sample), Throws.InstanceOf<MissingArgumentValueException>()); }
public void Execute_DuplicateParameterNames() { try { var printer = new Printer(); var sample = new Sample_05 { Printer = printer }; Parser.Run(new[] { "p", }, sample); Assert.Fail(); } catch (InvalidOperationException ex) { Assert.IsTrue(ex.Message.Contains("Duplicate parameter names found in Print: c, x")); } }
public void Execute_WithEnum() { var printer = new Printer(); var sample = new Sample_04 { Printer = printer }; Parser.Run(new[] { "/count=5", "/msg=test", "/prefix=hello_", "/c:Upper", }, sample); Assert.AreEqual(5, printer.PrintedTexts.Count); Assert.IsTrue(printer.PrintedTexts.All(t => t.Equals("HELLO_TEST"))); }
public void Foo(string x) { Printer.Print(x); }