public void ShouldHandleSubQueries()
        {
            query = new NLinqQuery(@"
                from m in methods
                where !m.IsStatic
                orderby m.Name
                group m by m.Name into g
                select new { MethodName = g.Key, Overloads = g.Count() }");

            linq = new LinqToMemory(query);
            linq.AddSource("methods", typeof(string).GetMethods());

            IList result = linq.List();

            Assert.AreEqual(35, result.Count);

            query = new NLinqQuery(@"
                from m in methods
                where !m.IsStatic
                orderby m.Name
                group m by m.Name into g
                select new { MethodName = g.Key, Overloads = g.Count(), MethodNamesLength = g.Sum(
                    meth => meth.Name.Length ) }");

            linq = new LinqToMemory(query);
            linq.AddSource("methods", typeof(string).GetMethods());


            result = linq.List();

            Assert.AreEqual(35, result.Count);
        }
        public void ShouldHandleSubQueries2()
        {
            query = new NLinqQuery(@"
                from m in methods
                where !m.IsStatic
                orderby m.Name
                group m by m.Name into g
                select new { MethodName = g.Key, Overloads = g.Count(), MethodParameters = g.Sum(
                    meth => (from p in meth.GetParameters() select p).Count() 
                    ) 
                }"
                                   );

            linq = new LinqToMemory(query);
            linq.AddSource("methods", typeof(string).GetMethods());

            IList result = linq.List();

            Assert.AreEqual(35, result.Count);

            foreach (Variant v in result)
            {
                Console.WriteLine(v["MethodName"] + " " + v["Overloads"] + " " + v["MethodParameters"]);
            }
        }
        public void ShouldHandleKeywordsInStringLiterals()
        {
            string[] words = { " che rry " };

            query = new NLinqQuery(@"
                from m in words
                select 'true'
            ");

            linq = new LinqToMemory(query);
            linq.AddSource("words", words);

            Assert.AreEqual("true", linq.List <string>()[0]);
        }
        public void SkipSimple()
        {
            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                from n in numbers.Skip(4)
                select n");

            List <object> n = new List <object>();

            linq = new LinqToMemory(query);
            linq.AddSource("numbers", numbers);

            IList where1 = linq.List();

            Assert.AreEqual(6, where1.Count);
        }
        public void WhereIndexedBis()
        {
            string[] digits = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };

            query = new NLinqQuery(@"
                from n in 
                    digits.Where((digit, index) => digit.Length < index)
                select n");

            List <object> n = new List <object>();

            linq = new LinqToMemory(query);
            linq.AddSource("digits", digits);

            IList where1 = linq.List();

            Assert.AreEqual(5, where1.Count);
        }
        public void Distinct1()
        {
            int[] factorsOf300 = { 2, 2, 3, 5, 5 };

            query = new NLinqQuery(@"
                from n in 
                    factorsOf300.Distinct()
                select n");

            List <object> n = new List <object>();

            linq = new LinqToMemory(query);
            linq.AddSource("factorsOf300", factorsOf300);

            IList where1 = linq.List();

            Assert.AreEqual(3, where1.Count);
        }
Ejemplo n.º 7
0
        public void WhereIndexedBis()
        {
            string[] digits = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };

            query = new NLinqQuery(@"
                from n in 
                    digits.Where((digit, index) => digit.Length < index)
                select n");

            List<object> n = new List<object>();

            linq = new LinqToMemory(query);
            linq.AddSource("digits", digits);

            IList where1 = linq.List();

            Assert.AreEqual(5, where1.Count);
        }
        public void Except()
        {
            int[] numbersA = { 0, 2, 4, 5, 6, 8, 9 };
            int[] numbersB = { 1, 3, 5, 7, 8 };

            query = new NLinqQuery(@"
                from n in 
                    numbersA.Except(numbersB)
                select n");

            linq = new LinqToMemory(query);
            linq.AddSource("numbersA", numbersA);
            linq.AddSource("numbersB", numbersB);

            IList where1 = linq.List();

            Assert.AreEqual(5, where1.Count);
        }
        public void SelectIndexed()
        {
            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                from n in numbers.Select((num, index) => new {Num = num, InPlace = (num == index)})
                select n");

            List <object> n = new List <object>();

            linq = new LinqToMemory(query);
            linq.AddSource("numbers", numbers);

            IList where1 = linq.List();

            Assert.AreEqual(10, where1.Count);
            Assert.AreEqual(false, ((Variant)where1[0])["InPlace"]);
            Assert.AreEqual(true, ((Variant)where1[3])["InPlace"]);
        }
Ejemplo n.º 10
0
        public void WhereSimple1()
        {
            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                from n in numbers
                where n < 5
                select n ");

            List<object> n = new List<object>();

            linq = new LinqToMemory(query);
            linq.AddSource("numbers", numbers);

            IList where1 = linq.List();

            Assert.AreEqual(5, where1.Count);

        }
        public void ShouldSortAList()
        {
            List <Person> people = new List <Person>(
                new Person[] { new Person("B"), new Person("A"), new Person("C") });

            query = new NLinqQuery(@"
                from p in people
                orderby p.Name
                select p
            ");

            linq = new LinqToMemory(query);
            linq.AddSource("people", people);

            List <Person> result = linq.List <Person>();

            Assert.AreEqual(3, result.Count);
            Assert.AreEqual("A", result[0].Name);
            Assert.AreEqual("B", result[1].Name);
            Assert.AreEqual("C", result[2].Name);
        }
        public void ShouldHandleNullValues()
        {
            List <Person> people = new List <Person>(
                new Person[] { new Person("B"), new Person("A"), null });

            query = new NLinqQuery(@"
                from p in people
                where p != null
                select p
            ");

            linq = new LinqToMemory(query);
            linq.AddSource("people", people);

            List <Person> result = linq.List <Person>();

            Assert.AreEqual(2, result.Count);

            Assert.AreEqual("B", result[0].Name);
            Assert.AreEqual("A", result[1].Name);
        }
        public void ShouldProvidePaging()
        {
            List <Person> people = new List <Person>(
                new Person[] { new Person("B"), new Person("A"), new Person("C") });

            query = new NLinqQuery(@"
                (from p in people
                orderby p.Name
                select p).Where((p, index) => index > 0)
            ");

            linq = new LinqToMemory(query);
            linq.AddSource("people", people);

            /// TODO: be able to add linq.AddSource("first", 0);

            List <Person> result = linq.List <Person>();

            Assert.AreEqual(2, result.Count);

            Assert.AreEqual("B", result[0].Name);
            Assert.AreEqual("C", result[1].Name);
        }
        public void ShouldHandleEscapeSequence()
        {
            string[] words = { " che rry " };

            query = new NLinqQuery(@"
                from m in words
                select ' \'che rr :     y\' '
            ");

            linq = new LinqToMemory(query);
            linq.AddSource("words", words);

            Assert.AreEqual(" 'che rr :     y' ", linq.List <string>()[0]);

            query = new NLinqQuery(@"
                from m in words
                select 's.ros\u0040evaluant.com'
            ");

            linq = new LinqToMemory(query);
            linq.AddSource("words", words);

            Assert.AreEqual("*****@*****.**", linq.List <string>()[0]);
        }
Ejemplo n.º 15
0
        public void ShouldHandleNullValues()
        {
            List<Person> people = new List<Person>(
                new Person[] { new Person("B"), new Person("A"), null });

            query = new NLinqQuery(@"
                from p in people
                where p != null
                select p
            ");

            linq = new LinqToMemory(query);
            linq.AddSource("people", people);

            List<Person> result = linq.List<Person>();

            Assert.AreEqual(2, result.Count);

            Assert.AreEqual("B", result[0].Name);
            Assert.AreEqual("A", result[1].Name);
        }
Ejemplo n.º 16
0
        public void ShouldProvidePaging()
        {
            List<Person> people = new List<Person>(
                new Person[] { new Person("B"), new Person("A"), new Person("C") });

            query = new NLinqQuery(@"
                (from p in people
                orderby p.Name
                select p).Where((p, index) => index > 0)
            ");

            linq = new LinqToMemory(query);
            linq.AddSource("people", people);

            /// TODO: be able to add linq.AddSource("first", 0);

            List<Person> result = linq.List<Person>();

            Assert.AreEqual(2, result.Count);

            Assert.AreEqual("B", result[0].Name);
            Assert.AreEqual("C", result[1].Name);
        }
Ejemplo n.º 17
0
        public void ShouldSortAList()
        {
            List<Person> people = new List<Person>(
                new Person[] { new Person("B"), new Person("A"), new Person("C") });

            query = new NLinqQuery(@"
                from p in people
                orderby p.Name
                select p
            ");

            linq = new LinqToMemory(query);
            linq.AddSource("people", people);

            List<Person> result = linq.List<Person>();

            Assert.AreEqual(3, result.Count);
            Assert.AreEqual("A", result[0].Name);
            Assert.AreEqual("B", result[1].Name);
            Assert.AreEqual("C", result[2].Name);
        }
Ejemplo n.º 18
0
        public void ShouldHandleKeywordsInStringLiterals()
        {
            string[] words = { " che rry " };

            query = new NLinqQuery(@"
                from m in words
                select 'true'
            ");

            linq = new LinqToMemory(query);
            linq.AddSource("words", words);

            Assert.AreEqual("true", linq.List<string>()[0]);
        }
Ejemplo n.º 19
0
        public void ShouldHandleEscapeSequence()
        {
            string[] words = { " che rry " };

            query = new NLinqQuery(@"
                from m in words
                select ' \'che rr :     y\' '
            ");

            linq = new LinqToMemory(query);
            linq.AddSource("words", words);

            Assert.AreEqual(" 'che rr :     y' ", linq.List<string>()[0]);

            query = new NLinqQuery(@"
                from m in words
                select 's.ros\u0040evaluant.com'
            ");

            linq = new LinqToMemory(query);
            linq.AddSource("words", words);

            Assert.AreEqual("*****@*****.**", linq.List<string>()[0]);
        }
Ejemplo n.º 20
0
        public void Except()
        {
            int[] numbersA = { 0, 2, 4, 5, 6, 8, 9 };
            int[] numbersB = { 1, 3, 5, 7, 8 };

            query = new NLinqQuery(@"
                from n in 
                    numbersA.Except(numbersB)
                select n");

            linq = new LinqToMemory(query);
            linq.AddSource("numbersA", numbersA);
            linq.AddSource("numbersB", numbersB);

            IList where1 = linq.List();

            Assert.AreEqual(5, where1.Count);
        }
Ejemplo n.º 21
0
        public void Distinct1()
        {
            int[] factorsOf300 = { 2, 2, 3, 5, 5 };

            query = new NLinqQuery(@"
                from n in 
                    factorsOf300.Distinct()
                select n");

            List<object> n = new List<object>();

            linq = new LinqToMemory(query);
            linq.AddSource("factorsOf300", factorsOf300);

            IList where1 = linq.List();

            Assert.AreEqual(3, where1.Count);

        }
Ejemplo n.º 22
0
        public void SelectIndexed()
        {
            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                from n in numbers.Select((num, index) => new {Num = num, InPlace = (num == index)})
                select n");

            List<object> n = new List<object>();

            linq = new LinqToMemory(query);
            linq.AddSource("numbers", numbers);

            IList where1 = linq.List();

            Assert.AreEqual(10, where1.Count);
            Assert.AreEqual(false, ((Variant)where1[0])["InPlace"]);
            Assert.AreEqual(true, ((Variant)where1[3])["InPlace"]);

        }
Ejemplo n.º 23
0
        public void ShouldHandleSubQueries()
        {
            query = new NLinqQuery(@"
                from m in methods
                where !m.IsStatic
                orderby m.Name
                group m by m.Name into g
                select new { MethodName = g.Key, Overloads = g.Count() }");

            linq = new LinqToMemory(query);
            linq.AddSource("methods", typeof(string).GetMethods());

            IList result = linq.List();

            Assert.AreEqual(35, result.Count);

            query = new NLinqQuery(@"
                from m in methods
                where !m.IsStatic
                orderby m.Name
                group m by m.Name into g
                select new { MethodName = g.Key, Overloads = g.Count(), MethodNamesLength = g.Sum(
                    meth => meth.Name.Length ) }");

            linq = new LinqToMemory(query);
            linq.AddSource("methods", typeof(string).GetMethods());


            result = linq.List();

            Assert.AreEqual(35, result.Count);
        }
Ejemplo n.º 24
0
        public void ShouldHandleSubQueries2()
        {
            query = new NLinqQuery(@"
                from m in methods
                where !m.IsStatic
                orderby m.Name
                group m by m.Name into g
                select new { MethodName = g.Key, Overloads = g.Count(), MethodParameters = g.Sum(
                    meth => (from p in meth.GetParameters() select p).Count() 
                    ) 
                }"
            );

            linq = new LinqToMemory(query);
            linq.AddSource("methods", typeof(string).GetMethods());

            IList result = linq.List();

            Assert.AreEqual(35, result.Count);

            foreach (Variant v in result)
            {
                Console.WriteLine(v["MethodName"] + " " + v["Overloads"] + " " + v["MethodParameters"]);
            }
        }
Ejemplo n.º 25
0
        public void SkipWhileSimple()
        {
            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                from n in numbers.SkipWhile(n => n % 3 != 0)
                select n");

            List<object> n = new List<object>();

            linq = new LinqToMemory(query);
            linq.AddSource("numbers", numbers);

            IList where1 = linq.List();

            Assert.AreEqual(7, where1.Count);

        }