public void SimpleCaseWithKeyAndProperties() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel model = builder.Create(typeof(ClassA)); Assert.IsNotNull(model); SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models); semanticVisitor.VisitNode(model); XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor(); xmlVisitor.CreateXml(model); String xml = xmlVisitor.Xml; String expected = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" + "<hibernate-mapping xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:nhibernate-mapping-2.0\">\r\n" + " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassA, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClassA\" >\r\n" + " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" + " <generator class=\"native\">\r\n" + " </generator>\r\n" + " </id>\r\n" + " <property name=\"Name1\" access=\"property\" column=\"Name1\" type=\"String\" insert=\"false\" update=\"false\" />\r\n" + " <property name=\"Name2\" access=\"property\" column=\"Name2\" type=\"String\" unsaved-value=\"hammett\" />\r\n" + " <property name=\"Name3\" access=\"property\" column=\"Name3\" type=\"String\" not-null=\"true\" unique=\"true\" />\r\n" + " <property name=\"Text\" access=\"property\" column=\"Text\" type=\"StringClob\" />\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); }
public void SimpleCaseWithNestedComponent() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel model = builder.Create(typeof(SimpleNestedComponent)); Assert.IsNotNull(model); SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models); semanticVisitor.VisitNode(model); XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor(); xmlVisitor.CreateXml(model); String xml = xmlVisitor.Xml; const string expected = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" + "<hibernate-mapping auto-import=\"true\" default-lazy=\"false\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:nhibernate-mapping-2.2\">\r\n" + " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.SimpleNestedComponent, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"SimpleNestedComponent\">\r\n" + " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" + " <generator class=\"native\">\r\n" + " </generator>\r\n" + " </id>\r\n" + " <component name=\"Nested\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.NestedComponent, Castle.ActiveRecord.Framework.Internal.Tests\" access=\"property\">\r\n" + " <parent name=\"Parent\"/>\r\n" + " <property name=\"NestedProperty\" access=\"property\" type=\"String\">\r\n" + " <column name=\"NestedProperty\"/>\r\n" + " </property>\r\n" + " </component>\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); }
public void SimpleClassWithMappedFieldAndNonDefaultAccess() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel model = builder.Create(typeof(ClassWithMappedField)); Assert.IsNotNull(model); SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models); semanticVisitor.VisitNode(model); XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor(); xmlVisitor.CreateXml(model); String xml = xmlVisitor.Xml; String expected = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" + "<hibernate-mapping xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:nhibernate-mapping-2.0\">\r\n" + " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassWithMappedField, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClassWithMappedField\" >\r\n" + " <id name=\"Id\" access=\"nosetter.camelcase-underscore\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" + " <generator class=\"native\">\r\n" + " </generator>\r\n" + " </id>\r\n" + " <property name=\"name1\" access=\"field\" column=\"MyCustomName\" type=\"String\" />\r\n" + " <property name=\"Value\" access=\"CustomAccess\" column=\"Value\" type=\"Int32\" />\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); }
public void LazyForClass() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); builder.Create(typeof(ClassWithAnyAttribute)); ActiveRecordModel model = builder.Create(typeof(LazyClass)); Assert.IsNotNull(model); SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models); semanticVisitor.VisitNode(model); XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor(); xmlVisitor.CreateXml(model); String xml = xmlVisitor.Xml; String expected = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" + "<hibernate-mapping xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:nhibernate-mapping-2.0\">\r\n" + " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.LazyClass, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"LazyClass\" lazy=\"true\">\r\n" + " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" + " <generator class=\"native\">\r\n" + " </generator>\r\n" + " </id>\r\n" + " <many-to-one name=\"Clazz\" access=\"property\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassWithAnyAttribute, Castle.ActiveRecord.Framework.Internal.Tests\" column=\"Clazz\" />\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); }
public void AnyAttribute() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel model = builder.Create(typeof(ClassWithAnyAttribute)); Assert.IsNotNull(model); SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models); semanticVisitor.VisitNode(model); XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor(); xmlVisitor.CreateXml(model); String xml = xmlVisitor.Xml; const string expected = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" + "<hibernate-mapping auto-import=\"true\" default-lazy=\"false\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:nhibernate-mapping-2.2\">\r\n" + " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassWithAnyAttribute, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClassWithAnyAttribute\">\r\n" + " <id name=\"Id\" access=\"nosetter.camelcase-underscore\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" + " <generator class=\"native\">\r\n" + " </generator>\r\n" + " </id>\r\n" + " <any name=\"PaymentMethod\" access=\"property\" id-type=\"Int64\" meta-type=\"System.String\" cascade=\"save-update\" not-null=\"true\">\r\n" + " <meta-value value=\"BANK_ACCOUNT\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.BankAccount, Castle.ActiveRecord.Framework.Internal.Tests\" />\r\n" + " <column name=\"BILLING_DETAILS_TYPE\" />\r\n" + " <column name=\"BILLING_DETAILS_ID\" />\r\n" + " </any>\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); }
public void UsingAnyWithoutSpecifyingTheMetaType() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel model = builder.Create(typeof(BadClassWithAnyAttribute)); Assert.IsNotNull(model); Assert.IsNotNull(model); SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models); semanticVisitor.VisitNode(model); }
public void UsingAnyWithoutSpecifyingTheMetaType() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel model = builder.Create(typeof(BadClassWithAnyAttribute)); Assert.IsNotNull(model); Assert.IsNotNull(model); SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models); semanticVisitor.VisitNode(model); }
private string Process(ActiveRecordModelBuilder builder, ActiveRecordModel model) { GraphConnectorVisitor connectorVisitor = new GraphConnectorVisitor(builder.Models); connectorVisitor.VisitNode(model); SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models); semanticVisitor.VisitNode(model); XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor(); xmlVisitor.CreateXml(model); return xmlVisitor.Xml; }
private string Process(ActiveRecordModelBuilder builder, ActiveRecordModel model) { GraphConnectorVisitor connectorVisitor = new GraphConnectorVisitor(builder.Models); connectorVisitor.VisitNode(model); SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models); semanticVisitor.VisitNode(model); XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor(); xmlVisitor.CreateXml(model); return(xmlVisitor.Xml); }
private static void RegisterTypes(ISessionFactoryHolder holder, IConfigurationSource source, IEnumerable <Type> types, bool ignoreProblematicTypes) { lock (lockConfig) { ActiveRecordModelCollection models = BuildModels(holder, source, types, ignoreProblematicTypes); GraphConnectorVisitor connectorVisitor = new GraphConnectorVisitor(models); connectorVisitor.VisitNodes(models); ModelsDelegate modelsCreatedHandler = ModelsCreated; if (modelsCreatedHandler != null) { modelsCreatedHandler(models, source); } SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(models); semanticVisitor.VisitNodes(models); ModelsDelegate modelsValidatedHandler = ModelsValidated; if (modelsValidatedHandler != null) { modelsValidatedHandler(models, source); } AddXmlToNHibernateCfg(holder, models); AddXmlToNHibernateFromAssmebliesAttributes(holder, models); SessionFactoryHolderDelegate registeredInConfigurationHandler = MappingRegisteredInConfiguration; if (registeredInConfigurationHandler != null) { registeredInConfigurationHandler(holder); } if (source.VerifyModelsAgainstDBSchema) { VerifySchema(models); } } }
public void XmlConfigTest() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel model = builder.Create(typeof(Order)); Assert.IsNotNull(model); SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models); semanticVisitor.VisitNode(model); XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor(); xmlVisitor.CreateXml(model); String xml = xmlVisitor.Xml; String expected = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" + "<hibernate-mapping auto-import=\"true\" default-lazy=\"false\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:nhibernate-mapping-2.2\">\r\n" + " <class name=\"Castle.ActiveRecord.Tests.Model.AnyModel.Order, Castle.ActiveRecord.Tests\" table=\"Orders\">\r\n" + " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" + " <generator class=\"native\">\r\n" + " </generator>\r\n" + " </id>\r\n" + " <bag name=\"Payments\" access=\"property\" table=\"payments_table\" lazy=\"false\">\r\n" + " <key column=\"pay_id\" />\r\n" + " <many-to-any id-type=\"Int32\" meta-type=\"System.String\">\r\n" + " <meta-value value=\"BANK_ACCOUNT\" class=\"Castle.ActiveRecord.Tests.Model.AnyModel.BankAccounts, Castle.ActiveRecord.Tests\" />\r\n" + " <meta-value value=\"CREDIT_CARD\" class=\"Castle.ActiveRecord.Tests.Model.AnyModel.CreditCards, Castle.ActiveRecord.Tests\" />\r\n" + " <column name=\"Billing_Details_Type\" />\r\n" + " <column name=\"Billing_Details_Id\" />\r\n" + " </many-to-any>\r\n" + " </bag>\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); }
public void AnyAttribute() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel model = builder.Create(typeof(ClassWithAnyAttribute)); Assert.IsNotNull(model); SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models); semanticVisitor.VisitNode(model); XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor(); xmlVisitor.CreateXml(model); String xml = xmlVisitor.Xml; String expected = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" + "<hibernate-mapping xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:nhibernate-mapping-2.0\">\r\n" + " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassWithAnyAttribute, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClassWithAnyAttribute\" >\r\n" + " <id name=\"Id\" access=\"nosetter.camelcase-underscore\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" + " <generator class=\"native\">\r\n" + " </generator>\r\n" + " </id>\r\n" + " <any name=\"PaymentMethod\" access=\"property\" id-type=\"Int64\" meta-type=\"System.String\" cascade=\"save-update\" >\r\n" + // " <meta-value value=\"CREDIT_CARD\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.CreditCard, Castle.ActiveRecord.Framework.Internal.Tests\" />\r\n" + " <meta-value value=\"BANK_ACCOUNT\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.BankAccount, Castle.ActiveRecord.Framework.Internal.Tests\" />\r\n" + " <column name=\"BILLING_DETAILS_TYPE\" />\r\n" + " <column name=\"BILLING_DETAILS_ID\" />\r\n" + " </any>\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); }
public void HasManyToAnyAttribute() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel model = builder.Create(typeof(ClasssWithHasManyToAny)); Assert.IsNotNull(model); SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models); semanticVisitor.VisitNode(model); XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor(); xmlVisitor.CreateXml(model); String xml = xmlVisitor.Xml; String expected = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" + "<hibernate-mapping xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:nhibernate-mapping-2.0\">\r\n" + " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClasssWithHasManyToAny, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClasssWithHasManyToAny\" >\r\n" + " <id name=\"Id\" access=\"nosetter.camelcase-underscore\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" + " <generator class=\"native\">\r\n" + " </generator>\r\n" + " </id>\r\n" + " <set name=\"PaymentMethod\" access=\"property\" table=\"payments_table\" >\r\n" + " <key column=\"pay_id\" />\r\n" + " <many-to-any id-type=\"Int32\" >\r\n" + " <column name=\"payment_type\" />\r\n" + " <column name=\"payment_method_id\" />\r\n" + " </many-to-any>\r\n" + " </set>\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); }
public void SimpleClassWithMappedFieldAndNonDefaultAccess() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel model = builder.Create(typeof(ClassWithMappedField)); Assert.IsNotNull(model); SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models); semanticVisitor.VisitNode(model); XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor(); xmlVisitor.CreateXml(model); String xml = xmlVisitor.Xml; const string expected = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" + "<hibernate-mapping auto-import=\"true\" default-lazy=\"false\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:nhibernate-mapping-2.2\">\r\n" + " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassWithMappedField, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClassWithMappedField\">\r\n" + " <id name=\"Id\" access=\"nosetter.camelcase-underscore\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" + " <generator class=\"native\">\r\n" + " </generator>\r\n" + " </id>\r\n" + " <property name=\"name1\" access=\"field\" type=\"String\">\r\n" + " <column name=\"MyCustomName\"/>\r\n" + " </property>\r\n" + " <property name=\"Value\" access=\"CustomAccess\" type=\"Int32\">\r\n" + " <column name=\"Value\"/>\r\n" + " </property>\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); }
public void HasManyToAnyAttribute() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel model = builder.Create(typeof(ClasssWithHasManyToAny)); Assert.IsNotNull(model); SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models); semanticVisitor.VisitNode(model); XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor(); xmlVisitor.CreateXml(model); String xml = xmlVisitor.Xml; const string expected = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" + "<hibernate-mapping auto-import=\"true\" default-lazy=\"false\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:nhibernate-mapping-2.2\">\r\n" + " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClasssWithHasManyToAny, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClasssWithHasManyToAny\">\r\n" + " <id name=\"Id\" access=\"nosetter.camelcase-underscore\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" + " <generator class=\"native\">\r\n" + " </generator>\r\n" + " </id>\r\n" + " <set name=\"PaymentMethod\" access=\"property\" table=\"payments_table\" lazy=\"false\">\r\n" + " <key column=\"pay_id\" />\r\n" + " <many-to-any id-type=\"Int32\" meta-type=\"Int32\">\r\n" + " <column name=\"payment_type\" />\r\n" + " <column name=\"payment_method_id\" />\r\n" + " </many-to-any>\r\n" + " </set>\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); }
public void LazyForClass() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); builder.Create(typeof(ClassWithAnyAttribute)); ActiveRecordModel model = builder.Create(typeof(LazyClass)); Assert.IsNotNull(model); SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models); semanticVisitor.VisitNode(model); XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor(); xmlVisitor.CreateXml(model); String xml = xmlVisitor.Xml; const string expected = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" + "<hibernate-mapping auto-import=\"true\" default-lazy=\"false\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:nhibernate-mapping-2.2\">\r\n" + " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.LazyClass, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"LazyClass\" lazy=\"true\">\r\n" + " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" + " <generator class=\"native\">\r\n" + " </generator>\r\n" + " </id>\r\n" + " <many-to-one name=\"Clazz\" access=\"property\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassWithAnyAttribute, Castle.ActiveRecord.Framework.Internal.Tests\" column=\"Clazz\" />\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); }
public void SimpleCaseWithBatch_SelectBeforeUpdate_Locking_Polimorphism() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel model = builder.Create(typeof(ClassWithSomeCustomOptions)); Assert.IsNotNull(model); SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models); semanticVisitor.VisitNode(model); XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor(); xmlVisitor.CreateXml(model); String xml = xmlVisitor.Xml; const string expected = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" + "<hibernate-mapping auto-import=\"true\" default-lazy=\"false\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:nhibernate-mapping-2.2\">\r\n" + " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassWithSomeCustomOptions, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClassA\" select-before-update=\"true\" polymorphism=\"explicit\" batch-size=\"10\" optimistic-lock=\"dirty\">\r\n" + " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" + " <generator class=\"native\">\r\n" + " </generator>\r\n" + " </id>\r\n" + " <property name=\"Name1\" access=\"property\" type=\"String\" insert=\"false\" update=\"false\">\r\n" + " <column name=\"Name1\"/>\r\n" + " </property>\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); }
/// <summary> /// Initialize the mappings using the configuration and /// the list of types /// </summary> public static void Initialize(IConfigurationSource source, params Type[] types) { if (source == null) { throw new ArgumentNullException("source"); } if (types == null) { throw new ArgumentNullException("types"); } // First initialization ISessionFactoryHolder holder = CreateSessionFactoryHolderImplementation(source); holder.ThreadScopeInfo = CreateThreadScopeInfoImplementation(source); RaiseSessionFactoryHolderCreated(holder); ActiveRecordModel.type2Model.Clear(); ActiveRecordBase._holder = holder; // Base configuration SetUpConfiguration(source, typeof(ActiveRecordBase), holder); ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModelCollection models = builder.Models; foreach (Type type in types) { if (models.Contains(type) || type == typeof(ActiveRecordBase) || type == typeof(ActiveRecordValidationBase)) { continue; } else if (type.IsAbstract && typeof(ActiveRecordBase).IsAssignableFrom(type)) { SetUpConfiguration(source, type, holder); continue; } else if (!IsActiveRecordType(type)) { continue; } builder.Create(type); } GraphConnectorVisitor connectorVisitor = new GraphConnectorVisitor(models); connectorVisitor.VisitNodes(models); SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(models); semanticVisitor.VisitNodes(models); XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor(); foreach (ActiveRecordModel model in models) { Configuration cfg = holder.GetConfiguration(holder.GetRootType(model.Type)); if (!model.IsNestedType && !model.IsDiscriminatorSubClass && !model.IsJoinedSubClass) { xmlVisitor.Reset(); xmlVisitor.CreateXml(model); String xml = xmlVisitor.Xml; if (xml != String.Empty) { cfg.AddXmlString(xml); } } } }
public void SimpleCaseWithKeyPropertiesAndDynamicInsertUpdate() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel model = builder.Create(typeof(ClassADynamicInsertUpdate)); Assert.IsNotNull(model); SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models); semanticVisitor.VisitNode(model); XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor(); xmlVisitor.CreateXml(model); String xml = xmlVisitor.Xml; String expected = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" + "<hibernate-mapping auto-import=\"true\" default-lazy=\"false\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:nhibernate-mapping-2.2\">\r\n" + " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassADynamicInsertUpdate, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClassA\" dynamic-update=\"true\" dynamic-insert=\"true\">\r\n" + " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" + " <generator class=\"native\">\r\n" + " </generator>\r\n" + " </id>\r\n" + " <property name=\"Name1\" access=\"property\" type=\"String\" insert=\"false\" update=\"false\">\r\n" + " <column name=\"Name1\"/>\r\n" + " </property>\r\n" + " <property name=\"Name2\" access=\"property\" type=\"String\">\r\n" + " <column name=\"Name2\"/>\r\n" + " </property>\r\n" + " <property name=\"Name3\" access=\"property\" type=\"String\">\r\n" + " <column name=\"Name3\" not-null=\"true\" unique=\"true\"/>\r\n" + " </property>\r\n" + " <property name=\"Text\" access=\"property\" type=\"StringClob\">\r\n" + " <column name=\"Text\"/>\r\n" + " </property>\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); }