Castle 1.0 RC2 尝鲜

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

下载安装Castle 1.0后,在VS2005中会发现多出了两个项目模版:Castle ActiveRecord ProjectCastle MonoRail Project,如下图:

Castle 1.0 RC2 尝鲜_第1张图片

新建一个ActiveRecord项目,它会在解决方案中生成一个实体类项目的同时,还会生成一个单元测试项目:

Castle 1.0 RC2 尝鲜_第2张图片

并且提供一个用于测试实体的抽象类,在这里面已经设置好了要做单元测试的一切,写自己的测试类时只需要继承于该类:

None.gif public   abstract   class  AbstractModelTestCase
None.gif
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
protected SessionScope scope;
InBlock.gif
InBlock.gif    [TestFixtureSetUp]
InBlock.gif
InBlock.gif    
public virtual void FixtureInit()
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        InitFramework();
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    [SetUp]
InBlock.gif
InBlock.gif    
public virtual void Init()
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        PrepareSchema();
InBlock.gif
InBlock.gif        CreateScope();
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    [TearDown]
InBlock.gif
InBlock.gif    
public virtual void Terminate()
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        DisposeScope();
InBlock.gif
InBlock.gif        DropSchema();
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    [TestFixtureTearDown]
InBlock.gif
InBlock.gif    
public virtual void TerminateAll()
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
protected void Flush()
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        SessionScope.Current.Flush();
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
protected void CreateScope()
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        scope 
= new SessionScope(FlushAction.Never);
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
protected void DisposeScope()
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        scope.Dispose();
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// 
InBlock.gif
InBlock.gif    
/// If you want to delete everything from the model.
InBlock.gif
InBlock.gif    
/// Remember to do it in a descendent dependency order
InBlock.gif
ExpandedSubBlockEnd.gif    
/// 

InBlock.gif
InBlock.gif    
protected virtual void PrepareSchema()
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
// If you want to delete everything from the model.
InBlock.gif
InBlock.gif        
// Remember to do it in a descendent dependency order
InBlock.gif
InBlock.gif        
// Office.DeleteAll();
InBlock.gif
InBlock.gif        
// User.DeleteAll();
InBlock.gif
InBlock.gif        
// Another approach is to always recreate the schema 
InBlock.gif
InBlock.gif        
// (please use a separate test database if you want to do that)
InBlock.gif

InBlock.gif        ActiveRecordStarter.CreateSchema();
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
protected virtual void DropSchema()
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        ActiveRecordStarter.DropSchema();
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
protected virtual void InitFramework()
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        IConfigurationSource source 
= ActiveRecordSectionHandler.Instance;
InBlock.gif
InBlock.gif        ActiveRecordStarter.Initialize(source);
InBlock.gif
InBlock.gif        
// Remember to add the types, for example
InBlock.gif
InBlock.gif        
// ActiveRecordStarter.Initialize( source, typeof(Blog), typeof(Post) );
InBlock.gif
InBlock.gif        
// Or to use the assembly that holds the ActiveRecord types
InBlock.gif
InBlock.gif        
// ActiveRecordStarter.Initialize(System.Reflection.Assembly.Load("MyARProject"), source);
InBlock.gif

ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedBlockEnd.gif}


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

你可能感兴趣的:(Castle 1.0 RC2 尝鲜)