博客园  :: 首页  :: 新随笔  :: 联系 :: 管理

有时候如果我们的配置信息是动态的获取,这种方式就会变得非常有用。

示例 C# 代码

using System;
using NUnit.Framework;

using test;

using System.Reflection;

using Castle.ActiveRecord.Framework.Config;
using Castle.ActiveRecord;

namespace test._TestUnitCase
{
    
/**//// <summary>
    
/// BlogTest 的摘要说明。
    
/// </summary>
    [TestFixture]
    
public class BlogTest
    {
        
public BlogTest()
        {
        }
        
        [Test]
        
public void CreateBlogTest()
        {
            Assembly assembly 
= typeof(test.Blog).Assembly;

            InPlaceConfigurationSource src 
= new InPlaceConfigurationSource();

            Hashtable properties 
= new Hashtable();
            properties.Add(
"hibernate.connection.driver_class""NHibernate.Driver.SqlClientDriver");
            properties.Add(
"hibernate.dialect""NHibernate.Dialect.MsSql2000Dialect");
            properties.Add(
"hibernate.connection.provider""NHibernate.Connection.DriverConnectionProvider");
            properties.Add(
"hibernate.connection.connection_string""UID=sa;Password=19811218;Initial Catalog=ARDemo;Data Source=.");
            src.Add( 
typeof(ActiveRecordBase), properties );

            ActiveRecordStarter.Initialize( src, 
typeof(Blog) );


            Blog blog 
= new Blog();

            blog.Name
="abcde1234";
            blog.Author
="stephenabcdef";
            
            Console.WriteLine(BlogManager.getInstance().CreateBlog(blog));
        }
    }
}