示例#1
0
        public void GreaterThan()
        {
            List <Game> list  = Test("greaterThan.json");
            int         total = FakeGameService.GetDatas().Count();

            Assert.True(list.Count > 0 && list.Count < total);
        }
示例#2
0
        public void ListIn()
        {
            string rules = GetJsonTestFile("listIn.json");

            var  items  = FakeGameService.GetDatas();
            bool result = JsonRuleEngine.Evaluate(items.First(), rules);

            Assert.True(result);
        }
示例#3
0
        public void Guid()
        {
            string rules = GetJsonTestFile("guid.json");

            var  items  = FakeGameService.GetDatas();
            bool result = JsonRuleEngine.Evaluate(items.First(), rules);

            Assert.False(result);
        }
示例#4
0
        private static List <Game> Test(string jsonRuleFilePath)
        {
            string rules = GetJsonTestFile(jsonRuleFilePath);

            var expression = JsonRuleEngine.ParseExpression <Game>(rules);

            var datas = FakeGameService.GetDatas();
            var list  = datas.Where(expression).ToList();

            return(list);
        }
示例#5
0
        public void IsNotNull()
        {
            string rules  = GetJsonTestFile("isNotNull.json");
            var    items  = FakeGameService.GetDatas();
            bool   result = JsonRuleEngine.Evaluate(new Game()
            {
                Category = "Titi", Date = DateTime.UtcNow
            }, rules);

            Assert.True(result);
        }
示例#6
0
        public void EvaluateWithClass()
        {
            string rules = GetJsonTestFile("complex.json");

            var  items  = FakeGameService.GetDatas();
            bool result = JsonRuleEngine.Evaluate(items.First(), new ConditionRuleSet()
            {
                Field = "Name", Operator = ConditionRuleOperator.isNotNull
            });

            Assert.True(result);
        }
示例#7
0
        public void ValidateExpression()
        {
            var data      = File.ReadAllText(Path.Combine("TestJsons/", "complex.json"));
            var items     = FakeGameService.GetDatas();
            var whiteList = new List <string>()
            {
                "Category",
                "Price",
                "Name",
                "Editor.Name",
                "Reviews.Id"
            };
            var result = JsonRuleEngine.ValidateExpressionFields(data, whiteList);

            Assert.True(result.Success);
        }