I am writting Unit Test for my database connection.
I have following class
Public class A
{
public IDbConnection _dbConnection;
public A()
{
You can easely use the constructor to of class A to insert your dependencies, add the following constructor to class A:
public A(IDBConnection connection)
{
_dbConnection = connection;
}
Then you test will look like:
[TestMethod]
public void TestMethod1()
{
StubIDbConnection stubIDbConnection = new StubIDbConnection();
stubIDbConnection.Execute =(null) => -1;
var a = new classA(stubIDbConnection);
int answer = a.ExecuteNoneQuery(null);
Assert.AreEqual(-1,answer);
}