This library can be used to create a temporary database that can be used for testing and then dropped once the tests are complete. Currently, only LocalDb is supported. The code attempts to connect to LocalDb on localhost.
Install the Nuget package and write the following code:
using System;
using TemporaryDb;
public class Program
{
public static void Main(string[] args)
{
using (var db = new TempLocalDb("testdb"))
{
UseTheDatabase(db.ConnectionString);
}
}
}