public void SimpleMappingResolverTest() { var domainConfiguration = DomainConfigurationFactory.Create(); domainConfiguration.UpgradeMode = DomainUpgradeMode.Recreate; domainConfiguration.Types.Register(typeof(model.Part1.TestEntity1).Assembly, typeof(model.Part1.TestEntity1).Namespace); using (var domain = Domain.Build(domainConfiguration)) { var node = domain.StorageNodeManager.GetNode(WellKnown.DefaultNodeId); var nodeConfiguration = node.Configuration; DefaultSchemaInfo defaultSchemaInfo; using (var connection = driver.CreateConnection()) { connection.Open(); defaultSchemaInfo = driver.GetDefaultSchema(connection); } var mappingResolver = MappingResolver.Create(domainConfiguration, nodeConfiguration, defaultSchemaInfo); Assert.That(mappingResolver, Is.InstanceOf <SimpleMappingResolver>()); var metadataExtactionTasks = mappingResolver.GetMetadataTasks(); Assert.That(metadataExtactionTasks.Count(), Is.EqualTo(1)); Assert.That(metadataExtactionTasks.First().Catalog, Is.EqualTo(defaultSchemaInfo.Database)); Assert.That(metadataExtactionTasks.First().Schema, Is.EqualTo(defaultSchemaInfo.Schema)); var schemaExtractionTasks = mappingResolver.GetSchemaTasks(); Assert.That(schemaExtractionTasks.SequenceEqual(metadataExtactionTasks)); SchemaExtractionResult extractionResult; using (var connection = driver.CreateConnection()) { connection.Open(); extractionResult = new SchemaExtractionResult(driver.Extract(connection, mappingResolver.GetSchemaTasks())); } var fullName = mappingResolver.GetNodeName("dummy", "dummy", "Table1"); Assert.That(fullName.ToLower(), Is.EqualTo("Table1".ToLower())); fullName = mappingResolver.GetNodeName(extractionResult.Catalogs.First().DefaultSchema.Tables["TestEntity1"]); Assert.That(fullName.ToLower(), Is.EqualTo("TestEntity1".ToLower())); var typeInfo = domain.Model.Types[typeof(model.Part1.TestEntity1)]; fullName = mappingResolver.GetNodeName(typeInfo); Assert.That(fullName.ToLower(), Is.EqualTo("TestEntity1".ToLower())); var sequence = typeInfo.Hierarchy.Key.Sequence; fullName = mappingResolver.GetNodeName(sequence); Assert.That(fullName.ToLower(), Is.EqualTo(sequence.MappingName.ToLower())); var schema = mappingResolver.ResolveSchema(extractionResult, defaultSchemaInfo.Database, defaultSchemaInfo.Schema); Assert.That(schema, Is.EqualTo(extractionResult.Catalogs.First().DefaultSchema)); var resolveResult = mappingResolver.Resolve(extractionResult, typeInfo.MappingName); Assert.That(resolveResult.Name, Is.EqualTo(typeInfo.MappingName)); Assert.That(resolveResult.Schema, Is.EqualTo(extractionResult.Catalogs.Single().DefaultSchema)); Assert.That(resolveResult.GetTable(), Is.EqualTo(extractionResult.Catalogs.Single().DefaultSchema.Tables["TestEntity1"])); resolveResult = mappingResolver.Resolve(extractionResult, sequence.MappingName); Assert.That(resolveResult.Name, Is.EqualTo(sequence.MappingName)); Assert.That(resolveResult.Schema, Is.EqualTo(extractionResult.Catalogs.Single().DefaultSchema)); } }
private void ClearSchema(SqlDriver driver) { using (var connection = driver.CreateConnection()) { connection.Open(); try { var schema = driver.ExtractSchema(connection, SpecialSchemaAlias); var foreignKeys = schema.Tables .Select(t => new { Table = t, ForeignKeys = t.TableConstraints.OfType <ForeignKey>() }); foreach (var dropConstraintText in from foreignKeyInfo in foreignKeys from foreignKey in foreignKeyInfo.ForeignKeys select driver.Compile(SqlDdl.Alter(foreignKeyInfo.Table, SqlDdl.DropConstraint(foreignKey))).GetCommandText()) { using (var command = connection.CreateCommand(dropConstraintText)) command.ExecuteNonQuery(); } foreach (var table in schema.Tables) { var dropTableText = driver.Compile(SqlDdl.Drop(table, true)).GetCommandText(); using (var command = connection.CreateCommand(dropTableText)) command.ExecuteNonQuery(); } } finally { connection.Close(); } } }
public void MainTest() { SchemaExtractionResult extractionResult; using (var connection = driver.CreateConnection()) { connection.Open(); var defaultSchema = driver.ExtractDefaultSchema(connection); extractionResult = new SchemaExtractionResult(); extractionResult.Catalogs.Add(defaultSchema.Catalog); } Assert.That(extractionResult.IsShared, Is.False); Assert.DoesNotThrow(() => { var name = extractionResult.Catalogs.First().Name; }); Assert.DoesNotThrow(() => { var name = extractionResult.Catalogs.First().DbName; }); Assert.DoesNotThrow(() => { var name = extractionResult.Catalogs.First().DefaultSchema.Name; }); Assert.DoesNotThrow(() => { var name = extractionResult.Catalogs.First().DefaultSchema.DbName; }); Assert.DoesNotThrow(() => { var name = extractionResult.Catalogs.First().DefaultSchema.Tables["Product"].Name; }); Assert.DoesNotThrow(() => { var name = extractionResult.Catalogs.First().DefaultSchema.Tables["Product"].DbName; }); extractionResult.MakeShared(); Assert.That(extractionResult.IsShared, Is.True); Assert.Throws <InvalidOperationException>(() => { var name = extractionResult.Catalogs.First().Name; }); Assert.Throws <InvalidOperationException>(() => { var name = extractionResult.Catalogs.First().DbName; }); Assert.Throws <InvalidOperationException>(() => { var name = extractionResult.Catalogs.First().DefaultSchema.Name; }); Assert.Throws <InvalidOperationException>(() => { var name = extractionResult.Catalogs.First().DefaultSchema.DbName; }); Assert.DoesNotThrow(() => { var name = extractionResult.Catalogs.First().DefaultSchema.Tables["Product"].Name; }); Assert.DoesNotThrow(() => { var name = extractionResult.Catalogs.First().DefaultSchema.Tables["Product"].DbName; }); }
public virtual void SetUp() { CheckRequirements(); sqlDriver = TestSqlDriver.Create(Url); sqlConnection = sqlDriver.CreateConnection(); try { sqlConnection.Open(); } catch (Exception exception) { Console.WriteLine(exception); throw; } try { sqlConnection.BeginTransaction(); Catalog = sqlDriver.ExtractCatalog(sqlConnection); var schema = Catalog.DefaultSchema; var creator = new ChinookSchemaCreator(sqlDriver); creator.DropSchemaContent(sqlConnection, schema); creator.CreateSchemaContent(sqlConnection, schema); sqlConnection.Commit(); } catch { sqlConnection.Rollback(); throw; } }
public override void SetUp() { base.SetUp(); sqlDriver = TestSqlDriver.Create(Url); sqlConnection = sqlDriver.CreateConnection(); sqlCommand = sqlConnection.CreateCommand(); }
protected virtual void TestFixtureSetUp() { var parsedUrl = UrlInfo.Parse(Url); Driver = TestSqlDriver.Create(parsedUrl); Connection = Driver.CreateConnection(); Connection.Open(); }
public override void SetUp() { CheckRequirements(); SqlDriver = TestSqlDriver.Create(ConnectionInfo.ConnectionUrl.Url); SqlConnection = SqlDriver.CreateConnection(); SqlConnection.Open(); sqlCommand = SqlConnection.CreateCommand(); }
public virtual void SetUp() { CheckRequirements(); SqlDriver = TestSqlDriver.Create(ConnectionInfo.ConnectionUrl.Url); SqlConnection = SqlDriver.CreateConnection(); SqlConnection.Open(); Catalog = SqlDriver.ExtractCatalog(SqlConnection); DropAllTables(Catalog.DefaultSchema, true); CreateSchema(); InsertTestData(); }
public override void SetUp() { base.SetUp(); sqlDriver = TestSqlDriver.Create(Url); sqlConnection = sqlDriver.CreateConnection(); sqlCommand = sqlConnection.CreateCommand(); try { sqlConnection.Open(); } catch (SystemException e) { Console.WriteLine(e); } }
private void ManuallyInsertIgnoredItems(Catalog catalog) { var validatableSchemas = new List <Schema>(); if (nodeToSchemaMap.Count > 0) { validatableSchemas.Add(catalog.Schemas[nodeToSchemaMap[MainNodeId]]); validatableSchemas.Add(catalog.Schemas[nodeToSchemaMap[AdditionalNodeId]]); } else { validatableSchemas.Add(catalog.DefaultSchema); } foreach (var schema in validatableSchemas) { using (var connection = driver.CreateConnection()) { connection.Open(); var productTable = schema.Tables["Product"]; var hiddenNameColumn = productTable.CreateColumn("HiddenName", GetTypeForString(255)); hiddenNameColumn.IsNullable = true; var commandText = driver.Compile(SqlDdl.Alter(productTable, SqlDdl.AddColumn(hiddenNameColumn))).GetCommandText(); using (var command = connection.CreateCommand(commandText)) { _ = command.ExecuteNonQuery(); } var priceListTable = schema.Tables["PriceList"]; var hiddenCommentColumn = priceListTable.CreateColumn("HiddenComment", GetTypeForString(255)); hiddenCommentColumn.IsNullable = true; commandText = driver.Compile(SqlDdl.Alter(priceListTable, SqlDdl.AddColumn(hiddenCommentColumn))).GetCommandText(); using (var command = connection.CreateCommand(commandText)) { _ = command.ExecuteNonQuery(); } var currencyTable = schema.Tables["Currency"]; var prefixColumnTemplate = "NotInDomain{0}"; var columns = new[] { "Column1", "Column2", "Column3" }; foreach (var column in columns) { var prefixColumn = currencyTable.CreateColumn(string.Format(prefixColumnTemplate, column), GetTypeForString(255)); prefixColumn.IsNullable = true; commandText = driver.Compile(SqlDdl.Alter(currencyTable, SqlDdl.AddColumn(prefixColumn))).GetCommandText(); using (var command = connection.CreateCommand(commandText)) { _ = command.ExecuteNonQuery(); } } var ignoredTable = schema.CreateTable("HiddenTable"); var idColumn = ignoredTable.CreateColumn("Id", new SqlValueType(SqlType.Int64)); idColumn.IsNullable = false; var name = ignoredTable.CreateColumn("Name", GetTypeForString(255)); name.IsNullable = false; var pk = ignoredTable.CreatePrimaryKey("PK_HiddenTable", idColumn); using (var command = connection.CreateCommand(SqlDdl.Create(ignoredTable))) { _ = command.ExecuteNonQuery(); } var notInDomainTable1 = schema.CreateTable("NotInDomain1"); idColumn = notInDomainTable1.CreateColumn("Id", new SqlValueType(SqlType.Int64)); idColumn.IsNullable = false; name = notInDomainTable1.CreateColumn("Name", GetTypeForString(255)); name.IsNullable = false; pk = notInDomainTable1.CreatePrimaryKey("PK_NotInDomain1", idColumn); using (var command = connection.CreateCommand(SqlDdl.Create(notInDomainTable1))) { _ = command.ExecuteNonQuery(); } var notInDomainTable2 = schema.CreateTable("NotInDomain2"); idColumn = notInDomainTable2.CreateColumn("Id", new SqlValueType(SqlType.Int64)); idColumn.IsNullable = false; name = notInDomainTable2.CreateColumn("Name", GetTypeForString(255)); name.IsNullable = false; pk = notInDomainTable2.CreatePrimaryKey("PK_NotInDomain2", idColumn); using (var command = connection.CreateCommand(SqlDdl.Create(notInDomainTable2))) { _ = command.ExecuteNonQuery(); } var notInDomainTable3 = schema.CreateTable("NotInDomain3"); idColumn = notInDomainTable3.CreateColumn("Id", new SqlValueType(SqlType.Int64)); idColumn.IsNullable = false; name = notInDomainTable3.CreateColumn("Name", GetTypeForString(255)); name.IsNullable = false; pk = notInDomainTable3.CreatePrimaryKey("PK_NotInDomain3", idColumn); using (var command = connection.CreateCommand(SqlDdl.Create(notInDomainTable3))) { _ = command.ExecuteNonQuery(); } } } }