Added RedirectUsingNamedRoute
[castle.git] / ActiveRecord / Castle.ActiveRecord.Tests / ActiveRecordWithoutBaseTestCase.cs
blob9cb774bfdcc2c48810a497b361971e650ba2f71f
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.Tests
17 using System;
19 using NUnit.Framework;
21 using Castle.ActiveRecord.Tests.Model.RulesModel;
22 using Castle.ActiveRecord.Framework.Internal;
24 [TestFixture]
25 public class ActiveRecordWithoutBaseTestCase : AbstractActiveRecordTest
27 [SetUp]
28 public void Setup()
30 base.Init();
31 ActiveRecordStarter.Initialize(GetConfigSource(),
32 typeof(PersistedRule),
33 typeof(WorkDaysRules));
34 Recreate();
37 [Test]
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();
46 rule.Count = 5;
47 rule.Days = 4;
48 rule.Name = "blah";
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);
67 [Test]
68 public void DiscriminatorUse()
70 XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor();
71 xmlVisitor.CreateXml(ActiveRecordModel.GetModel(typeof(PersistedRule)));
72 String xml = xmlVisitor.Xml;
74 String expected =
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"+
80 " </generator>\r\n"+
81 " </id>\r\n"+
82 " <discriminator column=\"discriminator\" />\r\n"+
83 " <property name=\"Count\" access=\"property\" type=\"Int32\">\r\n"+
84 " <column name=\"Count\"/>\r\n" +
85 " </property>\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" +
89 " </property>\r\n" +
90 " <property name=\"Days\" access=\"property\" type=\"Int32\">\r\n"+
91 " <column name=\"Days\"/>\r\n" +
92 " </property>\r\n" +
93 " </subclass>\r\n"+
94 " </class>\r\n"+
95 "</hibernate-mapping>\r\n";;
97 Assert.AreEqual(expected, xml);