Castle 1.0 RC2 嘗鮮

來源:互聯網
上載者:User

今天才看到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);

    }

}

看來又要很多東西要去研究了:)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.