public void Validate1KeyTest(bool valid) { DefArgs defArgs = new DefArgs(); Arg newArg = new Arg(valid ? "" : "p", true, 0, false); defArgs.Add(newArg, false); Assert.AreEqual(valid, defArgs.Validate(new string[] { })); }
public void Validate1MoreArgsTest(bool valid) { DefArgs defArgs = new DefArgs(); Arg newArg = new Arg("", true, 0, !valid); defArgs.Add(newArg, false); Assert.AreEqual(valid, defArgs.Validate(valid ? new string[] { } : new[] { "abc" })); }
public void Add1Test(string name, bool required, int anzRequired, bool moreAllowed) { DefArgs defArgs = new DefArgs(); Arg newArg = new Arg(name, required, (uint)anzRequired, moreAllowed); defArgs.Add(newArg, false); Assert.IsTrue(defArgs.Args.Contains(newArg)); }
public void Validate1RequiredTest(bool valid) { DefArgs defArgs = new DefArgs(); Arg newArg = new Arg("p", !valid, 0, false); defArgs.Add(newArg, false); Assert.AreEqual(valid, defArgs.Validate(new string[] { })); }
public void Add2Test(string name, bool required) { DefArgs defArgs = new DefArgs(); defArgs.Add(name, required, false); Assert.IsTrue(defArgs.Args.Contains(new Arg(name, required))); }
public void Validate2RequiredTest(bool valid) { DefArgs defArgs = new DefArgs(); Arg newArg = new Arg("p", !valid, 0, false); defArgs.Add(newArg, false); IArgDictionary<string, string[]> args = new ArgDictionary<string, string[]>(); args.Add("", new string[] { }); Assert.AreEqual(valid, defArgs.Validate(args)); }
public void Validate2NumArgsTest(bool valid) { DefArgs defArgs = new DefArgs(); Arg newArg = new Arg("", true, 0, false); defArgs.Add(newArg, false); IArgDictionary<string,string[]> args = new ArgDictionary<string, string[]>(); args.Add("", valid ? new string[] { } : new[] { "abc" }); Assert.AreEqual(valid, defArgs.Validate(args)); }
//-t = type of database (just sqlite for now) //-s = SQL statement for execution //-h = help //--showtables //--show tblname static void Main(string[] args) { IArgDictionary<string,string[]> arguments = Parser.Parse(args); DefArgs requiredArgs = new DefArgs(); requiredArgs.Add("", true, 1, false); requiredArgs.Add("t", true, 1, false); requiredArgs.Add("h", false, 0, false, true); requiredArgs.Add("showtables", false, 0, false); requiredArgs.Add("show", false, 1, false); if (requiredArgs.Validate(arguments)) { if (arguments.ContainsKey("h")) { PrintHelp(); } else if (arguments["t"][0].ToLower() == "SQLite".ToLower()) { string filename = arguments[""][0]; SqLiteOperations.CreateDatabase(filename); CheckResult(); SQLiteConnection mdbConnection = SqLiteOperations.OpenDatabase(filename); CheckResult(mdbConnection); if(arguments.ContainsKey("showtables") && arguments["showtables"]!=null) { List<string> tables = SqLiteOperations.ShowAllUserTables(mdbConnection).ToList(); CheckResult(tables); Console.WriteLine("Tablesnames:\r\n------------------------------"); foreach (string table in tables) { Console.WriteLine(" " + table); } } else if (arguments.ContainsKey("show") && arguments["show"] != null) { foreach (string tablename in arguments["show"]) { string[] columnNames = SqLiteOperations.GetColumnNames(mdbConnection, tablename); CheckResult(new object[] {columnNames}); string[][] rows = SqLiteOperations.ShowTableContent(mdbConnection, tablename); CheckResult(new object[] {rows}); Console.WriteLine(tablename + ":\r\n------------------------------\r\n"); Console.Write("| "); foreach (string name in columnNames) { Console.Write(name + " | "); } Console.WriteLine(); foreach (string[] row in rows) { Console.Write("| "); for (int j = 0; j < row.Count(); j++) { Console.Write(row[j] + " | "); } Console.WriteLine(); } } } //überarbeiten wegen execute else if (arguments.ContainsKey(("s")) && arguments["s"] != null && arguments["s"].Any()) { foreach (string statement in arguments["s"]) { string[] tableNames = SqLiteOperations.GetEffectedTableNames(mdbConnection, statement); CheckResult(new object[] {tableNames}); string[][] rows = SqLiteOperations.QueryFromTable(mdbConnection, statement); CheckResult(new object[] {rows}); string[] columnNames = SqLiteOperations.GetColumnNames(mdbConnection, tableNames[0]); CheckResult(new object[] {columnNames}); Console.WriteLine( tableNames[0] + ":\r\n------------------------------\r\n"); Console.Write("| "); foreach (string name in columnNames) { Console.Write(name + " | "); } Console.WriteLine(); foreach (string[] row in rows) { Console.Write("| "); for (int j = 0; j < row.Count(); j++) { Console.Write(row[j] + " | "); } Console.WriteLine(); } } } mdbConnection.Close(); } } #if DEBUG Console.ReadLine(); #endif }