Reputation: 2772
I'm trying to use JustMock Lite to UnitTest a method that uses SqlConnection to call a stored proc. I obviously need to mock the database call. I have been searching, and finding it very hard to even find something even mentioning doing this. Closest I have is the following:
http://www.telerik.com/blogs/working-with-mock-behaviors-in-justmock
Now, I have tried this, but it looks like this require the full version on JustMock (something I am still working on getting them to spring for). Is there anyway to test this kind of behavior without the full version?
Thanks
Upvotes: 0
Views: 238
Reputation: 14473
SqlConnection
inherits from MarshalByRefObject
, which means that you should be able to create a mock of it with Mock.Create<SqlConnection>()
and arrange it to your heart's content. If you need to mock also the construction of the SqlConnection
, then you need the full verision.
A much cleaner design would be to have no dependence on SqlConnection
in the code under test, but rather on IDbConnection
. The concrete connection object (whether an SqlConnection
or a mock of IDbConnection
) can then be passed in by the consumer of the class.
If you have specific problems mocking and arranging any of these classes, then please elaborate on them in your question, preferably with code snippets demonstrating the issue.
Upvotes: 0