C
C#2y ago
OukiShogun

❔ Which database for integration test using db transactions

Hi there, I am coding my integration test project. And I want to test the transactionnal aspect of two functions called. I installed sqllite inmemory on my project. And set it in memory I well mocked my the last function called before the commit and do a .throw(new Exception()); and context.rollbackTransaction() in the catch. But I get a "no such table : Buy" when I run my test. I don't understand why I will have to do migration on a inmemory database. For me, it's a no-sense. So, what do you advise me to use for my test ? in prod I use sql server
8 Replies
Angius
Angius2y ago
Use SQL Server for integration tests as well, then
Insire
Insire2y ago
your sqlite db still needs tables and you need to keep a connection to the sqlite db open if its in memory, or it will be gone, when you open another connection
OukiShogun
OukiShogunOP2y ago
So, how to apply migration to an in-memo sqllite db. If my migrations are in another project. And that my integration test project doesn't have appsetting.... then ? ^^
Insire
Insire2y ago
no idea how appsettings are relevant to this. but you apply migrations as you usually do, by pointing ef core at the assembly to use
Insire
Insire2y ago
OukiShogun
OukiShogunOP2y ago
Because , i was thinking that dotnet ef update database read the C# code who read a string connection but may be it works with the 'var connection = new SqliteConnection("DataSource=:memory:");'
Insire
Insire2y ago
do you understand what the memory bit means? it means, as soon as all connection to that database are closed, the database will be gone tldr: once your update command completes, your sqlite db will be gone
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.

Did you find this page helpful?