I'm working on making EF easier to unit test by writing some helpers that will make properties for me. I have a couple of backing fields
private Mock<DbSet<Workflow>> mockedWorkFlows;
private Mock<DbSet<WorkflowError>> mockedWorkFlowErrors;
And I want a generic function to be able to return me the correct backing field with the following function
public Mock<DbSet<T>> Mocked<T>(T t) where T : class
{
if ( (object)t is Workflow)
{
return mockedWorkFlows; //cannot Workflow to T
}
}
There are several private backing fields which I want to be returned based on the type passed it.
However, even if I add a class constraint of Workflow
, I get the same error.
I also tried switching on t's
type but no luck there either. The types of the several backing fields do not share a common ancestor, other than object. Is what I'm trying to do possible?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…