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
17 using NUnit
.Framework
;
19 using Castle
.ActiveRecord
.Tests
.Model
;
22 public class JoinedSubClassTestCase
: AbstractActiveRecordTest
25 public void Entities()
27 ActiveRecordStarter
.Initialize( GetConfigSource(),
28 typeof(Entity
), typeof(CompanyEntity
), typeof(PersonEntity
) );
32 CompanyEntity
.DeleteAll();
33 PersonEntity
.DeleteAll();
35 Entity ent
= new Entity();
39 CompanyEntity ce
= new CompanyEntity();
44 Entity
[] ents
= Entity
.FindAll();
45 Assert
.AreEqual( 2, ents
.Length
);
47 CompanyEntity
[] ces
= CompanyEntity
.FindAll();
48 Assert
.AreEqual( 1, ces
.Length
);
50 PersonEntity
[] pes
= PersonEntity
.FindAll();
51 Assert
.AreEqual( 0, pes
.Length
);
53 Assert
.AreEqual( ce
.CompId
, ces
[0].CompId
);
54 Assert
.AreEqual( ce
.Name
, ces
[0].Name
);
55 Assert
.AreEqual( ce
.Id
, ces
[0].Id
);
59 public void JoinedSubClass_WithAnyProperty()
61 ActiveRecordStarter
.Initialize(GetConfigSource(),
62 typeof(Entity
), typeof(CompanyEntity
), typeof(PersonEntity
), typeof(ManagerEntity
));
66 CompanyEntity
.DeleteAll();
67 PersonEntity
.DeleteAll();
68 ManagerEntity
.DeleteAll();
70 ManagerEntity manager
= new ManagerEntity();
71 manager
.Name
= "pointy haired";
74 PersonEntity person
= new PersonEntity();
75 person
.Name
= "dilbert";
76 person
.Manager
= manager
;
79 PersonEntity
[] people
= PersonEntity
.FindAll();
80 Assert
.AreEqual(1, people
.Length
);
81 Assert
.IsNotNull(people
[0].Manager
);