Not sure I'm asking the right question, so please bear with me! NHibernate noob bit.
We use Fluent NH and have the following identifier generation scheme for all tables
public class IdGenerationConvention : IIdConvention
{
public void Apply(IIdentityInstance instance)
{
var where = string.Format("TableKey = '{0}'", instance.EntityType.Name);
instance.GeneratedBy.HiLo("HiloPrimaryKeys", "NextHighValue", "1000", x => x.AddParam("where", where));
}
}
We have an SQL script that generates a table HiloPrimaryKeysand parses it with data that runs during deployment. This works fine.
Now I'm trying to write unit tests to test our persistence level, ideally using SQLite in the memory configuration for speed. This is how I configure NH for tests:
[SetUp]
public void SetupContext()
{
config = new SQLiteConfiguration()
.InMemory()
.ShowSql()
.Raw("hibernate.generate_statistics", "true");
var nhConfig = Fluently.Configure()
.Database(PersistenceConfigurer)
.Mappings(mappings =>
mappings.FluentMappings.AddFromAssemblyOf<DocumentMap>()
.Conventions.AddFromAssemblyOf<IdGenerationConvention>());
SessionSource = new SessionSource(nhConfig);
Session = SessionSource.CreateSession();
SessionSource.BuildSchema(Session);
}
The problem is that I don’t know how to tell NHibernate about our script deployment so that it generates the correct schema and seed data during the tests.
, , PersistenceSpecification:
[Test]
public void ShouldAddDocumentToDatabaseWithSimpleValues()
{
new PersistenceSpecification<Document>(Session)
.CheckProperty(x => x.CreatedBy, "anonymous")
.CheckProperty(x => x.CreatedOn, new DateTime(1954, 12, 23))
.CheckProperty(x => x.Reference, "anonymous")
.CheckProperty(x => x.IsMigrated, true)
.CheckReference(x => x.DocumentType, documentType)
.VerifyTheMappings();
}
:
TestCase ... failed:
Execute
NHibernate.Exceptions.GenericADOException:
could not get or update next value[SQL: ]
no such column: TableKey
, , script .
? Google-, , .