public void NullableInt_NotSet( ) { ICliNullableInt cli = new InterfaceSpecBoilerPlateHelper <ICliNullableInt>( new string[0]).CliConfigObject; Assert.IsFalse(cli.Arg.HasValue); }
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); }
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); }
public void FloatArg_Zero( ) { ICliFloatArg cli = new InterfaceSpecBoilerPlateHelper <ICliFloatArg>( new[] { 0f.ToString(CultureInfo.InvariantCulture) }).CliConfigObject; Assert.AreEqual(0f, cli.Arg); }
public void LongArg_Zero( ) { ICliLongArg cli = new InterfaceSpecBoilerPlateHelper <ICliLongArg>( new[] { 0.ToString( ) }).CliConfigObject; Assert.AreEqual(0, cli.Arg); }
public void IntArg_MaxValue( ) { ICliIntArg cli = new InterfaceSpecBoilerPlateHelper <ICliIntArg>( new[] { int.MaxValue.ToString( ) }).CliConfigObject; Assert.AreEqual(int.MaxValue, cli.Arg); }
public void EnumArg_IsSetLowerCase( ) { ICliEnumArg cli = new InterfaceSpecBoilerPlateHelper <ICliEnumArg>( new[] { MyEnum.Value2.ToString( ).ToLower( ) }).CliConfigObject; Assert.AreEqual(MyEnum.Value2, cli.Arg); }
public void NullableEnumArg_IsSet( ) { ICliNullableEnumArg cli = new InterfaceSpecBoilerPlateHelper <ICliNullableEnumArg>( new[] { MyEnum.Value2.ToString( ) }).CliConfigObject; Assert.AreEqual(MyEnum.Value2, cli.Arg); }
public void LongArg_MinValue( ) { ICliLongArg cli = new InterfaceSpecBoilerPlateHelper <ICliLongArg>( new[] { long.MinValue.ToString( ) }).CliConfigObject; Assert.AreEqual(long.MinValue, cli.Arg); }
public void NullableInt_Set( ) { ICliNullableInt cli = new InterfaceSpecBoilerPlateHelper <ICliNullableInt>( new[] { 42.ToString( ) }).CliConfigObject; Assert.IsTrue(cli.Arg.HasValue); Assert.AreEqual(42, cli.Arg); }
public void IntArgMinVal( ) { InterfaceSpecBoilerPlateHelper <ICliIntArg> isbph = new InterfaceSpecBoilerPlateHelper <ICliIntArg>( new[] { 0.ToString( ) }); isbph.Config.UserPrompt = AutoSolve; Assert.AreEqual(IntMinVal, isbph.CliConfigObject.IntArg); }
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); }
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); }
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); }
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); }
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); }
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]); }
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( ); } }
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); }
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); }
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( )); }