New tests.
[mono.git] / mcs / class / System.Core / Test / System.Linq.Expressions / ExpressionTest_Call.cs
index b170c3df23d1df0d1948ed1bc49390f7f755548d..8f668d288ab00b6908fd60f63b958e17f153b2f3 100644 (file)
@@ -87,7 +87,11 @@ namespace MonoTests.System.Linq.Expressions {
                }
 
                [Test]
+#if NET_4_0
+               [ExpectedException (typeof (ArgumentException))]
+#else
                [ExpectedException (typeof (ArgumentNullException))]
+#endif
                public void ArgInstanceNullForNonStaticMethod ()
                {
                        Expression.Call (null, typeof (object).GetMethod ("ToString"));
@@ -281,7 +285,7 @@ namespace MonoTests.System.Linq.Expressions {
                {
                        return (int) (i as ConstantExpression).Value;
                }
-
+#if !NET_4_0 // dlr bug 5875
                [Test]
                public void CallMethodWithExpressionParameter ()
                {
@@ -292,7 +296,7 @@ namespace MonoTests.System.Linq.Expressions {
 
                        Assert.AreEqual (42, l ());
                }
-
+#endif
                static bool fout_called = false;
 
                public static int FooOut (out int x)
@@ -420,5 +424,75 @@ namespace MonoTests.System.Linq.Expressions {
                        Assert.IsNotNull (call);
                        Assert.IsNotNull (call.Method);
                }
+
+               [Test]
+               public void CallAsQueryable () // #537768
+               {
+                       var constant = Expression.Constant (
+                               new List<string> (),
+                               typeof (IEnumerable<string>));
+
+                       var call = Expression.Call (
+                               typeof (Queryable),
+                               "AsQueryable",
+                               new [] { typeof (string) },
+                               constant);
+
+                       Assert.IsNotNull (call);
+                       Assert.AreEqual (1, call.Arguments.Count);
+                       Assert.AreEqual (constant, call.Arguments [0]);
+
+                       var method = call.Method;
+
+                       Assert.AreEqual ("AsQueryable", method.Name);
+                       Assert.IsTrue (method.IsGenericMethod);
+                       Assert.AreEqual (typeof (string), method.GetGenericArguments () [0]);
+               }
+
+
+               [Test]
+               public void CallQueryableSelect () // #536637
+               {
+                       var parameter = Expression.Parameter (typeof (string), "s");
+                       var string_length = Expression.Property (parameter, typeof (string).GetProperty ("Length"));
+                       var lambda = Expression.Lambda (string_length, parameter);
+
+                       var strings = new [] { "1", "22", "333" };
+
+                       var call = Expression.Call (
+                               typeof (Queryable),
+                               "Select",
+                               new [] { typeof (string), typeof (int) },
+                               Expression.Constant (strings.AsQueryable ()),
+                               lambda);
+
+                       Assert.IsNotNull (call);
+
+                       var method = call.Method;
+
+                       Assert.AreEqual ("Select", method.Name);
+                       Assert.IsTrue (method.IsGenericMethod);
+                       Assert.AreEqual (typeof (string), method.GetGenericArguments () [0]);
+                       Assert.AreEqual (typeof (int), method.GetGenericArguments () [1]);
+               }
+
+               [Test]
+               public void CallNullableGetValueOrDefault () // #568989
+               {
+                       var value = Expression.Parameter (typeof (int?), "value");
+                       var default_parameter = Expression.Parameter (typeof (int), "default");
+
+                       var getter = Expression.Lambda<Func<int?, int, int>> (
+                               Expression.Call (
+                                       value,
+                                       "GetValueOrDefault",
+                                       Type.EmptyTypes,
+                                       default_parameter),
+                               value,
+                               default_parameter).Compile ();
+
+                       Assert.AreEqual (2, getter (null, 2));
+                       Assert.AreEqual (4, getter (4, 2));
+               }
        }
 }