Created
October 23, 2015 21:40
-
-
Save sdanna/e22bc99a7ebb59273eae to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using System; | |
using System.IO; | |
using Zomg.DAL; | |
namespace IntegrationTests.Fixtures | |
{ | |
public class DbFixture<T> : IDisposable | |
{ | |
private readonly string _connectionString; | |
public ApplicationDbContext Context { get; private set; } | |
public DbFixture() | |
{ | |
var typeOfT = GetType().UnderlyingSystemType.GenericTypeArguments[0].FullName.Replace(".", "_"); | |
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AppData"); | |
AppDomain.CurrentDomain.SetData("DataDirectory", path); | |
if (Directory.Exists(path) == false) | |
Directory.CreateDirectory(path); | |
_connectionString = String.Format(@"Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\Zomg-{0}.mdf;Integrated Security=True;MultipleActiveResultSets=True", typeOfT); | |
Context = new ApplicationDbContext(_connectionString); | |
} | |
public void Dispose() | |
{ | |
Context.Database.Connection.Close(); | |
Context.Database.Delete(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment