https://github.com/karenpayneoregon/entityframeworkcoreinmemorytesting
Examples for InMemory testing with EF Core
https://github.com/karenpayneoregon/entityframeworkcoreinmemorytesting
csharp dependency-injection efcore unit-testing
Last synced: about 2 months ago
JSON representation
Examples for InMemory testing with EF Core
- Host: GitHub
- URL: https://github.com/karenpayneoregon/entityframeworkcoreinmemorytesting
- Owner: karenpayneoregon
- Created: 2019-08-19T20:21:46.000Z (almost 7 years ago)
- Default Branch: Version2021
- Last Pushed: 2022-12-27T15:02:09.000Z (over 3 years ago)
- Last Synced: 2025-03-23T18:17:26.137Z (over 1 year ago)
- Topics: csharp, dependency-injection, efcore, unit-testing
- Language: C#
- Homepage:
- Size: 274 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
### Entity Framework Core 2x InMemory unit testng for windows forms
:green_circle: Code samples showing basics of in memory unit testing
# Solution structure
There was a mishap when performing an experiment which messed up where several projects got created. Even so, all code works as expected. To fix the folder structure would require more work than any benefits so the folder structure remains as is.
### Dependency injection
While in `ASP.NET` in memory test is rather easy as dependency injection is done in Startup.cs in ConfigureServices there is no configure service event in windows forms so developers must using a library such as [Simple Injector](https://simpleinjector.readthedocs.io/en/latest/index.html) to setup dependence injection as done in SimpleInjectorWindowsForms1 windows form project.
Simple Injector was picked from a handfull of open source libaries which means if a developer has a go to dependence injection library then replace Simple Injector with that one.
### Unit test
All unit test use [InMemory data provider](https://docs.microsoft.com/en-us/ef/core/providers/in-memory/). `SqlLite` is used in several examples.
### Important
EF�s in-memory database `isn�t a relational database` so it does not `enforce constaints` that a real database would.
A bit slower and more work to setup but is a real database consider SQLLite In-Memory.
# Tidbits
[How can I reset an EF7 InMemory provider between unit tests?](https://stackoverflow.com/questions/33490696/how-can-i-reset-an-ef7-inmemory-provider-between-unit-tests)