public void OverwriteExistingFilter()
        {
            var pipeline = new TextFilterPipeline("Append BAR");

            Assert.AreEqual("FOOBAR", pipeline.Execute("FOO"));

            TextFilterPipeline.AddType(typeof(OverwriteFilterTestClass));   // This should overwrite Core.Append

            Assert.AreEqual("FOOBAZ", pipeline.Execute("FOO"));
        }
Ejemplo n.º 2
0
        public void ReadFromVariable()
        {
            var pipeline = new TextFilterPipeline();

            pipeline.AddCommand("WriteTo Name");     // Writes original input to the variable "Name"
            pipeline.AddCommand("ReplaceAll Annie"); // Resets input to "Annie"

            Assert.AreEqual("Annie", pipeline.Execute("Anything"));

            pipeline.AddCommand("ReadFrom Name"); // Input should be the original again

            Assert.AreEqual("Deane", pipeline.Execute("Deane"));
        }
Ejemplo n.º 3
0
        public void ReadNonExistentVariableWithDefault()
        {
            var pipeline = new TextFilterPipeline();

            pipeline.AddCommand("ReadFrom Name Deane");

            Assert.AreEqual("Deane", pipeline.Execute("Annie"));
        }
        public void Replace()
        {
            var pipeline = new TextFilterPipeline();

            pipeline.AddCommand("Replace Deane Annie");
            string result = pipeline.Execute("Deane was here.");

            Assert.AreEqual("Annie was here.", result);
        }
        public void Prepend()
        {
            var pipeline = new TextFilterPipeline();

            pipeline.AddCommand("Prepend Deane");
            string result = pipeline.Execute(" was here.");

            Assert.AreEqual("Deane was here.", result);
        }
        public void Append()
        {
            var pipeline = new TextFilterPipeline();

            pipeline.AddCommand("Append Deane");
            string result = pipeline.Execute("I am ");

            Assert.AreEqual("I am Deane", result);
        }
        public void Format()
        {
            var pipeline = new TextFilterPipeline();

            pipeline.AddCommand("Format \"{0} was here.\"");
            string result = pipeline.Execute("Deane");

            Assert.AreEqual("Deane was here.", result);
        }
Ejemplo n.º 8
0
        public void Wrap()
        {
            var pipeline = new TextFilterPipeline();

            pipeline.AddCommand("html.Wrap p theClass theId");
            string result = pipeline.Execute("Deane");

            Assert.AreEqual("<p class=\"theClass\" id=\"theId\">Deane</p>", result);
        }
Ejemplo n.º 9
0
        public void GetFromArgument()
        {
            var pipeline = new TextFilterPipeline();

            pipeline.AddCommand("HTTP.Get http://gadgetopia.com/");
            string result = pipeline.Execute("");

            Assert.IsTrue(result.ToLower().Contains("gadgetopia"));
        }
        public void ReadContentFromFile()
        {
            var pipeline = new TextFilterPipeline();

            pipeline.AddCommand("file.Read Utility/text.txt");
            string result = pipeline.Execute(String.Empty);

            Assert.AreEqual("Deane", result);
        }
Ejemplo n.º 11
0
        public void WriteToVariable()
        {
            var pipeline = new TextFilterPipeline();

            pipeline.AddCommand("WriteTo Name");
            pipeline.Execute("Deane");

            Assert.AreEqual("Deane", pipeline.Variables["Name"]);
        }
        public void LoadCustomFiltersFromTypeWithCategoryName()
        {
            TextFilterPipeline.AddType("something", typeof(CustomFilters));
            Assert.IsTrue(TextFilterPipeline.CommandMethods.ContainsKey("something.mymethod"));

            var pipeline = new TextFilterPipeline();

            pipeline.AddCommand("something.MyMethod");
            Assert.AreEqual("MyMethod", pipeline.Execute());
        }
Ejemplo n.º 13
0
        public void WritingIntoImplicitVariable()
        {
            var pipeline = new TextFilterPipeline();

            pipeline.AddCommand("Append \" married Deane.\" => myVar");
            var result = pipeline.Execute("Annie");

            Assert.AreEqual(result, "Annie");   // The input text should be unchanged
            Assert.AreEqual(pipeline.Variables["myVar"], "Annie married Deane.");
        }
        public void FormatFromVariables()
        {
            var pipeline = new TextFilterPipeline();

            pipeline.AddCommand("WriteTo Name");
            pipeline.AddCommand("Format \"{Name} was here.\"");
            string result = pipeline.Execute("Deane");

            Assert.AreEqual("Deane was here.", result);
        }
Ejemplo n.º 15
0
        public void InvalidXpathFailsBackToCssSelector()
        {
            var pipeline = new TextFilterPipeline();

            pipeline.AddCommand("html.Extract h3.title");
            var result =
                pipeline.Execute(
                    "<html><head></head><body><h3 class='title'>2 + 2 = 10 ....in base 4</h3></body></html>");

            Assert.AreEqual("2 + 2 = 10 ....in base 4", result);
        }
Ejemplo n.º 16
0
        public void TransformXml()
        {
            // This test relies on a controled XSLT in the "Utility" folder

            var elementValue = "Deane";

            var pipeline = new TextFilterPipeline();

            // Write the incoming XML to a variable
            pipeline.AddCommand("WriteTo xml");

            // Read in the XSL
            pipeline.AddCommand("File.Read utility/transform.xslt");
            pipeline.AddCommand("WriteTo xsl");

            // Read back the XML, then call the transform from the XSL in the variable
            pipeline.AddCommand("ReadFrom xml");
            pipeline.AddCommand("XML.TransformXmlFromVariable xsl");

            var result = pipeline.Execute("<element>" + elementValue + "</element>");

            Assert.AreEqual(result.Substring(result.Length - elementValue.Length), elementValue);
        }
Ejemplo n.º 17
0
        private void ExecuteButton_Click(object sender, EventArgs e)
        {
            PipelineResults.BackColor = Color.FromName("White");

            try
            {
                var stopWatch = new Stopwatch();
                stopWatch.Start();
                var pipeline = new TextFilterPipeline();
                pipeline.AddCommand(PipelineCommands.Text);
                long parseTime = stopWatch.ElapsedMilliseconds;
                PipelineResults.Text = pipeline.Execute(InputTextbox.Text);
                long executionTime = stopWatch.ElapsedMilliseconds;
                stopWatch.Reset();

                Status.Text = String.Format("{0}ms / {1}ms", parseTime, executionTime);
            }
            catch (Exception exception)
            {
                PipelineResults.Text      = String.Join(Environment.NewLine, exception.Message, exception.StackTrace);
                PipelineResults.BackColor = Color.FromName("LightPink");
            }
        }