-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for using a test connection string.
- Loading branch information
Showing
3 changed files
with
32 additions
and
6 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
TrackableEntities.EF.Core.Tests/Helpers/DbContextOptionsHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
|
||
using Microsoft.Data.SqlClient; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace TrackableEntities.EF.Core.Tests.Helpers | ||
{ | ||
public static class DbContextOptionsHelper | ||
{ | ||
public static DbContextOptions<TContext> GetContextOptions<TContext>(string initialCatalog) | ||
where TContext : DbContext | ||
{ | ||
// default connection string for tests 'LocalDb' | ||
var connectionString = | ||
@"Data Source=(localdb)\MSSQLLocalDB; Initial Catalog=FamilyTest; Integrated Security=True; MultipleActiveResultSets=True"; | ||
|
||
if (Environment.GetEnvironmentVariable("ConnectionString") != null) | ||
{ | ||
// LocalDb isn't supported in Linux. To support running tests, allow env variable for conn string | ||
connectionString = Environment.GetEnvironmentVariable("ConnectionString"); | ||
} | ||
|
||
var builder = new SqlConnectionStringBuilder(connectionString) { InitialCatalog = initialCatalog }; | ||
|
||
return new DbContextOptionsBuilder<TContext>() | ||
.UseSqlServer(builder.ConnectionString) | ||
.Options; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters