Esempio n. 1
0
        public void Example15()
        {
            string             query              = @"select{name family posts{title articles{author}date news{newsName}}files{id name}}
                                    var user
                                    {
                                        where sum(sum(count(user.posts),count(user.posts)),count(user.posts))==6)
                                        var post in user.posts
	                                    {
		                                    where post.Title = ""hello every body""
	                                    }
                                        var file in user.files
	                                    {
		                                    where file.Name = ""page.jpg""
	                                    }
                                    }";
            SelectCompiler     selectCompiler     = new SelectCompiler();
            string             anotherResult      = selectCompiler.Compile(query);
            ConditionsCompiler conditionsCompiler = new ConditionsCompiler();

            conditionsCompiler.Compile(anotherResult);
            IEnumerable <UserEx> toComiple  = QueryDataExchangerText.GetUsersEx();
            IEnumerable <UserEx> toComiple2 = QueryDataExchangerText.GetUsersEx();

            object result = selectCompiler.Run(toComiple);
            IEnumerable <UserEx> resultWheres = (IEnumerable <UserEx>)conditionsCompiler.Run <UserEx>(toComiple);
            List <UserEx>        resultData   = resultWheres.ToList();
            List <UserEx>        linqList     = toComiple2.Where(x => ((x.Posts.Count() + x.Posts.Count()) + x.Posts.Count()) == 6).ToList();

            foreach (UserEx item in linqList)
            {
                if (item.Files != null)
                {
                    item.Files = item.Files.Where(x => x.Name == "page.jpg").ToList();
                    foreach (var file in item.Files)
                    {
                        file.DateTime = DateTime.MinValue;
                    }
                }
                if (item.Posts != null)
                {
                    foreach (var post in item.Posts)
                    {
                        post.Content = null;
                        foreach (var news in post.News)
                        {
                            news.Description = null;
                        }
                        foreach (var art in post.Articles)
                        {
                            art.Date = DateTime.MinValue;
                        }
                    }
                    item.Posts = item.Posts.Where(x => x.Title == "hello every body").ToList();
                }
            }
            bool equal = resultData.SequenceEqual(linqList);

            Assert.IsTrue(equal);
        }
Esempio n. 2
0
        public List <UserInfo> GetAllUsers(string query)
        {
            var queryFromDataBaseExample = Program.InitializeUsers();

            SelectCompiler     selectCompiler     = new SelectCompiler();
            string             anotherResult      = selectCompiler.Compile(query);
            ConditionsCompiler conditionsCompiler = new ConditionsCompiler();

            conditionsCompiler.Compile(anotherResult);

            object result = selectCompiler.Run(queryFromDataBaseExample);
            IEnumerable <UserInfo> resultWheres = (IEnumerable <UserInfo>)conditionsCompiler.Run <UserInfo>(queryFromDataBaseExample);
            List <UserInfo>        resultData   = resultWheres.ToList();

            return(resultData);
        }
Esempio n. 3
0
        public void Example14()
        {
            string             query              = @"select{name family posts{title articles{author}date news{newsName}}files{id name}}var user{where sum(sum(count(user.posts),count(user.posts)),count(user.posts))==6)}";
            SelectCompiler     selectCompiler     = new SelectCompiler();
            string             anotherResult      = selectCompiler.Compile(query);
            ConditionsCompiler conditionsCompiler = new ConditionsCompiler();

            conditionsCompiler.Compile(anotherResult);
            IEnumerable <UserEx> toComiple = QueryDataExchangerText.GetUsersEx();

            object result = selectCompiler.Run(toComiple);
            IEnumerable <UserEx> resultWheres = (IEnumerable <UserEx>)conditionsCompiler.Run <UserEx>(toComiple);
            List <UserEx>        resultData   = resultWheres.ToList();
            List <UserEx>        linqList     = toComiple.Where(x => ((x.Posts.Count() + x.Posts.Count()) + x.Posts.Count()) == 6).ToList();
            bool equal = resultData.SequenceEqual(linqList);

            Assert.IsTrue(equal);
        }
Esempio n. 4
0
        public void Example12()
        {
            string             query              = @"select{name family posts{title articles{author}date news{newsName}}files{id name}}var user{where user.family=""yousefi"" and sum(5,1,4)==10)}";
            SelectCompiler     selectCompiler     = new SelectCompiler();
            string             anotherResult      = selectCompiler.Compile(query);
            ConditionsCompiler conditionsCompiler = new ConditionsCompiler();

            conditionsCompiler.Compile(anotherResult);
            IEnumerable <UserEx> toComiple = QueryDataExchangerText.GetUsersEx();

            object result = selectCompiler.Run(toComiple);
            IEnumerable <UserEx> resultWheres = (IEnumerable <UserEx>)conditionsCompiler.Run <UserEx>(toComiple);
            List <UserEx>        resultData   = resultWheres.ToList();
            List <UserEx>        linqList     = toComiple.Where(x => x.Family == "yousefi" && 5 + 1 + 4 == 10).ToList();
            bool equal = resultData.SequenceEqual(linqList);

            Assert.IsTrue(equal);
        }
Esempio n. 5
0
        public void TestMethod1()
        {
            return;

            while (true)
            {
                try
                {
                    string             query              = @"select
{
	name 
	family 
	posts
	{
		title 
		content
		articles
		{
			author 
			date
		}
		date
        files
        {
            id 
            name 
            datetime
        }
	}
} 
var user
{
	where user.id > 10 and user.name = ""reza"" and count(user.posts) > 0 skip 10 take 20
	post in user.posts
	{
		where post.id > 20 and contains(post.title,""hello"")
        or count(var x from post.articles where x.author = ""ali"") > 5 order by post.id desc
	}
}
";
                    string             query2             = @"select{name family posts{title content articles{author date}date news{newsName description}} files{id name datetime}}var user
{
	where user.id > 10 and user.name = ""reza"" and count(user.posts) > 0 skip 10 take 20
	post in user.posts
	{
		where post.id > 20 and contains(post.title,""hello"")
        or count(var x from post.articles where x.author = ""ali"") > 5 order by post.id desc
	}
}
";
                    string             query3             = @"select{name family posts{title articles{author}date news{newsName}}files{id name}}var user{where user.name=""ali"" and(user.family=""yousefi""and user.name=""reza"")or user.posts.count>
1
}";
                    string             query4             = @"select{name family posts{title articles{author}date news{newsName}}files{id name}}var user{where user.name=""ali""and (user.posts.count<=5 or (user.posts.count>=1))}";
                    SelectCompiler     selectCompiler     = new SelectCompiler();
                    string             anotherResult      = selectCompiler.Compile(query3);
                    ConditionsCompiler conditionsCompiler = new ConditionsCompiler();
                    conditionsCompiler.Compile(anotherResult);
                    IEnumerable <UserEx> main      = GetUsersEx();
                    IEnumerable <UserEx> toComiple = GetUsersEx();

                    object result = selectCompiler.Run(toComiple);
                    IEnumerable <UserEx> resultWheres = (IEnumerable <UserEx>)conditionsCompiler.Run <UserEx>(toComiple);
                    List <UserEx>        realData     = resultWheres.ToList();
                }
                catch (System.Exception ex)
                {
                }
            }
        }