public void StoreThenIncludeTest() { Require.AllFeaturesSupported(ProviderFeatures.TemporaryTables); using (var session = Domain.OpenSession()) using (var transaction = session.OpenTransaction()) { var businessUnitIds = session.Query.All <BusinessUnit>().Select(bu => bu.Id).ToList(); var bounds = new Tuple <DateTime, DateTime, string> [26]; for (var i = 0; i < bounds.Length; i++) { bounds[i] = new Tuple <DateTime, DateTime, string>(DateTime.UtcNow, DateTime.UtcNow, ""); } var list = session.Query.All <Job>() .Select(job => new { BusinessUnitId = job.BusinessUnit.Id, Month = bounds.FirstOrDefault().Item3 }) .Where(job => job.BusinessUnitId.In(businessUnitIds)) .ToList(); } }
public void SimplifiedTest() { Require.AllFeaturesSupported(ProviderFeatures.ScalarSubqueries); var today = DateTime.Now; using (var session = Domain.OpenSession()) { using (var t = session.OpenTransaction()) { var query = from kalinaGasObject in session.Query.All <PipeAbonent>() let matchGuess = session.Query.All <Kalina2RngGasObjectMatchGuess>().FirstOrDefault() let owner = session.Query.All <PipeAbonentOwnershipInfo>().FirstOrDefault() orderby matchGuess.Rank ?? 0 descending select matchGuess; var result = query.ToList(); } } }
public void TypeIdExtractionTest() { Require.AllFeaturesSupported(ProviderFeatures.Multischema); InitializeSchemas(); var defaultSchemaMap = new Dictionary <Type, int>(); var alternativeSchemaMap = new Dictionary <Type, int>(); BuildDomain(DefaultSchema, DomainUpgradeMode.Recreate, typeof(Entity1)).Dispose(); using (var domain = BuildDomain(DefaultSchema, DomainUpgradeMode.PerformSafely, typeof(Entity1), typeof(Entity2))) defaultSchemaMap = domain.Model.Types.ToDictionary(el => el.UnderlyingType, el => el.TypeId); BuildDomain(AlternativeSchema, DomainUpgradeMode.Recreate, typeof(Entity2)); using (var domain = BuildDomain(AlternativeSchema, DomainUpgradeMode.PerformSafely, typeof(Entity2), typeof(Entity1))) alternativeSchemaMap = domain.Model.Types.ToDictionary(el => el.UnderlyingType, el => el.TypeId); using (var domain = BuildDomain(DefaultSchema, DomainUpgradeMode.Validate, typeof(Entity1), typeof(Entity2))) { var nodeConfiguration = new NodeConfiguration(AlternativeSchema) { UpgradeMode = DomainUpgradeMode.Validate }; nodeConfiguration.SchemaMapping.Add(DefaultSchema, AlternativeSchema); domain.StorageNodeManager.AddNode(nodeConfiguration); using (var session = domain.OpenSession()) { session.SelectStorageNode(WellKnown.DefaultNodeId); var types = new[] { typeof(BaseEntity), typeof(Entity1), typeof(Entity2) }; foreach (var type in types) { Assert.That(session.StorageNode.TypeIdRegistry[domain.Model.Types[type]], Is.EqualTo(defaultSchemaMap[type])); } } using (var session = domain.OpenSession()) { session.SelectStorageNode(AlternativeSchema); var types = new[] { typeof(BaseEntity), typeof(Entity1), typeof(Entity2) }; foreach (var type in types) { Assert.That(session.StorageNode.TypeIdRegistry[domain.Model.Types[type]], Is.EqualTo(alternativeSchemaMap[type])); } } } }
public void MySqlModeGeneration() { Require.AllFeaturesNotSupported(ProviderFeatures.Sequences); Require.AllFeaturesSupported(ProviderFeatures.AutoIncrementSettingsInMemory); using (var session = Domain.OpenSession()) { foreach (var keyGenerator in Domain.Configuration.KeyGenerators) CheckGeneratorsAfterDomainBuilded(keyGenerator, session, 0); } using (var session = Domain.OpenSession()) using (session.Activate()) using (var transaction = session.OpenTransaction()) { for (int i = 0; i < 1; i++) { var entity = new Entity1(); } } using (var session = Domain.OpenSession()) { foreach (var keyGenerator in Domain.Configuration.KeyGenerators) CheckGeneratorsAfterDomainBuilded(keyGenerator, session, 1); } using (var session = Domain.OpenSession()) using (session.Activate()) using (var transaction = session.OpenTransaction()) { for (int i = 0; i < 120; i++) { var entity = new Entity1(); } } using (var session = Domain.OpenSession()) { foreach (var keyGenerator in Domain.Configuration.KeyGenerators) CheckGeneratorsAfterDomainBuilded(keyGenerator, session, 1); } using (var session = Domain.OpenSession()) using (session.Activate()) using (var transaction = session.OpenTransaction()) { for (int i = 0; i < 250; i++) { var entity = new Entity1(); } } using (var session = Domain.OpenSession()) { foreach (var keyGenerator in Domain.Configuration.KeyGenerators) CheckGeneratorsAfterDomainBuilded(keyGenerator, session, 1); } }
public void TwoCalculateWithApplyTest() { Require.AllFeaturesSupported(ProviderFeatures.Apply); var actual = from c in Session.Query.All <Customer>() from n in (c.Invoices.Select(i => c.FirstName + i.BillingAddress.StreetAddress)) .Union(c.Invoices.Select(i => c.FirstName + i.BillingAddress.StreetAddress)) orderby n select n; var expected = from c in Customers from n in (c.Invoices.Select(i => c.FirstName + i.BillingAddress.StreetAddress)) .Union(c.Invoices.Select(i => c.FirstName + i.BillingAddress.StreetAddress)) orderby n select n; Assert.That(actual, Is.Not.Empty); Assert.IsTrue(expected.SequenceEqual(actual)); }
public void JoinStructureDirectTest() { Require.AllFeaturesSupported(ProviderFeatures.TemporaryTables); using (Session session = Domain.OpenSession()) { using (TransactionScope t = session.OpenTransaction()) { session.SaveChanges(); var localStructure = session.Query.All <EntityB>().Select(b => b.AdditionalInfo).First(); var array = session.Query.All <EntityB>().Where(b => b.AdditionalInfo == localStructure).ToArray(); var localItems = session.Query.All <EntityB>().Select(b => b.AdditionalInfo).ToArray(); var join = session.Query.All <EntityB>().Select(b => b.AdditionalInfo).Join(localItems, b => b, l => l, (b, l) => new { b, l }); var expected = session.Query.All <EntityB>().AsEnumerable().Select(b => b.AdditionalInfo).Join(localItems, b => b, l => l, (b, l) => new { b, l }); var except = expected.Except(join); var joinArray = join.ToArray(); var expectedArray = expected.ToArray(); Assert.AreEqual(0, except.Count()); } } }
public void JoinEntityTest() { Require.AllFeaturesSupported(ProviderFeatures.TemporaryTables); var localInvoices = Session.Query.All <Invoice>().Take(5).ToList(); var query = Session.Query.All <Invoice>().Join( localInvoices, invoice => invoice, localInvoice => localInvoice, (invoice, localInvoice) => new { invoice, localInvoice }); Assert.That(query, Is.Not.Empty); QueryDumper.Dump(query); var expectedQuery = Invoices.Join( localInvoices, invoice => invoice, localInvoice => localInvoice, (invoice, localInvoice) => new { invoice, localInvoice }); Assert.AreEqual(0, expectedQuery.Except(query).Count()); }
public void JoinEntityField2MaterializeTest() { Require.AllFeaturesSupported(ProviderFeatures.TemporaryTables); var localCommissions = Session.Query.All <Invoice>().Take(5).Select(invoice => invoice.Commission).ToList(); var query = Session.Query.All <Invoice>().Join( localCommissions, invoice => invoice.Commission, commission => commission, (invoice, commission) => new { invoice, commission }).Select(x => x.commission); Assert.That(query, Is.Not.Empty); QueryDumper.Dump(query); var expectedQuery = Invoices.Join( localCommissions, invoice => invoice.Commission, commission => commission, (invoice, commission) => new { invoice, commission }).Select(x => x.commission); Assert.AreEqual(0, expectedQuery.Except(query).Count()); }
public void Store2Test() { Require.AllFeaturesSupported(ProviderFeatures.TemporaryTables); var query = Session.Query.All <Customer>() .Join( Session.Query.Store(Session.Query.All <Customer>().Take(10)), customer => customer, localCustomer => localCustomer, (customer, localCustomer) => new { customer, localCustomer }); var expected = Session.Query.All <Customer>().AsEnumerable() .Join( Session.Query.Store(Session.Query.All <Customer>().Take(10)), customer => customer, localCustomer => localCustomer, (customer, localCustomer) => new { customer, localCustomer }); Assert.That(query, Is.Not.Empty); Assert.AreEqual(0, expected.Except(query).Count()); }
public void MainTest() { Require.AllFeaturesSupported(ProviderFeatures.ScalarSubqueries); using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { var r = session.Query.All <Container>() .Select(c => new { c.Id, LastLocation = Query.All <StoredContainer>() .Where(s => s.Container == c) .OrderByDescending(s => s.CreationTime) .Select(s => s.Address) .FirstOrDefault() }) .OrderBy(c => c.Id) .Single(); Assert.That(r.LastLocation, Is.EqualTo("3")); } }
public void MainTest() { Require.AllFeaturesSupported(ProviderFeatures.ScalarSubqueries); using (var session = Domain.OpenSession()) { using (var transaction = session.OpenTransaction()) { var myEntity = new MyEntity() { Date = DateTime.Now, Text = "Text" }; var query = session.Query.All <MyEntity>() .Select(e => new { MyEntity = e, Year = (int?)e.Date.Value.Year, Status = e.Infos.OfType <SuccessInfo>().Any() ? Status.Success : (e.Infos.OfType <ErrorInfo>().Any() ? Status.Error : Status.Unknown) }) .Select(o => new object[] { o.MyEntity.Id, o.Year, o.Status }); var result = query.ToList(); } } }
public void OuterJoinAnonymousTest() { Require.AllFeaturesSupported(ProviderFeatures.ScalarSubqueries); var assertCount = Session.Query.All <Invoice>().Count() + Session.Query.All <Customer>().Count(c => !Session.Query.All <Invoice>().Any(i => i.Customer == c)); var result = from c in Session.Query.All <Customer>() from i in Session.Query.All <Invoice>().Where(i => i.Customer == c).Select(i => new { i.InvoiceId, c.Phone }).DefaultIfEmpty() select new { c.LastName, i }; var list = result.ToList(); Assert.That(list, Is.Not.Empty); Assert.AreEqual(assertCount, list.Count); foreach (var item in result) { Assert.IsNotNull(item); Assert.IsNotNull(item.LastName); Assert.IsNotNull(item.i); } QueryDumper.Dump(list); }
public void Subquery2Test() { Require.AllFeaturesSupported(ProviderFeatures.TemporaryTables); var localItems = GetLocalItems(10); var queryable = Session.Query.Store(localItems); var result = queryable .Select(poco => queryable.Where(poco2 => poco2.Value2 > poco.Value2).Select(p => p.Value3)).AsEnumerable().Cast <IEnumerable <string> >(); var expected = localItems .Select(poco => localItems.Where(poco2 => poco2.Value2 > poco.Value2).Select(p => p.Value3)); var expectedList = expected.ToList(); var resultList = result.ToList(); Assert.That(resultList, Is.Not.Empty); Assert.AreEqual(resultList.Count, expectedList.Count); for (var i = 0; i < resultList.Count; i++) { Assert.AreEqual(0, expectedList[i].Except(resultList[i]).Count()); } QueryDumper.Dump(result); }
public void BaseTest() { Require.AllFeaturesSupported(ProviderFeatures.UpdateFrom); // Test MoveFieldHint (RemoveFieldHint) var config = base.BuildConfiguration(); config.Types.Register(Assembly.GetExecutingAssembly(), "Xtensive.Orm.Tests.Issues.Issue0376.Model2"); config.UpgradeMode = DomainUpgradeMode.PerformSafely; Domain domain; using (M2.Upgrader.Enable()) { domain = Domain.Build(config); } using (var session = domain.OpenSession()) { using (var transactionScope = session.OpenTransaction()) { var son = session.Query.All <M2.Son>().Single(); Assert.AreEqual("FirstName", son.FirstName); Assert.AreEqual("LastName", son.LastName); Assert.AreEqual("NickName", son.NickName); transactionScope.Complete(); } } // Test RemoveTypeHint config = base.BuildConfiguration(); config.Types.Register(Assembly.GetExecutingAssembly(), "Xtensive.Orm.Tests.Issues.Issue0376.Model3"); config.UpgradeMode = DomainUpgradeMode.PerformSafely; using (M3.Upgrader.Enable()) { domain = Domain.Build(config); } using (var session = domain.OpenSession()) { using (var transactionScope = session.OpenTransaction()) { Assert.IsTrue(session.Query.All <M3.Father>().Count() == 0); transactionScope.Complete(); } } }
public void Grouping2Test() { Require.AllFeaturesSupported(ProviderFeatures.TemporaryTables); var localItems = GetLocalItems(10); var queryable = Session.Query.Store(localItems); var result = queryable .GroupBy(keySelector => keySelector.Value3[0], (key, grouping) => new { key, Value1 = grouping.Select(p => p.Value1) }) .OrderBy(grouping => grouping.key); var expected = localItems .GroupBy(keySelector => keySelector.Value3[0], (key, grouping) => new { key, Value1 = grouping.Select(p => p.Value1) }) .OrderBy(grouping => grouping.key); var expectedList = expected.ToList(); var resultList = result.ToList(); Assert.That(resultList, Is.Not.Empty); Assert.AreEqual(resultList.Count, expectedList.Count); for (var i = 0; i < resultList.Count; i++) { Assert.AreEqual(resultList[i].key, expectedList[i].key); Assert.AreEqual(0, expectedList[i].Value1.Except(resultList[i].Value1).Count()); } QueryDumper.Dump(result); }
public void MainTest() { Require.AllFeaturesSupported(ProviderFeatures.Multischema); InitializeSchemas(); BuildDomain(DefaultSchema, DomainUpgradeMode.Recreate, typeof(Entity1)).Dispose(); BuildDomain(DefaultSchema, DomainUpgradeMode.PerformSafely, typeof(Entity1), typeof(Entity2)).Dispose(); BuildDomain(AlternativeSchema, DomainUpgradeMode.Recreate, typeof(Entity2)); BuildDomain(AlternativeSchema, DomainUpgradeMode.PerformSafely, typeof(Entity2), typeof(Entity1)).Dispose(); using (var domain = BuildDomain(DefaultSchema, DomainUpgradeMode.Validate, typeof(Entity1), typeof(Entity2))) { var nodeConfiguration = new NodeConfiguration(AlternativeSchema) { UpgradeMode = DomainUpgradeMode.Validate }; nodeConfiguration.SchemaMapping.Add(DefaultSchema, AlternativeSchema); domain.StorageNodeManager.AddNode(nodeConfiguration); RunTest(domain, WellKnown.DefaultNodeId, MainTestBody); RunTest(domain, AlternativeSchema, MainTestBody); } }
public void Grouping1Test() { Require.AllFeaturesSupported(ProviderFeatures.TemporaryTables); var localItems = GetLocalItems(10); var queryable = Session.Query.Store(localItems); var result = queryable .GroupBy(keySelector => keySelector.Value3.Substring(0, 1), (key, grouping) => new { key, Value1 = grouping.Select(p => p.Value1) }) .OrderBy(grouping => grouping.key); var expected = localItems .GroupBy(keySelector => keySelector.Value3.Substring(0, 1), (key, grouping) => new { key, Value1 = grouping.Select(p => p.Value1) }) .OrderBy(grouping => grouping.key); var expectedList = expected.ToList(); var resultList = result.ToList(); Assert.That(resultList, Is.Not.Empty); Assert.AreEqual(resultList.Count, expectedList.Count); for (var i = 0; i < resultList.Count; i++) { Console.WriteLine(string.Format("Key (expected/result): {0} / {1}", expectedList[i].key, resultList[i].key)); foreach (var expectedValue in expectedList[i].Value1) { Console.WriteLine(string.Format("Expected Value: {0}", expectedValue)); } foreach (var resultValue in resultList[i].Value1) { Console.WriteLine(string.Format("Result Value: {0}", resultValue)); } Assert.AreEqual(resultList[i].key, expectedList[i].key); var isCorrect = expectedList[i].Value1.Except(resultList[i].Value1).Count() == 0; Assert.IsTrue(isCorrect); } QueryDumper.Dump(result); }
public void MainTest() { Require.AllFeaturesSupported(ProviderFeatures.ScalarSubqueries); using (var session = Domain.OpenSession()) using (var t = session.OpenTransaction()) { var person = new Person(Guid.NewGuid()) { Rank = 1 }; var position = new Position(Guid.NewGuid()) { Rank = 1 }; // session.Persist(); var rank = session.Query.All <Position>().Where(r => r.Rank == 1).Single().Rank; // Ok here Assert.AreEqual(1, rank); var people = session.Query.All <Person>() .Where(p => p.Rank == session.Query.All <Position>().Where(r => r.Rank == 1).Single().Rank) .ToList(); //Exception Assert.AreEqual(1, people.Count); t.Complete(); } }
public void UpgradeDateTimeOffsetAndDateTimeTest() { Require.AllFeaturesSupported(ProviderFeatures.DateTimeOffset); Require.ProviderIsNot(StorageProvider.PostgreSql, "ToLocalTime is not supported"); using (var domain = BuildInitialDomain()) using (var session = domain.OpenSession()) using (var tx = session.OpenTransaction()) { new V1.EntityWithDateTimeOffset { DateTimeOffset = dateTimeOffset, DateTime = dateTime }; tx.Complete(); } using (var domain = BuildUpgradedDomain()) using (var session = domain.OpenSession()) using (var tx = session.OpenTransaction()) { var valuesAfterUpgrade = session.Query.All <V2.EntityWithDateTimeOffsetUpgrade>().Single(); var queryServerOffset = from t in session.Query.All <V2.EntityWithDateTimeOffsetUpgrade>() group t by new { ServerOffset = t.DateTime.ToLocalTime().Offset }; var resultQueryServerOffset = queryServerOffset.ToList().FirstOrDefault(); if (resultQueryServerOffset != null) { Assert.That(valuesAfterUpgrade.DateTime, Is.EqualTo(new DateTimeOffset(dateTime, resultQueryServerOffset.Key.ServerOffset))); } Assert.That(valuesAfterUpgrade.DateTimeOffset, Is.EqualTo(dateTime)); tx.Complete(); } }
protected override void CheckRequirements() { base.CheckRequirements(); Require.AllFeaturesSupported(ProviderFeatures.Multidatabase); }
protected override void CheckRequirements() { Require.ProviderIs(StorageProvider.SqlServer); Require.AllFeaturesSupported(ProviderFeatures.Multidatabase); }
protected override void CheckRequirements() => Require.AllFeaturesSupported(ProviderFeatures.Multischema);
protected override void CheckRequirements() { Require.AllFeaturesSupported(ProviderFeatures.DateTimeOffset); }
public void TestSetUp() { Require.AllFeaturesSupported(ProviderFeatures.FullText); }
protected override void CheckRequirements() { Require.AllFeaturesSupported(ProviderFeatures.FullText); }
protected override void CheckRequirements() { Require.AllFeaturesSupported(ProviderFeatures.ScalarSubqueries); }
public virtual void CheckRequirements() { Require.AllFeaturesSupported(ProviderFeatures.Multischema); }
public void MultidatabaseMappingResolverOnSharedSchemaTest() { Require.AllFeaturesSupported(ProviderFeatures.Multidatabase); var domainConfiguration = DomainConfigurationFactory.Create(); domainConfiguration.UpgradeMode = DomainUpgradeMode.Recreate; domainConfiguration.Types.Register(typeof(model.Part1.TestEntity1).Assembly, typeof(model.Part1.TestEntity1).Namespace); domainConfiguration.Types.Register(typeof(model.Part2.TestEntity2).Assembly, typeof(model.Part2.TestEntity2).Namespace); domainConfiguration.Types.Register(typeof(model.Part3.TestEntity3).Assembly, typeof(model.Part3.TestEntity3).Namespace); domainConfiguration.Types.Register(typeof(model.Part4.TestEntity4).Assembly, typeof(model.Part4.TestEntity4).Namespace); _ = domainConfiguration.Databases.Add(DOTests1Db); _ = domainConfiguration.Databases.Add(DOTests2Db); domainConfiguration.MappingRules.Map(typeof(model.Part1.TestEntity1).Assembly, typeof(model.Part1.TestEntity1).Namespace).To(DOTests1Db, Schema1); domainConfiguration.MappingRules.Map(typeof(model.Part2.TestEntity2).Assembly, typeof(model.Part2.TestEntity2).Namespace).To(DOTests1Db, Schema2); domainConfiguration.MappingRules.Map(typeof(model.Part3.TestEntity3).Assembly, typeof(model.Part3.TestEntity3).Namespace).To(DOTests2Db, Schema1); domainConfiguration.MappingRules.Map(typeof(model.Part4.TestEntity4).Assembly, typeof(model.Part4.TestEntity4).Namespace).To(DOTests2Db, Schema2); domainConfiguration.DefaultDatabase = DOTests1Db; domainConfiguration.DefaultSchema = Schema1; var nodeConfiguration = new NodeConfiguration("Additional"); nodeConfiguration.UpgradeMode = DomainUpgradeMode.Recreate; nodeConfiguration.DatabaseMapping.Add(DOTests1Db, DOTests3Db); nodeConfiguration.DatabaseMapping.Add(DOTests2Db, DOTests4Db); nodeConfiguration.SchemaMapping.Add(Schema1, Schema3); nodeConfiguration.SchemaMapping.Add(Schema2, Schema4); using (var domain = Domain.Build(domainConfiguration)) { _ = domain.StorageNodeManager.AddNode(nodeConfiguration); var defaultNodeConfig = domain.StorageNodeManager.GetNode(WellKnown.DefaultNodeId).Configuration; var additionalNodeConfig = domain.StorageNodeManager.GetNode("Additional").Configuration; DefaultSchemaInfo defaultSchemaInfo; using (var connection = driver.CreateConnection()) { connection.Open(); defaultSchemaInfo = driver.GetDefaultSchema(connection); } var defaultMappingResolver = MappingResolver.Create(domainConfiguration, defaultNodeConfig, defaultSchemaInfo); Assert.That(defaultMappingResolver, Is.InstanceOf <MultidatabaseMappingResolver>()); var additionalMappingResolver = MappingResolver.Create(domainConfiguration, additionalNodeConfig, defaultSchemaInfo); Assert.That(additionalMappingResolver, Is.InstanceOf <MultidatabaseMappingResolver>()); SchemaExtractionResult extractionResult; using (var connection = driver.CreateConnection()) { connection.Open(); extractionResult = new SchemaExtractionResult(driver.Extract(connection, defaultMappingResolver.GetSchemaTasks())); } _ = extractionResult.MakeShared(); var resolverPerNodeMap = new Dictionary <NodeConfiguration, MappingResolver> { { defaultNodeConfig, defaultMappingResolver }, { additionalNodeConfig, additionalMappingResolver } }; var baseDb1 = DOTests1Db; var baseDb2 = DOTests2Db; var baseSch1 = Schema1; var baseSch2 = Schema2; foreach (var pair in resolverPerNodeMap) { var nodeConfig = pair.Key; var resolver = pair.Value; var tasks = resolver.GetSchemaTasks(); Assert.That(tasks.Count(), Is.EqualTo(4)); Assert.That(tasks.Any(t => t.Catalog == nodeConfig.DatabaseMapping.Apply(DOTests1Db) && t.Schema == nodeConfig.SchemaMapping.Apply(Schema1)), Is.True); Assert.That(tasks.Any(t => t.Catalog == nodeConfig.DatabaseMapping.Apply(DOTests1Db) && t.Schema == nodeConfig.SchemaMapping.Apply(Schema2)), Is.True); Assert.That(tasks.Any(t => t.Catalog == nodeConfig.DatabaseMapping.Apply(DOTests2Db) && t.Schema == nodeConfig.SchemaMapping.Apply(Schema1)), Is.True); Assert.That(tasks.Any(t => t.Catalog == nodeConfig.DatabaseMapping.Apply(DOTests2Db) && t.Schema == nodeConfig.SchemaMapping.Apply(Schema2)), Is.True); tasks = resolver.GetMetadataTasks(); Assert.That(tasks.Count(), Is.EqualTo(2)); Assert.That(tasks.Any(t => t.Catalog == nodeConfig.DatabaseMapping.Apply(DOTests1Db) && t.Schema == nodeConfig.SchemaMapping.Apply(Schema1)), Is.True); Assert.That(tasks.Any(t => t.Catalog == nodeConfig.DatabaseMapping.Apply(DOTests2Db) && t.Schema == nodeConfig.SchemaMapping.Apply(Schema1)), Is.True); var fullName = resolver.GetNodeName("TestDb", "TestSchema", "TestEntity1"); Assert.That(fullName, Is.EqualTo("TestDb:TestSchema:TestEntity1")); var expectedDatabase = nodeConfig.DatabaseMapping.Apply(baseDb1); var expectedSchema = nodeConfig.SchemaMapping.Apply(baseSch1); fullName = resolver.GetNodeName(DOTests1Db, Schema1, "TestEntity1"); Assert.That(fullName, Is.EqualTo(string.Format("{0}:{1}:TestEntity1", expectedDatabase, expectedSchema))); var table = extractionResult .Catalogs[baseDb1] .Schemas[baseSch1] .Tables["TestEntity1"]; fullName = resolver.GetNodeName(table); expectedDatabase = baseDb1; expectedSchema = baseSch1; Assert.That(fullName, Is.EqualTo(string.Format("{0}:{1}:TestEntity1", expectedDatabase, expectedSchema))); table = extractionResult .Catalogs[baseDb1] .Schemas[baseSch2] .Tables["TestEntity2"]; fullName = resolver.GetNodeName(table); expectedDatabase = baseDb1; expectedSchema = baseSch2; Assert.That(fullName, Is.EqualTo(string.Format("{0}:{1}:TestEntity2", expectedDatabase, expectedSchema))); table = extractionResult .Catalogs[baseDb2] .Schemas[baseSch1] .Tables["TestEntity3"]; expectedDatabase = baseDb2; expectedSchema = baseSch1; fullName = resolver.GetNodeName(table); Assert.That(fullName, Is.EqualTo(string.Format("{0}:{1}:TestEntity3", expectedDatabase, expectedSchema))); var typeinfo = domain.Model.Types[typeof(model.Part1.TestEntity1)]; expectedDatabase = nodeConfig.DatabaseMapping.Apply(baseDb1); expectedSchema = nodeConfig.SchemaMapping.Apply(baseSch1); fullName = resolver.GetNodeName(typeinfo); Assert.That(fullName, Is.EqualTo(string.Format("{0}:{1}:TestEntity1", expectedDatabase, expectedSchema))); var resolveResult = resolver.Resolve(extractionResult, fullName); expectedDatabase = baseDb1; expectedSchema = baseSch1; Assert.That(resolveResult.Schema.GetNameInternal(), Is.EqualTo(expectedSchema)); Assert.That(resolveResult.Schema.Catalog.GetNameInternal(), Is.EqualTo(expectedDatabase)); var schema = resolver.ResolveSchema(extractionResult, typeinfo.MappingDatabase, typeinfo.MappingSchema); Assert.That(schema.GetNameInternal(), Is.EqualTo(expectedSchema)); Assert.That(schema.Catalog.GetNameInternal(), Is.EqualTo(expectedDatabase)); typeinfo = domain.Model.Types[typeof(model.Part2.TestEntity2)]; expectedDatabase = nodeConfig.DatabaseMapping.Apply(baseDb1); expectedSchema = nodeConfig.SchemaMapping.Apply(baseSch2); fullName = resolver.GetNodeName(typeinfo); Assert.That(fullName, Is.EqualTo(string.Format("{0}:{1}:TestEntity2", expectedDatabase, expectedSchema))); resolveResult = resolver.Resolve(extractionResult, fullName); expectedDatabase = baseDb1; expectedSchema = baseSch2; Assert.That(resolveResult.Schema.GetNameInternal(), Is.EqualTo(expectedSchema)); Assert.That(resolveResult.Schema.Catalog.GetNameInternal(), Is.EqualTo(expectedDatabase)); schema = resolver.ResolveSchema(extractionResult, typeinfo.MappingDatabase, typeinfo.MappingSchema); Assert.That(schema.GetNameInternal(), Is.EqualTo(expectedSchema)); Assert.That(schema.Catalog.GetNameInternal(), Is.EqualTo(expectedDatabase)); typeinfo = domain.Model.Types[typeof(model.Part3.TestEntity3)]; expectedDatabase = nodeConfig.DatabaseMapping.Apply(baseDb2); expectedSchema = nodeConfig.SchemaMapping.Apply(baseSch1); fullName = resolver.GetNodeName(typeinfo); Assert.That(fullName, Is.EqualTo(string.Format("{0}:{1}:TestEntity3", expectedDatabase, expectedSchema))); resolveResult = resolver.Resolve(extractionResult, fullName); expectedDatabase = baseDb2; expectedSchema = baseSch1; Assert.That(resolveResult.Schema.GetNameInternal(), Is.EqualTo(expectedSchema)); Assert.That(resolveResult.Schema.Catalog.GetNameInternal(), Is.EqualTo(expectedDatabase)); schema = resolver.ResolveSchema(extractionResult, typeinfo.MappingDatabase, typeinfo.MappingSchema); Assert.That(schema.GetNameInternal(), Is.EqualTo(expectedSchema)); Assert.That(schema.Catalog.GetNameInternal(), Is.EqualTo(expectedDatabase)); } } }
public void MultischemaMappingResolverOnSharedSchemaTest() { Require.AllFeaturesSupported(ProviderFeatures.Multischema); var domainConfiguration = DomainConfigurationFactory.Create(); domainConfiguration.UpgradeMode = DomainUpgradeMode.Recreate; domainConfiguration.Types.Register(typeof(model.Part1.TestEntity1).Assembly, typeof(model.Part1.TestEntity1).Namespace); domainConfiguration.Types.Register(typeof(model.Part2.TestEntity2).Assembly, typeof(model.Part2.TestEntity2).Namespace); domainConfiguration.Types.Register(typeof(model.Part3.TestEntity3).Assembly, typeof(model.Part3.TestEntity3).Namespace); domainConfiguration.Types.Register(typeof(model.Part4.TestEntity4).Assembly, typeof(model.Part4.TestEntity4).Namespace); domainConfiguration.MappingRules.Map(typeof(model.Part1.TestEntity1).Assembly, typeof(model.Part1.TestEntity1).Namespace).ToSchema(Schema1); domainConfiguration.MappingRules.Map(typeof(model.Part2.TestEntity2).Assembly, typeof(model.Part2.TestEntity2).Namespace).ToSchema(Schema1); domainConfiguration.MappingRules.Map(typeof(model.Part3.TestEntity3).Assembly, typeof(model.Part3.TestEntity3).Namespace).ToSchema(Schema2); domainConfiguration.MappingRules.Map(typeof(model.Part4.TestEntity4).Assembly, typeof(model.Part4.TestEntity4).Namespace).ToSchema(Schema2); domainConfiguration.DefaultSchema = Schema1; var nodeConfiguration = new NodeConfiguration("Additional"); nodeConfiguration.UpgradeMode = DomainUpgradeMode.Recreate; nodeConfiguration.SchemaMapping.Add(Schema1, Schema3); nodeConfiguration.SchemaMapping.Add(Schema2, Schema4); using (var domain = Domain.Build(domainConfiguration)) { domain.StorageNodeManager.AddNode(nodeConfiguration); var defaultNodeConfig = domain.StorageNodeManager.GetNode(WellKnown.DefaultNodeId).Configuration; var additionalNodeConfig = domain.StorageNodeManager.GetNode("Additional").Configuration; DefaultSchemaInfo defaultSchemaInfo; using (var connection = driver.CreateConnection()) { connection.Open(); defaultSchemaInfo = driver.GetDefaultSchema(connection); } var defaultMappingResolver = MappingResolver.Create(domainConfiguration, defaultNodeConfig, defaultSchemaInfo); Assert.That(defaultMappingResolver, Is.InstanceOf <MultischemaMappingResolver>()); var additionalMappingResolver = MappingResolver.Create(domainConfiguration, additionalNodeConfig, defaultSchemaInfo); Assert.That(additionalMappingResolver, Is.InstanceOf <MultischemaMappingResolver>()); SchemaExtractionResult extractionResult; using (var connection = driver.CreateConnection()) { connection.Open(); extractionResult = new SchemaExtractionResult(driver.Extract(connection, defaultMappingResolver.GetSchemaTasks())); } _ = extractionResult.MakeShared(); var resolverPerNodeMap = new Dictionary <NodeConfiguration, MappingResolver> { { defaultNodeConfig, defaultMappingResolver }, { additionalNodeConfig, additionalMappingResolver } }; foreach (var pair in resolverPerNodeMap) { var nodeConfig = pair.Key; var mappingResolver = pair.Value; Assert.That(mappingResolver, Is.InstanceOf <MultischemaMappingResolver>()); 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(nodeConfig.SchemaMapping.Apply(Schema1))); var schemaExtractionTasks = mappingResolver.GetSchemaTasks(); Assert.That(schemaExtractionTasks.Count(), Is.EqualTo(2)); Assert.That(schemaExtractionTasks.Any(t => t.Catalog == defaultSchemaInfo.Database && t.Schema == nodeConfig.SchemaMapping.Apply(Schema1)), Is.True); Assert.That(schemaExtractionTasks.Any(t => t.Catalog == defaultSchemaInfo.Database && t.Schema == nodeConfig.SchemaMapping.Apply(Schema2)), Is.True); var fullName = mappingResolver.GetNodeName("dummy", "SchemaName", "Table1"); Assert.That(fullName, Is.EqualTo("SchemaName:Table1")); fullName = mappingResolver.GetNodeName("dummy", Schema1, "Table1"); Assert.That(fullName, Is.EqualTo(nodeConfig.SchemaMapping.Apply(Schema1) + ":Table1")); var table = extractionResult.Catalogs.First().Schemas[Schema1].Tables["TestEntity1"]; fullName = mappingResolver.GetNodeName(table); Assert.That(fullName, Is.EqualTo(Schema1 + ":TestEntity1")); table = extractionResult.Catalogs.First().Schemas[Schema2].Tables["TestEntity4"]; fullName = mappingResolver.GetNodeName(table); Assert.That(fullName, Is.EqualTo(Schema2 + ":TestEntity4")); var typeInfo = domain.Model.Types[typeof(model.Part1.TestEntity1)]; fullName = mappingResolver.GetNodeName(typeInfo); Assert.That(fullName, Is.EqualTo(nodeConfig.SchemaMapping.Apply(Schema1) + ":TestEntity1")); var resolveResult = mappingResolver.Resolve(extractionResult, fullName); Assert.That(resolveResult.Schema.GetNameInternal(), Is.EqualTo(Schema1)); var schema = mappingResolver.ResolveSchema(extractionResult, typeInfo.MappingDatabase, typeInfo.MappingSchema); Assert.That(schema.GetNameInternal(), Is.EqualTo(Schema1)); typeInfo = domain.Model.Types[typeof(model.Part4.TestEntity4)]; fullName = mappingResolver.GetNodeName(typeInfo); Assert.That(fullName, Is.EqualTo(nodeConfig.SchemaMapping.Apply(Schema2) + ":TestEntity4")); resolveResult = mappingResolver.Resolve(extractionResult, fullName); Assert.That(resolveResult.Schema.GetNameInternal(), Is.EqualTo(Schema2)); schema = mappingResolver.ResolveSchema(extractionResult, typeInfo.MappingDatabase, typeInfo.MappingSchema); Assert.That(schema.GetNameInternal(), Is.EqualTo(Schema2)); var sequence = typeInfo.Hierarchy.Key.Sequence; fullName = mappingResolver.GetNodeName(sequence); Assert.That(fullName, Is.EqualTo(nodeConfig.SchemaMapping.Apply(Schema1) + ":" + sequence.MappingName)); resolveResult = mappingResolver.Resolve(extractionResult, fullName); Assert.That(resolveResult.Schema.GetNameInternal(), Is.EqualTo(Schema1)); } } }
public void MainTest() { Require.AllFeaturesSupported(ProviderFeatures.ScalarSubqueries); using (var session = Domain.OpenSession()) { using (var transactionn = session.OpenTransaction()) { var sevRGasCustomer2 = new SevRGasCustomer() { Code = "Code", FullName = "Customer FullName", Name = "Customer Name", Tin = 44 }; // var ePassportAgent2 = new EPassportAgent(); var sevRGas2EPassportCustomerMatchGuess2 = new SevRGas2EPassportCustomerMatchGuess { SevRGasCustomerID = sevRGasCustomer2.Id, EPassportCustomerID = 12345, Rank = 12345 }; var dataUnitCustomer2 = new DataUnitCustomer { SevRGasCustomer = sevRGasCustomer2, EPassportAgent = null }; var sevRGasCustomer1 = new SevRGasCustomer() { Code = "Code", FullName = "Customer FullName", Name = "Customer Name", Tin = 12 }; var ePassportAgent1 = new EPassportAgent(); var sevRGas2EPassportCustomerMatchGuess1 = new SevRGas2EPassportCustomerMatchGuess { SevRGasCustomerID = sevRGasCustomer1.Id, EPassportCustomerID = ePassportAgent1.Id, Rank = 12345 }; var dataUnitCustomer1 = new DataUnitCustomer { SevRGasCustomer = sevRGasCustomer1, EPassportAgent = ePassportAgent1 }; var query = from customer in session.Query.All <SevRGasCustomer>() let matchGuess = session.Query.All <SevRGas2EPassportCustomerMatchGuess>().Where( g => g.SevRGasCustomerID == customer.Id).FirstOrDefault() let matchGuessObject = session.Query.All <EPassportAgent>().Where( go => go.Id == matchGuess.EPassportCustomerID).FirstOrDefault() let unifiedCustomer = session.Query.All <DataUnitCustomer>().Where( ua => ua.SevRGasCustomer == customer && ua.EPassportAgent != null).FirstOrDefault() select new SevRGas2EPassportCustomerMatchListItem { LeftID = customer.Id, LeftName = customer.Name ?? customer.FullName, LeftUniqueTaxpayerNumber = customer.Tin, LeftCode = customer.Code, Rank = matchGuess.Rank, Status = unifiedCustomer == null ? MatchStatus.NotConfirmed : MatchStatus.Confirmed, Right = GetRight(unifiedCustomer, matchGuess, matchGuessObject) }; var result = query.ToList(); } } }