I'm trying to configure EntityFramework for integration tests in an MSTest Project, normally I might configure my project through my startup like so:
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddApplicationInsightsTelemetry(Configuration);
var defaultConnectionString = Configuration.GetConnectionString("DefaultConnection");
services.AddEntityFrameworkSqlServer()
.AddDbContext<AstootContext>(options =>
options.UseSqlServer(defaultConnectionString))
.AddDbContext<PublicAstootContext>(options =>
options.UseSqlServer(defaultConnectionString));
//...
}
My testing project looks like so:
[TestClass]
public class UnitTest1 : ServiceTestBase
{
string ConnectionString = @"Data Source=.\SQLEXPRESS;
AttachDbFilename=C:\source\Astoot\RestEzCore.Tests\TestDB\NORTHWND.MDF;
Integrated Security=True;
Connect Timeout=30;
User Instance=True";
[TestInitialize]
public void RegisterTestModules
{
}
[TestMethod]
public void TestMethod1()
{
}
}
How can I reuse the same dependency injection my webapi project uses and so configure my tests in a similar fashion.