Hi,
I'm relatively new to mocking frameworks so bear with me. :)
We're testing a couple of classes which depend on IDb* objects (sort
of a DAL). I was trying to mock DbFactoryProvider so we can inject
mock IDb objects to the classes.
So, i did this:
Mock<IDbCommand> mockIDbCommand = new
Mock<IDbCommand>(MockBehavior.Strict);
mockIDbCommand.SetupAllProperties();
Mock<IDbConnection> mockIDbConnection = new
Mock<IDbConnection>(MockBehavior.Strict);
mockIDbConnection.SetupAllProperties();
mockIDbConnection.Setup(c =>
c.CreateCommand()).Returns(mockIDbCommand.Object);
Mock<DbProviderFactory> mockDbProviderFactory = new
Mock<DbProviderFactory>(MockBehavior.Strict);
mockDbProviderFactory.Setup(f =>
f.CreateConnection()).Returns(mockIDbConnection.Object);
The last line won't compile since DbProviderFactory.CreateConnection()
returns an DbConnection and not an IDbConnection.
The problem is can't mock DbConnection.CreateCommand() since that
method is not virtual/overridable.
I tried casting mockIDbConnection.Object to DbConnection but that
doesn't work.
Any suggestions on how to solve this problem ?
Huge thanks,
Nuno Leong
--
Post:
moq...@googlegroups.com
Unsubscribe:
moqdisc-u...@googlegroups.com