Ejemplo n.º 1
0
        public void AddCommand_Duplicate()
        {
            TextWriter outputStream = new StringWriter();
            TextWriter errorStream  = new StringWriter();

            CommandExecutor executor = new CommandExecutor("TestContext", outputStream, errorStream);

            executor.AddCommand <OutputCommand>();
            ArgumentException exception = TestUtils.TestForError <ArgumentException>(
                () => executor.AddCommand <DuplicateOutputCommand>(),
                "Did not catch expected exception.");

            Validate.Value.AreEqual("DuplicateOutputCommand", exception.ParamName,
                                    "Exception occurred for wrong argument.");
        }
Ejemplo n.º 2
0
        public void Execute_Error()
        {
            TextWriter outputStream = new StringWriter();
            TextWriter errorStream  = new StringWriter();

            CommandExecutor executor = new CommandExecutor("TestContext", outputStream, errorStream);

            executor.AddCommand <ErrorCommand>();
            executor.Execute("Error hello");

            Validate.Value.AreEqual("hello" + Environment.NewLine, errorStream.ToString(),
                                    "Did not find the expected error.");
        }
Ejemplo n.º 3
0
        public void Example1()
        {
            TextWriter outputStream = new StringWriter();
            TextWriter errorStream  = new StringWriter();

            CommandExecutor executor = new CommandExecutor("TestContext", outputStream, errorStream);

            executor.AddCommand <OutputCommand>();
            executor.Execute("Output 'hello world'");

            Validate.Value.AreEqual("hello world" + Environment.NewLine, outputStream.ToString(),
                                    "Did not find the expected output.");
        }
Ejemplo n.º 4
0
        public void ExecuteWithParentContext_Output()
        {
            TextWriter outputStream = new StringWriter();
            TextWriter errorStream  = new StringWriter();

            CommandExecutor parentExecutor = new CommandExecutor("TestContext", outputStream, errorStream);
            CommandExecutor childExecutor  = new CommandExecutor("ChildContext", parentExecutor);

            parentExecutor.AddCommand <OutputCommand>();
            childExecutor.Execute("Output hello");

            Validate.Value.AreEqual("hello" + Environment.NewLine, outputStream.ToString(),
                                    "Did not find the expected output.");
        }
Ejemplo n.º 5
0
        public void Test()
        {
            var tv = new ExternalDisplay();
            var measurementnDevice = new LaboratoryDevice();

            var tvOnCommand       = new DeviceOnCommand(tv);
            var deviceOnCommand   = new DeviceOnCommand(measurementnDevice);
            var programOneCommand = new StartMesurementProgramCommand(measurementnDevice, 1);
            var programTwoCommand = new StartMesurementProgramCommand(measurementnDevice, 2);
            var deviceOffCommand  = new DeviceOffCommand(measurementnDevice);

            var commandProcessor = new CommandExecutor();

            commandProcessor.AddCommand(tvOnCommand);
            commandProcessor.AddCommand(deviceOnCommand);
            commandProcessor.AddCommand(programOneCommand);
            commandProcessor.AddCommand(programTwoCommand);
            commandProcessor.AddCommand(deviceOffCommand);

            while (commandProcessor.HasCommands)
            {
                Thread.Sleep(10);
            }
        }
Ejemplo n.º 6
0
        public void ShowHelp_InvalidCommand()
        {
            TextWriter outputStream = new StringWriter();
            TextWriter errorStream  = new StringWriter();

            CommandExecutor executor = new CommandExecutor("TestContext", outputStream, errorStream);

            executor.AddCommand <OutputCommand>();
            executor.Execute("help invalid");

            Validate.Value.IsNullOrWhiteSpace(outputStream.ToString(),
                                              "Should not have written value to output.");
            Validate.Value.IsNotNullOrWhiteSpace(errorStream.ToString(),
                                                 "Did not find the expected error output.");
            Console.WriteLine(errorStream.ToString());
        }
Ejemplo n.º 7
0
        public void Execute_UnknownCommand()
        {
            TextWriter outputStream = new StringWriter();
            TextWriter errorStream  = new StringWriter();

            CommandExecutor executor = new CommandExecutor("TestContext", outputStream, errorStream);

            executor.AddCommand <OutputCommand>();

            UnknownCommandException exception = TestUtils.TestForError <UnknownCommandException>(
                () => executor.Execute("Error hello"),
                "Did not catch expected exception");

            Validate.Value.AreEqual("Error", exception.CommandName,
                                    "Error did not occur with the correct command.");
        }
Ejemplo n.º 8
0
    public void testCompiler(string command)
    {
        bool errorOccured = false;

        using (Process otherProcess = new Process())
        {
            otherProcess.StartInfo.FileName               = "python";
            otherProcess.StartInfo.Arguments              = COMPILER_PATH + " \"" + command + "\"";
            otherProcess.StartInfo.CreateNoWindow         = true;
            otherProcess.StartInfo.UseShellExecute        = false;
            otherProcess.StartInfo.RedirectStandardInput  = true;
            otherProcess.StartInfo.RedirectStandardOutput = true;

            otherProcess.OutputDataReceived += new DataReceivedEventHandler((sender, e) =>
            {
                if (!String.IsNullOrEmpty(e.Data))
                {
                    if (e.Data.Substring(0, 6) == "ERROR:")
                    {
                        errorOccured = true;
                    }

                    if (!errorOccured)
                    {
                        commExec.AddCommand(e.Data);
                    }

                    chatController.AddCompilerOutput(e.Data);
                }
            });

            otherProcess.Start();

            // Asynchronously read the standard output of the spawned process.
            // This raises OutputDataReceived events for each line of output.
            otherProcess.BeginOutputReadLine();
            otherProcess.WaitForExit();

            otherProcess.Close();
        }


        // Now communicate via streams
        //     otherProcess.StandardOutput
        // and
        //     otherProcess.StandardInput
    }