I’m currently building a .net web application that uses WCF web services to allow a Flex front end to access the database.
I’m in the process of setting up some unit/integration style testing on the web services and am trying to work out the best way to allow the tests to access and modify data in a separate test database.
Currently, the connection string in my unit test project points to my testing database, and the connection string in my web services project points to my development database. However, as I am using Linq it appears that when I call the web service methods from my test class, it uses the development database connection string.
I have looked into creating mock objects or in-memory database but I believe the same issue would occur.
Is there a way to get this to work, or is my entire idea about what I want incorrect, in which case is there a better way to set this up? I’m still early enough in my project that I’m not adverse to significantly changing the architecture of the solution.
Make sure the code in the web service is minimal and not much more than a simple call to your service layer. When you do that you can skip calling the web service directly, and create an integration test suite that also calls your service layer. In that case you are doing an in-process call instead of an call over the network. In that situation it will be much easier to ensure the right database is accessed and you can easily wrap those calls with database transactions that will be rolled back. You certainly want to rollback any actions to the database, because it will be very hard to maintain RTM tests. One way to do this is by using TransactionScope inside tests.
Good luck.