I'm not aware of any way to do this directly. I don't think DynamicProxy (which FakeItEasy uses) supports open generic types. However, there's a workaround, if you're interested.
There's a way to specify a call to any method or property on a fake. Check out the Where
and WithReturnType
bits in this passing test:
[TestFixture]
public class BarTests
{
[Test]
public void BarFooDoesStuff()
{
var expected = 9999999;
var fakeBar = A.Fake<IBar>();
A.CallTo(fakeBar)
.Where(call => call.Method.Name == "Foo")
.WithReturnType<int>()
.Returns(expected);
var response = fakeBar.Foo<bool>();
Assert.AreEqual(expected, response);
}
}
Still, though, I'm curious about the use for this. Do you have an example test that actually uses the faked interface as a dependency?