public void BuildingSessionFactoryShouldNotThrows()
        {
            Configuration cfg = TestConfigurationHelper.GetDefaultConfiguration();

            cfg.AddMapping(GetMappings());
            cfg.Executing(c => c.BuildSessionFactory()).NotThrows();
        }
Beispiel #2
0
        public void CurrentTimestampSelection()
        {
            var conf = TestConfigurationHelper.GetDefaultConfiguration();

            Dialect.Dialect dialect = Dialect.Dialect.GetDialect(conf.Properties);
            if (!dialect.SupportsCurrentTimestampSelection)
            {
                Assert.Ignore("This test does not apply to " + dialect.GetType().FullName);
            }
            var sessions = (ISessionFactoryImplementor)conf.BuildSessionFactory();

            sessions.ConnectionProvider.Configure(conf.Properties);
            IDriver driver = sessions.ConnectionProvider.Driver;

            using (var connection = sessions.ConnectionProvider.GetConnection())
            {
                var statement = driver.GenerateCommand(CommandType.Text, new SqlString(dialect.CurrentTimestampSelectString), Array.Empty <SqlType>());
                statement.Connection = connection;
                using (var reader = statement.ExecuteReader())
                {
                    Assert.That(reader.Read(), "should return one record");
                    Assert.That(reader[0], Is.InstanceOf <DateTime>());
                }
            }
        }
Beispiel #3
0
        private void MigrateSchema(string resource1, string resource2)
        {
            Configuration v1cfg = TestConfigurationHelper.GetDefaultConfiguration();

            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource1))
                v1cfg.AddInputStream(stream);
            new SchemaExport(v1cfg).Execute(false, true, true);

            Tool.hbm2ddl.SchemaUpdate v1schemaUpdate = new Tool.hbm2ddl.SchemaUpdate(v1cfg);
            v1schemaUpdate.Execute(true, true);

            foreach (Exception e in v1schemaUpdate.Exceptions)
            {
                Console.WriteLine(e);
            }

            Assert.AreEqual(0, v1schemaUpdate.Exceptions.Count);

            Configuration v2cfg = TestConfigurationHelper.GetDefaultConfiguration();

            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource2))
                v2cfg.AddInputStream(stream);

            Tool.hbm2ddl.SchemaUpdate v2schemaUpdate = new Tool.hbm2ddl.SchemaUpdate(v2cfg);
            v2schemaUpdate.Execute(true, true);

            foreach (Exception e in v2schemaUpdate.Exceptions)
            {
                Console.WriteLine(e);
            }

            Assert.AreEqual(0, v2schemaUpdate.Exceptions.Count);
        }
        public async Task ExplicitAutoQuoteAsync()
        {
            var configuration = TestConfigurationHelper.GetDefaultConfiguration();

            configuration.AddResource("NHibernate.Test.Tools.hbm2ddl.SchemaMetadataUpdaterTest.HeavyEntity.hbm.xml",
                                      GetType().Assembly);

            var dialect = Dialect.Dialect.GetDialect(configuration.GetDerivedProperties());

            dialect.Keywords.Add("Abracadabra");

            await(SchemaMetadataUpdater.UpdateAsync(configuration, dialect, CancellationToken.None));
            SchemaMetadataUpdater.QuoteTableAndColumns(configuration, dialect);

            var cm = configuration.GetClassMapping(typeof(Order));

            Assert.That(cm.Table.IsQuoted);
            var culs = new List <Column>(cm.Table.ColumnIterator);

            Assert.That(GetColumnByName(culs, "From").IsQuoted);
            Assert.That(GetColumnByName(culs, "And").IsQuoted);
            Assert.That(GetColumnByName(culs, "Select").IsQuoted);
            Assert.That(GetColumnByName(culs, "Abracadabra").IsQuoted);
            Assert.That(!GetColumnByName(culs, "Name").IsQuoted);
        }
        public void UpdateReservedWordsInDialect()
        {
            var reservedDb       = new HashedSet <string>();
            var configuration    = TestConfigurationHelper.GetDefaultConfiguration();
            var dialect          = Dialect.Dialect.GetDialect(configuration.Properties);
            var connectionHelper = new ManagedProviderConnectionHelper(configuration.Properties);

            connectionHelper.Prepare();
            try
            {
                var metaData = dialect.GetDataBaseSchema(connectionHelper.Connection);
                foreach (var rw in metaData.GetReservedWords())
                {
                    reservedDb.Add(rw.ToLowerInvariant());
                }
            }
            finally
            {
                connectionHelper.Release();
            }

            var sf = (ISessionFactoryImplementor)configuration.BuildSessionFactory();

            SchemaMetadataUpdater.Update(sf);
            var match = reservedDb.Intersect(sf.Dialect.Keywords);

            Assert.That(match, Is.EquivalentTo(reservedDb));
        }
Beispiel #6
0
        public void WhenUpdateCalledExplicitlyThenTakeInAccountHbm2DdlKeyWordsSetting()
        {
            var configuration = TestConfigurationHelper.GetDefaultConfiguration();
            var dialect       = NHibernate.Dialect.Dialect.GetDialect(configuration.Properties);

            if (!(dialect is MsSql2000Dialect))
            {
                Assert.Ignore(GetType() + " does not apply to " + dialect);
            }

            configuration.SetProperty(Environment.Hbm2ddlKeyWords, "auto-quote");
            configuration.AddResource("NHibernate.Test.Tools.hbm2ddl.SchemaMetadataUpdaterTest.HeavyEntity.hbm.xml",
                                      GetType().Assembly);

            var script = new StringBuilder();

            new Tool.hbm2ddl.SchemaUpdate(configuration).Execute(s => script.AppendLine(s), false);

            // With SchemaUpdate the auto-quote method should be called and the conf. should hold quoted stuff
            var cm   = configuration.GetClassMapping(typeof(Order));
            var culs = cm.Table.ColumnIterator.ToList();

            Assert.That(cm.Table.IsQuoted, Is.True);
            Assert.That(culs.First(c => "From" == c.Name).IsQuoted, Is.True);
            Assert.That(culs.First(c => "And" == c.Name).IsQuoted, Is.True);
            Assert.That(culs.First(c => "Select" == c.Name).IsQuoted, Is.True);
            Assert.That(culs.First(c => "Column" == c.Name).IsQuoted, Is.True);
        }
        public async Task AutoQuoteTableAndColumnsAtStratupIncludeKeyWordsImportAsync()
        {
            var reservedDb       = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            var configuration    = TestConfigurationHelper.GetDefaultConfiguration();
            var dialect          = Dialect.Dialect.GetDialect(configuration.Properties);
            var connectionHelper = new ManagedProviderConnectionHelper(configuration.Properties);

            await(connectionHelper.PrepareAsync(CancellationToken.None));
            try
            {
                var metaData = dialect.GetDataBaseSchema(connectionHelper.Connection);
                foreach (var rw in metaData.GetReservedWords())
                {
                    reservedDb.Add(rw.ToLowerInvariant());
                }
            }
            finally
            {
                connectionHelper.Release();
            }

            configuration.SetProperty(Environment.Hbm2ddlKeyWords, "auto-quote");
            configuration.AddResource("NHibernate.Test.Tools.hbm2ddl.SchemaMetadataUpdaterTest.HeavyEntity.hbm.xml",
                                      GetType().Assembly);
            var sf    = (ISessionFactoryImplementor)configuration.BuildSessionFactory();
            var match = reservedDb.Intersect(sf.Dialect.Keywords, StringComparer.OrdinalIgnoreCase);

            Assert.That(match, Is.EquivalentTo(reservedDb).IgnoreCase);
        }
Beispiel #8
0
        public void WithSpecificValuesInMapping()
        {
            Configuration cfg = TestConfigurationHelper.GetDefaultConfiguration();

            cfg.AddResource("NHibernate.Test.NHSpecificTest.NH1443.AclassWithSpecific.hbm.xml", GetType().Assembly);
            Bug(cfg);
        }
        public async Task CanWorkWithAutoQuoteTableAndColumnsAtStratupAsync()
        {
            var configuration = TestConfigurationHelper.GetDefaultConfiguration();

            configuration.SetProperty(Environment.Hbm2ddlKeyWords, "auto-quote");
            configuration.SetProperty(Environment.Hbm2ddlAuto, "create-drop");
            configuration.AddResource("NHibernate.Test.Tools.hbm2ddl.SchemaMetadataUpdaterTest.HeavyEntity.hbm.xml",
                                      GetType().Assembly);
            var sf = configuration.BuildSessionFactory();

            using (ISession s = sf.OpenSession())
                using (ITransaction t = s.BeginTransaction())
                {
                    await(s.SaveAsync(new Order {
                        From = "from", Column = "column", And = "order"
                    }));
                    await(t.CommitAsync());
                }

            using (ISession s = sf.OpenSession())
                using (ITransaction t = s.BeginTransaction())
                {
                    await(s.DeleteAsync("from Order"));
                    await(t.CommitAsync());
                }

            TestCase.DropSchema(false, new SchemaExport(configuration), (ISessionFactoryImplementor)sf);
        }
Beispiel #10
0
        public void CanCreateSchemaWithCompositeIdWithKeyManyToOneUsesEntityName()
        {
            var cfg = TestConfigurationHelper.GetDefaultConfiguration();

            cfg.AddResource("NHibernate.Test.NHSpecificTest.NH3793.Mappings.hbm.xml", GetType().Assembly);
            Assert.DoesNotThrow(() => cfg.BuildMappings());
        }
        public async Task UpdateReservedWordsInDialectAsync()
        {
            var reservedDb       = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            var configuration    = TestConfigurationHelper.GetDefaultConfiguration();
            var dialect          = Dialect.Dialect.GetDialect(configuration.Properties);
            var connectionHelper = new ManagedProviderConnectionHelper(configuration.Properties);

            await(connectionHelper.PrepareAsync(CancellationToken.None));
            try
            {
                var metaData = dialect.GetDataBaseSchema(connectionHelper.Connection);
                foreach (var rw in metaData.GetReservedWords())
                {
                    reservedDb.Add(rw.ToLowerInvariant());
                }
            }
            finally
            {
                connectionHelper.Release();
            }

            var sf = (ISessionFactoryImplementor)configuration.BuildSessionFactory();

            await(SchemaMetadataUpdater.UpdateAsync(sf, CancellationToken.None));
            var match = reservedDb.Intersect(sf.Dialect.Keywords, StringComparer.OrdinalIgnoreCase);

            // tests that nothing in the first metaData.GetReservedWords() is left out of the second metaData.GetReservedWords() call.
            // i.e. always passes.
            Assert.That(match, Is.EquivalentTo(reservedDb));
        }
        public void NoBooleanParameters(bool managed)
        {
            var driver = GetDriver(managed, TestConfigurationHelper.GetDefaultConfiguration().Properties);
            var param  = GetParameterForType(driver, SqlTypeFactory.Boolean);

            Assert.That(param.DbType, Is.Not.EqualTo(DbType.Boolean), "should not still be a DbType.Boolean");
        }
        public void BuildingSessionFactoryShouldNotThrows()
        {
            Configuration cfg = TestConfigurationHelper.GetDefaultConfiguration();

            cfg.AddMapping(GetMappings());
            Assert.That(() => cfg.BuildSessionFactory(), Throws.Nothing);
        }
Beispiel #14
0
        public void WhenConfiguredOnlyExplicitAutoQuote()
        {
            var configuration     = TestConfigurationHelper.GetDefaultConfiguration();
            var configuredDialect = Dialect.Dialect.GetDialect();

            if (!configuredDialect.DefaultProperties.ContainsKey(Environment.ConnectionDriver))
            {
                Assert.Ignore(GetType() + " does not apply to " + configuredDialect);
            }
            configuration.Properties.Remove(Environment.ConnectionDriver);
            configuration.AddResource("NHibernate.Test.Tools.hbm2ddl.SchemaMetadataUpdaterTest.HeavyEntity.hbm.xml",
                                      GetType().Assembly);

            SchemaMetadataUpdater.QuoteTableAndColumns(configuration);

            var cm = configuration.GetClassMapping(typeof(Order));

            Assert.That(cm.Table.IsQuoted);
            var culs = new List <Column>(cm.Table.ColumnIterator);

            Assert.That(GetColumnByName(culs, "From").IsQuoted);
            Assert.That(GetColumnByName(culs, "And").IsQuoted);
            Assert.That(GetColumnByName(culs, "Select").IsQuoted);
            Assert.That(!GetColumnByName(culs, "Name").IsQuoted);
        }
Beispiel #15
0
        public void WhenLoadWorngMappingThenMessageShouldContaingWrongClassName()
        {
            Configuration cfg = TestConfigurationHelper.GetDefaultConfiguration();

            cfg.AddResource("NHibernate.Test.NHSpecificTest.NH2313.Mappings.hbm.xml", GetType().Assembly);
            cfg.Executing(c => c.BuildSessionFactory()).Throws <MappingException>().And.ValueOf.Message.Should().Contain("TheOther");
        }
Beispiel #16
0
        public async Task WithSpecificValuesInMappingAsync()
        {
            Configuration cfg = TestConfigurationHelper.GetDefaultConfiguration();

            cfg.AddResource("NHibernate.Test.NHSpecificTest.NH1443.AclassWithSpecific.hbm.xml", GetType().Assembly);
            await(BugAsync(cfg));
        }
Beispiel #17
0
        public void WorkAddingMappings()
        {
            var cfg = TestConfigurationHelper.GetDefaultConfiguration();

            cfg.SetProperty(Environment.CollectionTypeFactoryClass, typeof(CustomCollectionTypeFactory).AssemblyQualifiedName);
            cfg.AddResource("NHibernate.Test.Bytecode.Lightweight.ProductLine.hbm.xml", GetType().Assembly);
            Assert.That(Environment.BytecodeProvider.CollectionTypeFactory, Is.TypeOf <CustomCollectionTypeFactory>());
        }
Beispiel #18
0
        public async Task WithSpecificValuesInMappingAsync()
        {
            Configuration cfg = TestConfigurationHelper.GetDefaultConfiguration();

            CheckDialect(cfg);
            cfg.AddResource("NHibernate.Test.NHSpecificTest.NH1521.AclassWithSpecific.hbm.xml", GetType().Assembly);
            await(AssertThatCheckOnTableExistenceIsCorrectAsync(cfg));
        }
Beispiel #19
0
        public void IndependentSubclassElementCanExtendSubclass()
        {
            Configuration cfg = TestConfigurationHelper.GetDefaultConfiguration();

            Assert.That(() => cfg.AddResource("NHibernate.Test.NHSpecificTest.NH2303.Mappings.hbm.xml", GetType().Assembly), Throws.Nothing);
            cfg.BuildSessionFactory();
            Assert.That(() => cfg.BuildSessionFactory(), Throws.Nothing);
        }
Beispiel #20
0
        public void WithDefaultValuesInMapping()
        {
            Configuration cfg = TestConfigurationHelper.GetDefaultConfiguration();

            CheckDialect(cfg);
            cfg.AddResource("NHibernate.Test.NHSpecificTest.NH1521.AclassWithDefault.hbm.xml", GetType().Assembly);
            AssertThatCheckOnTableExistenceIsCorrect(cfg);
        }
Beispiel #21
0
        public void WhenLoadWorngMappingThenMessageShouldContaingWrongClassName()
        {
            Configuration cfg = TestConfigurationHelper.GetDefaultConfiguration();

            cfg.AddResource("NHibernate.Test.NHSpecificTest.NH2313.Mappings.hbm.xml", GetType().Assembly);
            Assert.That(() => cfg.BuildSessionFactory(), Throws.TypeOf <MappingException>()
                        .And.Message.ContainsSubstring("TheOther"));
        }
        private static Configuration BuildConfiguration(string resource)
        {
            var cfg = TestConfigurationHelper.GetDefaultConfiguration();

            using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource))
                cfg.AddInputStream(stream);
            return(cfg);
        }
Beispiel #23
0
        public void WhenBuildSessionFactoryThenThrows()
        {
            Configuration cfg = TestConfigurationHelper.GetDefaultConfiguration();

            cfg.AddResource("NHibernate.Test.NHSpecificTest.NH2266.Mappings.hbm.xml", GetType().Assembly);
            cfg.Executing(c => c.BuildSessionFactory()).Throws <NotSupportedException>()
            .And.ValueOf.Message.Should().Contain("does not have mapped subclasses").And.Contain(typeof(TemporaryToken).FullName);
        }
Beispiel #24
0
        private Configuration GetConfigurationForMapping(string resourcePath)
        {
            var cfg = TestConfigurationHelper.GetDefaultConfiguration();

            using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourcePath))
                cfg.AddInputStream(stream);
            return(cfg);
        }
Beispiel #25
0
        public void GetDecimalTypeName()
        {
            var cfg     = TestConfigurationHelper.GetDefaultConfiguration();
            var dialect = Dialect.Dialect.GetDialect(cfg.Properties);

            Assert.That(dialect.GetTypeName(SqlTypeFactory.GetSqlType(DbType.Decimal, 40, 40)), Does.Not.Contain("40"), "oversized decimal");
            // This regex tests wether the type is qualified with expected length/precision/scale or not qualified at all.
            Assert.That(dialect.GetTypeName(SqlTypeFactory.GetSqlType(DbType.Decimal, 3, 2)), Does.Match(@"^[^(]*(\(\s*3\s*,\s*2\s*\))?\s*$"), "small decimal");
        }
Beispiel #26
0
        public void WhenBuildSessionFactoryThenThrows()
        {
            Configuration cfg = TestConfigurationHelper.GetDefaultConfiguration();

            cfg.AddResource("NHibernate.Test.NHSpecificTest.NH2266.Mappings.hbm.xml", GetType().Assembly);
            Assert.That(() => cfg.BuildSessionFactory(), Throws.TypeOf <NotSupportedException>()
                        .And.Message.ContainsSubstring("does not have mapped subclasses")
                        .And.Message.ContainsSubstring(typeof(TemporaryToken).FullName));
        }
Beispiel #27
0
        public void WithDefaultValuesInConfiguration()
        {
            Configuration cfg = TestConfigurationHelper.GetDefaultConfiguration();

            cfg.AddResource("NHibernate.Test.NHSpecificTest.NH1443.AclassWithNothing.hbm.xml", GetType().Assembly);
            cfg.SetProperty(Environment.DefaultCatalog, "nhibernate");
            cfg.SetProperty(Environment.DefaultSchema, "dbo");
            Bug(cfg);
        }
Beispiel #28
0
        public void WithDefaultValuesInConfigurationPriorityToMapping()
        {
            Configuration cfg = TestConfigurationHelper.GetDefaultConfiguration();

            cfg.AddResource("NHibernate.Test.NHSpecificTest.NH1443.AclassWithDefault.hbm.xml", GetType().Assembly);
            cfg.SetProperty(Environment.DefaultCatalog, "somethingDifferent");
            cfg.SetProperty(Environment.DefaultSchema, "somethingDifferent");
            Bug(cfg);
        }
Beispiel #29
0
        public async Task TestForClassWithDefaultSchemaAsync()
        {
            Configuration cfg = TestConfigurationHelper.GetDefaultConfiguration();

            CheckDialect(cfg);
            cfg.AddResource("NHibernate.Test.NHSpecificTest.NH1521.AclassWithNothing.hbm.xml", GetType().Assembly);
            cfg.SetProperty(Environment.DefaultCatalog, "nhibernate");
            cfg.SetProperty(Environment.DefaultSchema, "dbo");
            await(AssertThatCheckOnTableExistenceIsCorrectAsync(cfg));
        }
Beispiel #30
0
        public async Task WithDefaultValuesInConfigurationPriorityToMappingAsync()
        {
            Configuration cfg = TestConfigurationHelper.GetDefaultConfiguration();

            CheckDialect(cfg);
            cfg.AddResource("NHibernate.Test.NHSpecificTest.NH1521.AclassWithDefault.hbm.xml", GetType().Assembly);
            cfg.SetProperty(Environment.DefaultCatalog, "somethingDifferent");
            cfg.SetProperty(Environment.DefaultSchema, "somethingDifferent");
            await(AssertThatCheckOnTableExistenceIsCorrectAsync(cfg));
        }