CSharpTest.Net
DefaultCommands Enumeration
Example  See Also  Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Commands Namespace : DefaultCommands Enumeration

Glossary Item Box

A list of built-in commands that can be added to the interpreter

Syntax

Visual Basic (Declaration) 
Public Enum DefaultCommands 
   Inherits System.Enum
C# 
public enum DefaultCommands : System.Enum 

Members

MemberDescription
AllNot a command, indicates to use all default commands
DefaultNot a command, indicates the default commands added if not specified
EchoA command to echo back to std::out the arguments provided.
ErrorLevelAn option to set and get the environment error-level
FindA command to search for a text string in a file or the standard input stream.
GetA command to get the value of an option
HelpA command to display help about the commands and their options
HostHTTPA command that allows the console application to be hosted as a restful HTTP server.
IORedirectA command filter that allows redirect of std in/out to files.
MoreA command to read the input stream and show one screen at a time to standard output.
NoneNot a command, indicates no default commands
PipeCommandsA command filter that allows piping the output of one command into the input of another.
PromptAn option that provides customization of the command prompt for interactive mode
SetA command to set the value of an option

Example

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.NETCopy 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)

Inheritance Hierarchy

System.Object
   System.ValueType
      System.Enum
         CSharpTest.Net.Commands.DefaultCommands

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys