Hi Eli,
My first crack at writing the unit test created the product object outside the recorder block as you have shown. That make sense to me as you don't want it mocked.
I have however tracked down my problem with the unit test. My test class (DatabaseTest.BizProduct) has a constructor that creates the database access object (DatabaseTest.ProductAccess).
The problem here is that I have created the test class
before the recorder block. The mocked database access object is not being used as the testclass has already created its data access object.
So if you mock an object that is created in your test class constructor be careful to create you test class
after you have completed your recording block.
I retested the two previous suggestions moving the test class creation to after the recording block.
See "MockTestStopRecordingTest" and "MockTestCallOriginalTest"
MockTestStopRecordingTest, works
MockTestCallOriginalTest, still fails. It appears that the values plugged in are not being used and the plain uninitialised object.
Thanks for all your help
Below is the code for the test class showing the constructor creating the data access object.
public class BizProduct
{
private IProductDataAccess _dbAccess = null;
public BizProduct()
{
_dbAccess = new ProductAccess();
}
public BizProduct(IProductDataAccess DBaccess)
{
_dbAccess = DBaccess;
}
public IProduct GetProduct(string ProductCode)
{
return _dbAccess.GetProduct(ProductCode);
}
}