|
| 1 | +// Copyright (C) 2022 Xtensive LLC. |
| 2 | +// This code is distributed under MIT license terms. |
| 3 | +// See the License.txt file in the project root for more information. |
| 4 | + |
| 5 | +using System.Linq; |
| 6 | +using NUnit.Framework; |
| 7 | +using Xtensive.Orm.Configuration; |
| 8 | +using M = Xtensive.Orm.Tests.Storage.Multimapping.CaseSensitiveSchemasTestModel; |
| 9 | + |
| 10 | +namespace Xtensive.Orm.Tests.Storage.Multimapping.CaseSensitiveSchemasTestModel |
| 11 | +{ |
| 12 | + namespace Schema1 |
| 13 | + { |
| 14 | + [HierarchyRoot] |
| 15 | + public class Entity1 : Entity |
| 16 | + { |
| 17 | + [Field, Key] |
| 18 | + public int Id { get; private set; } |
| 19 | + |
| 20 | + [Field] |
| 21 | + public string OriginalSchemaName { get; set; } |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + namespace Schema2 |
| 26 | + { |
| 27 | + [HierarchyRoot] |
| 28 | + public class Entity2 : Entity |
| 29 | + { |
| 30 | + [Field, Key] |
| 31 | + public int Id { get; private set; } |
| 32 | + |
| 33 | + [Field] |
| 34 | + public string OriginalSchemaName { get; set; } |
| 35 | + } |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +namespace Xtensive.Orm.Tests.Storage.Multimapping |
| 40 | +{ |
| 41 | + public sealed class CaseSensitiveSchemasTest : MultimappingTest |
| 42 | + { |
| 43 | + private const string Schema1Name = WellKnownSchemas.Schema1; |
| 44 | + |
| 45 | + private readonly string schema1UpperCaseName = Schema1Name.ToUpperInvariant(); |
| 46 | + |
| 47 | + protected override void CheckRequirements() => Require.ProviderIs(StorageProvider.Oracle); |
| 48 | + |
| 49 | + protected override DomainConfiguration BuildConfiguration() |
| 50 | + { |
| 51 | + var configuration = base.BuildConfiguration(); |
| 52 | + configuration.DefaultSchema = Schema1Name; |
| 53 | + configuration.Types.Register(typeof(M.Schema1.Entity1)); |
| 54 | + configuration.Types.Register(typeof(M.Schema2.Entity2)); |
| 55 | + var rules = configuration.MappingRules; |
| 56 | + rules.Map(typeof(M.Schema1.Entity1).Namespace).ToSchema(Schema1Name); |
| 57 | + rules.Map(typeof(M.Schema2.Entity2).Namespace).ToSchema(schema1UpperCaseName); |
| 58 | + return configuration; |
| 59 | + } |
| 60 | + |
| 61 | + [Test] |
| 62 | + public void MainTest() |
| 63 | + { |
| 64 | + BuildInitialDomain(); |
| 65 | + BuildUpgradedDomain(); |
| 66 | + } |
| 67 | + |
| 68 | + private void BuildInitialDomain() |
| 69 | + { |
| 70 | + var config = BuildConfiguration(); |
| 71 | + PrepareSchema(config.ConnectionInfo); |
| 72 | + var domain = Domain.Build(config); |
| 73 | + using (domain) { |
| 74 | + using (var session = domain.OpenSession()) |
| 75 | + using (var tx = session.OpenTransaction()) { |
| 76 | + _ = new M.Schema1.Entity1 { OriginalSchemaName = Schema1Name }; |
| 77 | + _ = new M.Schema2.Entity2 { OriginalSchemaName = schema1UpperCaseName }; |
| 78 | + tx.Complete(); |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + private void BuildUpgradedDomain() |
| 84 | + { |
| 85 | + var config = BuildConfiguration(); |
| 86 | + config.UpgradeMode = DomainUpgradeMode.PerformSafely; |
| 87 | + var domain = Domain.Build(config); |
| 88 | + using (domain) { |
| 89 | + using (var session = domain.OpenSession()) |
| 90 | + using (var tx = session.OpenTransaction()) { |
| 91 | + var e1 = session.Query.All<M.Schema1.Entity1>().Single(); |
| 92 | + var e2 = session.Query.All<M.Schema2.Entity2>().Single(); |
| 93 | + Assert.That(e1.OriginalSchemaName, Is.EqualTo(Schema1Name)); |
| 94 | + Assert.That(e2.OriginalSchemaName, Is.EqualTo(schema1UpperCaseName)); |
| 95 | + tx.Complete(); |
| 96 | + } |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | + private void PrepareSchema(ConnectionInfo connectionInfo) |
| 101 | + { |
| 102 | + StorageTestHelper.DemandSchemas( |
| 103 | + connectionInfo, Schema1Name, schema1UpperCaseName); |
| 104 | + } |
| 105 | + } |
| 106 | +} |
0 commit comments