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 System
.Text
.RegularExpressions
;
20 using NUnit
.Framework
;
22 using Castle
.ActiveRecord
.Tests
.Model
.Nested
;
25 public class NestedClassWithPrefixTestCase
: AbstractActiveRecordTest
28 public void WithPrefix()
30 ActiveRecordStarter
.Initialize( GetConfigSource(), typeof(NestedWithPrefix
));
33 String fileName
= null;
36 fileName
= Path
.GetTempFileName();
37 ActiveRecordStarter
.GenerateCreationScripts(fileName
);
38 using (TextReader r
= new StreamReader(fileName
))
40 string schema
= r
.ReadToEnd();
41 Assert
.IsTrue(Regex
.IsMatch(schema
, @"\bfirst\b", RegexOptions
.IgnoreCase
));
42 Assert
.IsTrue(Regex
.IsMatch(schema
, @"\blast\b", RegexOptions
.IgnoreCase
));
43 Assert
.IsTrue(Regex
.IsMatch(schema
, @"\bothername_first\b", RegexOptions
.IgnoreCase
));
44 Assert
.IsTrue(Regex
.IsMatch(schema
, @"\bothername_last\b", RegexOptions
.IgnoreCase
));
50 File
.Delete(fileName
);
53 NestedWithPrefix
.DeleteAll();
55 NestedWithPrefix nested
= new NestedWithPrefix();
58 nested
= NestedWithPrefix
.Find(nested
.Id
);
59 Assert
.AreEqual(1, nested
.Id
);
60 Assert
.IsNull(nested
.Self
);
61 Assert
.IsNull(nested
.Other
);
63 nested
.Self
= new Name();
64 nested
.Self
.First
= "John";
65 nested
.Self
.Middle
= "Mystery";
66 nested
.Self
.Last
= "Doe";
68 nested
.Other
= new Name();
69 nested
.Other
.First
= "Edward";
70 nested
.Other
.Middle
= "G";
71 nested
.Other
.Last
= "Norton";
75 nested
= NestedWithPrefix
.Find(nested
.Id
);
76 Assert
.IsNotNull(nested
.Self
);
77 Assert
.IsNotNull(nested
.Other
);
78 Assert
.AreEqual("John", nested
.Self
.First
);
79 Assert
.AreEqual("Doe", nested
.Self
.Last
);
80 Assert
.AreEqual("Mystery", nested
.Self
.Middle
);
82 Assert
.AreEqual("Edward", nested
.Other
.First
);
83 Assert
.AreEqual("Norton", nested
.Other
.Last
);
84 Assert
.AreEqual("G", nested
.Other
.Middle
);