Last post May 19, 2013 11:53 PM by falconsfire
May 15, 2013 07:33 PM|falconsfire|LINK
I have a question, if we push complex/multi table queries into the repository layer which I agree is where it should belong - how would you go about unit testing this logic without having a database?
I might add, that normally I would have that when unit testing, you would implement a dummy IRepository, or mock the IRepository so that it would return your domain objects, and you would then unit test the controller classes with a mocked repository.
However by pushing complex queries into the repository itself, it makes it difficult to mock - I mean you wouldn't want to reimplement your complex query logic in the mock, which really only leaves testing with a real database connected, which makes it an
May 17, 2013 06:01 AM|DarrellNorton|LINK
Correct to your last statement that this is an integration test. When reading your question (before I read the body) I said to myself "just use an integration test." If you have setup things correctly, you should be able to swap out a LocalDb implementation
in your test project's App.config and attach a database at test run time so you will have known values for the query (see this link: http://stackoverflow.com/questions/12244495/how-to-set-up-localdb-for-unit-tests-in-visual-studio-2012-and-entity-framework).
Everything doesn't have to be unit tested - especially if you have an integration test covering it. Heck there are parts of your application that you may never test (e.g., the visual layout on pages).
May 19, 2013 11:53 PM|falconsfire|LINK
Thanks Darrell, thanks for the link too good stuff