1
Vote

Needs better exception message when accidently trying to mock extension method

description

The following code:
[Test]
public void ExpectExtensionMethodCall()
{
  var c = Mock.Interface<IEnumerable<int>>();

  Expect.MethodCall(() => c.Where(e => e % 2 == 0)).Returns(new[]{ 2, 4, 6 });
}
Gives you this null reference exception. Should give you something more specific.
System.ArgumentNullException : Value cannot be null.
Parameter name: expression
   at System.Linq.Expressions.Expression.RequiresCanRead(Expression expression, String paramName)
   at System.Linq.Expressions.Expression.Convert(Expression expression, Type type, MethodInfo method)
   at Simple.Mocking.SetUp.InvocationMatcher.ResolveObjectFromExpression(Expression expression) in InvocationMatcher.cs: line 281
   at Simple.Mocking.SetUp.InvocationMatcher.CreateForMethodCall(LambdaExpression methodCallExpression) in InvocationMatcher.cs: line 159
   at Simple.Mocking.SetUp.InvocationMatcher.ForMethodCall(LambdaExpression methodCallExpression) in InvocationMatcher.cs: line 141
   at Simple.Mocking.Expect.SpecifyInvocation.MethodCall(Expression 1 methodCallExpression) in Expect.cs: line 135
   at Simple.Mocking.Expect.MethodCall(Expression 1 methodCallExpression) in Expect.cs: line 58
   at Simple.Mocking.AcceptanceTests.ExpectTests.ExpectExtensionMethodCall() in ExpectTests.cs: line 474

comments