public void TestAddDuplicatedParameter_ArgumentException() { TcpAppCommand cmd = new TcpAppCommand("CMD", "Dummy Command", null); cmd.AddParameter(TcpAppParameter.CreateParameter("P1", "Parameter 1")); Assert.Throws <ArgumentException>(() => { cmd.AddParameter(TcpAppParameter.CreateParameter("P1", "Parameter 1")); }); }
public void Setup() { Server = new TcpAppServer(); Server.Start(25000); Server.ClientSignedIn += Server_ClientSignedIn; Server.ClientSigningOut += Server_ClientSigningOut; Server.RegisterCommand("Custom_1", "Custom Command.", Custom1Callback); Server.RegisterQueuedCommand("Delay", "Custom Delay", (TcpAppInputCommand sender) => { //Each connection execute command from different thread int delay = Convert.ToInt32(sender.Command.Parameter("duration").Value); //TestContext.Progress.WriteLine(sender.Command.Parameter("client").Value + " Sleep " + delay.ToString()); Thread.Sleep(delay); sender.Status = TcpAppCommandStatus.OK; sender.OutputMessage = "Delay Tick"; }, TcpAppParameter.CreateParameter("client", "client name"), TcpAppParameter.CreateParameter("duration", "Duration in ms")); Server.RegisterCommand("DelayNoQueue", "Custom Delay", (TcpAppInputCommand sender) => { //Each connection execute command from different thread int delay = Convert.ToInt32(sender.Command.Parameter("duration").Value); //TestContext.Progress.WriteLine(sender.Command.Parameter("client").Value + " Sleep " + delay.ToString()); Thread.Sleep(delay); sender.Status = TcpAppCommandStatus.OK; sender.OutputMessage = "MAIN"; }, TcpAppParameter.CreateParameter("client", "client name"), TcpAppParameter.CreateParameter("duration", "Duration in ms")); Server.RegisterPluginType(typeof(TcpAppServerSimpleMath)); Client = new TcpAppClient("localhost", 25000); Tcp = new TcpClient("localhost", 25000); }
public void RegisterCommands() { RegisterCommand("Replace", "Replace string", SplitString, TcpAppParameter.CreateParameter("Input", "Input String"), TcpAppParameter.CreateParameter("Search", "String to search"), TcpAppParameter.CreateParameter("Replace", "String to replace")); }
public void RegisterCommandWithParameterArray() { TcpAppServer server = new TcpAppServer(); server.RegisterCommand("DummyCommand", "Dummy", null, TcpAppParameter.CreateParameter("P1", "Param 1"), TcpAppParameter.CreateParameter("P2", "Param 2"), TcpAppParameter.CreateParameterArray("PArr1", "Array Param 1", true) ); }
public void RegisterCommandWithParameterArray_ArrayNotLastParam_ArgumentException() { TcpAppServer server = new TcpAppServer(); Assert.Throws <ArgumentException>(() => { server.RegisterCommand("DummyCommand", "Dummy", null, TcpAppParameter.CreateParameter("P1", "Param 1"), TcpAppParameter.CreateParameterArray("PArr1", "Array Param 1", true), TcpAppParameter.CreateParameter("P2", "Param 2") ); }); }
public void TestCommand_Clone() { TcpAppCommand cmd = new TcpAppCommand("CMD", "Dummy Command", null); cmd.AddParameter(TcpAppParameter.CreateParameter("P1", "Parameter 1")); cmd.AddParameter(TcpAppParameter.CreateParameter("P2", "Parameter 2")); cmd.AddParameter(TcpAppParameter.CreateParameterArray("Array1", "Array 1", false)); TcpAppCommand cloned = cmd.Clone() as TcpAppCommand; Assert.AreEqual("CMD", cloned.Keyword); Assert.AreEqual("Dummy Command", cloned.Description); Assert.AreEqual(3, cloned.Parameters.Count()); Assert.AreEqual("Array 1", cloned.Parameters[2].Description); }
public Form1() { InitializeComponent(); Server = new TcpServer(); Server.MaxClients = 5; Server.ServerStarted += Server_StateChanged; Server.ServerStopped += Server_StateChanged; Server.ClientConnected += Server_ClientConnected; Server.ClientDisconnected += Server_ClientDisconnected; propertyGrid1.SelectedObject = Server; AppServer = new TcpAppServer() { WelcomeMessage = "Welcome to TCP Application Server. Copyright (C) Code Art Engineering." }; AppServer.MaxClients = 5; AppServer.ExecutionTimeout = 1000; AppServer.ClientConnected += AppServer_ClientConnected; AppServer.ClientDisconnected += AppServer_ClientDisconnected; AppServer.ClientSignedIn += AppServer_ClientInitialized; AppServer.ClientSigningOut += AppServer_ClientSigningOut; tcpClientsList1.AssignObject(AppServer); tcpAppServerQueue1.AssignObject(AppServer); //TCP Application Server Customization Test AppServer.RegisterCommand("CustomFunction", "Dummy Custom Function", customFunctionCallback); AppServer.RegisterCommand("CustomFunction2", "Dummy Custom Function with Parameter", customFunction2Callback, TcpAppParameter.CreateParameter("P1", "Parameter 1"), TcpAppParameter.CreateOptionalParameter("P2", "Parameter 2, optional.", "10")); AppServer.RegisterCommand("SlowCommand", "Command which take 10 seconds to complete. Simulate blocking!", SlowCommand); AppServer.RegisterQueuedCommand("SlowCommandQ", "Command which take 10 seconds to complete. Run in queue. Simulate blocking!", SlowCommand); CodeArtEng.Tcp.Tests.TcpAppServerSamplePlugin SamplePlugin = new CodeArtEng.Tcp.Tests.TcpAppServerSamplePlugin(); AppServer.RegisterPluginType(typeof(CodeArtEng.Tcp.Tests.TcpAppServerSamplePlugin)); AppServer.RegisterPluginType(typeof(CodeArtEng.Tcp.Tests.TcpAppServerSimpleMath)); propertyGrid2.SelectedObject = AppServer; }