There is a collection of data in the database on which a integration test is run. For preventing NHibernate persisting objects modification in the database an EventListener that inherits from DefaultSaveOrUpdateEventListener was implemented.
Then there is a method:
public override void OnSaveOrUpdate(SaveOrUpdateEvent @event)
{
@event.Session.CancelQuery();
Trace.TraceWarning("NhibernateSaveUpdateCanceler: Persistence will be ignored.");
}
Unfortunately this does not work as expected. So intended behavior is to catch the moment when changes are written in the database and cancel it somehow though leaving objects as there are so modification on them can be validated.
Thanks.
EDIT
Cannot do this because there are multiple transaction in the tested method so there is contradiction in requirements by persisting changes so that there are available for all transaction from one side and that changes are not persistent in the database from the other.
re-write your integration test with an Integration test fixture base. in the base class create:
a fixture setup that initializes nhibernate and creates a session factory
a fixture teardown that closes the session factory
a test setup that creates a session and transaction
a test teardown that rolls back the transaction and closes the session.
like this
then write your test.