Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Tools / VSNetWizards / CastleTemplates / VS8 / CSharp / AbstractModelTestCase.cs
bloba3f0f2677f1deddd65d73d61d1b13277e8f8bd1d
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 !NAMESPACE!.Tests
17 using System;
18 using System.Configuration;
20 using Castle.ActiveRecord;
21 using Castle.ActiveRecord.Framework;
23 using NUnit.Framework;
25 /// <summary>
26 /// This is a suggestion of base class that might
27 /// simplify the unit testing for the ActiveRecord
28 /// classes.
29 /// <para>
30 /// Basically you have to create a separate database
31 /// for your tests, which is always a good idea:
32 /// - production
33 /// - development
34 /// - test
35 /// </para>
36 /// <para>
37 /// You have to decide if you want to administrate the
38 /// schema on the <c>test</c> database or let ActiveRecord
39 /// generate them for you during test execution. Check
40 /// <see cref="AbstractModelTestCase.PrepareSchema"/>
41 /// </para>
42 /// </summary>
43 /// <remarks>
44 /// Note that this class enables lazy classes and collections
45 /// by using a <see cref="SessionScope"/>.
46 /// This have side effects. Some of your test must
47 /// invoke <see cref="FlushAndRecreateScope"/> sometimes
48 /// to persist the changes.
49 /// </remarks>
50 public abstract class AbstractModelTestCase
52 protected SessionScope scope;
54 [TestFixtureSetUp]
55 public virtual void FixtureInit()
57 InitFramework();
60 [SetUp]
61 public virtual void Init()
63 PrepareSchema();
65 CreateScope();
68 [TearDown]
69 public virtual void Terminate()
71 DisposeScope();
73 DropSchema();
76 [TestFixtureTearDown]
77 public virtual void TerminateAll()
81 protected void FlushAndRecreateScope()
83 DisposeScope();
84 CreateScope();
87 protected void CreateScope()
89 scope = new SessionScope();
92 protected void DisposeScope()
94 scope.Dispose();
97 /// <summary>
98 /// If you want to delete everything from the model.
99 /// Remember to do it in a descendent dependency order
100 /// </summary>
101 protected virtual void PrepareSchema()
103 // If you want to delete everything from the model.
104 // Remember to do it in a descendent dependency order
106 // Office.DeleteAll();
107 // User.DeleteAll();
109 // Another approach is to always recreate the schema
110 // (please use a separate test database if you want to do that)
112 ActiveRecordStarter.CreateSchema();
114 // You may also execute an external script
115 // to create your schema using ExecuteSchemaFromFile
117 // ActiveRecordStarter.ExecuteSchemaFromFile("script.sql");
120 protected virtual void DropSchema()
122 ActiveRecordStarter.DropSchema();
125 protected virtual void InitFramework()
127 IConfigurationSource source = ConfigurationSettings.GetConfig("activerecord") as IConfigurationSource;
129 ActiveRecordStarter.Initialize( source );
131 // Remember to add the types, for example
132 // ActiveRecordStarter.Initialize( source, typeof(Blog), typeof(Post) );