hello.
i have the following test code:
[Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfigurationNameMapper(typeof(Microsoft.Practices.EnterpriseLibrary.Data.DatabaseMapper))]
[Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.CustomFactory(typeof(Microsoft.Practices.EnterpriseLibrary.Data.DatabaseCustomFactory))]
public abstract class Database
{
public virtual System.Data.IDataReader ExecuteReader(System.Data.Common.DbCommand dbCmd)
{
return null;
}
public System.Data.Common.DbCommand GetSqlStringCommand(string p)
{
return null;
}
}
[TestMethod]
[VerifyMocks]
public void TypeMockFailureTest()
{
Database dataBase = (Database)RecorderManager.CreateMockedObject(typeof(Database));
System.Data.Common.DbCommand dbCmd = (System.Data.Common.DbCommand)RecorderManager.CreateMockedObject(typeof(System.Data.Common.DbCommand));
using (RecordExpectations recorder = RecorderManager.StartRecording())
{
// CAUTION: ALL calls here are mocked!!!
dataBase.GetSqlStringCommand("bla bla");
recorder.Return(dbCmd);
dataBase.ExecuteReader(dbCmd);
recorder.Return(null);
}
System.Data.Common.DbCommand cmd = dataBase.GetSqlStringCommand("bla bla");
System.Data.IDataReader reader = dataBase.ExecuteReader(cmd);
}
}
This UnitTest Code fails with
TypeMock Verification: Unexpected Call to UnitTests.TypeMockTest+Database.GetSqlStringCommand().
It happenes in recording stage.
The problems goes away if we remove the two attributes over “Database” class.
If we leave only the “ConfigurationNameMapper” attribute, the unittest fails with:
Test method UnitTests.TypeMockTest.TypeMockFailureTest threw exception: TypeMock.TypeMockException:
*** Cannot return a value for AssemblyResolver.OnResolve() because no value was set. use recorder.Return().
*** Note: Cannot mock types from mscorlib assembly..
It is clearly a bug.
I use Microsoft Enterprise Library 3.1, Data Access Application Block (although DAAB is not involved in the failed code...)
can you suggest a fix or a workaround? i need to be able to mock a database object and excpect calls.
thank you.