unit testing - How to test my repositories implementation? -


i using nunit test units. have interface on domain ready make implementation of interfaces in persistence layer. question how make unit tests testing repositories ? believe isnt idea test directly database. ive heard poeple using sqlite okay use mocks instead ? why poeple using sqlite in-memory database when can provide mock actuals entities ?

any example welcome too.

note: intended repositories coded in c# gonna use nhibernate , fluent nhibernate mapping.

thanks.

it of course depends, in cases i'd it's enough mock repositories in tests , using in-memory sqlite database test mappings (fluentnhibernate persistence specification testing).

for nunit mappings tests sqlite i'm using following base class:

public abstract class mappingstestbase {     [setup]     public void setup()     {         _session = sessionfactory.opensession();         buildschema(_session);     }      [testfixtureteardown]     public void terminate()     {         _session.close();         _session.dispose();          _session = null;         _sessionfactory = null;         _configuration = null;     }      #region nhibernate inmemory sqlite session      internal static isession _session;      private static isessionfactory _sessionfactory;     private static configuration _configuration;      private static isessionfactory sessionfactory     {                 {             if (_sessionfactory == null)             {                 fluentconfiguration configuration = fluently.configure()                     .database(sqliteconfiguration.standard.inmemory().showsql)                     .mappings(m => m.fluentmappings                         .addfromassemblyof<nhibernatesession>())                     .exposeconfiguration(c => _configuration = c);                  _sessionfactory = configuration.buildsessionfactory();             }              return _sessionfactory;         }     }      private static void buildschema(isession session)     {         schemaexport export = new schemaexport(_configuration);         export.execute(true, true, false, session.connection, null);     }      #endregion } 

an example mappings test class deriving above base class following:

[testfixture] public class mappingstest : mappingstestbase {     [test]     public void persistence_employee_shouldmapcorrectly()     {         category employee = new persistencespecification<employee>(_session)             .checkproperty(e => e.id, 1)             .checkproperty(e => e.firstname, "john")             .checkproperty(e => e.lastname, "doe")             .verifythemappings();         ...         assert.equals(employee.firstname, "john");         ...     } } 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -