Parameters
- property
Library/Library.Test/TestCmdInterpreter.cs
C# | Copy Code |
---|---|
Assert.AreEqual(DefaultCommands.Get | DefaultCommands.Set | DefaultCommands.Help, DefaultCommands.Default); //defaults the DefaultCommands to Get/Set/Help via the enum value of DefaultCommands.Default CommandInterpreter ci = new CommandInterpreter(new TestCommands()); Assert.AreEqual(2, ci.Options.Length); Assert.AreEqual("Other", ci.Options[0].DisplayName); Assert.AreEqual(typeof(int), ci.Options[0].Type); Assert.AreEqual("SomeData", ci.Options[1].DisplayName); Assert.AreEqual(typeof(String), ci.Options[1].Type); TextWriter stdout = Console.Out; try { Console.SetOut(new StringWriter());// <= Get will also write to console Assert.AreEqual(-1, ci.Get("other"));//default was applied ci.Set("other", 1); Assert.AreEqual(1, ci.Get("other")); Assert.AreNotEqual("abc", ci.Get("somedata")); ci.Set("somedata", "abc"); Assert.AreEqual("abc", ci.Get("somedata")); } finally { Console.SetOut(stdout); } string result; result = Capture(ci, "GET Somedata"); Assert.AreEqual("abc", result); //Set without args lists options result = Capture(ci, "SET"); Assert.IsTrue(result.ToUpper().Contains("somedata".ToUpper())); //Set without value returns the current value result = Capture(ci, "SET somedata"); Assert.AreEqual("abc", result); result = Capture(ci, "SET somedata 123"); Assert.AreEqual("", result); result = Capture(ci, "GET somedata"); Assert.AreEqual("123", result); |
VB.NET | Copy Code |
---|---|
Assert.AreEqual(DefaultCommands.[Get] Or DefaultCommands.[Set] Or DefaultCommands.Help, DefaultCommands.[Default]) 'defaults the DefaultCommands to Get/Set/Help via the enum value of DefaultCommands.Default Dim ci As New CommandInterpreter(New TestCommands()) Assert.AreEqual(2, ci.Options.Length) Assert.AreEqual("Other", ci.Options(0).DisplayName) Assert.AreEqual(GetType(Integer), ci.Options(0).Type) Assert.AreEqual("SomeData", ci.Options(1).DisplayName) Assert.AreEqual(GetType([String]), ci.Options(1).Type) Dim stdout As TextWriter = Console.Out Try Console.SetOut(New StringWriter()) ' <= Get will also write to console Assert.AreEqual(-1, ci.[Get]("other")) 'default was applied ci.[Set]("other", 1) Assert.AreEqual(1, ci.[Get]("other")) Assert.AreNotEqual("abc", ci.[Get]("somedata")) ci.[Set]("somedata", "abc") Assert.AreEqual("abc", ci.[Get]("somedata")) Finally Console.SetOut(stdout) End Try Dim result As String result = Capture(ci, "GET Somedata") Assert.AreEqual("abc", result) 'Set without args lists options result = Capture(ci, "SET") Assert.IsTrue(result.ToUpper().Contains("somedata".ToUpper())) 'Set without value returns the current value result = Capture(ci, "SET somedata") Assert.AreEqual("abc", result) result = Capture(ci, "SET somedata 123") Assert.AreEqual("", result) result = Capture(ci, "GET somedata") Assert.AreEqual("123", result) |
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7