ameniameni / moq

Automatically exported from code.google.com/p/moq
Other
0 stars 0 forks source link

Moq doesn't recognize generic delegate invocations as method calls #224

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Define an interface that can take a delegate as a generic parameter like 
so:
 public interface ICreateDestroyFactory<CreateType>
        where CreateType : class
    {
        CreateType Create
        {
            get;
        }
        void Destroy();
    }
2.  Define a mock that implements the interface and specifies the generic 
parameter as a delegate like so:
Mock<ICreateDestroyFactory<Func<object>>> mock = new 
Mock<ICreateDestroyFactory<Func<object>>>();

3.  Try to put a setup on the mock like so:
mock.Setup(i=>i.Create()).Returns(new object());

The following exception is thrown:
System.ArgumentException: Expression is not a method invocation: i => 
Invoke(i.Create).

What version of the product are you using? On what operating system?
Moq 4.0.812.4

Original issue reported on code.google.com by kayode81...@gmail.com on 20 Dec 2009 at 2:35

GoogleCodeExporter commented 8 years ago
This case is invalid as Create is a property and not a method, also the Returns 
should receive a delegate, the right definition of the case would be:

var mock = new Mock<ICreateDestroyFactory<Func<object>>>();
mock.Setup(i => i.Create).Returns(() => new object());

Original comment by marian...@gmail.com on 25 Jun 2010 at 1:44