I have a general method: (simplified)
public class DataAccess : IDataAccess
{
public List<T> GetEntity<T>()
{
return GetFromDatabase<T>();
}
}
For testing purposes, I want to create a stub from which I want "Foo" to return with some data:
public class DataAccessStub : IDataAccess
{
public List<T> GetEntity<T>()
{
List<Foo> listFoo = new List<Foo>();
Foo foo = new Foo();
foo.Name = "Some Name";
listFoo.Add(foo);
return listFoo;
}
}
Since I have Tnot determined what type it is, I cannot return it List<Foo>. Compiler error. So, how can I write a stub for this kind of common method?
Edit: slightly changed the code. The first method will be retrieved from the database on the type parameter. The second is a stub for testing. Sorry I'm not sure if this explains what I want to mention.
Thank.
source
share