SQL Server integration testing using xUnit

Recently I wanted to verify that my data access layer could properly read and write to a SQL Server database, and I wanted to have these tests automated. I wanted to answer these questions: Can my DbContext roundtrip entities to the database and back? Does the schema in my migration scripts match the expected schema in my code? (follows from 1) Can my migration scripts be applied to the database correctly? …

Authorizing Managed Service Identity in Azure SQL Database

When trying to deploy a simple web application and Azure SQL database through Azure DevOps pipelines, I wanted to use a system managed application identity to authorize the web application to access the database. This requires running something like the following SQL script on the Azure SQL database. CREATE USER [<identity-name>] FROM EXTERNAL PROVIDER; ALTER ROLE db_datareader ADD MEMBER [<identity-name>]; ALTER ROLE db_datawriter ADD MEMBER [<identity-name>]; ALTER ROLE db_ddladmin ADD MEMBER [<identity-name>]; I was having a lot of trouble getting the Azure SqlCmd task to work, while the error(s) it was showing was not helpful at all. …