Castle 1.0 RC2 尝鲜

今天才看到Castle 1.0 RC2 发布的消息,便迫不及待的载了下来,看看有什么新鲜的玩艺儿。

下载安装Castle 1.0后,在VS2005中会发现多出了两个项目模版:Castle ActiveRecord ProjectCastle 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);

    }


}


看来又要很多东西要去研究了:)

posted @ 2006-11-02 22:27  TerryLee  阅读(4182)  评论(18编辑  收藏  举报