Exemplo n.º 1
0
        public ProtoExecutionResult Execute(MethodInfo method, params object[] args)
        {
            Logger.Debug("Execution method: {0}.{1}", method.DeclaringType.FullName, method.Name);
            var stopwatch       = Stopwatch.StartNew();
            var builder         = ProtoExecutionResult.CreateBuilder().SetFailed(false);
            var executionResult = _sandbox.ExecuteMethod(method, StringParamConverter.TryConvertParams(method, args));

            builder.SetExecutionTime(stopwatch.ElapsedMilliseconds);
            if (!executionResult.Success)
            {
                Logger.Error("Error executing {0}.{1}", method.DeclaringType.FullName, method.Name);

                var elapsedMilliseconds = stopwatch.ElapsedMilliseconds;
                builder.SetFailed(true);
                var isScreenShotEnabled = Utils.TryReadEnvValue("SCREENSHOT_ENABLED");
                if (isScreenShotEnabled == null || isScreenShotEnabled.ToLower() != "false")
                {
                    builder.SetScreenShot(TakeScreenshot());
                }
                builder.SetErrorMessage(executionResult.ExceptionMessage);
                builder.SetStackTrace(executionResult.StackTrace);
                builder.SetRecoverableError(false);
                builder.SetExecutionTime(elapsedMilliseconds);
            }
            return(builder.Build());
        }
Exemplo n.º 2
0
        public void ShouldTryToConvertStringParameterToString()
        {
            var type   = new TestTypeConversion().GetType();
            var method = type.GetMethod("Int");

            var getParams = StringParamConverter.TryConvertParams(method, new object[] { "hahaha" });

            Assert.AreEqual(typeof(string), getParams.First().GetType());
        }
Exemplo n.º 3
0
        public void ShouldTryToConvertStringParameterToBool()
        {
            var type   = new TestTypeConversion().GetType();
            var method = type.GetMethod("Bool");

            var getParams = StringParamConverter.TryConvertParams(method, new object[] { "false" });

            Assert.AreEqual(typeof(bool), getParams.First().GetType());
        }
Exemplo n.º 4
0
        public void ShouldConvertFromParameterToString()
        {
            const string expected  = "Foo";
            var          parameter = new Parameter.Builder().SetParameterType(Parameter.Types.ParameterType.Static).SetValue(expected).Build();

            var actual = new StringParamConverter().Convert(parameter, null);

            Assert.AreEqual(expected, actual);
        }
        public void ShouldConvertFromParameterToString()
        {
            const string expected  = "Foo";
            var          parameter = new Parameter
            {
                ParameterType = Parameter.Types.ParameterType.Static,
                Value         = expected
            };

            var actual = new StringParamConverter().Convert(parameter);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 6
0
        public ExecutionResult Execute(GaugeMethod gaugeMethod, params string[] args)
        {
            {
                var method          = gaugeMethod.MethodInfo;
                var executionResult = new ExecutionResult {
                    Success = true
                };
                var logger = LogManager.GetLogger("StepExecutor");
                try
                {
                    var parameters = args.Select(o =>
                    {
                        try
                        {
                            return(GetTable(o));
                        }
                        catch
                        {
                            return(o);
                        }
                    }).ToArray();
                    logger.Debug("Executing method: {0}", gaugeMethod.Name);
                    Execute(method, StringParamConverter.TryConvertParams(method, parameters));
                }
                catch (Exception ex)
                {
                    logger.Debug("Error executing {0}", method.Name);
                    var innerException = ex.InnerException ?? ex;
                    executionResult.ExceptionMessage = innerException.Message;
                    executionResult.StackTrace       = innerException is AggregateException
                        ? innerException.ToString()
                        : innerException.StackTrace;

                    executionResult.Source      = innerException.Source;
                    executionResult.Success     = false;
                    executionResult.Recoverable = gaugeMethod.ContinueOnFailure;
                }

                return(executionResult);
            }
        }