unit testing - Fluent NHibernate - PersistenceSpecification of HiLo scheme -


not sure if i'm asking right question please bear me! bit of nhibernate noob.

we're using fluent nh , have following id generation scheme tables

public class idgenerationconvention : iidconvention {     public void apply(iidentityinstance instance)     {         var = string.format("tablekey = '{0}'", instance.entitytype.name);         instance.generatedby.hilo("hiloprimarykeys", "nexthighvalue", "1000", x => x.addparam("where", where));     } } 

we have sql script generates hiloprimarykeys table , seeds data gets run during deployment. working fine.

i'm trying write unit tests verify our persistence layer, ideally using sqlite in memory configuration speed. how configure nh 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 don't know how tell nhibernate our deployment script generates correct schema , seed data during tests.

the specific problem when running following persistencespecification test:

[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(); } 

which throws following exception:

testcase ... failed:  execute nhibernate.exceptions.genericadoexception:          not or update next value[sql: ]          ---> system.data.sqlite.sqliteexception: sqlite error         no such column: tablekey 

so deduction hasn't run deployment script when checking persistence spec.

is there existing solution situation? google-fu seems have deserted me on one.

as brian said, can run deployment script after schema built. code works me:

var config = new sqliteconfiguration()         .inmemory()         .showsql()         .raw("hibernate.generate_statistics", "true");  var nhconfig = fluently.configure()         .database(config)         .mappings(mappings =>              mappings.fluentmappings.addfromassemblyof<documentmap>()         .conventions.addfromassemblyof<idgenerationconvention>());  var sessionsource = new sessionsource(nhconfig); var session = sessionsource.createsession(); sessionsource.buildschema(session);  // run deployment script var deploymentscriptquery = session.createsqlquery("alter table hiloprimarykeys add column tablekey varchar(255); insert hiloprimarykeys (tablekey, nexthighvalue) values ('document', 1);"); deploymentscriptquery.executeupdate(); 

the deployment script loaded file etc...

building fnh configuration , database schema time consuming action. execution of test suit take unacceptable amount of time if count of tests using schema grows , schema , configuration built each test class. both configuration , schema should shared between tests. here how achieve without loosing test isolation.

edit: if more 1 session instance required in test connection pooling should turned on, or both sessions should created via same connection. details here...


Comments

Popular posts from this blog

how to build hyperlink for query string in php -

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

queue - mq_receive: message too long -