Esempio n. 1
0
 public void OpTestIn01()
 {
     Assert.IsTrue(JsonLogic.Apply("{'in':[ 'Ringo', ['John', 'Paul', 'George', 'Ringo'] ]}"));
     Assert.IsFalse(JsonLogic.Apply("{'in':[ 'Ringo', ['John', 'Paul', 'George'] ]}"));
     Assert.IsTrue(JsonLogic.Apply("{'in':[ 1, [2, 3, 4, 1] ]}"));
     Assert.IsFalse(JsonLogic.Apply("{'in':[ 1, [2, 3, 4] ]}"));
 }
Esempio n. 2
0
 public void OpTestLessThan01()
 {
     Assert.IsTrue(JsonLogic.Apply("{'<' :[2, 3]}"));
     Assert.IsFalse(JsonLogic.Apply("{'<' :[3, 2]}"));
     Assert.IsTrue(JsonLogic.Apply("{'<' :[1, 2, 3, 4, 5]}"));
     Assert.IsFalse(JsonLogic.Apply("{'<' :[2, 3, 4, 1]}"));
 }
Esempio n. 3
0
 public void OpTestGreaterThan01()
 {
     Assert.IsFalse(JsonLogic.Apply("{'>' :[2, 3]}"));
     Assert.IsTrue(JsonLogic.Apply("{'>' :[3, 2]}"));
     Assert.IsFalse(JsonLogic.Apply("{'>' :[1, 2, 3, 4, 5]}"));
     Assert.IsTrue(JsonLogic.Apply("{'>' :[5, 4, 3, 2, 1]}"));
 }
Esempio n. 4
0
        public void OpTestVar03()
        {
            string rule = @"{'+': [1, {'var':'age'}, 2]}";
            string data = @"{'age' : 10, 'salary' : 150000}";

            Assert.AreEqual(13, JsonLogic.Apply(rule, data));
        }
Esempio n. 5
0
 public void OpTestNot01()
 {
     Assert.IsTrue(JsonLogic.Apply("{\"!\" :false}"));
     Assert.IsFalse(JsonLogic.Apply("{\"!\" :true}"));
     Assert.IsFalse(JsonLogic.Apply("{\"!!\" :false}"));
     Assert.IsTrue(JsonLogic.Apply("{\"!!\" :true}"));
 }
Esempio n. 6
0
 public void OpTestNot02()
 {
     Assert.IsTrue(JsonLogic.Apply("{\"!\" :[false]}"));
     Assert.IsFalse(JsonLogic.Apply("{\"!\" :[true]}"));
     Assert.IsFalse(JsonLogic.Apply("{\"!!\" :[false]}"));
     Assert.IsTrue(JsonLogic.Apply("{\"!!\" :[true]}"));
 }
Esempio n. 7
0
        public void OpTestMissing02()
        {
            string rule = @"{'missing': ['a', 'b', 'c']}";
            string data = @"{'a':'ape', 'b':'boy', 'c':'cat'}";

            CollectionAssert.AreEqual(new string[] { }, JsonLogic.Apply(rule, data));
        }
Esempio n. 8
0
 public void OpTestBoolean01()
 {
     Assert.IsFalse(JsonLogic.Apply("{'and': [true, true, true, false]}"));
     Assert.IsTrue(JsonLogic.Apply("{'and': [true, true, true, true]}"));
     Assert.IsTrue(JsonLogic.Apply("{'or': [false, false, false, true]}"));
     Assert.IsFalse(JsonLogic.Apply("{'or': [false, false, false, false]}"));
 }
Esempio n. 9
0
        public void OpTestVar05()
        {
            string rule = @"{'<': [{'var':'age'}, 30]}";
            string data = @"{'age' : 25, 'salary' : 150000}";

            Assert.IsTrue(JsonLogic.Apply(rule, data));
        }
Esempio n. 10
0
        public void OpTestVar06()
        {
            string rule = @"{'var': 1}";
            string data = @"{'x': ['zero', 'one', 'two', 'three']}";

            Assert.AreEqual("one", JsonLogic.Apply(rule, data));
        }
Esempio n. 11
0
        public void OpTestAll01()
        {
            string rule = @"{ 'all' : [ {'var':'pies'}, {'==':[{'var':'filling'}, 'apple']} ]}";
            string data = @"
                        {'pies':[
                                 { 'filling':'apple','temp':110},
                                 { 'filling':'apple','temp':210},
                                 { 'filling':'apple','temp':310}
                        ]}";

            Assert.IsTrue(JsonLogic.Apply(rule, data));


            rule = @"{ 'all' : [ {'var':'pies'}, {'==':[{'var':'filling'}, 'peach']} ]}";

            Assert.IsFalse(JsonLogic.Apply(rule, data));

            rule = @"{ 'all' : [ {'var':'pies'}, {'==':[{'var':'temp'}, 210]} ]}";

            Assert.IsFalse(JsonLogic.Apply(rule, data));

            data = @"
                        {'pies':[
                                 { 'filling':'peach','temp':300},
                                 { 'filling':'pear','temp':300},
                                 { 'filling':'apple','temp':300}
                        ]}";

            rule = @"{ 'all' : [ {'var':'pies'}, {'==':[{'var':'temp'}, 300]} ]}";

            Assert.IsTrue(JsonLogic.Apply(rule, data));
        }
Esempio n. 12
0
        public void OpTestVar01()
        {
            string rule = @"{'var': 'a'}";
            string data = @"{'a' : 1}";

            Assert.AreEqual(1, JsonLogic.Apply(rule, data));
        }
Esempio n. 13
0
 public void OpTestAdd01()
 {
     Assert.AreEqual(5, JsonLogic.Apply("{\"+\" :[2, 3]}"));
     Assert.AreEqual(4.0, JsonLogic.Apply("{\"+\" :[2.0, 2.0]}"));
     Assert.AreEqual(8, JsonLogic.Apply("{\"+\" :[2, 2, 2, 2]}"));
     Assert.AreEqual(10, JsonLogic.Apply("{\"+\" :[10]}"));
     Assert.AreEqual(10, JsonLogic.Apply("{\"+\" :10}"));
 }
Esempio n. 14
0
        public void OpTestVar02()
        {
            string rule = @"{'var': 'person1.age'}";
            string data = @"{'person1' : {'name': 'Mary', 'age': 10, },
                             'person2' : {'name': 'Joe', 'age': 15, }}";

            Assert.AreEqual(10, JsonLogic.Apply(rule, data));
        }
Esempio n. 15
0
 public void OpTestMult01()
 {
     Assert.AreEqual(6, JsonLogic.Apply("{'*' :[2, 3]}"));
     Assert.AreEqual(9.0, JsonLogic.Apply("{\"*\" :[3.0, 3.0]}"));
     Assert.AreEqual(16, JsonLogic.Apply("{\"*\" :[2, 2, 2, 2]}"));
     Assert.AreEqual(10, JsonLogic.Apply("{\"*\" :[10]}"));
     Assert.AreEqual(10, JsonLogic.Apply("{\"*\" :10}"));
 }
Esempio n. 16
0
 public void OpTestComplexAdd01()
 {
     Assert.AreEqual(27, JsonLogic.Apply(
                         @"{'+': 
                         [   { '*' : [3,2]},
                             { '+' : [2,2,2,2,2]},
                             { '+' : [2,2,2,2,2]},
                             { '/' : [10,10]}
                         ]
                       }"));
 }
Esempio n. 17
0
        public void OpTestSomeMissing01()
        {
            string rule = @"{'missing_some': ['a', 'b', 'c']}";
            string data = @"{'a':'ape', 'b':'boy', 'c':'cat'}";

            Assert.AreEqual(false, JsonLogic.Apply(rule, data));

            rule = @"{'missing_some': ['a', 'b', 'c']}";
            data = @"{'a':'ape', 'b':'boy'}";

            Assert.IsTrue(JsonLogic.Apply(rule, data));
        }
Esempio n. 18
0
        public void OpTestShallowEqual()
        {
            Assert.IsTrue(JsonLogic.Apply("{\"==\" :[2, 2.0]}"));
            Assert.IsTrue(JsonLogic.Apply("{\"==\" :[2.0, 2.0]}"));
            Assert.IsFalse(JsonLogic.Apply("{\"==\" :[2.0, 3.0]}"));
            Assert.IsTrue(JsonLogic.Apply("{\"==\" :[\"dog\", \"dog\"]}"));

            Assert.IsTrue(JsonLogic.Apply("{'==' :[2, 2.0]}"));
            Assert.IsTrue(JsonLogic.Apply("{'==' :[2.0, 2.0]}"));
            Assert.IsFalse(JsonLogic.Apply("{'==' :[2.0, 3.0]}"));
            Assert.IsTrue(JsonLogic.Apply("{'==' :['dog', 'dog']}"));
        }
Esempio n. 19
0
        public void Test(int testIndex)
        {
            var sample = Samples[testIndex];
            // Create a lambda expression.
            var lambdaExpr = JsonLogic.Parse(sample.Logic, sample.Data?.GetType());
            // Compile the lambda expression.
            var compiledExpression = lambdaExpr.Compile();
            // Execute the lambda expression.
            var result = compiledExpression.DynamicInvoke(sample.Data);

            Assert.Equal(Convert.ChangeType(sample.TheoricalResult, result.GetType()), result);
        }
Esempio n. 20
0
        public void Test_That_Request_Has_Properly_Formatted_Date()
        {
            var properties = new
            {
                DateTimeToTest = new DateTime(2017, 4, 30)
            };

            var result = new JsonLogic(_clientMock.Object, _config).PrepareRequest("", "", properties);

            result.Parameters[0].Value.ToString()
            .Contains("\"DateTimeToTest\": \"2017-04-30 00:00:00\"")
            .Should()
            .Be(true);
        }
Esempio n. 21
0
        public void OpTestBoolean02()
        {
            Assert.IsTrue(JsonLogic.Apply(
                              @"{'and': 
                                [   { '==' : [3,3]},
                                    { '==' : [2,2]},
                                    { '!=' : [4,2]}                                   
                                ]
                              }"));

            Assert.IsFalse(JsonLogic.Apply(
                               @"{'and': 
                                [   { '==' : [3,3]},
                                    { '==' : [2,2]},
                                    { '==' : [4,2]}                                   
                                ]
                              }"));
        }
Esempio n. 22
0
        public void OpTestNone01()
        {
            string rule = @"{ 'none' : [ {'var':'pies'}, {'==':[{'var':'filling'}, 'apple']} ]}";
            string data = @"
                        {'pies':[
                                 { 'filling':'pumpkin','temp':110},
                                 { 'filling':'rhubarb','temp':210},
                                 { 'filling':'apple','temp':310}
                        ]}";

            Assert.IsFalse(JsonLogic.Apply(rule, data));

            rule = @"{ 'none' : [ {'var':'pies'}, {'==':[{'var':'filling'}, 'peach']} ]}";

            Assert.IsTrue(JsonLogic.Apply(rule, data));

            rule = @"{ 'none' : [ {'var':'pies'}, {'==':[{'var':'temp'}, 210]} ]}";

            Assert.IsFalse(JsonLogic.Apply(rule, data));
        }
Esempio n. 23
0
        public void OpTestMerge01()
        {
            string rule = @"{'merge' :[ [1,2], [3,4] ]}";

            CollectionAssert.AreEqual(new int[] { 1, 2, 3, 4 }, JsonLogic.Apply(rule, null));
        }
Esempio n. 24
0
 public void OpTestDeepEqual()
 {
     Assert.IsFalse(JsonLogic.Apply("{\"===\" :[2, 2.0]}"));
     Assert.IsTrue(JsonLogic.Apply("{\"===\" :[2.0, 2.0]}"));
     Assert.IsTrue(JsonLogic.Apply("{\"===\" :[\"dog\", \"dog\"]}"));
 }
Esempio n. 25
0
 public void OpTestIf01()
 {
     Assert.AreEqual("yes", JsonLogic.Apply("{'if' : [true, 'yes', 'no']}"));
     Assert.AreEqual("no", JsonLogic.Apply("{'if' : [false, 'yes', 'no']}"));
 }
Esempio n. 26
0
 public void OpTestIn02()
 {
     Assert.IsTrue(JsonLogic.Apply("{'in':[ 'Spring', 'Springfield']}"));
     Assert.IsFalse(JsonLogic.Apply("{'in':[ 'Springx', 'Springfield']}"));
 }
Esempio n. 27
0
 public void OpTestDiv01()
 {
     Assert.AreEqual(6, JsonLogic.Apply("{'/' :[12, 2]}"));
     Assert.AreEqual(2.5, JsonLogic.Apply("{'/' :[5.0, 2.0]}"));
     Assert.AreEqual(2, JsonLogic.Apply("{'/' :[5, 2]}"));
 }
Esempio n. 28
0
        public void OpTestCat01()
        {
            string rule = @"{'cat' : ['The ', 'cat ', 'in ', 'the ', 'hat.']}";

            Assert.AreEqual("The cat in the hat.", JsonLogic.Apply(rule, null));
        }
Esempio n. 29
0
        public void Test_That_Request_Is_Json_Format()
        {
            var result = new JsonLogic(_clientMock.Object, _config).PrepareRequest("", "", "");

            result.RequestFormat.Should().Be(DataFormat.Json);
        }
Esempio n. 30
0
        public void OpTestMerge02()
        {
            string rule = @"{'merge' :[ ['a', 'b'], ['c','d'] ]}";

            CollectionAssert.AreEqual(new string[] { "a", "b", "c", "d" }, JsonLogic.Apply(rule, null));
        }