1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
.Tests
18 using Castle
.ActiveRecord
.Framework
;
19 using Castle
.ActiveRecord
.Framework
.Internal
;
20 using Castle
.ActiveRecord
.Tests
.Model
.AnyModel
;
21 using NUnit
.Framework
;
24 public class AnyRelationTestCase
: AbstractActiveRecordTest
27 [ExpectedException(typeof(ActiveRecordException
))]
28 public void TestInvalidAnyMapping()
30 ActiveRecordStarter
.Initialize(GetConfigSource(), typeof(ModelWithInCorrectMapping
));
34 public void XmlConfigTest()
36 ActiveRecordModelBuilder builder
= new ActiveRecordModelBuilder();
37 ActiveRecordModel model
= builder
.Create(typeof(Order
));
38 Assert
.IsNotNull(model
);
40 SemanticVerifierVisitor semanticVisitor
= new SemanticVerifierVisitor(builder
.Models
);
41 semanticVisitor
.VisitNode(model
);
43 XmlGenerationVisitor xmlVisitor
= new XmlGenerationVisitor();
44 xmlVisitor
.CreateXml(model
);
46 String xml
= xmlVisitor
.Xml
;
49 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
50 "<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" +
51 " <class name=\"Castle.ActiveRecord.Tests.Model.AnyModel.Order, Castle.ActiveRecord.Tests\" table=\"Orders\">\r\n" +
52 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" +
53 " <generator class=\"native\">\r\n" +
56 " <bag name=\"Payments\" access=\"property\" table=\"payments_table\" lazy=\"false\">\r\n" +
57 " <key column=\"pay_id\" />\r\n" +
58 " <many-to-any id-type=\"Int32\" meta-type=\"System.String\">\r\n" +
59 " <meta-value value=\"BANK_ACCOUNT\" class=\"Castle.ActiveRecord.Tests.Model.AnyModel.BankAccounts, Castle.ActiveRecord.Tests\" />\r\n" +
60 " <meta-value value=\"CREDIT_CARD\" class=\"Castle.ActiveRecord.Tests.Model.AnyModel.CreditCards, Castle.ActiveRecord.Tests\" />\r\n" +
61 " <column name=\"Billing_Details_Type\" />\r\n" +
62 " <column name=\"Billing_Details_Id\" />\r\n" +
63 " </many-to-any>\r\n" +
66 "</hibernate-mapping>\r\n";
68 Assert
.AreEqual(expected
, xml
);
72 public void SchemaTest()
74 ActiveRecordStarter
.Initialize(GetConfigSource(), typeof(BankAccounts
), typeof(Order
), typeof(CreditCards
));