Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TDD: Does EF Core In Memory Provider validates referential constraints?

I'm really excited about in memory feature of EF Core for unit testing. It relieves me of the burden to write dedicated repository, just for the sake of making code unit testable. But merely in memory testing in a collection wont't suffice.

Does EF Core In Memory Provider validates referential constraints?

like image 769
Abhijeet Avatar asked Jun 23 '18 09:06

Abhijeet


1 Answers

Does EF Core In Memory Provider validates referential constraints?

The answer is: No.

InMemory provider is not a replacement for relational database. It is created for testing purpose.

Excerpt from the documenation:

InMemory is designed to be a general purpose database for testing, and is not designed to mimic a relational database. Some examples of this include:

  • InMemory will allow you to save data that would violate referential integrity constraints in a relational database.

  • If you use DefaultValueSql(string) for a property in your model, this is a relational database API and will have no effect when running against InMemory.

The first point spot that any constraint is not validated by the provider.

like image 159
CodeNotFound Avatar answered Oct 19 '22 07:10

CodeNotFound