Example #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string url = "http://www.glennjones.net/about/";

            UfWebRequest webRequest = new UfWebRequest();

            webRequest.Load(url, UfFormats.HCard());

            UfDataNode hcard = webRequest.Data.Nodes[0];
            string     gn1   = hcard.DescendantValue("n/given-name");
            string     gn2   = hcard.DescendantNode("n/given-name").Value;
            string     ea    = hcard.DescendantNode("adr[0]/extended-address[1]").Value;

            Response.Write("<div>" + gn1 + "</div>");
            Response.Write("<div>" + gn2 + "</div>");
            Response.Write("<div>" + ea + "</div>");

            Response.Write("<html><body>");
            foreach (UfDataNode node in webRequest.Data.Nodes)
            {
                WriteNode(node, "");
            }

            Response.Write("</body></html>");
        }
Example #2
0
 public void WriteNode(UfDataNode node, string indent)
 {
     Response.Write("<div>" + indent + node.Name + " - " + node.Value);
     indent += "&nbsp;&nbsp;&nbsp;";
     foreach (UfDataNode childnode in node.Nodes)
     {
         //Response.Write("<div>" + indent + childnode.Name + " - " + childnode.Value + "</div>");
         WriteNode(childnode, indent);
     }
 }
        /// <summary>
        /// Finds each test suite group
        /// </summary>
        /// <param name="node"></param>
        public void FindTestSuite(UfDataNode node)
        {
            foreach (UfDataNode childNode in node.Nodes)
            {
                string url    = childNode.Nodes["url"].Value;
                string format = childNode.Nodes["format"].Value;
                //Console.WriteLine("Found: " + url);

                LoadTestFixture(url);
                number++;
            }
        }
        public void BuildAsset(UfDataNode node, StringBuilder stringBuilder, int assertNumber)
        {
            string test    = node.Nodes["test"].Value;
            string result  = node.Nodes["result"].Value;
            string comment = node.Nodes["comment"].Value;

            stringBuilder.AppendLine(" ");
            stringBuilder.AppendLine("[Test]");
            if (assertNumber > 9)
            {
                stringBuilder.AppendLine("public void Test_" + assertNumber.ToString() + "()");
            }
            else
            {
                stringBuilder.AppendLine("public void Test_0" + assertNumber.ToString() + "()");
            }
            stringBuilder.AppendLine("{");
            stringBuilder.AppendLine("// " + test);

            BuildAssertResult(stringBuilder, test, result, comment);

            stringBuilder.AppendLine("}");
            stringBuilder.AppendLine(" ");
        }
        public void BuildTest(UfDataNode node, string url)
        {
            // Find summary, description and format
            string summary     = node.Nodes[0].Nodes["summary"].Value;
            string description = node.Nodes[0].Nodes["description"].Value;
            string format      = node.Nodes[0].Nodes["format"].Value;
            //Console.WriteLine(summary);

            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("using System;");
            stringBuilder.AppendLine("using System.Collections;");
            stringBuilder.AppendLine("using System.Collections.Generic;");
            stringBuilder.AppendLine("using System.Text;");
            stringBuilder.AppendLine("using NUnit.Framework;");
            stringBuilder.AppendLine("using NUnit.Framework.Constraints;");
            stringBuilder.AppendLine("using NUnit.Framework.SyntaxHelpers;");
            stringBuilder.AppendLine("using UfXtract;");
            stringBuilder.AppendLine("using UfXtract.Utilities;");
            stringBuilder.AppendLine(" ");
            stringBuilder.AppendLine("namespace UfXtract.UnitTests." + format);
            stringBuilder.AppendLine("{");
            stringBuilder.AppendLine(" ");


            stringBuilder.AppendLine("[TestFixture]");
            stringBuilder.AppendLine("public class test_" + TestName(summary, url));
            stringBuilder.AppendLine("{");

            stringBuilder.AppendLine("// " + url);
            stringBuilder.AppendLine("// " + summary);
            stringBuilder.AppendLine("// " + description);
            stringBuilder.AppendLine("// Built: " + DateTime.Now.ToLongDateString());

            stringBuilder.AppendLine(" ");
            stringBuilder.AppendLine("UfWebRequest webRequest;");
            stringBuilder.AppendLine("UfDataNodes nodes;");
            stringBuilder.AppendLine(" ");

            stringBuilder.AppendLine("[SetUp]");
            stringBuilder.AppendLine("public void Test_Settup()");
            stringBuilder.AppendLine("{");
            stringBuilder.AppendLine("webRequest = new UfWebRequest();");
            stringBuilder.AppendLine("string url = \"" + url + "#uf\";");

            if (format.ToLower() == "hcard")
            {
                stringBuilder.AppendLine("webRequest.Load(url, UfFormats.HCard());");
            }
            if (format.ToLower() == "hcalendar")
            {
                stringBuilder.AppendLine("webRequest.Load(url, UfFormats.HCalendar());");
            }
            if (format.ToLower() == "hresume")
            {
                stringBuilder.AppendLine("webRequest.Load(url, UfFormats.HResume());");
            }
            if (format.ToLower() == "hrecipe")
            {
                stringBuilder.AppendLine("webRequest.Load(url, UfFormats.HRecipe());");
            }
            if (format.ToLower() == "geo")
            {
                stringBuilder.AppendLine("webRequest.Load(url, UfFormats.Geo());");
            }


            stringBuilder.AppendLine("nodes = webRequest.Data.Nodes;");
            stringBuilder.AppendLine("}");
            stringBuilder.AppendLine(" ");

            int assertNumber = 1;

            foreach (UfDataNode childNode in node.Nodes[0].Nodes)
            {
                if (childNode.Name == "assert")
                {
                    BuildAsset(childNode, stringBuilder, assertNumber);
                    assertNumber++;
                }
            }

            stringBuilder.AppendLine("}");
            stringBuilder.AppendLine("}");

            string filename = "test_" + TestName(summary, url) + ".cs";

            string filepath = path + filename;

            WriteFile(stringBuilder.ToString(), filepath);
        }