-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
24 additions
and
17 deletions.
There are no files selected for viewing
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
30 changes: 20 additions & 10 deletions
30
tests/Filter.Tests/Generic/Integration/DatabaseFixture.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 |
---|---|---|
@@ -1,25 +1,35 @@ | ||
using System; | ||
using System.Threading; | ||
using RimDev.Automation.Sql; | ||
using RimDev.Filter.Tests.Extensions; | ||
using System.Data.Common; | ||
using System.Data.SqlLocalDb; | ||
|
||
namespace RimDev.Filter.Tests.Generic.Integration | ||
{ | ||
public sealed class DatabaseFixture : IDisposable | ||
public class DatabaseFixture : IDisposable | ||
{ | ||
private readonly Lazy<LocalDb> lazyDatabase; | ||
private readonly Lazy<TemporarySqlLocalDbInstance> lazyInstance; | ||
|
||
public DatabaseFixture() | ||
{ | ||
lazyDatabase = new Lazy<LocalDb>( | ||
() => new LocalDb(version: "v13.0"), LazyThreadSafetyMode.ExecutionAndPublication); | ||
lazyInstance = new Lazy<TemporarySqlLocalDbInstance>( | ||
() => TemporarySqlLocalDbInstance.Create(true)); | ||
} | ||
|
||
public string ConnectionString => lazyDatabase.Value.ConnectionString; | ||
|
||
public DbConnectionStringBuilder CreateConnectionStringBuilder() | ||
{ | ||
var instance = lazyInstance.Value; | ||
|
||
var builder = lazyInstance.Value.CreateConnectionStringBuilder(); | ||
builder.SetInitialCatalogName(Guid.NewGuid().ToString("N")); | ||
|
||
return builder; | ||
} | ||
|
||
public string ConnectionString => CreateConnectionStringBuilder().ConnectionString; | ||
|
||
public void Dispose() | ||
{ | ||
lazyDatabase.Dispose(); | ||
if (lazyInstance.IsValueCreated) | ||
lazyInstance.Value.Dispose(); | ||
} | ||
} | ||
} |
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