public static void AssemblyInit(TestContext context) { const string connectionStringName = "ProductContext"; CreateTestDatabase.TestDatabase.Create(connectionStringName); //optional - run Entity Framework migrations var migrate = new MigrateDatabaseToLatestVersion<ProductContext, Configuration>(connectionStringName); using (var dbContext = new ProductContext()) { migrate.InitializeDatabase(dbContext); } }
public void TestMethod() { //no special code, because we used AssemblyInitialize using (var context = new ProductContext()) { var banana = new Product { Name = "Banana", PricePerUnit = 1 }; context.Products.Add(banana); context.SaveChanges(); var con = context.Database.Connection; Assert.AreEqual("(LocalDB)\\MSSQLLocalDB", con.DataSource); Assert.AreEqual("TestProductContext", con.Database); } }