1 // Copyright 2004-2007 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
19 using NUnit
.Framework
;
21 using Castle
.ActiveRecord
.Tests
.Model
.RulesModel
;
22 using Castle
.ActiveRecord
.Framework
.Internal
;
25 public class ActiveRecordWithoutBaseTestCase
: AbstractActiveRecordTest
31 ActiveRecordStarter
.Initialize(GetConfigSource(),
32 typeof(PersistedRule
),
33 typeof(WorkDaysRules
));
38 public void SimpleOperations()
40 RuleBase
[] rules
= (RuleBase
[]) ActiveRecordMediator
.FindAll(typeof(PersistedRule
));
42 Assert
.IsNotNull(rules
);
43 Assert
.AreEqual(0, rules
.Length
);
45 WorkDaysRules rule
= new WorkDaysRules();
50 ActiveRecordMediator
.Save(rule
);
52 Assert
.IsFalse(0 == rule
.Id
);
54 rules
= (PersistedRule
[]) ActiveRecordMediator
.FindAll(typeof(PersistedRule
));
56 Assert
.IsNotNull(rules
);
57 Assert
.AreEqual(1, rules
.Length
);
59 WorkDaysRules retrieved
= (WorkDaysRules
) ActiveRecordMediator
.FindByPrimaryKey(typeof(WorkDaysRules
), rule
.Id
);
60 Assert
.IsNotNull(retrieved
);
62 Assert
.AreEqual(rule
.Name
, retrieved
.Name
);
63 Assert
.AreEqual(rule
.Count
, retrieved
.Count
);
64 Assert
.AreEqual(rule
.Days
, retrieved
.Days
);
68 public void DiscriminatorUse()
70 XmlGenerationVisitor xmlVisitor
= new XmlGenerationVisitor();
71 xmlVisitor
.CreateXml(ActiveRecordModel
.GetModel(typeof(PersistedRule
)));
72 String xml
= xmlVisitor
.Xml
;
75 "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n"+
76 "<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"+
77 " <class name=\"Castle.ActiveRecord.Tests.Model.RulesModel.PersistedRule, Castle.ActiveRecord.Tests\" table=\"PersistedRule\" discriminator-value=\"0\" lazy=\"false\">\r\n"+
78 " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n"+
79 " <generator class=\"native\">\r\n"+
82 " <discriminator column=\"discriminator\" />\r\n"+
83 " <property name=\"Count\" access=\"property\" type=\"Int32\">\r\n"+
84 " <column name=\"Count\"/>\r\n" +
86 " <subclass name=\"Castle.ActiveRecord.Tests.Model.RulesModel.WorkDaysRules, Castle.ActiveRecord.Tests\" discriminator-value=\"2\" lazy=\"false\">\r\n"+
87 " <property name=\"Name\" access=\"property\" type=\"String\">\r\n"+
88 " <column name=\"Name\"/>\r\n" +
90 " <property name=\"Days\" access=\"property\" type=\"Int32\">\r\n"+
91 " <column name=\"Days\"/>\r\n" +
95 "</hibernate-mapping>\r\n";;
97 Assert
.AreEqual(expected
, xml
);