I am having a hard time seeing how to test something like the following. This method updates a record in the database. So how should this be approached, as I would like to have it update, verify the record was updated, then rollback the transaction at the end of the test?
If I just mock the database, that is a valid unit test but I am also looking for an integration test that verifies that the update actually works and that the database is updated. But I don't see how I can create a test that will roll this back, as SaveChanges() executes a commit.
So how would you suggest that I handle a unit test and an integration test for the CreateFileHistoryRecord() function?
/// Constructor. Injects the connection string and creates the OpenAccess domain model object.
JustMock is not particularly useful for creating integration tests. After all, its main purpose is isolating dependencies.
In your case you'd like to do some changes to the database, assert that the changes are made (possibly using a second query that checks the DB's data) and then rollback. The pattern isn't much different than the regular Arrange/Act/Assert pattern. It's just that in your Arrange phase, you will have to bootstrap a fresh database (clone an existing one, maybe?). Then, in your Assert phase, you will query the DB and check that all necessary changes were indeed made. In the test cleanup just drop the database.
JustMock can't help you with writing integration tests. You will pretty much have to roll your own code and test structure that lets you quickly add new integration tests.
Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums, or our JustTrace or JustMock portals.