Last active
November 16, 2017 14:00
-
-
Save duncansmart/f28ae2940c7ef08aa6bb to your computer and use it in GitHub Desktop.
EF DbContext setup/teardown for tests
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
[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