Exemple #1
0
        /// <summary>
        /// Runs a test for a specific class and method.
        /// </summary>
        /// <param name="op">The operation data.</param>
        /// <param name="done">The completion callback.</param>
        public void HandleOp(OperationData op, Action done)
        {
            var testOp = (RunTestOperation)op;
            var func = GetTestFunc(testOp);
            var err = "";

            ConsoleProxy.log("Running test: " + testOp.ClassName + "." + testOp.MethodName);

            object result = null;
            try { result = func(); }
            catch (Exception ex)
            {
                // exceptions indicate test failure
                var browser = GetBrowserName();
                err = ((browser != null) ? ("[" + browser + "] ") : "") + ex.toString();

                ConsoleProxy.log("Test Failed: " + err);
                ClientHost.Service.FailTest(err, done);
                return;
            }

            // tests returing null or undefined indicate 
            // the test is complete and has passed
            if (result == null || result == window.undefined)
            {
                ConsoleProxy.log("Test Passed");
                ClientHost.Service.PassTest(done);
                return;
            }

            // if a test result type is returned, the 
            // result may be deferred due to async execution
            if (result is TestResult)
            {
                CheckAsyncResult((TestResult)result, done);
                return;
            }

            // the return type was not of any expected
            // value, return as test failure
            ClientHost.Service.FailTest(
                "Unexpected test return value. Synchronous tests should return void. " +
                "Asynchronous tests should return an object of type TestResult.", done);
        }
Exemple #2
0
        /// <summary>
        /// Routes the operation to the correct handler, based on the command.
        /// </summary>
        /// <param name="op">The operation data.</param>
        /// <param name="done">The completion callback.</param>
        public static void HandleOp(OperationData op, Action done)
        {
            if (!(dynamic)op || !(dynamic)op.Command)
                return;

            IOperationHandler handler = null;

            switch (op.Command)
            {
                case "RunTest": handler = new RunTestHandler();
                    break;

                case "Wait": handler = new WaitHandler();
                    break;

                default:
                    throw new Error("Unexpected command: " + op.Command);
            }

            if (handler != null)
                handler.HandleOp(op, done);
            else done();
        }
Exemple #3
0
 /// <summary>
 /// Waits for a short period.
 /// </summary>
 /// <param name="op">The operation data.</param>
 /// <param name="done">The completion callback.</param>
 public void HandleOp(OperationData op, Action done)
 {
     ConsoleProxy.log("Waiting...");
     window.setTimeout(done, 1500);
 }