Change methods in Queryable.cs - call Provider.CreateQuery instead of Provider.Execute
authorLeonid Freydovich <leonidf@mono-cvs.ximian.com>
Tue, 22 Apr 2008 09:16:55 +0000 (09:16 -0000)
committerLeonid Freydovich <leonidf@mono-cvs.ximian.com>
Tue, 22 Apr 2008 09:16:55 +0000 (09:16 -0000)
in some of them. Add tests.

svn path=/trunk/mcs/; revision=101400

mcs/class/System.Core/System.Linq/Queryable.cs
mcs/class/System.Core/Test/System.Core.Tests-2008.JavaEE.csproj
mcs/class/System.Core/Test/System.Core.Tests-2008.csproj
mcs/class/System.Core/Test/System.Linq/ChangeLog
mcs/class/System.Core/Test/System.Linq/QueryableProviderTest.cs [new file with mode: 0644]

index 328a75b7c3ee6ce087d9cf1fefce4b38f04a001f..f52d21d1c9ab163ddba0e5d675241003ad55c6e0 100644 (file)
@@ -35,9 +35,11 @@ using System.Linq.Expressions;
 using System.Reflection;
 using System.Linq;
 
-namespace System.Linq {
+namespace System.Linq
+{
 
-       public static class Queryable {
+       public static class Queryable
+       {
 
                static MethodInfo MakeGeneric (MethodBase method, params Type [] parameters)
                {
@@ -383,7 +385,7 @@ namespace System.Linq {
                {
                        Check.Source1AndSource2 (source1, source2);
 
-                       return source1.Provider.Execute<IQueryable<TSource>> (
+                       return source1.Provider.CreateQuery<TSource> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
                                        source1.Expression,
@@ -443,21 +445,21 @@ namespace System.Linq {
 
                #region DefaultIfEmpty
 
-               public static TSource DefaultIfEmpty<TSource> (this IQueryable<TSource> source)
+               public static IQueryable<TSource> DefaultIfEmpty<TSource> (this IQueryable<TSource> source)
                {
                        Check.Source (source);
 
-                       return source.Provider.Execute<TSource> (
+                       return source.Provider.CreateQuery<TSource> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
                                        source.Expression));
                }
 
-               public static TSource DefaultIfEmpty<TSource> (this IQueryable<TSource> source, TSource defaultValue)
+               public static IQueryable<TSource> DefaultIfEmpty<TSource> (this IQueryable<TSource> source, TSource defaultValue)
                {
                        Check.Source (source);
 
-                       return source.Provider.Execute<TSource> (
+                       return source.Provider.CreateQuery<TSource> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
                                        source.Expression,
@@ -468,21 +470,21 @@ namespace System.Linq {
 
                #region Distinct
 
-               public static bool Distinct<TSource> (this IQueryable<TSource> source)
+               public static IQueryable<TSource> Distinct<TSource> (this IQueryable<TSource> source)
                {
                        Check.Source (source);
 
-                       return source.Provider.Execute<bool> (
+                       return source.Provider.CreateQuery<TSource> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
                                        source.Expression));
                }
 
-               public static bool Distinct<TSource> (this IQueryable<TSource> source, IEqualityComparer<TSource> comparer)
+               public static IQueryable<TSource> Distinct<TSource> (this IQueryable<TSource> source, IEqualityComparer<TSource> comparer)
                {
                        Check.Source (source);
 
-                       return source.Provider.Execute<bool> (
+                       return source.Provider.CreateQuery<TSource> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
                                        source.Expression,
@@ -527,7 +529,7 @@ namespace System.Linq {
                {
                        Check.Source1AndSource2 (source1, source2);
 
-                       return source1.Provider.Execute<IQueryable<TSource>> (
+                       return source1.Provider.CreateQuery<TSource> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
                                        source1.Expression,
@@ -538,7 +540,7 @@ namespace System.Linq {
                {
                        Check.Source1AndSource2 (source1, source2);
 
-                       return source1.Provider.Execute<IQueryable<TSource>> (
+                       return source1.Provider.CreateQuery<TSource> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
                                        source1.Expression,
@@ -604,7 +606,7 @@ namespace System.Linq {
                {
                        Check.SourceAndKeySelector (source, keySelector);
 
-                       return source.Provider.Execute<IQueryable<IGrouping<TKey, TSource>>> (
+                       return source.Provider.CreateQuery<IGrouping<TKey, TSource>> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey)),
                                        source.Expression,
@@ -614,7 +616,7 @@ namespace System.Linq {
                {
                        Check.SourceAndKeySelector (source, keySelector);
 
-                       return source.Provider.Execute<IQueryable<IGrouping<TKey, TSource>>> (
+                       return source.Provider.CreateQuery<IGrouping<TKey, TSource>> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey)),
                                        source.Expression,
@@ -625,7 +627,7 @@ namespace System.Linq {
                {
                        Check.SourceAndKeyElementSelectors (source, keySelector, elementSelector);
 
-                       return source.Provider.Execute<IQueryable<IGrouping<TKey, TSource>>> (
+                       return source.Provider.CreateQuery<IGrouping<TKey, TSource>> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey), typeof (TElement)),
                                        source.Expression,
@@ -636,7 +638,7 @@ namespace System.Linq {
                {
                        Check.SourceAndKeyResultSelectors (source, keySelector, resultSelector);
 
-                       return source.Provider.Execute<IQueryable<TResult>> (
+                       return source.Provider.CreateQuery<TResult> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey), typeof (TResult)),
                                        source.Expression,
@@ -647,7 +649,7 @@ namespace System.Linq {
                {
                        Check.SourceAndKeyElementSelectors (source, keySelector, elementSelector);
 
-                       return source.Provider.Execute<IQueryable<IGrouping<TKey, TElement>>> (
+                       return source.Provider.CreateQuery<IGrouping<TKey, TElement>> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey), typeof (TElement)),
                                        source.Expression,
@@ -659,7 +661,7 @@ namespace System.Linq {
                {
                        Check.GroupBySelectors (source, keySelector, elementSelector, resultSelector);
 
-                       return source.Provider.Execute<IQueryable<TResult>> (
+                       return source.Provider.CreateQuery<TResult> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey), typeof (TElement), typeof (TResult)),
                                        source.Expression,
@@ -672,7 +674,7 @@ namespace System.Linq {
                {
                        Check.SourceAndKeyResultSelectors (source, keySelector, resultSelector);
 
-                       return source.Provider.Execute<IQueryable<TResult>> (
+                       return source.Provider.CreateQuery<TResult> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey), typeof (TResult)),
                                        source.Expression,
@@ -684,7 +686,7 @@ namespace System.Linq {
                {
                        Check.GroupBySelectors (source, keySelector, elementSelector, resultSelector);
 
-                       return source.Provider.Execute<IQueryable<TResult>> (
+                       return source.Provider.CreateQuery<TResult> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey), typeof (TElement), typeof (TResult)),
                                        source.Expression,
@@ -710,7 +712,7 @@ namespace System.Linq {
                        if (resultSelector == null)
                                throw new ArgumentNullException ("resultSelector");
 
-                       return outer.Provider.Execute<IQueryable<TResult>> (
+                       return outer.Provider.CreateQuery<TResult> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TOuter), typeof (TInner), typeof (TKey), typeof (TResult)),
                                        outer.Expression,
@@ -733,7 +735,7 @@ namespace System.Linq {
                        if (resultSelector == null)
                                throw new ArgumentNullException ("resultSelector");
 
-                       return outer.Provider.Execute<IQueryable<TResult>> (
+                       return outer.Provider.CreateQuery<TResult> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TOuter), typeof (TInner), typeof (TKey), typeof (TResult)),
                                        outer.Expression,
@@ -752,7 +754,7 @@ namespace System.Linq {
                {
                        Check.Source1AndSource2 (source1, source2);
 
-                       return source1.Provider.Execute<IQueryable<TSource>> (
+                       return source1.Provider.CreateQuery<TSource> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
                                        source1.Expression,
@@ -763,7 +765,7 @@ namespace System.Linq {
                {
                        Check.Source1AndSource2 (source1, source2);
 
-                       return source1.Provider.Execute<IQueryable<TSource>> (
+                       return source1.Provider.CreateQuery<TSource> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
                                        source1.Expression,
@@ -779,7 +781,7 @@ namespace System.Linq {
                {
                        Check.JoinSelectors (outer, inner, outerKeySelector, innerKeySelector, resultSelector);
 
-                       return outer.Provider.Execute<IQueryable<TResult>> (
+                       return outer.Provider.CreateQuery<TResult> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TOuter), typeof (TInner), typeof (TKey), typeof (TResult)),
                                        outer.Expression,
@@ -793,7 +795,7 @@ namespace System.Linq {
                {
                        Check.JoinSelectors (outer, inner, outerKeySelector, innerKeySelector, resultSelector);
 
-                       return outer.Provider.Execute<IQueryable<TResult>> (
+                       return outer.Provider.CreateQuery<TResult> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TOuter), typeof (TInner), typeof (TKey), typeof (TResult)),
                                        outer.Expression,
@@ -951,7 +953,7 @@ namespace System.Linq {
                {
                        Check.SourceAndKeySelector (source, keySelector);
 
-                       return source.Provider.Execute<IQueryable<TSource>> (
+                       return source.Provider.CreateQuery<TSource> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey)),
                                        source.Expression,
@@ -962,7 +964,7 @@ namespace System.Linq {
                {
                        Check.SourceAndKeySelector (source, keySelector);
 
-                       return source.Provider.Execute<IQueryable<TSource>> (
+                       return source.Provider.CreateQuery<TSource> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey)),
                                        source.Expression,
@@ -978,7 +980,7 @@ namespace System.Linq {
                {
                        Check.SourceAndKeySelector (source, keySelector);
 
-                       return source.Provider.Execute<IQueryable<TSource>> (
+                       return source.Provider.CreateQuery<TSource> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey)),
                                        source.Expression,
@@ -989,7 +991,7 @@ namespace System.Linq {
                {
                        Check.SourceAndKeySelector (source, keySelector);
 
-                       return source.Provider.Execute<IQueryable<TSource>> (
+                       return source.Provider.CreateQuery<TSource> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey)),
                                        source.Expression,
@@ -1005,7 +1007,7 @@ namespace System.Linq {
                {
                        Check.Source (source);
 
-                       return source.Provider.Execute<IQueryable<TSource>> (
+                       return source.Provider.CreateQuery<TSource> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
                                        source.Expression));
@@ -1019,7 +1021,7 @@ namespace System.Linq {
                {
                        Check.SourceAndSelector (source, selector);
 
-                       return source.Provider.Execute<IQueryable<TResult>> (
+                       return source.Provider.CreateQuery<TResult> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TResult)),
                                        source.Expression,
@@ -1030,7 +1032,7 @@ namespace System.Linq {
                {
                        Check.SourceAndSelector (source, selector);
 
-                       return source.Provider.Execute<IQueryable<TResult>> (
+                       return source.Provider.CreateQuery<TResult> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TResult)),
                                        source.Expression,
@@ -1045,7 +1047,7 @@ namespace System.Linq {
                {
                        Check.SourceAndSelector (source, selector);
 
-                       return source.Provider.Execute<IQueryable<TResult>> (
+                       return source.Provider.CreateQuery<TResult> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TResult)),
                                        source.Expression,
@@ -1056,7 +1058,7 @@ namespace System.Linq {
                {
                        Check.SourceAndSelector (source, selector);
 
-                       return source.Provider.Execute<IQueryable<TResult>> (
+                       return source.Provider.CreateQuery<TResult> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TResult)),
                                        source.Expression,
@@ -1067,7 +1069,7 @@ namespace System.Linq {
                {
                        Check.SourceAndCollectionSelectorAndResultSelector (source, collectionSelector, resultSelector);
 
-                       return source.Provider.Execute<IQueryable<TResult>> (
+                       return source.Provider.CreateQuery<TResult> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TCollection), typeof (TResult)),
                                        source.Expression,
@@ -1079,7 +1081,7 @@ namespace System.Linq {
                {
                        Check.SourceAndCollectionSelectorAndResultSelector (source, collectionSelector, resultSelector);
 
-                       return source.Provider.Execute<IQueryable<TResult>> (
+                       return source.Provider.CreateQuery<TResult> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TCollection), typeof (TResult)),
                                        source.Expression,
@@ -1172,7 +1174,7 @@ namespace System.Linq {
                {
                        Check.Source (source);
 
-                       return source.Provider.Execute<IQueryable<TSource>> (
+                       return source.Provider.CreateQuery<TSource> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
                                        source.Expression,
@@ -1187,7 +1189,7 @@ namespace System.Linq {
                {
                        Check.SourceAndPredicate (source, predicate);
 
-                       return source.Provider.Execute<IQueryable<TSource>> (
+                       return source.Provider.CreateQuery<TSource> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
                                        source.Expression,
@@ -1198,7 +1200,7 @@ namespace System.Linq {
                {
                        Check.SourceAndPredicate (source, predicate);
 
-                       return source.Provider.Execute<IQueryable<TSource>> (
+                       return source.Provider.CreateQuery<TSource> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
                                        source.Expression,
@@ -1441,7 +1443,7 @@ namespace System.Linq {
                {
                        Check.Source (source);
 
-                       return source.Provider.Execute<IQueryable<TSource>> (
+                       return source.Provider.CreateQuery<TSource> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
                                        source.Expression,
@@ -1456,7 +1458,7 @@ namespace System.Linq {
                {
                        Check.SourceAndPredicate (source, predicate);
 
-                       return source.Provider.Execute<IQueryable<TSource>> (
+                       return source.Provider.CreateQuery<TSource> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
                                        source.Expression,
@@ -1467,7 +1469,7 @@ namespace System.Linq {
                {
                        Check.SourceAndPredicate (source, predicate);
 
-                       return source.Provider.Execute<IQueryable<TSource>> (
+                       return source.Provider.CreateQuery<TSource> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
                                        source.Expression,
@@ -1482,7 +1484,7 @@ namespace System.Linq {
                {
                        Check.SourceAndKeySelector (source, keySelector);
 
-                       return source.Provider.Execute<IOrderedQueryable<TSource>> (
+                       return (IOrderedQueryable<TSource>) source.Provider.CreateQuery (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey)),
                                        source.Expression,
@@ -1493,7 +1495,7 @@ namespace System.Linq {
                {
                        Check.SourceAndKeySelector (source, keySelector);
 
-                       return source.Provider.Execute<IOrderedQueryable<TSource>> (
+                       return (IOrderedQueryable<TSource>) source.Provider.CreateQuery (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey)),
                                        source.Expression,
@@ -1509,7 +1511,7 @@ namespace System.Linq {
                {
                        Check.SourceAndKeySelector (source, keySelector);
 
-                       return source.Provider.Execute<IOrderedQueryable<TSource>> (
+                       return (IOrderedQueryable<TSource>) source.Provider.CreateQuery (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey)),
                                        source.Expression,
@@ -1520,7 +1522,7 @@ namespace System.Linq {
                {
                        Check.SourceAndKeySelector (source, keySelector);
 
-                       return source.Provider.Execute<IOrderedQueryable<TSource>> (
+                       return (IOrderedQueryable<TSource>) source.Provider.CreateQuery (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey)),
                                        source.Expression,
@@ -1536,7 +1538,7 @@ namespace System.Linq {
                {
                        Check.Source1AndSource2 (source1, source2);
 
-                       return source1.Provider.Execute<IOrderedQueryable<TSource>> (
+                       return source1.Provider.CreateQuery<TSource> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
                                        source1.Expression,
@@ -1547,7 +1549,7 @@ namespace System.Linq {
                {
                        Check.Source1AndSource2 (source1, source2);
 
-                       return source1.Provider.Execute<IOrderedQueryable<TSource>> (
+                       return source1.Provider.CreateQuery<TSource> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
                                        source1.Expression,
@@ -1564,7 +1566,7 @@ namespace System.Linq {
                {
                        Check.SourceAndPredicate (source, predicate);
 
-                       return source.Provider.Execute<IQueryable<TSource>> (
+                       return source.Provider.CreateQuery<TSource> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
                                        source.Expression,
@@ -1575,7 +1577,7 @@ namespace System.Linq {
                {
                        Check.SourceAndPredicate (source, predicate);
 
-                       return source.Provider.Execute<IQueryable<TSource>> (
+                       return source.Provider.CreateQuery<TSource> (
                                StaticCall (
                                        MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
                                        source.Expression,
index 67386500926c7d43ec535c04ba0f2ebb9c1a98e6..5a58919298bc3840eb02e794bfb09ebbc1582bc9 100644 (file)
   -->\r
   <ProjectExtensions>\r
     <VisualStudio>\r
-      <UserProperties REFS-RefInfo-system-core="repository:vmw:framework:2.0" REFS-JarPath-system-core="" REFS-RefInfo-system-core-2008-javaee="j2il:" REFS-JarPath-system-core-2008-javaee="..\bin\Debug_Java\System.Core-2008.JavaEE.jar" REFS-RefInfo-system="repository:vmw:framework:2.0" REFS-JarPath-system="" REFS-RefInfo-nunit-framework="j2il:" REFS-JarPath-nunit-framework="..\..\..\nunit20\framework\bin\Debug_Java20\nunit.framework.jar" REFS-JarPath-rt="" REFS-RefInfo-rt="repository:jre:sun:1.6.0" />\r
+      <UserProperties REFS-RefInfo-rt="repository:jre:sun:1.6.0" REFS-JarPath-rt="" REFS-JarPath-nunit-framework="..\..\..\nunit20\framework\bin\Debug_Java20\nunit.framework.jar" REFS-RefInfo-nunit-framework="j2il:" REFS-JarPath-system="" REFS-RefInfo-system="repository:vmw:framework:2.0" REFS-JarPath-system-core-2008-javaee="..\bin\Debug_Java\System.Core-2008.JavaEE.jar" REFS-RefInfo-system-core-2008-javaee="j2il:" REFS-JarPath-system-core="" REFS-RefInfo-system-core="repository:vmw:framework:2.0" />\r
     </VisualStudio>\r
   </ProjectExtensions>\r
   <ItemGroup>\r
     <Compile Include="System.Linq.Expressions\ExpressionTest_Utils.cs" />\r
     <Compile Include="System.Linq\EnumerableMoreTest.cs" />\r
     <Compile Include="System.Linq\EnumerableTest.cs" />\r
+    <Compile Include="System.Linq\QueryableProviderTest.cs" />\r
     <Compile Include="System.Linq\QueryableTest.cs" />\r
   </ItemGroup>\r
   <ItemGroup>\r
index c62c46263a4aa7e045cc83032508dcecc3accf30..e592341572fb311c00c5502c706e5f3068c8851f 100755 (executable)
     <Compile Include="System.Linq.Expressions\ExpressionTest_Utils.cs" />\r
     <Compile Include="System.Linq\EnumerableMoreTest.cs" />\r
     <Compile Include="System.Linq\EnumerableTest.cs" />\r
+    <Compile Include="System.Linq\QueryableProviderTest.cs" />\r
     <Compile Include="System.Linq\QueryableTest.cs" />\r
     <Compile Include="System\TimeZoneInfo.AdjustmentRuleTest.cs" />\r
     <Compile Include="System\TimeZoneInfo.TransitionTimeTest.cs" />\r
index e01af185e1c4fef92ee2db504189225ce1b9e357..b4c78b7741e00afcb8d8416db75a36466a37fd97 100644 (file)
@@ -1,3 +1,7 @@
+2008-04-22  Leonid Freydovich <leonidf@mainsoft.com>
+
+       * QueryableProviderTest.cs: add simple test for Queryable.
+
 2008-01-22  Jb Evain  <jbevain@novell.com>
 
        * EnumerableMoreTest.cs: add tests by
diff --git a/mcs/class/System.Core/Test/System.Linq/QueryableProviderTest.cs b/mcs/class/System.Core/Test/System.Linq/QueryableProviderTest.cs
new file mode 100644 (file)
index 0000000..467d1aa
--- /dev/null
@@ -0,0 +1,442 @@
+using System;\r
+using System.Text;\r
+using System.Collections;\r
+using System.Collections.Generic;\r
+using System.Linq;\r
+using System.Linq.Expressions;\r
+using System.Reflection;\r
+using NUnit.Framework;\r
+\r
+\r
+namespace MonoTests.System.Linq\r
+{\r
+\r
+       [TestFixture]\r
+       public class QueryableProviderTest\r
+       {\r
+               QueryProvider _provider;\r
+\r
+               Query<int> _src;\r
+\r
+               int [] _array = { 1, 2, 3 };\r
+               int [] _otherArray = { 0, 2 };\r
+\r
+               public QueryableProviderTest ()\r
+               {\r
+                       _provider = new QueryProvider ();\r
+                       _src = new Query<int> (_provider, _array);\r
+\r
+               }\r
+\r
+               [SetUp]\r
+               public void MyTestCleanup ()\r
+               {\r
+                       _provider.Init ();\r
+               }\r
+\r
+               [Test]\r
+               public void TestAggregate ()\r
+               {\r
+                       _src.Aggregate<int> ((n, m) => n + m);\r
+                       Assert.AreEqual (StatusEnum.Execute, _provider.Status);\r
+\r
+               }\r
+\r
+               [Test]\r
+               public void TestAll ()\r
+               {\r
+                       _src.All<int> ((n) => true);\r
+                       Assert.AreEqual (StatusEnum.Execute, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestAny ()\r
+               {\r
+                       _src.Any<int> ();\r
+                       Assert.AreEqual (StatusEnum.Execute, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestAverage ()\r
+               {\r
+                       _src.Average<int> ((n) => n);\r
+                       Assert.AreEqual (StatusEnum.Execute, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestCast ()\r
+               {\r
+                       _src.Cast<int> ();\r
+                       Assert.AreEqual (StatusEnum.CreateQuery, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestConcat ()\r
+               {\r
+                       _src.Concat<int> (_otherArray);\r
+                       Assert.AreEqual (StatusEnum.CreateQuery, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestContains ()\r
+               {\r
+                       _src.Contains<int> (3);\r
+                       Assert.AreEqual (StatusEnum.Execute, _provider.Status);\r
+               }\r
+\r
+\r
+               [Test]\r
+               public void TestCount ()\r
+               {\r
+                       _src.Count<int> ();\r
+                       Assert.AreEqual (StatusEnum.Execute, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestDefaultIfEmpty ()\r
+               {\r
+                       _src.DefaultIfEmpty<int> (0);\r
+                       Assert.AreEqual (StatusEnum.CreateQuery, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestDistinct ()\r
+               {\r
+                       _src.Distinct<int> ();\r
+                       Assert.AreEqual (StatusEnum.CreateQuery, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestElementAt ()\r
+               {\r
+                       _src.ElementAt<int> (1);\r
+                       Assert.AreEqual (StatusEnum.Execute, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestElementAtOrDefault ()\r
+               {\r
+                       _src.ElementAtOrDefault<int> (1);\r
+                       Assert.AreEqual (StatusEnum.Execute, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestExcept ()\r
+               {\r
+                       _src.Except<int> (_otherArray);\r
+                       Assert.AreEqual (StatusEnum.CreateQuery, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestFirst ()\r
+               {\r
+                       _src.First<int> ();\r
+                       Assert.AreEqual (StatusEnum.Execute, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestFirstOrDefault ()\r
+               {\r
+                       _src.FirstOrDefault<int> ((n) => n > 1);\r
+                       Assert.AreEqual (StatusEnum.Execute, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestGroupBy ()\r
+               {\r
+                       _src.GroupBy<int, bool> ((n) => n > 2);\r
+                       Assert.AreEqual (StatusEnum.CreateQuery, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestGroupJoin ()\r
+               {\r
+                       _src.GroupJoin<int, int, bool, int> (_otherArray, (n) => n > 1, (n) => n > 1, (n, col) => n);\r
+                       Assert.AreEqual (StatusEnum.CreateQuery, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestIntersect ()\r
+               {\r
+                       _src.Intersect<int> (_otherArray);\r
+                       Assert.AreEqual (StatusEnum.CreateQuery, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestJoin ()\r
+               {\r
+                       _src.Join<int, int, int, int> (_otherArray, (n) => n, (n => n), (n, m) => n + m);\r
+                       Assert.AreEqual (StatusEnum.CreateQuery, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestLast ()\r
+               {\r
+                       _src.Last<int> ((n) => n > 1);\r
+                       Assert.AreEqual (StatusEnum.Execute, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestLastOrDefault ()\r
+               {\r
+                       _src.LastOrDefault<int> ();\r
+                       Assert.AreEqual (StatusEnum.Execute, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestLongCount ()\r
+               {\r
+                       _src.LongCount<int> ();\r
+                       Assert.AreEqual (StatusEnum.Execute, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestMax ()\r
+               {\r
+                       _src.Max<int> ();\r
+                       Assert.AreEqual (StatusEnum.Execute, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestMin ()\r
+               {\r
+                       _src.Min<int> ();\r
+                       Assert.AreEqual (StatusEnum.Execute, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestOfType ()\r
+               {\r
+                       _src.OfType<int> ();\r
+                       Assert.AreEqual (StatusEnum.CreateQuery, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestOrderBy ()\r
+               {\r
+                       _src.OrderBy<int, bool> ((n) => n > 1);\r
+                       Assert.AreEqual (StatusEnum.CreateQuery, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestOrderByDescending ()\r
+               {\r
+                       _src.OrderByDescending<int, bool> ((n) => n > 1);\r
+                       Assert.AreEqual (StatusEnum.CreateQuery, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestReverse ()\r
+               {\r
+                       _src.Reverse<int> ();\r
+                       Assert.AreEqual (StatusEnum.CreateQuery, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestSelect ()\r
+               {\r
+                       _src.Select<int, int> ((n) => n);\r
+                       Assert.AreEqual (StatusEnum.CreateQuery, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestSelectMany ()\r
+               {\r
+                       _src.SelectMany<int, int> ((n) => new int [] { n });\r
+                       Assert.AreEqual (StatusEnum.CreateQuery, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestSequenceEqual ()\r
+               {\r
+                       _src.SequenceEqual<int> (_otherArray);\r
+                       Assert.AreEqual (StatusEnum.Execute, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestSingle ()\r
+               {\r
+                       (new Query<int> (_provider, new int [] { 1 })).Single<int> ();\r
+                       Assert.AreEqual (StatusEnum.Execute, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestSingleOrDefault ()\r
+               {\r
+                       (new Query<int> (_provider, new int [] { 1 })).SingleOrDefault<int> ();\r
+                       Assert.AreEqual (StatusEnum.Execute, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestSkip ()\r
+               {\r
+                       _src.Skip<int> (1);\r
+                       Assert.AreEqual (StatusEnum.CreateQuery, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestSkipWhile ()\r
+               {\r
+                       _src.SkipWhile<int> ((n) => n > 1);\r
+                       Assert.AreEqual (StatusEnum.CreateQuery, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestSum ()\r
+               {\r
+                       _src.Sum<int> ((n) => n);\r
+                       Assert.AreEqual (StatusEnum.Execute, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestTake ()\r
+               {\r
+                       _src.Take<int> (3);\r
+                       Assert.AreEqual (StatusEnum.CreateQuery, _provider.Status);\r
+               }\r
+\r
+\r
+               [Test]\r
+               public void TestTakeWhile ()\r
+               {\r
+                       _src.TakeWhile<int> ((n) => n < 2);\r
+                       Assert.AreEqual (StatusEnum.CreateQuery, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestThenBy ()\r
+               {\r
+                       _src.ThenBy<int, bool> ((n) => n < 2);\r
+                       Assert.AreEqual (StatusEnum.CreateQuery, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestThenByDescending ()\r
+               {\r
+                       _src.ThenByDescending<int, bool> ((n) => n < 2);\r
+                       Assert.AreEqual (StatusEnum.CreateQuery, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestUnion ()\r
+               {\r
+                       _src.Union<int> (_otherArray);\r
+                       Assert.AreEqual (StatusEnum.CreateQuery, _provider.Status);\r
+               }\r
+\r
+               [Test]\r
+               public void TestWhere ()\r
+               {\r
+                       _src.Where<int> ((n) => true);\r
+                       Assert.AreEqual (StatusEnum.CreateQuery, _provider.Status);\r
+               }\r
+\r
+               public class Query<T> : IQueryable<T>, IQueryable, IEnumerable<T>, IEnumerable, IOrderedQueryable<T>, IOrderedQueryable\r
+               {\r
+                       IQueryProvider provider;\r
+\r
+                       Expression expression;\r
+\r
+                       IEnumerable<T> _context;\r
+\r
+                       public Query (IQueryProvider provider, IEnumerable<T> context)\r
+                       {\r
+                               _context = context;\r
+                               this.provider = provider;\r
+                               this.expression = Expression.Constant (this);\r
+                       }\r
+\r
+                       Expression IQueryable.Expression\r
+                       {\r
+\r
+                               get { return this.expression; }\r
+\r
+                       }\r
+\r
+\r
+\r
+                       Type IQueryable.ElementType\r
+                       {\r
+\r
+                               get { return typeof (T); }\r
+\r
+                       }\r
+\r
+\r
+                       IQueryProvider IQueryable.Provider\r
+                       {\r
+\r
+                               get { return this.provider; }\r
+\r
+                       }\r
+\r
+\r
+                       public IEnumerator<T> GetEnumerator ()\r
+                       {\r
+                               throw new NotImplementedException ();\r
+                       }\r
+\r
+                       IEnumerator IEnumerable.GetEnumerator ()\r
+                       {\r
+                               throw new NotImplementedException ();\r
+                       }\r
+\r
+               }\r
+\r
+               public enum StatusEnum { NotInitilized, Execute, CreateQuery }\r
+\r
+               public class QueryProvider : IQueryProvider\r
+               {\r
+\r
+                       private StatusEnum _status = StatusEnum.NotInitilized;\r
+\r
+                       public StatusEnum Status\r
+                       {\r
+                               get { return _status; }\r
+                               set { _status = value; }\r
+                       }\r
+\r
+                       public void Init ()\r
+                       {\r
+                               _status = StatusEnum.NotInitilized;\r
+                       }\r
+\r
+                       public QueryProvider ()\r
+                       {\r
+                               Init ();\r
+                       }\r
+\r
+                       #region IQueryProvider Members\r
+\r
+                       IQueryable<S> IQueryProvider.CreateQuery<S> (Expression expression)\r
+                       {\r
+                               Status = StatusEnum.CreateQuery;\r
+                               return null;\r
+                       }\r
+\r
+                       IQueryable IQueryProvider.CreateQuery (Expression expression)\r
+                       {\r
+                               Status = StatusEnum.CreateQuery;\r
+                               return null;\r
+\r
+                       }\r
+\r
+                       S IQueryProvider.Execute<S> (Expression expression)\r
+                       {\r
+                               Status = StatusEnum.Execute;\r
+                               return default (S);\r
+                       }\r
+\r
+\r
+\r
+                       object IQueryProvider.Execute (Expression expression)\r
+                       {\r
+                               Status = StatusEnum.Execute;\r
+                               return null;\r
+\r
+                       }\r
+\r
+                       #endregion\r
+               }\r
+       }\r
+}\r