public static void CreateTestDatabase(Type dataContextType) { if (IsSqlServer(dataContextType)) { MsSqlTestHelper.CreateTestDatabase(TestContext.CurrentContext.Test.FullName); } else if (IsMySql(dataContextType)) { MySqlTestHelper.CreateTestDatabase(TestContext.CurrentContext.Test.FullName); } else if (IsSqlite(dataContextType)) { SqliteTestHelper.CreateTestDatabase(TestContext.CurrentContext.Test.FullName); } }
public static IDataContext SetupDataContext( Type dataContextType, ITableNameResolver tableNameResolver = null, IColumnNameResolver columnNameResolver = null) { // check whether we are dealing with a type that implement IDataContext if (!IsDataContext(dataContextType)) { throw new ArgumentException($"Type {dataContextType.Name} does not implement IDataContext."); } // return the data context for the given type if (IsInMemory(dataContextType)) { return(new InMemoryDataContext()); } else if (IsSqlServer(dataContextType)) { MsSqlTestHelper.CreateTestDatabase(TestContext.CurrentContext.Test.FullName); return(new SqlServerDataContext( MsSqlTestHelper.GetTestConnectionString(TestContext.CurrentContext.Test.FullName), tableNameResolver ?? new DefaultTableNameResolver(), columnNameResolver ?? new DefaultColumnNameResolver())); } else if (IsMySql(dataContextType)) { MySqlTestHelper.CreateTestDatabase(TestContext.CurrentContext.Test.FullName); return(new MySqlDataContext( MySqlTestHelper.GetTestConnectionString(TestContext.CurrentContext.Test.FullName), tableNameResolver ?? new DefaultTableNameResolver(), columnNameResolver ?? new DefaultColumnNameResolver())); } else if (IsSqlite(dataContextType)) { SqliteTestHelper.CreateTestDatabase(TestContext.CurrentContext.Test.FullName); return(new SqliteDataContext( SqliteTestHelper.GetTestConnectionString(TestContext.CurrentContext.Test.FullName), tableNameResolver ?? new DefaultTableNameResolver(), columnNameResolver ?? new DefaultColumnNameResolver())); } else { throw new ArgumentException($"Type {dataContextType} is not supported, add support in {nameof(Helpers.DataContextTestHelper)}.cs"); } }