I'm currently using a test framework I've thrown together using xUnit, AutoMoq, AutoFixture, and AutoFixture.XUnit2. I'm running into issues with mocking methods with generic signatures.
AutoFixture seems to handle generic items just fine. If I ask for a CustomeObject<Task<List<Task<string>>>>
, or some other ridiculous nested generic type, it seems to generate them as expected all the way down to the last node.
However, if I have an interface like this:
public interface ITestInterface{
T Get<T>();
}
and then try to call the method from the mock I got from AutoMoq it just returns null. So, for example:
[Theory]
[MyAutoDaqaAttribute]
public async Task ATest(
Mock<ITestInterface> service
) {
var result = service.Object.Get<string>();
}
In this code result will be null. That seems odd to me. Shouldn't it go to autofixture and try to create a value of type T i.e. a new string? It seems like Autofixture has already shown that it can handle generics just fine.
Or do you always just have to manually setup any mock method that has a generic in its signature?