I have the following config set up in my test project:
<configuration>
<configSections>
<section name="activerecord" type="Castle.ActiveRecord.Framework.Config.ActiveRecordSectionHandler, Castle.ActiveRecord" />
...
</configSections>
...
<activerecord>
<config>
<add key="connection.provider" value="(MyNamespace).Tests.Helpers.TestingConnectionProvider, (MyNamespace).Tests" />
<add key="dialect" value="NHibernate.Dialect.NHibernate.Dialect.SQLiteDialect" />
<add key="connection.driver_class" value="NHibernate.Driver.SQLiteDriver" />
<add key="connection.connection_string" value="Data Source=:memory:;Version=3;New=True;" />
<add key="show_sql" value="true" />
<add key="query.substitutions" value="true=1;false=0" />
<add key="proxyfactory.factory_class" value="NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle"/>
</config>
</activerecord>
...
</configuration>
I have also added the nhibernate prefix to the keys, as some documentation has suggested. My connection provider looks like:
public class TestingConnectionProvider : DriverConnectionProvider
{
public static IDbConnection Connection { get; private set; }
public override IDbConnection GetConnection()
{
return Connection ?? (Connection = base.GetConnection());
}
}
When I try to run my test:
[TestClass]
public class PersistenceTests
{
[TestMethod]
public void CanBuildSchemaInMemory()
{
if (File.Exists("SqlCreate.sql")) File.Delete("SqlCreate.sql");
ActiveRecordStarter.Initialize(typeof(IPermissionsManager).Assembly, new ActiveRecordSectionHandler());
ActiveRecordStarter.GenerateCreationScripts("CreateNew.sql");
Assert.IsTrue(File.Exists("SqlCreate.sql"));
}
}
... I get a failure that indicates I am not properly set up. However, if I change the ActiveRecordSectionHandler()
out for:
InPlaceConfigurationSource.Build(DatabaseType.MsSqlServer2008, "Server=localhost, Initial Catalog=Permissions, Integrated Security=SSPI;")
... this works, so clearly the problem is with my configuration. What am I doing wrong?
OK this was based off a couple of boneheaded things I did, and a genuine lack of understanding on some other things.
Boneheaded thing #1: I was generating a file other than the name I was looking for. Nice job, Jeremy.
Boneheaded thing #2: I had extra namespace elements in my config file; it's not NHibernate.Dialect.NHibernate.Dialect.SQLiteDialect
, it's just NHibernate.Dialect.SQLiteDialect
.
Genuine misunderstanding: I thought the ActiveRecordSectionHandler
was meant to be instantiated; turns out, I needed the static property of Instance
to work. So what it should have looked like is:
ActiveRecordStarter.Initialize(typeof(IPermissionsManager).Assembly, ActiveRecordSectionHandler.Instance);
Voila! the test passes.