Exemplo n.º 1
0
Arquivo: Tests.cs Projeto: serra/CLAP
        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"));
        }
Exemplo n.º 2
0
Arquivo: Tests.cs Projeto: serra/CLAP
        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);
        }
Exemplo n.º 3
0
Arquivo: Tests.cs Projeto: serra/CLAP
        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>());
        }
Exemplo n.º 4
0
Arquivo: Tests.cs Projeto: serra/CLAP
        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" },
                                                                         }));
        }
Exemplo n.º 5
0
Arquivo: Tests.cs Projeto: serra/CLAP
        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")));
        }
Exemplo n.º 6
0
Arquivo: Tests.cs Projeto: serra/CLAP
        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));
        }
Exemplo n.º 7
0
Arquivo: Tests.cs Projeto: serra/CLAP
        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"));
        }
Exemplo n.º 8
0
Arquivo: Tests.cs Projeto: serra/CLAP
        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);
        }
Exemplo n.º 9
0
Arquivo: Tests.cs Projeto: serra/CLAP
        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);
        }
Exemplo n.º 10
0
Arquivo: Tests.cs Projeto: kurtaj/CLAP
        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")));
        }
Exemplo n.º 11
0
Arquivo: Tests.cs Projeto: kurtaj/CLAP
        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);
        }
Exemplo n.º 12
0
Arquivo: Tests.cs Projeto: kurtaj/CLAP
        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"));
            }
        }
Exemplo n.º 13
0
Arquivo: Tests.cs Projeto: kurtaj/CLAP
        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);
            }
        }
Exemplo n.º 14
0
Arquivo: Tests.cs Projeto: kurtaj/CLAP
        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]);
        }