This repository has been archived by the owner on Nov 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify setup of a SQL database for unit tests
Using the LocalDb NuGet package makes it very easy to setup a test database. With the connection string from the App.config file I would get an exception: > System.Data.SqlClient.SqlException > A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.)
- Loading branch information
Showing
10 changed files
with
48 additions
and
47 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using LocalDb; | ||
|
||
namespace Dapper.NodaTime.Tests | ||
{ | ||
public class DatabaseFixture : IDisposable | ||
{ | ||
private readonly SqlInstance _sqlInstance; | ||
private readonly SqlDatabase _database; | ||
|
||
public DatabaseFixture() | ||
{ | ||
_sqlInstance = new SqlInstance(name: "Dapper.NodaTime.Tests", buildTemplate: _ => Task.CompletedTask); | ||
_database = _sqlInstance.Build("DapperNodaTimeTests").Result; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_database.Dispose(); | ||
_sqlInstance.Cleanup(); | ||
} | ||
|
||
public string ConnectionString => _database.ConnectionString; | ||
} | ||
} |
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
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
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
Binary file not shown.
Binary file not shown.