RajOpteamix / moq

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

Can't define a mock that responds to all types of a generic method #360

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Try to define a mock for an interface that has a generic method. E.g.:
public interface IFoo
{
    T Bar<T>();
}

var mock = new Mock<IFoo>();
mock.Setup(foo => foo.Bar<It.IsAnyType>()).Returns(default(anyType));

What is the expected output? What do you see instead?
The last line is invalid syntax. I would expect that there is a way to mock 
generic methods such that I can get the type that was used in the call and do 
something with it. I do NOT want to mock each possible type one by one.

What version of the product are you using? On what operating system?
.NET 4
Windows 7

Please provide any additional information below.

Original issue reported on code.google.com by gkn0...@gmail.com on 1 Mar 2013 at 11:33