Added RedirectUsingNamedRoute
[castle.git] / ActiveRecord / Castle.ActiveRecord.Tests / StrictModelTestCase.cs
blob991373118084f5c38eed8a10ce7f6149dcb86d36
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.StrictModel;
24 [TestFixture]
25 public class StrictModelTestCase : AbstractActiveRecordTest
27 [SetUp]
28 public new void Init()
30 base.Init();
32 ActiveRecordStarter.Initialize( GetConfigSource(),
33 typeof(Estrato), typeof(ReferenceEstrato), typeof(SurveyEstrato),
34 typeof(QuestionContainer), typeof(Repository), typeof(Survey) );
36 Recreate();
39 [Test]
40 public void Creation()
42 Repository repos = new Repository();
43 repos.Save();
45 ReferenceEstrato refEst = new ReferenceEstrato();
46 refEst.Repository = repos;
48 ReferenceEstrato subRefEst1 = new ReferenceEstrato();
49 subRefEst1.ParentEstrato = refEst;
50 subRefEst1.Repository = repos;
51 ReferenceEstrato subRefEst2 = new ReferenceEstrato();
52 subRefEst2.ParentEstrato = refEst;
53 subRefEst2.Repository = repos;
55 refEst.Save();
56 subRefEst1.Save();
57 subRefEst2.Save();
59 ReferenceEstrato[] refEsts = ReferenceEstrato.FindAll();
60 Assert.AreEqual(3, refEsts.Length);
62 SurveyEstrato[] surEsts = SurveyEstrato.FindAll();
63 Assert.AreEqual(0, surEsts.Length);
66 [Test]
67 public void DistinctTypes()
69 Repository repos = new Repository();
71 ReferenceEstrato loc = new ReferenceEstrato(repos);
72 ReferenceEstrato sul = new ReferenceEstrato(loc);
73 ReferenceEstrato norte = new ReferenceEstrato(loc);
74 ReferenceEstrato sudeste = new ReferenceEstrato(loc);
75 ReferenceEstrato nordeste = new ReferenceEstrato(loc);
77 using(new SessionScope())
79 repos.Save();
80 loc.Save();
81 sul.Save();
82 sudeste.Save();
83 norte.Save();
84 nordeste.Save();
87 Survey pesquisa = new Survey();
89 SurveyEstrato extCidade = new SurveyEstrato(pesquisa);
90 // extCidade.ReferencedEstratos.Add(loc);
92 SurveyEstrato extSub1 = new SurveyEstrato(extCidade, pesquisa);
93 // extSub1.ReferencedEstratos.Add(sudeste);
95 SurveyEstrato extSub2 = new SurveyEstrato(extCidade, pesquisa);
96 // extSub2.ReferencedEstratos.Add(sudeste);
98 SurveyEstrato extSub3 = new SurveyEstrato(extCidade, pesquisa);
99 // extSub3.ReferencedEstratos.Add(sudeste);
101 using(new SessionScope())
103 pesquisa.Save();
104 extCidade.Save();
105 extSub1.Save();
106 extSub2.Save();
107 extSub3.Save();
110 extCidade = SurveyEstrato.Find(extCidade.Id);
111 Assert.IsNotNull(extCidade);
113 Estrato[] estratos = SurveyEstrato.FindAll();
114 Assert.AreEqual( 4, estratos.Length );
116 estratos = ReferenceEstrato.FindAll();
117 Assert.AreEqual( 5, estratos.Length );
120 [Test]
121 public void UsageWithReferences()
123 Repository repos = new Repository();
125 ReferenceEstrato loc = new ReferenceEstrato(repos);
126 ReferenceEstrato sul = new ReferenceEstrato(loc);
127 ReferenceEstrato norte = new ReferenceEstrato(loc);
128 ReferenceEstrato sudeste = new ReferenceEstrato(loc);
129 ReferenceEstrato nordeste = new ReferenceEstrato(loc);
131 using(new SessionScope())
133 repos.Save();
134 loc.Save();
135 sul.Save();
136 sudeste.Save();
137 norte.Save();
138 nordeste.Save();
141 Survey pesquisa = new Survey();
143 SurveyEstrato extCidade = new SurveyEstrato(pesquisa);
144 extCidade.ReferencedEstratos.Add(loc);
146 SurveyEstrato extSub1 = new SurveyEstrato(extCidade, pesquisa);
147 extSub1.ReferencedEstratos.Add(sudeste);
149 SurveyEstrato extSub2 = new SurveyEstrato(extCidade, pesquisa);
150 extSub2.ReferencedEstratos.Add(sudeste);
152 SurveyEstrato extSub3 = new SurveyEstrato(extCidade, pesquisa);
153 extSub3.ReferencedEstratos.Add(sudeste);
155 using(new SessionScope())
157 pesquisa.Save();
158 extCidade.Save();
159 extSub1.Save();
160 extSub2.Save();
161 extSub3.Save();
164 extCidade = SurveyEstrato.Find(extCidade.Id);
165 Assert.IsNotNull(extCidade);
167 Estrato[] estratos = SurveyEstrato.FindAll();
168 Assert.AreEqual( 4, estratos.Length );
170 estratos = ReferenceEstrato.FindAll();
171 Assert.AreEqual( 5, estratos.Length );