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
19 using NUnit
.Framework
;
21 using Castle
.ActiveRecord
.Tests
.Model
.StrictModel
;
25 public class StrictModelTestCase
: AbstractActiveRecordTest
28 public new void Init()
32 ActiveRecordStarter
.Initialize( GetConfigSource(),
33 typeof(Estrato
), typeof(ReferenceEstrato
), typeof(SurveyEstrato
),
34 typeof(QuestionContainer
), typeof(Repository
), typeof(Survey
) );
40 public void Creation()
42 Repository repos
= new Repository();
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
;
59 ReferenceEstrato
[] refEsts
= ReferenceEstrato
.FindAll();
60 Assert
.AreEqual(3, refEsts
.Length
);
62 SurveyEstrato
[] surEsts
= SurveyEstrato
.FindAll();
63 Assert
.AreEqual(0, surEsts
.Length
);
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())
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())
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
);
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())
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())
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
);