Skip to content

Instantly share code, notes, and snippets.

@duncansmart
Last active November 16, 2017 14:00
Show Gist options
  • Save duncansmart/f28ae2940c7ef08aa6bb to your computer and use it in GitHub Desktop.
Save duncansmart/f28ae2940c7ef08aa6bb to your computer and use it in GitHub Desktop.
EF DbContext setup/teardown for tests
[TestFixture]
public class FooController_Tests
{
FooDbContext _dbContext = new FooDbContext(@"SERVER=(localdb)\v11.0; DATABASE=FooControllerTests_"+ Guid.NewGuid().ToString("n"));
[TestFixtureSetUp]
public void Setup()
{
_dbContext.Database.CreateIfNotExists();
}
[TestFixtureTearDown]
public void TearDown()
{
_dbContext.Database.Delete();
}
// Tests ....
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment