Beispiel #1
0
        public void SubstitutedCommand()
        {
            Pipeline.RegisterCommandFactory("Add.IsAwesome", (command) =>
            {
                // The first included script references a second script
                if (command.NormalizedCommandName.ToLower() == "Add.IsAwesome".ToLower())
                {
                    return(PipelineCommandParser.ParseCommandString("Text.Append -suffix:IsAwesome"));
                }
                else
                {
                    return(new List <PipelineCommand>());
                }
            });

            var p = new Pipeline();

            p.AddCommand("Text.Append -suffix:Foo");
            p.AddCommand("Add.IsAwesome");
            p.AddCommand("Text.Append -suffix:Bar");

            var result = p.Execute();

            Assert.AreEqual("FooIsAwesomeBar", result);
        }
Beispiel #2
0
        public void SetVar()
        {
            var pipeline = new Pipeline();

            pipeline.AddCommand("SetVar -var:Deane -value:Awesome");
            pipeline.AddCommand("ReadFrom Deane");
            var result = pipeline.Execute();

            Assert.AreEqual("Awesome", result);
        }
        public void AppendingVariables()
        {
            var pipeline = new Pipeline();

            pipeline.AddCommand("SetVar -var:Name -value:Annie");
            pipeline.AddCommand("AppendVar -var:Name -value:Deane");
            var result = pipeline.Execute();

            Assert.AreEqual("AnnieDeane", pipeline.GetVariable("Name"));
        }
        public void ReadFromVariable()
        {
            var pipeline = new Pipeline();

            pipeline.AddCommand("WriteTo $Name");               // Writes original input to the variable "Name"
            pipeline.AddCommand("Text.ReplaceAll -text:Annie"); // Resets input to "Annie"
            pipeline.AddCommand("ReadFrom $Name");              // Input should be the original again

            Assert.AreEqual("Deane", pipeline.Execute("Deane"));
        }
Beispiel #5
0
        public void FormatFromVariables()
        {
            var pipeline = new Pipeline();

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

            Assert.AreEqual("Deane was here.", result);
        }
Beispiel #6
0
        public void InitVar()
        {
            var pipeline = new Pipeline();

            pipeline.AddCommand("InitVar -var:Deane -var:Annie");
            pipeline.AddCommand("ReadFrom Deane");
            pipeline.AddCommand("ReadFrom Annie");
            pipeline.Execute();

            // No need for an assertion. If it didn't work, it would throw an exception...
        }
        public void ResolveVariableNames()
        {
            var input = "Deane";

            var pipeline = new Pipeline();

            pipeline.AddCommand("WriteTo $myVar");              // Write the input to a variable
            pipeline.AddCommand("Text.Prepend -prefix:$myVar"); // Prepend that variable onto the input
            var result = pipeline.Execute(input);

            Assert.AreEqual(String.Concat(input, input), result);   // Result should be the input twice
        }
        public void AppendToImplicitVariable()
        {
            var pipeline = new Pipeline();

            pipeline.AddCommand("Text.Append -suffix:\" married Deane.\" => $myVar");
            pipeline.AddCommand("Text.ReplaceAll -text:\" \" ==> $myVar");
            pipeline.AddCommand("Text.Append -suffix:\" likes Deane.\" ==> $myVar");
            var result = pipeline.Execute("Annie");

            Assert.AreEqual(result, "Annie");   // The input text should be unchanged
            Assert.AreEqual(pipeline.GetVariable("myVar"), "Annie married Deane. Annie likes Deane.");
        }
Beispiel #9
0
        public void DebugData()
        {
            var pipeline = new Pipeline();

            pipeline.AddCommand("Text.Prepend -prefix:Deane");
            pipeline.AddCommand("Text.Append -suffix:Barker");
            pipeline.Execute();

            Assert.AreEqual(pipeline.DebugData.Count, 2);
            Assert.AreEqual(pipeline.DebugData.First().InputValue.Length, 0);
            Assert.AreEqual(pipeline.DebugData.First().OutputValue.Length, 5);
            Assert.AreEqual(pipeline.DebugData.Last().InputValue.Length, 5);
            Assert.AreEqual(pipeline.DebugData.Last().OutputValue.Length, 11);
        }
Beispiel #10
0
        public void SimpleFactory()
        {
            Pipeline.RegisterCommandFactory("Core.Include", (command) => { return(PipelineCommandParser.ParseCommandString("Text.Append -suffix:Bar")); });

            var p = new Pipeline();

            p.AddCommand("Text.Append -suffix:Foo");
            p.AddCommand("Include");
            p.AddCommand("Text.Append -suffix:Baz");

            var result = p.Execute();

            Assert.AreEqual("FooBarBaz", result);
        }
Beispiel #11
0
        public void RemoveFilter()
        {
            Func <string, PipelineCommand, ExecutionLog, string> myFilter = (input, command, log) =>
            {
                return("It worked!");
            };

            Pipeline.ReflectMethod(myFilter.Method, "Foo", "Bar");

            Assert.IsTrue(Pipeline.CommandMethods.ContainsKey("foo.bar"));
            Pipeline.RemoveCommand("Foo.Bar", "Never use this!!!");
            Assert.IsFalse(Pipeline.CommandMethods.ContainsKey("foo.bar"));

            var pipeline = new Pipeline();

            pipeline.AddCommand("Foo.Bar");

            try
            {
                pipeline.Execute("baz");
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.Message.Contains("!!!"));
            }
        }
        public void VariablePrefixes()
        {
            return; // This test may be invalid now...

            var input        = "Deane";
            var variableName = "myVar";

            var pipeline = new Pipeline();

            pipeline.AddCommand("WriteTo " + variableName);
            pipeline.AddCommand("WriteTo $" + variableName);    // The prefix should be removed. This should write the same place as the first command.
            var result = pipeline.Execute(input);

            Assert.AreEqual(1, pipeline.Variables.Count);
            Assert.AreEqual(variableName, pipeline.Variables.First().Key);
            Assert.AreEqual(input, pipeline.GetVariable(variableName));
        }
Beispiel #13
0
        public void ReplaceAll()
        {
            var pipeline = new Pipeline();

            pipeline.AddCommand("Text.ReplaceAll -text:deane");
            string result = pipeline.Execute("Annie was here.");

            Assert.AreEqual("deane", result);
        }
Beispiel #14
0
        public void LineBreaks()
        {
            var pipeline = new Pipeline();

            pipeline.AddCommand("Html.LineBreaks");
            var result = pipeline.Execute("Deane" + Environment.NewLine + "Annie");

            Assert.AreEqual("Deane<br/>Annie", result);
        }
Beispiel #15
0
        public void Wrap()
        {
            var pipeline = new Pipeline();

            pipeline.AddCommand("html.Wrap -tag:p -class:theClass -id:theId");
            string result = pipeline.Execute("Deane");

            Assert.AreEqual("<p class=\"theClass\" id=\"theId\">Deane</p>", result);
        }
Beispiel #16
0
        public void ReadContentFromFile()
        {
            var pipeline = new Pipeline();

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

            Assert.AreEqual("Deane", result);
        }
Beispiel #17
0
        public void Append()
        {
            var pipeline = new Pipeline();

            pipeline.AddCommand("Text.Append -suffix:Deane");
            string result = pipeline.Execute("I am ");

            Assert.AreEqual("I am Deane", result);
        }
Beispiel #18
0
        public void NullFactory()
        {
            Pipeline.RegisterCommandFactory("Core.Include", (command) =>
            {
                // This is an empty list...
                return(new List <PipelineCommand>());
            });

            var p = new Pipeline();

            p.AddCommand("Text.Append -suffix:Foo");
            p.AddCommand("Include"); // This should include nothing, and just get removed
            p.AddCommand("Text.Append -suffix:Baz");

            var result = p.Execute();

            Assert.AreEqual("FooBaz", result);
        }
Beispiel #19
0
        public void FromText()
        {
            var pipeline = new Pipeline();

            pipeline.AddCommand("Template.FromText -template:\"Foo {{ data }}\"");
            string result = pipeline.Execute("Bar");

            Assert.AreEqual("Foo Bar", result);
        }
Beispiel #20
0
        public void FromXml()
        {
            var pipeline = new Pipeline();

            pipeline.AddCommand("Template.FromXml -template:\"Foo {{ data.name.first }} {{ data.name.last }}\"");
            string result = pipeline.Execute("<person><name><first>Bar</first><last>Baz</last></name></person>");

            Assert.AreEqual("Foo Bar Baz", result);
        }
        public void WriteToVariable()
        {
            var pipeline = new Pipeline();

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

            Assert.AreEqual("Deane", pipeline.GetVariable("Name"));
        }
Beispiel #22
0
        public void Format()
        {
            var pipeline = new Pipeline();

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

            Assert.AreEqual("Deane was here.", result);
        }
Beispiel #23
0
        public void Prepend()
        {
            var pipeline = new Pipeline();

            pipeline.AddCommand("Text.Prepend -prefix:Deane");
            string result = pipeline.Execute(" was here.");

            Assert.AreEqual("Deane was here.", result);
        }
Beispiel #24
0
        public void AddQuotedCommandsByString()
        {
            var pipeline = new Pipeline();

            pipeline.AddCommand("Replace -old:Deane -new:\"Annie was here\"");

            Assert.AreEqual("Replace", pipeline.Commands.First().FullyQualifiedCommandName);
            Assert.AreEqual("Deane", pipeline.Commands.First().CommandArgs.First().Value);
            Assert.AreEqual("Annie was here", pipeline.Commands.First().CommandArgs.Last().Value);
        }
Beispiel #25
0
        public void AddCommandByString()
        {
            var pipeline = new Pipeline();

            pipeline.AddCommand("Replace", new Dictionary <object, string> {
                { "a", "b" }
            });

            Assert.AreEqual("b", pipeline.Commands.First().CommandArgs.Last().Value);
        }
Beispiel #26
0
        public void ChangeQuerystringArg()
        {
            var url = "http://example.com/?a=b";
            var p   = new Pipeline();

            p.AddCommand("Url.AddQuerystringArg -key:a -value:c");
            var result = p.Execute(url);

            Assert.AreEqual("http://example.com/?a=c", result);
        }
Beispiel #27
0
        public void ReadContentFromFile()
        {
            Pipeline.SetGlobalVariable(File.SANDBOX_VARIABLE_NAME, AppDomain.CurrentDomain.BaseDirectory);
            var pipeline = new Pipeline();

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

            Assert.AreEqual("Deane", result);
        }
Beispiel #28
0
        public void LoadCustomFiltersFromTypeWithCategoryName()
        {
            Pipeline.AddType(typeof(CustomFilters), "something");
            Assert.IsTrue(Pipeline.CommandMethods.ContainsKey("something.mymethod"));

            var pipeline = new Pipeline();

            pipeline.AddCommand("something.MyMethod");
            Assert.AreEqual("MyMethod", pipeline.Execute());
        }
Beispiel #29
0
        public void AddingIdenticalArgumentKeys()
        {
            var pipeline = new Pipeline();

            pipeline.AddCommand("Text.Format -template:deane -template:barker -template:was -template:here -other:argument");

            Assert.AreEqual(5, pipeline.Commands.First().CommandArgs.Count);
            Assert.AreEqual("template.3", pipeline.Commands.First().CommandArgs.Skip(3).First().Key);
            Assert.AreEqual(4, pipeline.Commands.First().GetMultiArgument("template").Count);
        }
Beispiel #30
0
        public void GetFromInput()
        {
            Pipeline.SetGlobalVariable(Http.ALLOWED_DOMAINS_VARIABLE_NAME, "gadgetopia.com");
            var pipeline = new Pipeline();

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

            Assert.IsTrue(result.ToLower().Contains("gadgetopia"));
        }