private void Execute(TestSet testSet) { // Each testset will run in it's own http session HttpSession session = new HttpSession(this.project.GetBaseUrl(), testSet.GetAuthentication()); LOG.InfoFormat("TestSet: {0}", testSet.Name); foreach (Function function in testSet.Functions) { Execute(session, testSet.GetContext(), function); } testSet.Executed = true; session.End(); session = null; }
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; }