Beispiel #1
0
        public Context GetContext()
        {
            if (this.context == null)
            {
                this.context = this.project.GetInitialContext();
            }

            return this.context;
        }
Beispiel #2
0
        public Context Copy()
        {
            Context copy = new Context();

            foreach (string key in this.variables.Keys)
            {
                copy.Add(key, this.variables[key]);
            }

            return copy;
        }
Beispiel #3
0
 public void Process(IResponse response, Context context)
 {
     foreach (AbstractProcessor processor in this.processors)
     {
         processor.Process(response, context);
     }
 }
 public ContextResolver(Context context)
 {
     this.context = context;
 }
        private void Execute(HttpSession session, Context context, Function function)
        {
            LOG.InfoFormat("Function: {0}", function.Name);

            if (function.WhenPreviousFunctionFailed() && this.lastFunctionSucceeded)
            {
                LOG.InfoFormat("Function: {0} is not required to run, previous function succeeded.", function.Name);
                function.Skip();
                return;
            }

            if (function.GetWaitInSeconds() > 0)
            {
                LOG.InfoFormat("Waiting for {0} seconds...", function.GetWaitInSeconds());
                Thread.Sleep(function.GetWaitInSeconds() * 1000);
            }

            string url = function.GetUrl(context.GetResolver());

            if ("GET".Equals(function.Method))
            {
                session.Execute(url, "GET", function.GetHeaders());
            }
            else if ("POST".Equals(function.Method))
            {
                session.Execute(url, "POST", function.GetHeaders(), function.GetPostData(context.GetResolver()), function.GetPostBody());
            }
            else if ("PUT".Equals(function.Method))
            {
                session.Execute(url, "PUT", function.GetHeaders(), function.GetPostData(context.GetResolver()), function.GetPostBody());
            }
            else if ("DELETE".Equals(function.Method))
            {
                session.Execute(url, "DELETE", function.GetHeaders());
            }
            else
            {
                // Not support http method
                throw new InvalidOperationException();
            }

            // execute tests on results
            try
            {
                function.Assert(session);
            }
            catch (Exception e)
            {
                LOG.Error("Failed to run assertions on " + session.GetResponseText(), e);

                throw e;
            }

            // process the data
            try
            {
                function.Process(session, context);
            }
            catch (Exception e)
            {
                LOG.Error("Failed to run processor on " + session.GetResponseText(), e);

                throw e;
            }

            LOG.Info("Function call: " + (function.GetResult().Success ? "SUCCESS" : "FAILED"));

            if (!function.GetResult().Success)
            {
                LOG.DebugFormat("Result (code:{0}): {1}", function.GetResult().StatusCode, function.GetResult().ResponseText);
            }

            this.lastFunctionSucceeded = function.GetResult().Success;
        }