private static void AddXmlToNHibernateCfg(ISessionFactoryHolder holder, ActiveRecordModelCollection models) { XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor(); AssemblyXmlGenerator assemblyXmlGenerator = new AssemblyXmlGenerator(); ISet assembliesGeneratedXmlFor = new HashedSet(); foreach (ActiveRecordModel model in models) { Configuration config = holder.GetConfiguration(holder.GetRootType(model.Type)); if (config == null) { throw new ActiveRecordException( string.Format( "Could not find configuration for {0} or its root type {1} this is usually an indication that the configuration has not been setup correctly.", model.Type, holder.GetRootType(model.Type))); } if (!model.IsNestedType && !model.IsDiscriminatorSubClass && !model.IsJoinedSubClass) { xmlVisitor.Reset(); xmlVisitor.CreateXml(model); String xml = xmlVisitor.Xml; if (xml != String.Empty) { AddXmlString(config, xml, model); } } } }
public void CanGetCustomValueFromRawXmlDerivedAttribute() { string expected = @"<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2'> <import class='Castle.ActiveRecord.Framework.Internal.Tests.ImportClassRow2, Castle.ActiveRecord.Framework.Internal.Tests' rename='ImportClassRow2'/> </hibernate-mapping>"; AssemblyXmlGenerator generator = new AssemblyXmlGenerator(); string[] xmlConfigurations = generator.CreateXmlConfigurations(typeof(AssemblyXmlGenerationTestCase).Assembly); string actual = xmlConfigurations[1]; Assert.AreEqual(expected, actual); }
private static void AddXmlToNHibernateFromAssmebliesAttributes(ISessionFactoryHolder holder, ActiveRecordModelCollection models) { Iesi.Collections.Generic.ISet <Assembly> assembliesGeneratedXmlFor = new HashedSet <Assembly>(); AssemblyXmlGenerator assemblyXmlGenerator = new AssemblyXmlGenerator(); foreach (ActiveRecordModel model in models) { if (assembliesGeneratedXmlFor.Contains(model.Type.Assembly)) { continue; } assembliesGeneratedXmlFor.Add(model.Type.Assembly); Configuration config = holder.GetConfiguration(holder.GetRootType(model.Type)); string[] configurations = assemblyXmlGenerator.CreateXmlConfigurations(model.Type.Assembly); foreach (string xml in configurations) { if (xml != string.Empty) { config.AddXmlString(xml); } } } foreach (Assembly assembly in registeredAssemblies) { if (assembliesGeneratedXmlFor.Contains(assembly)) { continue; } assembliesGeneratedXmlFor.Add(assembly); Configuration config = holder.GetConfiguration(holder.GetRootType(typeof(ActiveRecordBase))); string[] configurations = assemblyXmlGenerator.CreateXmlConfigurations(assembly); foreach (string xml in configurations) { if (xml != string.Empty) { config.AddXmlString(xml); } } } }
public void GenerateHqlQueryAndImportsFromAssembly() { AssemblyXmlGenerator generator = new AssemblyXmlGenerator(); string[] xmlConfigurations = generator.CreateXmlConfigurations(typeof(AssemblyXmlGenerationTestCase).Assembly); string actual = xmlConfigurations[0]; string expected = "<?xml version=\"1.0\" encoding=\"utf-16\"?>"+ "<hibernate-mapping xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:nhibernate-mapping-2.2\">"+ "<import class=\"Castle.ActiveRecord.Framework.Internal.Tests.ImportClassRow, Castle.ActiveRecord.Framework.Internal.Tests\" rename=\"ImportClassRow\"/>\r\n"+ " <query name='allAdultUsers'>\r\n"+ " <![CDATA[from User user where user.Age > 21]]>\r\n"+ " </query>\r\n"+ "</hibernate-mapping>\r\n" ; Assert.AreEqual(expected, actual); }
public void GenerateHqlQueryAndImportsFromAssembly() { AssemblyXmlGenerator generator = new AssemblyXmlGenerator(); string[] xmlConfigurations = generator.CreateXmlConfigurations(typeof(AssemblyXmlGenerationTestCase).Assembly); string actual = xmlConfigurations[0]; string expected = "<?xml version=\"1.0\" encoding=\"utf-16\"?>" + "<hibernate-mapping xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:nhibernate-mapping-2.2\">" + "<import class=\"Castle.ActiveRecord.Framework.Internal.Tests.ImportClassRow, Castle.ActiveRecord.Framework.Internal.Tests\" rename=\"ImportClassRow\"/>\r\n" + " <query name='allAdultUsers'>\r\n"+ " <![CDATA[from User user where user.Age > 21]]>\r\n"+ " </query>\r\n"+ "\r\n" + " <sql-query name='allAdultUsersSql'>\r\n"+ " <![CDATA[select * from Users where Age > 21]]>\r\n"+ " </sql-query>\r\n"+ "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, actual); }