Skip to content

How to mock Database Access #385

Answered by paillave
mlholt03 asked this question in Q&A
Discussion options

You must be logged in to vote

About mocking and unit tests, the solutions are the same than the ones you use for regular NET development.
At the moment, no there is no such things like SqlCommandValueProvider that returns data without querying the database. The ways you can do are the ones described in here:
https://learn.microsoft.com/en-us/ef/core/testing/testing-without-the-database?source=recommendations

EF core In memory provider

https://learn.microsoft.com/en-us/ef/core/testing/testing-without-the-database?source=recommendations#in-memory-provider

Instead of injecting a DbContext that uses SQL Server, you inject a DBContext setup to work in memory instead

SQL Lite in memory

https://learn.microsoft.com/en-us/ef/c…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by paillave
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants