I'm using the VS2012 built-in Fakes framework.
This design question is related to the following post: Unit test won't "cover" simple get method. (c#)
I'm not certain how to design class for "IDbAccess" to successfully "fake" hitting the database.
Ex code (taken from previous post):
public class Foo : IFoo
{
IDbAccess db;
public Foo(IDbAccess db)
{
this.db = db;
}
public Dictionary<string,string> GetSomething(string xyz)
{
var result = new Dictionary<string,string>
db.commandText = "text..."
db.connection = conn;
result.Add(db.MethodWhatever(xyz));
return result;
}
}
Ex Test Method:
[TestMethod()]
public void GetSomething()
{
var dba = new StubIDbAccess();
var target = new Foo(dba);
var expected = new Dictionary<string, string>
{
{"blahKey","blahValue"}
};
// get something
var results = target.GetSomething("xyzstring");
// verify results
var actual = results.whatever;
CollectionAssert.AreEqual(expected,actual);
}
In order to "stub" IDbAccess, IDbAccess needs to be a class that inherits from IDbCommand. I'm just not sure how to implement it to avoid having to override everything in IDbCommand.
public interface IDbAccess : IDbCommand
{
...?
}