Files
mono/mcs/class/System.Core/Test/System.Linq.Expressions/ExpressionTest.cs
T
Jb Evain db7207ef3a 2008-01-15 Jb Evain <[email protected]>
* ExpressionTest.cs: tests for Expression.Parameter


svn path=/trunk/mcs/; revision=92948
2008-01-15 13:55:15 +00:00

149 lines
4.4 KiB
C#

//
// ExpressionTest.cs
//
// Author:
// Jb Evain ([email protected])
//
// (C) 2008 Novell, Inc. (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Reflection;
using System.Linq;
using System.Linq.Expressions;
using NUnit.Framework;
namespace MonoTests.System.Linq.Expressions {
[TestFixture]
public class ExpressionTest {
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void GetFuncTypeArgNull ()
{
Expression.GetFuncType (null);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void GetFuncTypeArgEmpty ()
{
Expression.GetFuncType (new Type [0]);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void GetFuncTypeArgTooBig ()
{
Expression.GetFuncType (new Type [6]);
}
[Test]
public void GetFuncTypeTest ()
{
var func = Expression.GetFuncType (new [] {typeof (int)});
Assert.AreEqual (typeof (Func<int>), func);
func = Expression.GetFuncType (new [] {typeof (int), typeof (int)});
Assert.AreEqual (typeof (Func<int, int>), func);
func = Expression.GetFuncType (new [] {typeof (int), typeof (int), typeof (int)});
Assert.AreEqual (typeof (Func<int, int, int>), func);
func = Expression.GetFuncType (new [] {typeof (int), typeof (int), typeof (int), typeof (int)});
Assert.AreEqual (typeof (Func<int, int, int, int>), func);
func = Expression.GetFuncType (new [] {typeof (int), typeof (int), typeof (int), typeof (int), typeof (int)});
Assert.AreEqual (typeof (Func<int, int, int, int, int>), func);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void GetActionTypeArgNull ()
{
Expression.GetActionType (null);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void GetActionTypeArgTooBig ()
{
Expression.GetActionType (new Type [5]);
}
[Test]
public void GetActionTypeTest ()
{
var action = Expression.GetActionType (new Type [0]);
Assert.AreEqual (typeof (Action), action);
action = Expression.GetActionType (new [] {typeof (int)});
Assert.AreEqual (typeof (Action<int>), action);
action = Expression.GetActionType (new [] {typeof (int), typeof (int)});
Assert.AreEqual (typeof (Action<int, int>), action);
action = Expression.GetActionType (new [] {typeof (int), typeof (int), typeof (int)});
Assert.AreEqual (typeof (Action<int, int, int>), action);
action = Expression.GetActionType (new [] {typeof (int), typeof (int), typeof (int), typeof (int)});
Assert.AreEqual (typeof (Action<int, int, int, int>), action);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ParameterNullType ()
{
Expression.Parameter (null, "foo");
}
[Test]
public void ParameterNullName ()
{
var p = Expression.Parameter (typeof (string), null);
Assert.AreEqual (null, p.Name);
Assert.AreEqual (typeof (string), p.Type);
Assert.AreEqual ("<param>", p.ToString ());
}
[Test]
public void ParameterEmptyName ()
{
var p = Expression.Parameter (typeof (string), "");
Assert.AreEqual ("", p.Name);
Assert.AreEqual (typeof (string), p.Type);
Assert.AreEqual ("", p.ToString ());
}
[Test]
public void Parameter ()
{
var p = Expression.Parameter (typeof (string), "foo");
Assert.AreEqual ("foo", p.Name);
Assert.AreEqual (typeof (string), p.Type);
Assert.AreEqual ("foo", p.ToString ());
}
}
}