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 JoinedSubClassUse() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); builder.Create(typeof(ClassJoinedSubClassA)); ActiveRecordModel model = builder.Create(typeof(ClassJoinedSubClassParent)); Assert.IsNotNull(model); String xml = Process(builder, model); 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.ClassJoinedSubClassParent, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"disctable\" >\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=\"Name\" access=\"property\" column=\"Name\" type=\"String\" />\r\n" + " <joined-subclass name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassJoinedSubClassA, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"disctablea\" >\r\n" + " <key column=\"AId\" />\r\n" + " <property name=\"Age\" access=\"property\" column=\"Age\" type=\"Int32\" />\r\n" + " </joined-subclass>\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 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 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 ImportsGeneration() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel model = builder.Create(typeof(ImportClass)); Assert.IsNotNull(model); string xml = Process(builder, model); 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" + " <import class=\"Castle.ActiveRecord.Framework.Internal.Tests.ImportClassRow, Castle.ActiveRecord.Framework.Internal.Tests\" rename=\"ImportClassRow\" />\r\n" + " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ImportClass, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ImportClass\" lazy=\"false\">\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=\"Name\" access=\"property\" type=\"String\">\r\n" + " <column name=\"Name\" />\r\n" + " </property>\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); }
public void HasManyInfering() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel model = builder.Create(typeof(Category)); Assert.IsNotNull(model); String xml = Process(builder, model); 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.Category, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"Category\" >\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=\"Name\" access=\"property\" column=\"Name\" type=\"String\" />\r\n" + " <many-to-one name=\"Parent\" access=\"property\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.Category, Castle.ActiveRecord.Framework.Internal.Tests\" column=\"parent_id\" />\r\n" + " <bag name=\"SubCategories\" access=\"property\" table=\"Category\" >\r\n" + " <key column=\"parent_id\" />\r\n" + " <one-to-many class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.Category, Castle.ActiveRecord.Framework.Internal.Tests\" />\r\n" + " </bag>\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); }
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 HasManyWithExplicitInfo() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel model = builder.Create(typeof(HasManyClassA)); Assert.IsNotNull(model); String xml = Process(builder, model); 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.HasManyClassA, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"HasManyClassA\" >\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=\"Items\" access=\"property\" table=\"ClassATable\" inverse=\"true\" >\r\n" + " <key column=\"keycol\" />\r\n" + " <one-to-many class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassA, Castle.ActiveRecord.Framework.Internal.Tests\" />\r\n" + " </bag>\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 CompositeKey() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel model = builder.Create(typeof(ClassWithCompositeKey)); Assert.IsNotNull(model); string xml = Process(builder, model); 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.ClassWithCompositeKey, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClassWithCompositeKey\" >\r\n" + " <composite-id name=\"Key\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.CompositeKeyForClassWithCompositeKey, Castle.ActiveRecord.Framework.Internal.Tests\" unsaved-value=\"none\" access=\"property\">\r\n" + " <key-property name=\"KeyA\" access=\"property\" column=\"KeyA\" type=\"String\" />\r\n" + " <key-property name=\"KeyB\" access=\"property\" column=\"KeyB\" type=\"String\" />\r\n" + " </composite-id>\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); }
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 BelongsTo2() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel model = builder.Create(typeof(BelongsToClassA2)); Assert.IsNotNull(model); String xml = Process(builder, model); 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.BelongsToClassA2, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"BelongsToClassA2\" >\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=\"ClassA\" access=\"property\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassA, Castle.ActiveRecord.Framework.Internal.Tests\" column=\"classa_id\" insert=\"false\" update=\"false\" not-null=\"true\" unique=\"true\" cascade=\"save-update\" />\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); }
public void SequenceParamClass() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel model = builder.Create(typeof(SequenceParamClass)); Assert.IsNotNull(model); String xml = Process(builder, model); 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.SequenceParamClass, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"SequenceParamClass\" >\r\n" + " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" + " <generator class=\"sequence\">\r\n" + " <param name=\"sequence\">my_seq</param>\r\n" + " </generator>\r\n" + " </id>\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 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 JoinedSubClassUseWithGenericTypeAndGenericAbstractBase() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); builder.Create(typeof(GenSubClassJoinedClass)); ActiveRecordModel model = builder.Create(typeof(GenBaseJoinedClass<GenSubClassJoinedClass>)); Assert.IsNotNull(model); String xml = Process(builder, model); 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.GenBaseJoinedClass`1[[Castle.ActiveRecord.Framework.Internal.Tests.Model.GenSubClassJoinedClass, Castle.ActiveRecord.Framework.Internal.Tests, Version=1.0.3.0, Culture=neutral, PublicKeyToken=null]], Castle.ActiveRecord.Framework.Internal.Tests\" table=\"disctable\">\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=\"Name\" access=\"property\" type=\"String\">\r\n" + " <column name=\"Name\"/>\r\n" + " </property>\r\n" + " <joined-subclass name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.GenSubClassJoinedClass, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"disctablea\" lazy=\"false\">\r\n" + " <key column=\"AId\" />\r\n" + " <property name=\"Age\" access=\"property\" type=\"Int32\">\r\n" + " <column name=\"Age\"/>\r\n" + " </property>\r\n" + " </joined-subclass>\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); }
public void BelongsTo2() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel model = builder.Create(typeof(BelongsToClassA2)); Assert.IsNotNull(model); String xml = Process(builder, model); 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.BelongsToClassA2, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"BelongsToClassA2\" lazy=\"false\">\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=\"ClassA\" access=\"property\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassA, Castle.ActiveRecord.Framework.Internal.Tests\" column=\"classa_id\" insert=\"false\" update=\"false\" not-null=\"true\" unique=\"true\" foreign-key=\"FK_FOREIGN_KEY_B\" cascade=\"save-update\" />\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); }
public void DiscriminatorLengthUse() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); builder.Create(typeof(ClassDiscriminatorB)); ActiveRecordModel model = builder.Create(typeof(ClassDiscriminatorLengthParent)); Assert.IsNotNull(model); String xml = Process(builder, model); 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.ClassDiscriminatorLengthParent, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"disctable\" discriminator-value=\"parent\">\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" + " <discriminator column=\"type\" type=\"String\" length=\"10\" />\r\n" + " <property name=\"Name\" access=\"property\" type=\"String\">\r\n" + " <column name=\"Name\"/>\r\n" + " </property>\r\n" + " <subclass name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassDiscriminatorB, Castle.ActiveRecord.Framework.Internal.Tests\" discriminator-value=\"B\">\r\n" + " <property name=\"Age\" access=\"property\" type=\"Int32\">\r\n" + " <column name=\"Age\"/>\r\n" + " </property>\r\n" + " </subclass>\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); }
public void HasManyWithBatch() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel model = builder.Create(typeof(HasManyWithBatch)); Assert.IsNotNull(model); String xml = Process(builder, model); 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.HasManyWithBatch, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"HasManyWithBatch\" lazy=\"false\">\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=\"Items\" access=\"property\" table=\"ClassATable\" lazy=\"false\" inverse=\"true\" batch-size=\"3\">\r\n" + " <key column=\"keycol\" />\r\n" + " <one-to-many class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassA, Castle.ActiveRecord.Framework.Internal.Tests\" />\r\n" + " </bag>\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); }
public void CompositeClassWithBelongsTo() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel model = builder.Create(typeof(ClassWithCompositeKey3)); Assert.IsNotNull(model); String xml = Process(builder, model); 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.ClassWithCompositeKey3, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClassWithCompositeKey3\" lazy=\"false\">\r\n" + " <composite-id name=\"Key\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.CompositeKey2, Castle.ActiveRecord.Framework.Internal.Tests\" unsaved-value=\"none\" access=\"property\">\r\n" + " <key-property name=\"Key1\" access=\"property\" column=\"Key1\" type=\"Int32\" />\r\n" + " <key-many-to-one name=\"Key2\" access=\"property\" column=\"Key2\" type=\"String\" />\r\n" + " </composite-id>\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); }
public void SimpleClassWithGuessedEnumElementList() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel model = builder.Create(typeof(EnumModel)); Assert.IsNotNull(model); String xml = Process(builder, model); 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.EnumModel, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"EnumModel\">\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=\"Roles\" access=\"property\" table=\"Roles\" lazy=\"false\">\r\n" + " <key column=\"EnumModelId\" />\r\n" + " <element column=\"RoleId\" type=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.Role, Castle.ActiveRecord.Framework.Internal.Tests\"/>\r\n" + " </bag>\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 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 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); }
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 IdBagPrimitive() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel model = builder.Create(typeof(IdBagPrimitive)); Assert.IsNotNull(model); String xml = Process(builder, model); 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.IdBagPrimitive, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"IdBagPrimitive\">\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" + " <idbag name=\"Items\" access=\"property\" table=\"IdToItems\" lazy=\"false\">\r\n" + " <collection-id type=\"Int32\" column=\"col\">\r\n" + " <generator class=\"sequence\">\r\n" + " </generator>\r\n" + " </collection-id>\r\n" + " <key column=\"keyid\" />\r\n" + " <element type=\"System.String\" />\r\n" + " </idbag>\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); }
public void ManyToMayViaComponents() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel model = builder.Create(typeof(HasManyToManyViaComponents)); Assert.IsNotNull(model); String xml = Process(builder, model); 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.HasManyToManyViaComponents, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"HasManyToManyViaComponents\">\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" + " <list name=\"Components\" access=\"property\" table=\"components_to_a\" lazy=\"false\">\r\n" + " <key column=\"id\" />\r\n" + " <index column=\"pos\" />\r\n" + " <composite-element class=\"Castle.ActiveRecord.Framework.Internal.Tests.ComponentManyToClassA, Castle.ActiveRecord.Framework.Internal.Tests\">\r\n" + " <property name=\"Value\" access=\"property\" type=\"String\">\r\n" + " <column name=\"Value\"/>\r\n" + " </property>\r\n" + " <many-to-one name=\"A\" access=\"property\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassA, Castle.ActiveRecord.Framework.Internal.Tests\" column=\"aId\" />\r\n" + " </composite-element>\r\n" + " </list>\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); }
public void HasManyWithDictionary() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel model = builder.Create(typeof(DictionaryModel)); Assert.IsNotNull(model); string xml = Process(builder, model); 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.DictionaryModel, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"DictionaryModel\">\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" + " <map name=\"Snippet\" access=\"property\" table=\"DictionaryModel_Snippet\" lazy=\"false\">\r\n" + " <key column=\"id\" />\r\n" + " <index column=\"LangCode\" type=\"String\" />\r\n" + " <element column=\"Text\" type=\"System.String, mscorlib\"/>\r\n" + " </map>\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); }
public void NotFoundBehaviourClass() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel NotFoundBehaviourClassModel = builder.Create(typeof(NotFoundBehaviourClass)); ActiveRecordModel RelationalFoobarModel = builder.Create(typeof(RelationalFoobar)); Assert.IsNotNull(NotFoundBehaviourClassModel); Assert.IsNotNull(RelationalFoobarModel); String xml = Process(builder, NotFoundBehaviourClassModel); 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.NotFoundBehaviourClass, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"NotFoundBehaviourClass\">\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=\"SubClasses\" access=\"property\" table=\"RelationalFoobarTable\" lazy=\"false\">\r\n" + " <key column=\"keycol\" />\r\n" + " <one-to-many class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.RelationalFoobar, Castle.ActiveRecord.Framework.Internal.Tests\" not-found=\"ignore\" />\r\n" + " </bag>\r\n" + " <bag name=\"ManySubClasses\" access=\"property\" table=\"ManySubClasses\" lazy=\"false\">\r\n" + " <key column=\"id\" />\r\n" + " <many-to-many class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.RelationalFoobar, Castle.ActiveRecord.Framework.Internal.Tests\" column=\"ref_id\" not-found=\"ignore\"/>\r\n" + " </bag>\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); xml = Process(builder, RelationalFoobarModel); 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.RelationalFoobar, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"RelationalFoobar\">\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=\"NotFoundBehaviourClass\" access=\"property\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.NotFoundBehaviourClass, Castle.ActiveRecord.Framework.Internal.Tests\" column=\"NotFoundBehaviourClass\" not-found=\"ignore\" />\r\n" + " <bag name=\"NotFoundBehaviourClassList\" access=\"property\" table=\"ManySubClasses\" lazy=\"false\">\r\n" + " <key column=\"id\" />\r\n" + " <many-to-many class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.NotFoundBehaviourClass, Castle.ActiveRecord.Framework.Internal.Tests\" column=\"ref_id\" not-found=\"ignore\"/>\r\n" + " </bag>\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); }
private static ActiveRecordModelCollection BuildModels(ISessionFactoryHolder holder, IConfigurationSource source, IEnumerable <Type> types, bool ignoreProblematicTypes) { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); builder.SetExtension(new ModelBuilderExtensionComposite(extensions)); ActiveRecordModelCollection models = builder.Models; foreach (Type type in types) { if (ShouldIgnoreType(type)) { if (ignoreProblematicTypes) { continue; } else { throw new ActiveRecordException( String.Format("Type `{0}` is registered already", type.FullName)); } } else if (IsConfiguredAsRootType(type)) { if (TypeDefinesADatabaseBoundary(type)) { SetUpConfiguration(source, type, holder); continue; } else { throw new ActiveRecordException( string.Format( "Type `{0}` is not a valid root type. Make sure it is abstract and does not define a table itself.", type.FullName)); } } else if (!IsActiveRecordType(type)) { if (ignoreProblematicTypes) { continue; } else { throw new ActiveRecordException( String.Format("Type `{0}` is not an ActiveRecord type. Use ActiveRecordAttributes to define one", type.FullName)); } } if (type.ContainsGenericParameters) { // Owing to a restriction in NHibernate the reflection optimiser will not work // if we have generic types so turn it off. Do we have anywhere we could log this? Environment.UseReflectionOptimizer = false; } ActiveRecordModel model = builder.Create(type); if (model == null) { throw new ActiveRecordException( String.Format("ActiveRecordModel for `{0}` could not be created", type.FullName)); } registeredTypes.Add(type, String.Empty); if (ModelCreated != null) { ModelCreated(model, source); } } return(models); }
public void HasManyInfering() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel model = builder.Create(typeof(Category)); Assert.IsNotNull(model); String xml = Process(builder, model); 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.Category, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"Category\" lazy=\"false\">\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=\"Name\" access=\"property\" type=\"String\">\r\n" + " <column name=\"Name\"/>\r\n" + " </property>\r\n" + " <many-to-one name=\"Parent\" access=\"property\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.Category, Castle.ActiveRecord.Framework.Internal.Tests\" column=\"parent_id\" />\r\n" + " <bag name=\"SubCategories\" access=\"property\" table=\"Category\" lazy=\"false\">\r\n" + " <key column=\"parent_id\" />\r\n" + " <one-to-many class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.Category, Castle.ActiveRecord.Framework.Internal.Tests\" />\r\n" + " </bag>\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); }
public void One2OneKey() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel empModel = builder.Create(typeof(Employee)); ActiveRecordModel awardModel = builder.Create(typeof(Award)); Assert.IsNotNull(empModel); Assert.IsNotNull(awardModel); string xml = Process(builder, empModel); 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.Employee, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"Employee\" lazy=\"false\">\r\n" + " <id name=\"ID\" access=\"property\" column=\"EmployeeID\" type=\"Int32\" unsaved-value=\"0\">\r\n" + " <generator class=\"native\">\r\n" + " </generator>\r\n" + " </id>\r\n" + " <property name=\"FirstName\" access=\"property\" type=\"String\">\r\n" + " <column name=\"FirstName\"/>\r\n" + " </property>\r\n" + " <property name=\"LastName\" access=\"property\" type=\"String\">\r\n" + " <column name=\"LastName\"/>\r\n" + " </property>\r\n" + " <one-to-one name=\"Award\" access=\"property\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.Award, Castle.ActiveRecord.Framework.Internal.Tests\" foreign-key=\"FK_FOREIGN_KEY\" fetch=\"join\" constrained=\"true\" />\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); xml = Process(builder, awardModel); 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.Award, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"Award\" lazy=\"false\">\r\n" + " <id name=\"ID\" access=\"property\" column=\"EmployeeID\" type=\"Int32\" unsaved-value=\"0\">\r\n" + " <generator class=\"foreign\">\r\n" + " <param name=\"property\">Employee</param>\r\n" + " </generator>\r\n" + " </id>\r\n" + " <property name=\"Description\" access=\"property\" type=\"String\">\r\n" + " <column name=\"Description\"/>\r\n" + " </property>\r\n" + " <one-to-one name=\"Employee\" access=\"property\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.Employee, Castle.ActiveRecord.Framework.Internal.Tests\" />\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); }