0

This question is NOT about what's here: Mocking EF DbContext with Moq and/or similar questions. I am well aware of that. Please, read the question before replying. Thanks.

  1. We have a fairly complicated database, which has some, call them, "business objects" and some, call them, "data objects". The "business objects" are usually created or updated with every new user request and the "data objects" are fairly stable but may be occasionally created during user request if missing at the first call.

  2. I want to create integration tests in the sand box where I could pull the data objects out of the real database (because there are too many of them to mock) but control what happens with the business objects. For example, if I have a get or create workflow (with some validation, of course), then I want explicitly test that whole workflow after testing separately get or create workflows in some other tests. However, if I test get or create workflow, then with the real DB I can only test create part of workflow once but then I will only hit a get workflow (because the object will exist after the first test run). Throw in that many tests are routinely run in parallel and the results become unpredictable.

I wonder what is the proper approach to perform a partial "mock" of a database context where most of the tables would come from the real DB but a few tables could be setup per test, e.g. in InMemoryDbSets

Thanks a lot!

  • One common set of terms used to make a distinction between these types of data is: Transactional data vs. Operational data. – David Tansey Mar 21 '19 at 20:41
  • 1. The database is already there and I don't control what objects are in it. 2. The line between business objects and data objects is blurry: when I create a completely "new" business object, some "data objects" will be created, but just once. Subsequent user calls with the same "key" value will pull the same "data objects" but may create / update / "mark as deleted" business objects. 3. The worst part is that there are many other "completely static" objects, which are never updated due to user actions but they do, unfortunately, reside in the same DB. And, of course, I need them as well. – Konstantin Konstantinov Mar 21 '19 at 20:52
  • I'm voting to close this question as off-topic because I feel it is a better fit at https://softwareengineering.stackexchange.com/help/on-topic – Jasen Mar 22 '19 at 01:00

0 Answers0