public void WhenSubscribedToAfterBindThenRaiseEventForEachMapping()
		{
			var listOfCalls = new List<BindMappingEventArgs>();
			var configuration = new Configuration();
			configuration.DataBaseIntegration(x => x.Dialect<MsSql2008Dialect>());
			configuration.AfterBindMapping += (sender, args) => { Assert.That(sender, Is.SameAs(configuration)); listOfCalls.Add(args); };

			configuration.AddXmlString(ProductLineMapping);
			configuration.AddXmlString(ModelMapping);

			Assert.That(listOfCalls.Count, Is.EqualTo(2));
			Assert.That(listOfCalls.Select(x => x.FileName).All(x => x != null), Is.True);
			Assert.That(listOfCalls.Select(x => x.Mapping).All(x => x != null), Is.True);
			Assert.That(listOfCalls.Select(x => x.Dialect).All(x => x.GetType() == typeof(MsSql2008Dialect)), Is.True);
		}
		public void WhenSubscribedToAfterBindThenRaiseEventForEachMapping()
		{
			var listOfCalls = new List<BindMappingEventArgs>();
			var configuration = new Configuration();
			configuration.DataBaseIntegration(x => x.Dialect<MsSql2008Dialect>());
			configuration.AfterBindMapping += (sender, args) => { sender.Should().Be.SameInstanceAs(configuration); listOfCalls.Add(args); };

			configuration.AddXmlString(ProductLineMapping);
			configuration.AddXmlString(ModelMapping);

			listOfCalls.Count.Should().Be(2);
			listOfCalls.Select(x => x.FileName).All(x => x.Satisfy(filename => filename != null));
			listOfCalls.Select(x => x.Mapping).All(x => x.Satisfy(mappingDoc => mappingDoc != null));
			listOfCalls.Select(x => x.Dialect).All(x => x.Satisfy(dialect => dialect.GetType() == typeof(MsSql2008Dialect)));
		}
Esempio n. 3
0
		public void ExposeBug()
		{
	
			string hbm =
@"<?xml version='1.0' encoding='utf-8' ?> 
<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2'
								namespace='NHibernate.Test.NHSpecificTest.NH1290'
								assembly='NHibernate.Test'>
	<database-object>
		<definition class='AuxType'/>
	</database-object>
</hibernate-mapping>";

			Configuration cfg = new Configuration();
			cfg.AddXmlString(hbm);
			// the mapping is added without problem
		}
		public void PersisterWithDefaultNamespaceAndAssembly()
		{
			string hbm = @"<?xml version='1.0' encoding='utf-8' ?> 
							<hibernate-mapping xmlns='urn:nhibernate-mapping-2.0'
								namespace='NHibernate.DomainModel'
								assembly='NHibernate.DomainModel'>
								<class name='A' persister='A'>
									<id name='Id'>
										<generator class='native' />
									</id>
								</class>
							</hibernate-mapping>";

			Configuration cfg = new Configuration();
			cfg.AddXmlString( hbm );
		}
		private static void AddXmlString(Configuration config, string xml, ActiveRecordModel model)
		{
			try
			{
				config.AddXmlString(xml);
			}
			catch(Exception ex)
			{
				throw new ActiveRecordException(
					"Error adding information from class " + model.Type.FullName +
					" to NHibernate. Check the inner exception for more information", ex);
			}
		}
		public void DisabledProxyValidator()
		{
			string hbm =
				@"<?xml version='1.0' ?>
<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2'>
	<class name='NHibernate.DomainModel.NHSpecific.InvalidProxyClass, NHibernate.DomainModel'
		lazy='true'>
		<id name='Id' column='somecolumn'>
			<generator class='native' />
		</id>
	</class>
</hibernate-mapping>";

			Configuration cfg = new Configuration();
			cfg.Properties[Environment.UseProxyValidator] = "false";
			cfg.AddXmlString(hbm).BuildSessionFactory();
		}
		public void ProxyValidator()
		{
			string hbm =
				@"<?xml version='1.0' ?>
<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2'>
	<class name='NHibernate.DomainModel.NHSpecific.InvalidProxyClass, NHibernate.DomainModel'
		lazy='true'>
		<id name='Id' column='somecolumn'>
			<generator class='native' />
		</id>
	</class>
</hibernate-mapping>";

			Configuration cfg = new Configuration();

			try
			{
				cfg.AddXmlString(hbm).BuildSessionFactory();
				Assert.Fail("Validation should have failed");
			}
			catch (MappingException e)
			{
				Assert.IsTrue(e is InvalidProxyTypeException);
			}
		}
Esempio n. 8
0
        private ISessionFactory PrepareNHSessionFactory()
        {
            lock (_sessionFactoryLock)
            {
                if (_sessionFactory != null)
                    return _sessionFactory;

                var sw = Stopwatch.StartNew();

                var forceLoadObjectModel = _domainObjectModel.ObjectModel; // This is needed for "new Configuration()".
                var configuration = new Configuration();
                configuration.SetProperty("connection.provider", "NHibernate.Connection.DriverConnectionProvider");
                configuration.SetProperty("connection.connection_string", _connectionString);

                if (SqlUtility.DatabaseLanguage == "MsSql")
                {
                    configuration.SetProperty("dialect", "NHibernate.Dialect.MsSql2005Dialect");
                    configuration.SetProperty("connection.driver_class", "NHibernate.Driver.SqlClientDriver");
                }
                else if (SqlUtility.DatabaseLanguage == "Oracle")
                {
                    configuration.SetProperty("dialect", "NHibernate.Dialect.Oracle10gDialect");
                    configuration.SetProperty("connection.driver_class", "NHibernate.Driver.OracleDataClientDriver");
                }
                else
                    throw new FrameworkException(DatabaseLanguageError);

                ResolveEventHandler resolveAssembly = (s, args) => _domainObjectModel.ObjectModel;
                try
                {
                    AppDomain.CurrentDomain.AssemblyResolve += resolveAssembly;
                    configuration.AddXmlString(_nHibernateMapping.GetMapping());
                }
                finally
                {
                    AppDomain.CurrentDomain.AssemblyResolve -= resolveAssembly;
                }

                foreach (var configurationExtension in _nHibernateConfigurationExtensions)
                    configurationExtension.ExtendConfiguration(configuration);

                SchemaMetadataUpdater.QuoteTableAndColumns(configuration);
                var sessionFactory = configuration.BuildSessionFactory();

                _performanceLogger.Write(sw, "NHibernatePersistenceEngine.PrepareNHSessionFactory");
                return sessionFactory;
            }
        }