public void UsageTest() { var args = new MyTestCmdLineObject(); args.InitializeEmpty(); Debug.WriteLine(args.Options.Usage); Assert.AreEqual("TESTAPP [/H <Hello>] [/FavoriteCar <FavoriteCar>] [/?[-]]", args.Options.Usage); }
public void HelpTextWrappingTest() { var args = new MyTestCmdLineObject(); args.InitializeFromCmdLine(); var vals = new[] { 1, 2 }; Debug.WriteLine(args.GetHelpText(40)); Assert.IsTrue(args.IsValid()); }
public void PartialNameTest() { MyTestCmdLineObject target; string[] args; target = new MyTestCmdLineObject(); args = new[] { "/Hell", "Hi Brian" }; target.InitializeFromCmdLine(args); Assert.AreEqual("Hi Brian", target.Hello); }
public void InitializeFromCmdLine_Alias_Initialized() { // full alias var cmdLine = new MyTestCmdLineObject(); cmdLine.InitializeFromCmdLine(new[] { "/crap", "Christine" }); Assert.AreEqual("Christine", cmdLine.StuffILike[0]); // partial alias cmdLine = new MyTestCmdLineObject(); cmdLine.InitializeFromCmdLine(new[] { "/c", "Christine" }); Assert.AreEqual("Christine", cmdLine.StuffILike[0]); }
public void QueryStringTest() { MyTestCmdLineObject target; string args; target = new MyTestCmdLineObject(); args = ""; target.InitializeFromQueryString(args); Assert.IsNull(target.Hello); Assert.IsNull(target.Goodbye); target = new MyTestCmdLineObject(); args = string.Format("H={0}", "Hi Brian!".UrlEncode()); target.InitializeFromQueryString(args); Assert.AreEqual("Hi Brian!", target.Hello); Assert.IsNull(target.Goodbye); target = new MyTestCmdLineObject(); args = string.Format("h={0}", "Hi Brian!".UrlEncode()); target.InitializeFromQueryString(args); Assert.AreEqual("Hi Brian!", target.Hello); Assert.IsNull(target.Goodbye); target = new MyTestCmdLineObject(); args = string.Format("h={0}&G={1}", "Hi Brian!".UrlEncode(), "Goodbye Christine.".UrlEncode()); target.InitializeFromQueryString(args); Assert.AreEqual("Hi Brian!", target.Hello); Assert.AreEqual("Goodbye Christine.", target.Goodbye); target = new MyTestCmdLineObject(); args = "i=true"; target.InitializeFromQueryString(args); Assert.IsTrue(target.DoesLikeIceCream); target = new MyTestCmdLineObject(); args = "I=false"; target.InitializeFromQueryString(args); Assert.IsFalse(target.DoesLikeIceCream); target = new MyTestCmdLineObject(); args = "i=Yes"; target.InitializeFromQueryString(args); Assert.IsTrue(target.DoesLikeIceCream); target = new MyTestCmdLineObject(); args = "i=No"; target.InitializeFromQueryString(args); Assert.IsFalse(target.DoesLikeIceCream); }
public void CmdLineDescriptionTest() { string test = "This is a test\ntest test test"; string[] lines = test.Lines(); foreach (string line in lines) { Debug.WriteLine(line); } var args = new MyTestCmdLineObject(); args.InitializeEmpty(); Debug.WriteLine(args.GetHelpText(50)); }
public void ValidateSetTest() { var args = new MyTestCmdLineObject(); args.InitializeFromCmdLine("/SampleColor", "red"); Assert.IsTrue(args.IsValid()); Assert.AreEqual("red", args.SampleColor); args = new MyTestCmdLineObject(); args.InitializeFromCmdLine("/SampleColor", "green"); Assert.IsTrue(args.IsValid()); args = new MyTestCmdLineObject(); args.InitializeFromCmdLine("/SampleColor", "blue"); Assert.IsTrue(args.IsValid()); args = new MyTestCmdLineObject(); args.InitializeFromCmdLine("/SampleColor", "Blue"); Assert.IsTrue(args.IsValid()); args = new MyTestCmdLineObject(); args.InitializeFromCmdLine("/SampleColor", "purple"); Assert.IsFalse(args.IsValid()); Debug.WriteLine(args.ErrorText); args = new MyTestCmdLineObject(); args.InitializeFromCmdLine("/SampleColor2", "pink"); args.Properties["SampleColor2"].Validators.Add(new SetValidator <string>("pink", "purple", "puce")); Assert.IsTrue(args.IsValid()); args = new MyTestCmdLineObject(); args.InitializeFromCmdLine("/SampleColor2", "pink"); // Uses a custom equality comparer (a BizArk class). args.Properties["SampleColor2"].Validators.Add( new SetValidator <string>(new EqualityComparer((a, b) => { return(a == b); }), "pink")); Assert.IsTrue(args.IsValid()); args = new MyTestCmdLineObject(); args.InitializeFromCmdLine("/NumberOfScoops", "2"); var vals = new[] { 1, 2 }; args.Properties["NumberOfScoops"].Validators.Add(new SetValidator <int>(vals)); Debug.WriteLine(args.GetHelpText(50)); Assert.IsTrue(args.IsValid()); }
public void InitializeFromCmdLine_ArgumentValidationTest() { var args = new MyTestCmdLineObject(); args.InitializeFromCmdLine("/NumberOfScoops", "2"); Assert.AreEqual(2, args.NumberOfScoops); Assert.IsTrue(args.IsValid()); args = new MyTestCmdLineObject(); args.InitializeFromCmdLine("/NumberOfScoops", "chocolate"); Assert.AreEqual(1, args.NumberOfScoops); Assert.IsFalse(args.IsValid()); Debug.WriteLine(args.GetHelpText(200)); args = new MyTestCmdLineObject(); args.InitializeFromCmdLine("/FavoriteNumbers", "1", "2", "3"); Assert.AreEqual(3, args.FavoriteNumbers.Length); Assert.AreEqual(1, args.FavoriteNumbers[0]); Assert.AreEqual(2, args.FavoriteNumbers[1]); Assert.AreEqual(3, args.FavoriteNumbers[2]); Assert.IsTrue(args.IsValid()); args = new MyTestCmdLineObject(); args.InitializeFromCmdLine("/FavoriteNumbers", "Red", "Green", "Blue"); Assert.AreEqual(1, args.NumberOfScoops); Assert.IsFalse(args.IsValid()); Debug.WriteLine(args.GetHelpText(200)); args = new MyTestCmdLineObject(); args.InitializeFromCmdLine("/FavoriteCar", "Ford"); Assert.IsFalse(args.IsValid()); Debug.WriteLine(args.GetHelpText(200)); args = new MyTestCmdLineObject(); args.InitializeFromCmdLine("/NumberOfScoops", "5"); Assert.IsFalse(args.IsValid()); Debug.WriteLine(args.GetHelpText(200)); }
public void SaveAndRestoreTest() { string settingsPath = @"C:\garb\Test.xml"; if (!Directory.Exists(@"C:\garb")) { Directory.CreateDirectory(@"C:\garb"); } var cmdLine = new MyTestCmdLineObject(); var stuffILike = new[] { "Cookies", "Candy", "Ice Cream" }; Assert.AreNotEqual("Hi", cmdLine.Hello); cmdLine.InitializeFromCmdLine("/H", "Hi", "/S", "Cookies", "Candy", "Ice Cream"); Assert.AreEqual("Hi", cmdLine.Hello); AssertEx.AreEqual(stuffILike, cmdLine.StuffILike); cmdLine.SaveToXml(settingsPath); Assert.IsTrue(File.Exists(settingsPath)); cmdLine = new MyTestCmdLineObject(); Assert.AreNotEqual("Hi", cmdLine.Hello); cmdLine.RestoreFromXml(settingsPath); Assert.AreEqual("Hi", cmdLine.Hello); AssertEx.AreEqual(stuffILike, cmdLine.StuffILike); }
public void InitializeTest() { MyTestCmdLineObject target; string[] args; target = new MyTestCmdLineObject(); args = new string[] {}; target.InitializeFromCmdLine(args); Assert.IsNull(target.Hello); Assert.IsNull(target.Goodbye); target = new MyTestCmdLineObject(); args = new[] { "/H", "Hi Brian!" }; target.InitializeFromCmdLine(args); Assert.That(target.Hello, Is.EqualTo("Hi Brian!")); Assert.IsNull(target.Goodbye); target = new MyTestCmdLineObject(); args = new[] { "/h", "Hi Brian!" }; target.InitializeFromCmdLine(args); Assert.AreEqual("Hi Brian!", target.Hello); Assert.IsNull(target.Goodbye); target = new MyTestCmdLineObject(); args = new[] { "/h", "Hi Brian!", "/G", "Goodbye Christine." }; target.InitializeFromCmdLine(args); Assert.AreEqual("Hi Brian!", target.Hello); Assert.AreEqual("Goodbye Christine.", target.Goodbye); target = new MyTestCmdLineObject(); args = new[] { "Hi Brian!", "/G", "Goodbye Christine." }; target.InitializeFromCmdLine(args); Assert.AreEqual("Hi Brian!", target.Hello); Assert.AreEqual("Goodbye Christine.", target.Goodbye); target = new MyTestCmdLineObject2(); args = new[] { "Goodbye Christine." }; target.InitializeFromCmdLine(args); Assert.IsNull(target.Hello); Assert.AreEqual("Goodbye Christine.", target.Goodbye); target = new MyTestCmdLineObject(); args = new[] { "TEST", "/h", "Hi Brian!", "/G", "Goodbye Christine.", "TEST" }; target.InitializeFromCmdLine(args); Assert.AreEqual("Hi Brian!", target.Hello); Assert.AreEqual("Goodbye Christine.", target.Goodbye); target = new MyTestCmdLineObject(); args = new[] { "/I" }; target.InitializeFromCmdLine(args); Assert.IsTrue(target.DoesLikeIceCream); target = new MyTestCmdLineObject(); args = new[] { "/I-" }; target.InitializeFromCmdLine(args); Assert.IsFalse(target.DoesLikeIceCream); target = new MyTestCmdLineObject(); args = new[] { "/I", "Yes" }; target.InitializeFromCmdLine(args); Assert.IsTrue(target.DoesLikeIceCream); target = new MyTestCmdLineObject(); args = new[] { "/I", "No" }; target.InitializeFromCmdLine(args); Assert.IsFalse(target.DoesLikeIceCream); target = new MyTestCmdLineObject(); args = new[] { "/S", "Cars", "Computers", "Food" }; target.InitializeFromCmdLine(args); string[] expectedStuff = { "Cars", "Computers", "Food" }; AssertEx.AreEqual(expectedStuff, target.StuffILike); }