Adding passing test case for IoC-73.
[castle.git] / ActiveRecord / Castle.ActiveRecord.Framework.Internal.Tests / XmlGenerationTestCase.cs
blob445e58842ae281401c8a937544a6f67cc2370d50
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.ActiveRecord.Framework.Internal.Tests
17 using System;
18 using NUnit.Framework;
19 using Castle.ActiveRecord.Framework.Internal.Tests.Model;
21 [TestFixture]
22 public class XmlGenerationTestCase : AbstractActiveRecordTest
24 [Test]
25 public void SimpleCaseWithPrimaryAssigned()
27 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
28 ActiveRecordModel model = builder.Create(typeof(ClassKeyAssigned));
29 Assert.IsNotNull(model);
31 SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models);
32 semanticVisitor.VisitNode(model);
34 XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor();
35 xmlVisitor.CreateXml(model);
37 String xml = xmlVisitor.Xml;
39 String expected =
40 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
41 "<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" +
42 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassKeyAssigned, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClassKeyAssigned\">\r\n" +
43 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
44 " <generator class=\"assigned\">\r\n" +
45 " </generator>\r\n" +
46 " </id>\r\n" +
47 " <property name=\"Name1\" access=\"property\" type=\"String\">\r\n" +
48 " <column name=\"Name1\"/>\r\n" +
49 " </property>\r\n" +
50 " </class>\r\n" +
51 "</hibernate-mapping>\r\n";
53 Assert.AreEqual(expected, xml);
56 [Test]
57 public void SimpleCaseWithNestedComponent()
59 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
60 ActiveRecordModel model = builder.Create(typeof(SimpleNestedComponent));
61 Assert.IsNotNull(model);
63 SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models);
64 semanticVisitor.VisitNode(model);
66 XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor();
67 xmlVisitor.CreateXml(model);
69 String xml = xmlVisitor.Xml;
71 String expected =
72 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
73 "<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" +
74 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.SimpleNestedComponent, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"SimpleNestedComponent\">\r\n" +
75 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
76 " <generator class=\"native\">\r\n" +
77 " </generator>\r\n" +
78 " </id>\r\n" +
79 " <component name=\"Nested\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.NestedComponent, Castle.ActiveRecord.Framework.Internal.Tests\" access=\"property\">\r\n" +
80 " <parent name=\"Parent\"/>\r\n" +
81 " <property name=\"NestedProperty\" access=\"property\" type=\"String\">\r\n" +
82 " <column name=\"NestedProperty\"/>\r\n" +
83 " </property>\r\n" +
84 " </component>\r\n" +
85 " </class>\r\n" +
86 "</hibernate-mapping>\r\n";
88 Assert.AreEqual(expected, xml);
92 [Test]
93 public void SimpleCaseWithNestedComponentWithFieldAccess()
95 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
96 ActiveRecordModel model = builder.Create(typeof(SimpleNestedComponentWithFieldAccess));
97 Assert.IsNotNull(model);
99 SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models);
100 semanticVisitor.VisitNode(model);
102 XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor();
103 xmlVisitor.CreateXml(model);
105 String xml = xmlVisitor.Xml;
107 String expected =
108 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
109 "<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" +
110 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.SimpleNestedComponentWithFieldAccess, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"SimpleNestedComponentWithFieldAccess\">\r\n" +
111 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
112 " <generator class=\"native\">\r\n" +
113 " </generator>\r\n" +
114 " </id>\r\n" +
115 " <component name=\"Nested\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.NestedComponent, Castle.ActiveRecord.Framework.Internal.Tests\" access=\"nosetter.camelcase\">\r\n" +
116 " <parent name=\"Parent\"/>\r\n" +
117 " <property name=\"NestedProperty\" access=\"property\" type=\"String\">\r\n" +
118 " <column name=\"NestedProperty\"/>\r\n" +
119 " </property>\r\n" +
120 " </component>\r\n" +
121 " </class>\r\n" +
122 "</hibernate-mapping>\r\n";
124 Assert.AreEqual(expected, xml);
128 [Test]
129 public void SimpleCaseWithKeyAndProperties()
131 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
132 ActiveRecordModel model = builder.Create(typeof(ClassA));
133 Assert.IsNotNull(model);
135 SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models);
136 semanticVisitor.VisitNode(model);
138 XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor();
139 xmlVisitor.CreateXml(model);
141 String xml = xmlVisitor.Xml;
143 String expected =
144 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
145 "<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" +
146 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassA, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClassA\">\r\n" +
147 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
148 " <generator class=\"native\">\r\n" +
149 " </generator>\r\n" +
150 " </id>\r\n" +
151 " <property name=\"Name1\" access=\"property\" type=\"String\" insert=\"false\" update=\"false\">\r\n" +
152 " <column name=\"Name1\"/>\r\n" +
153 " </property>\r\n" +
154 " <property name=\"Name2\" access=\"property\" type=\"String\">\r\n" +
155 " <column name=\"Name2\"/>\r\n" +
156 " </property>\r\n" +
157 " <property name=\"Name3\" access=\"property\" type=\"String\">\r\n" +
158 " <column name=\"Name3\" not-null=\"true\" unique=\"true\"/>\r\n" +
159 " </property>\r\n" +
160 " <property name=\"Text\" access=\"property\" type=\"StringClob\">\r\n" +
161 " <column name=\"Text\"/>\r\n" +
162 " </property>\r\n" +
163 " </class>\r\n" +
164 "</hibernate-mapping>\r\n";
166 Assert.AreEqual(expected, xml);
169 [Test]
170 public void SimpleCaseWithKeyPropertiesAndDynamicInsertUpdate()
172 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
173 ActiveRecordModel model = builder.Create(typeof(ClassADynamicInsertUpdate));
174 Assert.IsNotNull(model);
176 SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models);
177 semanticVisitor.VisitNode(model);
179 XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor();
180 xmlVisitor.CreateXml(model);
182 String xml = xmlVisitor.Xml;
184 String expected =
185 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
186 "<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" +
187 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassADynamicInsertUpdate, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClassA\" dynamic-update=\"true\" dynamic-insert=\"true\">\r\n" +
188 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
189 " <generator class=\"native\">\r\n" +
190 " </generator>\r\n" +
191 " </id>\r\n" +
192 " <property name=\"Name1\" access=\"property\" type=\"String\" insert=\"false\" update=\"false\">\r\n" +
193 " <column name=\"Name1\"/>\r\n" +
194 " </property>\r\n" +
195 " <property name=\"Name2\" access=\"property\" type=\"String\">\r\n" +
196 " <column name=\"Name2\"/>\r\n" +
197 " </property>\r\n" +
198 " <property name=\"Name3\" access=\"property\" type=\"String\">\r\n" +
199 " <column name=\"Name3\" not-null=\"true\" unique=\"true\"/>\r\n" +
200 " </property>\r\n" +
201 " <property name=\"Text\" access=\"property\" type=\"StringClob\">\r\n" +
202 " <column name=\"Text\"/>\r\n" +
203 " </property>\r\n" +
204 " </class>\r\n" +
205 "</hibernate-mapping>\r\n";
207 Assert.AreEqual(expected, xml);
210 [Test]
211 public void SimpleCaseWithKeyPropertiesAndCustomPersister()
213 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
214 ActiveRecordModel model = builder.Create(typeof(ClassWithCustomPersister));
215 Assert.IsNotNull(model);
217 SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models);
218 semanticVisitor.VisitNode(model);
220 XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor();
221 xmlVisitor.CreateXml(model);
223 String xml = xmlVisitor.Xml;
225 String expected =
226 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
227 "<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" +
228 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassWithCustomPersister, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClassA\" persister=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.CustomPersister, Castle.ActiveRecord.Framework.Internal.Tests\">\r\n" +
229 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
230 " <generator class=\"native\">\r\n" +
231 " </generator>\r\n" +
232 " </id>\r\n" +
233 " <property name=\"Name1\" access=\"property\" type=\"String\" insert=\"false\" update=\"false\">\r\n" +
234 " <column name=\"Name1\"/>\r\n" +
235 " </property>\r\n" +
236 " <property name=\"Name2\" access=\"property\" type=\"String\">\r\n" +
237 " <column name=\"Name2\"/>\r\n" +
238 " </property>\r\n" +
239 " <property name=\"Name3\" access=\"property\" type=\"String\">\r\n" +
240 " <column name=\"Name3\" not-null=\"true\" unique=\"true\"/>\r\n" +
241 " </property>\r\n" +
242 " <property name=\"Text\" access=\"property\" type=\"StringClob\">\r\n" +
243 " <column name=\"Text\"/>\r\n" +
244 " </property>\r\n" +
245 " </class>\r\n" +
246 "</hibernate-mapping>\r\n";
248 Assert.AreEqual(expected, xml);
251 [Test]
252 public void SimpleCaseWithBatch_SelectBeforeUpdate_Locking_Polimorphism()
254 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
255 ActiveRecordModel model = builder.Create(typeof(ClassWithSomeCustomOptions));
256 Assert.IsNotNull(model);
258 SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models);
259 semanticVisitor.VisitNode(model);
261 XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor();
262 xmlVisitor.CreateXml(model);
264 String xml = xmlVisitor.Xml;
266 String expected =
267 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
268 "<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" +
269 " <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" +
270 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
271 " <generator class=\"native\">\r\n" +
272 " </generator>\r\n" +
273 " </id>\r\n" +
274 " <property name=\"Name1\" access=\"property\" type=\"String\" insert=\"false\" update=\"false\">\r\n" +
275 " <column name=\"Name1\"/>\r\n" +
276 " </property>\r\n" +
277 " </class>\r\n" +
278 "</hibernate-mapping>\r\n";
280 Assert.AreEqual(expected, xml);
283 [Test]
284 public void AnyAttribute()
286 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
287 ActiveRecordModel model = builder.Create(typeof(ClassWithAnyAttribute));
288 Assert.IsNotNull(model);
290 SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models);
291 semanticVisitor.VisitNode(model);
293 XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor();
294 xmlVisitor.CreateXml(model);
296 String xml = xmlVisitor.Xml;
298 String expected =
299 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
300 "<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" +
301 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassWithAnyAttribute, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClassWithAnyAttribute\">\r\n" +
302 " <id name=\"Id\" access=\"nosetter.camelcase-underscore\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
303 " <generator class=\"native\">\r\n" +
304 " </generator>\r\n" +
305 " </id>\r\n" +
306 " <any name=\"PaymentMethod\" access=\"property\" id-type=\"Int64\" meta-type=\"System.String\" cascade=\"save-update\" not-null=\"true\">\r\n" +
307 " <meta-value value=\"BANK_ACCOUNT\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.BankAccount, Castle.ActiveRecord.Framework.Internal.Tests\" />\r\n" +
308 " <column name=\"BILLING_DETAILS_TYPE\" />\r\n" +
309 " <column name=\"BILLING_DETAILS_ID\" />\r\n" +
310 " </any>\r\n" +
311 " </class>\r\n" +
312 "</hibernate-mapping>\r\n";
314 Assert.AreEqual(expected, xml);
317 [Test]
318 public void LazyForClass()
320 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
321 builder.Create(typeof(ClassWithAnyAttribute));
322 ActiveRecordModel model = builder.Create(typeof(LazyClass));
323 Assert.IsNotNull(model);
325 SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models);
326 semanticVisitor.VisitNode(model);
328 XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor();
329 xmlVisitor.CreateXml(model);
331 String xml = xmlVisitor.Xml;
333 String expected =
334 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
335 "<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" +
336 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.LazyClass, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"LazyClass\" lazy=\"true\">\r\n" +
337 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
338 " <generator class=\"native\">\r\n" +
339 " </generator>\r\n" +
340 " </id>\r\n" +
341 " <many-to-one name=\"Clazz\" access=\"property\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassWithAnyAttribute, Castle.ActiveRecord.Framework.Internal.Tests\" column=\"Clazz\" />\r\n" +
342 " </class>\r\n" +
343 "</hibernate-mapping>\r\n";
345 Assert.AreEqual(expected, xml);
348 [Test]
349 public void HasManyToAnyAttribute()
351 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
352 ActiveRecordModel model = builder.Create(typeof(ClasssWithHasManyToAny));
353 Assert.IsNotNull(model);
355 SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models);
356 semanticVisitor.VisitNode(model);
358 XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor();
359 xmlVisitor.CreateXml(model);
361 String xml = xmlVisitor.Xml;
362 String expected =
363 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
364 "<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" +
365 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClasssWithHasManyToAny, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClasssWithHasManyToAny\">\r\n" +
366 " <id name=\"Id\" access=\"nosetter.camelcase-underscore\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
367 " <generator class=\"native\">\r\n" +
368 " </generator>\r\n" +
369 " </id>\r\n" +
370 " <set name=\"PaymentMethod\" access=\"property\" table=\"payments_table\" lazy=\"false\">\r\n" +
371 " <key column=\"pay_id\" />\r\n" +
372 " <many-to-any id-type=\"Int32\" meta-type=\"Int32\">\r\n" +
373 " <column name=\"payment_type\" />\r\n" +
374 " <column name=\"payment_method_id\" />\r\n" +
375 " </many-to-any>\r\n" +
376 " </set>\r\n" +
377 " </class>\r\n" +
378 "</hibernate-mapping>\r\n";
380 Assert.AreEqual(expected, xml);
383 [Test]
384 public void SimpleClassWithMappedFieldAndNonDefaultAccess()
386 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
387 ActiveRecordModel model = builder.Create(typeof(ClassWithMappedField));
388 Assert.IsNotNull(model);
390 SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models);
391 semanticVisitor.VisitNode(model);
393 XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor();
394 xmlVisitor.CreateXml(model);
396 String xml = xmlVisitor.Xml;
398 String expected =
399 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
400 "<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" +
401 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassWithMappedField, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClassWithMappedField\">\r\n" +
402 " <id name=\"Id\" access=\"nosetter.camelcase-underscore\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
403 " <generator class=\"native\">\r\n" +
404 " </generator>\r\n" +
405 " </id>\r\n" +
406 " <property name=\"name1\" access=\"field\" type=\"String\">\r\n" +
407 " <column name=\"MyCustomName\"/>\r\n" +
408 " </property>\r\n" +
409 " <property name=\"Value\" access=\"CustomAccess\" type=\"Int32\">\r\n" +
410 " <column name=\"Value\"/>\r\n" +
411 " </property>\r\n" +
412 " </class>\r\n" +
413 "</hibernate-mapping>\r\n";
415 Assert.AreEqual(expected, xml);
418 [Test]
419 public void SimpleCompositeClass()
421 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
422 ActiveRecordModel model = builder.Create(typeof(ClassWithCompositeKey2));
423 Assert.IsNotNull(model);
425 String xml = Process(builder, model);
426 String expected =
427 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
428 "<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" +
429 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassWithCompositeKey2, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClassWithCompositeKey2\" lazy=\"false\">\r\n" +
430 " <composite-id name=\"Key\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.CompositeKey2, Castle.ActiveRecord.Framework.Internal.Tests\" unsaved-value=\"none\" access=\"property\">\r\n" +
431 " <key-property name=\"Key1\" access=\"property\" column=\"Key1\" type=\"Int32\" />\r\n" +
432 " <key-property name=\"Key2\" access=\"property\" column=\"Key2\" type=\"String\" />\r\n" +
433 " </composite-id>\r\n" +
434 " </class>\r\n" +
435 "</hibernate-mapping>\r\n";
437 Assert.AreEqual(expected, xml);
440 [Test, Ignore("This is not implemented yet")]
441 public void CompositeClassWithBelongsTo()
443 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
444 ActiveRecordModel model = builder.Create(typeof(ClassWithCompositeKey3));
445 Assert.IsNotNull(model);
447 String xml = Process(builder, model);
448 String expected =
449 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
450 "<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" +
451 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassWithCompositeKey3, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClassWithCompositeKey3\" lazy=\"false\">\r\n" +
452 " <composite-id name=\"Key\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.CompositeKey2, Castle.ActiveRecord.Framework.Internal.Tests\" unsaved-value=\"none\" access=\"property\">\r\n" +
453 " <key-property name=\"Key1\" access=\"property\" column=\"Key1\" type=\"Int32\" />\r\n" +
454 " <key-many-to-one name=\"Key2\" access=\"property\" column=\"Key2\" type=\"String\" />\r\n" +
455 " </composite-id>\r\n" +
456 " </class>\r\n" +
457 "</hibernate-mapping>\r\n";
459 Assert.AreEqual(expected, xml);
462 [Test]
463 public void SimpleClassWithElementList()
465 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
466 ActiveRecordModel model = builder.Create(typeof(ClassWithElementList));
467 Assert.IsNotNull(model);
469 String xml = Process(builder, model);
470 String expected =
471 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
472 "<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" +
473 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassWithElementList, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClassWithElementList\">\r\n" +
474 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
475 " <generator class=\"native\">\r\n" +
476 " </generator>\r\n" +
477 " </id>\r\n" +
478 " <bag name=\"Elements\" access=\"property\" table=\"Elements\" lazy=\"false\">\r\n" +
479 " <key column=\"ClassId\" />\r\n" +
480 " <element column=\"Name\" type=\"System.String, mscorlib\"/>\r\n" +
481 " </bag>\r\n" +
482 " </class>\r\n" +
483 "</hibernate-mapping>\r\n";
485 Assert.AreEqual(expected, xml);
488 [Test]
489 public void DiscriminatorUse()
491 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
492 builder.Create(typeof(ClassDiscriminatorA));
493 ActiveRecordModel model = builder.Create(typeof(ClassDiscriminatorParent));
494 Assert.IsNotNull(model);
496 String xml = Process(builder, model);
498 String expected =
499 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
500 "<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" +
501 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassDiscriminatorParent, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"disctable\" discriminator-value=\"parent\">\r\n" +
502 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
503 " <generator class=\"native\">\r\n" +
504 " </generator>\r\n" +
505 " </id>\r\n" +
506 " <discriminator column=\"type\" type=\"String\" />\r\n" +
507 " <property name=\"Name\" access=\"property\" type=\"String\">\r\n" +
508 " <column name=\"Name\"/>\r\n" +
509 " </property>\r\n" +
510 " <subclass name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassDiscriminatorA, Castle.ActiveRecord.Framework.Internal.Tests\" discriminator-value=\"A\">\r\n" +
511 " <property name=\"Age\" access=\"property\" type=\"Int32\">\r\n" +
512 " <column name=\"Age\"/>\r\n" +
513 " </property>\r\n" +
514 " </subclass>\r\n" +
515 " </class>\r\n" +
516 "</hibernate-mapping>\r\n";
518 Assert.AreEqual(expected, xml);
521 #if DOTNET2
523 [Test]
524 public void JoinedSubClassUseWithGenericType()
526 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
527 builder.Create(typeof(GenClassJoinedSubClassA));
528 ActiveRecordModel model = builder.Create(typeof(GenClassJoinedSubClassParent));
529 Assert.IsNotNull(model);
531 String xml = Process(builder, model);
533 String expected =
534 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
535 "<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" +
536 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.GenClassJoinedSubClassParent, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"disctable\" lazy=\"false\">\r\n" +
537 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
538 " <generator class=\"native\">\r\n" +
539 " </generator>\r\n" +
540 " </id>\r\n" +
541 " <property name=\"Name\" access=\"property\" type=\"String\">\r\n" +
542 " <column name=\"Name\"/>\r\n" +
543 " </property>\r\n" +
544 " <joined-subclass name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.GenClassJoinedSubClassA, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"disctablea\" lazy=\"false\">\r\n" +
545 " <key column=\"AId\" />\r\n" +
546 " <property name=\"Age\" access=\"property\" type=\"Int32\">\r\n" +
547 " <column name=\"Age\"/>\r\n" +
548 " </property>\r\n" +
549 " </joined-subclass>\r\n" +
550 " </class>\r\n" +
551 "</hibernate-mapping>\r\n";
553 Assert.AreEqual(expected, xml);
556 [Test]
557 public void JoinedSubClassUseWithGenericTypeAndAbstractBase()
559 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
560 builder.Create(typeof(SubClassJoinedClass));
561 ActiveRecordModel model = builder.Create(typeof(BaseJoinedClass));
562 Assert.IsNotNull(model);
564 String xml = Process(builder, model);
566 String expected =
567 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
568 "<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" +
569 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.BaseJoinedClass, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"disctable\" lazy=\"false\">\r\n" +
570 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
571 " <generator class=\"native\">\r\n" +
572 " </generator>\r\n" +
573 " </id>\r\n" +
574 " <property name=\"Name\" access=\"property\" type=\"String\">\r\n" +
575 " <column name=\"Name\"/>\r\n" +
576 " </property>\r\n" +
577 " <joined-subclass name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.SubClassJoinedClass, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"disctablea\" lazy=\"false\">\r\n" +
578 " <key column=\"AId\" />\r\n" +
579 " <property name=\"Age\" access=\"property\" type=\"Int32\">\r\n" +
580 " <column name=\"Age\"/>\r\n" +
581 " </property>\r\n" +
582 " </joined-subclass>\r\n" +
583 " </class>\r\n" +
584 "</hibernate-mapping>\r\n";
586 Assert.AreEqual(expected, xml);
589 [Test]
590 public void JoinedSubClassUseWithGenericTypeAndGenericAbstractBase()
592 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
593 builder.Create(typeof(GenSubClassJoinedClass));
594 ActiveRecordModel model = builder.Create(typeof(GenBaseJoinedClass<GenSubClassJoinedClass>));
595 Assert.IsNotNull(model);
597 String xml = Process(builder, model);
599 String expected =
600 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
601 "<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" +
602 " <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.0.0, Culture=neutral, PublicKeyToken=null]], Castle.ActiveRecord.Framework.Internal.Tests\" table=\"disctable\">\r\n" +
603 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
604 " <generator class=\"native\">\r\n" +
605 " </generator>\r\n" +
606 " </id>\r\n" +
607 " <property name=\"Name\" access=\"property\" type=\"String\">\r\n" +
608 " <column name=\"Name\"/>\r\n" +
609 " </property>\r\n" +
610 " <joined-subclass name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.GenSubClassJoinedClass, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"disctablea\" lazy=\"false\">\r\n" +
611 " <key column=\"AId\" />\r\n" +
612 " <property name=\"Age\" access=\"property\" type=\"Int32\">\r\n" +
613 " <column name=\"Age\"/>\r\n" +
614 " </property>\r\n" +
615 " </joined-subclass>\r\n" +
616 " </class>\r\n" +
617 "</hibernate-mapping>\r\n";
619 Assert.AreEqual(expected, xml);
622 #endif
624 [Test]
625 public void JoinedSubClassUse()
627 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
628 builder.Create(typeof(ClassJoinedSubClassA));
629 ActiveRecordModel model = builder.Create(typeof(ClassJoinedSubClassParent));
630 Assert.IsNotNull(model);
632 String xml = Process(builder, model);
634 String expected =
635 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
636 "<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" +
637 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassJoinedSubClassParent, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"disctable\" lazy=\"false\">\r\n" +
638 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
639 " <generator class=\"native\">\r\n" +
640 " </generator>\r\n" +
641 " </id>\r\n" +
642 " <property name=\"Name\" access=\"property\" type=\"String\">\r\n" +
643 " <column name=\"Name\"/>\r\n" +
644 " </property>\r\n" +
645 " <joined-subclass name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassJoinedSubClassA, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"disctablea\" lazy=\"false\">\r\n" +
646 " <key column=\"AId\" />\r\n" +
647 " <property name=\"Age\" access=\"property\" type=\"Int32\">\r\n" +
648 " <column name=\"Age\"/>\r\n" +
649 " </property>\r\n" +
650 " </joined-subclass>\r\n" +
651 " </class>\r\n" +
652 "</hibernate-mapping>\r\n";
654 Assert.AreEqual(expected, xml);
657 [Test]
658 public void VersionedClass()
660 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
661 ActiveRecordModel model = builder.Create(typeof(VersionedClass));
662 Assert.IsNotNull(model);
664 String xml = Process(builder, model);
666 String expected =
667 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
668 "<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" +
669 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.VersionedClass, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"VersionedClass\" lazy=\"false\">\r\n" +
670 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
671 " <generator class=\"native\">\r\n" +
672 " </generator>\r\n" +
673 " </id>\r\n" +
674 " <version name=\"Ver\" access=\"property\" column=\"Ver\" type=\"String\" />\r\n" +
675 " <property name=\"Name\" access=\"property\" type=\"String\">\r\n" +
676 " <column name=\"Name\"/>\r\n" +
677 " </property>\r\n" +
678 " </class>\r\n" +
679 "</hibernate-mapping>\r\n";
681 Assert.AreEqual(expected, xml);
684 [Test]
685 public void TimestampedClass()
687 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
688 ActiveRecordModel model = builder.Create(typeof(TimestampedClass));
689 Assert.IsNotNull(model);
691 String xml = Process(builder, model);
693 String expected =
694 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
695 "<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" +
696 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.TimestampedClass, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"TimestampedClass\" lazy=\"false\">\r\n" +
697 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
698 " <generator class=\"native\">\r\n" +
699 " </generator>\r\n" +
700 " </id>\r\n" +
701 " <timestamp name=\"Ts\" access=\"property\" column=\"Ts\" />\r\n" +
702 " <property name=\"Name\" access=\"property\" type=\"String\">\r\n" +
703 " <column name=\"Name\"/>\r\n" +
704 " </property>\r\n" +
705 " </class>\r\n" +
706 "</hibernate-mapping>\r\n";
708 Assert.AreEqual(expected, xml);
711 [Test]
712 public void SequenceParamClass()
714 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
715 ActiveRecordModel model = builder.Create(typeof(SequenceParamClass));
716 Assert.IsNotNull(model);
718 String xml = Process(builder, model);
720 String expected =
721 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
722 "<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" +
723 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.SequenceParamClass, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"SequenceParamClass\" lazy=\"false\">\r\n" +
724 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
725 " <generator class=\"sequence\">\r\n" +
726 " <param name=\"sequence\">my_seq</param>\r\n" +
727 " </generator>\r\n" +
728 " </id>\r\n" +
729 " </class>\r\n" +
730 "</hibernate-mapping>\r\n";
732 Assert.AreEqual(expected, xml);
735 [Test]
736 public void BelongsTo1()
738 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
739 ActiveRecordModel model = builder.Create(typeof(BelongsToClassA));
740 Assert.IsNotNull(model);
742 String xml = Process(builder, model);
744 String expected =
745 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
746 "<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" +
747 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.BelongsToClassA, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"BelongsToClassA\" lazy=\"false\">\r\n" +
748 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
749 " <generator class=\"native\">\r\n" +
750 " </generator>\r\n" +
751 " </id>\r\n" +
752 " <many-to-one name=\"ClassA\" access=\"property\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassA, Castle.ActiveRecord.Framework.Internal.Tests\" column=\"classa_id\" foreign-key=\"FK_FOREIGN_KEY_A\" />\r\n" +
753 " </class>\r\n" +
754 "</hibernate-mapping>\r\n";
756 Assert.AreEqual(expected, xml);
759 [Test]
760 public void BelongsTo2()
762 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
763 ActiveRecordModel model = builder.Create(typeof(BelongsToClassA2));
764 Assert.IsNotNull(model);
766 String xml = Process(builder, model);
768 String expected =
769 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
770 "<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" +
771 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.BelongsToClassA2, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"BelongsToClassA2\" lazy=\"false\">\r\n" +
772 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
773 " <generator class=\"native\">\r\n" +
774 " </generator>\r\n" +
775 " </id>\r\n" +
776 " <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" +
777 " </class>\r\n" +
778 "</hibernate-mapping>\r\n";
780 Assert.AreEqual(expected, xml);
783 [Test]
784 public void BelongsToWithFetch()
786 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
787 ActiveRecordModel model = builder.Create(typeof(BelongsToClassAFetch));
788 Assert.IsNotNull(model);
790 String xml = Process(builder, model);
792 String expected =
793 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
794 "<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" +
795 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.BelongsToClassAFetch, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"BelongsToClassAFetch\" lazy=\"false\">\r\n" +
796 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
797 " <generator class=\"native\">\r\n" +
798 " </generator>\r\n" +
799 " </id>\r\n" +
800 " <many-to-one name=\"ClassA\" access=\"property\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassA, Castle.ActiveRecord.Framework.Internal.Tests\" column=\"classa_id\" fetch=\"join\" />\r\n" +
801 " </class>\r\n" +
802 "</hibernate-mapping>\r\n";
804 Assert.AreEqual(expected, xml);
807 [Test]
808 public void HasManyWithExplicitInfo()
810 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
811 ActiveRecordModel model = builder.Create(typeof(HasManyClassA));
812 Assert.IsNotNull(model);
814 String xml = Process(builder, model);
816 String expected =
817 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
818 "<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" +
819 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.HasManyClassA, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"HasManyClassA\" lazy=\"false\">\r\n" +
820 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
821 " <generator class=\"native\">\r\n" +
822 " </generator>\r\n" +
823 " </id>\r\n" +
824 " <bag name=\"Items\" access=\"property\" table=\"ClassATable\" lazy=\"false\" inverse=\"true\">\r\n" +
825 " <key column=\"keycol\" />\r\n" +
826 " <one-to-many class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassA, Castle.ActiveRecord.Framework.Internal.Tests\" />\r\n" +
827 " </bag>\r\n" +
828 " </class>\r\n" +
829 "</hibernate-mapping>\r\n";
831 Assert.AreEqual(expected, xml);
834 [Test]
835 public void HasManyWithFetch()
837 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
838 ActiveRecordModel model = builder.Create(typeof(HasManyWithFetch));
839 Assert.IsNotNull(model);
841 String xml = Process(builder, model);
843 String expected =
844 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
845 "<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" +
846 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.HasManyWithFetch, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"HasManyWithFetch\" lazy=\"false\">\r\n" +
847 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
848 " <generator class=\"native\">\r\n" +
849 " </generator>\r\n" +
850 " </id>\r\n" +
851 " <bag name=\"Items\" access=\"property\" table=\"ClassATable\" lazy=\"false\" inverse=\"true\" fetch=\"join\">\r\n" +
852 " <key column=\"keycol\" />\r\n" +
853 " <one-to-many class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassA, Castle.ActiveRecord.Framework.Internal.Tests\" />\r\n" +
854 " </bag>\r\n" +
855 " </class>\r\n" +
856 "</hibernate-mapping>\r\n";
858 Assert.AreEqual(expected, xml);
861 [Test]
862 public void HasManyWithBatch()
864 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
865 ActiveRecordModel model = builder.Create(typeof(HasManyWithBatch));
866 Assert.IsNotNull(model);
868 String xml = Process(builder, model);
870 String expected =
871 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
872 "<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" +
873 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.HasManyWithBatch, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"HasManyWithBatch\" lazy=\"false\">\r\n" +
874 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
875 " <generator class=\"native\">\r\n" +
876 " </generator>\r\n" +
877 " </id>\r\n" +
878 " <bag name=\"Items\" access=\"property\" table=\"ClassATable\" lazy=\"false\" inverse=\"true\" batch-size=\"3\">\r\n" +
879 " <key column=\"keycol\" />\r\n" +
880 " <one-to-many class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassA, Castle.ActiveRecord.Framework.Internal.Tests\" />\r\n" +
881 " </bag>\r\n" +
882 " </class>\r\n" +
883 "</hibernate-mapping>\r\n";
885 Assert.AreEqual(expected, xml);
888 [Test]
889 public void HasManyInfering()
891 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
892 ActiveRecordModel model = builder.Create(typeof(Category));
893 Assert.IsNotNull(model);
895 String xml = Process(builder, model);
897 String expected =
898 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
899 "<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" +
900 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.Category, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"Category\" lazy=\"false\">\r\n" +
901 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
902 " <generator class=\"native\">\r\n" +
903 " </generator>\r\n" +
904 " </id>\r\n" +
905 " <property name=\"Name\" access=\"property\" type=\"String\">\r\n" +
906 " <column name=\"Name\"/>\r\n" +
907 " </property>\r\n" +
908 " <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" +
909 " <bag name=\"SubCategories\" access=\"property\" table=\"Category\" lazy=\"false\">\r\n" +
910 " <key column=\"parent_id\" />\r\n" +
911 " <one-to-many class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.Category, Castle.ActiveRecord.Framework.Internal.Tests\" />\r\n" +
912 " </bag>\r\n" +
913 " </class>\r\n" +
914 "</hibernate-mapping>\r\n";
916 Assert.AreEqual(expected, xml);
919 [Test]
920 public void CompositeKey()
922 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
923 ActiveRecordModel model = builder.Create(typeof(ClassWithCompositeKey));
924 Assert.IsNotNull(model);
926 string xml = Process(builder, model);
928 string expected =
929 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
930 "<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" +
931 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassWithCompositeKey, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClassWithCompositeKey\" lazy=\"false\">\r\n" +
932 " <composite-id name=\"Key\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.CompositeKeyForClassWithCompositeKey, Castle.ActiveRecord.Framework.Internal.Tests\" unsaved-value=\"none\" access=\"property\">\r\n" +
933 " <key-property name=\"KeyA\" access=\"property\" column=\"KeyA\" type=\"String\" />\r\n" +
934 " <key-property name=\"KeyB\" access=\"property\" column=\"KeyB\" type=\"String\" />\r\n" +
935 " </composite-id>\r\n" +
936 " </class>\r\n" +
937 "</hibernate-mapping>\r\n";
939 Assert.AreEqual(expected, xml);
942 [Test]
943 public void One2OneKey()
945 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
946 ActiveRecordModel empModel = builder.Create(typeof(Employee));
947 ActiveRecordModel awardModel = builder.Create(typeof(Award));
948 Assert.IsNotNull(empModel);
949 Assert.IsNotNull(awardModel);
951 string xml = Process(builder, empModel);
953 string expected =
954 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
955 "<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" +
956 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.Employee, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"Employee\" lazy=\"false\">\r\n" +
957 " <id name=\"ID\" access=\"property\" column=\"EmployeeID\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
958 " <generator class=\"native\">\r\n" +
959 " </generator>\r\n" +
960 " </id>\r\n" +
961 " <property name=\"FirstName\" access=\"property\" type=\"String\">\r\n" +
962 " <column name=\"FirstName\"/>\r\n" +
963 " </property>\r\n" +
964 " <property name=\"LastName\" access=\"property\" type=\"String\">\r\n" +
965 " <column name=\"LastName\"/>\r\n" +
966 " </property>\r\n" +
967 " <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" +
968 " </class>\r\n" +
969 "</hibernate-mapping>\r\n";
971 Assert.AreEqual(expected, xml);
973 xml = Process(builder, awardModel);
975 expected =
976 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
977 "<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" +
978 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.Award, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"Award\" lazy=\"false\">\r\n" +
979 " <id name=\"ID\" access=\"property\" column=\"EmployeeID\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
980 " <generator class=\"foreign\">\r\n" +
981 " <param name=\"property\">Employee</param>\r\n" +
982 " </generator>\r\n" +
983 " </id>\r\n" +
984 " <property name=\"Description\" access=\"property\" type=\"String\">\r\n" +
985 " <column name=\"Description\"/>\r\n" +
986 " </property>\r\n" +
987 " <one-to-one name=\"Employee\" access=\"property\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.Employee, Castle.ActiveRecord.Framework.Internal.Tests\" />\r\n" +
988 " </class>\r\n" +
989 "</hibernate-mapping>\r\n";
991 Assert.AreEqual(expected, xml);
994 [Test]
995 public void CachedClass()
997 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
998 ActiveRecordModel model = builder.Create(typeof(CacheClass));
999 Assert.IsNotNull(model);
1001 String xml = Process(builder, model);
1003 String expected =
1004 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
1005 "<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" +
1006 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.CacheClass, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"CacheClass\" lazy=\"false\">\r\n" +
1007 " <cache usage=\"read-write\" />\r\n" +
1008 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
1009 " <generator class=\"native\">\r\n" +
1010 " </generator>\r\n" +
1011 " </id>\r\n" +
1012 " <property name=\"Name\" access=\"property\" type=\"String\">\r\n" +
1013 " <column name=\"Name\"/>\r\n" +
1014 " </property>\r\n" +
1015 " <many-to-one name=\"Parent\" access=\"property\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.CacheClass, Castle.ActiveRecord.Framework.Internal.Tests\" column=\"parent_id\" />\r\n" +
1016 " <bag name=\"SubClasses\" access=\"property\" table=\"CacheClass\" lazy=\"false\">\r\n" +
1017 " <jcs-cache usage=\"read-write\" />\r\n" +
1018 " <key column=\"parent_id\" />\r\n" +
1019 " <one-to-many class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.CacheClass, Castle.ActiveRecord.Framework.Internal.Tests\" />\r\n" +
1020 " </bag>\r\n" +
1021 " </class>\r\n" +
1022 "</hibernate-mapping>\r\n";
1024 Assert.AreEqual(expected, xml);
1027 [Test]
1028 public void NotFoundBehaviourClass()
1030 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
1031 ActiveRecordModel NotFoundBehaviourClassModel = builder.Create(typeof(NotFoundBehaviourClass));
1032 ActiveRecordModel RelationalFoobarModel = builder.Create(typeof(RelationalFoobar));
1033 Assert.IsNotNull(NotFoundBehaviourClassModel);
1034 Assert.IsNotNull(RelationalFoobarModel);
1036 String xml = Process(builder, NotFoundBehaviourClassModel);
1038 String expected =
1039 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
1040 "<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" +
1041 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.NotFoundBehaviourClass, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"NotFoundBehaviourClass\">\r\n" +
1042 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
1043 " <generator class=\"native\">\r\n" +
1044 " </generator>\r\n" +
1045 " </id>\r\n" +
1046 " <bag name=\"SubClasses\" access=\"property\" table=\"RelationalFoobarTable\" lazy=\"false\">\r\n" +
1047 " <key column=\"keycol\" />\r\n" +
1048 " <one-to-many class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.RelationalFoobar, Castle.ActiveRecord.Framework.Internal.Tests\" not-found=\"ignore\" />\r\n" +
1049 " </bag>\r\n" +
1050 " <bag name=\"ManySubClasses\" access=\"property\" table=\"ManySubClasses\" lazy=\"false\">\r\n" +
1051 " <key column=\"id\" />\r\n" +
1052 " <many-to-many class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.RelationalFoobar, Castle.ActiveRecord.Framework.Internal.Tests\" column=\"ref_id\" not-found=\"ignore\"/>\r\n" +
1053 " </bag>\r\n" +
1054 " </class>\r\n" +
1055 "</hibernate-mapping>\r\n";
1057 Assert.AreEqual(expected, xml);
1059 xml = Process(builder, RelationalFoobarModel);
1061 expected =
1062 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
1063 "<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" +
1064 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.RelationalFoobar, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"RelationalFoobar\">\r\n" +
1065 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
1066 " <generator class=\"native\">\r\n" +
1067 " </generator>\r\n" +
1068 " </id>\r\n" +
1069 " <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" +
1070 " <bag name=\"NotFoundBehaviourClassList\" access=\"property\" table=\"ManySubClasses\" lazy=\"false\">\r\n" +
1071 " <key column=\"id\" />\r\n" +
1072 " <many-to-many class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.NotFoundBehaviourClass, Castle.ActiveRecord.Framework.Internal.Tests\" column=\"ref_id\" not-found=\"ignore\"/>\r\n" +
1073 " </bag>\r\n" +
1074 " </class>\r\n" +
1075 "</hibernate-mapping>\r\n";
1077 Assert.AreEqual(expected, xml);
1080 #if DOTNET2
1081 [Test]
1082 public void EnumWithColumnType()
1084 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
1085 ActiveRecordModel model = builder.Create(typeof(EnumTestClass));
1086 Assert.IsNotNull(model);
1088 string xml = Process(builder, model);
1090 string expected =
1091 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
1092 "<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" +
1093 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.EnumTestClass, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"EnumTestClass\" lazy=\"false\">\r\n" +
1094 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
1095 " <generator class=\"native\">\r\n" +
1096 " </generator>\r\n" +
1097 " </id>\r\n" +
1098 " <property name=\"NoColumnType\" access=\"property\">\r\n" +
1099 " <column name=\"NoColumnType\"/>\r\n" +
1100 " </property>\r\n" +
1101 " <property name=\"WithColumnType\" access=\"property\" type=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.GenericEnumStringType`1[[Castle.ActiveRecord.Framework.Internal.Tests.Model.EnumVal, Castle.ActiveRecord.Framework.Internal.Tests]], Castle.ActiveRecord.Framework.Internal.Tests\">\r\n" +
1102 " <column name=\"WithColumnType\"/>\r\n" +
1103 " </property>\r\n" +
1104 " </class>\r\n" +
1105 "</hibernate-mapping>\r\n";
1107 Assert.AreEqual(expected, xml);
1109 #endif
1111 private string Process(ActiveRecordModelBuilder builder, ActiveRecordModel model)
1113 GraphConnectorVisitor connectorVisitor = new GraphConnectorVisitor(builder.Models);
1114 connectorVisitor.VisitNode(model);
1116 SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models);
1117 semanticVisitor.VisitNode(model);
1119 XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor();
1120 xmlVisitor.CreateXml(model);
1122 return xmlVisitor.Xml;
1125 #if DOTNET2
1126 [Test]
1127 public void HasManyWithDictionary()
1129 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
1130 ActiveRecordModel model = builder.Create(typeof(DictionaryModel));
1131 Assert.IsNotNull(model);
1133 string xml = Process(builder, model);
1135 string expected =
1136 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
1137 "<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" +
1138 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.DictionaryModel, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"DictionaryModel\">\r\n" +
1139 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
1140 " <generator class=\"native\">\r\n" +
1141 " </generator>\r\n" +
1142 " </id>\r\n" +
1143 " <map name=\"Snippet\" access=\"property\" table=\"DictionaryModel_Snippet\" lazy=\"false\">\r\n" +
1144 " <key column=\"id\" />\r\n" +
1145 " <index column=\"LangCode\" type=\"String\" />\r\n" +
1146 " <element column=\"Text\" type=\"System.String, mscorlib\"/>\r\n" +
1147 " </map>\r\n" +
1148 " </class>\r\n" +
1149 "</hibernate-mapping>\r\n";
1151 Assert.AreEqual(expected, xml);
1153 #endif
1155 [Test]
1156 public void SimpleListOfComponents()
1158 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
1159 ActiveRecordModel model = builder.Create(typeof(HasManyDependentObjects));
1160 Assert.IsNotNull(model);
1162 String xml = Process(builder, model);
1164 string expected =
1165 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
1166 "<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" +
1167 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.HasManyDependentObjects, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"HasManyDependentObjects\">\r\n" +
1168 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
1169 " <generator class=\"native\">\r\n" +
1170 " </generator>\r\n" +
1171 " </id>\r\n" +
1172 " <list name=\"Components\" access=\"property\" table=\"dependent_objects\" lazy=\"false\">\r\n" +
1173 " <key column=\"id\" />\r\n" +
1174 " <index column=\"pos\" />\r\n" +
1175 " <composite-element class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.Component, Castle.ActiveRecord.Framework.Internal.Tests\">\r\n" +
1176 " <property name=\"Value\" access=\"property\" type=\"String\">\r\n" +
1177 " <column name=\"Value\"/>\r\n" +
1178 " </property>\r\n" +
1179 " </composite-element>\r\n" +
1180 " </list>\r\n" +
1181 " </class>\r\n" +
1182 "</hibernate-mapping>\r\n";
1184 Assert.AreEqual(expected, xml);
1187 [Test]
1188 public void SimpleListOfComponentsWithNestedComponents()
1190 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
1191 ActiveRecordModel model = builder.Create(typeof(HasManyDependentObjectsWithNested));
1192 Assert.IsNotNull(model);
1194 String xml = Process(builder, model);
1196 string expected =
1197 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
1198 "<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" +
1199 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.HasManyDependentObjectsWithNested, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"HasManyDependentObjectsWithNested\">\r\n" +
1200 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
1201 " <generator class=\"native\">\r\n" +
1202 " </generator>\r\n" +
1203 " </id>\r\n" +
1204 " <list name=\"ComponentsWithNested\" access=\"property\" table=\"dependent_objects\" lazy=\"false\">\r\n" +
1205 " <key column=\"id\" />\r\n" +
1206 " <index column=\"pos\" />\r\n" +
1207 " <composite-element class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ComponentWithNested, Castle.ActiveRecord.Framework.Internal.Tests\">\r\n" +
1208 " <nested-composite-element name=\"Component\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.Component, Castle.ActiveRecord.Framework.Internal.Tests\" access=\"property\">\r\n" +
1209 " <property name=\"Value\" access=\"property\" type=\"String\">\r\n" +
1210 " <column name=\"Value\"/>\r\n" +
1211 " </property>\r\n" +
1212 " </nested-composite-element>\r\n" +
1213 " </composite-element>\r\n" +
1214 " </list>\r\n" +
1215 " </class>\r\n" +
1216 "</hibernate-mapping>\r\n";
1218 Assert.AreEqual(expected, xml);
1221 [Test]
1222 public void SimpleListOfComponentsWithNestedComponents2LevelsDeep()
1224 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
1225 ActiveRecordModel model = builder.Create(typeof(HasManyDependentObjectsWithNested2LevelsDeep));
1226 Assert.IsNotNull(model);
1228 String xml = Process(builder, model);
1230 string expected =
1231 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
1232 "<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" +
1233 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.HasManyDependentObjectsWithNested2LevelsDeep, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"HasManyDependentObjectsWithNested2LevelsDeep\">\r\n" +
1234 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
1235 " <generator class=\"native\">\r\n" +
1236 " </generator>\r\n" +
1237 " </id>\r\n" +
1238 " <list name=\"ComponentsWithNested2LevelsDeep\" access=\"property\" table=\"dependent_objects\" lazy=\"false\">\r\n" +
1239 " <key column=\"id\" />\r\n" +
1240 " <index column=\"pos\" />\r\n" +
1241 " <composite-element class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ComponentWithNested2LevelsDeep, Castle.ActiveRecord.Framework.Internal.Tests\">\r\n" +
1242 " <nested-composite-element name=\"ComponentWithNested\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ComponentWithNested, Castle.ActiveRecord.Framework.Internal.Tests\" access=\"property\">\r\n" +
1243 " <nested-composite-element name=\"Component\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.Component, Castle.ActiveRecord.Framework.Internal.Tests\" access=\"property\">\r\n" +
1244 " <property name=\"Value\" access=\"property\" type=\"String\">\r\n" +
1245 " <column name=\"Value\"/>\r\n" +
1246 " </property>\r\n" +
1247 " </nested-composite-element>\r\n" +
1248 " </nested-composite-element>\r\n" +
1249 " </composite-element>\r\n" +
1250 " </list>\r\n" +
1251 " </class>\r\n" +
1252 "</hibernate-mapping>\r\n";
1254 Assert.AreEqual(expected, xml);
1258 [Test]
1259 public void ManyToMayViaComponents()
1261 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
1262 ActiveRecordModel model = builder.Create(typeof(HasManyToManyViaComponents));
1263 Assert.IsNotNull(model);
1265 String xml = Process(builder, model);
1266 string expected =
1267 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
1268 "<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" +
1269 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.HasManyToManyViaComponents, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"HasManyToManyViaComponents\">\r\n" +
1270 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
1271 " <generator class=\"native\">\r\n" +
1272 " </generator>\r\n" +
1273 " </id>\r\n" +
1274 " <list name=\"Components\" access=\"property\" table=\"components_to_a\" lazy=\"false\">\r\n" +
1275 " <key column=\"id\" />\r\n" +
1276 " <index column=\"pos\" />\r\n" +
1277 " <composite-element class=\"Castle.ActiveRecord.Framework.Internal.Tests.ComponentManyToClassA, Castle.ActiveRecord.Framework.Internal.Tests\">\r\n" +
1278 " <property name=\"Value\" access=\"property\" type=\"String\">\r\n" +
1279 " <column name=\"Value\"/>\r\n" +
1280 " </property>\r\n" +
1281 " <many-to-one name=\"A\" access=\"property\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassA, Castle.ActiveRecord.Framework.Internal.Tests\" column=\"aId\" />\r\n" +
1282 " </composite-element>\r\n" +
1283 " </list>\r\n" +
1284 " </class>\r\n" +
1285 "</hibernate-mapping>\r\n";
1286 Assert.AreEqual(expected, xml);