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?
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.
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.
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 separatelyget
orcreate
workflows in some other tests. However, if I testget or create
workflow, then with the real DB I can only testcreate
part of workflow once but then I will only hit aget
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 InMemoryDbSet
s
Thanks a lot!
c# entity-framework integration-testing moq
add a comment |
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.
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.
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 separatelyget
orcreate
workflows in some other tests. However, if I testget or create
workflow, then with the real DB I can only testcreate
part of workflow once but then I will only hit aget
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 InMemoryDbSet
s
Thanks a lot!
c# entity-framework integration-testing moq
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
add a comment |
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.
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.
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 separatelyget
orcreate
workflows in some other tests. However, if I testget or create
workflow, then with the real DB I can only testcreate
part of workflow once but then I will only hit aget
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 InMemoryDbSet
s
Thanks a lot!
c# entity-framework integration-testing moq
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.
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.
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 separatelyget
orcreate
workflows in some other tests. However, if I testget or create
workflow, then with the real DB I can only testcreate
part of workflow once but then I will only hit aget
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 InMemoryDbSet
s
Thanks a lot!
c# entity-framework integration-testing moq
c# entity-framework integration-testing moq
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
add a comment |
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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