Mock a PART of EF DbContext with Moq and/or InMemoryDbSetMocking EF DbContext with MoqHow to verify that method was NOT called in Moq?How to mock the Request on Controller in ASP.Net MVC?My Mocked DbContext writes to db in Unit Test using MoqMoq mocked DbContext returns null ObjectContextCreate mock based on existed real instanceMocking model collections in EntityFramework and MoqMocked DbContext update method error - A network-related or instance-specific error occurred while establishing a connection to SQL ServerSetting up mock objects for EF dbcontext to test repository methodsMock an Entity DbContext InsertCorrect way for testing services that using DBContext?

How dangerous is XSS

Sums of two squares in arithmetic progressions

Are British MPs missing the point, with these 'Indicative Votes'?

Can a virus destroy the BIOS of a modern computer?

How do conventional missiles fly?

How does a dynamic QR code work?

How badly should I try to prevent a user from XSSing themselves?

Could neural networks be considered metaheuristics?

What is the fastest integer factorization to break RSA?

How to install cross-compiler on Ubuntu 18.04?

Placement of More Information/Help Icon button for Radio Buttons

What is required to make GPS signals available indoors?

How obscure is the use of 令 in 令和?

How to Prove P(a) → ∀x(P(x) ∨ ¬(x = a)) using Natural Deduction

Do Iron Man suits sport waste management systems?

How can I deal with my CEO asking me to hire someone with a higher salary than me, a co-founder?

Different meanings of こわい

Why are UK visa biometrics appointments suspended at USCIS Application Support Centers?

How seriously should I take size and weight limits of hand luggage?

How to compactly explain secondary and tertiary characters without resorting to stereotypes?

How to coordinate airplane tickets?

How can I prove that a state of equilibrium is unstable?

Car headlights in a world without electricity

Finitely generated matrix groups whose eigenvalues are all algebraic



Mock a PART of EF DbContext with Moq and/or InMemoryDbSet


Mocking EF DbContext with MoqHow to verify that method was NOT called in Moq?How to mock the Request on Controller in ASP.Net MVC?My Mocked DbContext writes to db in Unit Test using MoqMoq mocked DbContext returns null ObjectContextCreate mock based on existed real instanceMocking model collections in EntityFramework and MoqMocked DbContext update method error - A network-related or instance-specific error occurred while establishing a connection to SQL ServerSetting up mock objects for EF dbcontext to test repository methodsMock an Entity DbContext InsertCorrect way for testing services that using DBContext?













1















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!










share|improve this question






















  • 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 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 at 20:52











  • I'm voting to close this question as off-topic because I feel it is a better fit at softwareengineering.stackexchange.com/help/on-topic

    – Jasen
    Mar 22 at 1:00















1















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!










share|improve this question






















  • 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 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 at 20:52











  • I'm voting to close this question as off-topic because I feel it is a better fit at softwareengineering.stackexchange.com/help/on-topic

    – Jasen
    Mar 22 at 1:00













1












1








1








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!










share|improve this question














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!







c# entity-framework integration-testing moq






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 21 at 20:37









Konstantin KonstantinovKonstantin Konstantinov

48729




48729












  • 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 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 at 20:52











  • I'm voting to close this question as off-topic because I feel it is a better fit at softwareengineering.stackexchange.com/help/on-topic

    – Jasen
    Mar 22 at 1:00

















  • 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 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 at 20:52











  • I'm voting to close this question as off-topic because I feel it is a better fit at softwareengineering.stackexchange.com/help/on-topic

    – Jasen
    Mar 22 at 1:00
















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 at 20:41





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 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 at 20:52





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 at 20:52













I'm voting to close this question as off-topic because I feel it is a better fit at softwareengineering.stackexchange.com/help/on-topic

– Jasen
Mar 22 at 1:00





I'm voting to close this question as off-topic because I feel it is a better fit at softwareengineering.stackexchange.com/help/on-topic

– Jasen
Mar 22 at 1:00












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55288867%2fmock-a-part-of-ef-dbcontext-with-moq-and-or-inmemorydbset%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55288867%2fmock-a-part-of-ef-dbcontext-with-moq-and-or-inmemorydbset%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript