Testing NHibernate with SQLite "No Such Table" - schema is generated -


i'm trying use in-memory sqlite database test data layer provided nhibernate.

i've read load of blogs , articles getting setup i'm confused why isn't working.

the problem - when run unit test error 'no such table: student'. articles i've read suggest because schema isn't getting generated, or, connection being closed between schemaexport , query. i've checked everywhere can think of , can't see how either of these scenarios occuring.

my test output log looks this:

open connection  drop table if exists "student"  drop table if exists "tutor"  create table "student" (     id  integer,    name text,    dob datetime,    tutorid integer,    primary key (id) )  create table "tutor" (     id  integer,    name text,    primary key (id) ) nhibernate: insert "student" (name, dob, tutorid) values (@p0, @p1, @p2); select last_insert_rowid();@p0 = 'text1', @p1 = 01/12/2010 14:55:05, @p2 = null 14:55:05,750 error [testrunnerthread] abstractbatcher [(null)]- not execute query: insert "student" (name, dob, tutorid) values (@p0, @p1, @p2); select last_insert_rowid() system.data.sqlite.sqliteexception (0x80004005): sqlite error  no such table: student  @ system.data.sqlite.sqlite3.prepare(string strsql, sqlitestatement previous, string& strremain)  @ system.data.sqlite.sqlitecommand.buildnextcommand()  @ system.data.sqlite.sqlitecommand.getstatement(int32 index)  @ system.data.sqlite.sqlitedatareader.nextresult()  @ system.data.sqlite.sqlitedatareader..ctor(sqlitecommand cmd, commandbehavior behave)  @ system.data.sqlite.sqlitecommand.executereader(commandbehavior behavior)  @ system.data.sqlite.sqlitecommand.executedbdatareader(commandbehavior behavior)  @ system.data.common.dbcommand.system.data.idbcommand.executereader()  @ nhibernate.adonet.abstractbatcher.executereader(idbcommand cmd)  14:55:05,781 error [testrunnerthread] adoexceptionreporter [(null)]- sqlite error no such table: student dispose closing connection 

originally using own code connection/session management have moved code in this blog post translated c# , couple changes dbconfig method , debug statements show state of connection.

private fluentnhibernate.cfg.db.ipersistenceconfigurer getdbconfig() {     return sqliteconfiguration.standard                                .connectionstring((connectionstringbuilder cs) => cs.is(connection_string))                                .proxyfactoryfactory("nhibernate.bytecode.linfu.proxyfactoryfactory, nhibernate.bytecode.linfu")                                .raw("connection.release_mode", "on_close"); } 

i added on_close after reading this

my test code looks this:

[test] public void cangetstudentbyid() {     using (var scope = new sqlitedatabasescope<studentmapping>())     {         using (isession sess = scope.opensession())         {             // arrange             var repo = new studentrepository();             repo.save(new student() { name = "text1", dob = datetime.now });              // act             var student = repo.getbyid(1);              // assert             assert.isnotnull(student);             assert.areequal("text1", student.name);         }    } } 

what have overlooked here?

update: created copy of class connects sqlite file db , worked fine. has connection being closed.

if change test method following, work?

[test] public void cangetstudentbyid() {     using (var scope = new sqlitedatabasescope<studentmapping>())     {         using (isession sess = scope.opensession())         {             // arrange             sess.save(new student() { name = "text1", dob = datetime.now });              // act             var student = sess.get<student>(1);              // assert             assert.isnotnull(student);             assert.areequal("text1", student.name);         }    } } 

i hazard guess studentrepository opening own session , hence doesn't see table.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -