public void TestProcessMockSession()
        {
            var objDir  = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            var startup = new ProcessConfig
            {
                ProcessName      = Path.Combine(objDir, "MockWs3270.exe"),
                ConnectRetryMsec = 50
            };

            // Try a successful start.
            var session = new ProcessSession(startup);
            var result  = session.Start();

            Assert.AreEqual(true, result.Success);
            session.Close();

            // Exercise some bad command-line options.
            startup.TestFirstOptions = "-baz";
            result = session.Start();
            Assert.AreEqual(false, result.Success);

            startup.TestFirstOptions = "-scriptport 12345678";
            result = session.Start();
            Assert.AreEqual(false, result.Success);
        }
        public void TestArgsTooLong()
        {
            var config = new ProcessConfig
            {
                ProcessName  = "MockWs3270.exe",
                ExtraOptions = Enumerable.Range(1, 11000).Select(x => new ProcessOptionWithoutValue("x"))
            };
            var session = new ProcessSession(config);

            Assert.Throws <InvalidOperationException>(() => session.Start());
        }
        public void TestNoSuchProcess()
        {
            var startup = new ProcessConfig
            {
                ProcessName = "MockWs3270NoSuch.exe"
            };
            var session = new ProcessSession(startup);

            var startResult = session.Start();

            Assert.AreEqual(false, startResult.Success);
        }
        /// <summary>
        /// Main method.
        /// </summary>
        /// <param name="args">Command line arguments.</param>
        public static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Usage: TrivialConsoleApp <hostname>");
                Environment.Exit(1);
            }

            var session     = new ProcessSession();
            var startResult = session.Start();

            if (!startResult.Success)
            {
                Console.WriteLine("Start failed: {0}", startResult.FailReason);
                session.Close();
                Environment.Exit(1);
            }

            var ioResult = session.Connect(args[0]);

            if (!ioResult.Success)
            {
                Console.WriteLine("Connect failed: {0}", ioResult.Result[0]);
                session.Close();
                Environment.Exit(1);
            }

            ioResult = session.Wait(WaitMode.InputField);
            if (!ioResult.Success)
            {
                Console.WriteLine("Wait failed: {0}", ioResult.Result[0]);
                session.Close();
                Environment.Exit(1);
            }

            ioResult = session.Ascii();
            if (!ioResult.Success)
            {
                Console.WriteLine("Ascii failed: {0}", ioResult.Result[0]);
                session.Close();
                Environment.Exit(1);
            }

            Console.Write(string.Join("\n", ioResult.Result));

            session.Close();
        }