Beispiel #1
0
        public void MultiParser_Run_With_Target_Alias_That_Is_Defined_More_Than_Once()
        {
            var mock = new MethodInvokerMock();

            var called = false;

            mock.Action = (method, obj, parameters) =>
            {
                called = true;
            };

            MethodInvoker.Invoker = mock;

            Assert.Throws <DuplicateTargetAliasException>(
                () =>
            {
                var p = new Parser(typeof(Sample_02), typeof(Sample_02_Default));


                p.RunTargets(new[]
                {
                    "s02.print",                  //both of the provided types below have the same alias attribute value.
                    "-c=10",
                    "-prefix=aaa",
                }, new Sample_02(), new Sample_02_Default());
            });
        }
Beispiel #2
0
        public void MultiParser_Run_With_TargetResolver()
        {
            var resolver = new TargetResolver();

            resolver.RegisterTargetType(() => new Sample_02());
            resolver.RegisterTargetType(() => new Sample_03());

            var mock = new MethodInvokerMock();

            var called = false;

            mock.Action = (method, obj, parameters) =>
            {
                called = true;
                Assert.IsTrue(method.Name == "Print");
                Assert.IsTrue(obj.GetType().Name == "Sample_03");
            };

            MethodInvoker.Invoker = mock;

            Parser.Run(new[]
            {
                "sample_03.print",
                "-c=8",
                "-prefix=xyz"
            }, resolver);

            Assert.IsTrue(called);
        }
Beispiel #3
0
        public void MultiParser_Run_HappyFlow_2()
        {
            var mock = new MethodInvokerMock();

            var called = false;

            mock.Action = (method, obj, parameters) =>
            {
                called = true;

                Assert.IsTrue(method.Name == "Print");
                Assert.IsTrue(method.DeclaringType == typeof(Sample_02));
                Assert.IsTrue(parameters.Contains(10));
                Assert.IsTrue(parameters.Contains("aaa"));
            };

            MethodInvoker.Invoker = mock;

            var p = new Parser(typeof(Sample_02), typeof(Sample_03));

            p.RunTargets(new[]
            {
                "sample_02.print",
                "-c=10",
                "-prefix=aaa",
            }, new Sample_02(), new Sample_03());

            Assert.IsTrue(called);
        }
Beispiel #4
0
        public void MultiParser_Run_HappyFlow_5_Types()
        {
            var mock = new MethodInvokerMock();

            var called = false;

            mock.Action = (method, obj, parameters) =>
            {
                called = true;

                Assert.IsTrue(method.Name == "Print");
                Assert.IsTrue(method.DeclaringType == typeof(Sample_07));
                Assert.IsTrue(parameters.Contains(10));
                Assert.IsTrue(parameters.Contains("a"));
            };

            MethodInvoker.Invoker = mock;

            var p = new Parser <Sample_02, Sample_03, Sample_04, Sample_06, Sample_07>();

            p.Run(new[]
            {
                "sample_07.print",
                "-count=10",
                "-prefix=a",
            },
                  new Sample_02(),
                  new Sample_03(),
                  new Sample_04(),
                  new Sample_06(),
                  new Sample_07());

            Assert.IsTrue(called);
        }
Beispiel #5
0
        public void MultiParser_Run_With_Target_Alias()
        {
            var mock = new MethodInvokerMock();

            var called = false;

            mock.Action = (method, obj, parameters) =>
            {
                called = true;

                Assert.IsTrue(method.Name == "Print");
                Assert.IsTrue(method.DeclaringType == typeof(Sample_03));
                Assert.IsTrue(parameters.Contains(10));
                Assert.IsTrue(parameters.Contains("aaa"));
            };

            MethodInvoker.Invoker = mock;

            var p = new Parser(typeof(Sample_02), typeof(Sample_03));

            p.RunTargets(new[]
            {
                "s03.print", //the Sample_03 class has an alias attribute of 's03'
                "-c=10",
                "-prefix=aaa",
            }, new Sample_02(), new Sample_03());

            Assert.IsTrue(called);
        }
Beispiel #6
0
        public void MultiParser_Run_HappyFlow_1_Type()
        {
            var mock = new MethodInvokerMock();

            var called = false;

            mock.Action = (method, obj, parameters) =>
            {
                called = true;

                Assert.IsTrue(method.Name == "Print");
                Assert.IsTrue(method.DeclaringType == typeof(Sample_02));
                Assert.IsTrue(parameters.Contains(10));
                Assert.IsTrue(parameters.Contains("aaa"));
            };

            MethodInvoker.Invoker = mock;

            var p = new Parser<Sample_02>();

            p.Run(new[]
            {
                "sample_02.print",
                "-c=10",
                "-prefix=aaa",
            }, new Sample_02());

            Assert.IsTrue(called);
        }
Beispiel #7
0
        public void MultiParser_Run_HappyFlow_8_Types()
        {
            var mock = new MethodInvokerMock();

            var called = false;

            mock.Action = (method, obj, parameters) =>
            {
                if (called)
                {
                    Assert.IsTrue(method.Name == "Print2");
                    Assert.IsTrue(method.DeclaringType == typeof(Sample_10));
                    Assert.IsTrue(parameters.Contains("fooblah"));
                }
                else
                {
                    Assert.IsTrue(method.Name == "Bar");
                    Assert.IsTrue(method.DeclaringType == typeof(Sample_10));
                }

                called = true;
            };

            MethodInvoker.Invoker = mock;

            var p = new Parser <Sample_02, Sample_03, Sample_04, Sample_06, Sample_07, Sample_08, Sample_10, Sample_12>();

            p.Run(new[]
            {
                "sample_10.print2",
                "-bar",
                "-str=fooblah",
            },
                  new Sample_02(),
                  new Sample_03(),
                  new Sample_04(),
                  new Sample_06(),
                  new Sample_07(),
                  new Sample_08(),
                  new Sample_10(),
                  new Sample_12());

            Assert.IsTrue(called);
        }
Beispiel #8
0
        public void MultiParser_Run_HappyFlow_6_Types()
        {
            var mock = new MethodInvokerMock();

            var called = false;

            mock.Action = (method, obj, parameters) =>
            {
                called = true;

                Assert.IsTrue(method.Name == "PrintEnums");
                Assert.IsTrue(method.DeclaringType == typeof(Sample_08));
                Assert.IsTrue(parameters.Contains("abc"));
                Assert.IsTrue(parameters.Any(param =>
                {
                    return(param.GetType() == typeof(Case[]) &&
                           ((Case[])param).Length == 2 &&
                           ((Case[])param)[0] == Case.Upper &&
                           ((Case[])param)[1] == Case.Lower);
                }));
            };

            MethodInvoker.Invoker = mock;

            var p = new Parser <Sample_02, Sample_03, Sample_04, Sample_06, Sample_07, Sample_08>();

            p.Run(new[]
            {
                "sample_08.PrintEnums",
                "-enums=Upper,Lower",
                "-prefix=abc",
            },
                  new Sample_02(),
                  new Sample_03(),
                  new Sample_04(),
                  new Sample_06(),
                  new Sample_07(),
                  new Sample_08());

            Assert.IsTrue(called);
        }
Beispiel #9
0
        public void MultiParser_Run_With_Target_Alias_That_Is_Defined_More_Than_Once()
        {
            var mock = new MethodInvokerMock();

            var called = false;

            mock.Action = (method, obj, parameters) =>
            {
                called = true;
            };

            MethodInvoker.Invoker = mock;

            var p = new Parser(typeof(Sample_02), typeof(Sample_02_Default));

            p.RunTargets(new[]
            {
                "s02.print", //both of the provided types below have the same alias attribute value.
                "-c=10",
                "-prefix=aaa",
            }, new Sample_02(), new Sample_02_Default());

            Assert.IsFalse(called, "The method should not have been called due to the conflicting aliases.");
        }
Beispiel #10
0
        public void MultiParser_Run_HappyFlow_9_Types()
        {
            var mock = new MethodInvokerMock();

            var called = false;

            mock.Action = (method, obj, parameters) =>
            {
                Assert.IsTrue(method.Name == "Zoo");
                Assert.IsTrue(method.DeclaringType == typeof(Sample_28));
                Assert.IsTrue(parameters.Contains(98));

                called = true;
            };

            MethodInvoker.Invoker = mock;

            var p = new Parser <Sample_02, Sample_03, Sample_04, Sample_06, Sample_07, Sample_08, Sample_10, Sample_12, Sample_28>();

            p.Run(new[]
            {
                "sample_28.zoo",
                "-n=98",
            },
                  new Sample_02(),
                  new Sample_03(),
                  new Sample_04(),
                  new Sample_06(),
                  new Sample_07(),
                  new Sample_08(),
                  new Sample_10(),
                  new Sample_12(),
                  new Sample_28());

            Assert.IsTrue(called);
        }
Beispiel #11
0
        public void MultiParser_Run_MissingRequiredArgument()
        {
            var mock = new MethodInvokerMock();

            var called = false;

            mock.Action = (method, obj, parameters) =>
            {
                called = true;

                Assert.IsTrue(method.Name == "Print");
                Assert.IsTrue(method.DeclaringType == typeof(Sample_07));
                Assert.IsTrue(parameters.Contains(10));
            };

            MethodInvoker.Invoker = mock;

            var p = new Parser <Sample_02, Sample_03, Sample_04, Sample_06, Sample_07>();

            Assert.Throws <MissingRequiredArgumentException>(
                () =>
            {
                p.Run(new[]
                {
                    "sample_07.print",
                    "-count=10",
                },
                      new Sample_02(),
                      new Sample_03(),
                      new Sample_04(),
                      new Sample_06(),
                      new Sample_07());
            });

            Assert.IsFalse(called);
        }
Beispiel #12
0
        public void MultiParser_Run_HappyFlow_9_Types()
        {
            var mock = new MethodInvokerMock();

            var called = false;

            mock.Action = (method, obj, parameters) =>
            {
                Assert.IsTrue(method.Name == "Zoo");
                Assert.IsTrue(method.DeclaringType == typeof(Sample_28));
                Assert.IsTrue(parameters.Contains(98));

                called = true;
            };

            MethodInvoker.Invoker = mock;

            var p = new Parser<Sample_02, Sample_03, Sample_04, Sample_06, Sample_07, Sample_08, Sample_10, Sample_12, Sample_28>();

            p.Run(new[]
            {
                "sample_28.zoo",
                "-n=98",
            },
            new Sample_02(),
            new Sample_03(),
            new Sample_04(),
            new Sample_06(),
            new Sample_07(),
            new Sample_08(),
            new Sample_10(),
            new Sample_12(),
            new Sample_28());

            Assert.IsTrue(called);
        }
Beispiel #13
0
        public void MultiParser_Run_HappyFlow_7_Types()
        {
            var mock = new MethodInvokerMock();

            var called = false;

            mock.Action = (method, obj, parameters) =>
            {
                called = true;

                Assert.IsTrue(method.Name == "Print");
                Assert.IsTrue(method.DeclaringType == typeof(Sample_07));
                Assert.IsTrue(parameters.Contains(10));
                Assert.IsTrue(parameters.Contains("a"));
            };

            MethodInvoker.Invoker = mock;

            var p = new Parser<Sample_02, Sample_03, Sample_04, Sample_06, Sample_07, Sample_08, Sample_10>();

            p.Run(new[]
            {
                "sample_07.print",
                "-count=10",
                "-prefix=a",
            },
            new Sample_02(),
            new Sample_03(),
            new Sample_04(),
            new Sample_06(),
            new Sample_07(),
            new Sample_08(),
            new Sample_10());

            Assert.IsTrue(called);
        }
Beispiel #14
0
        public void MultiParser_Run_With_Target_Alias_That_Is_Defined_More_Than_Once()
        {
            var mock = new MethodInvokerMock();

            var called = false;

            mock.Action = (method, obj, parameters) =>
            {
                called = true;
            };

            MethodInvoker.Invoker = mock;

            var p = new Parser(typeof(Sample_02), typeof(Sample_02_Default));

            p.RunTargets(new[]
            {
                "s02.print", //both of the provided types below have the same alias attribute value.
                "-c=10",
                "-prefix=aaa",
            }, new Sample_02(), new Sample_02_Default());

            Assert.IsFalse(called, "The method should not have been called due to the conflicting aliases.");
        }
Beispiel #15
0
        public void MultiParser_Run_With_Target_Alias()
        {
            var mock = new MethodInvokerMock();

            var called = false;

            mock.Action = (method, obj, parameters) =>
            {
                called = true;

                Assert.IsTrue(method.Name == "Print");
                Assert.IsTrue(method.DeclaringType == typeof(Sample_03));
                Assert.IsTrue(parameters.Contains(10));
                Assert.IsTrue(parameters.Contains("aaa"));
            };

            MethodInvoker.Invoker = mock;

            var p = new Parser(typeof(Sample_02), typeof(Sample_03));

            p.RunTargets(new[]
            {
                "s03.print", //the Sample_03 class has an alias attribute of 's03'
                "-c=10",
                "-prefix=aaa",
            }, new Sample_02(), new Sample_03());

            Assert.IsTrue(called);
        }
Beispiel #16
0
        public void MultiParser_Run_With_TargetResolver()
        {
            var resolver = new TargetResolver();
            resolver.RegisterTargetType(() => new Sample_02());
            resolver.RegisterTargetType(() => new Sample_03());

            var mock = new MethodInvokerMock();

            var called = false;
            mock.Action = (method, obj, parameters) =>
                {
                    called = true;
                    Assert.IsTrue(method.Name == "Print");
                    Assert.IsTrue(obj.GetType().Name == "Sample_03");
                };

            MethodInvoker.Invoker = mock;

            Parser.Run(new[]
                {
                    "sample_03.print",
                    "-c=8",
                    "-prefix=xyz"
                }, resolver);

            Assert.IsTrue(called);
        }
Beispiel #17
0
        public void MultiParser_Run_MissingRequiredArgument()
        {
            var mock = new MethodInvokerMock();

            var called = false;

            mock.Action = (method, obj, parameters) =>
            {
                called = true;

                Assert.IsTrue(method.Name == "Print");
                Assert.IsTrue(method.DeclaringType == typeof(Sample_07));
                Assert.IsTrue(parameters.Contains(10));
            };

            MethodInvoker.Invoker = mock;

            var p = new Parser<Sample_02, Sample_03, Sample_04, Sample_06, Sample_07>();

            p.Run(new[]
            {
                "sample_07.print",
                "-count=10",
            },
            new Sample_02(),
            new Sample_03(),
            new Sample_04(),
            new Sample_06(),
            new Sample_07());

            Assert.IsTrue(called);
        }
Beispiel #18
0
        public void MultiParser_Run_HappyFlow_6_Types()
        {
            var mock = new MethodInvokerMock();

            var called = false;

            mock.Action = (method, obj, parameters) =>
            {
                called = true;

                Assert.IsTrue(method.Name == "PrintEnums");
                Assert.IsTrue(method.DeclaringType == typeof(Sample_08));
                Assert.IsTrue(parameters.Contains("abc"));
                Assert.IsTrue(parameters.Any(param =>
                {
                    return param.GetType() == typeof(Case[]) &&
                        ((Case[])param).Length == 2 &&
                        ((Case[])param)[0] == Case.Upper &&
                        ((Case[])param)[1] == Case.Lower;
                }));
            };

            MethodInvoker.Invoker = mock;

            var p = new Parser<Sample_02, Sample_03, Sample_04, Sample_06, Sample_07, Sample_08>();

            p.Run(new[]
            {
                "sample_08.PrintEnums",
                "-enums=Upper,Lower",
                "-prefix=abc",
            },
            new Sample_02(),
            new Sample_03(),
            new Sample_04(),
            new Sample_06(),
            new Sample_07(),
            new Sample_08());

            Assert.IsTrue(called);
        }
Beispiel #19
0
        public void MultiParser_Run_HappyFlow_8_Types()
        {
            var mock = new MethodInvokerMock();

            var called = false;

            mock.Action = (method, obj, parameters) =>
            {
                if (called)
                {
                    Assert.IsTrue(method.Name == "Print2");
                    Assert.IsTrue(method.DeclaringType == typeof(Sample_10));
                    Assert.IsTrue(parameters.Contains("fooblah"));
                }
                else
                {
                    Assert.IsTrue(method.Name == "Bar");
                    Assert.IsTrue(method.DeclaringType == typeof(Sample_10));
                }

                called = true;
            };

            MethodInvoker.Invoker = mock;

            var p = new Parser<Sample_02, Sample_03, Sample_04, Sample_06, Sample_07, Sample_08, Sample_10, Sample_12>();

            p.Run(new[]
            {
                "sample_10.print2",
                "-bar",
                "-str=fooblah",
            },
            new Sample_02(),
            new Sample_03(),
            new Sample_04(),
            new Sample_06(),
            new Sample_07(),
            new Sample_08(),
            new Sample_10(),
            new Sample_12());

            Assert.IsTrue(called);
        }