今天才看到Castle 1.0 RC2 發布的訊息,便迫不及待的載了下來,看看有什麼新鮮的玩藝兒。
下載安裝Castle 1.0後,在VS2005中會發現多出了兩個項目模版:Castle ActiveRecord Project和Castle MonoRail Project,如:
建立一個ActiveRecord項目,它會在解決方案中產生一個實體類項目的同時,還會產生一個單元測試項目:
並且提供一個用於測試實體的抽象類別,在這裡面已經設定好了要做單元測試的一切,寫自己的測試類別時只需要繼承於該類:
public abstract class AbstractModelTestCase
{
protected SessionScope scope;
[TestFixtureSetUp]
public virtual void FixtureInit()
{
InitFramework();
}
[SetUp]
public virtual void Init()
{
PrepareSchema();
CreateScope();
}
[TearDown]
public virtual void Terminate()
{
DisposeScope();
DropSchema();
}
[TestFixtureTearDown]
public virtual void TerminateAll()
{
}
protected void Flush()
{
SessionScope.Current.Flush();
}
protected void CreateScope()
{
scope = new SessionScope(FlushAction.Never);
}
protected void DisposeScope()
{
scope.Dispose();
}
/**//// <summary>
/// If you want to delete everything from the model.
/// Remember to do it in a descendent dependency order
/// </summary>
protected virtual void PrepareSchema()
{
// If you want to delete everything from the model.
// Remember to do it in a descendent dependency order
// Office.DeleteAll();
// User.DeleteAll();
// Another approach is to always recreate the schema
// (please use a separate test database if you want to do that)
ActiveRecordStarter.CreateSchema();
}
protected virtual void DropSchema()
{
ActiveRecordStarter.DropSchema();
}
protected virtual void InitFramework()
{
IConfigurationSource source = ActiveRecordSectionHandler.Instance;
ActiveRecordStarter.Initialize(source);
// Remember to add the types, for example
// ActiveRecordStarter.Initialize( source, typeof(Blog), typeof(Post) );
// Or to use the assembly that holds the ActiveRecord types
// ActiveRecordStarter.Initialize(System.Reflection.Assembly.Load("MyARProject"), source);
}
}
看來又要很多東西要去研究了:)