0

My work has various .Net C# classes to perform discrete actions (i.e. get items in user's shopping cart, get list of products available, etc). I am looking to added unit tests to these classes/methods using Visual Studio unit test projects. My goal is to have the unit tests self contained where they do not depend on an external database. So I started investigating SQLite. I'm thinking each unit test will create it's own "mock" database to be used by the corresponding classes/methods that the unit test is executing.

Here is the problem I am running into. The real classes/methods execute SQL with fully qualified (guess that is the right term) database names and schemas as part of the query. Example:

SELECT * FROM Database01.Schema01.Table01

In SQLite is there a way to make it work with these type of table references? I see there is an ATTACH command where you can attach multiple databases to one connection. Then you reference a table with database-name.table-name. That is still missing the middle schema part though. Any thoughts?

1
  • 1
    A unit test should not need a database at all. Show an example of a method you'd like to test in order to get advice on restructuring your code. Also hardcoding database names sounds like a badly maintainable idea. I guess it's too late in the project to switch to an ORM? Commented May 15, 2014 at 22:54

1 Answer 1

0

If that code does not take care to quote database/schema names correctly, you could name the database [Database01.Schema01] and then tell that code that the database is called [Database01, and the schema, Schema01].

If your code is too smart for that, or if the database/schema names are fixed, then there is nothing you can do with SQLite.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.