Long did I hold this perception that integration tests are hard. With EF core, they are actually really easy. Instead of using SQL Sever, we can substitute with LocalDB. Run this before running the tests and you'll have your db setup. After calling EnsureCreated
you can add things into the database.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
public static DataContext Create() { var options = new DbContextOptionsBuilder<DataContext>() .UseSqlServer("Server=(localdb)\mssqllocaldb;Database=testDB;Trusted_Connection=True;MultipleActiveResultSets=true") .Options; var context = new DataContext(options); context.Database.EnsureCreated(); // ADD Test Data return context; } |