1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace System.Data.Entity.Migrations
{
using System.Collections.Generic;
using System.Data.Entity.Migrations.Design;
public class DatabaseProviderFixture
{
public const string DefaultDatabaseName = "MigrationsTest";
private readonly Dictionary<DatabaseProvider, TestDatabase> _testDatabases = new Dictionary<DatabaseProvider, TestDatabase>();
private readonly Dictionary<ProgrammingLanguage, MigrationCodeGenerator> _codeGenerators =
new Dictionary<ProgrammingLanguage, MigrationCodeGenerator>();
private readonly Dictionary<ProgrammingLanguage, MigrationCompiler> _migrationCompilers =
new Dictionary<ProgrammingLanguage, MigrationCompiler>();
public DatabaseProviderFixture()
{
foreach (DatabaseProvider provider in Enum.GetValues(typeof(DatabaseProvider)))
{
_testDatabases[provider] = InitializeTestDatabase(provider, DefaultDatabaseName);
}
_testDatabases[DatabaseProvider.SqlClient] = InitializeTestDatabase(DatabaseProvider.SqlClient, DefaultDatabaseName);
_codeGenerators[ProgrammingLanguage.CSharp] = new CSharpMigrationCodeGenerator();
_migrationCompilers[ProgrammingLanguage.CSharp] = new MigrationCompiler("cs");
;
_codeGenerators[ProgrammingLanguage.VB] = new VisualBasicMigrationCodeGenerator();
_migrationCompilers[ProgrammingLanguage.VB] = new MigrationCompiler("vb");
}
public Dictionary<DatabaseProvider, TestDatabase> TestDatabases
{
get { return _testDatabases; }
}
public Dictionary<ProgrammingLanguage, MigrationCodeGenerator> CodeGenerators
{
get { return _codeGenerators; }
}
public Dictionary<ProgrammingLanguage, MigrationCompiler> MigrationCompilers
{
get { return _migrationCompilers; }
}
public static TestDatabase InitializeTestDatabase(DatabaseProvider provider, string databaseName)
{
TestDatabase testDatabase;
switch (provider)
{
case DatabaseProvider.SqlClient:
testDatabase = new SqlTestDatabase(databaseName);
break;
case DatabaseProvider.SqlServerCe:
testDatabase = new SqlCeTestDatabase(databaseName);
break;
default:
throw new InvalidOperationException("Unsupported provider");
}
testDatabase.EnsureDatabase();
return testDatabase;
}
}
}
|