Skip to content

Instantly share code, notes, and snippets.

@shawnmclean
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shawnmclean/58217a22ade86acd3866 to your computer and use it in GitHub Desktop.
Save shawnmclean/58217a22ade86acd3866 to your computer and use it in GitHub Desktop.
Base Test class for integration testing WebAPI
[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