CreateXml() public méthode

Creates the XML.
public CreateXml ( ActiveRecordModel model ) : void
model ActiveRecordModel The model.
Résultat void
        public void DiscriminatorUse()
        {
            XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor();
            xmlVisitor.CreateXml(ActiveRecordModel.GetModel(typeof(PersistedRule)));
            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.RulesModel.PersistedRule, Castle.ActiveRecord.Tests\" table=\"PersistedRule\" discriminator-value=\"0\" 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"+
                "    <discriminator column=\"discriminator\" />\r\n"+
                "    <property name=\"Count\" access=\"property\" type=\"Int32\">\r\n"+
                "      <column name=\"Count\"/>\r\n" + 
                "    </property>\r\n" +
                "    <subclass name=\"Castle.ActiveRecord.Tests.Model.RulesModel.WorkDaysRules, Castle.ActiveRecord.Tests\" discriminator-value=\"2\" lazy=\"false\">\r\n"+
                "      <property name=\"Name\" access=\"property\" type=\"String\">\r\n"+
				"        <column name=\"Name\"/>\r\n" + 
				"      </property>\r\n" +
				"      <property name=\"Days\" access=\"property\" type=\"Int32\">\r\n"+
				"        <column name=\"Days\"/>\r\n" + 
				"      </property>\r\n" +
				"    </subclass>\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);
		}
		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);
					}
				}
			}
		}