Exemplo n.º 1
0
        public void NullableInt_NotSet( )
        {
            ICliNullableInt cli = new InterfaceSpecBoilerPlateHelper <ICliNullableInt>(
                new string[0]).CliConfigObject;

            Assert.IsFalse(cli.Arg.HasValue);
        }
Exemplo n.º 2
0
        public void FileArgDoesNotExist( )
        {
            InterfaceSpecBoilerPlateHelper <ICli2> isbph = new InterfaceSpecBoilerPlateHelper <ICli2>(
                new[] {
                Path.Combine(
                    __tempBaseDirDI.FullName,
                    "as.df")
            });

            IList <ISolution <IParserResult> > solutions = null;

            isbph.Config.UserPrompt = solutions2 => {
                solutions = solutions2;
                return(solutions2.FirstOrDefault(
                           solution => solution.Actions.Any(
                               action => action is GenericAction <IParserResult> genericAction &&
                               genericAction.Description.Equals("cancel"))));
            };

            Exception exc = null;

            try {
                ICli2 unused = isbph.CliConfigObject;
            } catch (Exception exc2) {
                exc = exc2;
            }

            Assert.IsNotNull(solutions);
            Assert.IsNotNull(exc);
            Assert.AreEqual("unresolved conflicts", exc.Message);
        }
Exemplo n.º 3
0
        public void ArgDerivedAsFileInfoArg( )
        {
            InterfaceSpecBoilerPlateHelper <ICli> isbph = new InterfaceSpecBoilerPlateHelper <ICli>(new string[0]);
            IArgument arg = isbph.CliSpecification.Arguments.FirstOrDefault( );

            Assert.IsNotNull(arg);
            Assert.IsInstanceOf <FileArgument>(arg);
        }
Exemplo n.º 4
0
        public void FloatArg_Zero( )
        {
            ICliFloatArg cli = new InterfaceSpecBoilerPlateHelper <ICliFloatArg>(
                new[] {
                0f.ToString(CultureInfo.InvariantCulture)
            }).CliConfigObject;

            Assert.AreEqual(0f, cli.Arg);
        }
Exemplo n.º 5
0
        public void LongArg_Zero( )
        {
            ICliLongArg cli = new InterfaceSpecBoilerPlateHelper <ICliLongArg>(
                new[] {
                0.ToString( )
            }).CliConfigObject;

            Assert.AreEqual(0, cli.Arg);
        }
Exemplo n.º 6
0
        public void IntArg_MaxValue( )
        {
            ICliIntArg cli = new InterfaceSpecBoilerPlateHelper <ICliIntArg>(
                new[] {
                int.MaxValue.ToString( )
            }).CliConfigObject;

            Assert.AreEqual(int.MaxValue, cli.Arg);
        }
Exemplo n.º 7
0
        public void EnumArg_IsSetLowerCase( )
        {
            ICliEnumArg cli = new InterfaceSpecBoilerPlateHelper <ICliEnumArg>(
                new[] {
                MyEnum.Value2.ToString( ).ToLower( )
            }).CliConfigObject;

            Assert.AreEqual(MyEnum.Value2, cli.Arg);
        }
Exemplo n.º 8
0
        public void NullableEnumArg_IsSet( )
        {
            ICliNullableEnumArg cli = new InterfaceSpecBoilerPlateHelper <ICliNullableEnumArg>(
                new[] {
                MyEnum.Value2.ToString( )
            }).CliConfigObject;

            Assert.AreEqual(MyEnum.Value2, cli.Arg);
        }
Exemplo n.º 9
0
        public void LongArg_MinValue( )
        {
            ICliLongArg cli = new InterfaceSpecBoilerPlateHelper <ICliLongArg>(
                new[] {
                long.MinValue.ToString( )
            }).CliConfigObject;

            Assert.AreEqual(long.MinValue, cli.Arg);
        }
Exemplo n.º 10
0
        public void NullableInt_Set( )
        {
            ICliNullableInt cli = new InterfaceSpecBoilerPlateHelper <ICliNullableInt>(
                new[] {
                42.ToString( )
            }).CliConfigObject;

            Assert.IsTrue(cli.Arg.HasValue);
            Assert.AreEqual(42, cli.Arg);
        }
Exemplo n.º 11
0
        public void IntArgMinVal( )
        {
            InterfaceSpecBoilerPlateHelper <ICliIntArg> isbph =
                new InterfaceSpecBoilerPlateHelper <ICliIntArg>(
                    new[] { 0.ToString( ) });

            isbph.Config.UserPrompt = AutoSolve;

            Assert.AreEqual(IntMinVal, isbph.CliConfigObject.IntArg);
        }
Exemplo n.º 12
0
        public void FloatArg_PositiveValue( )
        {
            const float  f   = 123.456789f;
            ICliFloatArg cli = new InterfaceSpecBoilerPlateHelper <ICliFloatArg>(
                new[] {
                f.ToString(CultureInfo.InvariantCulture)
            }).CliConfigObject;

            Assert.True(Math.Abs(f - cli.Arg) < 0.0001);
        }
Exemplo n.º 13
0
        public void DynArg_Empty( )
        {
            ICliDynArg cli = new InterfaceSpecBoilerPlateHelper <ICliDynArg>(
                new string[0]).CliConfigObject;

            Assert.IsNotNull(cli.Arg);

            List <int> argValues = cli.Arg.ToList( );

            Assert.AreEqual(0, argValues.Count);
        }
Exemplo n.º 14
0
        public void FileArgIsSet( )
        {
            InterfaceSpecBoilerPlateHelper <ICli> isbph = new InterfaceSpecBoilerPlateHelper <ICli>(
                new[] {
                Path.Combine("a", "s", "d.f")
            });
            ICli cli = isbph.CliConfigObject;

            Assert.IsNotNull(cli.FileArg);
            Assert.AreEqual(new DirectoryInfo("a/s"), cli.FileArg.Directory);
            Assert.AreEqual("d.f", cli.FileArg.Name);
        }
Exemplo n.º 15
0
        public void ConstraintOrTrueFalse( )
        {
            InterfaceSpecBoilerPlateHelper <ICliOr> isbph =
                new InterfaceSpecBoilerPlateHelper <ICliOr>(
                    new[] { "-o" });

            List <ISolution <IParserResult> > solutions = null;

            isbph.Config.UserPrompt = list => {
                solutions = list.ToList( );
                return(list.First( ));
            };

            ICliOr cli = isbph.CliConfigObject;

            Assert.IsNull(solutions);
            Assert.IsTrue(cli.Flag || cli.Option);
        }
Exemplo n.º 16
0
        public void ConstraintImpliesFalseFalse( )
        {
            InterfaceSpecBoilerPlateHelper <ICliImplies> isbph =
                new InterfaceSpecBoilerPlateHelper <ICliImplies>(
                    new string[0]);

            List <ISolution <IParserResult> > solutions = null;

            isbph.Config.UserPrompt = list => {
                solutions = list.ToList( );
                return(list.First( ));
            };

            ICliImplies cli = isbph.CliConfigObject;

            Assert.IsNull(solutions);
            Assert.IsFalse(cli.Flag || cli.Option);
        }
Exemplo n.º 17
0
        public void DynArg( )
        {
            ICliDynArg cli = new InterfaceSpecBoilerPlateHelper <ICliDynArg>(
                new[] {
                1.ToString( ),
                2.ToString( ),
                3.ToString( )
            }).CliConfigObject;

            Assert.IsNotNull(cli.Arg);

            List <int> argValues = cli.Arg.ToList( );

            Assert.AreEqual(3, argValues.Count);
            Assert.AreEqual(1, argValues[0]);
            Assert.AreEqual(2, argValues[1]);
            Assert.AreEqual(3, argValues[2]);
        }
Exemplo n.º 18
0
        public void FileArgExists( )
        {
            FileInfo fi = new FileInfo(
                Path.Combine(
                    __tempBaseDirDI.FullName,
                    "qw.ert"));

            try {
                fi.Create( );
                InterfaceSpecBoilerPlateHelper <ICli2> isbph = new InterfaceSpecBoilerPlateHelper <ICli2>(
                    new[] {
                    Path.Combine(
                        __tempBaseDirDI.FullName,
                        "qw.ert")
                });

                IList <ISolution <IParserResult> > solutions = null;
                isbph.Config.UserPrompt = solutions2 => {
                    solutions = solutions2;
                    return(solutions2.FirstOrDefault(
                               solution => solution.Actions.Any(
                                   action => action is GenericAction <IParserResult> genericAction &&
                                   genericAction.Description.Equals("cancel"))));
                };

                Exception exc = null;
                ICli2     cli = null;
                try {
                    cli = isbph.CliConfigObject;
                } catch (Exception exc2) {
                    exc = exc2;
                }

                Assert.IsNull(solutions);
                Assert.IsNull(exc);
                Assert.IsNotNull(cli);
                Assert.IsNotNull(cli.FileArg);
                Assert.IsTrue(cli.FileArg.Exists);
            } finally {
                fi.Delete( );
            }
        }
Exemplo n.º 19
0
        public void ResolveArg( )
        {
            InterfaceSpecBoilerPlateHelper <ICli1> isbph =
                new InterfaceSpecBoilerPlateHelper <ICli1>(
                    new[] {
                Value.ToString( )
            });

            List <ISolution <IParserResult> > solutions = null;

            isbph.Config.UserPrompt = list => {
                solutions = list.ToList( );
                return(list.First( ));
            };

            ICli1 cli = isbph.CliConfigObject;

            Assert.IsNull(solutions);
            Assert.AreEqual(Value, cli.Arg);
        }
Exemplo n.º 20
0
        public void ResolveOptionImplicitArgWithExplicitName( )
        {
            InterfaceSpecBoilerPlateHelper <ICli4> isbph =
                new InterfaceSpecBoilerPlateHelper <ICli4>(
                    new[] {
                "-o",
                Value.ToString( )
            });

            List <ISolution <IParserResult> > solutions = null;

            isbph.Config.UserPrompt = list => {
                solutions = list.ToList( );
                return(list.First( ));
            };

            ICli4 cli = isbph.CliConfigObject;

            Assert.IsNull(solutions);
            Assert.AreEqual(Value, cli.Option);
        }
Exemplo n.º 21
0
        public void MonsterTest( )
        {
            ICliTest cli = new InterfaceSpecBoilerPlateHelper <ICliTest>(
                new[] {
                "--string-option-one",
                "a string",
                "1",
                "2",
                "3",
                "-t",
                "another string",
                "42",
                "-m"
            }).CliConfigObject;

            Assert.AreEqual("a string", cli.StringOptionOne);
            Assert.AreEqual("another string", cli.StringOptionTwo);
            Assert.AreEqual(42, cli.StringOptionTwoCount);
            Assert.AreEqual(true, cli.MyFlag);
            Assert.AreEqual(3, cli.StringOptionOneDynIntArg.Count( ));
            Assert.AreEqual(1, cli.StringOptionOneDynIntArg.First( ));
            Assert.AreEqual(3, cli.StringOptionOneDynIntArg.Last( ));
        }