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); }
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")); }
public void ReadNonExistentVariableWithDefault() { var pipeline = new TextFilterPipeline(); pipeline.AddCommand("ReadFrom Name Deane"); Assert.AreEqual("Deane", pipeline.Execute("Annie")); }
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 GetFromArgument() { var pipeline = new TextFilterPipeline(); pipeline.AddCommand("HTTP.Get http://gadgetopia.com/"); string result = pipeline.Execute(""); Assert.IsTrue(result.ToLower().Contains("gadgetopia")); }
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); }
public void WriteToVariable() { var pipeline = new TextFilterPipeline(); pipeline.AddCommand("WriteTo Name"); pipeline.Execute("Deane"); Assert.AreEqual("Deane", pipeline.Variables["Name"]); }
public void ReadContentFromFile() { var pipeline = new TextFilterPipeline(); pipeline.AddCommand("file.Read Utility/text.txt"); string result = pipeline.Execute(String.Empty); Assert.AreEqual("Deane", 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 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 Format() { var pipeline = new TextFilterPipeline(); pipeline.AddCommand("Format \"{0} was here.\""); string result = pipeline.Execute("Deane"); Assert.AreEqual("Deane was here.", result); }
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()); }
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 AddCommandByString() { var pipeline = new TextFilterPipeline(); pipeline.AddCommand("Replace", new Dictionary <object, string> { { "a", "b" } }); Assert.AreEqual("b", pipeline.Commands.First().CommandArgs.Last().Value); }
public void AddQuotedCommandsByString() { var pipeline = new TextFilterPipeline(); pipeline.AddCommand("Replace Deane \"Annie was here\""); Assert.AreEqual("Replace", pipeline.Commands.First().CommandName); Assert.AreEqual("Deane", pipeline.Commands.First().CommandArgs.First().Value); Assert.AreEqual("Annie was here", pipeline.Commands.First().CommandArgs.Last().Value); }
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); }
public void AddCommandWithComment() { string commandString = @" Replace a b #Replace c d "; var pipeline = new TextFilterPipeline(); pipeline.AddCommand(commandString); Assert.AreEqual(1, pipeline.Commands.Count); }
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); }
public void AddCommandByObject() { var command = new TextFilterCommand(); command.CommandName = "Replace"; command.CommandArgs.Add("a", "b"); var pipeline = new TextFilterPipeline(); pipeline.AddCommand(command); Assert.AreEqual(1, pipeline.Commands.Count()); Assert.AreEqual("Replace", pipeline.Commands.First().CommandName); Assert.AreEqual("b", pipeline.Commands.First().CommandArgs.First().Value); }
public void AddMultipleCommandsByString() { string commandString = @" Replace a b Replace c d "; var pipeline = new TextFilterPipeline(); pipeline.AddCommand(commandString); Assert.AreEqual("Replace", pipeline.Commands.First().CommandName); Assert.AreEqual("Replace", pipeline.Commands[1].CommandName); Assert.AreEqual("b", pipeline.Commands.First().CommandArgs.Last().Value); }
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"); } }