5 using Castle
.ActiveRecord
;
6 using Castle
.ActiveRecord
.Framework
;
7 using Castle
.ActiveRecord
.Framework
.Config
;
12 /// This is a suggestion of base class that might
13 /// simplify the unit testing for the ActiveRecord
16 /// Basically you have to create a separate database
17 /// for your tests, which is always a good idea:
23 /// You have to decide if you want to administrate the
24 /// schema on the <c>test</c> database or let ActiveRecord
25 /// generate them for you during test execution. Check
26 /// <see cref="AbstractModelTestCase.PrepareSchema"/>
30 /// Note that this class enables lazy classes and collections
31 /// by using a <see cref="SessionScope"/>.
32 /// This have side effects. Some of your test must
33 /// invoke <see cref="Flush"/>
34 /// to persist the changes.
36 public abstract class AbstractModelTestCase
38 protected SessionScope scope
;
41 public virtual void FixtureInit()
47 public virtual void Init()
55 public virtual void Terminate()
63 public virtual void TerminateAll()
67 protected void Flush()
69 SessionScope
.Current
.Flush();
72 protected void CreateScope()
74 scope
= new SessionScope(FlushAction
.Never
);
77 protected void DisposeScope()
83 /// If you want to delete everything from the model.
84 /// Remember to do it in a descendent dependency order
86 protected virtual void PrepareSchema()
88 // If you want to delete everything from the model.
89 // Remember to do it in a descendent dependency order
91 // Office.DeleteAll();
94 // Another approach is to always recreate the schema
95 // (please use a separate test database if you want to do that)
97 ActiveRecordStarter
.CreateSchema();
100 protected virtual void DropSchema()
102 ActiveRecordStarter
.DropSchema();
105 protected virtual void InitFramework()
107 IConfigurationSource source
= ActiveRecordSectionHandler
.Instance
;
109 ActiveRecordStarter
.Initialize( source
);
111 // Remember to add the types, for example
112 // ActiveRecordStarter.Initialize( source, typeof(Blog), typeof(Post) );
114 // Or to use the assembly that holds the ActiveRecord types
115 // ActiveRecordStarter.Initialize(System.Reflection.Assembly.Load("MyARProject"), source);