Last active
August 29, 2015 14:05
-
-
Save shawnmclean/58217a22ade86acd3866 to your computer and use it in GitHub Desktop.
Base Test class for integration testing WebAPI
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
[TestClass] | |
public class TestBase | |
{ | |
private static TestServer server; | |
public static TestServer Server | |
{ | |
get { return server; } | |
} | |
[AssemblyInitialize] | |
public static void Initialize(TestContext context) | |
{ | |
server = TestServer.Create<Startup>(); | |
} | |
[AssemblyCleanup] | |
public static void CleanUp() | |
{ | |
server.Dispose(); | |
} | |
[TestInitialize] | |
public void BaseTestInit() | |
{ | |
cleanupDatabase(); | |
seedDatabase(); | |
} | |
private static void cleanupDatabase() | |
{ | |
// Cleanup databases by deleting it | |
var db = new EntityDatabaseContext(); | |
if (db.Database.Exists()) | |
{ | |
db.Database.Delete(); | |
} | |
} | |
private static void seedDatabase() | |
{ | |
var db = new EntityDatabaseContext(); | |
// If you check against an API Key that is stored in SQL Server, seed it here. | |
db.ApiApplications.Add(new ApiApplication | |
{ | |
ApiKey = Guid.Parse(Constants.API_KEY) | |
}); | |
db.SaveChanges(); | |
} | |
/// <summary> | |
/// So that the test runner copies dlls not directly referenced by the integration project | |
/// </summary> | |
private void referenceLibs() | |
{ | |
var useless = SqlProviderServices.Instance; | |
var useless1 = SqlCeProviderServices.Instance; | |
var useless2 = Content.Culture; | |
var useless3 = new JsonSerializer(); | |
var useless4 = new StorageException(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment