C
C#4w ago
JellyRekt

Xunit and database projects

I'm trying to write some integration tests and am having a little trouble setting up the database. I have imported my database as a SQL Server project to my solution and added a project reference from my test project to the database project. I expected that would place the dacpac in the test project's build output directory, but that's not the case. The dacpac is in the database project's build output directory, but only a dll and pdb in the test project's. I need the path to the dacpac so I can programmatically deploy it to the test environment when tests run. Seems to me I should be able to get it in the test project's output directory, but if there is another/a better way to do this, please lmk!
4 Replies
Becquerel
Becquerel4w ago
i recently set up integration tests for a database project in CI i just built the database project as its own step, and then copied the .dacpac file to a known location that my other apps could then access (the solution root i think) you could potentially also do this with an msbuild task/option on the dotnet build command, but i've not looked into that another approach, probably better, is to use testcontainers build the database project once to generate a .sql for the schema, put that .sql wherever you want run it into your container on startup downside is you need to remember to regenerate the schema .sql when your database changes
JellyRekt
JellyRekt4w ago
Thanks, this is exactly the kind of answer that I was looking for. Probably gonna go with copying out the dacpac to a known location
Becquerel
Becquerel4w ago
glhf, getting proper integration tests set up was a gamechanger for me
JellyRekt
JellyRekt4w ago
tell me about it. my teammates wrote some "unit tests" that just use data from our development database, which gets regularly restored from prod. so we don't have stable test cases, things change and move around and cause tests to fail. i've been pushing for this for a long time
Want results from more Discord servers?
Add your server