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));
            }
        }
Beispiel #2
0
        public SqlExtractionResult Extract(SqlConnection connection, IEnumerable <SqlExtractionTask> tasks)
        {
            var result = underlyingDriver.Extract(connection, tasks);

            FixExtractionResult(result);
            return(result);
        }