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_HandleError_Registered_UnhandledParameters() { var mock = new Mock<IPrinter>(); var sample = new Sample_02 { Printer = mock.Object }; var p = new Parser<Sample_02>(); var handled = false; p.Register.ErrorHandler(ex => { handled = true; }); p.Run(new[] { "-count:1", "-message:a", "-prefix:p", "-upper", "-what:x" }, sample); Expect(handled, Is.True); }
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 Unhandled_Exception_Some() { var mock = new Mock<IPrinter>(); var sample = new Sample_02 { Printer = mock.Object }; var p = new Parser<Sample_02>(); Expect(() => p.Run(new[] { "-count:1", "-who:me", "-foo:bar", "-message:a", "-prefix:p", "-upper", "-what:x" }, sample), Throws.InstanceOf<UnhandledParametersException>() .With.Property("UnhandledParameters").EqualTo(new Dictionary<string, string> { { "who", "me" }, { "foo", "bar" }, { "what", "x" }, })); }
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 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 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 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 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 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 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 Unhandled_Exception_Some() { var mock = new Mock<IPrinter>(); var sample = new Sample_02 { Printer = mock.Object }; var p = new Parser<Sample_02>(); try { p.Run(new[] { "-count:1", "-who:me", "-foo:bar", "-message:a", "-prefix:p", "-upper", "-what:x" }, sample); Assert.Fail(); } catch (UnhandledParametersException ex) { Assert.AreEqual(3, ex.UnhandledParameters.Count()); Assert.IsTrue(ex.UnhandledParameters.Keys.Contains("who")); Assert.IsTrue(ex.UnhandledParameters.Keys.Contains("foo")); Assert.IsTrue(ex.UnhandledParameters.Keys.Contains("what")); } }
public void Unhandled_Exception_One() { var mock = new Mock<IPrinter>(); var sample = new Sample_02 { Printer = mock.Object }; var p = new Parser<Sample_02>(); try { p.Run(new[] { "-count:1", "-message:a", "-prefix:p", "-upper", "-what:x" }, sample); Assert.Fail(); } catch (UnhandledParametersException ex) { Assert.AreEqual(1, ex.UnhandledParameters.Count()); Assert.AreEqual("what", ex.UnhandledParameters.First().Key); Assert.AreEqual("x", ex.UnhandledParameters.First().Value); } }
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]); }