Refactored the Kernel registration fluent interface to be more readable, better suppo...
[castle.git] / ActiveRecord / Castle.ActiveRecord.Framework.Internal.Tests / XmlGenerationTestCase.cs
blob1eec2773ebf64d30ef11faee3f29f5ac1c1a2994
1 // Copyright 2004-2008 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 AnyAttributeUsingGenericId()
320 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
321 ActiveRecordModel model = builder.Create(typeof(ClassWithAnyAttributeUsingGenericId));
322 Assert.IsNotNull(model);
324 SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models);
325 semanticVisitor.VisitNode(model);
327 XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor();
328 xmlVisitor.CreateXml(model);
330 String xml = xmlVisitor.Xml;
332 String expected =
333 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
334 "<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" +
335 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassWithAnyAttributeUsingGenericId, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClassWithAnyAttributeUsingGenericId\">\r\n" +
336 " <id name=\"Id\" access=\"nosetter.camelcase-underscore\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
337 " <generator class=\"native\">\r\n" +
338 " </generator>\r\n" +
339 " </id>\r\n" +
340 " <any name=\"PaymentMethod\" access=\"property\" id-type=\"System.Nullable`1[[System.Int64, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]\" meta-type=\"System.String\" cascade=\"save-update\" not-null=\"true\">\r\n" +
341 " <meta-value value=\"BANK_ACCOUNT\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.BankAccount, Castle.ActiveRecord.Framework.Internal.Tests\" />\r\n" +
342 " <column name=\"BILLING_DETAILS_TYPE\" />\r\n" +
343 " <column name=\"BILLING_DETAILS_ID\" />\r\n" +
344 " </any>\r\n" +
345 " </class>\r\n" +
346 "</hibernate-mapping>\r\n";
348 Assert.AreEqual(expected, xml);
351 [Test]
352 public void LazyForClass()
354 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
355 builder.Create(typeof(ClassWithAnyAttribute));
356 ActiveRecordModel model = builder.Create(typeof(LazyClass));
357 Assert.IsNotNull(model);
359 SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models);
360 semanticVisitor.VisitNode(model);
362 XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor();
363 xmlVisitor.CreateXml(model);
365 String xml = xmlVisitor.Xml;
367 String expected =
368 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
369 "<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" +
370 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.LazyClass, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"LazyClass\" lazy=\"true\">\r\n" +
371 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
372 " <generator class=\"native\">\r\n" +
373 " </generator>\r\n" +
374 " </id>\r\n" +
375 " <many-to-one name=\"Clazz\" access=\"property\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassWithAnyAttribute, Castle.ActiveRecord.Framework.Internal.Tests\" column=\"Clazz\" />\r\n" +
376 " </class>\r\n" +
377 "</hibernate-mapping>\r\n";
379 Assert.AreEqual(expected, xml);
382 [Test]
383 public void HasManyToAnyAttribute()
385 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
386 ActiveRecordModel model = builder.Create(typeof(ClasssWithHasManyToAny));
387 Assert.IsNotNull(model);
389 SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models);
390 semanticVisitor.VisitNode(model);
392 XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor();
393 xmlVisitor.CreateXml(model);
395 String xml = xmlVisitor.Xml;
396 String expected =
397 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
398 "<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" +
399 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClasssWithHasManyToAny, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClasssWithHasManyToAny\">\r\n" +
400 " <id name=\"Id\" access=\"nosetter.camelcase-underscore\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
401 " <generator class=\"native\">\r\n" +
402 " </generator>\r\n" +
403 " </id>\r\n" +
404 " <set name=\"PaymentMethod\" access=\"property\" table=\"payments_table\" lazy=\"false\">\r\n" +
405 " <key column=\"pay_id\" />\r\n" +
406 " <many-to-any id-type=\"Int32\" meta-type=\"Int32\">\r\n" +
407 " <column name=\"payment_type\" />\r\n" +
408 " <column name=\"payment_method_id\" />\r\n" +
409 " </many-to-any>\r\n" +
410 " </set>\r\n" +
411 " </class>\r\n" +
412 "</hibernate-mapping>\r\n";
414 Assert.AreEqual(expected, xml);
417 [Test]
418 public void SimpleClassWithMappedFieldAndNonDefaultAccess()
420 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
421 ActiveRecordModel model = builder.Create(typeof(ClassWithMappedField));
422 Assert.IsNotNull(model);
424 SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models);
425 semanticVisitor.VisitNode(model);
427 XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor();
428 xmlVisitor.CreateXml(model);
430 String xml = xmlVisitor.Xml;
432 String expected =
433 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
434 "<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" +
435 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassWithMappedField, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClassWithMappedField\">\r\n" +
436 " <id name=\"Id\" access=\"nosetter.camelcase-underscore\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
437 " <generator class=\"native\">\r\n" +
438 " </generator>\r\n" +
439 " </id>\r\n" +
440 " <property name=\"name1\" access=\"field\" type=\"String\">\r\n" +
441 " <column name=\"MyCustomName\"/>\r\n" +
442 " </property>\r\n" +
443 " <property name=\"Value\" access=\"CustomAccess\" type=\"Int32\">\r\n" +
444 " <column name=\"Value\"/>\r\n" +
445 " </property>\r\n" +
446 " </class>\r\n" +
447 "</hibernate-mapping>\r\n";
449 Assert.AreEqual(expected, xml);
452 [Test]
453 public void SimpleCompositeClass()
455 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
456 ActiveRecordModel model = builder.Create(typeof(ClassWithCompositeKey2));
457 Assert.IsNotNull(model);
459 String xml = Process(builder, model);
460 String expected =
461 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
462 "<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" +
463 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassWithCompositeKey2, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClassWithCompositeKey2\" lazy=\"false\">\r\n" +
464 " <composite-id name=\"Key\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.CompositeKey2, Castle.ActiveRecord.Framework.Internal.Tests\" unsaved-value=\"none\" access=\"property\">\r\n" +
465 " <key-property name=\"Key1\" access=\"property\" column=\"Key1\" type=\"Int32\" />\r\n" +
466 " <key-property name=\"Key2\" access=\"property\" column=\"Key2\" type=\"String\" />\r\n" +
467 " </composite-id>\r\n" +
468 " </class>\r\n" +
469 "</hibernate-mapping>\r\n";
471 Assert.AreEqual(expected, xml);
474 [Test, Ignore("This is not implemented yet")]
475 public void CompositeClassWithBelongsTo()
477 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
478 ActiveRecordModel model = builder.Create(typeof(ClassWithCompositeKey3));
479 Assert.IsNotNull(model);
481 String xml = Process(builder, model);
482 String expected =
483 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
484 "<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" +
485 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassWithCompositeKey3, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClassWithCompositeKey3\" lazy=\"false\">\r\n" +
486 " <composite-id name=\"Key\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.CompositeKey2, Castle.ActiveRecord.Framework.Internal.Tests\" unsaved-value=\"none\" access=\"property\">\r\n" +
487 " <key-property name=\"Key1\" access=\"property\" column=\"Key1\" type=\"Int32\" />\r\n" +
488 " <key-many-to-one name=\"Key2\" access=\"property\" column=\"Key2\" type=\"String\" />\r\n" +
489 " </composite-id>\r\n" +
490 " </class>\r\n" +
491 "</hibernate-mapping>\r\n";
493 Assert.AreEqual(expected, xml);
496 [Test]
497 public void SimpleClassWithElementList()
499 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
500 ActiveRecordModel model = builder.Create(typeof(ClassWithElementList));
501 Assert.IsNotNull(model);
503 String xml = Process(builder, model);
504 String expected =
505 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
506 "<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" +
507 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassWithElementList, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClassWithElementList\">\r\n" +
508 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
509 " <generator class=\"native\">\r\n" +
510 " </generator>\r\n" +
511 " </id>\r\n" +
512 " <bag name=\"Elements\" access=\"property\" table=\"Elements\" lazy=\"false\">\r\n" +
513 " <key column=\"ClassId\" />\r\n" +
514 " <element column=\"Name\" type=\"System.String, mscorlib\"/>\r\n" +
515 " </bag>\r\n" +
516 " </class>\r\n" +
517 "</hibernate-mapping>\r\n";
519 Assert.AreEqual(expected, xml);
522 [Test]
523 public void DiscriminatorUse()
525 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
526 builder.Create(typeof(ClassDiscriminatorA));
527 ActiveRecordModel model = builder.Create(typeof(ClassDiscriminatorParent));
528 Assert.IsNotNull(model);
530 String xml = Process(builder, model);
532 String expected =
533 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
534 "<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" +
535 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassDiscriminatorParent, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"disctable\" discriminator-value=\"parent\">\r\n" +
536 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
537 " <generator class=\"native\">\r\n" +
538 " </generator>\r\n" +
539 " </id>\r\n" +
540 " <discriminator column=\"type\" type=\"String\" />\r\n" +
541 " <property name=\"Name\" access=\"property\" type=\"String\">\r\n" +
542 " <column name=\"Name\"/>\r\n" +
543 " </property>\r\n" +
544 " <subclass name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassDiscriminatorA, Castle.ActiveRecord.Framework.Internal.Tests\" discriminator-value=\"A\">\r\n" +
545 " <property name=\"Age\" access=\"property\" type=\"Int32\">\r\n" +
546 " <column name=\"Age\"/>\r\n" +
547 " </property>\r\n" +
548 " </subclass>\r\n" +
549 " </class>\r\n" +
550 "</hibernate-mapping>\r\n";
552 Assert.AreEqual(expected, xml);
555 [Test]
556 public void DiscriminatorLengthUse()
558 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
559 builder.Create(typeof(ClassDiscriminatorB));
560 ActiveRecordModel model = builder.Create(typeof(ClassDiscriminatorLengthParent));
561 Assert.IsNotNull(model);
563 String xml = Process(builder, model);
565 String expected =
566 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
567 "<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" +
568 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassDiscriminatorLengthParent, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"disctable\" discriminator-value=\"parent\">\r\n" +
569 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
570 " <generator class=\"native\">\r\n" +
571 " </generator>\r\n" +
572 " </id>\r\n" +
573 " <discriminator column=\"type\" type=\"String\" length=\"10\" />\r\n" +
574 " <property name=\"Name\" access=\"property\" type=\"String\">\r\n" +
575 " <column name=\"Name\"/>\r\n" +
576 " </property>\r\n" +
577 " <subclass name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassDiscriminatorB, Castle.ActiveRecord.Framework.Internal.Tests\" discriminator-value=\"B\">\r\n" +
578 " <property name=\"Age\" access=\"property\" type=\"Int32\">\r\n" +
579 " <column name=\"Age\"/>\r\n" +
580 " </property>\r\n" +
581 " </subclass>\r\n" +
582 " </class>\r\n" +
583 "</hibernate-mapping>\r\n";
585 Assert.AreEqual(expected, xml);
588 [Test]
589 public void JoinedSubClassUseWithGenericType()
591 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
592 builder.Create(typeof(GenClassJoinedSubClassA));
593 ActiveRecordModel model = builder.Create(typeof(GenClassJoinedSubClassParent));
594 Assert.IsNotNull(model);
596 String xml = Process(builder, model);
598 String expected =
599 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
600 "<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" +
601 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.GenClassJoinedSubClassParent, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"disctable\" lazy=\"false\">\r\n" +
602 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
603 " <generator class=\"native\">\r\n" +
604 " </generator>\r\n" +
605 " </id>\r\n" +
606 " <property name=\"Name\" access=\"property\" type=\"String\">\r\n" +
607 " <column name=\"Name\"/>\r\n" +
608 " </property>\r\n" +
609 " <joined-subclass name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.GenClassJoinedSubClassA, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"disctablea\" lazy=\"false\">\r\n" +
610 " <key column=\"AId\" />\r\n" +
611 " <property name=\"Age\" access=\"property\" type=\"Int32\">\r\n" +
612 " <column name=\"Age\"/>\r\n" +
613 " </property>\r\n" +
614 " </joined-subclass>\r\n" +
615 " </class>\r\n" +
616 "</hibernate-mapping>\r\n";
618 Assert.AreEqual(expected, xml);
621 [Test]
622 public void JoinedSubClassUseWithGenericTypeAndAbstractBase()
624 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
625 builder.Create(typeof(SubClassJoinedClass));
626 ActiveRecordModel model = builder.Create(typeof(BaseJoinedClass));
627 Assert.IsNotNull(model);
629 String xml = Process(builder, model);
631 String expected =
632 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
633 "<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" +
634 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.BaseJoinedClass, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"disctable\" lazy=\"false\">\r\n" +
635 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
636 " <generator class=\"native\">\r\n" +
637 " </generator>\r\n" +
638 " </id>\r\n" +
639 " <property name=\"Name\" access=\"property\" type=\"String\">\r\n" +
640 " <column name=\"Name\"/>\r\n" +
641 " </property>\r\n" +
642 " <joined-subclass name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.SubClassJoinedClass, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"disctablea\" lazy=\"false\">\r\n" +
643 " <key column=\"AId\" />\r\n" +
644 " <property name=\"Age\" access=\"property\" type=\"Int32\">\r\n" +
645 " <column name=\"Age\"/>\r\n" +
646 " </property>\r\n" +
647 " </joined-subclass>\r\n" +
648 " </class>\r\n" +
649 "</hibernate-mapping>\r\n";
651 Assert.AreEqual(expected, xml);
654 [Test]
655 public void JoinedSubClassUseWithGenericTypeAndGenericAbstractBase()
657 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
658 builder.Create(typeof(GenSubClassJoinedClass));
659 ActiveRecordModel model = builder.Create(typeof(GenBaseJoinedClass<GenSubClassJoinedClass>));
660 Assert.IsNotNull(model);
662 String xml = Process(builder, model);
664 String expected =
665 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
666 "<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" +
667 " <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" +
668 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
669 " <generator class=\"native\">\r\n" +
670 " </generator>\r\n" +
671 " </id>\r\n" +
672 " <property name=\"Name\" access=\"property\" type=\"String\">\r\n" +
673 " <column name=\"Name\"/>\r\n" +
674 " </property>\r\n" +
675 " <joined-subclass name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.GenSubClassJoinedClass, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"disctablea\" lazy=\"false\">\r\n" +
676 " <key column=\"AId\" />\r\n" +
677 " <property name=\"Age\" access=\"property\" type=\"Int32\">\r\n" +
678 " <column name=\"Age\"/>\r\n" +
679 " </property>\r\n" +
680 " </joined-subclass>\r\n" +
681 " </class>\r\n" +
682 "</hibernate-mapping>\r\n";
684 Assert.AreEqual(expected, xml);
687 [Test]
688 public void JoinedSubClassUse()
690 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
691 builder.Create(typeof(ClassJoinedSubClassA));
692 ActiveRecordModel model = builder.Create(typeof(ClassJoinedSubClassParent));
693 Assert.IsNotNull(model);
695 String xml = Process(builder, model);
697 String expected =
698 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
699 "<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" +
700 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassJoinedSubClassParent, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"disctable\" lazy=\"false\">\r\n" +
701 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
702 " <generator class=\"native\">\r\n" +
703 " </generator>\r\n" +
704 " </id>\r\n" +
705 " <property name=\"Name\" access=\"property\" type=\"String\">\r\n" +
706 " <column name=\"Name\"/>\r\n" +
707 " </property>\r\n" +
708 " <joined-subclass name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassJoinedSubClassA, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"disctablea\" lazy=\"false\">\r\n" +
709 " <key column=\"AId\" />\r\n" +
710 " <property name=\"Age\" access=\"property\" type=\"Int32\">\r\n" +
711 " <column name=\"Age\"/>\r\n" +
712 " </property>\r\n" +
713 " </joined-subclass>\r\n" +
714 " </class>\r\n" +
715 "</hibernate-mapping>\r\n";
717 Assert.AreEqual(expected, xml);
720 [Test]
721 public void VersionedClass()
723 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
724 ActiveRecordModel model = builder.Create(typeof(VersionedClass));
725 Assert.IsNotNull(model);
727 String xml = Process(builder, model);
729 String expected =
730 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
731 "<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" +
732 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.VersionedClass, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"VersionedClass\" lazy=\"false\">\r\n" +
733 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
734 " <generator class=\"native\">\r\n" +
735 " </generator>\r\n" +
736 " </id>\r\n" +
737 " <version name=\"Ver\" access=\"property\" column=\"Ver\" type=\"String\" />\r\n" +
738 " <property name=\"Name\" access=\"property\" type=\"String\">\r\n" +
739 " <column name=\"Name\"/>\r\n" +
740 " </property>\r\n" +
741 " </class>\r\n" +
742 "</hibernate-mapping>\r\n";
744 Assert.AreEqual(expected, xml);
747 [Test]
748 public void TimestampedClass()
750 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
751 ActiveRecordModel model = builder.Create(typeof(TimestampedClass));
752 Assert.IsNotNull(model);
754 String xml = Process(builder, model);
756 String expected =
757 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
758 "<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" +
759 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.TimestampedClass, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"TimestampedClass\" lazy=\"false\">\r\n" +
760 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
761 " <generator class=\"native\">\r\n" +
762 " </generator>\r\n" +
763 " </id>\r\n" +
764 " <timestamp name=\"Ts\" access=\"property\" column=\"Ts\" />\r\n" +
765 " <property name=\"Name\" access=\"property\" type=\"String\">\r\n" +
766 " <column name=\"Name\"/>\r\n" +
767 " </property>\r\n" +
768 " </class>\r\n" +
769 "</hibernate-mapping>\r\n";
771 Assert.AreEqual(expected, xml);
774 [Test]
775 public void SequenceParamClass()
777 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
778 ActiveRecordModel model = builder.Create(typeof(SequenceParamClass));
779 Assert.IsNotNull(model);
781 String xml = Process(builder, model);
783 String expected =
784 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
785 "<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" +
786 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.SequenceParamClass, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"SequenceParamClass\" lazy=\"false\">\r\n" +
787 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
788 " <generator class=\"sequence\">\r\n" +
789 " <param name=\"sequence\">my_seq</param>\r\n" +
790 " </generator>\r\n" +
791 " </id>\r\n" +
792 " </class>\r\n" +
793 "</hibernate-mapping>\r\n";
795 Assert.AreEqual(expected, xml);
798 [Test]
799 public void BelongsTo1()
801 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
802 ActiveRecordModel model = builder.Create(typeof(BelongsToClassA));
803 Assert.IsNotNull(model);
805 String xml = Process(builder, model);
807 String expected =
808 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
809 "<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" +
810 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.BelongsToClassA, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"BelongsToClassA\" lazy=\"false\">\r\n" +
811 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
812 " <generator class=\"native\">\r\n" +
813 " </generator>\r\n" +
814 " </id>\r\n" +
815 " <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" +
816 " </class>\r\n" +
817 "</hibernate-mapping>\r\n";
819 Assert.AreEqual(expected, xml);
822 [Test]
823 public void BelongsTo2()
825 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
826 ActiveRecordModel model = builder.Create(typeof(BelongsToClassA2));
827 Assert.IsNotNull(model);
829 String xml = Process(builder, model);
831 String expected =
832 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
833 "<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" +
834 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.BelongsToClassA2, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"BelongsToClassA2\" lazy=\"false\">\r\n" +
835 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
836 " <generator class=\"native\">\r\n" +
837 " </generator>\r\n" +
838 " </id>\r\n" +
839 " <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" +
840 " </class>\r\n" +
841 "</hibernate-mapping>\r\n";
843 Assert.AreEqual(expected, xml);
846 [Test]
847 public void BelongsToWithFetch()
849 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
850 ActiveRecordModel model = builder.Create(typeof(BelongsToClassAFetch));
851 Assert.IsNotNull(model);
853 String xml = Process(builder, model);
855 String expected =
856 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
857 "<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" +
858 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.BelongsToClassAFetch, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"BelongsToClassAFetch\" lazy=\"false\">\r\n" +
859 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
860 " <generator class=\"native\">\r\n" +
861 " </generator>\r\n" +
862 " </id>\r\n" +
863 " <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" +
864 " </class>\r\n" +
865 "</hibernate-mapping>\r\n";
867 Assert.AreEqual(expected, xml);
870 [Test]
871 public void HasManyWithExplicitInfo()
873 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
874 ActiveRecordModel model = builder.Create(typeof(HasManyClassA));
875 Assert.IsNotNull(model);
877 String xml = Process(builder, model);
879 String expected =
880 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
881 "<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" +
882 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.HasManyClassA, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"HasManyClassA\" lazy=\"false\">\r\n" +
883 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
884 " <generator class=\"native\">\r\n" +
885 " </generator>\r\n" +
886 " </id>\r\n" +
887 " <bag name=\"Items\" access=\"property\" table=\"ClassATable\" lazy=\"false\" inverse=\"true\">\r\n" +
888 " <key column=\"keycol\" />\r\n" +
889 " <one-to-many class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassA, Castle.ActiveRecord.Framework.Internal.Tests\" />\r\n" +
890 " </bag>\r\n" +
891 " </class>\r\n" +
892 "</hibernate-mapping>\r\n";
894 Assert.AreEqual(expected, xml);
897 [Test]
898 public void HasManyWithFetch()
900 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
901 ActiveRecordModel model = builder.Create(typeof(HasManyWithFetch));
902 Assert.IsNotNull(model);
904 String xml = Process(builder, model);
906 String expected =
907 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
908 "<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" +
909 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.HasManyWithFetch, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"HasManyWithFetch\" lazy=\"false\">\r\n" +
910 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
911 " <generator class=\"native\">\r\n" +
912 " </generator>\r\n" +
913 " </id>\r\n" +
914 " <bag name=\"Items\" access=\"property\" table=\"ClassATable\" lazy=\"false\" inverse=\"true\" fetch=\"join\">\r\n" +
915 " <key column=\"keycol\" />\r\n" +
916 " <one-to-many class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassA, Castle.ActiveRecord.Framework.Internal.Tests\" />\r\n" +
917 " </bag>\r\n" +
918 " </class>\r\n" +
919 "</hibernate-mapping>\r\n";
921 Assert.AreEqual(expected, xml);
924 [Test]
925 public void HasManyWithBatch()
927 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
928 ActiveRecordModel model = builder.Create(typeof(HasManyWithBatch));
929 Assert.IsNotNull(model);
931 String xml = Process(builder, model);
933 String expected =
934 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
935 "<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" +
936 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.HasManyWithBatch, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"HasManyWithBatch\" lazy=\"false\">\r\n" +
937 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
938 " <generator class=\"native\">\r\n" +
939 " </generator>\r\n" +
940 " </id>\r\n" +
941 " <bag name=\"Items\" access=\"property\" table=\"ClassATable\" lazy=\"false\" inverse=\"true\" batch-size=\"3\">\r\n" +
942 " <key column=\"keycol\" />\r\n" +
943 " <one-to-many class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassA, Castle.ActiveRecord.Framework.Internal.Tests\" />\r\n" +
944 " </bag>\r\n" +
945 " </class>\r\n" +
946 "</hibernate-mapping>\r\n";
948 Assert.AreEqual(expected, xml);
951 [Test]
952 public void HasManyInfering()
954 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
955 ActiveRecordModel model = builder.Create(typeof(Category));
956 Assert.IsNotNull(model);
958 String xml = Process(builder, model);
960 String expected =
961 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
962 "<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" +
963 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.Category, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"Category\" lazy=\"false\">\r\n" +
964 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
965 " <generator class=\"native\">\r\n" +
966 " </generator>\r\n" +
967 " </id>\r\n" +
968 " <property name=\"Name\" access=\"property\" type=\"String\">\r\n" +
969 " <column name=\"Name\"/>\r\n" +
970 " </property>\r\n" +
971 " <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" +
972 " <bag name=\"SubCategories\" access=\"property\" table=\"Category\" lazy=\"false\">\r\n" +
973 " <key column=\"parent_id\" />\r\n" +
974 " <one-to-many class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.Category, Castle.ActiveRecord.Framework.Internal.Tests\" />\r\n" +
975 " </bag>\r\n" +
976 " </class>\r\n" +
977 "</hibernate-mapping>\r\n";
979 Assert.AreEqual(expected, xml);
982 [Test]
983 public void CompositeKey()
985 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
986 ActiveRecordModel model = builder.Create(typeof(ClassWithCompositeKey));
987 Assert.IsNotNull(model);
989 string xml = Process(builder, model);
991 string expected =
992 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
993 "<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" +
994 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassWithCompositeKey, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"ClassWithCompositeKey\" lazy=\"false\">\r\n" +
995 " <composite-id name=\"Key\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.CompositeKeyForClassWithCompositeKey, Castle.ActiveRecord.Framework.Internal.Tests\" unsaved-value=\"none\" access=\"property\">\r\n" +
996 " <key-property name=\"KeyA\" access=\"property\" column=\"KeyA\" type=\"String\" />\r\n" +
997 " <key-property name=\"KeyB\" access=\"property\" column=\"KeyB\" type=\"String\" />\r\n" +
998 " </composite-id>\r\n" +
999 " </class>\r\n" +
1000 "</hibernate-mapping>\r\n";
1002 Assert.AreEqual(expected, xml);
1005 [Test]
1006 public void One2OneKey()
1008 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
1009 ActiveRecordModel empModel = builder.Create(typeof(Employee));
1010 ActiveRecordModel awardModel = builder.Create(typeof(Award));
1011 Assert.IsNotNull(empModel);
1012 Assert.IsNotNull(awardModel);
1014 string xml = Process(builder, empModel);
1016 string expected =
1017 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
1018 "<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" +
1019 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.Employee, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"Employee\" lazy=\"false\">\r\n" +
1020 " <id name=\"ID\" access=\"property\" column=\"EmployeeID\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
1021 " <generator class=\"native\">\r\n" +
1022 " </generator>\r\n" +
1023 " </id>\r\n" +
1024 " <property name=\"FirstName\" access=\"property\" type=\"String\">\r\n" +
1025 " <column name=\"FirstName\"/>\r\n" +
1026 " </property>\r\n" +
1027 " <property name=\"LastName\" access=\"property\" type=\"String\">\r\n" +
1028 " <column name=\"LastName\"/>\r\n" +
1029 " </property>\r\n" +
1030 " <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" +
1031 " </class>\r\n" +
1032 "</hibernate-mapping>\r\n";
1034 Assert.AreEqual(expected, xml);
1036 xml = Process(builder, awardModel);
1038 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.Award, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"Award\" lazy=\"false\">\r\n" +
1042 " <id name=\"ID\" access=\"property\" column=\"EmployeeID\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
1043 " <generator class=\"foreign\">\r\n" +
1044 " <param name=\"property\">Employee</param>\r\n" +
1045 " </generator>\r\n" +
1046 " </id>\r\n" +
1047 " <property name=\"Description\" access=\"property\" type=\"String\">\r\n" +
1048 " <column name=\"Description\"/>\r\n" +
1049 " </property>\r\n" +
1050 " <one-to-one name=\"Employee\" access=\"property\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.Employee, Castle.ActiveRecord.Framework.Internal.Tests\" />\r\n" +
1051 " </class>\r\n" +
1052 "</hibernate-mapping>\r\n";
1054 Assert.AreEqual(expected, xml);
1057 [Test]
1058 public void CachedClass()
1060 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
1061 ActiveRecordModel model = builder.Create(typeof(CacheClass));
1062 Assert.IsNotNull(model);
1064 String xml = Process(builder, model);
1066 String expected =
1067 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
1068 "<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" +
1069 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.CacheClass, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"CacheClass\" lazy=\"false\">\r\n" +
1070 " <cache region=\"Region1\" usage=\"read-write\" />\r\n" +
1071 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
1072 " <generator class=\"native\">\r\n" +
1073 " </generator>\r\n" +
1074 " </id>\r\n" +
1075 " <property name=\"Name\" access=\"property\" type=\"String\">\r\n" +
1076 " <column name=\"Name\"/>\r\n" +
1077 " </property>\r\n" +
1078 " <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" +
1079 " <bag name=\"SubClasses\" access=\"property\" table=\"CacheClass\" lazy=\"false\">\r\n" +
1080 " <cache usage=\"read-write\" />\r\n" +
1081 " <key column=\"parent_id\" />\r\n" +
1082 " <one-to-many class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.CacheClass, Castle.ActiveRecord.Framework.Internal.Tests\" />\r\n" +
1083 " </bag>\r\n" +
1084 " </class>\r\n" +
1085 "</hibernate-mapping>\r\n";
1087 Assert.AreEqual(expected, xml);
1090 [Test]
1091 public void NotFoundBehaviourClass()
1093 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
1094 ActiveRecordModel NotFoundBehaviourClassModel = builder.Create(typeof(NotFoundBehaviourClass));
1095 ActiveRecordModel RelationalFoobarModel = builder.Create(typeof(RelationalFoobar));
1096 Assert.IsNotNull(NotFoundBehaviourClassModel);
1097 Assert.IsNotNull(RelationalFoobarModel);
1099 String xml = Process(builder, NotFoundBehaviourClassModel);
1101 String expected =
1102 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
1103 "<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" +
1104 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.NotFoundBehaviourClass, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"NotFoundBehaviourClass\">\r\n" +
1105 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
1106 " <generator class=\"native\">\r\n" +
1107 " </generator>\r\n" +
1108 " </id>\r\n" +
1109 " <bag name=\"SubClasses\" access=\"property\" table=\"RelationalFoobarTable\" lazy=\"false\">\r\n" +
1110 " <key column=\"keycol\" />\r\n" +
1111 " <one-to-many class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.RelationalFoobar, Castle.ActiveRecord.Framework.Internal.Tests\" not-found=\"ignore\" />\r\n" +
1112 " </bag>\r\n" +
1113 " <bag name=\"ManySubClasses\" access=\"property\" table=\"ManySubClasses\" lazy=\"false\">\r\n" +
1114 " <key column=\"id\" />\r\n" +
1115 " <many-to-many class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.RelationalFoobar, Castle.ActiveRecord.Framework.Internal.Tests\" column=\"ref_id\" not-found=\"ignore\"/>\r\n" +
1116 " </bag>\r\n" +
1117 " </class>\r\n" +
1118 "</hibernate-mapping>\r\n";
1120 Assert.AreEqual(expected, xml);
1122 xml = Process(builder, RelationalFoobarModel);
1124 expected =
1125 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
1126 "<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" +
1127 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.RelationalFoobar, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"RelationalFoobar\">\r\n" +
1128 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
1129 " <generator class=\"native\">\r\n" +
1130 " </generator>\r\n" +
1131 " </id>\r\n" +
1132 " <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" +
1133 " <bag name=\"NotFoundBehaviourClassList\" access=\"property\" table=\"ManySubClasses\" lazy=\"false\">\r\n" +
1134 " <key column=\"id\" />\r\n" +
1135 " <many-to-many class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.NotFoundBehaviourClass, Castle.ActiveRecord.Framework.Internal.Tests\" column=\"ref_id\" not-found=\"ignore\"/>\r\n" +
1136 " </bag>\r\n" +
1137 " </class>\r\n" +
1138 "</hibernate-mapping>\r\n";
1140 Assert.AreEqual(expected, xml);
1143 [Test]
1144 public void EnumWithColumnType()
1146 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
1147 ActiveRecordModel model = builder.Create(typeof(EnumTestClass));
1148 Assert.IsNotNull(model);
1150 string xml = Process(builder, model);
1152 string expected =
1153 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
1154 "<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" +
1155 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.EnumTestClass, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"EnumTestClass\" lazy=\"false\">\r\n" +
1156 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
1157 " <generator class=\"native\">\r\n" +
1158 " </generator>\r\n" +
1159 " </id>\r\n" +
1160 " <property name=\"NoColumnType\" access=\"property\">\r\n" +
1161 " <column name=\"NoColumnType\"/>\r\n" +
1162 " </property>\r\n" +
1163 " <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" +
1164 " <column name=\"WithColumnType\"/>\r\n" +
1165 " </property>\r\n" +
1166 " </class>\r\n" +
1167 "</hibernate-mapping>\r\n";
1169 Assert.AreEqual(expected, xml);
1172 private string Process(ActiveRecordModelBuilder builder, ActiveRecordModel model)
1174 GraphConnectorVisitor connectorVisitor = new GraphConnectorVisitor(builder.Models);
1175 connectorVisitor.VisitNode(model);
1177 SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models);
1178 semanticVisitor.VisitNode(model);
1180 XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor();
1181 xmlVisitor.CreateXml(model);
1183 return xmlVisitor.Xml;
1186 [Test]
1187 public void HasManyWithDictionary()
1189 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
1190 ActiveRecordModel model = builder.Create(typeof(DictionaryModel));
1191 Assert.IsNotNull(model);
1193 string xml = Process(builder, model);
1195 string expected =
1196 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
1197 "<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" +
1198 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.DictionaryModel, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"DictionaryModel\">\r\n" +
1199 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
1200 " <generator class=\"native\">\r\n" +
1201 " </generator>\r\n" +
1202 " </id>\r\n" +
1203 " <map name=\"Snippet\" access=\"property\" table=\"DictionaryModel_Snippet\" lazy=\"false\">\r\n" +
1204 " <key column=\"id\" />\r\n" +
1205 " <index column=\"LangCode\" type=\"String\" />\r\n" +
1206 " <element column=\"Text\" type=\"System.String, mscorlib\"/>\r\n" +
1207 " </map>\r\n" +
1208 " </class>\r\n" +
1209 "</hibernate-mapping>\r\n";
1211 Assert.AreEqual(expected, xml);
1214 [Test]
1215 public void SimpleListOfComponents()
1217 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
1218 ActiveRecordModel model = builder.Create(typeof(HasManyDependentObjects));
1219 Assert.IsNotNull(model);
1221 String xml = Process(builder, model);
1223 string expected =
1224 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
1225 "<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" +
1226 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.HasManyDependentObjects, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"HasManyDependentObjects\">\r\n" +
1227 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
1228 " <generator class=\"native\">\r\n" +
1229 " </generator>\r\n" +
1230 " </id>\r\n" +
1231 " <list name=\"Components\" access=\"property\" table=\"dependent_objects\" lazy=\"false\">\r\n" +
1232 " <key column=\"id\" />\r\n" +
1233 " <index column=\"pos\" />\r\n" +
1234 " <composite-element class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.Component, Castle.ActiveRecord.Framework.Internal.Tests\">\r\n" +
1235 " <property name=\"Value\" access=\"property\" type=\"String\">\r\n" +
1236 " <column name=\"Value\"/>\r\n" +
1237 " </property>\r\n" +
1238 " </composite-element>\r\n" +
1239 " </list>\r\n" +
1240 " </class>\r\n" +
1241 "</hibernate-mapping>\r\n";
1243 Assert.AreEqual(expected, xml);
1246 [Test]
1247 public void SimpleListOfComponentsWithNestedComponents()
1249 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
1250 ActiveRecordModel model = builder.Create(typeof(HasManyDependentObjectsWithNested));
1251 Assert.IsNotNull(model);
1253 String xml = Process(builder, model);
1255 string expected =
1256 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
1257 "<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" +
1258 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.HasManyDependentObjectsWithNested, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"HasManyDependentObjectsWithNested\">\r\n" +
1259 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
1260 " <generator class=\"native\">\r\n" +
1261 " </generator>\r\n" +
1262 " </id>\r\n" +
1263 " <list name=\"ComponentsWithNested\" access=\"property\" table=\"dependent_objects\" lazy=\"false\">\r\n" +
1264 " <key column=\"id\" />\r\n" +
1265 " <index column=\"pos\" />\r\n" +
1266 " <composite-element class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ComponentWithNested, Castle.ActiveRecord.Framework.Internal.Tests\">\r\n" +
1267 " <nested-composite-element name=\"Component\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.Component, Castle.ActiveRecord.Framework.Internal.Tests\" access=\"property\">\r\n" +
1268 " <property name=\"Value\" access=\"property\" type=\"String\">\r\n" +
1269 " <column name=\"Value\"/>\r\n" +
1270 " </property>\r\n" +
1271 " </nested-composite-element>\r\n" +
1272 " </composite-element>\r\n" +
1273 " </list>\r\n" +
1274 " </class>\r\n" +
1275 "</hibernate-mapping>\r\n";
1277 Assert.AreEqual(expected, xml);
1280 [Test]
1281 public void SimpleListOfComponentsWithNestedComponents2LevelsDeep()
1283 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
1284 ActiveRecordModel model = builder.Create(typeof(HasManyDependentObjectsWithNested2LevelsDeep));
1285 Assert.IsNotNull(model);
1287 String xml = Process(builder, model);
1289 string expected =
1290 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
1291 "<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" +
1292 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.HasManyDependentObjectsWithNested2LevelsDeep, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"HasManyDependentObjectsWithNested2LevelsDeep\">\r\n" +
1293 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
1294 " <generator class=\"native\">\r\n" +
1295 " </generator>\r\n" +
1296 " </id>\r\n" +
1297 " <list name=\"ComponentsWithNested2LevelsDeep\" access=\"property\" table=\"dependent_objects\" lazy=\"false\">\r\n" +
1298 " <key column=\"id\" />\r\n" +
1299 " <index column=\"pos\" />\r\n" +
1300 " <composite-element class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ComponentWithNested2LevelsDeep, Castle.ActiveRecord.Framework.Internal.Tests\">\r\n" +
1301 " <nested-composite-element name=\"ComponentWithNested\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ComponentWithNested, Castle.ActiveRecord.Framework.Internal.Tests\" access=\"property\">\r\n" +
1302 " <nested-composite-element name=\"Component\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.Component, Castle.ActiveRecord.Framework.Internal.Tests\" access=\"property\">\r\n" +
1303 " <property name=\"Value\" access=\"property\" type=\"String\">\r\n" +
1304 " <column name=\"Value\"/>\r\n" +
1305 " </property>\r\n" +
1306 " </nested-composite-element>\r\n" +
1307 " </nested-composite-element>\r\n" +
1308 " </composite-element>\r\n" +
1309 " </list>\r\n" +
1310 " </class>\r\n" +
1311 "</hibernate-mapping>\r\n";
1313 Assert.AreEqual(expected, xml);
1316 [Test]
1317 public void ManyToMayViaComponents()
1319 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
1320 ActiveRecordModel model = builder.Create(typeof(HasManyToManyViaComponents));
1321 Assert.IsNotNull(model);
1323 String xml = Process(builder, model);
1324 string expected =
1325 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
1326 "<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" +
1327 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.HasManyToManyViaComponents, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"HasManyToManyViaComponents\">\r\n" +
1328 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
1329 " <generator class=\"native\">\r\n" +
1330 " </generator>\r\n" +
1331 " </id>\r\n" +
1332 " <list name=\"Components\" access=\"property\" table=\"components_to_a\" lazy=\"false\">\r\n" +
1333 " <key column=\"id\" />\r\n" +
1334 " <index column=\"pos\" />\r\n" +
1335 " <composite-element class=\"Castle.ActiveRecord.Framework.Internal.Tests.ComponentManyToClassA, Castle.ActiveRecord.Framework.Internal.Tests\">\r\n" +
1336 " <property name=\"Value\" access=\"property\" type=\"String\">\r\n" +
1337 " <column name=\"Value\"/>\r\n" +
1338 " </property>\r\n" +
1339 " <many-to-one name=\"A\" access=\"property\" class=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassA, Castle.ActiveRecord.Framework.Internal.Tests\" column=\"aId\" />\r\n" +
1340 " </composite-element>\r\n" +
1341 " </list>\r\n" +
1342 " </class>\r\n" +
1343 "</hibernate-mapping>\r\n";
1344 Assert.AreEqual(expected, xml);
1347 [Test]
1348 public void IdBagPrimitive()
1350 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
1351 ActiveRecordModel model = builder.Create(typeof(IdBagPrimitive));
1352 Assert.IsNotNull(model);
1354 String xml = Process(builder, model);
1355 string expected =
1356 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
1357 "<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" +
1358 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.IdBagPrimitive, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"IdBagPrimitive\">\r\n" +
1359 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
1360 " <generator class=\"native\">\r\n" +
1361 " </generator>\r\n" +
1362 " </id>\r\n" +
1363 " <idbag name=\"Items\" access=\"property\" table=\"IdToItems\" lazy=\"false\">\r\n" +
1364 " <collection-id type=\"Int32\" column=\"col\">\r\n" +
1365 " <generator class=\"sequence\">\r\n" +
1366 " </generator>\r\n" +
1367 " </collection-id>\r\n" +
1368 " <key column=\"keyid\" />\r\n" +
1369 " <element type=\"string\" />\r\n" +
1370 " </idbag>\r\n" +
1371 " </class>\r\n" +
1372 "</hibernate-mapping>\r\n";
1373 Assert.AreEqual(expected, xml);
1376 [Test]
1377 public void SimpleClassWithOverride()
1379 ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();
1380 ActiveRecordModel model = builder.Create(typeof(SimpleClass));
1381 Assert.IsNotNull(model);
1383 String xml = Process(builder, model);
1385 String expected =
1386 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
1387 "<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" +
1388 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.SimpleClass, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"SimpleClass\" lazy=\"false\">\r\n" +
1389 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
1390 " <generator class=\"native\">\r\n" +
1391 " </generator>\r\n" +
1392 " </id>\r\n" +
1393 " <property name=\"Name\" access=\"property\" type=\"String\">\r\n" +
1394 " <column name=\"Name\"/>\r\n" +
1395 " </property>\r\n" +
1396 " </class>\r\n" +
1397 "</hibernate-mapping>\r\n";
1399 Assert.AreEqual(expected, xml);
1401 model = builder.Create(typeof(SimpleClassOverride));
1402 Assert.IsNotNull(model);
1404 xml = Process(builder, model);
1406 expected =
1407 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
1408 "<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" +
1409 " <class name=\"Castle.ActiveRecord.Framework.Internal.Tests.Model.SimpleClassOverride, Castle.ActiveRecord.Framework.Internal.Tests\" table=\"SimpleClassOverride\" lazy=\"false\">\r\n" +
1410 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
1411 " <generator class=\"native\">\r\n" +
1412 " </generator>\r\n" +
1413 " </id>\r\n" +
1414 " <property name=\"Name\" access=\"property\" type=\"String\">\r\n" +
1415 " <column name=\"Name\" length=\"50\"/>\r\n" +
1416 " </property>\r\n" +
1417 " </class>\r\n" +
1418 "</hibernate-mapping>\r\n";
1420 Assert.AreEqual(expected, xml);