C
C#16mo 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
Angius16mo ago
Use SQL Server for integration tests as well, then
Insire
Insire16mo 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
OukiShogunOP16mo 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
Insire16mo 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
Insire16mo ago
OukiShogun
OukiShogunOP16mo 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
Insire16mo 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
Accord16mo 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.
Want results from more Discord servers?
Add your server