Code:
public interface IDoStuff
{
void DoStuff<T>(T item);
}
[TestFixture]
public class MyTestClass
{
[SetUp]
public void Setup()
{
_doStuff = new Mock<IDoStuff>();
_doStuff.Setup(x => x.DoStuff(It.IsAny<object>)).Callback<object>(...);
}
}
The callback will only be called when T is object, not when T is another class (that inherits object). Is there a way of getting a callback to run, whatever the generic type is, as long as it inherits T rather than is T?
Im doing one setup per expected type instead, which isn't very elegant, or flexible (copy/paste coding and need to fix the test every time another case of T turns up...)
Edit: Solution seems to be a good old-fashined stub for this, but I'd still like to know if it's doable with Moq.
Last edited: