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 Castle
.ActiveRecord
.Framework
.Config
;
20 using NUnit
.Framework
;
23 public class VerifyModelsAgainstDBSchemaTestCase
: AbstractActiveRecordTest
25 [Test
, ExpectedExceptionAttribute(typeof(ActiveRecordException
), "Error verifying the schema for model Post")]
26 public void VerificationOnWithMissingTableError()
28 XmlConfigurationSource config
= (XmlConfigurationSource
) GetConfigSource();
29 config
.VerifyModelsAgainstDBSchema
= true;
31 ActiveRecordStarter
.Initialize(config
, typeof(Post
));
35 ExpectedExceptionAttribute(typeof(ActiveRecordException
),
36 "Error verifying the schema for model ModelClassWithBrokenField")]
37 public void VerificationOnWithMissingFieldError()
39 // Create the tables first
40 XmlConfigurationSource config
= (XmlConfigurationSource
) GetConfigSource();
41 config
.VerifyModelsAgainstDBSchema
= false;
42 ActiveRecordStarter
.Initialize(config
, typeof(ModelClassUsedToCreateTableForClassWithBrokenField
));
45 // Then test Broken field
46 config
.VerifyModelsAgainstDBSchema
= true;
48 ActiveRecordStarter
.ResetInitializationFlag();
49 ActiveRecordStarter
.Initialize(config
, typeof(ModelClassWithBrokenField
));
53 public void VerificationOnWithNoError()
55 // Create the tables first
56 XmlConfigurationSource config
= (XmlConfigurationSource
) GetConfigSource();
57 config
.VerifyModelsAgainstDBSchema
= false;
58 ActiveRecordStarter
.Initialize(config
, typeof(Blog
), typeof(Post
));
61 // Then run again with verification
62 config
.VerifyModelsAgainstDBSchema
= true;
63 ActiveRecordStarter
.ResetInitializationFlag();
64 ActiveRecordStarter
.Initialize(config
, typeof(Blog
), typeof(Post
));
68 public void VerificationOffWithMissingTableError()
70 XmlConfigurationSource config
= (XmlConfigurationSource
) GetConfigSource();
71 config
.VerifyModelsAgainstDBSchema
= false;
73 ActiveRecordStarter
.Initialize(config
, typeof(Post
));
77 public void VerificationOffWithMissingFieldError()
79 // Create the tables first
80 XmlConfigurationSource config
= (XmlConfigurationSource
) GetConfigSource();
81 config
.VerifyModelsAgainstDBSchema
= false;
82 ActiveRecordStarter
.Initialize(config
, typeof(ModelClassUsedToCreateTableForClassWithBrokenField
));
85 // Then test Broken field
86 ActiveRecordStarter
.ResetInitializationFlag();
87 ActiveRecordStarter
.Initialize(config
, typeof(ModelClassWithBrokenField
));