public void ConcatStrings() {
            var input = new RowsBuilder().Row().Field("f1", "v1").Field("f2", "v2").ToOperation();
            var parameters = new ParametersBuilder().Parameters("f1", "f2").ToParameters();
            var concat = new ConcatOperation("o1", parameters);

            var rows = TestOperation(input, concat);

            Assert.AreEqual("v1v2", rows[0]["o1"]);
        }
        public void If() {

            var input = new RowsBuilder()
                .Row("x", 5).Field("y", 7).Field("z", 10).Field("out", 0)
                .Row("x", 5).Field("y", 5).Field("z", 11).Field("out", 0).ToOperation();

            var parameters = new ParametersBuilder()
                .Parameter("x").Type("int32")
                .Parameter("y").Type("int32")
                .Parameter("z").Type("int32")
                .Parameter("v", "1").Name("v").Type("int32")
                .ToParameters();

            var ifTransform = new IfOperation(parameters["x"], ComparisonOperator.Equal, parameters["y"], parameters["z"], parameters["v"], "out", "int32");

            var output = TestOperation(input, ifTransform);

            Assert.AreEqual(1, output[0]["out"]);
            Assert.AreEqual(11, output[1]["out"]);
        }
 public void TemplateNVelocity() {
     Velocity.Init();
     var input = new RowsBuilder()
         .Row("input", 2).Field("out", "")
         .Row("input", 4).Field("out", "")
         .ToOperation();
     var templates = new List<KeyValuePair<string, Template>>();
     var parameters = new ParametersBuilder().Parameter("x", 3).Parameter("input").ToParameters();
     var velocityOperation = new VelocityOperation("out", "string", "#set($result = $input * $x)\r\n$result", templates, parameters);
     var output = TestOperation(input, velocityOperation);
     Assert.AreEqual("6", output[0]["out"]);
     Assert.AreEqual("12", output[1]["out"]);
 }
 public ParameterBuilder(ref ParametersBuilder parametersBuilder, ref IParameter parameter) {
     _parametersBuilder = parametersBuilder;
     _parameter = parameter;
 }
        public void ConcatNumbers() {
            var input = new RowsBuilder().Row().Field("f1", 1).Field("f2", 2).ToOperation();
            var parameters = new ParametersBuilder().Parameter("f1").Type("int32").Parameter("f2").Type("int32").ToParameters();
            var concat = new ConcatOperation("o1", parameters);

            var rows = TestOperation(input, concat);

            Assert.AreEqual("12", rows[0]["o1"]);
        }
        public void Javascript() {
            const int expected = 12;

            var input = new RowsBuilder().Row("x", 3).Field("y", 4).ToOperation();
            var scripts = new Dictionary<string, Script>() { { "script", new Script("script", "function multiply(x,y) { return x*y; }", "") } };
            var parameters = new ParametersBuilder().Parameters("x", "y").ToParameters();
            var javascript = new JavascriptOperation("o1", "multiply(x,y)", scripts, parameters, new TestLogger());
            var output = TestOperation(input, javascript);

            Assert.AreEqual(expected, output[0]["o1"]);
        }
        public void Distance() {

            var input = new RowsBuilder().Row().Field("toLat", 28.419385d).Field("toLong", -81.581234d).ToOperation();

            var fromLat = new ParametersBuilder().Parameter("fromLat", 42.101025d).Type("double").ToParameters()[0];
            var fromLong = new ParametersBuilder().Parameter("fromLong", -86.48423d).Type("double").ToParameters()[0];
            var toLat = new ParametersBuilder().Parameter("toLat").ToParameters()[0];
            var toLong = new ParametersBuilder().Parameter("toLong").ToParameters()[0];

            var distance = new DistanceOperation("o1", "miles", fromLat, fromLong, toLat, toLong);

            var rows = TestOperation(input, distance);

            Assert.AreEqual(985.32863773508757d, rows[0]["o1"]);
        }
        public void AnyParameterDifferentTypes() {
            var input = new RowsBuilder()
                .Row("x", "1").Field("y", "3").Field("test", "1").Field("any", null)
                .Row("x", "2").Field("y", "4").Field("test", 5.0).Field("any", null)
                .ToOperation();

            var parameters = new ParametersBuilder()
                .Parameter("x")
                .Parameter("y")
                .ToParameters();

            var pIn = new ParametersBuilder()
                .Parameter("test")
                .ToParameters();

            var any = new AnyOperation(pIn["test"], "any", ComparisonOperator.Equal, parameters, false);

            var output = TestOperation(input, any);

            Assert.AreEqual(true, output[0]["any"]);
            Assert.AreEqual(false, output[1]["any"]);
        }
 public void TemplateInt() {
     var input = new RowsBuilder().Row("input", 2).Field("out", "").ToOperation();
     var templates = new List<KeyValuePair<string, Template>>();
     var parameters = new ParametersBuilder().Parameter("x", 3).Parameter("input").ToParameters();
     var templateOperation = new RazorOperation("out", "int", "@{var result = Model.input * Model.x;}@result", "dynamic", templates, parameters, new TestLogger());
     var output = TestOperation(input, templateOperation);
     Assert.AreEqual(6, output[0]["out"]);
 }
 public void ToJson() {
     var input = new RowsBuilder().Row("f1", 1).Field("f2", "2").Field("out", "").ToOperation();
     var parameters = new ParametersBuilder().Parameters("f1", "f2").ToParameters();
     var toJsonOperation = new ToJsonOperation("out", parameters);
     var output = TestOperation(input, toJsonOperation);
     Assert.AreEqual("{\"f1\":1,\"f2\":\"2\"}", output[0]["out"]);
 }
        public void TagWithNamedParameters() {
            var input = new RowsBuilder()
                .Row("input", 2).Field("another", "thing").Field("out", "")
                .Row("input", 4).Field("another", "element").Field("out", "")
                .ToOperation();
            var parameters = new ParametersBuilder()
                .Parameter("x", 3)
                .Parameter("content", "it wants & needs it")
                .Parameter("input")
                .Parameter("another")
                .Parameter("y", "input", true)
                .ToParameters();
            var tagOperation = new TagOperation("out", "a", parameters, false, true);
            var output = TestOperation(input, tagOperation);

            Assert.AreEqual("<a x=\"3\" input=\"2\" another=\"thing\" y=\"2\">it wants &amp; needs it</a>", output[0]["out"]);
            Assert.AreEqual("<a x=\"3\" input=\"4\" another=\"element\" y=\"4\">it wants &amp; needs it</a>", output[1]["out"]);
        }
        public void Tag() {
            var input = new RowsBuilder()
                .Row("input", 2).Field("another", "thing").Field("out", "")
                .Row("input", 4).Field("another", "element").Field("out", "")
                .ToOperation();
            var parameters = new ParametersBuilder()
                .Parameter("x", 3)
                .Parameter("input")
                .Parameter("another")
                .ToParameters();
            var tagOperation = new TagOperation("out", "a", parameters, false, false);
            var output = TestOperation(input, tagOperation);

            Assert.AreEqual("<a x=\"3\" input=\"2\" another=\"thing\" />", output[0]["out"]);
            Assert.AreEqual("<a x=\"3\" input=\"4\" another=\"element\" />", output[1]["out"]);
        }
        public void TemplateNVelocityIf() {
            Velocity.Init();
            var input = new RowsBuilder()
                .Row("input", true)
                .Row("output", "")
                .ToOperation();
            var templates = new List<KeyValuePair<string, Template>>();
            var parameters = new ParametersBuilder()
                .Parameter("input")
                .ToParameters();
            var velocityOperation = new VelocityOperation("output", "string", @"#if($input)
It is True#else
It is False#end", templates, parameters);
            var output = TestOperation(input, velocityOperation);
            Assert.AreEqual("It is True", output[0]["output"]);
        }
        public void IfEmpty() {
            var input = new RowsBuilder()
                .Row("x", "x").Field("y", "").Field("out", "")
                .Row("x", "").Field("y", "y").Field("out", "").ToOperation();

            var parameters = new ParametersBuilder()
                .Parameter("x")
                .Parameter("y")
                .Parameter("empty", string.Empty).Name("empty")
                .ToParameters();

            var ifTransform = new IfOperation(parameters["x"], ComparisonOperator.Equal, parameters["empty"], parameters["y"], parameters["x"], "out", "string");

            var output = TestOperation(input, ifTransform);

            Assert.AreEqual("x", output[0]["out"]);
            Assert.AreEqual("y", output[1]["out"]);
        }
 public void EqualsParameters() {
     var parameters = new ParametersBuilder()
         .Parameter("p1")
         .Parameter("p2")
         .ToParameters();
     var rows = new RowsOperation(new RowsBuilder()
         .Row("f1", null).Field("p1", "test").Field("p2", "test")
         .Row("f1", null).Field("p1", "test").Field("p2", "not-test")
         .ToRows());
     var equals = new EqualsOperation("f1", parameters);
     var results = TestOperation(rows, equals);
     Assert.AreEqual(true, results[0]["f1"]);
     Assert.AreEqual(false, results[1]["f1"]);
 }
        public void AnyValueDifferentTypes() {
            var input = new RowsBuilder()
                .Row("x", "1").Field("y", "3").Field("any_1", null).Field("any_2", null)
                .Row("x", "2").Field("y", "4").Field("any_1", null).Field("any_2", null)
                .ToOperation();

            var parameters = new ParametersBuilder()
                .Parameter("x")
                .Parameter("y")
                .ToParameters();

            var any1 = new AnyOperation(new Parameter("1", 1), "any_1", ComparisonOperator.Equal, parameters, false);
            var any2 = new AnyOperation(new Parameter("2", 2), "any_2", ComparisonOperator.Equal, parameters, false);

            var output = TestOperation(input, any1, any2);

            Assert.AreEqual(false, output[0]["any_1"]);
            Assert.AreEqual(false, output[0]["any_2"]);

            Assert.AreEqual(false, output[1]["any_1"]);
            Assert.AreEqual(false, output[1]["any_2"]);

        }
        public void Format() {
            var input = new RowsBuilder().Row().Field("f1", true).Field("f2", 8).ToOperation();
            var parameters = new ParametersBuilder().Parameters("f1", "f2").ToParameters();
            var expression = new FormatOperation("o1", "{0} and {1:c}.", parameters);

            var rows = TestOperation(input, expression);

            Assert.AreEqual("True and $8.00.", rows[0]["o1"]);
        }
        public void JsonWithJavascript() {
            var input = new RowsBuilder()
                .Row("x", "[{\"value\":false},{\"value\":true}]")
                .ToOperation();
            var parameters = new ParametersBuilder()
                .Parameter("x")
                .ToParameters();
            var js = new JavascriptOperation("out", @"
                JSON.parse(x)[1].value",
                new Dictionary<string, Script>(),
                parameters,
                new TestLogger()
            );
            var output = TestOperation(input, js);

            Assert.AreEqual(true, output[0]["out"]);
        }
        public void FromJson() {
            var input = new RowsBuilder().Row().Field("f1", "{ \"j1\":\"v1\", \"j2\":7, \"array\":[{\"x\":1}] }").ToOperation();
            var outParameters = new ParametersBuilder().Parameter("j1").Parameter("j2").Type("int32").Parameter("array").ToParameters();
            var expression = new FromJsonOperation("f1", outParameters);

            var rows = TestOperation(input, expression);

            Assert.AreEqual("v1", rows[0]["j1"]);
            Assert.AreEqual(7, rows[0]["j2"]);
        }
        public void JavascriptWithDates() {
            const string minuteDiff = @"
                function minuteDiff(orderStatus, start, end) {
                    if (orderStatus == 'Completed' || orderStatus == 'Problematic') {

                        var answer = 0;
                        if (start.getFullYear() != 9999 && end.getFullYear() != 9999) {
                            var ms = Math.abs(start - end);
                            answer = Math.round((ms / 1000) / 60);
                        }

                        return answer > 60 ? 60 : answer;

                    } else {
                        return 0;
                    }
                }";

            var input = new RowsBuilder()
                .Row("OrderStatus", "Completed")
                    .Field("StartDate", DateTime.Now.AddMinutes(-30.0))
                    .Field("EndDate", DateTime.Now)
                .Row("OrderStatus", "Problematic")
                    .Field("StartDate", DateTime.Now.AddMinutes(-29.0))
                    .Field("EndDate", DateTime.Now)
                .Row("OrderStatus", "Problematic")
                    .Field("StartDate", DateTime.Now.AddMinutes(-78.0))
                    .Field("EndDate", DateTime.Now)
                .Row("OrderStatus", "x")
                    .Field("StartDate", DateTime.Now.AddMinutes(-20.0))
                    .Field("EndDate", DateTime.Now)
                .ToOperation();

            var scripts = new Dictionary<string, Script>() { { "script", new Script("script", minuteDiff, "") } };
            var parameters = new ParametersBuilder().Parameters("OrderStatus", "StartDate", "EndDate").ToParameters();
            var javascript = new JavascriptOperation("o1", "minuteDiff(OrderStatus,StartDate,EndDate);", scripts, parameters, new TestLogger());
            var output = TestOperation(input, javascript);

            Assert.AreEqual(30, output[0]["o1"]);
            Assert.AreEqual(29, output[1]["o1"]);
            Assert.AreEqual(60, output[2]["o1"]);
            Assert.AreEqual(0, output[3]["o1"]);
        }
        public void FromSplit() {
            var input = new RowsBuilder()
                .Row("x", "x.y.z")
                .Row("x", "z.y.x")
                .ToOperation();
            var outParameters = new ParametersBuilder()
                .Parameter("e1")
                .Parameter("e2")
                .Parameter("e3")
                .ToParameters();
            var fromSplit = new FromSplitOperation("x", ".", outParameters);

            var rows = TestOperation(input, fromSplit);

            Assert.AreEqual("x", rows[0]["e1"]);
            Assert.AreEqual("y", rows[0]["e2"]);
            Assert.AreEqual("z", rows[0]["e3"]);

            Assert.AreEqual("z", rows[1]["e1"]);
            Assert.AreEqual("y", rows[1]["e2"]);
            Assert.AreEqual("x", rows[1]["e3"]);

        }
        public void CSharpScript() {
            var input = new RowsBuilder()
                .Row("first", "dale").Field("last", "newman").Field("full", "")
                .Row("first", "adam").Field("last", "newman").Field("full", "")
                .ToOperation();

            var parameters = new ParametersBuilder().Parameters("first", "last").ToParameters();
            var scripts = new Dictionary<string, Script>();

            const string code = @"
                return first + "" "" + last;
            ";

            var cSharp = new CSharpOperation("full", "string", code, scripts, parameters);
            var output = TestOperation(input, cSharp);
            Assert.AreEqual("dale newman", output[0]["full"].ToString());
            Assert.AreEqual("adam newman", output[1]["full"].ToString());

        }
        public void FromSplitWithTypes() {
            var input = new RowsBuilder()
                .Row("x", "1.y.1/1/2001")
                .Row("x", "2.y.1/1/2002")
                .ToOperation();
            var outParameters = new ParametersBuilder()
                .Parameter("e1").Type("int")
                .Parameter("e2").Type("string")
                .Parameter("e3").Type("datetime")
                .ToParameters();
            var fromSplit = new FromSplitOperation("x", ".", outParameters);

            var rows = TestOperation(input, fromSplit);

            Assert.AreEqual(1, rows[0]["e1"]);
            Assert.AreEqual("y", rows[0]["e2"]);
            Assert.AreEqual(new DateTime(2001, 1, 1), rows[0]["e3"]);

            Assert.AreEqual(2, rows[1]["e1"]);
            Assert.AreEqual("y", rows[1]["e2"]);
            Assert.AreEqual(new DateTime(2002, 1, 1), rows[1]["e3"]);
        }
 public void Join() {
     var input = new RowsBuilder().Row("x", "X").Field("y", "Y").ToOperation();
     var parameters = new ParametersBuilder().Parameters("x", "y").ToParameters();
     var join = new JoinTransformOperation("o1", "|", parameters);
     var output = TestOperation(input, join);
     Assert.AreEqual("X|Y", output[0]["o1"]);
 }
        public void FromRegex() {
            var input = new RowsBuilder().Row().Field("f1", "991.1 #Something INFO and a rambling message.").ToOperation();
            var outParameters = new ParametersBuilder().Parameter("p1").Type("decimal").Parameter("p2").Parameter("p3").ToParameters();
            var fromRegex = new FromRegexOperation("f1", @"(?<p1>^[\d\.]+).*(?<p2> [A-Z]{4,5} )(?<p3>.*$)", outParameters);

            var rows = TestOperation(input, fromRegex);

            Assert.AreEqual(991.1M, rows[0]["p1"]);
            Assert.AreEqual(" INFO ", rows[0]["p2"]);
            Assert.AreEqual("and a rambling message.", rows[0]["p3"]);
        }
Exemple #26
0
 public ParameterBuilder(ref ParametersBuilder parametersBuilder, ref IParameter parameter)
 {
     _parametersBuilder = parametersBuilder;
     _parameter         = parameter;
 }
        public void EqualsAValue() {

            var rows = new RowsBuilder()
                .Row("in", "789A")
                .Row("in", "x").ToOperation();

            var parameters = new ParametersBuilder()
                .Parameter("other", new Parameter("other", "789A") { SimpleType = "string" })
                .ToParameters();

            var validator = new EqualsOperation("in", parameters);

            var output = TestOperation(rows, validator);

            Assert.AreEqual(true, output[0]["in"]);
            Assert.AreEqual(false, output[1]["in"]);
        }