-
If I am access a database using this tool, and I wish to write unit tests for the code I am writing, how can I mock out the database access such that my unit test is not actually attempting to connect to a database? Is there some way to provide a |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
About mocking and unit tests, the solutions are the same than the ones you use for regular NET development. EF core In memory providerInstead of injecting a DbContext that uses SQL Server, you inject a DBContext setup to work in memory instead SQL Lite in memoryInstead of injecting a DbContext that uses SQL Server, you inject a DBContext setup to work with SQL lite by giving a connecting string that is setup to work in memory. RepositoryIn the same way you inject a DbConnection or a DbContext into ETL.NET, you can inject anything you want (Services or Repositories for instance). Then, within your process, you can use what was injected by using If you have a business layer that you want to reuse within a stream, this is the way to go. FYI: I change this conversation into an issue to remind me to improve the documentation regarding DI in processes |
Beta Was this translation helpful? Give feedback.
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…