Exemplo n.º 1
0
        public static void ChooseMethods(IEnumerable <TestMethodExt> mtds, TestingWindow w)
        {
            w.Start();
            var methods = mtds.ToArray();

again:
            w.WriteLine();
            w.RememberState();
            w.WriteLine("Choose method:");
            for (int i = 0; i < methods.Length; i++)
            {
                w.WriteLine($"{i + 1}: {methods[i].Name}");
            }
            w.Write(">");
            var answ = w.ReadLine();

            if (int.TryParse(answ, out var ch) && ch <= methods.Length && ch > 0)
            {
                methods[ch - 1].InvokeWithConsole();
            }
            else
            {
                w.RestoreState();
                w.WriteLine($"\"{answ}\" is really bad choice! Try again");
                goto again;
            }
        }
Exemplo n.º 2
0
        static object parseParam(ref int i, ParameterInfo p, TestingWindow Window)
        {
            Window.WriteLine();
again:
            Window.RememberState();
            parse2(p, out var res, out var o, Window);

            switch (o)
            {
            case ParseResult.DEFAULT: goto case ParseResult.OK;

            case ParseResult.OK: return(res);

            case ParseResult.BAD:
                //long diff = Window.CursorTop - cstart;
                //for(int i = 0; i < diff; i++) { Window.Write("\b"); }
                Window.RestoreState();
                Window.WriteLine($"\"{res}\" has bad input format! Try again");
                break;

            case ParseResult.CANCEL:
                i -= 2;
                Window.RestoreState();
                return(null);

            default: throw new NotImplementedException();
            }

            goto again;
        }
Exemplo n.º 3
0
        static void parse2(ParameterInfo p, out object res, out ParseResult o, TestingWindow Window)
        {
            if (p.HasDefaultValue)
            {
                Window.WriteLine($"(default: {p.DefaultValue})");
            }
            Window.Write($"{p.Name}=");
            string answ = Window.ReadLine();

            res = answ;
            if (string.IsNullOrWhiteSpace(answ) && p.HasDefaultValue)
            {
                o = ParseResult.DEFAULT; res = p.DefaultValue; return;
            }
            else if (answ == "$back")
            {
                o = ParseResult.CANCEL; res = null; return;
            }

            o = ParseResult.OK;
            var type = p.ParameterType;

            if (type == typeof(string))
            {
                res = answ; return;
            }
            else if (type == typeof(int))
            {
                if (int.TryParse(answ, out var ire))
                {
                    res = ire; return;
                }
            }
            else if (type == typeof(double))
            {
                if (double.TryParse(answ, out var dre))
                {
                    res = dre; return;
                }
            }
            else if (type == typeof(bool))
            {
                if (bool.TryParse(answ, out var bre))
                {
                    res = bre; return;
                }
            }
            else
            {
                throw new NotImplementedException();
            }

            o = ParseResult.BAD;
        }
Exemplo n.º 4
0
        static void runall(MethodInfo Target, object[] obj, object parentInstance, TestingWindow Window)
        {
            IAsyncTesting at = null;

            if (parentInstance != null && parentInstance is IAsyncTesting)
            {
                at = (IAsyncTesting)parentInstance;
                Window.WriteLine("Method supports async commands. You can write");
            }

            var th = new Thread(asyncRun);

            th.Start();
            var wth = new Thread(asyncWriting);

            wth.Start();

            if (th != null && th.IsAlive)
            {
                th.Join();
            }
            try { wth.Abort(); } catch { }
            Window.EndRead();

            void asyncRun()
            {
                Window.WriteLine($"\nInvoking \"{Target.Name}\" with params: \n\t{string.Join("\n\t", obj)}\n\t");
                Target.Invoke(parentInstance, obj);
                Window.WriteLine($"\nEnd of \"{Target.Name}\" invoke.");
            }

            void asyncWriting()
            {
                while (th != null && th.IsAlive)
                {
                    try { parseComm(Window.ReadLine(), Window, th, at); }
                    catch (ThreadAbortException) { }
                    catch (Exception ex) { Window.WriteLine($"Error during execution command: {ex.Message}"); }
                }
            }
        }