We have an application with perfect data management. We want to use the unit test application, but the developers are resistant to creating completely fake repositories due to the amount of data. I really don't blame them.
Understand that we will reorient tests to the existing application. If we begin, we will make a ton of architectural changes to facilitate module testing with fake repositories.
We would like to distribute the well-known mdf file with tests, copy it and use it to run our tests. Is there an approved methodology for this? I am familiar with investing resources in a test dll, but not with mdf's embedding - if you can even do that.
Solution (view):
I ended up getting a DataContextWrapper message from Andrew Tokeli's message about mocking Linq data contexts (http://andrewtokeley.net/archive/2008/07/06/mocking-linq-to-sql-datacontext.aspx) and created FakeDataContext.cs, which is basically a list of lists.
I wrote a really barbaric T4 template (think "select * FROM <# = table.BaseClass.QualifiedName #>") to copy data from a well-known good database to create a huge class full of things like:
List<Customer> _customers = new List<Customer>(); _customers.Add(new Customer(){CustomerId = 1, CustomerName = "ACME"});
and etc.
The class is 25K lines, but since t4 writes all these lines, who needs it? This allows us to make fun of only the data context, so we can test our linq against the fake context with some reasonable assurance that we received the correct requests. Initial developers put a ton of business logic in the repo, so it allows us to test the logic using well-known good data.
unit-testing asp.net-mvc integration-testing mdf
Code silverback
source share