public void TestHypensInArguments() { string[] args = "-somefile \"this-is-a-terrible-filename.txt\" -another param ".Split(' '); var dest = new CommandTestObj(); CmdLineArg[] Arguments = new CmdLineArg[] { new CmdLineArg() { Flag = "somefile", DataType=typeof(string), PropertyName="somefile"}, new CmdLineArg() { Flag = "another", DataType=typeof(string), PropertyName="another"} }; CmdLineJobBase cmds = new CmdLineJobBase(); Assert.IsTrue(cmds.Load(args, Arguments, dest), "Load failed!"); Assert.AreEqual("param", dest.another, "parameter after filename with hypens was clobbered"); Assert.AreEqual("this-is-a-terrible-filename.txt", dest.somefile, "failed on filename with hyphens"); }
public void TestInvalidArguments() { string[] args = "-realarg abcde -realagr defghi ".Split(' '); var dest = new CommandTestObj(); CmdLineArg[] Arguments = new CmdLineArg[] { new CmdLineArg() { Flag = "realarg", DataType=typeof(string), PropertyName="somefile"} }; CmdLineJobBase cmds = new CmdLineJobBase(); bool loadDidFail = cmds.Load(args, Arguments, dest); //switched this, nunit was being weird Assert.IsTrue(loadDidFail == false, "Load Succeeded???"); //assert should pass, load should fail }
public void TestTypeConversion() { string[] args = "-string abcdef ghijklmno pqrstuvwxyz -double 3.14159265359 -int 8".Split(' '); var dest = new CommandTestObj(); CmdLineArg[] Arguments = new CmdLineArg[] { new CmdLineArg() { Flag = "string", DataType=typeof(string), PropertyName="str"}, new CmdLineArg() { Flag = "double", DataType=typeof(double), PropertyName="dbl"}, new CmdLineArg() { Flag = "int", DataType=typeof(int), PropertyName="it"}, }; CmdLineJobBase cmds = new CmdLineJobBase(); Assert.IsTrue(cmds.Load(args, Arguments, dest), "Load failed!"); Assert.AreEqual("abcdef ghijklmno pqrstuvwxyz", dest.str, "failed on string with spaces"); Assert.AreEqual(3.14159265359, dest.dbl, "failed on double parsing"); Assert.AreEqual(8, dest.it, "failed on integer parsing"); }
public void TestParamDisambiguation() { string[] args = "-f 1 -fo 2 -foo 3".Split(' '); var dest = new CommandTestObj(); CmdLineArg[] Arguments = new CmdLineArg[] { new CmdLineArg() { Flag = "f", DataType=typeof(int), PropertyName="f"}, new CmdLineArg() { Flag = "fo", DataType=typeof(int), PropertyName="fo"}, new CmdLineArg() { Flag = "foo", DataType=typeof(int), PropertyName="foo"}, }; CmdLineJobBase cmds = new CmdLineJobBase(); Assert.IsTrue(cmds.Load(args, Arguments, dest), "Load failed!"); Assert.AreEqual(1, dest.f, "failed on 'f'"); Assert.AreEqual(2, dest.fo, "failed on 'fo'"); Assert.AreEqual(3, dest.foo, "failed on 'foo'"); }