public IMessage SyncProcessMessage(IMessage msg)
        {
            var methodMessage = new MethodCallMessageWrapper((IMethodCallMessage)msg);

            IMethodReturnMessage mrm = null;

            Reporters.ExecuteStep(
                () =>
            {
                IMessage rtnMsg = next.SyncProcessMessage(msg);
                mrm             = (rtnMsg as IMethodReturnMessage);

                if (mrm.Exception != null)
                {
                    throw mrm.Exception;
                }
            },
                methodMessage.MethodBase,
                methodMessage.Args
                );

            return(mrm);
        }
Пример #2
0
        internal static void ExecuteStep(Action action, MethodBase methodBase, params object[] args)
        {
            methodBase = methodBase ?? action.Method;

            var currentSteps = new Dictionary <Reporter, Step>();

            var starttime = Reporters.CurrentRunTime;

            foreach (var reporter in Reporters.GetAll())
            {
                currentSteps.Add(reporter, reporter.CurrentStep);

                var step = CreateStep(starttime, methodBase, args);

                var stepContainer = reporter.CurrentStep ?? reporter.CurrentScenarioBlock;
                stepContainer.Steps.Add(step);
                reporter.CurrentStep = step;
                Reporters.OnStartedStep(reporter);
            }

            Exception actionException = null;

            try
            {
                if (action.Method.GetParameters().Count() == 0)
                {
                    action.Method.Invoke(action.Target, null);
                }
                else
                {
                    action.Method.Invoke(action.Target, args);
                }
            }
            catch (Exception ex)
            {
                if (ex is TargetInvocationException && ex.InnerException != null)
                {
                    // Exceptions thrown by ReportingMessageSink are wrapped in a TargetInvocationException
                    actionException = ex.InnerException;
                }
                else
                {
                    actionException = ex;
                }
            }
            finally
            {
                var endtime = Reporters.CurrentRunTime;

                TestResult testResult;
                if (actionException is PendingStepException)
                {
                    testResult = TestResult.Pending;
                }
                else if (actionException != null)
                {
                    testResult = TestResult.Error;
                }
                else
                {
                    testResult = TestResult.OK;
                }

                foreach (var reporter in Reporters.GetAll())
                {
                    reporter.CurrentStep.EndTime   = endtime;
                    reporter.CurrentStep.Result    = testResult;
                    reporter.CurrentStep.Exception = actionException.ToExceptionInfo();
                    Reporters.OnFinishedStep(reporter);

                    reporter.CurrentStep = currentSteps[reporter];
                }
            }
        }
Пример #3
0
 public void ReportStep(Action action, params object[] args)
 {
     Reporters.ExecuteStep(action, args);
 }