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 PdfPTable CreateTestSet(TestSet testSet)
        {
            PdfPTable table = new PdfPTable(new float[] { 2, 8 });
            StyleDefaultCell(table.DefaultCell);
            table.SpacingAfter = 5;
            table.WidthPercentage = 100f;
            AddHeaderCell(table, "TestSet");
            AddNormalCell(table, testSet.Name);

            if (!string.IsNullOrEmpty(testSet.Description))
            {
                AddHeaderCell(table, "Description");
                AddNormalCell(table, testSet.Description);
            }

            int success = 0;
            int total = 0;

            foreach (Function function in testSet.Functions)
            {
                if (!string.IsNullOrEmpty(function.Name))
                {
                    AddHeaderCell(table, "Name");
                    AddNormalCell(table, function.Name);
                }
                if (!string.IsNullOrEmpty(function.Description))
                {
                    AddHeaderCell(table, "Description");
                    AddNormalCell(table, function.Description);
                }

                AddHeaderCell(table, "Call");
                AddNormalCell(table, function.Method + " " + function.GetResult().ExecutedUrl);

                AddHeaderCell(table, "Result");

                if (function.GetResult().Executed)
                {
                    total++;

                    StringBuilder text = new StringBuilder();

                    if (function.GetResult().Success)
                    {
                        text.Append("SUCCESS");
                    }
                    else
                    {
                        text.Append("FAILED (");
                        text.Append(function.GetResult().StatusCode);
                        text.Append(" ");
                        text.Append(function.GetResult().StatusDescription);
                        text.Append(")");
                    }

                    Phrase phrase = new Phrase(text.ToString(), GetNormalFont());
                    PdfPCell cell = new PdfPCell(phrase);

                    if (function.GetResult().Success)
                    {
                        cell.BackgroundColor = new Color(0, 255, 0);
                    }
                    else
                    {
                        cell.BackgroundColor = new Color(255, 0, 0);
                    }
                    table.AddCell(cell);

                    // count the successes
                    if (function.GetResult().Success)
                    {
                        success++;
                    }
                    else
                    {
                        if (this.settings.ShowDebug)
                        {
                            AddHeaderCell(table, "Debuging output");
                            AddNormalCell(table, function.GetResult().ResponseText);
                        }
                    }
                }
                else
                {
                    Phrase phrase = new Phrase("Skipped", GetNormalFont());
                    PdfPCell cell = new PdfPCell(phrase);
                    cell.BackgroundColor = new Color(150, 150, 150);
                    table.AddCell(cell);
                }

                AddHeaderCell(table, "Execution time");
                AddNormalCell(table, function.GetResult().ExecutionTime.ToString());
            }

            // add summary
            decimal percentage = (((decimal)success / (decimal)total) * 100);
            AddHeaderCell(table, "Total score");
            AddNormalCell(table, string.Format("{1} total, {0} successful ({2:0.00}%)", success, total, percentage));

            return table;
        }
        private TestSet ReadTestSet(Project project)
        {
            TestSet testSet = new TestSet(project);

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:

                        if (reader.Name.Equals("name"))
                        {
                            testSet.Name = reader.ReadElementContentAsString();
                        }
                        else if (reader.Name.Equals("description"))
                        {
                            testSet.Description = GetDescription();
                        }
                        else if (reader.Name.Equals("authentication"))
                        {
                            string name = null;

                            for (int i = 0; i < reader.AttributeCount; i++)
                            {
                                reader.MoveToAttribute(i);
                                if (reader.Name.Equals("ref"))
                                {
                                    name = reader.Value;
                                }
                            }

                            testSet.SetAuthentication(project.GetAuthenticationByName(name));
                        }
                        else if (reader.Name.Equals("function"))
                        {
                            string refName = null;
                            int waitInSeconds = 0;
                            bool whenPreviousFunctionFailed = false;

                            if (testSet.Functions == null)
                            {
                                testSet.Functions = new List<Function>();
                            }
                            if (reader.HasAttributes)
                            {
                                for (int i = 0; i < reader.AttributeCount; i++)
                                {
                                    reader.MoveToAttribute(i);

                                    if (reader.Name.Equals("ref"))
                                    {
                                        refName = reader.Value;
                                    }

                                    else if (reader.Name.Equals("whenPreviousFunctionFailed"))
                                    {
                                        string boolVal = reader.Value;
                                        if (boolVal != null)
                                        {
                                            whenPreviousFunctionFailed = (boolVal.Equals("true") || boolVal.Equals("on") || boolVal.Equals("1"));
                                        }
                                    }
                                    else if (reader.Name.Equals("waitInSeconds"))
                                    {
                                        waitInSeconds = Int32.Parse(reader.Value);
                                    }
                                }

                                if (!string.IsNullOrEmpty(refName))
                                {
                                    Function functionRef = project.GetFunctionByName(reader.Value);
                                    if (functionRef != null)
                                    {
                                        testSet.Functions.Add(functionRef);
                                    }
                                }
                            }

                            if (string.IsNullOrEmpty(refName))
                            {
                                Function function = ReadFunction(project);
                                function.SetWaitInSeconds(waitInSeconds);
                                function.SetWhenPreviousFunctionFailed(whenPreviousFunctionFailed);

                                testSet.Functions.Add(function);
                            }
                        }
                        break;

                    case XmlNodeType.EndElement:

                        if (reader.Name.Equals("testSet"))
                        {
                            return testSet;
                        }

                        break;
                }
            }

            return testSet;
        }